Skip to content

Commit

Permalink
VERSION 3.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Salazar Delgado committed Feb 14, 2023
1 parent 78e384a commit 32a024e
Show file tree
Hide file tree
Showing 51 changed files with 949 additions and 1,093 deletions.
2 changes: 1 addition & 1 deletion assets/js/admin/yith-wcwl.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/jquery.yith-wcwl.min.js

Large diffs are not rendered by default.

343 changes: 0 additions & 343 deletions assets/js/unminified/admin/yith-wcwl.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,349 +45,6 @@ jQuery( function( $ ) {
}).change();
};

/* === PROMOTION WIZARD HANDLER === */

var Wizard = function( el, args ){
var self = this;

self.settings = {};

self.modal = null;

self._init = function(){
self.settings = $.extend( {
template: el.data('template'),
template_data: {},
container: '.yith-wcwl-wizard-modal',
events: {}
}, args );

if( typeof self.settings.events['init'] === 'function' ){
self.settings.events.init( el, args );
}

self._initOpener();
};

self._initOpener = function(){
el.on( 'click', function( ev ){
var t = $(this),
settings = self.settings.template_data;

ev.preventDefault();

// init opener-specific template data
if( typeof settings === 'function' ){
settings = ( settings )( t );
}

t.WCBackboneModal({
template: self.settings.template,
variable: settings
});

var container = $( self.settings.container );

self._initEditor( container );
self._initEnhancedSelect( container );
self._initTabs( container );
self._initSteps( container );
self._initOptions( container, settings );
self._initEvents( container, self.settings.events );
} );
};

self._initEditor = function( modal ){
modal.find( '.with-editor' ).each( function(){
var t = $(this),
id = t.attr('id');

// Destroy any existing editor so that it can be re-initialized when popup opens.
if ( tinymce.get( id ) ) {
restoreTextMode = tinymce.get( id ).isHidden();
wp.editor.remove( id );
}

wp.editor.initialize( id, {
tinymce: {
wpautop: true,
init_instance_callback: function (editor) {
editor.on('Change', function (e) {
t.val( editor.getContent() ).change();
});
}
},
quicktags: true,
mediaButtons: true
} );
} )
};

self._initEnhancedSelect = function( modal ){
$(document.body).trigger( 'wc-enhanced-select-init' );
};

self._initTabs = function( modal ){
modal.find( '.tabs' ).on( 'click', 'a', function( ev ){
var t = $(this),
ul = t.closest('ul'),
a = ul.find( 'a' ),
p = ul.parent(),
tabs = p.find( '.tab' ),
target = t.data( 'target' ),
tab = $( target ),
changed = false;

ev.preventDefault();

if( ! t.hasClass( 'active' ) ){
changed = true;
}

a.attr( 'aria-selected', 'false' ).removeClass( 'active' );
t.attr( 'aria-selected', 'true' ).addClass( 'active' );

tabs.attr( 'aria-expanded', 'false' ).removeClass( 'active' ).hide();
tab.attr( 'aria-expanded', 'true' ).addClass( 'active' ).show();

if( changed ){
t.trigger( 'tabChange' );
}
} );
};

self._initOptions = function( modal, values ){
$.each( values, function( i, v ){
var field = modal.find( '[name="' + i + '"]' );

if( ! field.length || v === field.val() ){
return;
}

if( field.is( 'select' ) && v && ! field.find( 'option[value="' + v + '"]' ).length ){
field.append( '<option value="' + v + '" selected="selected">' + v + ' </option>' );
}
else {
field.val(v);
}
} );
};

self._initSteps = function( modal ){
// show only first step by default
modal.find( '.step' ).hide().first().show();

// init continue button
modal.find( '.continue-button' ).on( 'click', function( ev ){
var t = $(this),
current_step = t.closest( '.step' ),
next_step = current_step.next( '.step' );

ev.preventDefault();

if( next_step.length ) {
self._changeStep( modal, current_step, next_step );
}
} );

// init back button
modal.find( '.back-button' ).on( 'click', function( ev ){
var t = $(this),
current_step = t.closest( '.step' ),
prev_step = current_step.prev( '.step' );

ev.preventDefault();

if( prev_step.length ) {
self._changeStep( modal, current_step, prev_step );
}
} );
};

self._initEvents = function( modal, events ){
if( typeof self.settings.events['open'] === 'function' ){
self.settings.events.open( el, modal );
}

$.each( events, function( i, v ){
var target = null;

// exclude general events
if( i === 'init' || i === 'open' ){
return;
}

// tab events
else if( i === 'tabChange' ){
target = modal.find( '.tabs' );
}

// step events
else if( i === 'stepChange' ){
target = modal.find( '.step' );
}

// input changes
else{
target = modal.find( ':input' );
}

target.on( i, function( ev ){
return ( v )( $(this), modal, ev );
} );
} );
};

self._changeStep = function( modal, current, next ){
current.animate( {
opacity: 0
}, {
duration: 200,
complete: function(){
var modalContent = modal.find( 'article' ),
modalContentWidth = modalContent.outerWidth(),
modalContentHeight = modalContent.outerHeight();

// calculate step size
modalContent.outerWidth( 'auto' );
modalContent.outerHeight( 'auto' );

current.hide();
next.show();

var nextWidth = next.outerWidth(),
nextHeight = next.outerHeight();

next.hide();
current.css( 'opacity', 1 );

// fix modal size
modalContent.outerWidth( modalContentWidth );
modalContent.outerHeight( modalContentHeight );

modalContent.animate( {
width: nextWidth,
height: nextHeight
}, {
duration: 200,
complete: function(){
next.fadeIn( 200 );
}
} );
}
} );

next.trigger( 'stepChange' );
};

self._init();
},
updatePreviewXHR = null,
updatePreview = function( el, modal, ev ){
var preview = modal.find( '.email-preview' ),
template = modal.find('#template').val();

if( updatePreviewXHR ){
updatePreviewXHR.abort();
}

updatePreviewXHR = $.ajax( {
url: ajaxurl + '?action=preview_promotion_email&_wpnonce=' + yith_wcwl.nonce.preview_promotion_email,
data: modal.find('form').serialize(),
method: 'POST',
beforeSend: function(){
preview.block({
message: null,
overlayCSS: {
background: 'transparent',
opacity: 0.6
}
});
},
complete: function(){
preview.unblock();
},
success: function( data ){
preview.removeClass( 'html plain' ).addClass( template ).find('.no-interactions').html( data );
}
} );
},
getPromotionWizardData = function(){
return {
template: 'yith-wcwl-promotion-wizard',
template_data: function( el ){
var data = el.data( 'draft' );

if( ! data ) {
data = $.extend( data, {
product_id : el.data('product_id'),
user_id : el.data('user_id'),
content_html: yith_wcwl.promotion.content_html,
content_text: yith_wcwl.promotion.content_html,
coupon : false,
} );
}

return data;
},
events: {
change: updatePreview,
open: function( el, modal, ev ){
modal.find( '#content_html-tmce' ).click();
updatePreview( el, modal, ev );
},
tabChange: function( el, modal, ev ){
modal.find( '#template' ).val( el.find( '.active' ).data( 'template' ) );
updatePreview( el, modal, ev );
},
stepChange: function( el, modal, ev ){
var counter = el.find( '.receivers-count' ),
additional_info = el.find( '.show-on-long-queue' ),
threshold = additional_info.data('threshold');

if( ! counter.length ){
return;
}

$.ajax({
url: ajaxurl + '?action=calculate_promotion_email_receivers&_wpnonce=' + yith_wcwl.nonce.calculate_promotion_email_receivers,
data: modal.find('form').serialize(),
method: 'post',
beforeSend: function(){
counter.css( 'opacity', 0.3 );

if( additional_info.length ){
additional_info.hide();
}
},
complete: function(){
counter.css( 'opacity', 1 );
},
success: function( data ){
if( typeof data.label === 'undefined' ){
return;
}

counter.html( data.label );

if( additional_info.length && typeof data.count !== 'undefined' && data.count > threshold ){
additional_info.show();
}
}
});
}
}
}
};

