/** * * ----------------------------------------------------------- * * SPF Framework * * ----------------------------------------------------------- * */ ; (function ($, window, document, undefined) { 'use strict' // // Constants // var SP_PC = SP_PC || {} SP_PC.funcs = {} SP_PC.vars = { onloaded: false, $body: $('body'), $window: $(window), $document: $(document), is_rtl: $('body').hasClass('rtl'), code_themes: [] } // // Helper Functions // SP_PC.helper = { // // Generate UID // uid: function (prefix) { return ( (prefix || '') + Math.random() .toString(36) .substr(2, 9) ) }, // Quote regular expression characters // preg_quote: function (str) { return (str + '').replace(/(\[|\-|\])/g, '\\$1') }, // // Rename input names // name_nested_replace: function ($selector, field_id) { var checks = [] var regex = new RegExp( '(' + SP_PC.helper.preg_quote(field_id) + ')\\[(\\d+)\\]', 'g' ) $selector.find(':radio').each(function () { if (this.checked || this.orginal_checked) { this.orginal_checked = true } }) $selector.each(function (index) { $(this) .find(':input') .each(function () { this.name = this.name.replace(regex, field_id + '[' + index + ']') if (this.orginal_checked) { this.checked = true } }) }) }, // // Debounce // debounce: function (callback, threshold, immediate) { var timeout return function () { var context = this, args = arguments var later = function () { timeout = null if (!immediate) { callback.apply(context, args) } } var callNow = immediate && !timeout clearTimeout(timeout) timeout = setTimeout(later, threshold) if (callNow) { callback.apply(context, args) } } }, // // Get a cookie // get_cookie: function (name) { var e, b, cookie = document.cookie, p = name + '=' if (!cookie) { return } b = cookie.indexOf('; ' + p) if (b === -1) { b = cookie.indexOf(p) if (b !== 0) { return null } } else { b += 2 } e = cookie.indexOf(';', b) if (e === -1) { e = cookie.length } return decodeURIComponent(cookie.substring(b + p.length, e)) }, // // Set a cookie // set_cookie: function (name, value, expires, path, domain, secure) { var d = new Date() if (typeof expires === 'object' && expires.toGMTString) { expires = expires.toGMTString() } else if (parseInt(expires, 10)) { d.setTime(d.getTime() + parseInt(expires, 10) * 1000) expires = d.toGMTString() } else { expires = '' } document.cookie = name + '=' + encodeURIComponent(value) + (expires ? '; expires=' + expires : '') + (path ? '; path=' + path : '') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : '') }, // // Remove a cookie // remove_cookie: function (name, path, domain, secure) { SP_PC.helper.set_cookie(name, '', -1000, path, domain, secure) } } // // Custom clone for textarea and select clone() bug // $.fn.spf_clone = function () { var base = $.fn.clone.apply(this, arguments), clone = this.find('select').add(this.filter('select')), cloned = base.find('select').add(base.filter('select')) for (var i = 0; i < clone.length; ++i) { for (var j = 0; j < clone[i].options.length; ++j) { if (clone[i].options[j].selected === true) { cloned[i].options[j].selected = true } } } this.find(':radio').each(function () { this.orginal_checked = this.checked }) return base } // // Expand All Options // $.fn.spf_expand_all = function () { return this.each(function () { $(this).on('click', function (e) { e.preventDefault() $('.spf-wrapper').toggleClass('spf-show-all') $('.spf-section').spf_reload_script() $(this) .find('.fa') .toggleClass('fa-indent') .toggleClass('fa-outdent') }) }) } // // Options Navigation // $.fn.spf_nav_options = function () { return this.each(function () { var $nav = $(this), $links = $nav.find('a'), $hidden = $nav.closest('.spf').find('.spf-section-id'), $last_section $(window) .on('hashchange', function () { var hash = window.location.hash.match(new RegExp('tab=([^&]*)')) var slug = hash ? hash[1] : $links .first() .attr('href') .replace('#tab=', '') var $link = $('#spf-tab-link-' + slug) if ($link.length > 0) { $link .closest('.spf-tab-depth-0') .addClass('spf-tab-active') .siblings() .removeClass('spf-tab-active') $links.removeClass('spf-section-active') $link.addClass('spf-section-active') if ($last_section !== undefined) { $last_section.hide() } var $section = $('#spf-section-' + slug) $section.css({ display: 'block' }) $section.spf_reload_script() $hidden.val(slug) $last_section = $section } }) .trigger('hashchange') }) } // // Metabox Tabs // $.fn.spf_nav_metabox = function () { return this.each(function () { var $nav = $(this), $links = $nav.find('a'), unique_id = $nav.data('unique'), post_id = $('#post_ID').val() || 'global', $last_section, $last_link $links.on('click', function (e) { e.preventDefault() var $link = $(this), section_id = $link.data('section') if ($last_link !== undefined) { $last_link.removeClass('spf-section-active') } if ($last_section !== undefined) { $last_section.hide() } $link.addClass('spf-section-active') var $section = $('#spf-section-' + section_id) $section.css({ display: 'block' }) $section.spf_reload_script() SP_PC.helper.set_cookie( 'spf-last-metabox-tab-' + post_id + '-' + unique_id, section_id ) $last_section = $section $last_link = $link }) var get_cookie = SP_PC.helper.get_cookie( 'spf-last-metabox-tab-' + post_id + '-' + unique_id ) if (get_cookie) { $nav.find('a[data-section="' + get_cookie + '"]').trigger('click') } else { $links.first('a').trigger('click') } }) } // // Metabox Page Templates Listener // $.fn.spf_page_templates = function () { if (this.length) { $(document).on( 'change', '.editor-page-attributes__template select, #page_template', function () { var maybe_value = $(this).val() || 'default' $('.spf-page-templates') .removeClass('spf-show') .addClass('spf-hide') $( '.spf-page-' + maybe_value.toLowerCase().replace(/[^a-zA-Z0-9]+/g, '-') ) .removeClass('spf-hide') .addClass('spf-show') } ) } } // // Metabox Post Formats Listener // $.fn.spf_post_formats = function () { if (this.length) { $(document).on( 'change', '.editor-post-format select, #formatdiv input[name="post_format"]', function () { var maybe_value = $(this).val() || 'default' // Fallback for classic editor version maybe_value = maybe_value === '0' ? 'default' : maybe_value $('.spf-post-formats') .removeClass('spf-show') .addClass('spf-hide') $('.spf-post-format-' + maybe_value) .removeClass('spf-hide') .addClass('spf-show') } ) } } // // Search // $.fn.spf_search = function () { return this.each(function () { var $this = $(this), $input = $this.find('input') $input.on('change keyup', function () { var value = $(this).val(), $wrapper = $('.spf-wrapper'), $section = $wrapper.find('.spf-section'), $fields = $section.find('> .spf-field:not(.hidden)'), $titles = $fields.find('> .spf-title, .spf-search-tags') if (value.length > 3) { $fields.addClass('spf-hidden') $wrapper.addClass('spf-search-all') $titles.each(function () { var $title = $(this) if ($title.text().match(new RegExp('.*?' + value + '.*?', 'i'))) { var $field = $title.closest('.spf-field') $field.removeClass('spf-hidden') $field.parent().spf_reload_script() } }) } else { $fields.removeClass('spf-hidden') $wrapper.removeClass('spf-search-all') } }) }) } // // Sticky Header // $.fn.spf_sticky = function () { return this.each(function () { var $this = $(this), $window = $(window), $inner = $this.find('.spf-header-inner'), padding = parseInt($inner.css('padding-left')) + parseInt($inner.css('padding-right')), offset = 32, scrollTop = 0, lastTop = 0, ticking = false, stickyUpdate = function () { var offsetTop = $this.offset().top, stickyTop = Math.max(offset, offsetTop - scrollTop), winWidth = Math.max( document.documentElement.clientWidth, window.innerWidth || 0 ) if (stickyTop <= offset && winWidth > 782) { $inner.css({ width: $this.outerWidth() - padding }) $this.css({ height: $this.outerHeight() }).addClass('spf-sticky') } else { $inner.removeAttr('style') $this.removeAttr('style').removeClass('spf-sticky') } }, requestTick = function () { if (!ticking) { requestAnimationFrame(function () { stickyUpdate() ticking = false }) } ticking = true }, onSticky = function () { scrollTop = $window.scrollTop() requestTick() } $window.on('scroll resize', onSticky) onSticky() }) } // // Dependency System // $.fn.spf_dependency = function () { return this.each(function () { var $this = $(this), ruleset = $.spf_deps.createRuleset(), depends = [], is_global = false $this.children('[data-controller]').each(function () { var $field = $(this), controllers = $field.data('controller').split('|'), conditions = $field.data('condition').split('|'), values = $field .data('value') .toString() .split('|'), rules = ruleset if ($field.data('depend-global')) { is_global = true } $.each(controllers, function (index, depend_id) { var value = values[index] || '', condition = conditions[index] || conditions[0] rules = rules.createRule( '[data-depend-id="' + depend_id + '"]', condition, value ) rules.include($field) depends.push(depend_id) }) }) if (depends.length) { if (is_global) { $.spf_deps.enable(SP_PC.vars.$body, ruleset, depends) } else { $.spf_deps.enable($this, ruleset, depends) } } }) } // // Field: accordion // $.fn.spf_field_accordion = function () { return this.each(function () { // Keep the accordion open by default. var $titles = $(this).find('.spf-accordion-title') //$titles.on('load', function() { //var $title_area = $(this), // var $content_area = $titles.next(); //$content_area.addClass('spf-accordion-open'); // if (!$content_area.data('opened')) { // $content_area.spf_reload_script(); // $content_area.data('opened', true); // } // $content_area.addClass('spf-accordion-open'); //}); $titles.on('click', function () { var $title = $(this), $icon = $title.find('.spf-accordion-icon'), $content = $title.next() if ($icon.hasClass('fa-angle-right')) { $icon.removeClass('fa-angle-right').addClass('fa-angle-down'); $title.toggleClass('expanded') } else { $icon.removeClass('fa-angle-down').addClass('fa-angle-right'); $title.toggleClass('expanded') } if (!$content.data('opened')) { $content.spf_reload_script() $content.data('opened', true) } $content.toggleClass('spf-accordion-open') }) /* var $sortable = $(this).find('.spf-accordion-items'); $sortable.sortable({ axis: 'y', helper: 'original', cursor: 'move', placeholder: 'widget-placeholder', update: function( event, ui ) { $sortable.spf_customizer_refresh(); } }); $sortable.find('.spf-accordion-content').spf_reload_script();*/ }) } // // Field: sortable // $.fn.spf_field_sortable = function () { return this.each(function () { var $sortable = $(this).find('.spf--sortable') // Post content sort only with handle if ($(this).hasClass('post_content_sorter')) { $sortable.sortable({ axis: 'y', helper: 'original', handle: '.spf--sortable-helper', cursor: 'move', placeholder: 'widget-placeholder', items: '.spf--sortable-item:not(:nth-child(5),:nth-child(6))' // cancel: '.spf--sortable-item:nth-child(5),.spf--sortable-item:nth-child(5)' // ⛔ disable last item // update: function( event, ui ) { // $sortable.spf_customizer_refresh(); // } }) } else { $sortable.sortable({ axis: 'y', helper: 'original', cursor: 'move', placeholder: 'widget-placeholder', items: '.spf--sortable-item:not(:nth-child(5),:nth-child(6))' // update: function( event, ui ) { // $sortable.spf_customizer_refresh(); // } }) } $sortable.find('.spf--sortable-content').spf_reload_script() }) } // // Field: code_editor - Using WP Code Editor. // $.fn.spf_field_code_editor = function () { return this.each(function () { if (typeof wp === 'undefined' || typeof wp.codeEditor === 'undefined') { return; } var $this = $(this), $textarea = $this.find('textarea'), settings = $textarea.data('editor') || {}; // Merge with WP defaults var editorSettings = wp.codeEditor.defaultSettings ? _.clone(wp.codeEditor.defaultSettings) : {}; editorSettings.codemirror = _.extend( {}, editorSettings.codemirror, settings ); // Initialize editor var editor = wp.codeEditor.initialize($textarea[0], editorSettings); //editor.codemirror.setOption('theme', 'monokai'); // Sync changes back to textarea editor.codemirror.on('change', function () { $textarea.val(editor.codemirror.getValue()).trigger('change'); }); }); }; // // Field: tabbed // $.fn.spf_field_tabbed = function () { return this.each(function () { var $this = $(this), $links = $this.find('.spf-tabbed-nav a'), $sections = $this.find('.spf-tabbed-section'); $links.on('click', function (e) { e.preventDefault(); var $link = $(this), index = $link.index(), $section = $sections.eq(index); // Store the active tab index in a cookie SP_PC.helper.set_cookie('activeTabIndex', index); $link.addClass('spf-tabbed-active').siblings().removeClass('spf-tabbed-active'); $section.spf_reload_script(); $section.removeClass('hidden').siblings().addClass('hidden'); }); // Check if there's a stored active tab index in the cookie var activeTabIndex = SP_PC.helper.get_cookie('activeTabIndex'); // Check if the cookie exists if (activeTabIndex !== null) { $links.eq(activeTabIndex).trigger('click'); } else { $links.first().trigger('click'); } }); }; // // Field: fieldset // $.fn.spf_field_fieldset = function () { return this.each(function () { $(this) .find('.spf-fieldset-content') .spf_reload_script() }) } // // Field: group // $.fn.spf_field_group = function () { return this.each(function () { var $this = $(this), $fieldset = $this.children('.spf-fieldset'), $group = $fieldset.length ? $fieldset : $this, $wrapper = $group.children('.spf-cloneable-wrapper'), $hidden = $group.children('.spf-cloneable-hidden'), $max = $group.children('.spf-cloneable-max'), $min = $group.children('.spf-cloneable-min'), field_id = $wrapper.data('field-id'), unique_id = $wrapper.data('unique-id'), is_number = Boolean(Number($wrapper.data('title-number'))), max = parseInt($wrapper.data('max')), min = parseInt($wrapper.data('min')) // clear accordion arrows if multi-instance if ($wrapper.hasClass('ui-accordion')) { $wrapper.find('.ui-accordion-header-icon').remove() } var update_title_numbers = function ($selector) { $selector.find('.spf-cloneable-title-number').each(function (index) { $(this).html( $(this) .closest('.spf-cloneable-item') .index() + 1 + '.' ) }) } // Hide the taxonomy relation field. -- Shamim var $pcp_group_parent = $this.parent() var pcp_hide_the_taxonomy_relation = function (count_tax) { if (count_tax < 2) { $($pcp_group_parent) .find('.pcp_relate_among_taxonomies') .hide() } else { $($pcp_group_parent) .find('.pcp_relate_among_taxonomies') .show() } } var count = $wrapper.children('.spf-cloneable-item').length pcp_hide_the_taxonomy_relation(count) $wrapper.accordion({ header: '> .spf-cloneable-item > .spf-cloneable-title', collapsible: true, active: false, animate: false, heightStyle: 'content', icons: { header: 'spf-cloneable-header-icon', activeHeader: 'spf-cloneable-header-icon' }, activate: function (event, ui) { var $panel = ui.newPanel var $header = ui.newHeader if ($panel.length && !$panel.data('opened')) { var $fields = $panel.children() var $first = $fields.first().find('select').first() var $title = $header.find('.spf-cloneable-value') var $title_value = $first.children("option").filter(":selected").text(); if ($title_value == 'Select Taxonomy') { $title_value = 'Taxonomy'; } $title.text($title_value); $first.on('change', function (event) { $title.text($first.val()); if ($title.text($first.val())) { $title.text($first.children("option").filter(":selected").text()); } }); $panel.spf_reload_script() $panel.data('opened', true) $panel.data('retry', false) } else if ($panel.data('retry')) { $panel.spf_reload_script_retry() $panel.data('retry', false) } } }) $wrapper.sortable({ axis: 'y', handle: '.spf-cloneable-title,.spf-cloneable-sort', helper: 'original', cursor: 'move', placeholder: 'widget-placeholder', start: function (event, ui) { $wrapper.accordion({ active: false }) $wrapper.sortable('refreshPositions') ui.item.children('.spf-cloneable-content').data('retry', true) }, update: function (event, ui) { SP_PC.helper.name_nested_replace( $wrapper.children('.spf-cloneable-item'), field_id ) //$wrapper.spf_customizer_refresh(); if (is_number) { update_title_numbers($wrapper) } } }) $group.children('.spf-cloneable-add').on('click', function (e) { e.preventDefault() var count = $wrapper.children('.spf-cloneable-item').length $min.hide() if (max && count + 1 > max) { $max.show() return } var new_field_id = unique_id + field_id + '[' + count + ']' var $cloned_item = $hidden.spf_clone(true) $cloned_item.removeClass('spf-cloneable-hidden') // $cloned_item.find(':input').each( function() { // this.name = new_field_id + this.name.replace( ( this.name.startsWith('_nonce') ? '_nonce' : unique_id ), ''); // }); $cloned_item.find(':input[name!="_pseudo"]').each(function () { this.name = new_field_id + this.name.replace( this.name.startsWith('_nonce') ? '_nonce' : unique_id, '' ) }) $cloned_item.find('.spf-data-wrapper').each(function () { $(this).attr('data-unique-id', new_field_id) }) $wrapper.append($cloned_item) $wrapper.accordion('refresh') $wrapper.accordion({ active: count }) // $wrapper.spf_customizer_refresh(); // $wrapper.spf_customizer_listen({closest: true}); if (is_number) { update_title_numbers($wrapper) } pcp_hide_the_taxonomy_relation(count + 1) }) var event_clone = function (e) { e.preventDefault() var count = $wrapper.children('.spf-cloneable-item').length $min.hide() if (max && count + 1 > max) { $max.show() return } var $this = $(this), $parent = $this.parent().parent(), $cloned_helper = $parent .children('.spf-cloneable-helper') .spf_clone(true), $cloned_title = $parent.children('.spf-cloneable-title').spf_clone(), $cloned_content = $parent .children('.spf-cloneable-content') .spf_clone(), cloned_regex = new RegExp( '(' + SP_PC.helper.preg_quote(field_id) + ')\\[(\\d+)\\]', 'g' ) $cloned_content.find('.spf-data-wrapper').each(function () { var $this = $(this) $this.attr( 'data-unique-id', $this .attr('data-unique-id') .replace( cloned_regex, field_id + '[' + ($parent.index() + 1) + ']' ) ) }) var $cloned = $('
') $cloned.append($cloned_helper) $cloned.append($cloned_title) $cloned.append($cloned_content) $wrapper .children() .eq($parent.index()) .after($cloned) SP_PC.helper.name_nested_replace( $wrapper.children('.spf-cloneable-item'), field_id ) $wrapper.accordion('refresh') // $wrapper.spf_customizer_refresh(); // $wrapper.spf_customizer_listen({closest: true}); if (is_number) { update_title_numbers($wrapper) } pcp_hide_the_taxonomy_relation(count + 1) } $wrapper .children('.spf-cloneable-item') .children('.spf-cloneable-helper') .on('click', '.spf-cloneable-clone', event_clone) $group .children('.spf-cloneable-hidden') .children('.spf-cloneable-helper') .on('click', '.spf-cloneable-clone', event_clone) var event_remove = function (e) { e.preventDefault() var count = $wrapper.children('.spf-cloneable-item').length $max.hide() $min.hide() if (min && count - 1 < min) { $min.show() return } $(this) .closest('.spf-cloneable-item') .remove() SP_PC.helper.name_nested_replace( $wrapper.children('.spf-cloneable-item'), field_id ) //$wrapper.spf_customizer_refresh(); if (is_number) { update_title_numbers($wrapper) } pcp_hide_the_taxonomy_relation(count - 1) } $wrapper .children('.spf-cloneable-item') .children('.spf-cloneable-helper') .on('click', '.spf-cloneable-remove', event_remove) $group .children('.spf-cloneable-hidden') .children('.spf-cloneable-helper') .on('click', '.spf-cloneable-remove', event_remove) }) } // // Field: icon // $.fn.spf_field_icon = function () { return this.each(function () { var $this = $(this) $this.on('click', '.spf-icon-add', function (e) { e.preventDefault() var $button = $(this) var $modal = $('#spf-modal-icon') $modal.show() SP_PC.vars.$icon_target = $this if (!SP_PC.vars.icon_modal_loaded) { $modal.find('.spf-modal-loading').show() // window.wp.ajax.post( 'spf-get-icons', { nonce: $button.data('nonce') } ).done( function( response ) { window.wp.ajax .post('spf-get-icons', { nonce: $button.data('nonce') }) .done(function (response) { $modal.find('.spf-modal-loading').hide() SP_PC.vars.icon_modal_loaded = true var $load = $modal.find('.spf-modal-load').html(response.content) $load.on('click', 'a', function (e) { e.preventDefault() var icon = $(this).data('spf-icon') SP_PC.vars.$icon_target .find('i') .removeAttr('class') .addClass(icon) SP_PC.vars.$icon_target .find('input') .val(icon) .trigger('change') SP_PC.vars.$icon_target .find('.spf-icon-preview') .removeClass('hidden') SP_PC.vars.$icon_target .find('.spf-icon-remove') .removeClass('hidden') $modal.hide() }) $modal.on('change keyup', '.spf-icon-search', function () { var value = $(this).val(), $icons = $load.find('a') $icons.each(function () { var $elem = $(this) if ( $elem.data('spf-icon').search(new RegExp(value, 'i')) < 0 ) { $elem.hide() } else { $elem.show() } }) }) $modal.on( 'click', '.spf-modal-close, .spf-modal-overlay', function () { $modal.hide() } ) }) .fail(function (response) { $modal.find('.spf-modal-loading').hide() $modal.find('.spf-modal-load').html(response.error) $modal.on('click', function () { $modal.hide() }) }) } }) $this.on('click', '.spf-icon-remove', function (e) { e.preventDefault() $this.find('.spf-icon-preview').addClass('hidden') $this .find('input') .val('') .trigger('change') $(this).addClass('hidden') }) }) } // // Field: slider // $.fn.spf_field_slider = function () { return this.each(function () { var $this = $(this), $input = $this.find('input'), $slider = $this.find('.spf-slider-ui'), data = $input.data(), value = $input.val() || 0 if ($slider.hasClass('ui-slider')) { $slider.empty() } $slider.slider({ range: 'min', value: value, min: data.min, max: data.max, step: data.step, slide: function (e, o) { $input.val(o.value).trigger('change') } }) $input.keyup(function () { $slider.slider('value', $input.val()) }) }) } // // Field: c // $.fn.spf_field_sorter = function () { return this.each(function () { var $this = $(this), $enabled = $this.find('.spf-enabled'), $has_disabled = $this.find('.spf-disabled'), $disabled = $has_disabled.length ? $has_disabled : false $enabled.sortable({ connectWith: $disabled, placeholder: 'ui-sortable-placeholder', update: function (event, ui) { var $el = ui.item.find('input') if (ui.item.parent().hasClass('spf-enabled')) { $el.attr('name', $el.attr('name').replace('disabled', 'enabled')) } else { $el.attr('name', $el.attr('name').replace('enabled', 'disabled')) } // $this.spf_customizer_refresh(); } }) if ($disabled) { $disabled.sortable({ connectWith: $enabled, placeholder: 'ui-sortable-placeholder' // update: function( event, ui ) { // $this.spf_customizer_refresh(); // } }) } }) } // // Field: spinner // $.fn.spf_field_spinner = function () { return this.each(function () { var $this = $(this), $input = $this.find('input'), $inited = $this.find('.ui-spinner-button'), $unit = $input.data('unit') if ($inited.length) { $inited.remove() } $input.spinner({ max: $input.data('max') || 100, min: $input.data('min') || 0, step: $input.data('step') || 1, create: function (event, ui) { if ($unit.length) { $this .find('.ui-spinner-up') .after( '' ) } }, spin: function (event, ui) { $input.val(ui.value).trigger('change') } }) }) } // // Field: switcher // $.fn.spf_field_switcher = function () { return this.each(function () { var $switcher = $(this).find('.spf--switcher') $switcher.on('click', function () { var value = 0 var $input = $switcher.find('input') if ($switcher.hasClass('spf--active')) { $switcher.removeClass('spf--active') } else { value = 1 $switcher.addClass('spf--active') } $input.val(value).trigger('change') }) }) } // // Confirm // $.fn.spf_confirm = function () { return this.each(function () { $(this).on('click', function (e) { var confirm_text = $(this).data('confirm') || window.spf_vars.i18n.confirm var confirm_answer = confirm(confirm_text) SP_PC.vars.is_confirm = true if (!confirm_answer) { e.preventDefault() SP_PC.vars.is_confirm = false return false } }) }) } $.fn.serializeObject = function () { var obj = {} $.each(this.serializeArray(), function (i, o) { var n = o.name, v = o.value obj[n] = obj[n] === undefined ? v : $.isArray(obj[n]) ? obj[n].concat(v) : [obj[n], v] }) return obj } // // Options Save // $.fn.spf_save = function () { return this.each(function () { var $this = $(this), $buttons = $('.spf-save'), $panel = $('.spf-options'), flooding = false, timeout $this.on('click', function (e) { if (!flooding) { var $text = $this.data('save'), $value = $this.val() $buttons.attr('value', $text) if ($this.hasClass('spf-save-ajax')) { e.preventDefault() $panel.addClass('spf-saving') $buttons.prop('disabled', true) window.wp.ajax .post('spf_' + $panel.data('unique') + '_ajax_save', { data: $('#spf-form').serializeJSONSP_PC(), nonce: $('#spf_options_nonce' + $panel.data('unique')).val(), }) .done(function (response) { clearTimeout(timeout) var $result_success = $('.spf-form-success') $result_success .empty() .append(response.notice) .slideDown('fast', function () { timeout = setTimeout(function () { $result_success.slideUp('fast') }, 2000) }) // clear errors $('.spf-error').remove() var $append_errors = $('.spf-form-error') $append_errors.empty().hide() if (Object.keys(response.errors).length) { var error_icon = '!' $.each(response.errors, function (key, error_message) { var $field = $('[data-depend-id="' + key + '"]'), $link = $( '#spf-tab-link-' + ($field.closest('.spf-section').index() + 1) ), $tab = $link.closest('.spf-tab-depth-0') $field .closest('.spf-fieldset') .append( '' + error_message + '
' ) if (!$link.find('.spf-error').length) { $link.append(error_icon) } if (!$tab.find('.spf-arrow .spf-error').length) { $tab.find('.spf-arrow').append(error_icon) } console.log(error_message) $append_errors.append( '