/** * plugin admin area javascript */ (function($){$(function () { if ( ! $('body.wpallimport-plugin').length) return; // do not execute any code if we are not on plugin page function wpai_set_custom_select_image() { // The class name to add to the element. var class_name = jQuery('[class^="dd-selected-text dashicon"]').text().toLowerCase(); class_name = class_name.replace( /\s+/g, '' ); // This gets the image URL out of the class. var class_check = jQuery('[class^="dd-selected-text dashicon"]').attr( 'class' ); class_check = class_check.replace( "dd-selected-text dashicon ", "" ); // String of allowed images. var imgs = ['jpg','jpeg','jpe','gif','png','bmp'], length = imgs.length; while( length-- ) { if ( class_check.indexOf( imgs[ length ] ) != -1 ) { // They have defined an image URL, which means it's a custom image and we need to add the class. jQuery('[class^="dd-selected-text dashicon"]').addClass("wpaiimgfor" + class_name); jQuery('[class^="dd-selected-text dashicon"]').removeClass( class_check ); } } } // Rapid Add-On API Images $(document).ready(function($){ var class_check; var original_class; var new_class_name; var allstyles = ""; $( allstyles ).appendTo("head"); }); // fix wpallimport-layout position setTimeout(function () { $('table.wpallimport-layout').length && $('table.wpallimport-layout td.left h2:first-child').css('margin-top', $('.wrap').has('.wpallimport-layout').offset().top - $('table.wpallimport-layout').offset().top); }, 10); // help icons $(document).tipsy({ gravity: function() { var ver = 'n'; if ($(document).scrollTop() < $(this).offset().top - $('.tipsy').height() - 2) { ver = 's'; } var hor = ''; if ($(this).offset().left + $('.tipsy').width() < $(window).width() + $(document).scrollLeft()) { hor = 'w'; } else if ($(this).offset().left - $('.tipsy').width() > $(document).scrollLeft()) { hor = 'e'; } return ver + hor; }, live: 'a.wpallimport-help, .scheduling-help', html: true, opacity: 1 }).each(function () { // fix tipsy title for IE $(this).attr('original-title', $(this).attr('title')); $(this).removeAttr('title'); }); // swither show/hide logic $('input.switcher').on("change", function (e) { if ($(this).is(':radio:checked')) { $(this).parents('form').find('input.switcher:radio[name="' + $(this).attr('name') + '"]').not(this).trigger('change'); } let $targets = $('.switcher-target-' + $(this).attr('id')); let is_show = $(this).is(':checked'); if ($(this).is('.switcher-reversed')) is_show = ! is_show; if (is_show) { $targets.slideDown(); } else { $targets.slideUp().find('.clear-on-switch').add($targets.filter('.clear-on-switch')).val(''); } }).trigger('change'); // swither show/hide logic $('input.switcher-horizontal').on('change', function (e) { if ($(this).is(':checked')) { $(this).parents('form').find('input.switcher-horizontal[name="' + $(this).attr('name') + '"]').not(this).trigger('change'); } let $targets = $('.switcher-target-' + $(this).attr('id')); let is_show = $(this).is(':checked'); if ($(this).is('.switcher-reversed')) is_show = ! is_show; if (is_show) { $targets.animate({width:'205px'}, 350); } else { $targets.animate({width:'0px'}, 1000).find('.clear-on-switch').add($targets.filter('.clear-on-switch')).val(''); } }).trigger('change'); // autoselect input content on click $(document).on('click', 'input.selectable', function () { $(this).select(); }); // input tags with title $('input[title]').each(function () { var $this = $(this); $this.on('focus', function () { if ('' == $(this).val() || $(this).val() == $(this).attr('title')) { $(this).removeClass('note').val(''); } }).on('blur', function () { if ('' == $(this).val() || $(this).val() == $(this).attr('title')) { $(this).addClass('note').val($(this).attr('title')); } }).trigger('blur'); $this.parents('form').on('submit', function () { if ($this.val() == $this.attr('title')) { $this.val(''); } }); }); // datepicker $('input.datepicker').datepicker({ dateFormat: 'yy-mm-dd', showOn: 'button', buttonText: '', constrainInput: false, showAnim: 'fadeIn', showOptions: 'fast' }).on('change', function () { var selectedDate = $(this).val(); var instance = $(this).data('datepicker'); var date = null; if ('' != selectedDate) { try { date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings); } catch (e) { date = null; } } if ($(this).hasClass('range-from')) { $(this).parent().find('.datepicker.range-to').datepicker("option", "minDate", date); } if ($(this).hasClass('range-to')) { $(this).parent().find('.datepicker.range-from').datepicker("option", "maxDate", date); } }).trigger('change'); $('.ui-datepicker').hide(); // fix: make sure datepicker doesn't break wordpress wpallimport-layout upon initialization // no-enter-submit forms $('form.no-enter-submit').find('input,select,textarea').not('*[type="submit"]').on('keydown', function (e) { if (13 == e.keyCode) e.preventDefault(); }); $('a.collapser').each(function(){ if ($(this).html() == "+"){ $(this).parents('div:first').find('.collapser_content:first').hide(); } else { $(this).parents('div:first').find('.collapser_content:first').fadeIn(); } $(this).next('h3').css({'cursor':'pointer'}); }); $('a.collapser').on('click', function(){ if ($(this).html() == "+") { $(this).html("-"); $(this).parents('div:first').find('.collapser_content:first').fadeIn(); } else { $(this).html("+"); $(this).parents('div:first').find('.collapser_content:first').hide(); } }); $('a.collapser').each(function(){ $(this).parents('.fieldset:first').find('h3:first').on('click', function(){ $(this).prev('a.collapser').trigger('click'); }); }); var toggle_dynamic_notice = function(){ $('.wpallimport-dynamic-notice').hide(); var $import_to_custom_type = $('input[name=custom_type]').val(); var $is_show_cf_notice = false; var $is_show_images_notice = false; $('input[name^=custom_name]').each(function(){ if ( $(this).val() != "") { $is_show_cf_notice = true; return false; } }); if ( $import_to_custom_type != 'product' && ( $('textarea[name=download_featured_image]').length && $('textarea[name=download_featured_image]').val() != "" || $('textarea[name=gallery_featured_image]').length && $('textarea[name=gallery_featured_image]').val() != "" || $('textarea[name=featured_image]').length && $('textarea[name=featured_image]').val() != "" )) { $is_show_images_notice = true; } if ( $is_show_cf_notice && $is_show_images_notice ){ $('.wpallimport-dynamic-notice').find('a').html($('.wpallimport-dynamic-notice-cf-image-text').val()); $('.wpallimport-dynamic-notice').show(); } else if ( $is_show_cf_notice ){ $('.wpallimport-dynamic-notice').find('a').html($('.wpallimport-dynamic-notice-cf-text').val()); $('.wpallimport-dynamic-notice').show(); } else if ( $is_show_images_notice ) { $('.wpallimport-dynamic-notice').find('a').html($('.wpallimport-dynamic-notice-images-text').val()); $('.wpallimport-dynamic-notice').show(); } } $('.change_file').each(function(){ let $wrap = $('.wrap').has('.wpallimport-layout'); var formHeight = $wrap.height(); var fixWrapHeight = false; $('#custom_type_selector').ddslick({ width: 590, onSlideDownOptions: function(o){ formHeight = ($('.wpallimport-layout').height() < 730) ? 730 : $('.wpallimport-layout').height(); $wrap.css({'height': formHeight + $('#custom_type_selector').find('.dd-options').height() + 'px'}); }, onSlideUpOptions: function(o){ $wrap.css({'height': 'auto'}); }, onSelected: function(selectedData){ if (fixWrapHeight) { $wrap.css({'height': 'auto'}); } else { fixWrapHeight = true; } $('.wpallimport-upgrade-notice').hide(); $('input[name=custom_type]').val(selectedData.selectedData.value); $('#custom_type_selector').find('.dd-selected').css({'color':'#555'}); var is_import_denied = $('.wpallimport-upgrade-notice[rel='+ selectedData.selectedData.value +']').length; if (is_import_denied){ $('.wpallimport-upgrade-notice[rel='+ selectedData.selectedData.value +']').slideDown(); $('.wpallimport-submit-buttons').hide(); } else { $('.wpallimport-submit-buttons').slideDown(); } // Rapid Add-On API Images wpai_set_custom_select_image(); } }); $('.wpallimport-import-from').on('click', function(){ var showImportType = false; switch ($(this).attr('rel')){ case 'upload_type': if ($('input[name=filepath]').val() != '') { showImportType = true; } $('.wpallimport-download-resource').hide(); break; case 'url_type': if ($('input[name=url]').val() != '') { showImportType = true; } $('.wpallimport-download-from-checked').trigger('click'); break; case 'file_type': if ($('input[name=file]').val() != '') { showImportType = true; } $('.wpallimport-download-resource').hide(); break; } $('.wpallimport-import-from').removeClass('selected').addClass('bind'); $(this).addClass('selected').removeClass('bind'); $('.wpallimport-import-from').removeClass('selected').addClass('bind'); $(this).addClass('selected').removeClass('bind'); $('.change_file').find('.wpallimport-upload-type-container').hide(); $('.change_file').find('.wpallimport-file-upload-result').attr('rel', $(this).attr('rel')); $('.change_file').find('.wpallimport-upload-type-container[rel=' + $(this).attr('rel') + ']').show(); $('.change_file').find('#wpallimport-url-upload-status').html(''); $('.change_file').find('input[name=new_type]').val( $(this).attr('rel').replace('_type', '') ); //$('.first-step-errors').hide(); if ($(this).attr('rel') == 'upload_type'){ $('input[type=file]').trigger('click'); } }); $('.wpallimport-import-from.selected').trigger('click'); $('.wpallimport-download-from').on('click', function(){ if ($(this).attr('rel') === 'url') { $('.wpallimport-download-resource-step-two-url').show(); $('.wpallimport-download-resource-step-two-ftp').hide(); } else { $('.wpallimport-download-resource-step-two-url').hide(); $('.wpallimport-download-resource-step-two-ftp').show(); } $('.wpallimport-download-from').removeClass('wpallimport-download-from-checked'); $(this).addClass('wpallimport-download-from-checked'); $('.change_file').find('input[name=new_type]').val( $(this).attr('rel') ); }); $('.wpallimport-download-from.wpallimport-download-from-checked').trigger('click'); }); $('input[name=url]').on('change', function(){ }).on('keyup', function (e) { if ($(this).val() != ''){ $('.wpallimport-url-icon').addClass('focus'); $(this).addClass('focus'); } else { $('.wpallimport-url-icon').removeClass('focus'); $(this).removeClass('focus'); } }).on('focus', function(){ if ($(this).val() == 'Enter a web address to download the file from...') $(this).val(''); }).on('blur', function(){ if($(this).val() == '') $(this).val('Enter a web address to download the file from...'); }); $('#taxonomy_to_import').ddslick({ width: 300, onSelected: function(selectedData){ if (selectedData.selectedData.value != ""){ $('#taxonomy_to_import').find('.dd-selected').css({'color':'#555'}); $('.wpallimport-choose-file').find('.wpallimport-submit-buttons').show(); } else { $('#taxonomy_to_import').find('.dd-selected').css({'color':'#cfceca'}); $('.wpallimport-choose-file').find('.wpallimport-submit-buttons').hide(); } $('input[name=taxonomy_type]').val(selectedData.selectedData.value); } }); // enter-submit form on step 1 $('.wpallimport-step-1').each(function(){ var $wrap = $('.wrap').has('.wpallimport-layout'); var formHeight = ($('.wpallimport-layout').height() < 730) ? 730 : $('.wpallimport-layout').height(); $('.wpallimport-import-from').on('click', function(){ var showImportType = false; switch ($(this).attr('rel')){ case 'upload_type': if ($('input[name=filepath]').val() != '') { showImportType = true; } $('.wpallimport-download-resource').hide(); break; case 'url_type': if ($('input[name=url]').val() != '') { showImportType = true; } $('.wpallimport-download-from-checked').trigger('click'); break; case 'file_type': if ($('input[name=file]').val() != '') { showImportType = true; } $('.wpallimport-download-resource').hide(); break; } $('.wpallimport-import-from').removeClass('selected').addClass('bind'); $('.wpallimport-import-types').find('h2').slideUp(); $(this).addClass('selected').removeClass('bind'); $('.wpallimport-choose-file').find('.wpallimport-upload-type-container').hide(); $('.wpallimport-choose-file').find('.wpallimport-file-upload-result').attr('rel', $(this).attr('rel')); $('.wpallimport-choose-file').find('.wpallimport-upload-type-container[rel=' + $(this).attr('rel') + ']').show(); $('.wpallimport-choose-file').find('#wpallimport-url-upload-status').html(''); $('.wpallimport-choose-file').find('input[name=type]').val( $(this).attr('rel').replace('_type', '') ); if ($('.auto-generate-template').attr('rel') == $(this).attr('rel')){ $('.auto-generate-template').css({'display':'inline-block'}); } else { $('.auto-generate-template').hide(); } if ($(this).attr('rel') == 'upload_type'){ $('input[type=file]').trigger('click'); } if ( ! showImportType){ $('.wpallimport-choose-file').find('.wpallimport-upload-resource-step-two').slideUp(); $('.wpallimport-choose-file').find('.wpallimport-submit-buttons').hide(); } else { $('.wpallimport-choose-file').find('.wpallimport-upload-resource-step-two').slideDown(); $('.wpallimport-choose-file').find('.wpallimport-submit-buttons').show(); } }); $('.wpallimport-import-from.selected').click(); $('.wpallimport-download-from-url').click(function(){ $(this).parents('.wpallimport-download-resource').find('.wpallimport-free-edition-notice').slideDown(); $('.auto-generate-template').hide(); }); $('.wpai-ftp-select-file-button').click(function () { $(this).parents('.wpallimport-download-resource').find('.wpallimport-free-edition-notice').slideDown(); }); var fixWrapHeight = false; $('#custom_type_selector').ddslick({ width: 300, onSlideDownOptions: function(o){ formHeight = ($('.wpallimport-layout').height() < 730) ? 730 : $('.wpallimport-layout').height(); $wrap.css({'height': formHeight + $('#custom_type_selector').find('.dd-options').height() + 'px'}); }, onSlideUpOptions: function(o){ $wrap.css({'height' : 'auto'}); }, onSelected: function(selectedData){ if (fixWrapHeight){ $wrap.css({'height': 'auto'}); } else { fixWrapHeight = true; } $('#custom_type_selector').find('.dd-selected').css({'color':'#555'}); $('.wpallimport-upgrade-notice').hide(); $('input[name=custom_type]').val(selectedData.selectedData.value); var is_import_denied = $('.wpallimport-upgrade-notice[rel='+ selectedData.selectedData.value +']').length; if (is_import_denied){ $('.wpallimport-upgrade-notice[rel='+ selectedData.selectedData.value +']').slideDown(); } if (is_import_denied) { $('.wpallimport-choose-file').find('.wpallimport-submit-buttons').hide(); $('.wpallimport-import-orders-notice').show(); } else { $('.wpallimport-import-orders-notice').hide(); if ($('.wpallimport-upload-resource-step-two:visible').length) { $('.wpallimport-choose-file').find('.wpallimport-submit-buttons').show(); } else { $('.wpallimport-choose-file').find('.wpallimport-submit-buttons').hide(); } } // Rapid Add-On API Images wpai_set_custom_select_image(); } }); $('.wpallimport-import-to').click(function(){ if ($(this).attr('rel') == 'new'){ $('.wpallimport-new-records').show(); $('.wpallimport-existing-records').hide(); } else { $('.wpallimport-new-records').hide(); $('.wpallimport-existing-records').show(); } $('.wpallimport-import-to').removeClass('wpallimport-import-to-checked'); $(this).addClass('wpallimport-import-to-checked'); $('input[name=wizard_type]').val($(this).attr('rel')); $('.wpallimport-choose-import-direction').attr({'rel' : $(this).attr('rel')}); $('.dd-container').fadeIn(); }); $('.wpallimport-download-from').on('click', function(){ if ($(this).attr('rel') === 'url') { $('.wpallimport-download-resource-step-two-url').show(); $('.wpallimport-download-resource-step-two-ftp').hide(); } else { $('.wpallimport-download-resource-step-two-url').hide(); $('.wpallimport-download-resource-step-two-ftp').show(); } $('.wpallimport-download-from').removeClass('wpallimport-download-from-checked'); $(this).addClass('wpallimport-download-from-checked'); $('.wpallimport-choose-file').find('input[name=type]').val( $(this).attr('rel') ); $('.dd-container').fadeIn(); }); $('#custom_type_selector').hide(); $('.wpallimport-import-to.wpallimport-import-to-checked').trigger('click'); $('.wpallimport-download-from.wpallimport-download-from-checked').trigger('click'); $('a.auto-generate-template').on('click', function(){ $('input[name^=auto_generate]').val('1'); $(this).parents('form:first').submit(); }); }); //[/End Step 1] // template form: auto submit when `load template` list value is picked $('form.wpallimport-template').find('select[name="load_template"]').on('change', function () { $(this).parents('form').submit(); }); var serialize_ctx_mapping = function(){ $('.custom_type[rel=tax_mapping]').each(function(){ var values = new Array(); $(this).find('.form-field').each(function(){ if ($(this).find('.mapping_to').val() != "") { var skey = $(this).find('.mapping_from').val(); if ('' != skey){ var obj = {}; obj[skey] = $(this).find('.mapping_to').val(); values.push(obj); } } }); $(this).find('input[name^=tax_mapping]').val(window.JSON.stringify(values)); }); }; // [xml representation dynamic] $.fn.xml = function (opt) { if ( ! this.length) return this; var $self = this; var opt = opt || {}; var action = {}; if ('object' == typeof opt) { action = opt; } else { action[opt] = true; } action = $.extend({init: ! this.data('initialized')}, action); if (action.init) { this.data('initialized', true); // add expander $(document).on('click', '.xml-expander', function () { var method; if ('-' == $(this).text()) { $(this).text('+'); method = 'addClass'; } else { $(this).text('-'); method = 'removeClass'; } // for nested representation based on div $(this).parent().find('> .xml-content')[method]('collapsed'); // for nested representation based on tr var $tr = $(this).parent().parent().filter('tr.xml-element').next()[method]('collapsed'); }); } if (action.dragable) { // drag & drop var _w; var _dbl = 0; var $drag = $('__drag'); $drag.length || ($drag = $('')); $drag.css({ position: 'absolute', background: 'transparent', top: -50, left: 0, margin: 0, border: 'none', lineHeight: 1, opacity: 0, cursor: 'pointer', borderRadius: 0, zIndex:99 }).appendTo(document.body).mousedown(function (e) { if (_dbl) return; var _x = e.pageX - $drag.offset().left; var _y = e.pageY - $drag.offset().top; if (_x < 4 || _y < 4 || $drag.width() - _x < 0 || $drag.height() - _y < 0) { return; } $drag.width($(document.body).width() - $drag.offset().left - 5).css('opacity', 1); $drag.select(); _dbl = true; setTimeout(function () {_dbl = false;}, 400); }).mouseup(function () { $drag.css('opacity', 0).css('width', _w); $drag.trigger('blur'); }).dblclick(function(){ if (dblclickbuf.selected) { $('.xml-element[title*="/'+dblclickbuf.value.replace('{','').replace('}','')+'"]').removeClass('selected'); if ($(this).val() == dblclickbuf.value) { dblclickbuf.value = ''; dblclickbuf.selected = false; } else { dblclickbuf.selected = true; dblclickbuf.value = $(this).val(); $('.xml-element[title*="/'+$(this).val().replace('{','').replace('}','')+'"]').addClass('selected'); } } else { dblclickbuf.selected = true; dblclickbuf.value = $(this).val(); $('.xml-element[title*="/'+$(this).val().replace('{','').replace('}','')+'"]').addClass('selected'); } }); $('input, textarea').not('#__drag').on('focus', insertxpath ); $(document).mousemove(function () { if (parseInt($drag.css('opacity')) != 0) { setTimeout(function () { $drag.css('opacity', 0); }, 50); setTimeout(function () { $drag.css('width', _w); }, 500); } }); this.find('.xml-tag.opening > .xml-tag-name, .xml-attr-name, .csv-tag.opening > .csv-tag-name, .ui-menu-item').each(function () { var $this = $(this); var xpath = '.'; if ($this.is('.xml-attr-name')) xpath = '{' + ($this.parents('.xml-element:first').attr('title').replace(/^\/[^\/]+\/?/, '') || '.') + '/@' + $this.html().trim() + '}'; else if($this.is('.ui-menu-item')) xpath = '{' + ($this.attr('title').replace(/^\/[^\/]+\/?/, '') || '.') + '}'; else xpath = '{' + ($this.parent().parent().attr('title').replace(/^\/[^\/]+\/?/, '') || '.') + '}'; $this.mouseover(function (e) { $drag.val(xpath).offset({left: $this.offset().left - 2, top: $this.offset().top - 2}).width(_w = $this.width()).height($this.height() + 4); }); }).eq(0).mouseover(); } return this; }; // template form: preview button $('form.wpallimport-template').each(function () { var $form = $(this); var $detected_cf = new Array(); $form.find('.preview, .preview_images, .preview_taxonomies, .preview_prices').on('click', function () { var $preview_type = $(this).attr('rel'); var $options_slug = $(this).parent('div').find('.wp_all_import_section_slug').val(); if ($preview_type == 'preview_taxonomies') serialize_ctx_mapping(); var $URL = 'admin.php?page=pmxi-admin-import&action=' + $preview_type + ((typeof import_id != "undefined") ? '&id=' + import_id : ''); var $tagURL = 'admin.php?page=pmxi-admin-import&action=tag' + ((typeof import_id != "undefined") ? '&id=' + import_id : ''); if ($options_slug != undefined) $URL += '&slug=' + $options_slug; $('.wpallimport-overlay').show(); var $ths = $(this); $(this).pointer({ content: '
', position: { edge: 'right', align: 'center' }, pointerWidth: ($preview_type == 'preview_images') ? 800 : 715, close: function() { $.post( ajaxurl, { pointer: 'pksn1', action: 'dismiss-wp-pointer' }); $('.wpallimport-overlay').hide(); } }).pointer('open'); var $pointer = $('.wpallimport-pointer-' + $preview_type).parents('.wp-pointer').first(); var $leftOffset = ($(window).width() - (($preview_type == 'preview_images') ? 800 : 715))/2; $pointer.css({'position':'fixed', 'top' : '15%', 'left' : $leftOffset + 'px'}); if (typeof tinyMCE != 'undefined') tinyMCE.triggerSave(false, false); $.post($URL, $form.serialize(), function (response) { $ths.pointer({'content' : response.html}); $pointer.css({'position':'fixed', 'top' : '15%', 'left' : $leftOffset + 'px'}); var $preview = $('.wpallimport-' + $preview_type); $preview.parent('.wp-pointer-content').removeClass('wp-pointer-content').addClass('wpallimport-pointer-content'); var $tag = $('.tag'); var tagno = parseInt($tag.find('input[name="tagno"]').val()); $preview.find('.navigation a').unbind('click').off('click').on('click', function () { tagno += '#prev' == $(this).attr('href') ? -1 : 1; $tag.addClass('loading').css('opacity', 0.7); $preview.addClass('loading').css('opacity', 0.7); $.post($tagURL, {tagno: tagno, import_action: import_action, security: wp_all_import_security}, function (data) { var $indicator = $('').insertBefore($tag); $tag.replaceWith(data.html); fix_tag_position(); $indicator.next().tag().prevObject.remove(); if ($('#variations_xpath').length){ $('#variations_xpath').data('checkedValue', '').trigger('change'); } $preview.find('input[name="tagno"]').off(); $preview.find('.navigation a').off('click'); $form.find('.' + $preview_type).trigger('click'); }, 'json'); return false; }); $preview.find('input[name="tagno"]').unbind('click').off('click').on('change', function () { tagno = (parseInt($(this).val()) > parseInt($preview.find('.pmxi_count').html())) ? $preview.find('.pmxi_count').html() : ( (parseInt($(this).val())) ? $(this).val() : 1 ); $tag.addClass('loading').css('opacity', 0.7); $.post($tagURL, {tagno: tagno, security: wp_all_import_security}, function (data) { var $indicator = $('').insertBefore($tag); $tag.replaceWith(data.html); fix_tag_position(); $indicator.next().tag().prevObject.remove(); if ($('#variations_xpath').length){ $('#variations_xpath').data('checkedValue', '').trigger('change'); } $preview.find('input[name="tagno"]').off(); $preview.find('.navigation a').off('click'); $form.find('.' + $preview_type).trigger('click'); }, 'json'); return false; }); }, 'json'); return false; }); $form.find('.set_encoding').on('click', function(e){ e.preventDefault(); $form.find('a[rel="preview"].preview').trigger('click'); }); $form.find('input[name$=download_images]').each(function(){ if ($(this).is(':checked') && $(this).val() == 'gallery' ) { $(this).parents('.wpallimport-collapsed-content:first').find('.advanced_options_files').find('p:first').show(); $(this).parents('.wpallimport-collapsed-content:first').find('.advanced_options_files').find('input').attr({'disabled':'disabled'}); } }); $form.find('input[name$=download_images]').on('click', function(){ if ($(this).is(':checked') && $(this).val() == 'gallery' ) { $(this).parents('.wpallimport-collapsed-content:first').find('.advanced_options_files').find('p:first').show(); $(this).parents('.wpallimport-collapsed-content:first').find('.advanced_options_files').find('input').attr({'disabled':'disabled'}); } else { $(this).parents('.wpallimport-collapsed-content:first').find('.advanced_options_files').find('p:first').hide(); $(this).parents('.wpallimport-collapsed-content:first').find('.advanced_options_files').find('input').removeAttr('disabled'); } }); // Auto-detect custom fields $form.find('.auto_detect_cf').on('click', function(){ var parent = $(this).parents('.wpallimport-collapsed-content:first'); var request = { action:'auto_detect_cf', fields: $('#existing_meta_keys').val().split(','), post_type: $('input[name=custom_type]').val(), security: wp_all_import_security }; $(this).attr({'disabled':'disabled'}); var $indicator = $('').insertBefore($(this)).show(); var ths = $(this); $.ajax({ type: 'POST', url: ajaxurl, data: request, success: function(response) { parent.find('input[name^=custom_name]:visible').each(function(){ if ("" == $(this).val()) $(this).parents('tr').first().remove(); }); $detected_cf = response.result; var $added_fields_count = 0; if (response.result.length){ for (var i = 0; i < response.result.length; i++){ var allow_add = true; parent.find('input[name^=custom_name]:visible').each(function(){ if (response.result[i].key == "" || response.result[i].key == $(this).val()) { allow_add = false; return false; } }); // if this field doesn't present in custom fields section then put it there if ( allow_add ){ parent.find('a.add-new-custom').trigger('click'); var fieldParent = parent.find('.form-field:visible').last(); fieldParent.find('input[name^=custom_name]:visible').last().val(response.result[i].key); fieldParent.find('textarea[name^=custom_value]:visible').last().val(response.result[i].val); if (response.result[i].is_serialized) fieldParent.find('.set_serialize').last().parent().trigger('click'); $added_fields_count++; } } } $indicator.remove(); $('.cf_detected').html(response.msg); $('.cf_welcome').hide(); $('.cf_detect_result').fadeIn(); ths.removeAttr('disabled'); }, error: function(request) { $indicator.remove(); ths.removeAttr('disabled'); }, dataType: "json" }); }); // Clear all detected custom fields $form.find('.clear_detected_cf').on('click', function(){ var parent = $(this).parents('.wpallimport-collapsed-content:first'); if ($detected_cf.length){ for (var i = 0; i < $detected_cf.length; i++){ parent.find('input[name^=custom_name]:visible').each(function(){ if ($detected_cf[i].key == $(this).val()) $(this).parents('tr').first().remove(); }); } } if ( ! parent.find('input[name^=custom_name]:visible').length){ parent.find('a.add-new-custom').trigger('click'); } $('.cf_detected').html(''); $('.cf_detect_result').hide(); $('.cf_welcome').fadeIn(); $detected_cf = new Array(); }); // toggle custom field as serialized/default $form.find('.wpallimport-cf-menu li').on('click', function(){ var $triggerEvent = $(this).find('a'); if ($triggerEvent.hasClass('set_serialize')){ var parent = $triggerEvent.parents('.form-field:first'); var parent_custom_format = parent.find('input[name^=custom_format]:first'); var parent_custom_value = parent.find('textarea[name^=custom_value]:first'); if (parseInt(parent_custom_format.val())){ parent_custom_format.val(0); parent.find('.specify_cf:first').hide(); parent_custom_value.fadeIn(); $triggerEvent.parent().removeClass('active'); } else { parent_custom_format.val(1); parent_custom_value.hide(); parent.find('.specify_cf:first').fadeIn(); $triggerEvent.parent().addClass('active'); } } }); // [Serialized custom fields] // Save serialized custom field format $(document).on('click', '.save_sf', function(){ var $source = $(this).parents('table:first'); var $destination = $('div#' + $source.attr('rel')); $destination.find('table:first').html(''); $source.find('input').each(function(i, e){ $(this).attr("value", $(this).val()); }); $destination.find('table:first').html($source.html()); $destination.parents('td:first').find('.pmxi_cf_pointer').pointer('destroy'); $('.wpallimport-overlay').hide(); }); // Auto-detect serialized custom fields $(document).on('click', '.auto_detect_sf', function() { var $source = $(this).parents('table:first'); var $destination = $('div#' + $source.attr('rel')); var $parentDestination = $destination.parents('tr:first'); var $cf_name = $parentDestination.find('input[name^=custom_name]:first').val(); if ($cf_name != ''){ var request = { action:'auto_detect_sf', security: wp_all_import_security, post_type: $('input[name=custom_type]').val(), name: $cf_name }; $(this).attr({'disabled':'disabled'}); var $indicator = $('').insertBefore($(this)).show(); var ths = $(this); $.ajax({ type: 'POST', url: ajaxurl, data: request, success: function(response) { if (response.result.length){ $destination.find('tr.form-field').each(function(){ if ( ! $(this).hasClass('template') ) $(this).remove(); }); for (var i = 0; i < response.result.length; i++){ $destination.find('a.add-new-key').trigger('click'); $destination.find('tr.form-field').not('.template').last().css({"opacity": 1}).find('input.serialized_key').attr("value", response.result[i].key); $destination.find('tr.form-field').not('.template').last().css({"opacity": 1}).find('input.serialized_value').attr("value", response.result[i].val); } $destination.parents('td:first').find('.pmxi_cf_pointer').pointer('destroy'); $destination.parents('td:first').find('.pmxi_cf_pointer').trigger('click'); } else { var $notice = $('No fields detected.
').insertBefore(ths).show(); setTimeout(function() { $notice.slideUp().remove(); }, 2500); } $indicator.remove(); ths.removeAttr('disabled'); }, error: function(request) { $indicator.remove(); ths.removeAttr('disabled'); }, dataType: "json" }); } }); // [/ Serialized custom fields] // Save mapping rules for custom field $(document).on('click', '.save_mr', function(){ let $source = $(this).parents('table:first'); let $destination = $('div#' + $source.attr('rel')); let $is_active = false; $destination.find('table:first').html(''); $source.find('input').each(function(i, e){ $(this).attr("value", $(this).val()); if ($(this).val() != "") { $is_active = true; } }); let $box = $destination.parents('td.action:first'); if ( $is_active ){ $box.find('.set_mapping').parent().addClass('active'); } else { $box.find('.set_mapping').parent().removeClass('active'); } $destination.find('table:first').html($source.html()); $destination.parents('td:first').find('.pmxi_cf_mapping').pointer('destroy'); $('.wpallimport-overlay').hide(); }); // Taxonnomies $form.find('#show_hidden_ctx').on('click', function(){ $form.find('tr.private_ctx').toggle(); }); // Test & Preview images $(document).on('click', '.test_images', function(){ let ths = $(this); $(this).attr({'disabled':'disabled'}); $('.img_preloader').show(); $('.img_success').html('').hide(); $('.img_failed').remove(); let imgs = new Array(); $('.images_list').find('li').each(function(){ imgs.push($(this).attr('rel')); }); let request = { action: 'test_images', security: wp_all_import_security, download: ths.attr('rel'), imgs:imgs }; $.ajax({ type: 'POST', url: ajaxurl, data: request, success: function(response) { $('.img_preloader').hide(); if ( parseInt(response.success_images)) { $('.img_success').html(response.success_msg).show(); } if (response.failed_msgs.length){ for (var i = 0; i < response.failed_msgs.length; i++){ $('.test_progress').append('No matching elements found for XPath expression specified.
' + response.msg + '
'); if (response.result){ $('.wp_all_import_functions_preloader').hide(); window.location.href = response.redirect; } else { deleteImport(); } }, error: function( jqXHR, textStatus ) { $ths.removeAttr('disabled'); $('.wp_all_import_functions_preloader').hide(); }, dataType: "json" }); } $('.wp_all_import_functions_preloader').show(); deleteImport(); }); $('.wpallimport-collapsed').each(function(){ if ( ! $(this).hasClass('closed')) $(this).find('.wpallimport-collapsed-content:first').slideDown(); }); $('.wpallimport-collapsed').find('.wpallimport-collapsed-header').not('.disabled').on('click', function(){ var $parent = $(this).parents('.wpallimport-collapsed:first'); if ($parent.hasClass('closed')){ $parent.removeClass('closed'); $parent.find('.wpallimport-collapsed-content:first').slideDown(400, function(){ if ($('#wp_all_import_code').length) editor.codemirror.setCursor(1); }); } else { $parent.addClass('closed'); $parent.find('.wpallimport-collapsed-content:first').slideUp(); } }); $('#is_delete_posts').on('change', function(){ if ($(this).is(':checked')){ $('.wpallimport-delete-posts-warning').show(); } else { $('.wpallimport-delete-posts-warning').hide(); } }); $('.wpallimport-dependent-options').each(function(){ $(this).prev('div.input').find('input[type=text]:last, textarea:last').addClass('wpallimport-top-radius'); }); $('.wpallimport-delete-and-edit, .download_import_template, .download_import_bundle').on('click', function(e){ e.preventDefault(); window.location.href = $(this).attr('rel'); }); $('.wpallimport-wpae-notify-read-more').on('click', function(e){ e.preventDefault(); var request = { action: 'dismiss_notifications', security: wp_all_import_security, addon: $(this).parent('div:first').attr('rel') }; var ths = $(this); $.ajax({ type: 'POST', url: ajaxurl, data: request, success: function(response) { }, dataType: "json" }); $(this).parent('div:first').slideUp(); window.open($(this).attr('href'), '_blank'); }); // [ Delete Import] var wpai_are_sure_to_delete_import = function() { if ( ! $('.delete-single-import').length ) return; $('.delete-single-import').removeAttr('disabled'); if ( $('#is_delete_import').is(':checked') || $('#is_delete_posts').is(':checked')) { $('.wp-all-import-sure-to-delete').show(); } if ( ! $('#is_delete_import').is(':checked') && ! $('#is_delete_posts').is(':checked')) { $('.wp-all-import-sure-to-delete').hide(); $('.delete-single-import').attr('disabled', 'disabled'); } if ( $('#is_delete_import').is(':checked') && $('#is_delete_posts').is(':checked')) { $('.sure_delete_posts_and_import').show(); } if ($('#is_delete_import').is(':checked')) { $('.sure_delete_import').show(); } else { $('.sure_delete_import').hide(); $('.sure_delete_posts_and_import').hide(); } if ($('#is_delete_posts').is(':checked')) { $('.sure_delete_posts').show(); } else { $('.sure_delete_posts').hide(); $('.sure_delete_posts_and_import').hide(); } } wpai_are_sure_to_delete_import(); $('#is_delete_import, #is_delete_posts').on('click', function(){ wpai_are_sure_to_delete_import(); }); // [\ Delete Import] let get_delete_missing_notice_type = function() { if (!$('input[name="is_delete_missing"]').is(':checked')) { return 0; } if ($('input[name="delete_missing_logic"]:checked').val() == 'import' && $('input[name="delete_missing_action"]:checked').val() == 'keep' && $('input[name="is_send_removed_to_trash"]').is(':checked')) { return 1; } if ($('input[name="delete_missing_logic"]:checked').val() == 'import' && $('input[name="delete_missing_action"]:checked').val() == 'keep' && $('input[name="is_change_post_status_of_removed"]').is(':checked')) { return 2; } if ($('input[name="delete_missing_logic"]:checked').val() == 'import' && $('input[name="delete_missing_action"]:checked').val() == 'remove') { return 3; } if ($('input[name="delete_missing_logic"]:checked').val() == 'all' && $('input[name="delete_missing_action"]:checked').val() == 'keep' && $('input[name="is_send_removed_to_trash"]').is(':checked')) { return 4; } if ($('input[name="delete_missing_logic"]:checked').val() == 'all' && $('input[name="delete_missing_action"]:checked').val() == 'keep' && $('input[name="is_change_post_status_of_removed"]').is(':checked')) { return 5; } if ($('input[name="delete_missing_logic"]:checked').val() == 'all' && $('input[name="delete_missing_action"]:checked').val() == 'remove') { return 6; } return 0; } function is_valid_delete_missing_options() { let is_valid = true; if ( $('input[name="is_delete_missing"]').is(':checked') && $('input[name="delete_missing_action"]:checked').val() == 'keep' ) { if ( ! $('input[name="is_send_removed_to_trash"]').is(':checked') && ! $('input[name="is_change_post_status_of_removed"]').is(':checked') && ! $('input[name="is_update_missing_cf"]').is(':checked') && ! $('input[name="missing_records_stock_status"]').is(':checked') ) { is_valid = false; } } return is_valid; } let delete_missing_helper_text = function() { $('.helper-text').hide(); if ( is_valid_delete_missing_options() ) { $('.delete-missing-error').addClass('hidden'); $('.switcher-target-delete_missing_action_keep').removeClass('delete-missing-error-wrapper'); } else { $('.delete-missing-error').removeClass('hidden'); $('.switcher-target-delete_missing_action_keep').addClass('delete-missing-error-wrapper'); } let notice_type = get_delete_missing_notice_type(); // Show notice if any. if (notice_type) { $('.helper-text-' + notice_type).find('.status_of_removed').html($('select[name="status_of_removed"]').val()); $('.helper-text-' + notice_type).show(); } }; delete_missing_helper_text(); $('.switcher-target-is_delete_missing').find('input, select').on('change', function() { delete_missing_helper_text(); }); $('#is_delete_missing').on('change', function() { delete_missing_helper_text(); }); if ($('.switcher-target-update_choosen_data').length) { var $re_import_options = $('.switcher-target-update_choosen_data'); var $toggle_re_import_options = $('.wpallimport-trigger-options'); if ($re_import_options.find('input[type=checkbox]').length == $re_import_options.find('input[type=checkbox]:checked').length) { var $newtitle = $toggle_re_import_options.attr('rel'); $toggle_re_import_options.attr('rel', $toggle_re_import_options.html()); $toggle_re_import_options.html($newtitle); $toggle_re_import_options.removeClass('wpallimport-select-all'); } } $('.wpallimport-trigger-options').on('click', function(){ var $parent = $(this).parents('.switcher-target-update_choosen_data:first'); var $newtitle = $(this).attr('rel'); if ( $(this).hasClass('wpallimport-select-all') ) { $parent.find('input[type=checkbox]').not('.exclude-select-all').removeAttr('checked').trigger('click'); $(this).removeClass('wpallimport-select-all'); } else { $parent.find('input[type=checkbox]:checked').not('.exclude-select-all').trigger('click'); $(this).addClass('wpallimport-select-all'); } $(this).attr('rel', $(this).html()); $(this).html($newtitle); }); $('table.pmxi-admin-imports').each(function () { let manage_table = $(this); $(this).find('thead tr th.check-column :checkbox, tfoot tr th.check-column :checkbox').on('click', function () { let is_checked = $(this).is(':checked'); manage_table.find('tbody tr th.check-column :checkbox').prop('checked', function () { if (is_checked) { return true; } return false; }); }); }); var fix_tag_position = function(){ if ($('.wpallimport-layout').length && $('.tag').length && $('.wpallimport-content-section').length){ var offset_top = $('.wpallimport-content-section').first().offset().top; var position_top = offset_top - $(document).scrollTop(); var wordpress_adminbar_height = $('#wpadminbar').height(); $('.tag').css({'top': offset_top}); $('.tag').css('margin-top', '0'); if ($(document).scrollTop() + wordpress_adminbar_height > offset_top){ $('.tag').css({'top':'50px'}); $('.wpallimport-xml').css({'max-height': ($(window).height() - 147) + 'px' }); } else { $('.tag').css({'top': position_top + 'px' }); $('.wpallimport-xml').css({'max-height': ($(window).height() - 220) + 'px' }); } } } $('input#is_send_removed_to_trash').change(function(e){ $('.wpallimport-free-edition-notice.send-removed-to_trash-notice').slideDown(); $('input#is_send_removed_to_trash').addClass('wpai-shake-small'); setTimeout(function(){ $('input#is_send_removed_to_trash').prop('checked', false); $('input#is_send_removed_to_trash').removeClass('wpai-shake-small'); return false; },600); }); $('input#is_delete_missing').change(function(e){ let selector = '.wpallimport-free-edition-notice.delete-missing-existing-items'; if ($(selector).length) { $(selector).slideDown(); $('input#is_delete_missing').addClass('wpai-shake-small'); setTimeout(function(){ $('input#is_delete_missing').prop('checked', false); $('input#is_delete_missing').removeClass('wpai-shake-small'); return false; },600); } }); fix_tag_position(); $(document).on('scroll', function() { fix_tag_position(); toggle_dynamic_notice(); }); toggle_dynamic_notice(); $('input[name^=custom_name], input[name^=custom_value], textarea[name=download_featured_image], textarea[name=gallery_featured_image], textarea[name=featured_image]').change(function() { toggle_dynamic_notice(); }); $('input[name^=custom_name], input[name^=custom_value], textarea[name=download_featured_image], textarea[name=gallery_featured_image], textarea[name=featured_image]').blur(function() { toggle_dynamic_notice(); }); });})(jQuery);