$.fn.wizard = function ( args ) {
var t = $(this),
w = new Wizard( t, args );
};

$('.create-promotion').wizard( getPromotionWizardData() );
$('.restore-draft').wizard( getPromotionWizardData() );

/* === UTILITY FUNCTIONS === */

var isRadioYes = function (t) {
Expand Down
12 changes: 12 additions & 0 deletions assets/js/unminified/jquery.yith-wcwl.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,14 @@ jQuery( function( $ ){
}
});

// Move the Add to Wishlist button under the gallery
$( document ).ready(function() {
if( yith_wcwl_l10n.yith_wcwl_button_position === 'thumbnails' ) {
$( '.woocommerce-product-gallery + div.yith-wcwl-add-to-wishlist' ).appendTo( '.woocommerce-product-gallery' );
}
});


/* === INIT FUNCTIONS === */

/**
Expand Down Expand Up @@ -1549,6 +1557,10 @@ jQuery( function( $ ){
else{
try {
$.prettyPhoto.close();

if ( yith_wcwl_l10n.redirect_after_ask_estimate ) {
window.location.replace( yith_wcwl_l10n.ask_estimate_redirect_url );
}
}
catch( e ){ /* do nothing, no popup to close */ }
}
Expand Down
14 changes: 1 addition & 13 deletions includes/class-yith-wcwl-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,7 @@ public function init() {
wp_register_style( 'yith-wcwl-font-awesome', YITH_WCWL_URL . 'assets/css/font-awesome.min.css', array(), '4.7.0' );
wp_register_style( 'yith-wcwl-material-icons', 'https://fonts.googleapis.com/icon?family=Material+Icons', array(), '3.0.1' );
wp_register_style( 'yith-wcwl-admin', YITH_WCWL_URL . 'assets/css/admin.css', array( 'yith-wcwl-font-awesome' ), YITH_WCWL_Frontend()->version );
wp_register_script( 'yith-wcwl-admin', YITH_WCWL_URL . 'assets/js/' . $prefix . 'admin/yith-wcwl' . $suffix . '.js', array( 'jquery', 'wc-backbone-modal', 'jquery-blockui' ), YITH_WCWL_Frontend()->version, true );

wp_localize_script(
'yith-wcwl-admin',
'yith_wcwl',
array(
'promotion' => get_option( 'woocommerce_yith_wcwl_promotion_mail_settings', array() ),
'nonce' => array(
'preview_promotion_email' => wp_create_nonce( 'preview_promotion_email' ),
'calculate_promotion_email_receivers' => wp_create_nonce( 'calculate_promotion_email_receivers' ),
),
)
);
wp_register_script( 'yith-wcwl-admin', YITH_WCWL_URL . 'assets/js/' . $prefix . 'admin/yith-wcwl' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ), YITH_WCWL_Frontend()->version, true );
}

/**
Expand Down
Loading

0 comments on commit 32a024e

Please sign in to comment.