Skip to content

Commit

Permalink
Merge pull request #156 from codersaiful/3.0.4.2
Browse files Browse the repository at this point in the history
3.0.4.2
  • Loading branch information
codersaiful authored Nov 27, 2021
2 parents 0e8ffde + 44b8616 commit 3fff6c9
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 2 deletions.
13 changes: 12 additions & 1 deletion admin/admin-enqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @update 1.0.3
*/
function wpt_admin_enqueue(){

/**
* Select2 CSS file including.
*
Expand All @@ -18,7 +19,7 @@ function wpt_admin_enqueue(){
* Including UltraAddons CSS form Style
*/
wp_enqueue_style( 'ultraaddons-css', WPT_Product_Table::getPath( 'BASE_URL' ) . 'assets/css/admin-common.css', array(), WPT_DEV_VERSION, 'all' );
wp_enqueue_style('ultraaddons-css');


wp_enqueue_style( 'wpt-admin', WPT_Product_Table::getPath( 'BASE_URL' ) . 'assets/css/admin.css', array('select2'), WPT_DEV_VERSION, 'all' );

Expand Down Expand Up @@ -47,6 +48,16 @@ function wpt_admin_enqueue(){

//WordPress Default Media Added only for addmin
wp_enqueue_media();

/**
* WPT Offer handle, User will able to
* see latest offer only when pro version
* is not installed.
*/
if( ! defined( 'WPT_PRO_DEV_VERSION' ) ){
wp_enqueue_style( 'wpt-offer-css', WPT_Product_Table::getPath( 'BASE_URL' ) . 'admin/notice/offeres/offer.css', array(), WPT_DEV_VERSION, 'all' );
wp_enqueue_script( 'wpt-offer-js', WPT_Product_Table::getPath( 'BASE_URL' ) . 'admin/notice/offeres/offer.js', array( 'jquery' ), WPT_DEV_VERSION, true );
}
}
}
add_action( 'admin_enqueue_scripts', 'wpt_admin_enqueue', 99 );
Expand Down
Binary file added admin/notice/offeres/images/Black-Friday.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions admin/notice/offeres/offer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.wpt-special-offer {
margin-top: 15px;

background: white;
padding: 0;
}
.wpt-special-offer img.offer_image {
max-height: 200px;
width: auto;
}
a.offer_image_link {
display: block;
}
106 changes: 106 additions & 0 deletions admin/notice/offeres/offer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
(function($) {
'use strict';
$(document).ready(function() {
if(! $('body').hasClass('wpt_admin_body')){
return false;
}

let wrapper_class = '.wpt-special-offer';
loadOfferContent();

function loadOfferContent(){
let offer_json = getCookie('wpt_offer_latest');
if( offer_json !== '' ){

offer_json = JSON.parse(offer_json);
console.log(offer_json);
jsonToHtmlMarkup(offer_json);

}else if(navigator.onLine){
loadContentByAjax();
}

}

function loadContentByAjax(){
let url = "https://raw.githubusercontent.com/codersaiful/woo-product-table/master/admin/notice/offeres/offer.json";
$.ajax({
url: url,
method: "GET",
dataType: 'json',
success:function(result){
if(result && result !== ''){
setCookie('wpt_offer_latest',JSON.stringify(result),2);//For Two days
jsonToHtmlMarkup(result);
}

},
error:function(e){
console.log("Something went wrong.");
}
});
}

function jsonToHtmlMarkup(result){
if(! result.offer.status){
return;
}
let offer = result.offer,
image_url = offer.image_url,
target_link = offer.target_link,
target_html = offer.target_html,
wrapper_css = offer.wrapper_css,
image_css = offer.image_css;


let location_selector = offer.display_wrapper + " " + offer.display_to;

$(wrapper_class).remove();

let image_link_html = "";
if( image_url && target_link ){
image_link_html = `<a class="offer_image_link" href="`+ target_link +`" target="_blank">
<img class="offer_image" src="` + image_url + `">
</a>`;
}

if(!target_html){
target_html=""
}

let html = `<div class="wpt-special-offer">` + image_link_html + target_html + `</div>`;


$(location_selector).prepend(html);
$(wrapper_class).css(wrapper_css);

if(image_css){
$(wrapper_class).find("img.offer_image").css(image_css);
}
}

function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000)); //(exdays*24*60*60*1000)
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

});
})(jQuery);
18 changes: 18 additions & 0 deletions admin/notice/offeres/offer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"offer": {
"status": true,
"target_link": "https://codecanyon.net/item/woo-product-table-pro/20676867",
"image_url": "https://raw.githubusercontent.com/codersaiful/woo-product-table/3.0.4.2/admin/notice/offeres/images/Black-Friday.png",
"display_to": "#wpbody-content",
"display_wrapper": ".wpt_admin_body",
"target_html": false,
"wrapper_css":{
"color":"green",
"background-color":"#240202"
},
"image_css":{
"height":"210px",
"width":"auto"
}
}
}
2 changes: 1 addition & 1 deletion woo-product-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

if( !defined( 'WPT_DEV_VERSION' ) ){
define( 'WPT_DEV_VERSION', '3.0.4.1' );
define( 'WPT_DEV_VERSION', '3.0.4.2' );
}

if( !defined( 'WPT_CAPABILITY' ) ){
Expand Down

0 comments on commit 3fff6c9

Please sign in to comment.