| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/test20.chuangfenglink.xyz/wp-content/themes/woodmart/inc/admin/assets/js/ |
Upload File : |
/* global woodmartConfig, woodmartAdminModule */
(function($) {
// Condition query select2.
function conditionQuerySelect2($field) {
$field.select2({
ajax : {
url : woodmartConfig.ajaxUrl,
data : function(params) {
return {
action : 'wd_conditions_query',
security : woodmartConfig.get_new_template_nonce,
query_type: $field.attr('data-query-type'),
search : params.term
};
},
method : 'POST',
dataType: 'json'
},
theme : 'xts',
dropdownAutoWidth: false,
width : 'resolve'
});
}
function conditionQueryFieldInit( conditionType, $querySelect ) {
if ($querySelect.data('select2')) {
$querySelect.val('');
$querySelect.select2('destroy');
}
var $conditionQueryFieldTitle = $querySelect.parents('.xts-controls-wrapper').find('.xts-condition-query').first();
var $dependencFields = $querySelect.parents('.xts-table-controls').find('[data-dependency]');
$dependencFields.each(function( key, field ) {
var $field = $(field);
var $select = $field.find('select');
var dependency = $field.data('dependency').split(';').filter(function( val ) {
return val.length > 0;
});
$showField = false;
for (var i = 0; i < dependency.length; i++) {
var dep = dependency[i];
var parts = dep.split(':');
var key = parts[0];
var compare = parts[1];
var value = parts[2].split(',').filter(function( val ) {
return val.length > 0;
});
if ( 'type' === key && 'all' !== conditionType ) {
$showField = 'equals' === compare ? value.includes( conditionType ) : ! value.includes( conditionType );
}
// This field will appear if at least one dependency returns a value of true.
if ( $showField ) {
break;
}
}
if ( $showField ) {
$field.removeClass('xts-hidden');
if ( $field.hasClass('xts-condition-query') ) {
$select.attr('data-query-type', conditionType);
conditionQuerySelect2($select);
}
} else {
$field.addClass('xts-hidden');
if ( $select.data('select2') ) {
$select.removeAttr('data-query-type', conditionType);
$select.val('');
$select.select2('destroy');
}
}
});
// Show or hide Condition query field title.
var showTitle = false;
$('select.xts-condition-type').each((key, type) => {
if ( 'all' !== $(type).val() ) {
showTitle = true;
}
});
if ( showTitle ) {
$conditionQueryFieldTitle.removeClass('xts-hidden');
} else {
$conditionQueryFieldTitle.addClass('xts-hidden');
}
}
function validate() {
let isValid = true;
let $conditions = $('.xts-conditions-control');
let $conditionRows = $conditions.find('.xts-controls-wrapper > .xts-table-controls:not(.xts-table-heading)');
if ( 0 === $conditionRows.length ) {
woodmartAdminModule.woodmartAdmin.addNotice($conditions, 'warning', woodmartConfig.no_discount_condition);
isValid = false;
}
return isValid;
}
$('#post:has(.xts-options)').on('submit', function(e){
if ( ! validate() ) {
e.preventDefault();
}
});
$(document)
.ready( function() {
$('.xts-condition-query:not(.xts-hidden) select.xts-condition-query').each((key, field) => {
var $querySelect = $( field );
var conditionType = $querySelect.parents('.xts-table-controls').find('select.xts-condition-type').val();
conditionQueryFieldInit( conditionType, $querySelect );
});
})
.on('change', 'select.xts-condition-type', function() {
var $this = $(this);
var conditionType = $this.val();
var $querySelect = $this.parents('.xts-table-controls').find('select.xts-condition-query');
conditionQueryFieldInit( conditionType, $querySelect );
});
$(document).on('xts_select_with_table_control_row_removed', function( e, $control ) {
if ( ! $control.hasClass('xts-conditions-control') ) {
return;
}
var $conditionQueryFieldTitle = $control.find('.xts-controls-wrapper .xts-condition-query').first();
var showTitle = false;
$control.find('.xts-controls-wrapper select.xts-condition-type').each((key, type) => {
if ( 'all' !== $(type).val() ) {
showTitle = true;
}
});
if ( ! showTitle ) {
$conditionQueryFieldTitle.addClass('xts-hidden');
}
});
})(jQuery)