/** * plugin admin area javascript */ (function($){$(function () { if ( ! $('body.wpallimport-plugin').length) return; // do not execute any code if we are not on plugin page // fix wpallimport-layout position setTimeout(function () { $('table.wpallimport-layout').length && $('table.wpallimport-layout td.left h2:first-child').css('margin-top', $('.wrap').offset().top - $('table.wpallimport-layout').offset().top); }, 10); // help icons $('a.wpallimport-help').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: true, html: true, opacity: 1 }).live('click', function () { return false; }).each(function () { // fix tipsy title for IE $(this).attr('original-title', $(this).attr('title')); $(this).removeAttr('title'); }); // swither show/hide logic $('input.switcher').live('change', function (e) { if ($(this).is(':radio:checked')) { $(this).parents('form').find('input.switcher:radio[name="' + $(this).attr('name') + '"]').not(this).change(); } var $targets = $('.switcher-target-' + $(this).attr('id')); var 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(''); } }).change(); // swither show/hide logic $('input.switcher-horizontal').live('change', function (e) { if ($(this).is(':checked')) { $(this).parents('form').find('input.switcher-horizontal[name="' + $(this).attr('name') + '"]').not(this).change(); } var $targets = $('.switcher-target-' + $(this).attr('id')); var 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(''); } }).change(); // autoselect input content on click $('input.selectable').live('click', function () { $(this).select(); }); // input tags with title $('input[title]').each(function () { var $this = $(this); $this.bind('focus', function () { if ('' == $(this).val() || $(this).val() == $(this).attr('title')) { $(this).removeClass('note').val(''); } }).bind('blur', function () { if ('' == $(this).val() || $(this).val() == $(this).attr('title')) { $(this).addClass('note').val($(this).attr('title')); } }).blur(); $this.parents('form').bind('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' }).bind('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); } }).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"]').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').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').click(function(){ $(this).prev('a.collapser').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(){ var $wrap = $('.wrap'); var formHeight = $wrap.height(); var fixWrapHeight = false; $('#custom_type_selector').ddslick({ width: 590, onSlideDownOptions: function(o){ formHeight = $wrap.height(); $wrap.css({'height': formHeight + $('#custom_type_selector').find('.dd-options').height() + 'px'}); }, onSlideUpOptions: function(o){ $wrap.css({'height': formHeight + 'px'}); }, onSelected: function(selectedData){ if (fixWrapHeight){ $wrap.css({'height': formHeight + 'px'}); } 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(); } } }); $('.wpallimport-import-from').click(function(){ $('.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]').click(); } }); $('.wpallimport-import-from.selected').click(); }); $('input[name=url]').change(function(){ }).keyup(function (e) { if ($(this).val() != ''){ $('.wpallimport-url-icon').addClass('focus'); $(this).addClass('focus'); } else{ $('.wpallimport-url-icon').removeClass('focus'); $(this).removeClass('focus'); } }).focus(function(){ if ($(this).val() == 'Enter a web address to download the file from...') $(this).val(''); }).blur(function(){ if($(this).val() == '') $(this).val('Enter a web address to download the file from...'); }); // enter-submit form on step 1 $('.wpallimport-step-1').each(function(){ var $wrap = $('.wrap'); var formHeight = $wrap.height(); $('.wpallimport-import-from').click(function(){ var showImportType = false; switch ($(this).attr('rel')){ case 'upload_type': if ($('input[name=filepath]').val() != '') showImportType = true; break; case 'url_type': if ($('input[name=url]').val() != '') showImportType = false; break; case 'file_type': if ($('input[name=file]').val() != '') showImportType = false; 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]').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-upload-type-container').find('.wpallimport-free-edition-notice').slideDown(); $('.auto-generate-template').hide(); }); var fixWrapHeight = false; $('#custom_type_selector').ddslick({ width: 300, onSlideDownOptions: function(o){ formHeight = $wrap.height(); $wrap.css({'height': formHeight + $('#custom_type_selector').find('.dd-options').height() + 'px'}); }, onSlideUpOptions: function(o){ $wrap.css({'height': formHeight + 'px'}); }, onSelected: function(selectedData){ if (fixWrapHeight) $wrap.css({'height': formHeight + 'px'}); 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(); } } } }); $('.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(); }); $('#custom_type_selector').hide(); $('.wpallimport-import-to.wpallimport-import-to-checked').click(); $('a.auto-generate-template').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"]').live('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 this.find('.xml-expander').live('click', 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.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'); } }); $('#title, #content, .widefat, input[name^=custom_name], textarea[name^=custom_value], input[name^=featured_image], input[name^=unique_key]').bind('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() + 4).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').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').die('click').live('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', '').change(); } $preview.find('input[name="tagno"]').die(); $preview.find('.navigation a').die('click'); $form.find('.' + $preview_type).click(); }, 'json'); return false; }); $preview.find('input[name="tagno"]').unbind('click').die('click').live('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', '').change(); } $preview.find('input[name="tagno"]').die(); $preview.find('.navigation a').die('click'); $form.find('.' + $preview_type).click(); }, 'json'); return false; }); }, 'json'); return false; }); $form.find('.set_encoding').live('click', function(e){ e.preventDefault(); $form.find('a[rel="preview"].preview').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]').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').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').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().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').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').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').live('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 $('.save_sf').live('click', 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 $('.auto_detect_sf').live('click', 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').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').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 $('.save_mr').live('click', function(){ var $source = $(this).parents('table:first'); var $destination = $('div#' + $source.attr('rel')); var $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; }); var $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').click(function(){ $(this).parents('table:first').find('tr.private_ctx').toggle(); }); // Test & Preview images $('.test_images').live('click', function(){ var ths = $(this); $(this).attr({'disabled':'disabled'}); $('.img_preloader').show(); $('.img_success').html('').hide(); $('.img_failed').remove(); var imgs = new Array(); $('.images_list').find('li').each(function(){ imgs.push($(this).attr('rel')); }); var 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').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.setCursor(1); }); } else{ $parent.addClass('closed'); $parent.find('.wpallimport-collapsed-content:first').slideUp(); } }); $('#is_delete_posts').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').click(function(e){ e.preventDefault(); window.location.href = $(this).attr('rel'); }); $('.wpallimport-wpae-notify-read-more').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').click(function(){ wpai_are_sure_to_delete_import(); }); // [\ Delete Import] 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').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]').removeAttr('checked').click(); $(this).removeClass('wpallimport-select-all'); } else { $parent.find('input[type=checkbox]:checked').click(); $(this).addClass('wpallimport-select-all'); } $(this).attr('rel', $(this).html()); $(this).html($newtitle); }); var fix_tag_position = function(){ if ($('.wpallimport-layout').length && $('.tag').length){ var offset = $('.wpallimport-layout').offset(); if ($(document).scrollTop() > offset.top){ $('.tag').css({'top':'50px'}); $('.wpallimport-xml').css({'max-height': ($(window).height() - 147) + 'px' }); } else{ $('.tag').css({'top':'127px'}); $('.wpallimport-xml').css({'max-height': ($(window).height() - 220) + 'px' }); } } } fix_tag_position(); $(document).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);