Plugin Directory

Changeset 2712509


Ignore:
Timestamp:
04/21/2022 05:28:25 AM (4 years ago)
Author:
shapedplugin
Message:

2.2.5 version release.

Location:
team-free
Files:
318 added
8 edited

Legend:

Unmodified
Added
Removed
  • team-free/trunk/readme.txt

    r2692012 r2712509  
    44Tags: team, wp team, team members, team showcase, team members showcase, our team members, our team, best team member plugin, wordpress team showcase plugin, meet the team, our stuff, responsive team plugin,  wordpress team, team carousel, team slider,  team grid, team list, team mosaic, team inline, team member filter, staff, workers, team profile, staff showcase, crew, squad, employees, modal, hexagonal grid, thumbnail pager, gallery, team gallery, people, company, organization
    55Requires at least: 4.3
    6 Tested up to: 5.9
    7 Stable tag: 2.2.4
     6Tested up to: 5.9.3
     7Stable tag: 2.2.5
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    279279== Changelog ==
    280280
     281= 2.2.5 - Apr 21, 2022 =
     282* Improved: The export-import functionality.
     283* Fix: Elementor addon deprecated warnings.
     284
    281285= 2.2.4 - Mar 10, 2022 =
    282286* New: Filter hook 'sp_wp_team_ui_permission' added for User role permission.
  • team-free/trunk/src/Admin/Framework/assets/js/main.js

    r2692012 r2712509  
    11; (function ($, window, document, undefined) {
    2   'use strict'
    3 
    4   //
    5   // Constants
    6   //
    7   var SPF = SPF || {}
    8 
    9   SPF.funcs = {}
    10 
    11   SPF.vars = {
    12     onloaded: false,
    13     $body: $('body'),
    14     $window: $(window),
    15     $document: $(document),
    16     $form_warning: null,
    17     is_confirm: false,
    18     form_modified: false,
    19     code_themes: [],
    20     is_rtl: $('body').hasClass('rtl')
    21   }
    22 
    23   //
    24   // Helper Functions
    25   //
    26   SPF.helper = {
    27     //
    28     // Generate UID
    29     //
    30     uid: function (prefix) {
    31       return (
    32         (prefix || '') +
    33         Math.random()
    34           .toString(36)
    35           .substr(2, 9)
    36       )
    37     },
    38 
    39     // Quote regular expression characters
    40     //
    41     preg_quote: function (str) {
    42       return (str + '').replace(/(\[|\])/g, '\\$1')
    43     },
    44 
    45     //
    46     // Rename input names
    47 
    48     //
    49     name_nested_replace: function ($selector, field_id) {
    50       var checks = []
    51       var regex = new RegExp(SPF.helper.preg_quote(field_id + '[\\d+]'), 'g')
    52 
    53       $selector.find(':radio').each(function () {
    54         if (this.checked || this.original_checked) {
    55           this.original_checked = true
    56         }
    57       })
    58 
    59       $selector.each(function (index) {
    60         $(this)
    61           .find(':input')
    62           .each(function () {
    63             this.name = this.name.replace(regex, field_id + '[' + index + ']')
    64             if (this.original_checked) {
    65               this.checked = true
    66             }
    67           })
    68       })
    69     },
    70 
    71     //
    72     // Debounce
    73     //
    74     debounce: function (callback, threshold, immediate) {
    75       var timeout
    76       return function () {
    77         var context = this,
    78           args = arguments
    79         var later = function () {
    80           timeout = null
    81           if (!immediate) {
    82             callback.apply(context, args)
    83           }
    84         }
    85         var callNow = immediate && !timeout
    86         clearTimeout(timeout)
    87         timeout = setTimeout(later, threshold)
    88         if (callNow) {
    89           callback.apply(context, args)
    90         }
    91       }
    92     },
    93 
    94     //
    95     // Get a cookie
    96     //
    97     get_cookie: function (name) {
    98       var e,
    99         b,
    100         cookie = document.cookie,
    101         p = name + '='
    102 
    103       if (!cookie) {
    104         return
    105       }
    106 
    107       b = cookie.indexOf('; ' + p)
    108 
    109       if (b === -1) {
    110         b = cookie.indexOf(p)
    111 
    112         if (b !== 0) {
    113           return null
    114         }
    115       } else {
    116         b += 2
    117       }
    118 
    119       e = cookie.indexOf(';', b)
    120 
    121       if (e === -1) {
    122         e = cookie.length
    123       }
    124 
    125       return decodeURIComponent(cookie.substring(b + p.length, e))
    126     },
    127 
    128     //
    129     // Set a cookie
    130     //
    131     set_cookie: function (name, value, expires, path, domain, secure) {
    132       var d = new Date()
    133 
    134       if (typeof expires === 'object' && expires.toGMTString) {
    135         expires = expires.toGMTString()
    136       } else if (parseInt(expires, 10)) {
    137         d.setTime(d.getTime() + parseInt(expires, 10) * 1000)
    138         expires = d.toGMTString()
    139       } else {
    140         expires = ''
    141       }
    142 
    143       document.cookie =
    144         name +
    145         '=' +
    146         encodeURIComponent(value) +
    147         (expires ? '; expires=' + expires : '') +
    148         (path ? '; path=' + path : '') +
    149         (domain ? '; domain=' + domain : '') +
    150         (secure ? '; secure' : '')
    151     },
    152 
    153     //
    154     // Remove a cookie
    155     //
    156     remove_cookie: function (name, path, domain, secure) {
    157       SPF.helper.set_cookie(name, '', -1000, path, domain, secure)
    158     }
    159   }
    160 
    161   //
    162   // Custom clone for textarea and select clone() bug
    163   //
    164   $.fn.spf_clone = function () {
    165     var base = $.fn.clone.apply(this, arguments),
    166       clone = this.find('select').add(this.filter('select')),
    167       cloned = base.find('select').add(base.filter('select'))
    168 
    169     for (var i = 0; i < clone.length; ++i) {
    170       for (var j = 0; j < clone[i].options.length; ++j) {
    171         if (clone[i].options[j].selected === true) {
    172           cloned[i].options[j].selected = true
    173         }
    174       }
    175     }
    176 
    177     this.find(':radio').each(function () {
    178       this.original_checked = this.checked
    179     })
    180 
    181     return base
    182   }
    183 
    184   //
    185   // Expand All Options
    186   //
    187   $.fn.spf_expand_all = function () {
    188     return this.each(function () {
    189       $(this).on('click', function (e) {
    190         e.preventDefault()
    191         $('.spf-wrapper').toggleClass('spf-show-all')
    192         $('.spf-section').spf_reload_script()
    193         $(this)
    194           .find('.fa')
    195           .toggleClass('fa-indent')
    196           .toggleClass('fa-outdent')
    197       })
    198     })
    199   }
    200 
    201   //
    202   // Options Navigation
    203   //
    204   $.fn.spf_nav_options = function () {
    205     return this.each(function () {
    206       var $nav = $(this),
    207         $links = $nav.find('a'),
    208         $last
    209 
    210       $(window)
    211         .on('hashchange spf.hashchange', function () {
    212           var hash = window.location.hash.replace('#tab=', '')
    213           var slug = hash
    214             ? hash
    215             : $links
    216               .first()
    217               .attr('href')
    218               .replace('#tab=', '')
    219           var $link = $('[data-tab-id="' + slug + '"]')
    220 
    221           if ($link.length) {
    222             $link
    223               .closest('.spf-tab-item')
    224               .addClass('spf-tab-expanded')
    225               .siblings()
    226               .removeClass('spf-tab-expanded')
    227 
    228             if ($link.next().is('ul')) {
    229               $link = $link
    230                 .next()
    231                 .find('li')
    232                 .first()
    233                 .find('a')
    234               slug = $link.data('tab-id')
    235             }
    236 
    237             $links.removeClass('spf-active')
    238             $link.addClass('spf-active')
    239 
    240             if ($last) {
    241               $last.addClass('hidden')
    242             }
    243 
    244             var $section = $('[data-section-id="' + slug + '"]')
    245 
    246             $section.removeClass('hidden')
    247             $section.spf_reload_script()
    248 
    249             $('.spf-section-id').val($section.index() + 1)
    250 
    251             $last = $section
    252           }
    253         })
    254         .trigger('spf.hashchange')
    255     })
    256   }
    257 
    258   //
    259   // Metabox Tabs
    260   //
    261   $.fn.spf_nav_metabox = function () {
    262     return this.each(function () {
    263       var $nav = $(this),
    264         $links = $nav.find('a'),
    265         unique_id = $nav.data('unique'),
    266         post_id = $('#post_ID').val() || 'global',
    267         $sections = $nav.parent().find('.spf-section'),
    268         $last
    269 
    270       $links.each(function (index) {
    271         $(this).on('click', function (e) {
    272           e.preventDefault()
    273 
    274           var $link = $(this)
    275           var section_id = $link.data('section')
    276 
    277           $links.removeClass('spf-active')
    278           $link.addClass('spf-active')
    279 
    280           if ($last !== undefined) {
    281             $last.addClass('hidden')
    282           }
    283 
    284           var $section = $sections.eq(index)
    285 
    286           $section.removeClass('hidden')
    287           $section.spf_reload_script()
    288 
    289           SPF.helper.set_cookie(
    290             'spf-last-metabox-tab-' + post_id + '-' + unique_id,
    291             section_id
    292           )
    293 
    294           $last = $section
    295         })
    296         var get_cookie = SPF.helper.get_cookie(
    297           'spf-last-metabox-tab-' + post_id + '-' + unique_id
    298         )
    299 
    300         if (get_cookie) {
    301           $nav.find('a[data-section="' + get_cookie + '"]').trigger('click')
    302         } else {
    303           $links.first('a').trigger('click')
    304         }
    305       })
    306 
    307       // $links.first().trigger('click')
    308     })
    309   }
    310 
    311   //
    312   // Metabox Page Templates Listener
    313   //
    314   $.fn.spf_page_templates = function () {
    315     if (this.length) {
    316       $(document).on(
    317         'change',
    318         '.editor-page-attributes__template select, #page_template',
    319         function () {
    320           var maybe_value = $(this).val() || 'default'
    321 
    322           $('.spf-page-templates')
    323             .removeClass('spf-metabox-show')
    324             .addClass('spf-metabox-hide')
    325           $(
    326             '.spf-page-' +
    327             maybe_value.toLowerCase().replace(/[^a-zA-Z0-9]+/g, '-')
    328           )
    329             .removeClass('spf-metabox-hide')
    330             .addClass('spf-metabox-show')
    331         }
    332       )
    333     }
    334   }
    335 
    336   //
    337   // Metabox Post Formats Listener
    338   //
    339   $.fn.spf_post_formats = function () {
    340     if (this.length) {
    341       $(document).on(
    342         'change',
    343         '.editor-post-format select, #formatdiv input[name="post_format"]',
    344         function () {
    345           var maybe_value = $(this).val() || 'default'
    346 
    347           // Fallback for classic editor version
    348           maybe_value = maybe_value === '0' ? 'default' : maybe_value
    349 
    350           $('.spf-post-formats')
    351             .removeClass('spf-metabox-show')
    352             .addClass('spf-metabox-hide')
    353           $('.spf-post-format-' + maybe_value)
    354             .removeClass('spf-metabox-hide')
    355             .addClass('spf-metabox-show')
    356         }
    357       )
    358     }
    359   }
    360 
    361   //
    362   // Search
    363   //
    364   $.fn.spf_search = function () {
    365     return this.each(function () {
    366       var $this = $(this),
    367         $input = $this.find('input')
    368 
    369       $input.on('change keyup', function () {
    370         var value = $(this).val(),
    371           $wrapper = $('.spf-wrapper'),
    372           $section = $wrapper.find('.spf-section'),
    373           $fields = $section.find('> .spf-field:not(.spf-depend-on)'),
    374           $titles = $fields.find('> .spf-title, .spf-search-tags')
    375 
    376         if (value.length > 3) {
    377           $fields.addClass('spf-metabox-hide')
    378           $wrapper.addClass('spf-search-all')
    379 
    380           $titles.each(function () {
    381             var $title = $(this)
    382 
    383             if ($title.text().match(new RegExp('.*?' + value + '.*?', 'i'))) {
    384               var $field = $title.closest('.spf-field')
    385 
    386               $field.removeClass('spf-metabox-hide')
    387               $field.parent().spf_reload_script()
    388             }
    389           })
    390         } else {
    391           $fields.removeClass('spf-metabox-hide')
    392           $wrapper.removeClass('spf-search-all')
    393         }
    394       })
    395     })
    396   }
    397 
    398   //
    399   // Sticky Header
    400   //
    401   $.fn.spf_sticky = function () {
    402     return this.each(function () {
    403       var $this = $(this),
    404         $window = $(window),
    405         $inner = $this.find('.spf-header-inner'),
    406         padding =
    407           parseInt($inner.css('padding-left')) +
    408           parseInt($inner.css('padding-right')),
    409         offset = 32,
    410         scrollTop = 0,
    411         lastTop = 0,
    412         ticking = false,
    413         stickyUpdate = function () {
    414           var offsetTop = $this.offset().top,
    415             stickyTop = Math.max(offset, offsetTop - scrollTop),
    416             winWidth = Math.max(
    417               document.documentElement.clientWidth,
    418               window.innerWidth || 0
    419             )
    420 
    421           if (stickyTop <= offset && winWidth > 782) {
    422             $inner.css({ width: $this.outerWidth() - padding })
    423             $this.css({ height: $this.outerHeight() }).addClass('spf-sticky')
    424           } else {
    425             $inner.removeAttr('style')
    426             $this.removeAttr('style').removeClass('spf-sticky')
    427           }
    428         },
    429         requestTick = function () {
    430           if (!ticking) {
    431             requestAnimationFrame(function () {
    432               stickyUpdate()
    433               ticking = false
    434             })
    435           }
    436 
    437           ticking = true
    438         },
    439         onSticky = function () {
    440           scrollTop = $window.scrollTop()
    441           requestTick()
    442         }
    443 
    444       $window.on('scroll resize', onSticky)
    445 
    446       onSticky()
    447     })
    448   }
    449 
    450   //
    451   // Dependency System
    452   //
    453   $.fn.spf_dependency = function () {
    454     return this.each(function () {
    455       var $this = $(this),
    456         $fields = $this.children('[data-controller]')
    457 
    458       if ($fields.length) {
    459         var normal_ruleset = $.spf_deps.createRuleset(),
    460           global_ruleset = $.spf_deps.createRuleset(),
    461           normal_depends = [],
    462           global_depends = []
    463 
    464         $fields.each(function () {
    465           var $field = $(this),
    466             controllers = $field.data('controller').split('|'),
    467             conditions = $field.data('condition').split('|'),
    468             values = $field
    469               .data('value')
    470               .toString()
    471               .split('|'),
    472             is_global = $field.data('depend-global') ? true : false,
    473             ruleset = is_global ? global_ruleset : normal_ruleset
    474 
    475           $.each(controllers, function (index, depend_id) {
    476             var value = values[index] || '',
    477               condition = conditions[index] || conditions[0]
    478 
    479             ruleset = ruleset.createRule(
    480               '[data-depend-id="' + depend_id + '"]',
    481               condition,
    482               value
    483             )
    484 
    485             ruleset.include($field)
    486 
    487             if (is_global) {
    488               global_depends.push(depend_id)
    489             } else {
    490               normal_depends.push(depend_id)
    491             }
    492           })
    493         })
    494 
    495         if (normal_depends.length) {
    496           $.spf_deps.enable($this, normal_ruleset, normal_depends)
    497         }
    498 
    499         if (global_depends.length) {
    500           $.spf_deps.enable(SPF.vars.$body, global_ruleset, global_depends)
    501         }
    502       }
    503     })
    504   }
    505 
    506   //
    507   // Field: code_editor
    508   //
    509   $.fn.spf_field_code_editor = function () {
    510     return this.each(function () {
    511       if (typeof CodeMirror !== 'function') {
    512         return
    513       }
    514 
    515       var $this = $(this),
    516         $textarea = $this.find('textarea'),
    517         $inited = $this.find('.CodeMirror'),
    518         data_editor = $textarea.data('editor')
    519 
    520       if ($inited.length) {
    521         $inited.remove()
    522       }
    523 
    524       var interval = setInterval(function () {
    525         if ($this.is(':visible')) {
    526           var code_editor = CodeMirror.fromTextArea($textarea[0], data_editor)
    527 
    528           // load code-mirror theme css.
    529           if (
    530             data_editor.theme !== 'default' &&
    531             SPF.vars.code_themes.indexOf(data_editor.theme) === -1
    532           ) {
    533             var $cssLink = $('<link>')
    534 
    535             $('#spf-codemirror-css').after($cssLink)
    536 
    537             $cssLink.attr({
    538               rel: 'stylesheet',
    539               id: 'spf-codemirror-' + data_editor.theme + '-css',
    540               href:
    541                 data_editor.cdnURL + '/theme/' + data_editor.theme + '.min.css',
    542               type: 'text/css',
    543               media: 'all'
    544             })
    545 
    546             SPF.vars.code_themes.push(data_editor.theme)
    547           }
    548 
    549           CodeMirror.modeURL = data_editor.cdnURL + '/mode/%N/%N.min.js'
    550           CodeMirror.autoLoadMode(code_editor, data_editor.mode)
    551 
    552           code_editor.on('change', function (editor, event) {
    553             $textarea.val(code_editor.getValue()).trigger('change')
    554           })
    555 
    556           clearInterval(interval)
    557         }
    558       })
    559     })
    560   }
    561 
    562   //
    563   // Field: fieldset
    564   //
    565   $.fn.spf_field_fieldset = function () {
    566     return this.each(function () {
    567       $(this)
    568         .find('.spf-fieldset-content')
    569         .spf_reload_script()
    570     })
    571   }
    572 
    573   //
    574   // Field: group
    575   //
    576   $.fn.spf_field_group = function () {
    577     return this.each(function () {
    578       var $this = $(this),
    579         $fieldset = $this.children('.spf-fieldset'),
    580         $group = $fieldset.length ? $fieldset : $this,
    581         $wrapper = $group.children('.spf-cloneable-wrapper'),
    582         $hidden = $group.children('.spf-cloneable-hidden'),
    583         $max = $group.children('.spf-cloneable-max'),
    584         $min = $group.children('.spf-cloneable-min'),
    585         field_id = $wrapper.data('field-id'),
    586         is_number = Boolean(Number($wrapper.data('title-number'))),
    587         max = parseInt($wrapper.data('max')),
    588         min = parseInt($wrapper.data('min'))
    589 
    590       // clear accordion arrows if multi-instance
    591       if ($wrapper.hasClass('ui-accordion')) {
    592         $wrapper.find('.ui-accordion-header-icon').remove()
    593       }
    594 
    595       var update_title_numbers = function ($selector) {
    596         $selector.find('.spf-cloneable-title-number').each(function (index) {
    597           $(this).html(
    598             $(this)
    599               .closest('.spf-cloneable-item')
    600               .index() +
    601             1 +
    602             '.'
    603           )
    604         })
    605       }
    606 
    607       $wrapper.accordion({
    608         header: '> .spf-cloneable-item > .spf-cloneable-title',
    609         collapsible: true,
    610         active: false,
    611         animate: false,
    612         heightStyle: 'content',
    613         icons: {
    614           header: 'spf-cloneable-header-icon fas fa-angle-right',
    615           activeHeader: 'spf-cloneable-header-icon fas fa-angle-down'
    616         },
    617         activate: function (event, ui) {
    618           var $panel = ui.newPanel
    619           var $header = ui.newHeader
    620 
    621           if ($panel.length && !$panel.data('opened')) {
    622             var $fields = $panel.children()
    623             var $first = $fields
    624               .first()
    625               .find(':input')
    626               .first()
    627             var $title = $header.find('.spf-cloneable-value')
    628 
    629             $first.on('change keyup', function (event) {
    630               $title.text($first.val())
    631             })
    632 
    633             $panel.spf_reload_script()
    634             $panel.data('opened', true)
    635             $panel.data('retry', false)
    636           } else if ($panel.data('retry')) {
    637             $panel.spf_reload_script_retry()
    638             $panel.data('retry', false)
    639           }
    640         }
    641       })
    642 
    643       $wrapper.sortable({
    644         axis: 'y',
    645         handle: '.spf-cloneable-title,.spf-cloneable-sort',
    646         helper: 'original',
    647         cursor: 'move',
    648         placeholder: 'widget-placeholder',
    649         start: function (event, ui) {
    650           $wrapper.accordion({ active: false })
    651           $wrapper.sortable('refreshPositions')
    652           ui.item.children('.spf-cloneable-content').data('retry', true)
    653         },
    654         update: function (event, ui) {
    655           SPF.helper.name_nested_replace(
    656             $wrapper.children('.spf-cloneable-item'),
    657             field_id
    658           )
    659           //  $wrapper.spf_customizer_refresh()
    660 
    661           if (is_number) {
    662             update_title_numbers($wrapper)
    663           }
    664         }
    665       })
    666 
    667       $group.children('.spf-cloneable-add').on('click', function (e) {
    668         e.preventDefault()
    669 
    670         var count = $wrapper.children('.spf-cloneable-item').length
    671 
    672         $min.hide()
    673 
    674         if (max && count + 1 > max) {
    675           $max.show()
    676           return
    677         }
    678 
    679         var $cloned_item = $hidden.spf_clone(true)
    680 
    681         $cloned_item.removeClass('spf-cloneable-hidden')
    682 
    683         $cloned_item.find(':input[name!="_pseudo"]').each(function () {
    684           this.name = this.name
    685             .replace('___', '')
    686             .replace(field_id + '[0]', field_id + '[' + count + ']')
    687         })
    688 
    689         $wrapper.append($cloned_item)
    690         $wrapper.accordion('refresh')
    691         $wrapper.accordion({ active: count })
    692         // $wrapper.spf_customizer_refresh()
    693         //  $wrapper.spf_customizer_listen({ closest: true })
    694 
    695         if (is_number) {
    696           update_title_numbers($wrapper)
    697         }
    698       })
    699 
    700       var event_clone = function (e) {
    701         e.preventDefault()
    702 
    703         var count = $wrapper.children('.spf-cloneable-item').length
    704 
    705         $min.hide()
    706 
    707         if (max && count + 1 > max) {
    708           $max.show()
    709           return
    710         }
    711 
    712         var $this = $(this),
    713           $parent = $this.parent().parent(),
    714           $cloned_helper = $parent
    715             .children('.spf-cloneable-helper')
    716             .spf_clone(true),
    717           $cloned_title = $parent.children('.spf-cloneable-title').spf_clone(),
    718           $cloned_content = $parent
    719             .children('.spf-cloneable-content')
    720             .spf_clone(),
    721           $cloned_item = $('<div class="spf-cloneable-item" />')
    722 
    723         $cloned_item.append($cloned_helper)
    724         $cloned_item.append($cloned_title)
    725         $cloned_item.append($cloned_content)
    726 
    727         $wrapper
    728           .children()
    729           .eq($parent.index())
    730           .after($cloned_item)
    731 
    732         SPF.helper.name_nested_replace(
    733           $wrapper.children('.spf-cloneable-item'),
    734           field_id
    735         )
    736 
    737         $wrapper.accordion('refresh')
    738         // $wrapper.spf_customizer_refresh()
    739         // $wrapper.spf_customizer_listen({ closest: true })
    740 
    741         if (is_number) {
    742           update_title_numbers($wrapper)
    743         }
    744       }
    745 
    746       $wrapper
    747         .children('.spf-cloneable-item')
    748         .children('.spf-cloneable-helper')
    749         .on('click', '.spf-cloneable-clone', event_clone)
    750       $group
    751         .children('.spf-cloneable-hidden')
    752         .children('.spf-cloneable-helper')
    753         .on('click', '.spf-cloneable-clone', event_clone)
    754 
    755       var event_remove = function (e) {
    756         e.preventDefault()
    757 
    758         var count = $wrapper.children('.spf-cloneable-item').length
    759 
    760         $max.hide()
    761         $min.hide()
    762 
    763         if (min && count - 1 < min) {
    764           $min.show()
    765           return
    766         }
    767 
    768         $(this)
    769           .closest('.spf-cloneable-item')
    770           .remove()
    771 
    772         SPF.helper.name_nested_replace(
    773           $wrapper.children('.spf-cloneable-item'),
    774           field_id
    775         )
    776 
    777         //$wrapper.spf_customizer_refresh()
    778 
    779         if (is_number) {
    780           update_title_numbers($wrapper)
    781         }
    782       }
    783 
    784       $wrapper
    785         .children('.spf-cloneable-item')
    786         .children('.spf-cloneable-helper')
    787         .on('click', '.spf-cloneable-remove', event_remove)
    788       $group
    789         .children('.spf-cloneable-hidden')
    790         .children('.spf-cloneable-helper')
    791         .on('click', '.spf-cloneable-remove', event_remove)
    792     })
    793   }
    794 
    795   //
    796   // Field: icon
    797   //
    798   $.fn.spf_field_icon = function () {
    799     return this.each(function () {
    800       var $this = $(this)
    801 
    802       $this.on('click', '.spf-icon-add', function (e) {
    803         e.preventDefault()
    804 
    805         var $button = $(this)
    806         var $modal = $('#spf-modal-icon')
    807 
    808         $modal.removeClass('hidden')
    809 
    810         SPF.vars.$icon_target = $this
    811 
    812         if (!SPF.vars.icon_modal_loaded) {
    813           $modal.find('.spf-modal-loading').show()
    814 
    815           window.wp.ajax
    816             .post('spf-get-icons', {
    817               nonce: $button.data('nonce')
    818             })
    819             .done(function (response) {
    820               $modal.find('.spf-modal-loading').hide()
    821 
    822               SPF.vars.icon_modal_loaded = true
    823 
    824               var $load = $modal.find('.spf-modal-load').html(response.content)
    825 
    826               $load.on('click', 'i', function (e) {
    827                 e.preventDefault()
    828 
    829                 var icon = $(this).attr('title')
    830 
    831                 SPF.vars.$icon_target
    832                   .find('.spf-icon-preview i')
    833                   .removeAttr('class')
    834                   .addClass(icon)
    835                 SPF.vars.$icon_target
    836                   .find('.spf-icon-preview')
    837                   .removeClass('hidden')
    838                 SPF.vars.$icon_target
    839                   .find('.spf-icon-remove')
    840                   .removeClass('hidden')
    841                 SPF.vars.$icon_target
    842                   .find('input')
    843                   .val(icon)
    844                   .trigger('change')
    845 
    846                 $modal.addClass('hidden')
    847               })
    848 
    849               $modal.on('change keyup', '.spf-icon-search', function () {
    850                 var value = $(this).val(),
    851                   $icons = $load.find('i')
    852 
    853                 $icons.each(function () {
    854                   var $elem = $(this)
    855 
    856                   if ($elem.attr('title').search(new RegExp(value, 'i')) < 0) {
    857                     $elem.hide()
    858                   } else {
    859                     $elem.show()
    860                   }
    861                 })
    862               })
    863 
    864               $modal.on(
    865                 'click',
    866                 '.spf-modal-close, .spf-modal-overlay',
    867                 function () {
    868                   $modal.addClass('hidden')
    869                 }
    870               )
    871             })
    872             .fail(function (response) {
    873               $modal.find('.spf-modal-loading').hide()
    874               $modal.find('.spf-modal-load').html(response.error)
    875               $modal.on('click', function () {
    876                 $modal.addClass('hidden')
    877               })
    878             })
    879         }
    880       })
    881 
    882       $this.on('click', '.spf-icon-remove', function (e) {
    883         e.preventDefault()
    884         $this.find('.spf-icon-preview').addClass('hidden')
    885         $this
    886           .find('input')
    887           .val('')
    888           .trigger('change')
    889         $(this).addClass('hidden')
    890       })
    891     })
    892   }
    893 
    894   //
    895   // Field: repeater
    896   //
    897   $.fn.spf_field_repeater = function () {
    898     return this.each(function () {
    899       var $this = $(this),
    900         $fieldset = $this.children('.spf-fieldset'),
    901         $repeater = $fieldset.length ? $fieldset : $this,
    902         $wrapper = $repeater.children('.spf-repeater-wrapper'),
    903         $hidden = $repeater.children('.spf-repeater-hidden'),
    904         $max = $repeater.children('.spf-repeater-max'),
    905         $min = $repeater.children('.spf-repeater-min'),
    906         field_id = $wrapper.data('field-id'),
    907         max = parseInt($wrapper.data('max')),
    908         min = parseInt($wrapper.data('min'))
    909 
    910       $wrapper
    911         .children('.spf-repeater-item')
    912         .children('.spf-repeater-content')
    913         .spf_reload_script()
    914 
    915       $wrapper.sortable({
    916         axis: 'y',
    917         handle: '.spf-repeater-sort',
    918         helper: 'original',
    919         cursor: 'move',
    920         placeholder: 'widget-placeholder',
    921         update: function (event, ui) {
    922           SPF.helper.name_nested_replace(
    923             $wrapper.children('.spf-repeater-item'),
    924             field_id
    925           )
    926           //  $wrapper.spf_customizer_refresh()
    927           ui.item.spf_reload_script_retry()
    928         }
    929       })
    930 
    931       $repeater.children('.spf-repeater-add').on('click', function (e) {
    932         e.preventDefault()
    933 
    934         var count = $wrapper.children('.spf-repeater-item').length
    935 
    936         $min.hide()
    937 
    938         if (max && count + 1 > max) {
    939           $max.show()
    940           return
    941         }
    942 
    943         var $cloned_item = $hidden.spf_clone(true)
    944 
    945         $cloned_item.removeClass('spf-repeater-hidden')
    946 
    947         $cloned_item.find(':input[name!="_pseudo"]').each(function () {
    948           this.name = this.name
    949             .replace('___', '')
    950             .replace(field_id + '[0]', field_id + '[' + count + ']')
    951         })
    952 
    953         $wrapper.append($cloned_item)
    954         $cloned_item.children('.spf-repeater-content').spf_reload_script()
    955         // $wrapper.spf_customizer_refresh()
    956         // $wrapper.spf_customizer_listen({ closest: true })
    957       })
    958 
    959       var event_clone = function (e) {
    960         e.preventDefault()
    961 
    962         var count = $wrapper.children('.spf-repeater-item').length
    963 
    964         $min.hide()
    965 
    966         if (max && count + 1 > max) {
    967           $max.show()
    968           return
    969         }
    970 
    971         var $this = $(this),
    972           $parent = $this
    973             .parent()
    974             .parent()
    975             .parent(),
    976           $cloned_content = $parent
    977             .children('.spf-repeater-content')
    978             .spf_clone(),
    979           $cloned_helper = $parent
    980             .children('.spf-repeater-helper')
    981             .spf_clone(true),
    982           $cloned_item = $('<div class="spf-repeater-item" />')
    983 
    984         $cloned_item.append($cloned_content)
    985         $cloned_item.append($cloned_helper)
    986 
    987         $wrapper
    988           .children()
    989           .eq($parent.index())
    990           .after($cloned_item)
    991 
    992         $cloned_item.children('.spf-repeater-content').spf_reload_script()
    993 
    994         SPF.helper.name_nested_replace(
    995           $wrapper.children('.spf-repeater-item'),
    996           field_id
    997         )
    998 
    999         // $wrapper.spf_customizer_refresh()
    1000         // $wrapper.spf_customizer_listen({ closest: true })
    1001       }
    1002 
    1003       $wrapper
    1004         .children('.spf-repeater-item')
    1005         .children('.spf-repeater-helper')
    1006         .on('click', '.spf-repeater-clone', event_clone)
    1007       $repeater
    1008         .children('.spf-repeater-hidden')
    1009         .children('.spf-repeater-helper')
    1010         .on('click', '.spf-repeater-clone', event_clone)
    1011 
    1012       var event_remove = function (e) {
    1013         e.preventDefault()
    1014 
    1015         var count = $wrapper.children('.spf-repeater-item').length
    1016 
    1017         $max.hide()
    1018         $min.hide()
    1019 
    1020         if (min && count - 1 < min) {
    1021           $min.show()
    1022           return
    1023         }
    1024 
    1025         $(this)
    1026           .closest('.spf-repeater-item')
    1027           .remove()
    1028 
    1029         SPF.helper.name_nested_replace(
    1030           $wrapper.children('.spf-repeater-item'),
    1031           field_id
    1032         )
    1033 
    1034         //  $wrapper.spf_customizer_refresh()
    1035       }
    1036 
    1037       $wrapper
    1038         .children('.spf-repeater-item')
    1039         .children('.spf-repeater-helper')
    1040         .on('click', '.spf-repeater-remove', event_remove)
    1041       $repeater
    1042         .children('.spf-repeater-hidden')
    1043         .children('.spf-repeater-helper')
    1044         .on('click', '.spf-repeater-remove', event_remove)
    1045     })
    1046   }
    1047 
    1048   //
    1049   // Field: slider
    1050   //
    1051   $.fn.spf_field_slider = function () {
    1052     return this.each(function () {
    1053       var $this = $(this),
    1054         $input = $this.find('input'),
    1055         $slider = $this.find('.spf-slider-ui'),
    1056         data = $input.data(),
    1057         value = $input.val() || 0
    1058 
    1059       if ($slider.hasClass('ui-slider')) {
    1060         $slider.empty()
    1061       }
    1062 
    1063       $slider.slider({
    1064         range: 'min',
    1065         value: value,
    1066         min: data.min || 0,
    1067         max: data.max || 100,
    1068         step: data.step || 1,
    1069         slide: function (e, o) {
    1070           $input.val(o.value).trigger('change')
    1071         }
    1072       })
    1073 
    1074       $input.on('keyup', function () {
    1075         $slider.slider('value', $input.val())
    1076       })
    1077     })
    1078   }
    1079 
    1080   //
    1081   // Field: sortable
    1082   //
    1083   $.fn.spf_field_sortable = function () {
    1084     return this.each(function () {
    1085       var $sortable = $(this).find('.spf-sortable')
    1086 
    1087       $sortable.sortable({
    1088         axis: 'y',
    1089         helper: 'original',
    1090         cursor: 'move',
    1091         placeholder: 'widget-placeholder',
    1092         update: function (event, ui) {
    1093           // $sortable.spf_customizer_refresh()
    1094         }
    1095       })
    1096 
    1097       $sortable.find('.spf-sortable-content').spf_reload_script()
    1098     })
    1099   }
    1100 
    1101   //
    1102   // Field: sorter
    1103   //
    1104   $.fn.spf_field_sorter = function () {
    1105     return this.each(function () {
    1106       var $this = $(this),
    1107         $enabled = $this.find('.spf-enabled'),
    1108         $has_disabled = $this.find('.spf-disabled'),
    1109         $disabled = $has_disabled.length ? $has_disabled : false
    1110 
    1111       $enabled.sortable({
    1112         connectWith: $disabled,
    1113         placeholder: 'ui-sortable-placeholder',
    1114         update: function (event, ui) {
    1115           var $el = ui.item.find('input')
    1116 
    1117           if (ui.item.parent().hasClass('spf-enabled')) {
    1118             $el.attr('name', $el.attr('name').replace('disabled', 'enabled'))
    1119           } else {
    1120             $el.attr('name', $el.attr('name').replace('enabled', 'disabled'))
    1121           }
    1122 
    1123           //  $this.spf_customizer_refresh()
    1124         }
    1125       })
    1126 
    1127       if ($disabled) {
    1128         $disabled.sortable({
    1129           connectWith: $enabled,
    1130           placeholder: 'ui-sortable-placeholder',
    1131           update: function (event, ui) {
    1132             // $this.spf_customizer_refresh()
    1133           }
    1134         })
    1135       }
    1136     })
    1137   }
    1138 
    1139   //
    1140   // Field: spinner
    1141   //
    1142   $.fn.spf_field_spinner = function () {
    1143     return this.each(function () {
    1144       var $this = $(this),
    1145         $input = $this.find('input'),
    1146         $inited = $this.find('.ui-button'),
    1147         // $inited = $this.find('.ui-spinner-button'),
    1148         data = $input.data()
    1149 
    1150       if ($inited.length) {
    1151         $inited.remove()
    1152       }
    1153 
    1154       $input.spinner({
    1155         min: data.min || 0,
    1156         max: data.max || 100,
    1157         step: data.step || 1,
    1158         create: function (event, ui) {
    1159           if (data.unit) {
    1160             $input.after(
    1161               '<span class="ui-button spf--unit">' + data.unit + '</span>'
    1162             )
    1163           }
    1164         },
    1165         spin: function (event, ui) {
    1166           $input.val(ui.value).trigger('change')
    1167         }
    1168       })
    1169     })
    1170   }
    1171 
    1172   //
    1173   // Field: switcher
    1174   //
    1175   $.fn.spf_field_switcher = function () {
    1176     return this.each(function () {
    1177       var $switcher = $(this).find('.spf--switcher')
    1178 
    1179       $switcher.on('click', function () {
    1180         var value = 0
    1181         var $input = $switcher.find('input')
    1182 
    1183         if ($switcher.hasClass('spf--active')) {
    1184           $switcher.removeClass('spf--active')
    1185         } else {
    1186           value = 1
    1187           $switcher.addClass('spf--active')
    1188         }
    1189 
    1190         $input.val(value).trigger('change')
    1191       })
    1192     })
    1193   }
    1194 
    1195   //
    1196   // Field: tabbed
    1197   //
    1198   $.fn.spf_field_tabbed = function () {
    1199     return this.each(function () {
    1200       var $this = $(this),
    1201         $links = $this.find('.spf-tabbed-nav a'),
    1202         $contents = $this.find('.spf-tabbed-content')
    1203 
    1204       $contents.eq(0).spf_reload_script()
    1205 
    1206       $links.on('click', function (e) {
    1207         e.preventDefault()
    1208 
    1209         var $link = $(this),
    1210           index = $link.index(),
    1211           $content = $contents.eq(index)
    1212 
    1213         $link
    1214           .addClass('spf-tabbed-active')
    1215           .siblings()
    1216           .removeClass('spf-tabbed-active')
    1217         $content.spf_reload_script()
    1218         $content
    1219           .removeClass('hidden')
    1220           .siblings()
    1221           .addClass('hidden')
    1222       })
    1223     })
    1224   }
    1225 
    1226   //
    1227   // Field: upload
    1228   //
    1229   $.fn.spf_field_upload = function () {
    1230     return this.each(function () {
    1231       var $this = $(this),
    1232         $input = $this.find('input'),
    1233         $upload_button = $this.find('.spf--button'),
    1234         $remove_button = $this.find('.spf--remove'),
    1235         $library =
    1236           ($upload_button.data('library') &&
    1237             $upload_button.data('library').split(',')) ||
    1238           '',
    1239         wp_media_frame
    1240 
    1241       $input.on('change', function (e) {
    1242         if ($input.val()) {
    1243           $remove_button.removeClass('hidden')
    1244         } else {
    1245           $remove_button.addClass('hidden')
    1246         }
    1247       })
    1248 
    1249       $upload_button.on('click', function (e) {
    1250         e.preventDefault()
    1251 
    1252         if (
    1253           typeof window.wp === 'undefined' ||
    1254           !window.wp.media ||
    1255           !window.wp.media.gallery
    1256         ) {
    1257           return
    1258         }
    1259 
    1260         if (wp_media_frame) {
    1261           wp_media_frame.open()
    1262           return
    1263         }
    1264 
    1265         wp_media_frame = window.wp.media({
    1266           library: {
    1267             type: $library
    1268           }
    1269         })
    1270 
    1271         wp_media_frame.on('select', function () {
    1272           var attributes = wp_media_frame
    1273             .state()
    1274             .get('selection')
    1275             .first().attributes
    1276 
    1277           if (
    1278             $library.length &&
    1279             $library.indexOf(attributes.subtype) === -1 &&
    1280             $library.indexOf(attributes.type) === -1
    1281           ) {
    1282             return
    1283           }
    1284 
    1285           $input.val(attributes.url).trigger('change')
    1286         })
    1287 
    1288         wp_media_frame.open()
    1289       })
    1290 
    1291       $remove_button.on('click', function (e) {
    1292         e.preventDefault()
    1293         $input.val('').trigger('change')
    1294       })
    1295     })
    1296   }
    1297 
    1298   //
    1299   // Confirm
    1300   //
    1301   $.fn.spf_confirm = function () {
    1302     return this.each(function () {
    1303       $(this).on('click', function (e) {
    1304         var confirm_text =
    1305           $(this).data('confirm') || window.spf_vars.i18n.confirm
    1306         var confirm_answer = confirm(confirm_text)
    1307 
    1308         if (confirm_answer) {
    1309           SPF.vars.is_confirm = true
    1310           SPF.vars.form_modified = false
    1311         } else {
    1312           e.preventDefault()
    1313           return false
    1314         }
    1315       })
    1316     })
    1317   }
    1318 
    1319   $.fn.serializeObject = function () {
    1320     var obj = {}
    1321 
    1322     $.each(this.serializeArray(), function (i, o) {
    1323       var n = o.name,
    1324         v = o.value
    1325 
    1326       obj[n] =
    1327         obj[n] === undefined
    1328           ? v
    1329           : $.isArray(obj[n])
    1330             ? obj[n].concat(v)
    1331             : [obj[n], v]
    1332     })
    1333 
    1334     return obj
    1335   }
    1336 
    1337   //
    1338   // Options Save
    1339   //
    1340   $.fn.spf_save = function () {
    1341     return this.each(function () {
    1342       var $this = $(this),
    1343         $buttons = $('.spf-save'),
    1344         $panel = $('.spf-options'),
    1345         flooding = false,
    1346         timeout
    1347 
    1348       $this.on('click', function (e) {
    1349         if (!flooding) {
    1350           var $text = $this.data('save'),
    1351             $value = $this.val()
    1352 
    1353           $buttons.attr('value', $text)
    1354 
    1355           if ($this.hasClass('spf-save-ajax')) {
    1356             e.preventDefault()
    1357 
    1358             $panel.addClass('spf-saving')
    1359             $buttons.prop('disabled', true)
    1360 
    1361             window.wp.ajax
    1362               .post('spf_' + $panel.data('unique') + '_ajax_save', {
    1363                 data: $('#spf-form').serializeJSONSPF()
    1364               })
    1365               .done(function (response) {
    1366                 // clear errors
    1367                 $('.spf-error').remove()
    1368 
    1369                 if (Object.keys(response.errors).length) {
    1370                   var error_icon = '<i class="spf-label-error spf-error">!</i>'
    1371 
    1372                   $.each(response.errors, function (key, error_message) {
    1373                     var $field = $('[data-depend-id="' + key + '"]'),
    1374                       $link = $(
    1375                         '#spf-tab-link-' +
    1376                         ($field.closest('.spf-section').index() + 1)
    1377                       ),
    1378                       $tab = $link.closest('.spf-tab-depth-0')
    1379 
    1380                     $field
    1381                       .closest('.spf-fieldset')
    1382                       .append(
    1383                         '<p class="spf-error spf-error-text">' +
    1384                         error_message +
    1385                         '</p>'
    1386                       )
    1387 
    1388                     if (!$link.find('.spf-error').length) {
    1389                       $link.append(error_icon)
    1390                     }
    1391 
    1392                     if (!$tab.find('.spf-arrow .spf-error').length) {
    1393                       $tab.find('.spf-arrow').append(error_icon)
    1394                     }
    1395                   })
    1396                 }
    1397 
    1398                 $panel.removeClass('spf-saving')
    1399                 $buttons.prop('disabled', false).attr('value', $value)
    1400                 flooding = false
    1401 
    1402                 SPF.vars.form_modified = false
    1403                 SPF.vars.$form_warning.hide()
    1404 
    1405                 clearTimeout(timeout)
    1406 
    1407                 var $result_success = $('.spf-form-success')
    1408                 $result_success
    1409                   .empty()
    1410                   .append(response.notice)
    1411                   .fadeIn('fast', function () {
    1412                     timeout = setTimeout(function () {
    1413                       $result_success.fadeOut('fast')
    1414                     }, 1000)
    1415                   })
    1416               })
    1417               .fail(function (response) {
    1418                 alert(response.error)
    1419               })
    1420           } else {
    1421             SPF.vars.form_modified = false
    1422           }
    1423         }
    1424 
    1425         flooding = true
    1426       })
    1427     })
    1428   }
    1429 
    1430   //
    1431   // Option Framework
    1432   //
    1433   $.fn.spf_options = function () {
    1434     return this.each(function () {
    1435       var $this = $(this),
    1436         $content = $this.find('.spf-content'),
    1437         $form_success = $this.find('.spf-form-success'),
    1438         $form_warning = $this.find('.spf-form-warning'),
    1439         $save_button = $this.find('.spf-header .spf-save')
    1440 
    1441       SPF.vars.$form_warning = $form_warning
    1442 
    1443       // Shows a message white leaving theme options without saving
    1444       if ($form_warning.length) {
    1445         window.onbeforeunload = function () {
    1446           return SPF.vars.form_modified ? true : undefined
    1447         }
    1448 
    1449         $content.on('change keypress', ':input', function () {
    1450           if (!SPF.vars.form_modified) {
    1451             $form_success.hide()
    1452             $form_warning.fadeIn('fast')
    1453             SPF.vars.form_modified = true
    1454           }
    1455         })
    1456       }
    1457 
    1458       if ($form_success.hasClass('spf-form-show')) {
    1459         setTimeout(function () {
    1460           $form_success.fadeOut('fast')
    1461         }, 1000)
    1462       }
    1463 
    1464       $(document).keydown(function (event) {
    1465         if ((event.ctrlKey || event.metaKey) && event.which === 83) {
    1466           $save_button.trigger('click')
    1467           event.preventDefault()
    1468           return false
    1469         }
    1470       })
    1471     })
    1472   }
    1473 
    1474   //
    1475   // Taxonomy Framework
    1476   //
    1477   $.fn.spf_taxonomy = function () {
    1478     return this.each(function () {
    1479       var $this = $(this),
    1480         $form = $this.parents('form')
    1481 
    1482       if ($form.attr('id') === 'addtag') {
    1483         var $submit = $form.find('#submit'),
    1484           $cloned = $this.find('.spf-field').spf_clone()
    1485 
    1486         $submit.on('click', function () {
    1487           if (!$form.find('.form-required').hasClass('form-invalid')) {
    1488             $this.data('inited', false)
    1489 
    1490             $this.empty()
    1491 
    1492             $this.html($cloned)
    1493 
    1494             $cloned = $cloned.spf_clone()
    1495 
    1496             $this.spf_reload_script()
    1497           }
    1498         })
    1499       }
    1500     })
    1501   }
    1502 
    1503   //
    1504   // Shortcode Framework
    1505   //
    1506   $.fn.spf_shortcode = function () {
    1507     var base = this
    1508 
    1509     base.shortcode_parse = function (serialize, key) {
    1510       var shortcode = ''
    1511 
    1512       $.each(serialize, function (shortcode_key, shortcode_values) {
    1513         key = key ? key : shortcode_key
    1514 
    1515         shortcode += '[' + key
    1516 
    1517         $.each(shortcode_values, function (shortcode_tag, shortcode_value) {
    1518           if (shortcode_tag === 'content') {
    1519             shortcode += ']'
    1520             shortcode += shortcode_value
    1521             shortcode += '[/' + key + ''
    1522           } else {
    1523             shortcode += base.shortcode_tags(shortcode_tag, shortcode_value)
    1524           }
    1525         })
    1526 
    1527         shortcode += ']'
    1528       })
    1529 
    1530       return shortcode
    1531     }
    1532 
    1533     base.shortcode_tags = function (shortcode_tag, shortcode_value) {
    1534       var shortcode = ''
    1535 
    1536       if (shortcode_value !== '') {
    1537         if (
    1538           typeof shortcode_value === 'object' &&
    1539           !$.isArray(shortcode_value)
    1540         ) {
    1541           $.each(shortcode_value, function (
    1542             sub_shortcode_tag,
    1543             sub_shortcode_value
    1544           ) {
    1545             // sanitize spesific key/value
    1546             switch (sub_shortcode_tag) {
    1547               case 'background-image':
    1548                 sub_shortcode_value = sub_shortcode_value.url
    1549                   ? sub_shortcode_value.url
    1550                   : ''
    1551                 break
    1552             }
    1553 
    1554             if (sub_shortcode_value !== '') {
    1555               shortcode +=
    1556                 ' ' +
    1557                 sub_shortcode_tag.replace('-', '_') +
    1558                 '="' +
    1559                 sub_shortcode_value.toString() +
    1560                 '"'
    1561             }
    1562           })
    1563         } else {
    1564           shortcode +=
    1565             ' ' +
    1566             shortcode_tag.replace('-', '_') +
    1567             '="' +
    1568             shortcode_value.toString() +
    1569             '"'
    1570         }
    1571       }
    1572 
    1573       return shortcode
    1574     }
    1575 
    1576     base.insertAtChars = function (_this, currentValue) {
    1577       var obj = typeof _this[0].name !== 'undefined' ? _this[0] : _this
    1578 
    1579       if (obj.value.length && typeof obj.selectionStart !== 'undefined') {
    1580         obj.focus()
    1581         return (
    1582           obj.value.substring(0, obj.selectionStart) +
    1583           currentValue +
    1584           obj.value.substring(obj.selectionEnd, obj.value.length)
    1585         )
    1586       } else {
    1587         obj.focus()
    1588         return currentValue
    1589       }
    1590     }
    1591 
    1592     base.send_to_editor = function (html, editor_id) {
    1593       var tinymce_editor
    1594 
    1595       if (typeof tinymce !== 'undefined') {
    1596         tinymce_editor = tinymce.get(editor_id)
    1597       }
    1598 
    1599       if (tinymce_editor && !tinymce_editor.isHidden()) {
    1600         tinymce_editor.execCommand('mceInsertContent', false, html)
    1601       } else {
    1602         var $editor = $('#' + editor_id)
    1603         $editor.val(base.insertAtChars($editor, html)).trigger('change')
    1604       }
    1605     }
    1606 
    1607     return this.each(function () {
    1608       var $modal = $(this),
    1609         $load = $modal.find('.spf-modal-load'),
    1610         $content = $modal.find('.spf-modal-content'),
    1611         $insert = $modal.find('.spf-modal-insert'),
    1612         $loading = $modal.find('.spf-modal-loading'),
    1613         $select = $modal.find('select'),
    1614         modal_id = $modal.data('modal-id'),
    1615         nonce = $modal.data('nonce'),
    1616         editor_id,
    1617         target_id,
    1618         sc_key,
    1619         sc_name,
    1620         sc_view,
    1621         sc_group,
    1622         $cloned,
    1623         $button
    1624 
    1625       $(document).on(
    1626         'click',
    1627         '.spf-shortcode-button[data-modal-id="' + modal_id + '"]',
    1628         function (e) {
    1629           e.preventDefault()
    1630 
    1631           $button = $(this)
    1632           editor_id = $button.data('editor-id') || false
    1633           target_id = $button.data('target-id') || false
    1634 
    1635           $modal.removeClass('hidden')
    1636 
    1637           // single usage trigger first shortcode
    1638           if (
    1639             $modal.hasClass('spf-shortcode-single') &&
    1640             sc_name === undefined
    1641           ) {
    1642             $select.trigger('change')
    1643           }
    1644         }
    1645       )
    1646 
    1647       $select.on('change', function () {
    1648         var $option = $(this)
    1649         var $selected = $option.find(':selected')
    1650 
    1651         sc_key = $option.val()
    1652         sc_name = $selected.data('shortcode')
    1653         sc_view = $selected.data('view') || 'normal'
    1654         sc_group = $selected.data('group') || sc_name
    1655 
    1656         $load.empty()
    1657 
    1658         if (sc_key) {
    1659           $loading.show()
    1660 
    1661           window.wp.ajax
    1662             .post('spf-get-shortcode-' + modal_id, {
    1663               shortcode_key: sc_key,
    1664               nonce: nonce
    1665             })
    1666             .done(function (response) {
    1667               $loading.hide()
    1668 
    1669               var $appended = $(response.content).appendTo($load)
    1670 
    1671               $insert.parent().removeClass('hidden')
    1672 
    1673               $cloned = $appended.find('.spf--repeat-shortcode').spf_clone()
    1674 
    1675               $appended.spf_reload_script()
    1676               $appended.find('.spf-fields').spf_reload_script()
    1677             })
    1678         } else {
    1679           $insert.parent().addClass('hidden')
    1680         }
    1681       })
    1682 
    1683       $insert.on('click', function (e) {
    1684         e.preventDefault()
    1685 
    1686         if ($insert.prop('disabled') || $insert.attr('disabled')) {
    1687           return
    1688         }
    1689 
    1690         var shortcode = ''
    1691         var serialize = $modal
    1692           .find('.spf-field:not(.spf-depend-on)')
    1693           .find(':input:not(.ignore)')
    1694           .serializeObjectSPF()
    1695 
    1696         switch (sc_view) {
    1697           case 'contents':
    1698             var contentsObj = sc_name ? serialize[sc_name] : serialize
    1699             $.each(contentsObj, function (sc_key, sc_value) {
    1700               var sc_tag = sc_name ? sc_name : sc_key
    1701               shortcode += '[' + sc_tag + ']' + sc_value + '[/' + sc_tag + ']'
    1702             })
    1703             break
    1704 
    1705           case 'group':
    1706             shortcode += '[' + sc_name
    1707             $.each(serialize[sc_name], function (sc_key, sc_value) {
    1708               shortcode += base.shortcode_tags(sc_key, sc_value)
    1709             })
    1710             shortcode += ']'
    1711             shortcode += base.shortcode_parse(serialize[sc_group], sc_group)
    1712             shortcode += '[/' + sc_name + ']'
    1713 
    1714             break
    1715 
    1716           case 'repeater':
    1717             shortcode += base.shortcode_parse(serialize[sc_group], sc_group)
    1718             break
    1719 
    1720           default:
    1721             shortcode += base.shortcode_parse(serialize)
    1722             break
    1723         }
    1724 
    1725         shortcode = shortcode === '' ? '[' + sc_name + ']' : shortcode
    1726 
    1727         if (editor_id) {
    1728           base.send_to_editor(shortcode, editor_id)
    1729         } else {
    1730           var $textarea = target_id
    1731             ? $(target_id)
    1732             : $button.parent().find('textarea')
    1733           $textarea
    1734             .val(base.insertAtChars($textarea, shortcode))
    1735             .trigger('change')
    1736         }
    1737 
    1738         $modal.addClass('hidden')
    1739       })
    1740 
    1741       $modal.on('click', '.spf--repeat-button', function (e) {
    1742         e.preventDefault()
    1743 
    1744         var $repeatable = $modal.find('.spf--repeatable')
    1745         var $new_clone = $cloned.spf_clone()
    1746         var $remove_btn = $new_clone.find('.spf-repeat-remove')
    1747 
    1748         var $appended = $new_clone.appendTo($repeatable)
    1749 
    1750         $new_clone.find('.spf-fields').spf_reload_script()
    1751 
    1752         SPF.helper.name_nested_replace(
    1753           $modal.find('.spf--repeat-shortcode'),
    1754           sc_group
    1755         )
    1756 
    1757         $remove_btn.on('click', function () {
    1758           $new_clone.remove()
    1759 
    1760           SPF.helper.name_nested_replace(
    1761             $modal.find('.spf--repeat-shortcode'),
    1762             sc_group
    1763           )
    1764         })
    1765       })
    1766 
    1767       $modal.on('click', '.spf-modal-close, .spf-modal-overlay', function () {
    1768         $modal.addClass('hidden')
    1769       })
    1770     })
    1771   }
    1772 
    1773   //
    1774   // WP Color Picker
    1775   //
    1776   if (typeof Color === 'function') {
    1777     Color.prototype.toString = function () {
    1778       if (this._alpha < 1) {
    1779         return this.toCSS('rgba', this._alpha).replace(/\s+/g, '')
    1780       }
    1781 
    1782       var hex = parseInt(this._color, 10).toString(16)
    1783 
    1784       if (this.error) {
    1785         return ''
    1786       }
    1787 
    1788       if (hex.length < 6) {
    1789         for (var i = 6 - hex.length - 1; i >= 0; i--) {
    1790           hex = '0' + hex
    1791         }
    1792       }
    1793 
    1794       return '#' + hex
    1795     }
    1796   }
    1797 
    1798   SPF.funcs.parse_color = function (color) {
    1799     var value = color.replace(/\s+/g, ''),
    1800       trans =
    1801         value.indexOf('rgba') !== -1
    1802           ? parseFloat(value.replace(/^.*,(.+)\)/, '$1') * 100)
    1803           : 100,
    1804       rgba = trans < 100 ? true : false
    1805 
    1806     return { value: value, transparent: trans, rgba: rgba }
    1807   }
    1808 
    1809   $.fn.spf_color = function () {
    1810     return this.each(function () {
    1811       var $input = $(this),
    1812         picker_color = SPF.funcs.parse_color($input.val()),
    1813         palette_color = window.spf_vars.color_palette.length
    1814           ? window.spf_vars.color_palette
    1815           : true,
    1816         $container
    1817 
    1818       // Destroy and Reinit
    1819       if ($input.hasClass('wp-color-picker')) {
    1820         $input
    1821           .closest('.wp-picker-container')
    1822           .after($input)
    1823           .remove()
    1824       }
    1825 
    1826       $input.wpColorPicker({
    1827         palettes: palette_color,
    1828         change: function (event, ui) {
    1829           var ui_color_value = ui.color.toString()
    1830 
    1831           $container.removeClass('spf--transparent-active')
    1832           $container
    1833             .find('.spf--transparent-offset')
    1834             .css('background-color', ui_color_value)
    1835           $input.val(ui_color_value).trigger('change')
    1836         },
    1837         create: function () {
    1838           $container = $input.closest('.wp-picker-container')
    1839 
    1840           var a8cIris = $input.data('a8cIris'),
    1841             $transparent_wrap = $(
    1842               '<div class="spf--transparent-wrap">' +
    1843               '<div class="spf--transparent-slider"></div>' +
    1844               '<div class="spf--transparent-offset"></div>' +
    1845               '<div class="spf--transparent-text"></div>' +
    1846               '<div class="spf--transparent-button">transparent <i class="fas fa-toggle-off"></i></div>' +
    1847               '</div>'
    1848             ).appendTo($container.find('.wp-picker-holder')),
    1849             $transparent_slider = $transparent_wrap.find(
    1850               '.spf--transparent-slider'
    1851             ),
    1852             $transparent_text = $transparent_wrap.find(
    1853               '.spf--transparent-text'
    1854             ),
    1855             $transparent_offset = $transparent_wrap.find(
    1856               '.spf--transparent-offset'
    1857             ),
    1858             $transparent_button = $transparent_wrap.find(
    1859               '.spf--transparent-button'
    1860             )
    1861 
    1862           if ($input.val() === 'transparent') {
    1863             $container.addClass('spf--transparent-active')
    1864           }
    1865 
    1866           $transparent_button.on('click', function () {
    1867             if ($input.val() !== 'transparent') {
    1868               $input
    1869                 .val('transparent')
    1870                 .trigger('change')
    1871                 .removeClass('iris-error')
    1872               $container.addClass('spf--transparent-active')
    1873             } else {
    1874               $input.val(a8cIris._color.toString()).trigger('change')
    1875               $container.removeClass('spf--transparent-active')
    1876             }
    1877           })
    1878 
    1879           $transparent_slider.slider({
    1880             value: picker_color.transparent,
    1881             step: 1,
    1882             min: 0,
    1883             max: 100,
    1884             slide: function (event, ui) {
    1885               var slide_value = parseFloat(ui.value / 100)
    1886               a8cIris._color._alpha = slide_value
    1887               $input.wpColorPicker('color', a8cIris._color.toString())
    1888               $transparent_text.text(
    1889                 slide_value === 1 || slide_value === 0 ? '' : slide_value
    1890               )
    1891             },
    1892             create: function () {
    1893               var slide_value = parseFloat(picker_color.transparent / 100),
    1894                 text_value = slide_value < 1 ? slide_value : ''
    1895 
    1896               $transparent_text.text(text_value)
    1897               $transparent_offset.css('background-color', picker_color.value)
    1898 
    1899               $container.on('click', '.wp-picker-clear', function () {
    1900                 a8cIris._color._alpha = 1
    1901                 $transparent_text.text('')
    1902                 $transparent_slider.slider('option', 'value', 100)
    1903                 $container.removeClass('spf--transparent-active')
    1904                 $input.trigger('change')
    1905               })
    1906 
    1907               $container.on('click', '.wp-picker-default', function () {
    1908                 var default_color = SPF.funcs.parse_color(
    1909                   $input.data('default-color')
    1910                 ),
    1911                   default_value = parseFloat(default_color.transparent / 100),
    1912                   default_text = default_value < 1 ? default_value : ''
    1913 
    1914                 a8cIris._color._alpha = default_value
    1915                 $transparent_text.text(default_text)
    1916                 $transparent_slider.slider(
    1917                   'option',
    1918                   'value',
    1919                   default_color.transparent
    1920                 )
    1921 
    1922                 if (default_color.value === 'transparent') {
    1923                   $input.removeClass('iris-error')
    1924                   $container.addClass('spf--transparent-active')
    1925                 }
    1926               })
    1927             }
    1928           })
    1929         }
    1930       })
    1931     })
    1932   }
    1933 
    1934   //
    1935   // ChosenJS
    1936   //
    1937   $.fn.spf_chosen = function () {
    1938     return this.each(function () {
    1939       var $this = $(this),
    1940         $inited = $this.parent().find('.chosen-container'),
    1941         is_sortable = $this.hasClass('spf-chosen-sortable') || false,
    1942         is_ajax = $this.hasClass('spf-chosen-ajax') || false,
    1943         is_multiple = $this.attr('multiple') || false,
    1944         set_width = is_multiple ? '100%' : 'auto',
    1945         set_options = $.extend(
    1946           {
    1947             allow_single_deselect: true,
    1948             disable_search_threshold: 10,
    1949             width: set_width,
    1950             no_results_text: window.spf_vars.i18n.no_results_text
    1951           },
    1952           $this.data('chosen-settings')
    1953         )
    1954 
    1955       if ($inited.length) {
    1956         $inited.remove()
    1957       }
    1958 
    1959       // Chosen ajax
    1960       if (is_ajax) {
    1961         var set_ajax_options = $.extend(
    1962           {
    1963             data: {
    1964               type: 'post',
    1965               nonce: ''
    1966             },
    1967             allow_single_deselect: true,
    1968             disable_search_threshold: -1,
    1969             width: '100%',
    1970             min_length: 3,
    1971             type_delay: 500,
    1972             typing_text: window.spf_vars.i18n.typing_text,
    1973             searching_text: window.spf_vars.i18n.searching_text,
    1974             no_results_text: window.spf_vars.i18n.no_results_text
    1975           },
    1976           $this.data('chosen-settings')
    1977         )
    1978 
    1979         $this.SPFAjaxChosen(set_ajax_options)
    1980       } else {
    1981         $this.chosen(set_options)
    1982       }
    1983 
    1984       // Chosen keep options order
    1985       if (is_multiple) {
    1986         var $hidden_select = $this.parent().find('.spf-hide-select')
    1987         var $hidden_value = $hidden_select.val() || []
    1988 
    1989         $this.on('change', function (obj, result) {
    1990           if (result && result.selected) {
    1991             $hidden_select.append(
    1992               '<option value="' +
    1993               result.selected +
    1994               '" selected="selected">' +
    1995               result.selected +
    1996               '</option>'
    1997             )
    1998           } else if (result && result.deselected) {
    1999             $hidden_select
    2000               .find('option[value="' + result.deselected + '"]')
    2001               .remove()
    2002           }
    2003 
    2004           // Force customize refresh
    2005           if (
    2006             window.wp.customize !== undefined &&
    2007             $hidden_select.children().length === 0 &&
    2008             $hidden_select.data('customize-setting-link')
    2009           ) {
    2010             window.wp.customize
    2011               .control($hidden_select.data('customize-setting-link'))
    2012               .setting.set('')
    2013           }
    2014 
    2015           $hidden_select.trigger('change')
    2016         })
    2017         SPF
    2018 
    2019         // Chosen order abstract
    2020         $this.CSFChosenOrder($hidden_value, true)
    2021       }
    2022 
    2023       // Chosen sortable
    2024       if (is_sortable) {
    2025         var $chosen_container = $this.parent().find('.chosen-container')
    2026         var $chosen_choices = $chosen_container.find('.chosen-choices')
    2027 
    2028         $chosen_choices.bind('mousedown', function (event) {
    2029           if ($(event.target).is('span')) {
    2030             event.stopPropagation()
    2031           }
    2032         })
    2033 
    2034         $chosen_choices.sortable({
    2035           items: 'li:not(.search-field)',
    2036           helper: 'orginal',
    2037           cursor: 'move',
    2038           placeholder: 'search-choice-placeholder',
    2039           start: function (e, ui) {
    2040             ui.placeholder.width(ui.item.innerWidth())
    2041             ui.placeholder.height(ui.item.innerHeight())
    2042           },
    2043           update: function (e, ui) {
    2044             var select_options = ''
    2045             var chosen_object = $this.data('chosen')
    2046             var $prev_select = $this.parent().find('.spf-hide-select')
    2047 
    2048             $chosen_choices.find('.search-choice-close').each(function () {
    2049               var option_array_index = $(this).data('option-array-index')
    2050               $.each(chosen_object.results_data, function (index, data) {
    2051                 if (data.array_index === option_array_index) {
    2052                   select_options +=
    2053                     '<option value="' +
    2054                     data.value +
    2055                     '" selected>' +
    2056                     data.value +
    2057                     '</option>'
    2058                 }
    2059               })
    2060             })
    2061 
    2062             $prev_select.children().remove()
    2063             $prev_select.append(select_options)
    2064             $prev_select.trigger('change')
    2065           }
    2066         })
    2067       }
    2068     })
    2069   }
    2070 
    2071   //
    2072   // Helper Checkbox Checker
    2073   //
    2074   $.fn.spf_checkbox = function () {
    2075     return this.each(function () {
    2076       var $this = $(this),
    2077         $input = $this.find('.spf--input'),
    2078         $checkbox = $this.find('.spf--checkbox')
    2079 
    2080       $checkbox.on('click', function () {
    2081         $input.val(Number($checkbox.prop('checked'))).trigger('change')
    2082       })
    2083     })
    2084   }
    2085 
    2086   //
    2087   // Siblings
    2088   //
    2089   $.fn.spf_siblings = function () {
    2090     return this.each(function () {
    2091       var $this = $(this),
    2092         $siblings = $this.find('.spf--sibling'),
    2093         multiple = $this.data('multiple') || false
    2094 
    2095       $siblings.on('click', function () {
    2096         var $sibling = $(this)
    2097 
    2098         if (multiple) {
    2099           if ($sibling.hasClass('spf--active')) {
    2100             $sibling.removeClass('spf--active')
    2101             $sibling
    2102               .find('input')
    2103               .prop('checked', false)
    2104               .trigger('change')
    2105           } else {
    2106             $sibling.addClass('spf--active')
    2107             $sibling
    2108               .find('input')
    2109               .prop('checked', true)
    2110               .trigger('change')
    2111           }
    2112         } else {
    2113           $this.find('input').prop('checked', false)
    2114           $sibling
    2115             .find('input')
    2116             .prop('checked', true)
    2117             .trigger('change')
    2118           $sibling
    2119             .addClass('spf--active')
    2120             .siblings()
    2121             .removeClass('spf--active')
    2122         }
    2123       })
    2124     })
    2125   }
    2126 
    2127   //
    2128   // Help Tooltip
    2129   //
    2130   $.fn.spf_help = function () {
    2131     return this.each(function () {
    2132       var $this = $(this),
    2133         $tooltip,
    2134         offset_left
    2135 
    2136       $this.on({
    2137         mouseenter: function () {
    2138           $tooltip = $('<div class="spf-tooltip"></div>')
    2139             .html($this.find('.spf-help-text').html())
    2140             .appendTo('body')
    2141 
    2142           offset_left = SPF.vars.is_rtl
    2143             ? $this.offset().left - 230
    2144             : $this.offset().left + 24
    2145 
    2146           $tooltip.css({
    2147             top: $this.offset().top - ($tooltip.outerHeight() / 2 - 14),
    2148             left: offset_left,
    2149             textAlign: SPF.vars.is_rtl ? 'right' : 'left'
    2150           })
    2151         },
    2152         mouseleave: function () {
    2153           if ($tooltip !== undefined) {
    2154             $tooltip.remove()
    2155           }
    2156         }
    2157       })
    2158     })
    2159   }
    2160 
    2161   //
    2162   // Window on resize
    2163   //
    2164   SPF.vars.$window
    2165     .on(
    2166       'resize spf.resize',
    2167       SPF.helper.debounce(function (event) {
    2168         var window_width =
    2169           navigator.userAgent.indexOf('AppleWebKit/') > -1
    2170             ? SPF.vars.$window.width()
    2171             : window.innerWidth
    2172 
    2173         if (window_width <= 782 && !SPF.vars.onloaded) {
    2174           $('.spf-section').spf_reload_script()
    2175           SPF.vars.onloaded = true
    2176         }
    2177       }, 200)
    2178     )
    2179     .trigger('spf.resize')
    2180 
    2181   //
    2182   // Widgets Framework
    2183   //
    2184   $.fn.spf_widgets = function () {
    2185     if (this.length) {
    2186       $(document).on('widget-added widget-updated', function (event, $widget) {
    2187         $widget.find('.spf-fields').spf_reload_script()
    2188       })
    2189 
    2190       $('.widgets-sortables, .control-section-sidebar').on(
    2191         'sortstop',
    2192         function (event, ui) {
    2193           ui.item.find('.spf-fields').spf_reload_script_retry()
    2194         }
    2195       )
    2196 
    2197       $(document).on('click', '.widget-top', function (event) {
    2198         $(this)
    2199           .parent()
    2200           .find('.spf-fields')
    2201           .spf_reload_script()
    2202       })
    2203     }
    2204   }
    2205 
    2206   //
    2207   // Nav Menu Options Framework
    2208   //
    2209   $.fn.spf_nav_menu = function () {
    2210     return this.each(function () {
    2211       var $navmenu = $(this)
    2212 
    2213       $navmenu.on('click', 'a.item-edit', function () {
    2214         $(this)
    2215           .closest('li.menu-item')
    2216           .find('.spf-fields')
    2217           .spf_reload_script()
    2218       })
    2219 
    2220       $navmenu.on('sortstop', function (event, ui) {
    2221         ui.item.find('.spf-fields').spf_reload_script_retry()
    2222       })
    2223     })
    2224   }
    2225 
    2226   //
    2227   // Retry Plugins
    2228   //
    2229   $.fn.spf_reload_script_retry = function () {
    2230     return this.each(function () {
    2231       var $this = $(this)
    2232 
    2233       if ($this.data('inited')) {
    2234       }
    2235     })
    2236   }
    2237 
    2238   //
    2239   // Reload Plugins
    2240   //
    2241   $.fn.spf_reload_script = function (options) {
    2242     var settings = $.extend(
    2243       {
    2244         dependency: true
    2245       },
    2246       options
    2247     )
    2248 
    2249     return this.each(function () {
    2250       var $this = $(this)
    2251 
    2252       // Avoid for conflicts
    2253       if (!$this.data('inited')) {
    2254         // Field plugins
    2255         // $this.children('.spf-field-accordion').spf_field_accordion()
    2256         // $this.children('.spf-field-backup').spf_field_backup()
    2257         //  $this.children('.spf-field-background').spf_field_background()
    2258         $this.children('.spf-field-code_editor').spf_field_code_editor()
    2259         // $this.children('.spf-field-date').spf_field_date()
    2260         $this.children('.spf-field-fieldset').spf_field_fieldset()
    2261         // $this.children('.spf-field-gallery').spf_field_gallery()
    2262         $this.children('.spf-field-group').spf_field_group()
    2263         $this.children('.spf-field-icon').spf_field_icon()
    2264         // $this.children('.spf-field-link').spf_field_link()
    2265         // $this.children('.spf-field-media').spf_field_media()
    2266         // $this.children('.spf-field-map').spf_field_map()
    2267         $this.children('.spf-field-repeater').spf_field_repeater()
    2268         $this.children('.spf-field-slider').spf_field_slider()
    2269         $this.children('.spf-field-sortable').spf_field_sortable()
    2270         $this.children('.spf-field-sorter').spf_field_sorter()
    2271         $this.children('.spf-field-spinner').spf_field_spinner()
    2272         $this.children('.spf-field-switcher').spf_field_switcher()
    2273         $this.children('.spf-field-tabbed').spf_field_tabbed()
    2274         // $this.children('.spf-field-typography').spf_field_typography()
    2275         $this.children('.spf-field-upload').spf_field_upload()
    2276 
    2277         // Field colors
    2278         $this
    2279           .children('.spf-field-box_shadow')
    2280           .find('.spf-color')
    2281           .spf_color() // ShapedPlugin.
    2282         $this
    2283           .children('.spf-field-border')
    2284           .find('.spf-color')
    2285           .spf_color()
    2286         $this
    2287           .children('.spf-field-background')
    2288           .find('.spf-color')
    2289           .spf_color()
    2290         $this
    2291           .children('.spf-field-color')
    2292           .find('.spf-color')
    2293           .spf_color()
    2294         $this
    2295           .children('.spf-field-color_group')
    2296           .find('.spf-color')
    2297           .spf_color()
    2298         $this
    2299           .children('.spf-field-link_color')
    2300           .find('.spf-color')
    2301           .spf_color()
    2302         $this
    2303           .children('.spf-field-typography')
    2304           .find('.spf-color')
    2305           .spf_color()
    2306 
    2307         // Field chosenjs
    2308         $this
    2309           .children('.spf-field-select')
    2310           .find('.spf-chosen')
    2311           .spf_chosen()
    2312 
    2313         // Field Checkbox
    2314         $this
    2315           .children('.spf-field-checkbox')
    2316           .find('.spf-checkbox')
    2317           .spf_checkbox()
    2318 
    2319         // Field Siblings
    2320         $this
    2321           .children('.spf-field-button_set')
    2322           .find('.spf-siblings')
    2323           .spf_siblings()
    2324         $this
    2325           .children('.spf-field-image_select')
    2326           .find('.spf-siblings')
    2327           .spf_siblings()
    2328         $this
    2329           .children('.spf-field-palette')
    2330           .find('.spf-siblings')
    2331           .spf_siblings()
    2332 
    2333         // Help Tooptip
    2334         $this
    2335           .children('.spf-field')
    2336           .find('.spf-help')
    2337           .spf_help()
    2338 
    2339         if (settings.dependency) {
    2340           $this.spf_dependency()
    2341         }
    2342 
    2343         $this.data('inited', true)
    2344 
    2345         $(document).trigger('spf-reload-script', $this)
    2346       }
    2347     })
    2348   }
    2349   $('.spf-clean-cache').on('click', function (e) {
    2350     e.preventDefault()
    2351     if (SPF.vars.is_confirm) {
    2352       //base.notificationOverlay()
    2353 
    2354       window.wp.ajax
    2355         .post('spf_clean_transient', {
    2356           nonce: $('#spf_options_nonce_sptp_settings').val()
    2357         })
    2358         .done(function (response) {
    2359           //  window.location.reload(true)
    2360           alert('data cleaned')
    2361         })
    2362         .fail(function (response) {
    2363           alert('data failed to clean')
    2364           alert(response.error)
    2365           //  wp.customize.notifications.remove('spf_field_backup_notification')
    2366         })
    2367     }
    2368   })
    2369   //
    2370   // Document ready and run scripts
    2371   //
    2372   $(document).ready(function () {
    2373     $('.spf-save').spf_save()
    2374     $('.spf-options').spf_options()
    2375     $('.spf-sticky-header').spf_sticky()
    2376     $('.spf-nav-options').spf_nav_options()
    2377     $('.spf-nav-metabox').spf_nav_metabox()
    2378     $('.spf-taxonomy').spf_taxonomy()
    2379     $('.spf-page-templates').spf_page_templates()
    2380     $('.spf-post-formats').spf_post_formats()
    2381     $('.spf-shortcode').spf_shortcode()
    2382     $('.spf-search').spf_search()
    2383     $('.spf-confirm').spf_confirm()
    2384     $('.spf-expand-all').spf_expand_all()
    2385     $('.spf-onload').spf_reload_script()
    2386     $('.widget').spf_widgets()
    2387     $('#menu-to-edit').spf_nav_menu()
    2388     $(".spf-field-button_clean.cache_remove .spf--sibling.spf--button").on("click", function (e) {
    2389       e.preventDefault();
    2390       if (SPF.vars.is_confirm) {
    2391         // base.notificationOverlay()
    2392         window.wp.ajax
    2393           .post("sptp_clean_transient", {
    2394             nonce: $("#spf_options_nonce_sptp_settings").val(),
    2395           })
    2396           .done(function (response) {
    2397             alert("Cache cleaned");
    2398           })
    2399           .fail(function (response) {
    2400             alert("Cache failed to clean");
    2401             alert(response.error);
    2402             //  wp.customize.notifications.remove('spf_field_backup_notification')
    2403           });
    2404       }
    2405     });
    2406   })
    2407 
    2408   // Wp Team export.
    2409   var $export_type = $('.sptp_what_export').find('input:checked').val();
    2410   $('.sptp_what_export').on('change', function () {
    2411     $export_type = $(this).find('input:checked').val();
    2412   });
    2413 
    2414   $('.sptp_export .spf--button').click(function (event) {
    2415     event.preventDefault();
    2416 
    2417     var $shortcode_ids = $('.sptp_post_ids select').val();
    2418     var $ex_nonce = $('#spf_options_nonce_sptp_tools').val();
    2419     console.log($ex_nonce);
    2420     if ($shortcode_ids.length && $export_type === 'selected_shortcodes') {
    2421       var data = {
    2422         action: 'SPT_export_shortcodes',
    2423         lcp_ids: $shortcode_ids,
    2424         nonce: $ex_nonce,
    2425       }
    2426     } else if ($export_type === 'all_shortcodes') {
    2427       var data = {
    2428         action: 'SPT_export_shortcodes',
    2429         lcp_ids: 'all_shortcodes',
    2430         nonce: $ex_nonce,
    2431       }
    2432     } else if ($export_type === 'all_members') {
    2433       var data = {
    2434         action: 'SPT_export_shortcodes',
    2435         lcp_ids: 'all_members',
    2436         nonce: $ex_nonce,
    2437       }
    2438     } else {
    2439       $('.spf-form-result.spf-form-success').text('No group selected.').show();
    2440       setTimeout(function () {
    2441         $('.spf-form-result.spf-form-success').hide().text('');
    2442       }, 3000);
    2443     }
    2444     $.post(ajaxurl, data, function (resp) {
    2445       if (resp) {
    2446         console.log(resp);
    2447         //  return;
    2448         // Convert JSON Array to string.
    2449         var json = JSON.stringify(resp);
    2450         // Convert JSON string to BLOB.
    2451         json = [json];
    2452         var blob = new Blob(json);
    2453         var link = document.createElement('a');
    2454         var lcp_time = $.now();
    2455         link.href = window.URL.createObjectURL(blob);
    2456         link.download = "wp-team-export-" + lcp_time + ".json";
    2457         link.click();
    2458         $('.spf-form-result.spf-form-success').text('Exported successfully!').show();
    2459         setTimeout(function () {
    2460           $('.spf-form-result.spf-form-success').hide().text('');
    2461           $('.sptp_post_ids select').val('').trigger('chosen:updated');
    2462         }, 3000);
    2463       }
    2464     });
    2465   });
    2466   // Wp Team import.
    2467   $('.sptp_import button.import').click(function (event) {
    2468     event.preventDefault();
    2469     var sptp_shortcodes = $('#import').prop('files')[0];
    2470     if ($('#import').val() != '') {
    2471       var $im_nonce = $('#spf_options_nonce_sptp_tools').val();
    2472       var reader = new FileReader();
    2473       reader.readAsText(sptp_shortcodes);
    2474       reader.onload = function (event) {
    2475         var jsonObj = JSON.stringify(event.target.result);
    2476         $.ajax({
    2477           url: ajaxurl,
    2478           type: 'POST',
    2479           data: {
    2480             shortcode: jsonObj,
    2481             action: 'SPT_import_shortcodes',
    2482             nonce: $im_nonce,
    2483           },
    2484           success: function (resp) {
    2485             console.log(resp);
    2486             $('.spf-form-result.spf-form-success').text('Imported successfully!').show();
    2487             setTimeout(function () {
    2488               $('.spf-form-result.spf-form-success').hide().text('');
    2489               $('#import').val('');
    2490               if (resp.data === 'sptp_member') {
    2491                 window.location.replace($('#sptp_member_link_redirect').attr('href'));
    2492               } else {
    2493                 window.location.replace($('#sptp_shortcode_link_redirect').attr('href'));
    2494               }
    2495             }, 2000);
    2496           }
    2497         });
    2498       }
    2499     } else {
    2500       $('.spf-form-result.spf-form-success').text('No exported json file chosen.').show();
    2501       setTimeout(function () {
    2502         $('.spf-form-result.spf-form-success').hide().text('');
    2503       }, 3000);
    2504     }
    2505   });
    2506 
    2507   // Live Preview script for Wp-Team-Pro.
    2508   var preview_box = $('#sp__team-preview-box');
    2509   var preview_display = $('#sptp_preview_display').hide();
    2510   $(document).on('click', '#sp__team-show-preview:contains(Hide)', function (e) {
    2511     e.preventDefault();
    2512     var _this = $(this);
    2513     _this.html('<i class="fa fa-eye" aria-hidden="true"></i> Show Preview');
    2514     preview_box.html('');
    2515     preview_display.hide();
    2516   });
    2517   $(document).on('click', '#sp__team-show-preview:not(:contains(Hide))', function (e) {
    2518     e.preventDefault();
    2519     var previewJS = sptp_admin.previewJS;
    2520     var _data = $('form#post').serialize();
    2521     var _this = $(this);
    2522     var data = {
    2523       action: 'sptp_preview_meta_box',
    2524       data: _data,
    2525       ajax_nonce: $('#spf_metabox_noncesptp_preview_display').val()
    2526     };
    2527     $.ajax({
    2528       type: "POST",
    2529       url: ajaxurl,
    2530       data: data,
    2531       error: function (response) {
    2532         console.log(response)
    2533       },
    2534       success: function (response) {
    2535         preview_display.show();
    2536         preview_box.html(response);
    2537         $.getScript(previewJS, function () {
    2538           _this.html('<i class="fa fa-eye-slash" aria-hidden="true"></i> Hide Preview');
    2539           $(document).on('keyup change', '.post-type-sptp_generator', function (e) {
    2540             e.preventDefault();
    2541             _this.html('<i class="fa fa-refresh" aria-hidden="true"></i> Update Preview');
    2542           });
    2543           $("html, body").animate({ scrollTop: preview_display.offset().top - 50 }, "slow");
    2544         });
    2545       }
    2546     })
    2547   });
    2548 
    2549 
    2550   $(document).on('keyup change', '.sptp_member_page_team_settings #spf-form', function (e)  {
    2551     e.preventDefault();
    2552     var $button = $(this).find('.spf-save');
    2553     $button.css({"background-color": "#00C263", "pointer-events": "initial"}).val('Save Settings');
    2554   });
    2555  $('.sptp_member_page_team_settings .spf-save').click(function(e) {
    2556     e.preventDefault();
    2557     $(this).css({"background-color": "#C5C5C6","pointer-events": "none"}).val('Changes Saved');
    2558 })
     2    'use strict'
     3
     4    //
     5    // Constants
     6    //
     7    var SPF = SPF || {}
     8
     9    SPF.funcs = {}
     10
     11    SPF.vars = {
     12        onloaded: false,
     13        $body: $('body'),
     14        $window: $(window),
     15        $document: $(document),
     16        $form_warning: null,
     17        is_confirm: false,
     18        form_modified: false,
     19        code_themes: [],
     20        is_rtl: $('body').hasClass('rtl')
     21    }
     22
     23    //
     24    // Helper Functions
     25    //
     26    SPF.helper = {
     27        //
     28        // Generate UID
     29        //
     30        uid: function (prefix) {
     31            return (
     32                (prefix || '') +
     33                Math.random()
     34                    .toString(36)
     35                    .substr(2, 9)
     36            )
     37        },
     38
     39        // Quote regular expression characters
     40        //
     41        preg_quote: function (str) {
     42            return (str + '').replace(/(\[|\])/g, '\\$1')
     43        },
     44
     45        //
     46        // Rename input names
     47
     48        //
     49        name_nested_replace: function ($selector, field_id) {
     50            var checks = []
     51            var regex = new RegExp(SPF.helper.preg_quote(field_id + '[\\d+]'), 'g')
     52
     53            $selector.find(':radio').each(function () {
     54                if (this.checked || this.original_checked) {
     55                    this.original_checked = true
     56                }
     57            })
     58
     59            $selector.each(function (index) {
     60                $(this)
     61                    .find(':input')
     62                    .each(function () {
     63                        this.name = this.name.replace(regex, field_id + '[' + index + ']')
     64                        if (this.original_checked) {
     65                            this.checked = true
     66                        }
     67                    })
     68            })
     69        },
     70
     71        //
     72        // Debounce
     73        //
     74        debounce: function (callback, threshold, immediate) {
     75            var timeout
     76            return function () {
     77                var context = this,
     78                    args = arguments
     79                var later = function () {
     80                    timeout = null
     81                    if (!immediate) {
     82                        callback.apply(context, args)
     83                    }
     84                }
     85                var callNow = immediate && !timeout
     86                clearTimeout(timeout)
     87                timeout = setTimeout(later, threshold)
     88                if (callNow) {
     89                    callback.apply(context, args)
     90                }
     91            }
     92        },
     93
     94        //
     95        // Get a cookie
     96        //
     97        get_cookie: function (name) {
     98            var e,
     99                b,
     100                cookie = document.cookie,
     101                p = name + '='
     102
     103            if (!cookie) {
     104                return
     105            }
     106
     107            b = cookie.indexOf('; ' + p)
     108
     109            if (b === -1) {
     110                b = cookie.indexOf(p)
     111
     112                if (b !== 0) {
     113                    return null
     114                }
     115            } else {
     116                b += 2
     117            }
     118
     119            e = cookie.indexOf(';', b)
     120
     121            if (e === -1) {
     122                e = cookie.length
     123            }
     124
     125            return decodeURIComponent(cookie.substring(b + p.length, e))
     126        },
     127
     128        //
     129        // Set a cookie
     130        //
     131        set_cookie: function (name, value, expires, path, domain, secure) {
     132            var d = new Date()
     133
     134            if (typeof expires === 'object' && expires.toGMTString) {
     135                expires = expires.toGMTString()
     136            } else if (parseInt(expires, 10)) {
     137                d.setTime(d.getTime() + parseInt(expires, 10) * 1000)
     138                expires = d.toGMTString()
     139            } else {
     140                expires = ''
     141            }
     142
     143            document.cookie =
     144                name +
     145                '=' +
     146                encodeURIComponent(value) +
     147                (expires ? '; expires=' + expires : '') +
     148                (path ? '; path=' + path : '') +
     149                (domain ? '; domain=' + domain : '') +
     150                (secure ? '; secure' : '')
     151        },
     152
     153        //
     154        // Remove a cookie
     155        //
     156        remove_cookie: function (name, path, domain, secure) {
     157            SPF.helper.set_cookie(name, '', -1000, path, domain, secure)
     158        }
     159    }
     160
     161    //
     162    // Custom clone for textarea and select clone() bug
     163    //
     164    $.fn.spf_clone = function () {
     165        var base = $.fn.clone.apply(this, arguments),
     166            clone = this.find('select').add(this.filter('select')),
     167            cloned = base.find('select').add(base.filter('select'))
     168
     169        for (var i = 0; i < clone.length; ++i) {
     170            for (var j = 0; j < clone[i].options.length; ++j) {
     171                if (clone[i].options[j].selected === true) {
     172                    cloned[i].options[j].selected = true
     173                }
     174            }
     175        }
     176
     177        this.find(':radio').each(function () {
     178            this.original_checked = this.checked
     179        })
     180
     181        return base
     182    }
     183
     184    //
     185    // Expand All Options
     186    //
     187    $.fn.spf_expand_all = function () {
     188        return this.each(function () {
     189            $(this).on('click', function (e) {
     190                e.preventDefault()
     191                $('.spf-wrapper').toggleClass('spf-show-all')
     192                $('.spf-section').spf_reload_script()
     193                $(this)
     194                    .find('.fa')
     195                    .toggleClass('fa-indent')
     196                    .toggleClass('fa-outdent')
     197            })
     198        })
     199    }
     200
     201    //
     202    // Options Navigation
     203    //
     204    $.fn.spf_nav_options = function () {
     205        return this.each(function () {
     206            var $nav = $(this),
     207                $links = $nav.find('a'),
     208                $last
     209
     210            $(window)
     211                .on('hashchange spf.hashchange', function () {
     212                    var hash = window.location.hash.replace('#tab=', '')
     213                    var slug = hash
     214                        ? hash
     215                        : $links
     216                            .first()
     217                            .attr('href')
     218                            .replace('#tab=', '')
     219                    var $link = $('[data-tab-id="' + slug + '"]')
     220
     221                    if ($link.length) {
     222                        $link
     223                            .closest('.spf-tab-item')
     224                            .addClass('spf-tab-expanded')
     225                            .siblings()
     226                            .removeClass('spf-tab-expanded')
     227
     228                        if ($link.next().is('ul')) {
     229                            $link = $link
     230                                .next()
     231                                .find('li')
     232                                .first()
     233                                .find('a')
     234                            slug = $link.data('tab-id')
     235                        }
     236
     237                        $links.removeClass('spf-active')
     238                        $link.addClass('spf-active')
     239
     240                        if ($last) {
     241                            $last.addClass('hidden')
     242                        }
     243
     244                        var $section = $('[data-section-id="' + slug + '"]')
     245
     246                        $section.removeClass('hidden')
     247                        $section.spf_reload_script()
     248
     249                        $('.spf-section-id').val($section.index() + 1)
     250
     251                        $last = $section
     252                    }
     253                })
     254                .trigger('spf.hashchange')
     255        })
     256    }
     257
     258    //
     259    // Metabox Tabs
     260    //
     261    $.fn.spf_nav_metabox = function () {
     262        return this.each(function () {
     263            var $nav = $(this),
     264                $links = $nav.find('a'),
     265                unique_id = $nav.data('unique'),
     266                post_id = $('#post_ID').val() || 'global',
     267                $sections = $nav.parent().find('.spf-section'),
     268                $last
     269
     270            $links.each(function (index) {
     271                $(this).on('click', function (e) {
     272                    e.preventDefault()
     273
     274                    var $link = $(this)
     275                    var section_id = $link.data('section')
     276
     277                    $links.removeClass('spf-active')
     278                    $link.addClass('spf-active')
     279
     280                    if ($last !== undefined) {
     281                        $last.addClass('hidden')
     282                    }
     283
     284                    var $section = $sections.eq(index)
     285
     286                    $section.removeClass('hidden')
     287                    $section.spf_reload_script()
     288
     289                    SPF.helper.set_cookie(
     290                        'spf-last-metabox-tab-' + post_id + '-' + unique_id,
     291                        section_id
     292                    )
     293
     294                    $last = $section
     295                })
     296                var get_cookie = SPF.helper.get_cookie(
     297                    'spf-last-metabox-tab-' + post_id + '-' + unique_id
     298                )
     299
     300                if (get_cookie) {
     301                    $nav.find('a[data-section="' + get_cookie + '"]').trigger('click')
     302                } else {
     303                    $links.first('a').trigger('click')
     304                }
     305            })
     306
     307            // $links.first().trigger('click')
     308        })
     309    }
     310
     311    //
     312    // Metabox Page Templates Listener
     313    //
     314    $.fn.spf_page_templates = function () {
     315        if (this.length) {
     316            $(document).on(
     317                'change',
     318                '.editor-page-attributes__template select, #page_template',
     319                function () {
     320                    var maybe_value = $(this).val() || 'default'
     321
     322                    $('.spf-page-templates')
     323                        .removeClass('spf-metabox-show')
     324                        .addClass('spf-metabox-hide')
     325                    $(
     326                        '.spf-page-' +
     327                        maybe_value.toLowerCase().replace(/[^a-zA-Z0-9]+/g, '-')
     328                    )
     329                        .removeClass('spf-metabox-hide')
     330                        .addClass('spf-metabox-show')
     331                }
     332            )
     333        }
     334    }
     335
     336    //
     337    // Metabox Post Formats Listener
     338    //
     339    $.fn.spf_post_formats = function () {
     340        if (this.length) {
     341            $(document).on(
     342                'change',
     343                '.editor-post-format select, #formatdiv input[name="post_format"]',
     344                function () {
     345                    var maybe_value = $(this).val() || 'default'
     346
     347                    // Fallback for classic editor version
     348                    maybe_value = maybe_value === '0' ? 'default' : maybe_value
     349
     350                    $('.spf-post-formats')
     351                        .removeClass('spf-metabox-show')
     352                        .addClass('spf-metabox-hide')
     353                    $('.spf-post-format-' + maybe_value)
     354                        .removeClass('spf-metabox-hide')
     355                        .addClass('spf-metabox-show')
     356                }
     357            )
     358        }
     359    }
     360
     361    //
     362    // Search
     363    //
     364    $.fn.spf_search = function () {
     365        return this.each(function () {
     366            var $this = $(this),
     367                $input = $this.find('input')
     368
     369            $input.on('change keyup', function () {
     370                var value = $(this).val(),
     371                    $wrapper = $('.spf-wrapper'),
     372                    $section = $wrapper.find('.spf-section'),
     373                    $fields = $section.find('> .spf-field:not(.spf-depend-on)'),
     374                    $titles = $fields.find('> .spf-title, .spf-search-tags')
     375
     376                if (value.length > 3) {
     377                    $fields.addClass('spf-metabox-hide')
     378                    $wrapper.addClass('spf-search-all')
     379
     380                    $titles.each(function () {
     381                        var $title = $(this)
     382
     383                        if ($title.text().match(new RegExp('.*?' + value + '.*?', 'i'))) {
     384                            var $field = $title.closest('.spf-field')
     385
     386                            $field.removeClass('spf-metabox-hide')
     387                            $field.parent().spf_reload_script()
     388                        }
     389                    })
     390                } else {
     391                    $fields.removeClass('spf-metabox-hide')
     392                    $wrapper.removeClass('spf-search-all')
     393                }
     394            })
     395        })
     396    }
     397
     398    //
     399    // Sticky Header
     400    //
     401    $.fn.spf_sticky = function () {
     402        return this.each(function () {
     403            var $this = $(this),
     404                $window = $(window),
     405                $inner = $this.find('.spf-header-inner'),
     406                padding =
     407                    parseInt($inner.css('padding-left')) +
     408                    parseInt($inner.css('padding-right')),
     409                offset = 32,
     410                scrollTop = 0,
     411                lastTop = 0,
     412                ticking = false,
     413                stickyUpdate = function () {
     414                    var offsetTop = $this.offset().top,
     415                        stickyTop = Math.max(offset, offsetTop - scrollTop),
     416                        winWidth = Math.max(
     417                            document.documentElement.clientWidth,
     418                            window.innerWidth || 0
     419                        )
     420
     421                    if (stickyTop <= offset && winWidth > 782) {
     422                        $inner.css({ width: $this.outerWidth() - padding })
     423                        $this.css({ height: $this.outerHeight() }).addClass('spf-sticky')
     424                    } else {
     425                        $inner.removeAttr('style')
     426                        $this.removeAttr('style').removeClass('spf-sticky')
     427                    }
     428                },
     429                requestTick = function () {
     430                    if (!ticking) {
     431                        requestAnimationFrame(function () {
     432                            stickyUpdate()
     433                            ticking = false
     434                        })
     435                    }
     436
     437                    ticking = true
     438                },
     439                onSticky = function () {
     440                    scrollTop = $window.scrollTop()
     441                    requestTick()
     442                }
     443
     444            $window.on('scroll resize', onSticky)
     445
     446            onSticky()
     447        })
     448    }
     449
     450    //
     451    // Dependency System
     452    //
     453    $.fn.spf_dependency = function () {
     454        return this.each(function () {
     455            var $this = $(this),
     456                $fields = $this.children('[data-controller]')
     457
     458            if ($fields.length) {
     459                var normal_ruleset = $.spf_deps.createRuleset(),
     460                    global_ruleset = $.spf_deps.createRuleset(),
     461                    normal_depends = [],
     462                    global_depends = []
     463
     464                $fields.each(function () {
     465                    var $field = $(this),
     466                        controllers = $field.data('controller').split('|'),
     467                        conditions = $field.data('condition').split('|'),
     468                        values = $field
     469                            .data('value')
     470                            .toString()
     471                            .split('|'),
     472                        is_global = $field.data('depend-global') ? true : false,
     473                        ruleset = is_global ? global_ruleset : normal_ruleset
     474
     475                    $.each(controllers, function (index, depend_id) {
     476                        var value = values[index] || '',
     477                            condition = conditions[index] || conditions[0]
     478
     479                        ruleset = ruleset.createRule(
     480                            '[data-depend-id="' + depend_id + '"]',
     481                            condition,
     482                            value
     483                        )
     484
     485                        ruleset.include($field)
     486
     487                        if (is_global) {
     488                            global_depends.push(depend_id)
     489                        } else {
     490                            normal_depends.push(depend_id)
     491                        }
     492                    })
     493                })
     494
     495                if (normal_depends.length) {
     496                    $.spf_deps.enable($this, normal_ruleset, normal_depends)
     497                }
     498
     499                if (global_depends.length) {
     500                    $.spf_deps.enable(SPF.vars.$body, global_ruleset, global_depends)
     501                }
     502            }
     503        })
     504    }
     505
     506    //
     507    // Field: code_editor
     508    //
     509    $.fn.spf_field_code_editor = function () {
     510        return this.each(function () {
     511            if (typeof CodeMirror !== 'function') {
     512                return
     513            }
     514
     515            var $this = $(this),
     516                $textarea = $this.find('textarea'),
     517                $inited = $this.find('.CodeMirror'),
     518                data_editor = $textarea.data('editor')
     519
     520            if ($inited.length) {
     521                $inited.remove()
     522            }
     523
     524            var interval = setInterval(function () {
     525                if ($this.is(':visible')) {
     526                    var code_editor = CodeMirror.fromTextArea($textarea[0], data_editor)
     527
     528                    // load code-mirror theme css.
     529                    if (
     530                        data_editor.theme !== 'default' &&
     531                        SPF.vars.code_themes.indexOf(data_editor.theme) === -1
     532                    ) {
     533                        var $cssLink = $('<link>')
     534
     535                        $('#spf-codemirror-css').after($cssLink)
     536
     537                        $cssLink.attr({
     538                            rel: 'stylesheet',
     539                            id: 'spf-codemirror-' + data_editor.theme + '-css',
     540                            href:
     541                                data_editor.cdnURL + '/theme/' + data_editor.theme + '.min.css',
     542                            type: 'text/css',
     543                            media: 'all'
     544                        })
     545
     546                        SPF.vars.code_themes.push(data_editor.theme)
     547                    }
     548
     549                    CodeMirror.modeURL = data_editor.cdnURL + '/mode/%N/%N.min.js'
     550                    CodeMirror.autoLoadMode(code_editor, data_editor.mode)
     551
     552                    code_editor.on('change', function (editor, event) {
     553                        $textarea.val(code_editor.getValue()).trigger('change')
     554                    })
     555
     556                    clearInterval(interval)
     557                }
     558            })
     559        })
     560    }
     561
     562    //
     563    // Field: fieldset
     564    //
     565    $.fn.spf_field_fieldset = function () {
     566        return this.each(function () {
     567            $(this)
     568                .find('.spf-fieldset-content')
     569                .spf_reload_script()
     570        })
     571    }
     572
     573    //
     574    // Field: group
     575    //
     576    $.fn.spf_field_group = function () {
     577        return this.each(function () {
     578            var $this = $(this),
     579                $fieldset = $this.children('.spf-fieldset'),
     580                $group = $fieldset.length ? $fieldset : $this,
     581                $wrapper = $group.children('.spf-cloneable-wrapper'),
     582                $hidden = $group.children('.spf-cloneable-hidden'),
     583                $max = $group.children('.spf-cloneable-max'),
     584                $min = $group.children('.spf-cloneable-min'),
     585                field_id = $wrapper.data('field-id'),
     586                is_number = Boolean(Number($wrapper.data('title-number'))),
     587                max = parseInt($wrapper.data('max')),
     588                min = parseInt($wrapper.data('min'))
     589
     590            // clear accordion arrows if multi-instance
     591            if ($wrapper.hasClass('ui-accordion')) {
     592                $wrapper.find('.ui-accordion-header-icon').remove()
     593            }
     594
     595            var update_title_numbers = function ($selector) {
     596                $selector.find('.spf-cloneable-title-number').each(function (index) {
     597                    $(this).html(
     598                        $(this)
     599                            .closest('.spf-cloneable-item')
     600                            .index() +
     601                        1 +
     602                        '.'
     603                    )
     604                })
     605            }
     606
     607            $wrapper.accordion({
     608                header: '> .spf-cloneable-item > .spf-cloneable-title',
     609                collapsible: true,
     610                active: false,
     611                animate: false,
     612                heightStyle: 'content',
     613                icons: {
     614                    header: 'spf-cloneable-header-icon fas fa-angle-right',
     615                    activeHeader: 'spf-cloneable-header-icon fas fa-angle-down'
     616                },
     617                activate: function (event, ui) {
     618                    var $panel = ui.newPanel
     619                    var $header = ui.newHeader
     620
     621                    if ($panel.length && !$panel.data('opened')) {
     622                        var $fields = $panel.children()
     623                        var $first = $fields
     624                            .first()
     625                            .find(':input')
     626                            .first()
     627                        var $title = $header.find('.spf-cloneable-value')
     628
     629                        $first.on('change keyup', function (event) {
     630                            $title.text($first.val())
     631                        })
     632
     633                        $panel.spf_reload_script()
     634                        $panel.data('opened', true)
     635                        $panel.data('retry', false)
     636                    } else if ($panel.data('retry')) {
     637                        $panel.spf_reload_script_retry()
     638                        $panel.data('retry', false)
     639                    }
     640                }
     641            })
     642
     643            $wrapper.sortable({
     644                axis: 'y',
     645                handle: '.spf-cloneable-title,.spf-cloneable-sort',
     646                helper: 'original',
     647                cursor: 'move',
     648                placeholder: 'widget-placeholder',
     649                start: function (event, ui) {
     650                    $wrapper.accordion({ active: false })
     651                    $wrapper.sortable('refreshPositions')
     652                    ui.item.children('.spf-cloneable-content').data('retry', true)
     653                },
     654                update: function (event, ui) {
     655                    SPF.helper.name_nested_replace(
     656                        $wrapper.children('.spf-cloneable-item'),
     657                        field_id
     658                    )
     659                    //  $wrapper.spf_customizer_refresh()
     660
     661                    if (is_number) {
     662                        update_title_numbers($wrapper)
     663                    }
     664                }
     665            })
     666
     667            $group.children('.spf-cloneable-add').on('click', function (e) {
     668                e.preventDefault()
     669
     670                var count = $wrapper.children('.spf-cloneable-item').length
     671
     672                $min.hide()
     673
     674                if (max && count + 1 > max) {
     675                    $max.show()
     676                    return
     677                }
     678
     679                var $cloned_item = $hidden.spf_clone(true)
     680
     681                $cloned_item.removeClass('spf-cloneable-hidden')
     682
     683                $cloned_item.find(':input[name!="_pseudo"]').each(function () {
     684                    this.name = this.name
     685                        .replace('___', '')
     686                        .replace(field_id + '[0]', field_id + '[' + count + ']')
     687                })
     688
     689                $wrapper.append($cloned_item)
     690                $wrapper.accordion('refresh')
     691                $wrapper.accordion({ active: count })
     692                // $wrapper.spf_customizer_refresh()
     693                //  $wrapper.spf_customizer_listen({ closest: true })
     694
     695                if (is_number) {
     696                    update_title_numbers($wrapper)
     697                }
     698            })
     699
     700            var event_clone = function (e) {
     701                e.preventDefault()
     702
     703                var count = $wrapper.children('.spf-cloneable-item').length
     704
     705                $min.hide()
     706
     707                if (max && count + 1 > max) {
     708                    $max.show()
     709                    return
     710                }
     711
     712                var $this = $(this),
     713                    $parent = $this.parent().parent(),
     714                    $cloned_helper = $parent
     715                        .children('.spf-cloneable-helper')
     716                        .spf_clone(true),
     717                    $cloned_title = $parent.children('.spf-cloneable-title').spf_clone(),
     718                    $cloned_content = $parent
     719                        .children('.spf-cloneable-content')
     720                        .spf_clone(),
     721                    $cloned_item = $('<div class="spf-cloneable-item" />')
     722
     723                $cloned_item.append($cloned_helper)
     724                $cloned_item.append($cloned_title)
     725                $cloned_item.append($cloned_content)
     726
     727                $wrapper
     728                    .children()
     729                    .eq($parent.index())
     730                    .after($cloned_item)
     731
     732                SPF.helper.name_nested_replace(
     733                    $wrapper.children('.spf-cloneable-item'),
     734                    field_id
     735                )
     736
     737                $wrapper.accordion('refresh')
     738                // $wrapper.spf_customizer_refresh()
     739                // $wrapper.spf_customizer_listen({ closest: true })
     740
     741                if (is_number) {
     742                    update_title_numbers($wrapper)
     743                }
     744            }
     745
     746            $wrapper
     747                .children('.spf-cloneable-item')
     748                .children('.spf-cloneable-helper')
     749                .on('click', '.spf-cloneable-clone', event_clone)
     750            $group
     751                .children('.spf-cloneable-hidden')
     752                .children('.spf-cloneable-helper')
     753                .on('click', '.spf-cloneable-clone', event_clone)
     754
     755            var event_remove = function (e) {
     756                e.preventDefault()
     757
     758                var count = $wrapper.children('.spf-cloneable-item').length
     759
     760                $max.hide()
     761                $min.hide()
     762
     763                if (min && count - 1 < min) {
     764                    $min.show()
     765                    return
     766                }
     767
     768                $(this)
     769                    .closest('.spf-cloneable-item')
     770                    .remove()
     771
     772                SPF.helper.name_nested_replace(
     773                    $wrapper.children('.spf-cloneable-item'),
     774                    field_id
     775                )
     776
     777                //$wrapper.spf_customizer_refresh()
     778
     779                if (is_number) {
     780                    update_title_numbers($wrapper)
     781                }
     782            }
     783
     784            $wrapper
     785                .children('.spf-cloneable-item')
     786                .children('.spf-cloneable-helper')
     787                .on('click', '.spf-cloneable-remove', event_remove)
     788            $group
     789                .children('.spf-cloneable-hidden')
     790                .children('.spf-cloneable-helper')
     791                .on('click', '.spf-cloneable-remove', event_remove)
     792        })
     793    }
     794
     795    //
     796    // Field: icon
     797    //
     798    $.fn.spf_field_icon = function () {
     799        return this.each(function () {
     800            var $this = $(this)
     801
     802            $this.on('click', '.spf-icon-add', function (e) {
     803                e.preventDefault()
     804
     805                var $button = $(this)
     806                var $modal = $('#spf-modal-icon')
     807
     808                $modal.removeClass('hidden')
     809
     810                SPF.vars.$icon_target = $this
     811
     812                if (!SPF.vars.icon_modal_loaded) {
     813                    $modal.find('.spf-modal-loading').show()
     814
     815                    window.wp.ajax
     816                        .post('spf-get-icons', {
     817                            nonce: $button.data('nonce')
     818                        })
     819                        .done(function (response) {
     820                            $modal.find('.spf-modal-loading').hide()
     821
     822                            SPF.vars.icon_modal_loaded = true
     823
     824                            var $load = $modal.find('.spf-modal-load').html(response.content)
     825
     826                            $load.on('click', 'i', function (e) {
     827                                e.preventDefault()
     828
     829                                var icon = $(this).attr('title')
     830
     831                                SPF.vars.$icon_target
     832                                    .find('.spf-icon-preview i')
     833                                    .removeAttr('class')
     834                                    .addClass(icon)
     835                                SPF.vars.$icon_target
     836                                    .find('.spf-icon-preview')
     837                                    .removeClass('hidden')
     838                                SPF.vars.$icon_target
     839                                    .find('.spf-icon-remove')
     840                                    .removeClass('hidden')
     841                                SPF.vars.$icon_target
     842                                    .find('input')
     843                                    .val(icon)
     844                                    .trigger('change')
     845
     846                                $modal.addClass('hidden')
     847                            })
     848
     849                            $modal.on('change keyup', '.spf-icon-search', function () {
     850                                var value = $(this).val(),
     851                                    $icons = $load.find('i')
     852
     853                                $icons.each(function () {
     854                                    var $elem = $(this)
     855
     856                                    if ($elem.attr('title').search(new RegExp(value, 'i')) < 0) {
     857                                        $elem.hide()
     858                                    } else {
     859                                        $elem.show()
     860                                    }
     861                                })
     862                            })
     863
     864                            $modal.on(
     865                                'click',
     866                                '.spf-modal-close, .spf-modal-overlay',
     867                                function () {
     868                                    $modal.addClass('hidden')
     869                                }
     870                            )
     871                        })
     872                        .fail(function (response) {
     873                            $modal.find('.spf-modal-loading').hide()
     874                            $modal.find('.spf-modal-load').html(response.error)
     875                            $modal.on('click', function () {
     876                                $modal.addClass('hidden')
     877                            })
     878                        })
     879                }
     880            })
     881
     882            $this.on('click', '.spf-icon-remove', function (e) {
     883                e.preventDefault()
     884                $this.find('.spf-icon-preview').addClass('hidden')
     885                $this
     886                    .find('input')
     887                    .val('')
     888                    .trigger('change')
     889                $(this).addClass('hidden')
     890            })
     891        })
     892    }
     893
     894    //
     895    // Field: repeater
     896    //
     897    $.fn.spf_field_repeater = function () {
     898        return this.each(function () {
     899            var $this = $(this),
     900                $fieldset = $this.children('.spf-fieldset'),
     901                $repeater = $fieldset.length ? $fieldset : $this,
     902                $wrapper = $repeater.children('.spf-repeater-wrapper'),
     903                $hidden = $repeater.children('.spf-repeater-hidden'),
     904                $max = $repeater.children('.spf-repeater-max'),
     905                $min = $repeater.children('.spf-repeater-min'),
     906                field_id = $wrapper.data('field-id'),
     907                max = parseInt($wrapper.data('max')),
     908                min = parseInt($wrapper.data('min'))
     909
     910            $wrapper
     911                .children('.spf-repeater-item')
     912                .children('.spf-repeater-content')
     913                .spf_reload_script()
     914
     915            $wrapper.sortable({
     916                axis: 'y',
     917                handle: '.spf-repeater-sort',
     918                helper: 'original',
     919                cursor: 'move',
     920                placeholder: 'widget-placeholder',
     921                update: function (event, ui) {
     922                    SPF.helper.name_nested_replace(
     923                        $wrapper.children('.spf-repeater-item'),
     924                        field_id
     925                    )
     926                    //  $wrapper.spf_customizer_refresh()
     927                    ui.item.spf_reload_script_retry()
     928                }
     929            })
     930
     931            $repeater.children('.spf-repeater-add').on('click', function (e) {
     932                e.preventDefault()
     933
     934                var count = $wrapper.children('.spf-repeater-item').length
     935
     936                $min.hide()
     937
     938                if (max && count + 1 > max) {
     939                    $max.show()
     940                    return
     941                }
     942
     943                var $cloned_item = $hidden.spf_clone(true)
     944
     945                $cloned_item.removeClass('spf-repeater-hidden')
     946
     947                $cloned_item.find(':input[name!="_pseudo"]').each(function () {
     948                    this.name = this.name
     949                        .replace('___', '')
     950                        .replace(field_id + '[0]', field_id + '[' + count + ']')
     951                })
     952
     953                $wrapper.append($cloned_item)
     954                $cloned_item.children('.spf-repeater-content').spf_reload_script()
     955                // $wrapper.spf_customizer_refresh()
     956                // $wrapper.spf_customizer_listen({ closest: true })
     957            })
     958
     959            var event_clone = function (e) {
     960                e.preventDefault()
     961
     962                var count = $wrapper.children('.spf-repeater-item').length
     963
     964                $min.hide()
     965
     966                if (max && count + 1 > max) {
     967                    $max.show()
     968                    return
     969                }
     970
     971                var $this = $(this),
     972                    $parent = $this
     973                        .parent()
     974                        .parent()
     975                        .parent(),
     976                    $cloned_content = $parent
     977                        .children('.spf-repeater-content')
     978                        .spf_clone(),
     979                    $cloned_helper = $parent
     980                        .children('.spf-repeater-helper')
     981                        .spf_clone(true),
     982                    $cloned_item = $('<div class="spf-repeater-item" />')
     983
     984                $cloned_item.append($cloned_content)
     985                $cloned_item.append($cloned_helper)
     986
     987                $wrapper
     988                    .children()
     989                    .eq($parent.index())
     990                    .after($cloned_item)
     991
     992                $cloned_item.children('.spf-repeater-content').spf_reload_script()
     993
     994                SPF.helper.name_nested_replace(
     995                    $wrapper.children('.spf-repeater-item'),
     996                    field_id
     997                )
     998
     999                // $wrapper.spf_customizer_refresh()
     1000                // $wrapper.spf_customizer_listen({ closest: true })
     1001            }
     1002
     1003            $wrapper
     1004                .children('.spf-repeater-item')
     1005                .children('.spf-repeater-helper')
     1006                .on('click', '.spf-repeater-clone', event_clone)
     1007            $repeater
     1008                .children('.spf-repeater-hidden')
     1009                .children('.spf-repeater-helper')
     1010                .on('click', '.spf-repeater-clone', event_clone)
     1011
     1012            var event_remove = function (e) {
     1013                e.preventDefault()
     1014
     1015                var count = $wrapper.children('.spf-repeater-item').length
     1016
     1017                $max.hide()
     1018                $min.hide()
     1019
     1020                if (min && count - 1 < min) {
     1021                    $min.show()
     1022                    return
     1023                }
     1024
     1025                $(this)
     1026                    .closest('.spf-repeater-item')
     1027                    .remove()
     1028
     1029                SPF.helper.name_nested_replace(
     1030                    $wrapper.children('.spf-repeater-item'),
     1031                    field_id
     1032                )
     1033
     1034                //  $wrapper.spf_customizer_refresh()
     1035            }
     1036
     1037            $wrapper
     1038                .children('.spf-repeater-item')
     1039                .children('.spf-repeater-helper')
     1040                .on('click', '.spf-repeater-remove', event_remove)
     1041            $repeater
     1042                .children('.spf-repeater-hidden')
     1043                .children('.spf-repeater-helper')
     1044                .on('click', '.spf-repeater-remove', event_remove)
     1045        })
     1046    }
     1047
     1048    //
     1049    // Field: slider
     1050    //
     1051    $.fn.spf_field_slider = function () {
     1052        return this.each(function () {
     1053            var $this = $(this),
     1054                $input = $this.find('input'),
     1055                $slider = $this.find('.spf-slider-ui'),
     1056                data = $input.data(),
     1057                value = $input.val() || 0
     1058
     1059            if ($slider.hasClass('ui-slider')) {
     1060                $slider.empty()
     1061            }
     1062
     1063            $slider.slider({
     1064                range: 'min',
     1065                value: value,
     1066                min: data.min || 0,
     1067                max: data.max || 100,
     1068                step: data.step || 1,
     1069                slide: function (e, o) {
     1070                    $input.val(o.value).trigger('change')
     1071                }
     1072            })
     1073
     1074            $input.on('keyup', function () {
     1075                $slider.slider('value', $input.val())
     1076            })
     1077        })
     1078    }
     1079
     1080    //
     1081    // Field: sortable
     1082    //
     1083    $.fn.spf_field_sortable = function () {
     1084        return this.each(function () {
     1085            var $sortable = $(this).find('.spf-sortable')
     1086
     1087            $sortable.sortable({
     1088                axis: 'y',
     1089                helper: 'original',
     1090                cursor: 'move',
     1091                placeholder: 'widget-placeholder',
     1092                update: function (event, ui) {
     1093                    // $sortable.spf_customizer_refresh()
     1094                }
     1095            })
     1096
     1097            $sortable.find('.spf-sortable-content').spf_reload_script()
     1098        })
     1099    }
     1100
     1101    //
     1102    // Field: sorter
     1103    //
     1104    $.fn.spf_field_sorter = function () {
     1105        return this.each(function () {
     1106            var $this = $(this),
     1107                $enabled = $this.find('.spf-enabled'),
     1108                $has_disabled = $this.find('.spf-disabled'),
     1109                $disabled = $has_disabled.length ? $has_disabled : false
     1110
     1111            $enabled.sortable({
     1112                connectWith: $disabled,
     1113                placeholder: 'ui-sortable-placeholder',
     1114                update: function (event, ui) {
     1115                    var $el = ui.item.find('input')
     1116
     1117                    if (ui.item.parent().hasClass('spf-enabled')) {
     1118                        $el.attr('name', $el.attr('name').replace('disabled', 'enabled'))
     1119                    } else {
     1120                        $el.attr('name', $el.attr('name').replace('enabled', 'disabled'))
     1121                    }
     1122
     1123                    //  $this.spf_customizer_refresh()
     1124                }
     1125            })
     1126
     1127            if ($disabled) {
     1128                $disabled.sortable({
     1129                    connectWith: $enabled,
     1130                    placeholder: 'ui-sortable-placeholder',
     1131                    update: function (event, ui) {
     1132                        // $this.spf_customizer_refresh()
     1133                    }
     1134                })
     1135            }
     1136        })
     1137    }
     1138
     1139    //
     1140    // Field: spinner
     1141    //
     1142    $.fn.spf_field_spinner = function () {
     1143        return this.each(function () {
     1144            var $this = $(this),
     1145                $input = $this.find('input'),
     1146                $inited = $this.find('.ui-button'),
     1147                // $inited = $this.find('.ui-spinner-button'),
     1148                data = $input.data()
     1149
     1150            if ($inited.length) {
     1151                $inited.remove()
     1152            }
     1153
     1154            $input.spinner({
     1155                min: data.min || 0,
     1156                max: data.max || 100,
     1157                step: data.step || 1,
     1158                create: function (event, ui) {
     1159                    if (data.unit) {
     1160                        $input.after(
     1161                            '<span class="ui-button spf--unit">' + data.unit + '</span>'
     1162                        )
     1163                    }
     1164                },
     1165                spin: function (event, ui) {
     1166                    $input.val(ui.value).trigger('change')
     1167                }
     1168            })
     1169        })
     1170    }
     1171
     1172    //
     1173    // Field: switcher
     1174    //
     1175    $.fn.spf_field_switcher = function () {
     1176        return this.each(function () {
     1177            var $switcher = $(this).find('.spf--switcher')
     1178
     1179            $switcher.on('click', function () {
     1180                var value = 0
     1181                var $input = $switcher.find('input')
     1182
     1183                if ($switcher.hasClass('spf--active')) {
     1184                    $switcher.removeClass('spf--active')
     1185                } else {
     1186                    value = 1
     1187                    $switcher.addClass('spf--active')
     1188                }
     1189
     1190                $input.val(value).trigger('change')
     1191            })
     1192        })
     1193    }
     1194
     1195    //
     1196    // Field: tabbed
     1197    //
     1198    $.fn.spf_field_tabbed = function () {
     1199        return this.each(function () {
     1200            var $this = $(this),
     1201                $links = $this.find('.spf-tabbed-nav a'),
     1202                $contents = $this.find('.spf-tabbed-content')
     1203
     1204            $contents.eq(0).spf_reload_script()
     1205
     1206            $links.on('click', function (e) {
     1207                e.preventDefault()
     1208
     1209                var $link = $(this),
     1210                    index = $link.index(),
     1211                    $content = $contents.eq(index)
     1212
     1213                $link
     1214                    .addClass('spf-tabbed-active')
     1215                    .siblings()
     1216                    .removeClass('spf-tabbed-active')
     1217                $content.spf_reload_script()
     1218                $content
     1219                    .removeClass('hidden')
     1220                    .siblings()
     1221                    .addClass('hidden')
     1222            })
     1223        })
     1224    }
     1225
     1226    //
     1227    // Field: upload
     1228    //
     1229    $.fn.spf_field_upload = function () {
     1230        return this.each(function () {
     1231            var $this = $(this),
     1232                $input = $this.find('input'),
     1233                $upload_button = $this.find('.spf--button'),
     1234                $remove_button = $this.find('.spf--remove'),
     1235                $library =
     1236                    ($upload_button.data('library') &&
     1237                        $upload_button.data('library').split(',')) ||
     1238                    '',
     1239                wp_media_frame
     1240
     1241            $input.on('change', function (e) {
     1242                if ($input.val()) {
     1243                    $remove_button.removeClass('hidden')
     1244                } else {
     1245                    $remove_button.addClass('hidden')
     1246                }
     1247            })
     1248
     1249            $upload_button.on('click', function (e) {
     1250                e.preventDefault()
     1251
     1252                if (
     1253                    typeof window.wp === 'undefined' ||
     1254                    !window.wp.media ||
     1255                    !window.wp.media.gallery
     1256                ) {
     1257                    return
     1258                }
     1259
     1260                if (wp_media_frame) {
     1261                    wp_media_frame.open()
     1262                    return
     1263                }
     1264
     1265                wp_media_frame = window.wp.media({
     1266                    library: {
     1267                        type: $library
     1268                    }
     1269                })
     1270
     1271                wp_media_frame.on('select', function () {
     1272                    var attributes = wp_media_frame
     1273                        .state()
     1274                        .get('selection')
     1275                        .first().attributes
     1276
     1277                    if (
     1278                        $library.length &&
     1279                        $library.indexOf(attributes.subtype) === -1 &&
     1280                        $library.indexOf(attributes.type) === -1
     1281                    ) {
     1282                        return
     1283                    }
     1284
     1285                    $input.val(attributes.url).trigger('change')
     1286                })
     1287
     1288                wp_media_frame.open()
     1289            })
     1290
     1291            $remove_button.on('click', function (e) {
     1292                e.preventDefault()
     1293                $input.val('').trigger('change')
     1294            })
     1295        })
     1296    }
     1297
     1298    //
     1299    // Confirm
     1300    //
     1301    $.fn.spf_confirm = function () {
     1302        return this.each(function () {
     1303            $(this).on('click', function (e) {
     1304                var confirm_text =
     1305                    $(this).data('confirm') || window.spf_vars.i18n.confirm
     1306                var confirm_answer = confirm(confirm_text)
     1307
     1308                if (confirm_answer) {
     1309                    SPF.vars.is_confirm = true
     1310                    SPF.vars.form_modified = false
     1311                } else {
     1312                    e.preventDefault()
     1313                    return false
     1314                }
     1315            })
     1316        })
     1317    }
     1318
     1319    $.fn.serializeObject = function () {
     1320        var obj = {}
     1321
     1322        $.each(this.serializeArray(), function (i, o) {
     1323            var n = o.name,
     1324                v = o.value
     1325
     1326            obj[n] =
     1327                obj[n] === undefined
     1328                    ? v
     1329                    : $.isArray(obj[n])
     1330                        ? obj[n].concat(v)
     1331                        : [obj[n], v]
     1332        })
     1333
     1334        return obj
     1335    }
     1336
     1337    //
     1338    // Options Save
     1339    //
     1340    $.fn.spf_save = function () {
     1341        return this.each(function () {
     1342            var $this = $(this),
     1343                $buttons = $('.spf-save'),
     1344                $panel = $('.spf-options'),
     1345                flooding = false,
     1346                timeout
     1347
     1348            $this.on('click', function (e) {
     1349                if (!flooding) {
     1350                    var $text = $this.data('save'),
     1351                        $value = $this.val()
     1352
     1353                    $buttons.attr('value', $text)
     1354
     1355                    if ($this.hasClass('spf-save-ajax')) {
     1356                        e.preventDefault()
     1357
     1358                        $panel.addClass('spf-saving')
     1359                        $buttons.prop('disabled', true)
     1360
     1361                        window.wp.ajax
     1362                            .post('spf_' + $panel.data('unique') + '_ajax_save', {
     1363                                data: $('#spf-form').serializeJSONSPF()
     1364                            })
     1365                            .done(function (response) {
     1366                                // clear errors
     1367                                $('.spf-error').remove()
     1368
     1369                                if (Object.keys(response.errors).length) {
     1370                                    var error_icon = '<i class="spf-label-error spf-error">!</i>'
     1371
     1372                                    $.each(response.errors, function (key, error_message) {
     1373                                        var $field = $('[data-depend-id="' + key + '"]'),
     1374                                            $link = $(
     1375                                                '#spf-tab-link-' +
     1376                                                ($field.closest('.spf-section').index() + 1)
     1377                                            ),
     1378                                            $tab = $link.closest('.spf-tab-depth-0')
     1379
     1380                                        $field
     1381                                            .closest('.spf-fieldset')
     1382                                            .append(
     1383                                                '<p class="spf-error spf-error-text">' +
     1384                                                error_message +
     1385                                                '</p>'
     1386                                            )
     1387
     1388                                        if (!$link.find('.spf-error').length) {
     1389                                            $link.append(error_icon)
     1390                                        }
     1391
     1392                                        if (!$tab.find('.spf-arrow .spf-error').length) {
     1393                                            $tab.find('.spf-arrow').append(error_icon)
     1394                                        }
     1395                                    })
     1396                                }
     1397
     1398                                $panel.removeClass('spf-saving')
     1399                                $buttons.prop('disabled', false).attr('value', $value)
     1400                                flooding = false
     1401
     1402                                SPF.vars.form_modified = false
     1403                                SPF.vars.$form_warning.hide()
     1404
     1405                                clearTimeout(timeout)
     1406
     1407                                var $result_success = $('.spf-form-success')
     1408                                $result_success
     1409                                    .empty()
     1410                                    .append(response.notice)
     1411                                    .fadeIn('fast', function () {
     1412                                        timeout = setTimeout(function () {
     1413                                            $result_success.fadeOut('fast')
     1414                                        }, 1000)
     1415                                    })
     1416                            })
     1417                            .fail(function (response) {
     1418                                alert(response.error)
     1419                            })
     1420                    } else {
     1421                        SPF.vars.form_modified = false
     1422                    }
     1423                }
     1424
     1425                flooding = true
     1426            })
     1427        })
     1428    }
     1429
     1430    //
     1431    // Option Framework
     1432    //
     1433    $.fn.spf_options = function () {
     1434        return this.each(function () {
     1435            var $this = $(this),
     1436                $content = $this.find('.spf-content'),
     1437                $form_success = $this.find('.spf-form-success'),
     1438                $form_warning = $this.find('.spf-form-warning'),
     1439                $save_button = $this.find('.spf-header .spf-save')
     1440
     1441            SPF.vars.$form_warning = $form_warning
     1442
     1443            // Shows a message white leaving theme options without saving
     1444            if ($form_warning.length) {
     1445                window.onbeforeunload = function () {
     1446                    return SPF.vars.form_modified ? true : undefined
     1447                }
     1448
     1449                $content.on('change keypress', ':input', function () {
     1450                    if (!SPF.vars.form_modified) {
     1451                        $form_success.hide()
     1452                        $form_warning.fadeIn('fast')
     1453                        SPF.vars.form_modified = true
     1454                    }
     1455                })
     1456            }
     1457
     1458            if ($form_success.hasClass('spf-form-show')) {
     1459                setTimeout(function () {
     1460                    $form_success.fadeOut('fast')
     1461                }, 1000)
     1462            }
     1463
     1464            $(document).keydown(function (event) {
     1465                if ((event.ctrlKey || event.metaKey) && event.which === 83) {
     1466                    $save_button.trigger('click')
     1467                    event.preventDefault()
     1468                    return false
     1469                }
     1470            })
     1471        })
     1472    }
     1473
     1474    //
     1475    // Taxonomy Framework
     1476    //
     1477    $.fn.spf_taxonomy = function () {
     1478        return this.each(function () {
     1479            var $this = $(this),
     1480                $form = $this.parents('form')
     1481
     1482            if ($form.attr('id') === 'addtag') {
     1483                var $submit = $form.find('#submit'),
     1484                    $cloned = $this.find('.spf-field').spf_clone()
     1485
     1486                $submit.on('click', function () {
     1487                    if (!$form.find('.form-required').hasClass('form-invalid')) {
     1488                        $this.data('inited', false)
     1489
     1490                        $this.empty()
     1491
     1492                        $this.html($cloned)
     1493
     1494                        $cloned = $cloned.spf_clone()
     1495
     1496                        $this.spf_reload_script()
     1497                    }
     1498                })
     1499            }
     1500        })
     1501    }
     1502
     1503    //
     1504    // Shortcode Framework
     1505    //
     1506    $.fn.spf_shortcode = function () {
     1507        var base = this
     1508
     1509        base.shortcode_parse = function (serialize, key) {
     1510            var shortcode = ''
     1511
     1512            $.each(serialize, function (shortcode_key, shortcode_values) {
     1513                key = key ? key : shortcode_key
     1514
     1515                shortcode += '[' + key
     1516
     1517                $.each(shortcode_values, function (shortcode_tag, shortcode_value) {
     1518                    if (shortcode_tag === 'content') {
     1519                        shortcode += ']'
     1520                        shortcode += shortcode_value
     1521                        shortcode += '[/' + key + ''
     1522                    } else {
     1523                        shortcode += base.shortcode_tags(shortcode_tag, shortcode_value)
     1524                    }
     1525                })
     1526
     1527                shortcode += ']'
     1528            })
     1529
     1530            return shortcode
     1531        }
     1532
     1533        base.shortcode_tags = function (shortcode_tag, shortcode_value) {
     1534            var shortcode = ''
     1535
     1536            if (shortcode_value !== '') {
     1537                if (
     1538                    typeof shortcode_value === 'object' &&
     1539                    !$.isArray(shortcode_value)
     1540                ) {
     1541                    $.each(shortcode_value, function (
     1542                        sub_shortcode_tag,
     1543                        sub_shortcode_value
     1544                    ) {
     1545                        // sanitize spesific key/value
     1546                        switch (sub_shortcode_tag) {
     1547                            case 'background-image':
     1548                                sub_shortcode_value = sub_shortcode_value.url
     1549                                    ? sub_shortcode_value.url
     1550                                    : ''
     1551                                break
     1552                        }
     1553
     1554                        if (sub_shortcode_value !== '') {
     1555                            shortcode +=
     1556                                ' ' +
     1557                                sub_shortcode_tag.replace('-', '_') +
     1558                                '="' +
     1559                                sub_shortcode_value.toString() +
     1560                                '"'
     1561                        }
     1562                    })
     1563                } else {
     1564                    shortcode +=
     1565                        ' ' +
     1566                        shortcode_tag.replace('-', '_') +
     1567                        '="' +
     1568                        shortcode_value.toString() +
     1569                        '"'
     1570                }
     1571            }
     1572
     1573            return shortcode
     1574        }
     1575
     1576        base.insertAtChars = function (_this, currentValue) {
     1577            var obj = typeof _this[0].name !== 'undefined' ? _this[0] : _this
     1578
     1579            if (obj.value.length && typeof obj.selectionStart !== 'undefined') {
     1580                obj.focus()
     1581                return (
     1582                    obj.value.substring(0, obj.selectionStart) +
     1583                    currentValue +
     1584                    obj.value.substring(obj.selectionEnd, obj.value.length)
     1585                )
     1586            } else {
     1587                obj.focus()
     1588                return currentValue
     1589            }
     1590        }
     1591
     1592        base.send_to_editor = function (html, editor_id) {
     1593            var tinymce_editor
     1594
     1595            if (typeof tinymce !== 'undefined') {
     1596                tinymce_editor = tinymce.get(editor_id)
     1597            }
     1598
     1599            if (tinymce_editor && !tinymce_editor.isHidden()) {
     1600                tinymce_editor.execCommand('mceInsertContent', false, html)
     1601            } else {
     1602                var $editor = $('#' + editor_id)
     1603                $editor.val(base.insertAtChars($editor, html)).trigger('change')
     1604            }
     1605        }
     1606
     1607        return this.each(function () {
     1608            var $modal = $(this),
     1609                $load = $modal.find('.spf-modal-load'),
     1610                $content = $modal.find('.spf-modal-content'),
     1611                $insert = $modal.find('.spf-modal-insert'),
     1612                $loading = $modal.find('.spf-modal-loading'),
     1613                $select = $modal.find('select'),
     1614                modal_id = $modal.data('modal-id'),
     1615                nonce = $modal.data('nonce'),
     1616                editor_id,
     1617                target_id,
     1618                sc_key,
     1619                sc_name,
     1620                sc_view,
     1621                sc_group,
     1622                $cloned,
     1623                $button
     1624
     1625            $(document).on(
     1626                'click',
     1627                '.spf-shortcode-button[data-modal-id="' + modal_id + '"]',
     1628                function (e) {
     1629                    e.preventDefault()
     1630
     1631                    $button = $(this)
     1632                    editor_id = $button.data('editor-id') || false
     1633                    target_id = $button.data('target-id') || false
     1634
     1635                    $modal.removeClass('hidden')
     1636
     1637                    // single usage trigger first shortcode
     1638                    if (
     1639                        $modal.hasClass('spf-shortcode-single') &&
     1640                        sc_name === undefined
     1641                    ) {
     1642                        $select.trigger('change')
     1643                    }
     1644                }
     1645            )
     1646
     1647            $select.on('change', function () {
     1648                var $option = $(this)
     1649                var $selected = $option.find(':selected')
     1650
     1651                sc_key = $option.val()
     1652                sc_name = $selected.data('shortcode')
     1653                sc_view = $selected.data('view') || 'normal'
     1654                sc_group = $selected.data('group') || sc_name
     1655
     1656                $load.empty()
     1657
     1658                if (sc_key) {
     1659                    $loading.show()
     1660
     1661                    window.wp.ajax
     1662                        .post('spf-get-shortcode-' + modal_id, {
     1663                            shortcode_key: sc_key,
     1664                            nonce: nonce
     1665                        })
     1666                        .done(function (response) {
     1667                            $loading.hide()
     1668
     1669                            var $appended = $(response.content).appendTo($load)
     1670
     1671                            $insert.parent().removeClass('hidden')
     1672
     1673                            $cloned = $appended.find('.spf--repeat-shortcode').spf_clone()
     1674
     1675                            $appended.spf_reload_script()
     1676                            $appended.find('.spf-fields').spf_reload_script()
     1677                        })
     1678                } else {
     1679                    $insert.parent().addClass('hidden')
     1680                }
     1681            })
     1682
     1683            $insert.on('click', function (e) {
     1684                e.preventDefault()
     1685
     1686                if ($insert.prop('disabled') || $insert.attr('disabled')) {
     1687                    return
     1688                }
     1689
     1690                var shortcode = ''
     1691                var serialize = $modal
     1692                    .find('.spf-field:not(.spf-depend-on)')
     1693                    .find(':input:not(.ignore)')
     1694                    .serializeObjectSPF()
     1695
     1696                switch (sc_view) {
     1697                    case 'contents':
     1698                        var contentsObj = sc_name ? serialize[sc_name] : serialize
     1699                        $.each(contentsObj, function (sc_key, sc_value) {
     1700                            var sc_tag = sc_name ? sc_name : sc_key
     1701                            shortcode += '[' + sc_tag + ']' + sc_value + '[/' + sc_tag + ']'
     1702                        })
     1703                        break
     1704
     1705                    case 'group':
     1706                        shortcode += '[' + sc_name
     1707                        $.each(serialize[sc_name], function (sc_key, sc_value) {
     1708                            shortcode += base.shortcode_tags(sc_key, sc_value)
     1709                        })
     1710                        shortcode += ']'
     1711                        shortcode += base.shortcode_parse(serialize[sc_group], sc_group)
     1712                        shortcode += '[/' + sc_name + ']'
     1713
     1714                        break
     1715
     1716                    case 'repeater':
     1717                        shortcode += base.shortcode_parse(serialize[sc_group], sc_group)
     1718                        break
     1719
     1720                    default:
     1721                        shortcode += base.shortcode_parse(serialize)
     1722                        break
     1723                }
     1724
     1725                shortcode = shortcode === '' ? '[' + sc_name + ']' : shortcode
     1726
     1727                if (editor_id) {
     1728                    base.send_to_editor(shortcode, editor_id)
     1729                } else {
     1730                    var $textarea = target_id
     1731                        ? $(target_id)
     1732                        : $button.parent().find('textarea')
     1733                    $textarea
     1734                        .val(base.insertAtChars($textarea, shortcode))
     1735                        .trigger('change')
     1736                }
     1737
     1738                $modal.addClass('hidden')
     1739            })
     1740
     1741            $modal.on('click', '.spf--repeat-button', function (e) {
     1742                e.preventDefault()
     1743
     1744                var $repeatable = $modal.find('.spf--repeatable')
     1745                var $new_clone = $cloned.spf_clone()
     1746                var $remove_btn = $new_clone.find('.spf-repeat-remove')
     1747
     1748                var $appended = $new_clone.appendTo($repeatable)
     1749
     1750                $new_clone.find('.spf-fields').spf_reload_script()
     1751
     1752                SPF.helper.name_nested_replace(
     1753                    $modal.find('.spf--repeat-shortcode'),
     1754                    sc_group
     1755                )
     1756
     1757                $remove_btn.on('click', function () {
     1758                    $new_clone.remove()
     1759
     1760                    SPF.helper.name_nested_replace(
     1761                        $modal.find('.spf--repeat-shortcode'),
     1762                        sc_group
     1763                    )
     1764                })
     1765            })
     1766
     1767            $modal.on('click', '.spf-modal-close, .spf-modal-overlay', function () {
     1768                $modal.addClass('hidden')
     1769            })
     1770        })
     1771    }
     1772
     1773    //
     1774    // WP Color Picker
     1775    //
     1776    if (typeof Color === 'function') {
     1777        Color.prototype.toString = function () {
     1778            if (this._alpha < 1) {
     1779                return this.toCSS('rgba', this._alpha).replace(/\s+/g, '')
     1780            }
     1781
     1782            var hex = parseInt(this._color, 10).toString(16)
     1783
     1784            if (this.error) {
     1785                return ''
     1786            }
     1787
     1788            if (hex.length < 6) {
     1789                for (var i = 6 - hex.length - 1; i >= 0; i--) {
     1790                    hex = '0' + hex
     1791                }
     1792            }
     1793
     1794            return '#' + hex
     1795        }
     1796    }
     1797
     1798    SPF.funcs.parse_color = function (color) {
     1799        var value = color.replace(/\s+/g, ''),
     1800            trans =
     1801                value.indexOf('rgba') !== -1
     1802                    ? parseFloat(value.replace(/^.*,(.+)\)/, '$1') * 100)
     1803                    : 100,
     1804            rgba = trans < 100 ? true : false
     1805
     1806        return { value: value, transparent: trans, rgba: rgba }
     1807    }
     1808
     1809    $.fn.spf_color = function () {
     1810        return this.each(function () {
     1811            var $input = $(this),
     1812                picker_color = SPF.funcs.parse_color($input.val()),
     1813                palette_color = window.spf_vars.color_palette.length
     1814                    ? window.spf_vars.color_palette
     1815                    : true,
     1816                $container
     1817
     1818            // Destroy and Reinit
     1819            if ($input.hasClass('wp-color-picker')) {
     1820                $input
     1821                    .closest('.wp-picker-container')
     1822                    .after($input)
     1823                    .remove()
     1824            }
     1825
     1826            $input.wpColorPicker({
     1827                palettes: palette_color,
     1828                change: function (event, ui) {
     1829                    var ui_color_value = ui.color.toString()
     1830
     1831                    $container.removeClass('spf--transparent-active')
     1832                    $container
     1833                        .find('.spf--transparent-offset')
     1834                        .css('background-color', ui_color_value)
     1835                    $input.val(ui_color_value).trigger('change')
     1836                },
     1837                create: function () {
     1838                    $container = $input.closest('.wp-picker-container')
     1839
     1840                    var a8cIris = $input.data('a8cIris'),
     1841                        $transparent_wrap = $(
     1842                            '<div class="spf--transparent-wrap">' +
     1843                            '<div class="spf--transparent-slider"></div>' +
     1844                            '<div class="spf--transparent-offset"></div>' +
     1845                            '<div class="spf--transparent-text"></div>' +
     1846                            '<div class="spf--transparent-button">transparent <i class="fas fa-toggle-off"></i></div>' +
     1847                            '</div>'
     1848                        ).appendTo($container.find('.wp-picker-holder')),
     1849                        $transparent_slider = $transparent_wrap.find(
     1850                            '.spf--transparent-slider'
     1851                        ),
     1852                        $transparent_text = $transparent_wrap.find(
     1853                            '.spf--transparent-text'
     1854                        ),
     1855                        $transparent_offset = $transparent_wrap.find(
     1856                            '.spf--transparent-offset'
     1857                        ),
     1858                        $transparent_button = $transparent_wrap.find(
     1859                            '.spf--transparent-button'
     1860                        )
     1861
     1862                    if ($input.val() === 'transparent') {
     1863                        $container.addClass('spf--transparent-active')
     1864                    }
     1865
     1866                    $transparent_button.on('click', function () {
     1867                        if ($input.val() !== 'transparent') {
     1868                            $input
     1869                                .val('transparent')
     1870                                .trigger('change')
     1871                                .removeClass('iris-error')
     1872                            $container.addClass('spf--transparent-active')
     1873                        } else {
     1874                            $input.val(a8cIris._color.toString()).trigger('change')
     1875                            $container.removeClass('spf--transparent-active')
     1876                        }
     1877                    })
     1878
     1879                    $transparent_slider.slider({
     1880                        value: picker_color.transparent,
     1881                        step: 1,
     1882                        min: 0,
     1883                        max: 100,
     1884                        slide: function (event, ui) {
     1885                            var slide_value = parseFloat(ui.value / 100)
     1886                            a8cIris._color._alpha = slide_value
     1887                            $input.wpColorPicker('color', a8cIris._color.toString())
     1888                            $transparent_text.text(
     1889                                slide_value === 1 || slide_value === 0 ? '' : slide_value
     1890                            )
     1891                        },
     1892                        create: function () {
     1893                            var slide_value = parseFloat(picker_color.transparent / 100),
     1894                                text_value = slide_value < 1 ? slide_value : ''
     1895
     1896                            $transparent_text.text(text_value)
     1897                            $transparent_offset.css('background-color', picker_color.value)
     1898
     1899                            $container.on('click', '.wp-picker-clear', function () {
     1900                                a8cIris._color._alpha = 1
     1901                                $transparent_text.text('')
     1902                                $transparent_slider.slider('option', 'value', 100)
     1903                                $container.removeClass('spf--transparent-active')
     1904                                $input.trigger('change')
     1905                            })
     1906
     1907                            $container.on('click', '.wp-picker-default', function () {
     1908                                var default_color = SPF.funcs.parse_color(
     1909                                    $input.data('default-color')
     1910                                ),
     1911                                    default_value = parseFloat(default_color.transparent / 100),
     1912                                    default_text = default_value < 1 ? default_value : ''
     1913
     1914                                a8cIris._color._alpha = default_value
     1915                                $transparent_text.text(default_text)
     1916                                $transparent_slider.slider(
     1917                                    'option',
     1918                                    'value',
     1919                                    default_color.transparent
     1920                                )
     1921
     1922                                if (default_color.value === 'transparent') {
     1923                                    $input.removeClass('iris-error')
     1924                                    $container.addClass('spf--transparent-active')
     1925                                }
     1926                            })
     1927                        }
     1928                    })
     1929                }
     1930            })
     1931        })
     1932    }
     1933
     1934    //
     1935    // ChosenJS
     1936    //
     1937    $.fn.spf_chosen = function () {
     1938        return this.each(function () {
     1939            var $this = $(this),
     1940                $inited = $this.parent().find('.chosen-container'),
     1941                is_sortable = $this.hasClass('spf-chosen-sortable') || false,
     1942                is_ajax = $this.hasClass('spf-chosen-ajax') || false,
     1943                is_multiple = $this.attr('multiple') || false,
     1944                set_width = is_multiple ? '100%' : 'auto',
     1945                set_options = $.extend(
     1946                    {
     1947                        allow_single_deselect: true,
     1948                        disable_search_threshold: 10,
     1949                        width: set_width,
     1950                        no_results_text: window.spf_vars.i18n.no_results_text
     1951                    },
     1952                    $this.data('chosen-settings')
     1953                )
     1954
     1955            if ($inited.length) {
     1956                $inited.remove()
     1957            }
     1958
     1959            // Chosen ajax
     1960            if (is_ajax) {
     1961                var set_ajax_options = $.extend(
     1962                    {
     1963                        data: {
     1964                            type: 'post',
     1965                            nonce: ''
     1966                        },
     1967                        allow_single_deselect: true,
     1968                        disable_search_threshold: -1,
     1969                        width: '100%',
     1970                        min_length: 3,
     1971                        type_delay: 500,
     1972                        typing_text: window.spf_vars.i18n.typing_text,
     1973                        searching_text: window.spf_vars.i18n.searching_text,
     1974                        no_results_text: window.spf_vars.i18n.no_results_text
     1975                    },
     1976                    $this.data('chosen-settings')
     1977                )
     1978
     1979                $this.SPFAjaxChosen(set_ajax_options)
     1980            } else {
     1981                $this.chosen(set_options)
     1982            }
     1983
     1984            // Chosen keep options order
     1985            if (is_multiple) {
     1986                var $hidden_select = $this.parent().find('.spf-hide-select')
     1987                var $hidden_value = $hidden_select.val() || []
     1988
     1989                $this.on('change', function (obj, result) {
     1990                    if (result && result.selected) {
     1991                        $hidden_select.append(
     1992                            '<option value="' +
     1993                            result.selected +
     1994                            '" selected="selected">' +
     1995                            result.selected +
     1996                            '</option>'
     1997                        )
     1998                    } else if (result && result.deselected) {
     1999                        $hidden_select
     2000                            .find('option[value="' + result.deselected + '"]')
     2001                            .remove()
     2002                    }
     2003
     2004                    // Force customize refresh
     2005                    if (
     2006                        window.wp.customize !== undefined &&
     2007                        $hidden_select.children().length === 0 &&
     2008                        $hidden_select.data('customize-setting-link')
     2009                    ) {
     2010                        window.wp.customize
     2011                            .control($hidden_select.data('customize-setting-link'))
     2012                            .setting.set('')
     2013                    }
     2014
     2015                    $hidden_select.trigger('change')
     2016                })
     2017                SPF
     2018
     2019                // Chosen order abstract
     2020                $this.CSFChosenOrder($hidden_value, true)
     2021            }
     2022
     2023            // Chosen sortable
     2024            if (is_sortable) {
     2025                var $chosen_container = $this.parent().find('.chosen-container')
     2026                var $chosen_choices = $chosen_container.find('.chosen-choices')
     2027
     2028                $chosen_choices.bind('mousedown', function (event) {
     2029                    if ($(event.target).is('span')) {
     2030                        event.stopPropagation()
     2031                    }
     2032                })
     2033
     2034                $chosen_choices.sortable({
     2035                    items: 'li:not(.search-field)',
     2036                    helper: 'orginal',
     2037                    cursor: 'move',
     2038                    placeholder: 'search-choice-placeholder',
     2039                    start: function (e, ui) {
     2040                        ui.placeholder.width(ui.item.innerWidth())
     2041                        ui.placeholder.height(ui.item.innerHeight())
     2042                    },
     2043                    update: function (e, ui) {
     2044                        var select_options = ''
     2045                        var chosen_object = $this.data('chosen')
     2046                        var $prev_select = $this.parent().find('.spf-hide-select')
     2047
     2048                        $chosen_choices.find('.search-choice-close').each(function () {
     2049                            var option_array_index = $(this).data('option-array-index')
     2050                            $.each(chosen_object.results_data, function (index, data) {
     2051                                if (data.array_index === option_array_index) {
     2052                                    select_options +=
     2053                                        '<option value="' +
     2054                                        data.value +
     2055                                        '" selected>' +
     2056                                        data.value +
     2057                                        '</option>'
     2058                                }
     2059                            })
     2060                        })
     2061
     2062                        $prev_select.children().remove()
     2063                        $prev_select.append(select_options)
     2064                        $prev_select.trigger('change')
     2065                    }
     2066                })
     2067            }
     2068        })
     2069    }
     2070
     2071    //
     2072    // Helper Checkbox Checker
     2073    //
     2074    $.fn.spf_checkbox = function () {
     2075        return this.each(function () {
     2076            var $this = $(this),
     2077                $input = $this.find('.spf--input'),
     2078                $checkbox = $this.find('.spf--checkbox')
     2079
     2080            $checkbox.on('click', function () {
     2081                $input.val(Number($checkbox.prop('checked'))).trigger('change')
     2082            })
     2083        })
     2084    }
     2085
     2086    //
     2087    // Siblings
     2088    //
     2089    $.fn.spf_siblings = function () {
     2090        return this.each(function () {
     2091            var $this = $(this),
     2092                $siblings = $this.find('.spf--sibling'),
     2093                multiple = $this.data('multiple') || false
     2094
     2095            $siblings.on('click', function () {
     2096                var $sibling = $(this)
     2097
     2098                if (multiple) {
     2099                    if ($sibling.hasClass('spf--active')) {
     2100                        $sibling.removeClass('spf--active')
     2101                        $sibling
     2102                            .find('input')
     2103                            .prop('checked', false)
     2104                            .trigger('change')
     2105                    } else {
     2106                        $sibling.addClass('spf--active')
     2107                        $sibling
     2108                            .find('input')
     2109                            .prop('checked', true)
     2110                            .trigger('change')
     2111                    }
     2112                } else {
     2113                    $this.find('input').prop('checked', false)
     2114                    $sibling
     2115                        .find('input')
     2116                        .prop('checked', true)
     2117                        .trigger('change')
     2118                    $sibling
     2119                        .addClass('spf--active')
     2120                        .siblings()
     2121                        .removeClass('spf--active')
     2122                }
     2123            })
     2124        })
     2125    }
     2126
     2127    //
     2128    // Help Tooltip
     2129    //
     2130    $.fn.spf_help = function () {
     2131        return this.each(function () {
     2132            var $this = $(this),
     2133                $tooltip,
     2134                offset_left
     2135
     2136            $this.on({
     2137                mouseenter: function () {
     2138                    $tooltip = $('<div class="spf-tooltip"></div>')
     2139                        .html($this.find('.spf-help-text').html())
     2140                        .appendTo('body')
     2141
     2142                    offset_left = SPF.vars.is_rtl
     2143                        ? $this.offset().left - 230
     2144                        : $this.offset().left + 24
     2145
     2146                    $tooltip.css({
     2147                        top: $this.offset().top - ($tooltip.outerHeight() / 2 - 14),
     2148                        left: offset_left,
     2149                        textAlign: SPF.vars.is_rtl ? 'right' : 'left'
     2150                    })
     2151                },
     2152                mouseleave: function () {
     2153                    if ($tooltip !== undefined) {
     2154                        $tooltip.remove()
     2155                    }
     2156                }
     2157            })
     2158        })
     2159    }
     2160
     2161    //
     2162    // Window on resize
     2163    //
     2164    SPF.vars.$window
     2165        .on(
     2166            'resize spf.resize',
     2167            SPF.helper.debounce(function (event) {
     2168                var window_width =
     2169                    navigator.userAgent.indexOf('AppleWebKit/') > -1
     2170                        ? SPF.vars.$window.width()
     2171                        : window.innerWidth
     2172
     2173                if (window_width <= 782 && !SPF.vars.onloaded) {
     2174                    $('.spf-section').spf_reload_script()
     2175                    SPF.vars.onloaded = true
     2176                }
     2177            }, 200)
     2178        )
     2179        .trigger('spf.resize')
     2180
     2181    //
     2182    // Widgets Framework
     2183    //
     2184    $.fn.spf_widgets = function () {
     2185        if (this.length) {
     2186            $(document).on('widget-added widget-updated', function (event, $widget) {
     2187                $widget.find('.spf-fields').spf_reload_script()
     2188            })
     2189
     2190            $('.widgets-sortables, .control-section-sidebar').on(
     2191                'sortstop',
     2192                function (event, ui) {
     2193                    ui.item.find('.spf-fields').spf_reload_script_retry()
     2194                }
     2195            )
     2196
     2197            $(document).on('click', '.widget-top', function (event) {
     2198                $(this)
     2199                    .parent()
     2200                    .find('.spf-fields')
     2201                    .spf_reload_script()
     2202            })
     2203        }
     2204    }
     2205
     2206    //
     2207    // Nav Menu Options Framework
     2208    //
     2209    $.fn.spf_nav_menu = function () {
     2210        return this.each(function () {
     2211            var $navmenu = $(this)
     2212
     2213            $navmenu.on('click', 'a.item-edit', function () {
     2214                $(this)
     2215                    .closest('li.menu-item')
     2216                    .find('.spf-fields')
     2217                    .spf_reload_script()
     2218            })
     2219
     2220            $navmenu.on('sortstop', function (event, ui) {
     2221                ui.item.find('.spf-fields').spf_reload_script_retry()
     2222            })
     2223        })
     2224    }
     2225
     2226    //
     2227    // Retry Plugins
     2228    //
     2229    $.fn.spf_reload_script_retry = function () {
     2230        return this.each(function () {
     2231            var $this = $(this)
     2232
     2233            if ($this.data('inited')) {
     2234            }
     2235        })
     2236    }
     2237
     2238    //
     2239    // Reload Plugins
     2240    //
     2241    $.fn.spf_reload_script = function (options) {
     2242        var settings = $.extend(
     2243            {
     2244                dependency: true
     2245            },
     2246            options
     2247        )
     2248
     2249        return this.each(function () {
     2250            var $this = $(this)
     2251
     2252            // Avoid for conflicts
     2253            if (!$this.data('inited')) {
     2254                // Field plugins
     2255                // $this.children('.spf-field-accordion').spf_field_accordion()
     2256                // $this.children('.spf-field-backup').spf_field_backup()
     2257                //  $this.children('.spf-field-background').spf_field_background()
     2258                $this.children('.spf-field-code_editor').spf_field_code_editor()
     2259                // $this.children('.spf-field-date').spf_field_date()
     2260                $this.children('.spf-field-fieldset').spf_field_fieldset()
     2261                // $this.children('.spf-field-gallery').spf_field_gallery()
     2262                $this.children('.spf-field-group').spf_field_group()
     2263                $this.children('.spf-field-icon').spf_field_icon()
     2264                // $this.children('.spf-field-link').spf_field_link()
     2265                // $this.children('.spf-field-media').spf_field_media()
     2266                // $this.children('.spf-field-map').spf_field_map()
     2267                $this.children('.spf-field-repeater').spf_field_repeater()
     2268                $this.children('.spf-field-slider').spf_field_slider()
     2269                $this.children('.spf-field-sortable').spf_field_sortable()
     2270                $this.children('.spf-field-sorter').spf_field_sorter()
     2271                $this.children('.spf-field-spinner').spf_field_spinner()
     2272                $this.children('.spf-field-switcher').spf_field_switcher()
     2273                $this.children('.spf-field-tabbed').spf_field_tabbed()
     2274                // $this.children('.spf-field-typography').spf_field_typography()
     2275                $this.children('.spf-field-upload').spf_field_upload()
     2276
     2277                // Field colors
     2278                $this
     2279                    .children('.spf-field-box_shadow')
     2280                    .find('.spf-color')
     2281                    .spf_color() // ShapedPlugin.
     2282                $this
     2283                    .children('.spf-field-border')
     2284                    .find('.spf-color')
     2285                    .spf_color()
     2286                $this
     2287                    .children('.spf-field-background')
     2288                    .find('.spf-color')
     2289                    .spf_color()
     2290                $this
     2291                    .children('.spf-field-color')
     2292                    .find('.spf-color')
     2293                    .spf_color()
     2294                $this
     2295                    .children('.spf-field-color_group')
     2296                    .find('.spf-color')
     2297                    .spf_color()
     2298                $this
     2299                    .children('.spf-field-link_color')
     2300                    .find('.spf-color')
     2301                    .spf_color()
     2302                $this
     2303                    .children('.spf-field-typography')
     2304                    .find('.spf-color')
     2305                    .spf_color()
     2306
     2307                // Field chosenjs
     2308                $this
     2309                    .children('.spf-field-select')
     2310                    .find('.spf-chosen')
     2311                    .spf_chosen()
     2312
     2313                // Field Checkbox
     2314                $this
     2315                    .children('.spf-field-checkbox')
     2316                    .find('.spf-checkbox')
     2317                    .spf_checkbox()
     2318
     2319                // Field Siblings
     2320                $this
     2321                    .children('.spf-field-button_set')
     2322                    .find('.spf-siblings')
     2323                    .spf_siblings()
     2324                $this
     2325                    .children('.spf-field-image_select')
     2326                    .find('.spf-siblings')
     2327                    .spf_siblings()
     2328                $this
     2329                    .children('.spf-field-palette')
     2330                    .find('.spf-siblings')
     2331                    .spf_siblings()
     2332
     2333                // Help Tooptip
     2334                $this
     2335                    .children('.spf-field')
     2336                    .find('.spf-help')
     2337                    .spf_help()
     2338
     2339                if (settings.dependency) {
     2340                    $this.spf_dependency()
     2341                }
     2342
     2343                $this.data('inited', true)
     2344
     2345                $(document).trigger('spf-reload-script', $this)
     2346            }
     2347        })
     2348    }
     2349    $('.spf-clean-cache').on('click', function (e) {
     2350        e.preventDefault()
     2351        if (SPF.vars.is_confirm) {
     2352            //base.notificationOverlay()
     2353
     2354            window.wp.ajax
     2355                .post('spf_clean_transient', {
     2356                    nonce: $('#spf_options_nonce_sptp_settings').val()
     2357                })
     2358                .done(function (response) {
     2359                    //  window.location.reload(true)
     2360                    alert('data cleaned')
     2361                })
     2362                .fail(function (response) {
     2363                    alert('data failed to clean')
     2364                    alert(response.error)
     2365                    //  wp.customize.notifications.remove('spf_field_backup_notification')
     2366                })
     2367        }
     2368    })
     2369    //
     2370    // Document ready and run scripts
     2371    //
     2372    $(document).ready(function () {
     2373        $('.spf-save').spf_save()
     2374        $('.spf-options').spf_options()
     2375        $('.spf-sticky-header').spf_sticky()
     2376        $('.spf-nav-options').spf_nav_options()
     2377        $('.spf-nav-metabox').spf_nav_metabox()
     2378        $('.spf-taxonomy').spf_taxonomy()
     2379        $('.spf-page-templates').spf_page_templates()
     2380        $('.spf-post-formats').spf_post_formats()
     2381        $('.spf-shortcode').spf_shortcode()
     2382        $('.spf-search').spf_search()
     2383        $('.spf-confirm').spf_confirm()
     2384        $('.spf-expand-all').spf_expand_all()
     2385        $('.spf-onload').spf_reload_script()
     2386        $('.widget').spf_widgets()
     2387        $('#menu-to-edit').spf_nav_menu()
     2388        $(".spf-field-button_clean.cache_remove .spf--sibling.spf--button").on("click", function (e) {
     2389            e.preventDefault();
     2390            if (SPF.vars.is_confirm) {
     2391                // base.notificationOverlay()
     2392                window.wp.ajax
     2393                    .post("sptp_clean_transient", {
     2394                        nonce: $("#spf_options_nonce_sptp_settings").val(),
     2395                    })
     2396                    .done(function (response) {
     2397                        alert("Cache cleaned");
     2398                    })
     2399                    .fail(function (response) {
     2400                        alert("Cache failed to clean");
     2401                        alert(response.error);
     2402                        //  wp.customize.notifications.remove('spf_field_backup_notification')
     2403                    });
     2404            }
     2405        });
     2406    })
     2407    function isValidJSONString(str) {
     2408        try {
     2409            JSON.parse(str);
     2410        } catch (e) {
     2411            return false;
     2412        }
     2413        return true;
     2414    }
     2415    // Wp Team export.
     2416    var $export_type = $('.sptp_what_export').find('input:checked').val();
     2417    $('.sptp_what_export').on('change', function () {
     2418        $export_type = $(this).find('input:checked').val();
     2419    });
     2420
     2421    $('.sptp_export .spf--button').click(function (event) {
     2422        event.preventDefault();
     2423
     2424        var $shortcode_ids = $('.sptp_post_ids select').val();
     2425        var $ex_nonce = $('#spf_options_nonce_sptp_tools').val();
     2426        console.log($ex_nonce);
     2427        if ($shortcode_ids.length && $export_type === 'selected_shortcodes') {
     2428            var data = {
     2429                action: 'SPT_export_shortcodes',
     2430                lcp_ids: $shortcode_ids,
     2431                nonce: $ex_nonce,
     2432            }
     2433        } else if ($export_type === 'all_shortcodes') {
     2434            var data = {
     2435                action: 'SPT_export_shortcodes',
     2436                lcp_ids: 'all_shortcodes',
     2437                nonce: $ex_nonce,
     2438            }
     2439        } else if ($export_type === 'all_members') {
     2440            var data = {
     2441                action: 'SPT_export_shortcodes',
     2442                lcp_ids: 'all_members',
     2443                nonce: $ex_nonce,
     2444            }
     2445        } else {
     2446            $('.spf-form-result.spf-form-success').text('No group selected.').show();
     2447            setTimeout(function () {
     2448                $('.spf-form-result.spf-form-success').hide().text('');
     2449            }, 3000);
     2450        }
     2451        $.post(ajaxurl, data, function (resp) {
     2452            if (resp) {
     2453                // Convert JSON Array to string.
     2454                if (isValidJSONString(resp)) {
     2455                    var json = JSON.stringify(JSON.parse(resp));
     2456                } else {
     2457                    var json = JSON.stringify(resp);
     2458                }
     2459                // Convert JSON string to BLOB.
     2460                var blob = new Blob([json], { type: 'application/json' });
     2461                var link = document.createElement('a');
     2462                var lcp_time = $.now();
     2463                link.href = window.URL.createObjectURL(blob);
     2464                link.download = "wp-team-export-" + lcp_time + ".json";
     2465                link.click();
     2466                $('.spf-form-result.spf-form-success').text('Exported successfully!').show();
     2467                setTimeout(function () {
     2468                    $('.spf-form-result.spf-form-success').hide().text('');
     2469                    $('.sptp_post_ids select').val('').trigger('chosen:updated');
     2470                }, 3000);
     2471            }
     2472        });
     2473    });
     2474    // Wp Team import.
     2475    $('.sptp_import button.import').click(function (event) {
     2476        event.preventDefault();
     2477        var sptp_shortcodes = $('#import').prop('files')[0];
     2478        if ($('#import').val() != '') {
     2479            var $im_nonce = $('#spf_options_nonce_sptp_tools').val();
     2480            var reader = new FileReader();
     2481            reader.readAsText(sptp_shortcodes);
     2482            reader.onload = function (event) {
     2483                var jsonObj = JSON.stringify(event.target.result);
     2484                $.ajax({
     2485                    url: ajaxurl,
     2486                    type: 'POST',
     2487                    data: {
     2488                        shortcode: jsonObj,
     2489                        action: 'SPT_import_shortcodes',
     2490                        nonce: $im_nonce,
     2491                    },
     2492                    success: function (resp) {
     2493                        console.log(resp);
     2494                        $('.spf-form-result.spf-form-success').text('Imported successfully!').show();
     2495                        setTimeout(function () {
     2496                            $('.spf-form-result.spf-form-success').hide().text('');
     2497                            $('#import').val('');
     2498                            if (resp.data === 'sptp_member') {
     2499                                window.location.replace($('#sptp_member_link_redirect').attr('href'));
     2500                            } else {
     2501                                window.location.replace($('#sptp_shortcode_link_redirect').attr('href'));
     2502                            }
     2503                        }, 2000);
     2504                    }
     2505                });
     2506            }
     2507        } else {
     2508            $('.spf-form-result.spf-form-success').text('No exported json file chosen.').show();
     2509            setTimeout(function () {
     2510                $('.spf-form-result.spf-form-success').hide().text('');
     2511            }, 3000);
     2512        }
     2513    });
     2514
     2515    // Live Preview script for Wp-Team-Pro.
     2516    var preview_box = $('#sp__team-preview-box');
     2517    var preview_display = $('#sptp_preview_display').hide();
     2518    $(document).on('click', '#sp__team-show-preview:contains(Hide)', function (e) {
     2519        e.preventDefault();
     2520        var _this = $(this);
     2521        _this.html('<i class="fa fa-eye" aria-hidden="true"></i> Show Preview');
     2522        preview_box.html('');
     2523        preview_display.hide();
     2524    });
     2525    $(document).on('click', '#sp__team-show-preview:not(:contains(Hide))', function (e) {
     2526        e.preventDefault();
     2527        var previewJS = sptp_admin.previewJS;
     2528        var _data = $('form#post').serialize();
     2529        var _this = $(this);
     2530        var data = {
     2531            action: 'sptp_preview_meta_box',
     2532            data: _data,
     2533            ajax_nonce: $('#spf_metabox_noncesptp_preview_display').val()
     2534        };
     2535        $.ajax({
     2536            type: "POST",
     2537            url: ajaxurl,
     2538            data: data,
     2539            error: function (response) {
     2540                console.log(response)
     2541            },
     2542            success: function (response) {
     2543                preview_display.show();
     2544                preview_box.html(response);
     2545                $.getScript(previewJS, function () {
     2546                    _this.html('<i class="fa fa-eye-slash" aria-hidden="true"></i> Hide Preview');
     2547                    $(document).on('keyup change', '.post-type-sptp_generator', function (e) {
     2548                        e.preventDefault();
     2549                        _this.html('<i class="fa fa-refresh" aria-hidden="true"></i> Update Preview');
     2550                    });
     2551                    $("html, body").animate({ scrollTop: preview_display.offset().top - 50 }, "slow");
     2552                });
     2553            }
     2554        })
     2555    });
     2556
     2557
     2558    $(document).on('keyup change', '.sptp_member_page_team_settings #spf-form', function (e) {
     2559        e.preventDefault();
     2560        var $button = $(this).find('.spf-save');
     2561        $button.css({ "background-color": "#00C263", "pointer-events": "initial" }).val('Save Settings');
     2562    });
     2563    $('.sptp_member_page_team_settings .spf-save').click(function (e) {
     2564        e.preventDefault();
     2565        $(this).css({ "background-color": "#C5C5C6", "pointer-events": "none" }).val('Changes Saved');
     2566    })
    25592567
    25602568})(jQuery, window, document)
  • team-free/trunk/src/Admin/Framework/assets/js/main.min.js

    r2692012 r2712509  
    1 !function($,window,document,undefined){"use strict";var SPF=SPF||{};SPF.funcs={},SPF.vars={onloaded:!1,$body:$("body"),$window:$(window),$document:$(document),$form_warning:null,is_confirm:!1,form_modified:!1,code_themes:[],is_rtl:$("body").hasClass("rtl")},SPF.helper={uid:function(prefix){return(prefix||"")+Math.random().toString(36).substr(2,9)},preg_quote:function(str){return(str+"").replace(/(\[|\])/g,"\\$1")},name_nested_replace:function($selector,field_id){var checks=[],regex=new RegExp(SPF.helper.preg_quote(field_id+"[\\d+]"),"g");$selector.find(":radio").each((function(){(this.checked||this.original_checked)&&(this.original_checked=!0)})),$selector.each((function(index){$(this).find(":input").each((function(){this.name=this.name.replace(regex,field_id+"["+index+"]"),this.original_checked&&(this.checked=!0)}))}))},debounce:function(callback,threshold,immediate){var timeout;return function(){var context=this,args=arguments,later=function(){timeout=null,immediate||callback.apply(context,args)},callNow=immediate&&!timeout;clearTimeout(timeout),timeout=setTimeout(later,threshold),callNow&&callback.apply(context,args)}},get_cookie:function(name){var e,b,cookie=document.cookie,p=name+"=";if(cookie){if(-1===(b=cookie.indexOf("; "+p))){if(0!==(b=cookie.indexOf(p)))return null}else b+=2;return-1===(e=cookie.indexOf(";",b))&&(e=cookie.length),decodeURIComponent(cookie.substring(b+p.length,e))}},set_cookie:function(name,value,expires,path,domain,secure){var d=new Date;"object"==typeof expires&&expires.toGMTString?expires=expires.toGMTString():parseInt(expires,10)?(d.setTime(d.getTime()+1e3*parseInt(expires,10)),expires=d.toGMTString()):expires="",document.cookie=name+"="+encodeURIComponent(value)+(expires?"; expires="+expires:"")+(path?"; path="+path:"")+(domain?"; domain="+domain:"")+(secure?"; secure":"")},remove_cookie:function(name,path,domain,secure){SPF.helper.set_cookie(name,"",-1e3,path,domain,secure)}},$.fn.spf_clone=function(){for(var base=$.fn.clone.apply(this,arguments),clone=this.find("select").add(this.filter("select")),cloned=base.find("select").add(base.filter("select")),i=0;i<clone.length;++i)for(var j=0;j<clone[i].options.length;++j)!0===clone[i].options[j].selected&&(cloned[i].options[j].selected=!0);return this.find(":radio").each((function(){this.original_checked=this.checked})),base},$.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")}))}))},$.fn.spf_nav_options=function(){return this.each((function(){var $nav,$links=$(this).find("a"),$last;$(window).on("hashchange spf.hashchange",(function(){var hash=window.location.hash.replace("#tab=",""),slug=hash||$links.first().attr("href").replace("#tab=",""),$link=$('[data-tab-id="'+slug+'"]');if($link.length){$link.closest(".spf-tab-item").addClass("spf-tab-expanded").siblings().removeClass("spf-tab-expanded"),$link.next().is("ul")&&(slug=($link=$link.next().find("li").first().find("a")).data("tab-id")),$links.removeClass("spf-active"),$link.addClass("spf-active"),$last&&$last.addClass("hidden");var $section=$('[data-section-id="'+slug+'"]');$section.removeClass("hidden"),$section.spf_reload_script(),$(".spf-section-id").val($section.index()+1),$last=$section}})).trigger("spf.hashchange")}))},$.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",$sections=$nav.parent().find(".spf-section"),$last;$links.each((function(index){$(this).on("click",(function(e){e.preventDefault();var $link=$(this),section_id=$link.data("section");$links.removeClass("spf-active"),$link.addClass("spf-active"),void 0!==$last&&$last.addClass("hidden");var $section=$sections.eq(index);$section.removeClass("hidden"),$section.spf_reload_script(),SPF.helper.set_cookie("spf-last-metabox-tab-"+post_id+"-"+unique_id,section_id),$last=$section}));var get_cookie=SPF.helper.get_cookie("spf-last-metabox-tab-"+post_id+"-"+unique_id);get_cookie?$nav.find('a[data-section="'+get_cookie+'"]').trigger("click"):$links.first("a").trigger("click")}))}))},$.fn.spf_page_templates=function(){this.length&&$(document).on("change",".editor-page-attributes__template select, #page_template",(function(){var maybe_value=$(this).val()||"default";$(".spf-page-templates").removeClass("spf-metabox-show").addClass("spf-metabox-hide"),$(".spf-page-"+maybe_value.toLowerCase().replace(/[^a-zA-Z0-9]+/g,"-")).removeClass("spf-metabox-hide").addClass("spf-metabox-show")}))},$.fn.spf_post_formats=function(){this.length&&$(document).on("change",'.editor-post-format select, #formatdiv input[name="post_format"]',(function(){var maybe_value=$(this).val()||"default";maybe_value="0"===maybe_value?"default":maybe_value,$(".spf-post-formats").removeClass("spf-metabox-show").addClass("spf-metabox-hide"),$(".spf-post-format-"+maybe_value).removeClass("spf-metabox-hide").addClass("spf-metabox-show")}))},$.fn.spf_search=function(){return this.each((function(){var $this,$input;$(this).find("input").on("change keyup",(function(){var value=$(this).val(),$wrapper=$(".spf-wrapper"),$section,$fields=$wrapper.find(".spf-section").find("> .spf-field:not(.spf-depend-on)"),$titles=$fields.find("> .spf-title, .spf-search-tags");value.length>3?($fields.addClass("spf-metabox-hide"),$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-metabox-hide"),$field.parent().spf_reload_script()}}))):($fields.removeClass("spf-metabox-hide"),$wrapper.removeClass("spf-search-all"))}))}))},$.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=!1,stickyUpdate=function(){var offsetTop=$this.offset().top,stickyTop=Math.max(32,offsetTop-scrollTop),winWidth=Math.max(document.documentElement.clientWidth,window.innerWidth||0);stickyTop<=32&&winWidth>782?($inner.css({width:$this.outerWidth()-padding}),$this.css({height:$this.outerHeight()}).addClass("spf-sticky")):($inner.removeAttr("style"),$this.removeAttr("style").removeClass("spf-sticky"))},requestTick=function(){ticking||requestAnimationFrame((function(){stickyUpdate(),ticking=!1})),ticking=!0},onSticky=function(){scrollTop=$window.scrollTop(),requestTick()};$window.on("scroll resize",onSticky),onSticky()}))},$.fn.spf_dependency=function(){return this.each((function(){var $this=$(this),$fields=$this.children("[data-controller]");if($fields.length){var normal_ruleset=$.spf_deps.createRuleset(),global_ruleset=$.spf_deps.createRuleset(),normal_depends=[],global_depends=[];$fields.each((function(){var $field=$(this),controllers=$field.data("controller").split("|"),conditions=$field.data("condition").split("|"),values=$field.data("value").toString().split("|"),is_global=!!$field.data("depend-global"),ruleset=is_global?global_ruleset:normal_ruleset;$.each(controllers,(function(index,depend_id){var value=values[index]||"",condition=conditions[index]||conditions[0];(ruleset=ruleset.createRule('[data-depend-id="'+depend_id+'"]',condition,value)).include($field),is_global?global_depends.push(depend_id):normal_depends.push(depend_id)}))})),normal_depends.length&&$.spf_deps.enable($this,normal_ruleset,normal_depends),global_depends.length&&$.spf_deps.enable(SPF.vars.$body,global_ruleset,global_depends)}}))},$.fn.spf_field_code_editor=function(){return this.each((function(){if("function"==typeof CodeMirror){var $this=$(this),$textarea=$this.find("textarea"),$inited=$this.find(".CodeMirror"),data_editor=$textarea.data("editor");$inited.length&&$inited.remove();var interval=setInterval((function(){if($this.is(":visible")){var code_editor=CodeMirror.fromTextArea($textarea[0],data_editor);if("default"!==data_editor.theme&&-1===SPF.vars.code_themes.indexOf(data_editor.theme)){var $cssLink=$("<link>");$("#spf-codemirror-css").after($cssLink),$cssLink.attr({rel:"stylesheet",id:"spf-codemirror-"+data_editor.theme+"-css",href:data_editor.cdnURL+"/theme/"+data_editor.theme+".min.css",type:"text/css",media:"all"}),SPF.vars.code_themes.push(data_editor.theme)}CodeMirror.modeURL=data_editor.cdnURL+"/mode/%N/%N.min.js",CodeMirror.autoLoadMode(code_editor,data_editor.mode),code_editor.on("change",(function(editor,event){$textarea.val(code_editor.getValue()).trigger("change")})),clearInterval(interval)}}))}}))},$.fn.spf_field_fieldset=function(){return this.each((function(){$(this).find(".spf-fieldset-content").spf_reload_script()}))},$.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"),is_number=Boolean(Number($wrapper.data("title-number"))),max=parseInt($wrapper.data("max")),min=parseInt($wrapper.data("min"));$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+".")}))};$wrapper.accordion({header:"> .spf-cloneable-item > .spf-cloneable-title",collapsible:!0,active:!1,animate:!1,heightStyle:"content",icons:{header:"spf-cloneable-header-icon fas fa-angle-right",activeHeader:"spf-cloneable-header-icon fas fa-angle-down"},activate:function(event,ui){var $panel=ui.newPanel,$header=ui.newHeader;if($panel.length&&!$panel.data("opened")){var $fields,$first=$panel.children().first().find(":input").first(),$title=$header.find(".spf-cloneable-value");$first.on("change keyup",(function(event){$title.text($first.val())})),$panel.spf_reload_script(),$panel.data("opened",!0),$panel.data("retry",!1)}else $panel.data("retry")&&($panel.spf_reload_script_retry(),$panel.data("retry",!1))}}),$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:!1}),$wrapper.sortable("refreshPositions"),ui.item.children(".spf-cloneable-content").data("retry",!0)},update:function(event,ui){SPF.helper.name_nested_replace($wrapper.children(".spf-cloneable-item"),field_id),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;if($min.hide(),max&&count+1>max)$max.show();else{var $cloned_item=$hidden.spf_clone(!0);$cloned_item.removeClass("spf-cloneable-hidden"),$cloned_item.find(':input[name!="_pseudo"]').each((function(){this.name=this.name.replace("___","").replace(field_id+"[0]",field_id+"["+count+"]")})),$wrapper.append($cloned_item),$wrapper.accordion("refresh"),$wrapper.accordion({active:count}),is_number&&update_title_numbers($wrapper)}}));var event_clone=function(e){e.preventDefault();var count=$wrapper.children(".spf-cloneable-item").length;if($min.hide(),max&&count+1>max)$max.show();else{var $this,$parent=$(this).parent().parent(),$cloned_helper=$parent.children(".spf-cloneable-helper").spf_clone(!0),$cloned_title=$parent.children(".spf-cloneable-title").spf_clone(),$cloned_content=$parent.children(".spf-cloneable-content").spf_clone(),$cloned_item=$('<div class="spf-cloneable-item" />');$cloned_item.append($cloned_helper),$cloned_item.append($cloned_title),$cloned_item.append($cloned_content),$wrapper.children().eq($parent.index()).after($cloned_item),SPF.helper.name_nested_replace($wrapper.children(".spf-cloneable-item"),field_id),$wrapper.accordion("refresh"),is_number&&update_title_numbers($wrapper)}};$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(),min&&count-1<min?$min.show():($(this).closest(".spf-cloneable-item").remove(),SPF.helper.name_nested_replace($wrapper.children(".spf-cloneable-item"),field_id),is_number&&update_title_numbers($wrapper))};$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)}))},$.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),$modal=$("#spf-modal-icon");$modal.removeClass("hidden"),SPF.vars.$icon_target=$this,SPF.vars.icon_modal_loaded||($modal.find(".spf-modal-loading").show(),window.wp.ajax.post("spf-get-icons",{nonce:$button.data("nonce")}).done((function(response){$modal.find(".spf-modal-loading").hide(),SPF.vars.icon_modal_loaded=!0;var $load=$modal.find(".spf-modal-load").html(response.content);$load.on("click","i",(function(e){e.preventDefault();var icon=$(this).attr("title");SPF.vars.$icon_target.find(".spf-icon-preview i").removeAttr("class").addClass(icon),SPF.vars.$icon_target.find(".spf-icon-preview").removeClass("hidden"),SPF.vars.$icon_target.find(".spf-icon-remove").removeClass("hidden"),SPF.vars.$icon_target.find("input").val(icon).trigger("change"),$modal.addClass("hidden")})),$modal.on("change keyup",".spf-icon-search",(function(){var value=$(this).val(),$icons;$load.find("i").each((function(){var $elem=$(this);$elem.attr("title").search(new RegExp(value,"i"))<0?$elem.hide():$elem.show()}))})),$modal.on("click",".spf-modal-close, .spf-modal-overlay",(function(){$modal.addClass("hidden")}))})).fail((function(response){$modal.find(".spf-modal-loading").hide(),$modal.find(".spf-modal-load").html(response.error),$modal.on("click",(function(){$modal.addClass("hidden")}))})))})),$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")}))}))},$.fn.spf_field_repeater=function(){return this.each((function(){var $this=$(this),$fieldset=$this.children(".spf-fieldset"),$repeater=$fieldset.length?$fieldset:$this,$wrapper=$repeater.children(".spf-repeater-wrapper"),$hidden=$repeater.children(".spf-repeater-hidden"),$max=$repeater.children(".spf-repeater-max"),$min=$repeater.children(".spf-repeater-min"),field_id=$wrapper.data("field-id"),max=parseInt($wrapper.data("max")),min=parseInt($wrapper.data("min"));$wrapper.children(".spf-repeater-item").children(".spf-repeater-content").spf_reload_script(),$wrapper.sortable({axis:"y",handle:".spf-repeater-sort",helper:"original",cursor:"move",placeholder:"widget-placeholder",update:function(event,ui){SPF.helper.name_nested_replace($wrapper.children(".spf-repeater-item"),field_id),ui.item.spf_reload_script_retry()}}),$repeater.children(".spf-repeater-add").on("click",(function(e){e.preventDefault();var count=$wrapper.children(".spf-repeater-item").length;if($min.hide(),max&&count+1>max)$max.show();else{var $cloned_item=$hidden.spf_clone(!0);$cloned_item.removeClass("spf-repeater-hidden"),$cloned_item.find(':input[name!="_pseudo"]').each((function(){this.name=this.name.replace("___","").replace(field_id+"[0]",field_id+"["+count+"]")})),$wrapper.append($cloned_item),$cloned_item.children(".spf-repeater-content").spf_reload_script()}}));var event_clone=function(e){e.preventDefault();var count=$wrapper.children(".spf-repeater-item").length;if($min.hide(),max&&count+1>max)$max.show();else{var $this,$parent=$(this).parent().parent().parent(),$cloned_content=$parent.children(".spf-repeater-content").spf_clone(),$cloned_helper=$parent.children(".spf-repeater-helper").spf_clone(!0),$cloned_item=$('<div class="spf-repeater-item" />');$cloned_item.append($cloned_content),$cloned_item.append($cloned_helper),$wrapper.children().eq($parent.index()).after($cloned_item),$cloned_item.children(".spf-repeater-content").spf_reload_script(),SPF.helper.name_nested_replace($wrapper.children(".spf-repeater-item"),field_id)}};$wrapper.children(".spf-repeater-item").children(".spf-repeater-helper").on("click",".spf-repeater-clone",event_clone),$repeater.children(".spf-repeater-hidden").children(".spf-repeater-helper").on("click",".spf-repeater-clone",event_clone);var event_remove=function(e){e.preventDefault();var count=$wrapper.children(".spf-repeater-item").length;$max.hide(),$min.hide(),min&&count-1<min?$min.show():($(this).closest(".spf-repeater-item").remove(),SPF.helper.name_nested_replace($wrapper.children(".spf-repeater-item"),field_id))};$wrapper.children(".spf-repeater-item").children(".spf-repeater-helper").on("click",".spf-repeater-remove",event_remove),$repeater.children(".spf-repeater-hidden").children(".spf-repeater-helper").on("click",".spf-repeater-remove",event_remove)}))},$.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;$slider.hasClass("ui-slider")&&$slider.empty(),$slider.slider({range:"min",value:value,min:data.min||0,max:data.max||100,step:data.step||1,slide:function(e,o){$input.val(o.value).trigger("change")}}),$input.on("keyup",(function(){$slider.slider("value",$input.val())}))}))},$.fn.spf_field_sortable=function(){return this.each((function(){var $sortable=$(this).find(".spf-sortable");$sortable.sortable({axis:"y",helper:"original",cursor:"move",placeholder:"widget-placeholder",update:function(event,ui){}}),$sortable.find(".spf-sortable-content").spf_reload_script()}))},$.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;$enabled.sortable({connectWith:$disabled,placeholder:"ui-sortable-placeholder",update:function(event,ui){var $el=ui.item.find("input");ui.item.parent().hasClass("spf-enabled")?$el.attr("name",$el.attr("name").replace("disabled","enabled")):$el.attr("name",$el.attr("name").replace("enabled","disabled"))}}),$disabled&&$disabled.sortable({connectWith:$enabled,placeholder:"ui-sortable-placeholder",update:function(event,ui){}})}))},$.fn.spf_field_spinner=function(){return this.each((function(){var $this=$(this),$input=$this.find("input"),$inited=$this.find(".ui-button"),data=$input.data();$inited.length&&$inited.remove(),$input.spinner({min:data.min||0,max:data.max||100,step:data.step||1,create:function(event,ui){data.unit&&$input.after('<span class="ui-button spf--unit">'+data.unit+"</span>")},spin:function(event,ui){$input.val(ui.value).trigger("change")}})}))},$.fn.spf_field_switcher=function(){return this.each((function(){var $switcher=$(this).find(".spf--switcher");$switcher.on("click",(function(){var value=0,$input=$switcher.find("input");$switcher.hasClass("spf--active")?$switcher.removeClass("spf--active"):(value=1,$switcher.addClass("spf--active")),$input.val(value).trigger("change")}))}))},$.fn.spf_field_tabbed=function(){return this.each((function(){var $this=$(this),$links=$this.find(".spf-tabbed-nav a"),$contents=$this.find(".spf-tabbed-content");$contents.eq(0).spf_reload_script(),$links.on("click",(function(e){e.preventDefault();var $link=$(this),index=$link.index(),$content=$contents.eq(index);$link.addClass("spf-tabbed-active").siblings().removeClass("spf-tabbed-active"),$content.spf_reload_script(),$content.removeClass("hidden").siblings().addClass("hidden")}))}))},$.fn.spf_field_upload=function(){return this.each((function(){var $this=$(this),$input=$this.find("input"),$upload_button=$this.find(".spf--button"),$remove_button=$this.find(".spf--remove"),$library=$upload_button.data("library")&&$upload_button.data("library").split(",")||"",wp_media_frame;$input.on("change",(function(e){$input.val()?$remove_button.removeClass("hidden"):$remove_button.addClass("hidden")})),$upload_button.on("click",(function(e){e.preventDefault(),void 0!==window.wp&&window.wp.media&&window.wp.media.gallery&&(wp_media_frame?wp_media_frame.open():((wp_media_frame=window.wp.media({library:{type:$library}})).on("select",(function(){var attributes=wp_media_frame.state().get("selection").first().attributes;$library.length&&-1===$library.indexOf(attributes.subtype)&&-1===$library.indexOf(attributes.type)||$input.val(attributes.url).trigger("change")})),wp_media_frame.open()))})),$remove_button.on("click",(function(e){e.preventDefault(),$input.val("").trigger("change")}))}))},$.fn.spf_confirm=function(){return this.each((function(){$(this).on("click",(function(e){var confirm_text=$(this).data("confirm")||window.spf_vars.i18n.confirm,confirm_answer;if(!confirm(confirm_text))return e.preventDefault(),!1;SPF.vars.is_confirm=!0,SPF.vars.form_modified=!1}))}))},$.fn.serializeObject=function(){var obj={};return $.each(this.serializeArray(),(function(i,o){var n=o.name,v=o.value;obj[n]=void 0===obj[n]?v:$.isArray(obj[n])?obj[n].concat(v):[obj[n],v]})),obj},$.fn.spf_save=function(){return this.each((function(){var $this=$(this),$buttons=$(".spf-save"),$panel=$(".spf-options"),flooding=!1,timeout;$this.on("click",(function(e){if(!flooding){var $text=$this.data("save"),$value=$this.val();$buttons.attr("value",$text),$this.hasClass("spf-save-ajax")?(e.preventDefault(),$panel.addClass("spf-saving"),$buttons.prop("disabled",!0),window.wp.ajax.post("spf_"+$panel.data("unique")+"_ajax_save",{data:$("#spf-form").serializeJSONSPF()}).done((function(response){if($(".spf-error").remove(),Object.keys(response.errors).length){var error_icon='<i class="spf-label-error spf-error">!</i>';$.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('<p class="spf-error spf-error-text">'+error_message+"</p>"),$link.find(".spf-error").length||$link.append(error_icon),$tab.find(".spf-arrow .spf-error").length||$tab.find(".spf-arrow").append(error_icon)}))}$panel.removeClass("spf-saving"),$buttons.prop("disabled",!1).attr("value",$value),flooding=!1,SPF.vars.form_modified=!1,SPF.vars.$form_warning.hide(),clearTimeout(timeout);var $result_success=$(".spf-form-success");$result_success.empty().append(response.notice).fadeIn("fast",(function(){timeout=setTimeout((function(){$result_success.fadeOut("fast")}),1e3)}))})).fail((function(response){alert(response.error)}))):SPF.vars.form_modified=!1}flooding=!0}))}))},$.fn.spf_options=function(){return this.each((function(){var $this=$(this),$content=$this.find(".spf-content"),$form_success=$this.find(".spf-form-success"),$form_warning=$this.find(".spf-form-warning"),$save_button=$this.find(".spf-header .spf-save");SPF.vars.$form_warning=$form_warning,$form_warning.length&&(window.onbeforeunload=function(){return!!SPF.vars.form_modified||void 0},$content.on("change keypress",":input",(function(){SPF.vars.form_modified||($form_success.hide(),$form_warning.fadeIn("fast"),SPF.vars.form_modified=!0)}))),$form_success.hasClass("spf-form-show")&&setTimeout((function(){$form_success.fadeOut("fast")}),1e3),$(document).keydown((function(event){if((event.ctrlKey||event.metaKey)&&83===event.which)return $save_button.trigger("click"),event.preventDefault(),!1}))}))},$.fn.spf_taxonomy=function(){return this.each((function(){var $this=$(this),$form=$this.parents("form");if("addtag"===$form.attr("id")){var $submit=$form.find("#submit"),$cloned=$this.find(".spf-field").spf_clone();$submit.on("click",(function(){$form.find(".form-required").hasClass("form-invalid")||($this.data("inited",!1),$this.empty(),$this.html($cloned),$cloned=$cloned.spf_clone(),$this.spf_reload_script())}))}}))},$.fn.spf_shortcode=function(){var base=this;return base.shortcode_parse=function(serialize,key){var shortcode="";return $.each(serialize,(function(shortcode_key,shortcode_values){shortcode+="["+(key=key||shortcode_key),$.each(shortcode_values,(function(shortcode_tag,shortcode_value){"content"===shortcode_tag?(shortcode+="]",shortcode+=shortcode_value,shortcode+="[/"+key):shortcode+=base.shortcode_tags(shortcode_tag,shortcode_value)})),shortcode+="]"})),shortcode},base.shortcode_tags=function(shortcode_tag,shortcode_value){var shortcode="";return""!==shortcode_value&&("object"!=typeof shortcode_value||$.isArray(shortcode_value)?shortcode+=" "+shortcode_tag.replace("-","_")+'="'+shortcode_value.toString()+'"':$.each(shortcode_value,(function(sub_shortcode_tag,sub_shortcode_value){switch(sub_shortcode_tag){case"background-image":sub_shortcode_value=sub_shortcode_value.url?sub_shortcode_value.url:""}""!==sub_shortcode_value&&(shortcode+=" "+sub_shortcode_tag.replace("-","_")+'="'+sub_shortcode_value.toString()+'"')}))),shortcode},base.insertAtChars=function(_this,currentValue){var obj=void 0!==_this[0].name?_this[0]:_this;return obj.value.length&&void 0!==obj.selectionStart?(obj.focus(),obj.value.substring(0,obj.selectionStart)+currentValue+obj.value.substring(obj.selectionEnd,obj.value.length)):(obj.focus(),currentValue)},base.send_to_editor=function(html,editor_id){var tinymce_editor;if("undefined"!=typeof tinymce&&(tinymce_editor=tinymce.get(editor_id)),tinymce_editor&&!tinymce_editor.isHidden())tinymce_editor.execCommand("mceInsertContent",!1,html);else{var $editor=$("#"+editor_id);$editor.val(base.insertAtChars($editor,html)).trigger("change")}},this.each((function(){var $modal=$(this),$load=$modal.find(".spf-modal-load"),$content=$modal.find(".spf-modal-content"),$insert=$modal.find(".spf-modal-insert"),$loading=$modal.find(".spf-modal-loading"),$select=$modal.find("select"),modal_id=$modal.data("modal-id"),nonce=$modal.data("nonce"),editor_id,target_id,sc_key,sc_name,sc_view,sc_group,$cloned,$button;$(document).on("click",'.spf-shortcode-button[data-modal-id="'+modal_id+'"]',(function(e){e.preventDefault(),$button=$(this),editor_id=$button.data("editor-id")||!1,target_id=$button.data("target-id")||!1,$modal.removeClass("hidden"),$modal.hasClass("spf-shortcode-single")&&void 0===sc_name&&$select.trigger("change")})),$select.on("change",(function(){var $option=$(this),$selected=$option.find(":selected");sc_key=$option.val(),sc_name=$selected.data("shortcode"),sc_view=$selected.data("view")||"normal",sc_group=$selected.data("group")||sc_name,$load.empty(),sc_key?($loading.show(),window.wp.ajax.post("spf-get-shortcode-"+modal_id,{shortcode_key:sc_key,nonce:nonce}).done((function(response){$loading.hide();var $appended=$(response.content).appendTo($load);$insert.parent().removeClass("hidden"),$cloned=$appended.find(".spf--repeat-shortcode").spf_clone(),$appended.spf_reload_script(),$appended.find(".spf-fields").spf_reload_script()}))):$insert.parent().addClass("hidden")})),$insert.on("click",(function(e){if(e.preventDefault(),!$insert.prop("disabled")&&!$insert.attr("disabled")){var shortcode="",serialize=$modal.find(".spf-field:not(.spf-depend-on)").find(":input:not(.ignore)").serializeObjectSPF();switch(sc_view){case"contents":var contentsObj=sc_name?serialize[sc_name]:serialize;$.each(contentsObj,(function(sc_key,sc_value){var sc_tag=sc_name||sc_key;shortcode+="["+sc_tag+"]"+sc_value+"[/"+sc_tag+"]"}));break;case"group":shortcode+="["+sc_name,$.each(serialize[sc_name],(function(sc_key,sc_value){shortcode+=base.shortcode_tags(sc_key,sc_value)})),shortcode+="]",shortcode+=base.shortcode_parse(serialize[sc_group],sc_group),shortcode+="[/"+sc_name+"]";break;case"repeater":shortcode+=base.shortcode_parse(serialize[sc_group],sc_group);break;default:shortcode+=base.shortcode_parse(serialize)}if(shortcode=""===shortcode?"["+sc_name+"]":shortcode,editor_id)base.send_to_editor(shortcode,editor_id);else{var $textarea=target_id?$(target_id):$button.parent().find("textarea");$textarea.val(base.insertAtChars($textarea,shortcode)).trigger("change")}$modal.addClass("hidden")}})),$modal.on("click",".spf--repeat-button",(function(e){e.preventDefault();var $repeatable=$modal.find(".spf--repeatable"),$new_clone=$cloned.spf_clone(),$remove_btn=$new_clone.find(".spf-repeat-remove"),$appended=$new_clone.appendTo($repeatable);$new_clone.find(".spf-fields").spf_reload_script(),SPF.helper.name_nested_replace($modal.find(".spf--repeat-shortcode"),sc_group),$remove_btn.on("click",(function(){$new_clone.remove(),SPF.helper.name_nested_replace($modal.find(".spf--repeat-shortcode"),sc_group)}))})),$modal.on("click",".spf-modal-close, .spf-modal-overlay",(function(){$modal.addClass("hidden")}))}))},"function"==typeof Color&&(Color.prototype.toString=function(){if(this._alpha<1)return this.toCSS("rgba",this._alpha).replace(/\s+/g,"");var hex=parseInt(this._color,10).toString(16);if(this.error)return"";if(hex.length<6)for(var i=6-hex.length-1;i>=0;i--)hex="0"+hex;return"#"+hex}),SPF.funcs.parse_color=function(color){var value=color.replace(/\s+/g,""),trans=-1!==value.indexOf("rgba")?parseFloat(100*value.replace(/^.*,(.+)\)/,"$1")):100,rgba;return{value:value,transparent:trans,rgba:trans<100}},$.fn.spf_color=function(){return this.each((function(){var $input=$(this),picker_color=SPF.funcs.parse_color($input.val()),palette_color=!window.spf_vars.color_palette.length||window.spf_vars.color_palette,$container;$input.hasClass("wp-color-picker")&&$input.closest(".wp-picker-container").after($input).remove(),$input.wpColorPicker({palettes:palette_color,change:function(event,ui){var ui_color_value=ui.color.toString();$container.removeClass("spf--transparent-active"),$container.find(".spf--transparent-offset").css("background-color",ui_color_value),$input.val(ui_color_value).trigger("change")},create:function(){$container=$input.closest(".wp-picker-container");var a8cIris=$input.data("a8cIris"),$transparent_wrap=$('<div class="spf--transparent-wrap"><div class="spf--transparent-slider"></div><div class="spf--transparent-offset"></div><div class="spf--transparent-text"></div><div class="spf--transparent-button">transparent <i class="fas fa-toggle-off"></i></div></div>').appendTo($container.find(".wp-picker-holder")),$transparent_slider=$transparent_wrap.find(".spf--transparent-slider"),$transparent_text=$transparent_wrap.find(".spf--transparent-text"),$transparent_offset=$transparent_wrap.find(".spf--transparent-offset"),$transparent_button=$transparent_wrap.find(".spf--transparent-button");"transparent"===$input.val()&&$container.addClass("spf--transparent-active"),$transparent_button.on("click",(function(){"transparent"!==$input.val()?($input.val("transparent").trigger("change").removeClass("iris-error"),$container.addClass("spf--transparent-active")):($input.val(a8cIris._color.toString()).trigger("change"),$container.removeClass("spf--transparent-active"))})),$transparent_slider.slider({value:picker_color.transparent,step:1,min:0,max:100,slide:function(event,ui){var slide_value=parseFloat(ui.value/100);a8cIris._color._alpha=slide_value,$input.wpColorPicker("color",a8cIris._color.toString()),$transparent_text.text(1===slide_value||0===slide_value?"":slide_value)},create:function(){var slide_value=parseFloat(picker_color.transparent/100),text_value=slide_value<1?slide_value:"";$transparent_text.text(text_value),$transparent_offset.css("background-color",picker_color.value),$container.on("click",".wp-picker-clear",(function(){a8cIris._color._alpha=1,$transparent_text.text(""),$transparent_slider.slider("option","value",100),$container.removeClass("spf--transparent-active"),$input.trigger("change")})),$container.on("click",".wp-picker-default",(function(){var default_color=SPF.funcs.parse_color($input.data("default-color")),default_value=parseFloat(default_color.transparent/100),default_text=default_value<1?default_value:"";a8cIris._color._alpha=default_value,$transparent_text.text(default_text),$transparent_slider.slider("option","value",default_color.transparent),"transparent"===default_color.value&&($input.removeClass("iris-error"),$container.addClass("spf--transparent-active"))}))}})}})}))},$.fn.spf_chosen=function(){return this.each((function(){var $this=$(this),$inited=$this.parent().find(".chosen-container"),is_sortable=$this.hasClass("spf-chosen-sortable")||!1,is_ajax=$this.hasClass("spf-chosen-ajax")||!1,is_multiple=$this.attr("multiple")||!1,set_width=is_multiple?"100%":"auto",set_options=$.extend({allow_single_deselect:!0,disable_search_threshold:10,width:set_width,no_results_text:window.spf_vars.i18n.no_results_text},$this.data("chosen-settings"));if($inited.length&&$inited.remove(),is_ajax){var set_ajax_options=$.extend({data:{type:"post",nonce:""},allow_single_deselect:!0,disable_search_threshold:-1,width:"100%",min_length:3,type_delay:500,typing_text:window.spf_vars.i18n.typing_text,searching_text:window.spf_vars.i18n.searching_text,no_results_text:window.spf_vars.i18n.no_results_text},$this.data("chosen-settings"));$this.SPFAjaxChosen(set_ajax_options)}else $this.chosen(set_options);if(is_multiple){var $hidden_select=$this.parent().find(".spf-hide-select"),$hidden_value=$hidden_select.val()||[];$this.on("change",(function(obj,result){result&&result.selected?$hidden_select.append('<option value="'+result.selected+'" selected="selected">'+result.selected+"</option>"):result&&result.deselected&&$hidden_select.find('option[value="'+result.deselected+'"]').remove(),void 0!==window.wp.customize&&0===$hidden_select.children().length&&$hidden_select.data("customize-setting-link")&&window.wp.customize.control($hidden_select.data("customize-setting-link")).setting.set(""),$hidden_select.trigger("change")})),$this.CSFChosenOrder($hidden_value,!0)}if(is_sortable){var $chosen_container,$chosen_choices=$this.parent().find(".chosen-container").find(".chosen-choices");$chosen_choices.bind("mousedown",(function(event){$(event.target).is("span")&&event.stopPropagation()})),$chosen_choices.sortable({items:"li:not(.search-field)",helper:"orginal",cursor:"move",placeholder:"search-choice-placeholder",start:function(e,ui){ui.placeholder.width(ui.item.innerWidth()),ui.placeholder.height(ui.item.innerHeight())},update:function(e,ui){var select_options="",chosen_object=$this.data("chosen"),$prev_select=$this.parent().find(".spf-hide-select");$chosen_choices.find(".search-choice-close").each((function(){var option_array_index=$(this).data("option-array-index");$.each(chosen_object.results_data,(function(index,data){data.array_index===option_array_index&&(select_options+='<option value="'+data.value+'" selected>'+data.value+"</option>")}))})),$prev_select.children().remove(),$prev_select.append(select_options),$prev_select.trigger("change")}})}}))},$.fn.spf_checkbox=function(){return this.each((function(){var $this=$(this),$input=$this.find(".spf--input"),$checkbox=$this.find(".spf--checkbox");$checkbox.on("click",(function(){$input.val(Number($checkbox.prop("checked"))).trigger("change")}))}))},$.fn.spf_siblings=function(){return this.each((function(){var $this=$(this),$siblings=$this.find(".spf--sibling"),multiple=$this.data("multiple")||!1;$siblings.on("click",(function(){var $sibling=$(this);multiple?$sibling.hasClass("spf--active")?($sibling.removeClass("spf--active"),$sibling.find("input").prop("checked",!1).trigger("change")):($sibling.addClass("spf--active"),$sibling.find("input").prop("checked",!0).trigger("change")):($this.find("input").prop("checked",!1),$sibling.find("input").prop("checked",!0).trigger("change"),$sibling.addClass("spf--active").siblings().removeClass("spf--active"))}))}))},$.fn.spf_help=function(){return this.each((function(){var $this=$(this),$tooltip,offset_left;$this.on({mouseenter:function(){$tooltip=$('<div class="spf-tooltip"></div>').html($this.find(".spf-help-text").html()).appendTo("body"),offset_left=SPF.vars.is_rtl?$this.offset().left-230:$this.offset().left+24,$tooltip.css({top:$this.offset().top-($tooltip.outerHeight()/2-14),left:offset_left,textAlign:SPF.vars.is_rtl?"right":"left"})},mouseleave:function(){void 0!==$tooltip&&$tooltip.remove()}})}))},SPF.vars.$window.on("resize spf.resize",SPF.helper.debounce((function(event){var window_width;(navigator.userAgent.indexOf("AppleWebKit/")>-1?SPF.vars.$window.width():window.innerWidth)<=782&&!SPF.vars.onloaded&&($(".spf-section").spf_reload_script(),SPF.vars.onloaded=!0)}),200)).trigger("spf.resize"),$.fn.spf_widgets=function(){this.length&&($(document).on("widget-added widget-updated",(function(event,$widget){$widget.find(".spf-fields").spf_reload_script()})),$(".widgets-sortables, .control-section-sidebar").on("sortstop",(function(event,ui){ui.item.find(".spf-fields").spf_reload_script_retry()})),$(document).on("click",".widget-top",(function(event){$(this).parent().find(".spf-fields").spf_reload_script()})))},$.fn.spf_nav_menu=function(){return this.each((function(){var $navmenu=$(this);$navmenu.on("click","a.item-edit",(function(){$(this).closest("li.menu-item").find(".spf-fields").spf_reload_script()})),$navmenu.on("sortstop",(function(event,ui){ui.item.find(".spf-fields").spf_reload_script_retry()}))}))},$.fn.spf_reload_script_retry=function(){return this.each((function(){var $this;$(this).data("inited")}))},$.fn.spf_reload_script=function(options){var settings=$.extend({dependency:!0},options);return this.each((function(){var $this=$(this);$this.data("inited")||($this.children(".spf-field-code_editor").spf_field_code_editor(),$this.children(".spf-field-fieldset").spf_field_fieldset(),$this.children(".spf-field-group").spf_field_group(),$this.children(".spf-field-icon").spf_field_icon(),$this.children(".spf-field-repeater").spf_field_repeater(),$this.children(".spf-field-slider").spf_field_slider(),$this.children(".spf-field-sortable").spf_field_sortable(),$this.children(".spf-field-sorter").spf_field_sorter(),$this.children(".spf-field-spinner").spf_field_spinner(),$this.children(".spf-field-switcher").spf_field_switcher(),$this.children(".spf-field-tabbed").spf_field_tabbed(),$this.children(".spf-field-upload").spf_field_upload(),$this.children(".spf-field-box_shadow").find(".spf-color").spf_color(),$this.children(".spf-field-border").find(".spf-color").spf_color(),$this.children(".spf-field-background").find(".spf-color").spf_color(),$this.children(".spf-field-color").find(".spf-color").spf_color(),$this.children(".spf-field-color_group").find(".spf-color").spf_color(),$this.children(".spf-field-link_color").find(".spf-color").spf_color(),$this.children(".spf-field-typography").find(".spf-color").spf_color(),$this.children(".spf-field-select").find(".spf-chosen").spf_chosen(),$this.children(".spf-field-checkbox").find(".spf-checkbox").spf_checkbox(),$this.children(".spf-field-button_set").find(".spf-siblings").spf_siblings(),$this.children(".spf-field-image_select").find(".spf-siblings").spf_siblings(),$this.children(".spf-field-palette").find(".spf-siblings").spf_siblings(),$this.children(".spf-field").find(".spf-help").spf_help(),settings.dependency&&$this.spf_dependency(),$this.data("inited",!0),$(document).trigger("spf-reload-script",$this))}))},$(".spf-clean-cache").on("click",(function(e){e.preventDefault(),SPF.vars.is_confirm&&window.wp.ajax.post("spf_clean_transient",{nonce:$("#spf_options_nonce_sptp_settings").val()}).done((function(response){alert("data cleaned")})).fail((function(response){alert("data failed to clean"),alert(response.error)}))})),$(document).ready((function(){$(".spf-save").spf_save(),$(".spf-options").spf_options(),$(".spf-sticky-header").spf_sticky(),$(".spf-nav-options").spf_nav_options(),$(".spf-nav-metabox").spf_nav_metabox(),$(".spf-taxonomy").spf_taxonomy(),$(".spf-page-templates").spf_page_templates(),$(".spf-post-formats").spf_post_formats(),$(".spf-shortcode").spf_shortcode(),$(".spf-search").spf_search(),$(".spf-confirm").spf_confirm(),$(".spf-expand-all").spf_expand_all(),$(".spf-onload").spf_reload_script(),$(".widget").spf_widgets(),$("#menu-to-edit").spf_nav_menu(),$(".spf-field-button_clean.cache_remove .spf--sibling.spf--button").on("click",(function(e){e.preventDefault(),SPF.vars.is_confirm&&window.wp.ajax.post("sptp_clean_transient",{nonce:$("#spf_options_nonce_sptp_settings").val()}).done((function(response){alert("Cache cleaned")})).fail((function(response){alert("Cache failed to clean"),alert(response.error)}))}))}));var $export_type=$(".sptp_what_export").find("input:checked").val();$(".sptp_what_export").on("change",(function(){$export_type=$(this).find("input:checked").val()})),$(".sptp_export .spf--button").click((function(event){event.preventDefault();var $shortcode_ids=$(".sptp_post_ids select").val(),$ex_nonce=$("#spf_options_nonce_sptp_tools").val();if(console.log($ex_nonce),$shortcode_ids.length&&"selected_shortcodes"===$export_type)var data={action:"SPT_export_shortcodes",lcp_ids:$shortcode_ids,nonce:$ex_nonce};else if("all_shortcodes"===$export_type)var data={action:"SPT_export_shortcodes",lcp_ids:"all_shortcodes",nonce:$ex_nonce};else if("all_members"===$export_type)var data={action:"SPT_export_shortcodes",lcp_ids:"all_members",nonce:$ex_nonce};else $(".spf-form-result.spf-form-success").text("No group selected.").show(),setTimeout((function(){$(".spf-form-result.spf-form-success").hide().text("")}),3e3);$.post(ajaxurl,data,(function(resp){if(resp){console.log(resp);var json=JSON.stringify(resp);json=[json];var blob=new Blob(json),link=document.createElement("a"),lcp_time=$.now();link.href=window.URL.createObjectURL(blob),link.download="wp-team-export-"+lcp_time+".json",link.click(),$(".spf-form-result.spf-form-success").text("Exported successfully!").show(),setTimeout((function(){$(".spf-form-result.spf-form-success").hide().text(""),$(".sptp_post_ids select").val("").trigger("chosen:updated")}),3e3)}}))})),$(".sptp_import button.import").click((function(event){event.preventDefault();var sptp_shortcodes=$("#import").prop("files")[0];if(""!=$("#import").val()){var $im_nonce=$("#spf_options_nonce_sptp_tools").val(),reader=new FileReader;reader.readAsText(sptp_shortcodes),reader.onload=function(event){var jsonObj=JSON.stringify(event.target.result);$.ajax({url:ajaxurl,type:"POST",data:{shortcode:jsonObj,action:"SPT_import_shortcodes",nonce:$im_nonce},success:function(resp){console.log(resp),$(".spf-form-result.spf-form-success").text("Imported successfully!").show(),setTimeout((function(){$(".spf-form-result.spf-form-success").hide().text(""),$("#import").val(""),"sptp_member"===resp.data?window.location.replace($("#sptp_member_link_redirect").attr("href")):window.location.replace($("#sptp_shortcode_link_redirect").attr("href"))}),2e3)}})}}else $(".spf-form-result.spf-form-success").text("No exported json file chosen.").show(),setTimeout((function(){$(".spf-form-result.spf-form-success").hide().text("")}),3e3)}));var preview_box=$("#sp__team-preview-box"),preview_display=$("#sptp_preview_display").hide();$(document).on("click","#sp__team-show-preview:contains(Hide)",(function(e){var _this;e.preventDefault(),$(this).html('<i class="fa fa-eye" aria-hidden="true"></i> Show Preview'),preview_box.html(""),preview_display.hide()})),$(document).on("click","#sp__team-show-preview:not(:contains(Hide))",(function(e){e.preventDefault();var previewJS=sptp_admin.previewJS,_data=$("form#post").serialize(),_this=$(this),data={action:"sptp_preview_meta_box",data:_data,ajax_nonce:$("#spf_metabox_noncesptp_preview_display").val()};$.ajax({type:"POST",url:ajaxurl,data:data,error:function(response){console.log(response)},success:function(response){preview_display.show(),preview_box.html(response),$.getScript(previewJS,(function(){_this.html('<i class="fa fa-eye-slash" aria-hidden="true"></i> Hide Preview'),$(document).on("keyup change",".post-type-sptp_generator",(function(e){e.preventDefault(),_this.html('<i class="fa fa-refresh" aria-hidden="true"></i> Update Preview')})),$("html, body").animate({scrollTop:preview_display.offset().top-50},"slow")}))}})})),$(document).on("keyup change",".sptp_member_page_team_settings #spf-form",(function(e){var $button;e.preventDefault(),$(this).find(".spf-save").css({"background-color":"#00C263","pointer-events":"initial"}).val("Save Settings")})),$(".sptp_member_page_team_settings .spf-save").click((function(e){e.preventDefault(),$(this).css({"background-color":"#C5C5C6","pointer-events":"none"}).val("Changes Saved")}))}(jQuery,window,document);
     1!function($,window,document,undefined){"use strict";var SPF=SPF||{};function isValidJSONString(str){try{JSON.parse(str)}catch(e){return!1}return!0}SPF.funcs={},SPF.vars={onloaded:!1,$body:$("body"),$window:$(window),$document:$(document),$form_warning:null,is_confirm:!1,form_modified:!1,code_themes:[],is_rtl:$("body").hasClass("rtl")},SPF.helper={uid:function(prefix){return(prefix||"")+Math.random().toString(36).substr(2,9)},preg_quote:function(str){return(str+"").replace(/(\[|\])/g,"\\$1")},name_nested_replace:function($selector,field_id){var checks=[],regex=new RegExp(SPF.helper.preg_quote(field_id+"[\\d+]"),"g");$selector.find(":radio").each((function(){(this.checked||this.original_checked)&&(this.original_checked=!0)})),$selector.each((function(index){$(this).find(":input").each((function(){this.name=this.name.replace(regex,field_id+"["+index+"]"),this.original_checked&&(this.checked=!0)}))}))},debounce:function(callback,threshold,immediate){var timeout;return function(){var context=this,args=arguments,later=function(){timeout=null,immediate||callback.apply(context,args)},callNow=immediate&&!timeout;clearTimeout(timeout),timeout=setTimeout(later,threshold),callNow&&callback.apply(context,args)}},get_cookie:function(name){var e,b,cookie=document.cookie,p=name+"=";if(cookie){if(-1===(b=cookie.indexOf("; "+p))){if(0!==(b=cookie.indexOf(p)))return null}else b+=2;return-1===(e=cookie.indexOf(";",b))&&(e=cookie.length),decodeURIComponent(cookie.substring(b+p.length,e))}},set_cookie:function(name,value,expires,path,domain,secure){var d=new Date;"object"==typeof expires&&expires.toGMTString?expires=expires.toGMTString():parseInt(expires,10)?(d.setTime(d.getTime()+1e3*parseInt(expires,10)),expires=d.toGMTString()):expires="",document.cookie=name+"="+encodeURIComponent(value)+(expires?"; expires="+expires:"")+(path?"; path="+path:"")+(domain?"; domain="+domain:"")+(secure?"; secure":"")},remove_cookie:function(name,path,domain,secure){SPF.helper.set_cookie(name,"",-1e3,path,domain,secure)}},$.fn.spf_clone=function(){for(var base=$.fn.clone.apply(this,arguments),clone=this.find("select").add(this.filter("select")),cloned=base.find("select").add(base.filter("select")),i=0;i<clone.length;++i)for(var j=0;j<clone[i].options.length;++j)!0===clone[i].options[j].selected&&(cloned[i].options[j].selected=!0);return this.find(":radio").each((function(){this.original_checked=this.checked})),base},$.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")}))}))},$.fn.spf_nav_options=function(){return this.each((function(){var $nav,$links=$(this).find("a"),$last;$(window).on("hashchange spf.hashchange",(function(){var hash=window.location.hash.replace("#tab=",""),slug=hash||$links.first().attr("href").replace("#tab=",""),$link=$('[data-tab-id="'+slug+'"]');if($link.length){$link.closest(".spf-tab-item").addClass("spf-tab-expanded").siblings().removeClass("spf-tab-expanded"),$link.next().is("ul")&&(slug=($link=$link.next().find("li").first().find("a")).data("tab-id")),$links.removeClass("spf-active"),$link.addClass("spf-active"),$last&&$last.addClass("hidden");var $section=$('[data-section-id="'+slug+'"]');$section.removeClass("hidden"),$section.spf_reload_script(),$(".spf-section-id").val($section.index()+1),$last=$section}})).trigger("spf.hashchange")}))},$.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",$sections=$nav.parent().find(".spf-section"),$last;$links.each((function(index){$(this).on("click",(function(e){e.preventDefault();var $link=$(this),section_id=$link.data("section");$links.removeClass("spf-active"),$link.addClass("spf-active"),void 0!==$last&&$last.addClass("hidden");var $section=$sections.eq(index);$section.removeClass("hidden"),$section.spf_reload_script(),SPF.helper.set_cookie("spf-last-metabox-tab-"+post_id+"-"+unique_id,section_id),$last=$section}));var get_cookie=SPF.helper.get_cookie("spf-last-metabox-tab-"+post_id+"-"+unique_id);get_cookie?$nav.find('a[data-section="'+get_cookie+'"]').trigger("click"):$links.first("a").trigger("click")}))}))},$.fn.spf_page_templates=function(){this.length&&$(document).on("change",".editor-page-attributes__template select, #page_template",(function(){var maybe_value=$(this).val()||"default";$(".spf-page-templates").removeClass("spf-metabox-show").addClass("spf-metabox-hide"),$(".spf-page-"+maybe_value.toLowerCase().replace(/[^a-zA-Z0-9]+/g,"-")).removeClass("spf-metabox-hide").addClass("spf-metabox-show")}))},$.fn.spf_post_formats=function(){this.length&&$(document).on("change",'.editor-post-format select, #formatdiv input[name="post_format"]',(function(){var maybe_value=$(this).val()||"default";maybe_value="0"===maybe_value?"default":maybe_value,$(".spf-post-formats").removeClass("spf-metabox-show").addClass("spf-metabox-hide"),$(".spf-post-format-"+maybe_value).removeClass("spf-metabox-hide").addClass("spf-metabox-show")}))},$.fn.spf_search=function(){return this.each((function(){var $this,$input;$(this).find("input").on("change keyup",(function(){var value=$(this).val(),$wrapper=$(".spf-wrapper"),$section,$fields=$wrapper.find(".spf-section").find("> .spf-field:not(.spf-depend-on)"),$titles=$fields.find("> .spf-title, .spf-search-tags");value.length>3?($fields.addClass("spf-metabox-hide"),$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-metabox-hide"),$field.parent().spf_reload_script()}}))):($fields.removeClass("spf-metabox-hide"),$wrapper.removeClass("spf-search-all"))}))}))},$.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=!1,stickyUpdate=function(){var offsetTop=$this.offset().top,stickyTop=Math.max(32,offsetTop-scrollTop),winWidth=Math.max(document.documentElement.clientWidth,window.innerWidth||0);stickyTop<=32&&winWidth>782?($inner.css({width:$this.outerWidth()-padding}),$this.css({height:$this.outerHeight()}).addClass("spf-sticky")):($inner.removeAttr("style"),$this.removeAttr("style").removeClass("spf-sticky"))},requestTick=function(){ticking||requestAnimationFrame((function(){stickyUpdate(),ticking=!1})),ticking=!0},onSticky=function(){scrollTop=$window.scrollTop(),requestTick()};$window.on("scroll resize",onSticky),onSticky()}))},$.fn.spf_dependency=function(){return this.each((function(){var $this=$(this),$fields=$this.children("[data-controller]");if($fields.length){var normal_ruleset=$.spf_deps.createRuleset(),global_ruleset=$.spf_deps.createRuleset(),normal_depends=[],global_depends=[];$fields.each((function(){var $field=$(this),controllers=$field.data("controller").split("|"),conditions=$field.data("condition").split("|"),values=$field.data("value").toString().split("|"),is_global=!!$field.data("depend-global"),ruleset=is_global?global_ruleset:normal_ruleset;$.each(controllers,(function(index,depend_id){var value=values[index]||"",condition=conditions[index]||conditions[0];(ruleset=ruleset.createRule('[data-depend-id="'+depend_id+'"]',condition,value)).include($field),is_global?global_depends.push(depend_id):normal_depends.push(depend_id)}))})),normal_depends.length&&$.spf_deps.enable($this,normal_ruleset,normal_depends),global_depends.length&&$.spf_deps.enable(SPF.vars.$body,global_ruleset,global_depends)}}))},$.fn.spf_field_code_editor=function(){return this.each((function(){if("function"==typeof CodeMirror){var $this=$(this),$textarea=$this.find("textarea"),$inited=$this.find(".CodeMirror"),data_editor=$textarea.data("editor");$inited.length&&$inited.remove();var interval=setInterval((function(){if($this.is(":visible")){var code_editor=CodeMirror.fromTextArea($textarea[0],data_editor);if("default"!==data_editor.theme&&-1===SPF.vars.code_themes.indexOf(data_editor.theme)){var $cssLink=$("<link>");$("#spf-codemirror-css").after($cssLink),$cssLink.attr({rel:"stylesheet",id:"spf-codemirror-"+data_editor.theme+"-css",href:data_editor.cdnURL+"/theme/"+data_editor.theme+".min.css",type:"text/css",media:"all"}),SPF.vars.code_themes.push(data_editor.theme)}CodeMirror.modeURL=data_editor.cdnURL+"/mode/%N/%N.min.js",CodeMirror.autoLoadMode(code_editor,data_editor.mode),code_editor.on("change",(function(editor,event){$textarea.val(code_editor.getValue()).trigger("change")})),clearInterval(interval)}}))}}))},$.fn.spf_field_fieldset=function(){return this.each((function(){$(this).find(".spf-fieldset-content").spf_reload_script()}))},$.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"),is_number=Boolean(Number($wrapper.data("title-number"))),max=parseInt($wrapper.data("max")),min=parseInt($wrapper.data("min"));$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+".")}))};$wrapper.accordion({header:"> .spf-cloneable-item > .spf-cloneable-title",collapsible:!0,active:!1,animate:!1,heightStyle:"content",icons:{header:"spf-cloneable-header-icon fas fa-angle-right",activeHeader:"spf-cloneable-header-icon fas fa-angle-down"},activate:function(event,ui){var $panel=ui.newPanel,$header=ui.newHeader;if($panel.length&&!$panel.data("opened")){var $fields,$first=$panel.children().first().find(":input").first(),$title=$header.find(".spf-cloneable-value");$first.on("change keyup",(function(event){$title.text($first.val())})),$panel.spf_reload_script(),$panel.data("opened",!0),$panel.data("retry",!1)}else $panel.data("retry")&&($panel.spf_reload_script_retry(),$panel.data("retry",!1))}}),$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:!1}),$wrapper.sortable("refreshPositions"),ui.item.children(".spf-cloneable-content").data("retry",!0)},update:function(event,ui){SPF.helper.name_nested_replace($wrapper.children(".spf-cloneable-item"),field_id),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;if($min.hide(),max&&count+1>max)$max.show();else{var $cloned_item=$hidden.spf_clone(!0);$cloned_item.removeClass("spf-cloneable-hidden"),$cloned_item.find(':input[name!="_pseudo"]').each((function(){this.name=this.name.replace("___","").replace(field_id+"[0]",field_id+"["+count+"]")})),$wrapper.append($cloned_item),$wrapper.accordion("refresh"),$wrapper.accordion({active:count}),is_number&&update_title_numbers($wrapper)}}));var event_clone=function(e){e.preventDefault();var count=$wrapper.children(".spf-cloneable-item").length;if($min.hide(),max&&count+1>max)$max.show();else{var $this,$parent=$(this).parent().parent(),$cloned_helper=$parent.children(".spf-cloneable-helper").spf_clone(!0),$cloned_title=$parent.children(".spf-cloneable-title").spf_clone(),$cloned_content=$parent.children(".spf-cloneable-content").spf_clone(),$cloned_item=$('<div class="spf-cloneable-item" />');$cloned_item.append($cloned_helper),$cloned_item.append($cloned_title),$cloned_item.append($cloned_content),$wrapper.children().eq($parent.index()).after($cloned_item),SPF.helper.name_nested_replace($wrapper.children(".spf-cloneable-item"),field_id),$wrapper.accordion("refresh"),is_number&&update_title_numbers($wrapper)}};$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(),min&&count-1<min?$min.show():($(this).closest(".spf-cloneable-item").remove(),SPF.helper.name_nested_replace($wrapper.children(".spf-cloneable-item"),field_id),is_number&&update_title_numbers($wrapper))};$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)}))},$.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),$modal=$("#spf-modal-icon");$modal.removeClass("hidden"),SPF.vars.$icon_target=$this,SPF.vars.icon_modal_loaded||($modal.find(".spf-modal-loading").show(),window.wp.ajax.post("spf-get-icons",{nonce:$button.data("nonce")}).done((function(response){$modal.find(".spf-modal-loading").hide(),SPF.vars.icon_modal_loaded=!0;var $load=$modal.find(".spf-modal-load").html(response.content);$load.on("click","i",(function(e){e.preventDefault();var icon=$(this).attr("title");SPF.vars.$icon_target.find(".spf-icon-preview i").removeAttr("class").addClass(icon),SPF.vars.$icon_target.find(".spf-icon-preview").removeClass("hidden"),SPF.vars.$icon_target.find(".spf-icon-remove").removeClass("hidden"),SPF.vars.$icon_target.find("input").val(icon).trigger("change"),$modal.addClass("hidden")})),$modal.on("change keyup",".spf-icon-search",(function(){var value=$(this).val(),$icons;$load.find("i").each((function(){var $elem=$(this);$elem.attr("title").search(new RegExp(value,"i"))<0?$elem.hide():$elem.show()}))})),$modal.on("click",".spf-modal-close, .spf-modal-overlay",(function(){$modal.addClass("hidden")}))})).fail((function(response){$modal.find(".spf-modal-loading").hide(),$modal.find(".spf-modal-load").html(response.error),$modal.on("click",(function(){$modal.addClass("hidden")}))})))})),$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")}))}))},$.fn.spf_field_repeater=function(){return this.each((function(){var $this=$(this),$fieldset=$this.children(".spf-fieldset"),$repeater=$fieldset.length?$fieldset:$this,$wrapper=$repeater.children(".spf-repeater-wrapper"),$hidden=$repeater.children(".spf-repeater-hidden"),$max=$repeater.children(".spf-repeater-max"),$min=$repeater.children(".spf-repeater-min"),field_id=$wrapper.data("field-id"),max=parseInt($wrapper.data("max")),min=parseInt($wrapper.data("min"));$wrapper.children(".spf-repeater-item").children(".spf-repeater-content").spf_reload_script(),$wrapper.sortable({axis:"y",handle:".spf-repeater-sort",helper:"original",cursor:"move",placeholder:"widget-placeholder",update:function(event,ui){SPF.helper.name_nested_replace($wrapper.children(".spf-repeater-item"),field_id),ui.item.spf_reload_script_retry()}}),$repeater.children(".spf-repeater-add").on("click",(function(e){e.preventDefault();var count=$wrapper.children(".spf-repeater-item").length;if($min.hide(),max&&count+1>max)$max.show();else{var $cloned_item=$hidden.spf_clone(!0);$cloned_item.removeClass("spf-repeater-hidden"),$cloned_item.find(':input[name!="_pseudo"]').each((function(){this.name=this.name.replace("___","").replace(field_id+"[0]",field_id+"["+count+"]")})),$wrapper.append($cloned_item),$cloned_item.children(".spf-repeater-content").spf_reload_script()}}));var event_clone=function(e){e.preventDefault();var count=$wrapper.children(".spf-repeater-item").length;if($min.hide(),max&&count+1>max)$max.show();else{var $this,$parent=$(this).parent().parent().parent(),$cloned_content=$parent.children(".spf-repeater-content").spf_clone(),$cloned_helper=$parent.children(".spf-repeater-helper").spf_clone(!0),$cloned_item=$('<div class="spf-repeater-item" />');$cloned_item.append($cloned_content),$cloned_item.append($cloned_helper),$wrapper.children().eq($parent.index()).after($cloned_item),$cloned_item.children(".spf-repeater-content").spf_reload_script(),SPF.helper.name_nested_replace($wrapper.children(".spf-repeater-item"),field_id)}};$wrapper.children(".spf-repeater-item").children(".spf-repeater-helper").on("click",".spf-repeater-clone",event_clone),$repeater.children(".spf-repeater-hidden").children(".spf-repeater-helper").on("click",".spf-repeater-clone",event_clone);var event_remove=function(e){e.preventDefault();var count=$wrapper.children(".spf-repeater-item").length;$max.hide(),$min.hide(),min&&count-1<min?$min.show():($(this).closest(".spf-repeater-item").remove(),SPF.helper.name_nested_replace($wrapper.children(".spf-repeater-item"),field_id))};$wrapper.children(".spf-repeater-item").children(".spf-repeater-helper").on("click",".spf-repeater-remove",event_remove),$repeater.children(".spf-repeater-hidden").children(".spf-repeater-helper").on("click",".spf-repeater-remove",event_remove)}))},$.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;$slider.hasClass("ui-slider")&&$slider.empty(),$slider.slider({range:"min",value:value,min:data.min||0,max:data.max||100,step:data.step||1,slide:function(e,o){$input.val(o.value).trigger("change")}}),$input.on("keyup",(function(){$slider.slider("value",$input.val())}))}))},$.fn.spf_field_sortable=function(){return this.each((function(){var $sortable=$(this).find(".spf-sortable");$sortable.sortable({axis:"y",helper:"original",cursor:"move",placeholder:"widget-placeholder",update:function(event,ui){}}),$sortable.find(".spf-sortable-content").spf_reload_script()}))},$.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;$enabled.sortable({connectWith:$disabled,placeholder:"ui-sortable-placeholder",update:function(event,ui){var $el=ui.item.find("input");ui.item.parent().hasClass("spf-enabled")?$el.attr("name",$el.attr("name").replace("disabled","enabled")):$el.attr("name",$el.attr("name").replace("enabled","disabled"))}}),$disabled&&$disabled.sortable({connectWith:$enabled,placeholder:"ui-sortable-placeholder",update:function(event,ui){}})}))},$.fn.spf_field_spinner=function(){return this.each((function(){var $this=$(this),$input=$this.find("input"),$inited=$this.find(".ui-button"),data=$input.data();$inited.length&&$inited.remove(),$input.spinner({min:data.min||0,max:data.max||100,step:data.step||1,create:function(event,ui){data.unit&&$input.after('<span class="ui-button spf--unit">'+data.unit+"</span>")},spin:function(event,ui){$input.val(ui.value).trigger("change")}})}))},$.fn.spf_field_switcher=function(){return this.each((function(){var $switcher=$(this).find(".spf--switcher");$switcher.on("click",(function(){var value=0,$input=$switcher.find("input");$switcher.hasClass("spf--active")?$switcher.removeClass("spf--active"):(value=1,$switcher.addClass("spf--active")),$input.val(value).trigger("change")}))}))},$.fn.spf_field_tabbed=function(){return this.each((function(){var $this=$(this),$links=$this.find(".spf-tabbed-nav a"),$contents=$this.find(".spf-tabbed-content");$contents.eq(0).spf_reload_script(),$links.on("click",(function(e){e.preventDefault();var $link=$(this),index=$link.index(),$content=$contents.eq(index);$link.addClass("spf-tabbed-active").siblings().removeClass("spf-tabbed-active"),$content.spf_reload_script(),$content.removeClass("hidden").siblings().addClass("hidden")}))}))},$.fn.spf_field_upload=function(){return this.each((function(){var $this=$(this),$input=$this.find("input"),$upload_button=$this.find(".spf--button"),$remove_button=$this.find(".spf--remove"),$library=$upload_button.data("library")&&$upload_button.data("library").split(",")||"",wp_media_frame;$input.on("change",(function(e){$input.val()?$remove_button.removeClass("hidden"):$remove_button.addClass("hidden")})),$upload_button.on("click",(function(e){e.preventDefault(),void 0!==window.wp&&window.wp.media&&window.wp.media.gallery&&(wp_media_frame?wp_media_frame.open():((wp_media_frame=window.wp.media({library:{type:$library}})).on("select",(function(){var attributes=wp_media_frame.state().get("selection").first().attributes;$library.length&&-1===$library.indexOf(attributes.subtype)&&-1===$library.indexOf(attributes.type)||$input.val(attributes.url).trigger("change")})),wp_media_frame.open()))})),$remove_button.on("click",(function(e){e.preventDefault(),$input.val("").trigger("change")}))}))},$.fn.spf_confirm=function(){return this.each((function(){$(this).on("click",(function(e){var confirm_text=$(this).data("confirm")||window.spf_vars.i18n.confirm,confirm_answer;if(!confirm(confirm_text))return e.preventDefault(),!1;SPF.vars.is_confirm=!0,SPF.vars.form_modified=!1}))}))},$.fn.serializeObject=function(){var obj={};return $.each(this.serializeArray(),(function(i,o){var n=o.name,v=o.value;obj[n]=void 0===obj[n]?v:$.isArray(obj[n])?obj[n].concat(v):[obj[n],v]})),obj},$.fn.spf_save=function(){return this.each((function(){var $this=$(this),$buttons=$(".spf-save"),$panel=$(".spf-options"),flooding=!1,timeout;$this.on("click",(function(e){if(!flooding){var $text=$this.data("save"),$value=$this.val();$buttons.attr("value",$text),$this.hasClass("spf-save-ajax")?(e.preventDefault(),$panel.addClass("spf-saving"),$buttons.prop("disabled",!0),window.wp.ajax.post("spf_"+$panel.data("unique")+"_ajax_save",{data:$("#spf-form").serializeJSONSPF()}).done((function(response){if($(".spf-error").remove(),Object.keys(response.errors).length){var error_icon='<i class="spf-label-error spf-error">!</i>';$.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('<p class="spf-error spf-error-text">'+error_message+"</p>"),$link.find(".spf-error").length||$link.append(error_icon),$tab.find(".spf-arrow .spf-error").length||$tab.find(".spf-arrow").append(error_icon)}))}$panel.removeClass("spf-saving"),$buttons.prop("disabled",!1).attr("value",$value),flooding=!1,SPF.vars.form_modified=!1,SPF.vars.$form_warning.hide(),clearTimeout(timeout);var $result_success=$(".spf-form-success");$result_success.empty().append(response.notice).fadeIn("fast",(function(){timeout=setTimeout((function(){$result_success.fadeOut("fast")}),1e3)}))})).fail((function(response){alert(response.error)}))):SPF.vars.form_modified=!1}flooding=!0}))}))},$.fn.spf_options=function(){return this.each((function(){var $this=$(this),$content=$this.find(".spf-content"),$form_success=$this.find(".spf-form-success"),$form_warning=$this.find(".spf-form-warning"),$save_button=$this.find(".spf-header .spf-save");SPF.vars.$form_warning=$form_warning,$form_warning.length&&(window.onbeforeunload=function(){return!!SPF.vars.form_modified||void 0},$content.on("change keypress",":input",(function(){SPF.vars.form_modified||($form_success.hide(),$form_warning.fadeIn("fast"),SPF.vars.form_modified=!0)}))),$form_success.hasClass("spf-form-show")&&setTimeout((function(){$form_success.fadeOut("fast")}),1e3),$(document).keydown((function(event){if((event.ctrlKey||event.metaKey)&&83===event.which)return $save_button.trigger("click"),event.preventDefault(),!1}))}))},$.fn.spf_taxonomy=function(){return this.each((function(){var $this=$(this),$form=$this.parents("form");if("addtag"===$form.attr("id")){var $submit=$form.find("#submit"),$cloned=$this.find(".spf-field").spf_clone();$submit.on("click",(function(){$form.find(".form-required").hasClass("form-invalid")||($this.data("inited",!1),$this.empty(),$this.html($cloned),$cloned=$cloned.spf_clone(),$this.spf_reload_script())}))}}))},$.fn.spf_shortcode=function(){var base=this;return base.shortcode_parse=function(serialize,key){var shortcode="";return $.each(serialize,(function(shortcode_key,shortcode_values){shortcode+="["+(key=key||shortcode_key),$.each(shortcode_values,(function(shortcode_tag,shortcode_value){"content"===shortcode_tag?(shortcode+="]",shortcode+=shortcode_value,shortcode+="[/"+key):shortcode+=base.shortcode_tags(shortcode_tag,shortcode_value)})),shortcode+="]"})),shortcode},base.shortcode_tags=function(shortcode_tag,shortcode_value){var shortcode="";return""!==shortcode_value&&("object"!=typeof shortcode_value||$.isArray(shortcode_value)?shortcode+=" "+shortcode_tag.replace("-","_")+'="'+shortcode_value.toString()+'"':$.each(shortcode_value,(function(sub_shortcode_tag,sub_shortcode_value){switch(sub_shortcode_tag){case"background-image":sub_shortcode_value=sub_shortcode_value.url?sub_shortcode_value.url:""}""!==sub_shortcode_value&&(shortcode+=" "+sub_shortcode_tag.replace("-","_")+'="'+sub_shortcode_value.toString()+'"')}))),shortcode},base.insertAtChars=function(_this,currentValue){var obj=void 0!==_this[0].name?_this[0]:_this;return obj.value.length&&void 0!==obj.selectionStart?(obj.focus(),obj.value.substring(0,obj.selectionStart)+currentValue+obj.value.substring(obj.selectionEnd,obj.value.length)):(obj.focus(),currentValue)},base.send_to_editor=function(html,editor_id){var tinymce_editor;if("undefined"!=typeof tinymce&&(tinymce_editor=tinymce.get(editor_id)),tinymce_editor&&!tinymce_editor.isHidden())tinymce_editor.execCommand("mceInsertContent",!1,html);else{var $editor=$("#"+editor_id);$editor.val(base.insertAtChars($editor,html)).trigger("change")}},this.each((function(){var $modal=$(this),$load=$modal.find(".spf-modal-load"),$content=$modal.find(".spf-modal-content"),$insert=$modal.find(".spf-modal-insert"),$loading=$modal.find(".spf-modal-loading"),$select=$modal.find("select"),modal_id=$modal.data("modal-id"),nonce=$modal.data("nonce"),editor_id,target_id,sc_key,sc_name,sc_view,sc_group,$cloned,$button;$(document).on("click",'.spf-shortcode-button[data-modal-id="'+modal_id+'"]',(function(e){e.preventDefault(),$button=$(this),editor_id=$button.data("editor-id")||!1,target_id=$button.data("target-id")||!1,$modal.removeClass("hidden"),$modal.hasClass("spf-shortcode-single")&&void 0===sc_name&&$select.trigger("change")})),$select.on("change",(function(){var $option=$(this),$selected=$option.find(":selected");sc_key=$option.val(),sc_name=$selected.data("shortcode"),sc_view=$selected.data("view")||"normal",sc_group=$selected.data("group")||sc_name,$load.empty(),sc_key?($loading.show(),window.wp.ajax.post("spf-get-shortcode-"+modal_id,{shortcode_key:sc_key,nonce:nonce}).done((function(response){$loading.hide();var $appended=$(response.content).appendTo($load);$insert.parent().removeClass("hidden"),$cloned=$appended.find(".spf--repeat-shortcode").spf_clone(),$appended.spf_reload_script(),$appended.find(".spf-fields").spf_reload_script()}))):$insert.parent().addClass("hidden")})),$insert.on("click",(function(e){if(e.preventDefault(),!$insert.prop("disabled")&&!$insert.attr("disabled")){var shortcode="",serialize=$modal.find(".spf-field:not(.spf-depend-on)").find(":input:not(.ignore)").serializeObjectSPF();switch(sc_view){case"contents":var contentsObj=sc_name?serialize[sc_name]:serialize;$.each(contentsObj,(function(sc_key,sc_value){var sc_tag=sc_name||sc_key;shortcode+="["+sc_tag+"]"+sc_value+"[/"+sc_tag+"]"}));break;case"group":shortcode+="["+sc_name,$.each(serialize[sc_name],(function(sc_key,sc_value){shortcode+=base.shortcode_tags(sc_key,sc_value)})),shortcode+="]",shortcode+=base.shortcode_parse(serialize[sc_group],sc_group),shortcode+="[/"+sc_name+"]";break;case"repeater":shortcode+=base.shortcode_parse(serialize[sc_group],sc_group);break;default:shortcode+=base.shortcode_parse(serialize)}if(shortcode=""===shortcode?"["+sc_name+"]":shortcode,editor_id)base.send_to_editor(shortcode,editor_id);else{var $textarea=target_id?$(target_id):$button.parent().find("textarea");$textarea.val(base.insertAtChars($textarea,shortcode)).trigger("change")}$modal.addClass("hidden")}})),$modal.on("click",".spf--repeat-button",(function(e){e.preventDefault();var $repeatable=$modal.find(".spf--repeatable"),$new_clone=$cloned.spf_clone(),$remove_btn=$new_clone.find(".spf-repeat-remove"),$appended=$new_clone.appendTo($repeatable);$new_clone.find(".spf-fields").spf_reload_script(),SPF.helper.name_nested_replace($modal.find(".spf--repeat-shortcode"),sc_group),$remove_btn.on("click",(function(){$new_clone.remove(),SPF.helper.name_nested_replace($modal.find(".spf--repeat-shortcode"),sc_group)}))})),$modal.on("click",".spf-modal-close, .spf-modal-overlay",(function(){$modal.addClass("hidden")}))}))},"function"==typeof Color&&(Color.prototype.toString=function(){if(this._alpha<1)return this.toCSS("rgba",this._alpha).replace(/\s+/g,"");var hex=parseInt(this._color,10).toString(16);if(this.error)return"";if(hex.length<6)for(var i=6-hex.length-1;i>=0;i--)hex="0"+hex;return"#"+hex}),SPF.funcs.parse_color=function(color){var value=color.replace(/\s+/g,""),trans=-1!==value.indexOf("rgba")?parseFloat(100*value.replace(/^.*,(.+)\)/,"$1")):100,rgba;return{value:value,transparent:trans,rgba:trans<100}},$.fn.spf_color=function(){return this.each((function(){var $input=$(this),picker_color=SPF.funcs.parse_color($input.val()),palette_color=!window.spf_vars.color_palette.length||window.spf_vars.color_palette,$container;$input.hasClass("wp-color-picker")&&$input.closest(".wp-picker-container").after($input).remove(),$input.wpColorPicker({palettes:palette_color,change:function(event,ui){var ui_color_value=ui.color.toString();$container.removeClass("spf--transparent-active"),$container.find(".spf--transparent-offset").css("background-color",ui_color_value),$input.val(ui_color_value).trigger("change")},create:function(){$container=$input.closest(".wp-picker-container");var a8cIris=$input.data("a8cIris"),$transparent_wrap=$('<div class="spf--transparent-wrap"><div class="spf--transparent-slider"></div><div class="spf--transparent-offset"></div><div class="spf--transparent-text"></div><div class="spf--transparent-button">transparent <i class="fas fa-toggle-off"></i></div></div>').appendTo($container.find(".wp-picker-holder")),$transparent_slider=$transparent_wrap.find(".spf--transparent-slider"),$transparent_text=$transparent_wrap.find(".spf--transparent-text"),$transparent_offset=$transparent_wrap.find(".spf--transparent-offset"),$transparent_button=$transparent_wrap.find(".spf--transparent-button");"transparent"===$input.val()&&$container.addClass("spf--transparent-active"),$transparent_button.on("click",(function(){"transparent"!==$input.val()?($input.val("transparent").trigger("change").removeClass("iris-error"),$container.addClass("spf--transparent-active")):($input.val(a8cIris._color.toString()).trigger("change"),$container.removeClass("spf--transparent-active"))})),$transparent_slider.slider({value:picker_color.transparent,step:1,min:0,max:100,slide:function(event,ui){var slide_value=parseFloat(ui.value/100);a8cIris._color._alpha=slide_value,$input.wpColorPicker("color",a8cIris._color.toString()),$transparent_text.text(1===slide_value||0===slide_value?"":slide_value)},create:function(){var slide_value=parseFloat(picker_color.transparent/100),text_value=slide_value<1?slide_value:"";$transparent_text.text(text_value),$transparent_offset.css("background-color",picker_color.value),$container.on("click",".wp-picker-clear",(function(){a8cIris._color._alpha=1,$transparent_text.text(""),$transparent_slider.slider("option","value",100),$container.removeClass("spf--transparent-active"),$input.trigger("change")})),$container.on("click",".wp-picker-default",(function(){var default_color=SPF.funcs.parse_color($input.data("default-color")),default_value=parseFloat(default_color.transparent/100),default_text=default_value<1?default_value:"";a8cIris._color._alpha=default_value,$transparent_text.text(default_text),$transparent_slider.slider("option","value",default_color.transparent),"transparent"===default_color.value&&($input.removeClass("iris-error"),$container.addClass("spf--transparent-active"))}))}})}})}))},$.fn.spf_chosen=function(){return this.each((function(){var $this=$(this),$inited=$this.parent().find(".chosen-container"),is_sortable=$this.hasClass("spf-chosen-sortable")||!1,is_ajax=$this.hasClass("spf-chosen-ajax")||!1,is_multiple=$this.attr("multiple")||!1,set_width=is_multiple?"100%":"auto",set_options=$.extend({allow_single_deselect:!0,disable_search_threshold:10,width:set_width,no_results_text:window.spf_vars.i18n.no_results_text},$this.data("chosen-settings"));if($inited.length&&$inited.remove(),is_ajax){var set_ajax_options=$.extend({data:{type:"post",nonce:""},allow_single_deselect:!0,disable_search_threshold:-1,width:"100%",min_length:3,type_delay:500,typing_text:window.spf_vars.i18n.typing_text,searching_text:window.spf_vars.i18n.searching_text,no_results_text:window.spf_vars.i18n.no_results_text},$this.data("chosen-settings"));$this.SPFAjaxChosen(set_ajax_options)}else $this.chosen(set_options);if(is_multiple){var $hidden_select=$this.parent().find(".spf-hide-select"),$hidden_value=$hidden_select.val()||[];$this.on("change",(function(obj,result){result&&result.selected?$hidden_select.append('<option value="'+result.selected+'" selected="selected">'+result.selected+"</option>"):result&&result.deselected&&$hidden_select.find('option[value="'+result.deselected+'"]').remove(),void 0!==window.wp.customize&&0===$hidden_select.children().length&&$hidden_select.data("customize-setting-link")&&window.wp.customize.control($hidden_select.data("customize-setting-link")).setting.set(""),$hidden_select.trigger("change")})),$this.CSFChosenOrder($hidden_value,!0)}if(is_sortable){var $chosen_container,$chosen_choices=$this.parent().find(".chosen-container").find(".chosen-choices");$chosen_choices.bind("mousedown",(function(event){$(event.target).is("span")&&event.stopPropagation()})),$chosen_choices.sortable({items:"li:not(.search-field)",helper:"orginal",cursor:"move",placeholder:"search-choice-placeholder",start:function(e,ui){ui.placeholder.width(ui.item.innerWidth()),ui.placeholder.height(ui.item.innerHeight())},update:function(e,ui){var select_options="",chosen_object=$this.data("chosen"),$prev_select=$this.parent().find(".spf-hide-select");$chosen_choices.find(".search-choice-close").each((function(){var option_array_index=$(this).data("option-array-index");$.each(chosen_object.results_data,(function(index,data){data.array_index===option_array_index&&(select_options+='<option value="'+data.value+'" selected>'+data.value+"</option>")}))})),$prev_select.children().remove(),$prev_select.append(select_options),$prev_select.trigger("change")}})}}))},$.fn.spf_checkbox=function(){return this.each((function(){var $this=$(this),$input=$this.find(".spf--input"),$checkbox=$this.find(".spf--checkbox");$checkbox.on("click",(function(){$input.val(Number($checkbox.prop("checked"))).trigger("change")}))}))},$.fn.spf_siblings=function(){return this.each((function(){var $this=$(this),$siblings=$this.find(".spf--sibling"),multiple=$this.data("multiple")||!1;$siblings.on("click",(function(){var $sibling=$(this);multiple?$sibling.hasClass("spf--active")?($sibling.removeClass("spf--active"),$sibling.find("input").prop("checked",!1).trigger("change")):($sibling.addClass("spf--active"),$sibling.find("input").prop("checked",!0).trigger("change")):($this.find("input").prop("checked",!1),$sibling.find("input").prop("checked",!0).trigger("change"),$sibling.addClass("spf--active").siblings().removeClass("spf--active"))}))}))},$.fn.spf_help=function(){return this.each((function(){var $this=$(this),$tooltip,offset_left;$this.on({mouseenter:function(){$tooltip=$('<div class="spf-tooltip"></div>').html($this.find(".spf-help-text").html()).appendTo("body"),offset_left=SPF.vars.is_rtl?$this.offset().left-230:$this.offset().left+24,$tooltip.css({top:$this.offset().top-($tooltip.outerHeight()/2-14),left:offset_left,textAlign:SPF.vars.is_rtl?"right":"left"})},mouseleave:function(){void 0!==$tooltip&&$tooltip.remove()}})}))},SPF.vars.$window.on("resize spf.resize",SPF.helper.debounce((function(event){var window_width;(navigator.userAgent.indexOf("AppleWebKit/")>-1?SPF.vars.$window.width():window.innerWidth)<=782&&!SPF.vars.onloaded&&($(".spf-section").spf_reload_script(),SPF.vars.onloaded=!0)}),200)).trigger("spf.resize"),$.fn.spf_widgets=function(){this.length&&($(document).on("widget-added widget-updated",(function(event,$widget){$widget.find(".spf-fields").spf_reload_script()})),$(".widgets-sortables, .control-section-sidebar").on("sortstop",(function(event,ui){ui.item.find(".spf-fields").spf_reload_script_retry()})),$(document).on("click",".widget-top",(function(event){$(this).parent().find(".spf-fields").spf_reload_script()})))},$.fn.spf_nav_menu=function(){return this.each((function(){var $navmenu=$(this);$navmenu.on("click","a.item-edit",(function(){$(this).closest("li.menu-item").find(".spf-fields").spf_reload_script()})),$navmenu.on("sortstop",(function(event,ui){ui.item.find(".spf-fields").spf_reload_script_retry()}))}))},$.fn.spf_reload_script_retry=function(){return this.each((function(){var $this;$(this).data("inited")}))},$.fn.spf_reload_script=function(options){var settings=$.extend({dependency:!0},options);return this.each((function(){var $this=$(this);$this.data("inited")||($this.children(".spf-field-code_editor").spf_field_code_editor(),$this.children(".spf-field-fieldset").spf_field_fieldset(),$this.children(".spf-field-group").spf_field_group(),$this.children(".spf-field-icon").spf_field_icon(),$this.children(".spf-field-repeater").spf_field_repeater(),$this.children(".spf-field-slider").spf_field_slider(),$this.children(".spf-field-sortable").spf_field_sortable(),$this.children(".spf-field-sorter").spf_field_sorter(),$this.children(".spf-field-spinner").spf_field_spinner(),$this.children(".spf-field-switcher").spf_field_switcher(),$this.children(".spf-field-tabbed").spf_field_tabbed(),$this.children(".spf-field-upload").spf_field_upload(),$this.children(".spf-field-box_shadow").find(".spf-color").spf_color(),$this.children(".spf-field-border").find(".spf-color").spf_color(),$this.children(".spf-field-background").find(".spf-color").spf_color(),$this.children(".spf-field-color").find(".spf-color").spf_color(),$this.children(".spf-field-color_group").find(".spf-color").spf_color(),$this.children(".spf-field-link_color").find(".spf-color").spf_color(),$this.children(".spf-field-typography").find(".spf-color").spf_color(),$this.children(".spf-field-select").find(".spf-chosen").spf_chosen(),$this.children(".spf-field-checkbox").find(".spf-checkbox").spf_checkbox(),$this.children(".spf-field-button_set").find(".spf-siblings").spf_siblings(),$this.children(".spf-field-image_select").find(".spf-siblings").spf_siblings(),$this.children(".spf-field-palette").find(".spf-siblings").spf_siblings(),$this.children(".spf-field").find(".spf-help").spf_help(),settings.dependency&&$this.spf_dependency(),$this.data("inited",!0),$(document).trigger("spf-reload-script",$this))}))},$(".spf-clean-cache").on("click",(function(e){e.preventDefault(),SPF.vars.is_confirm&&window.wp.ajax.post("spf_clean_transient",{nonce:$("#spf_options_nonce_sptp_settings").val()}).done((function(response){alert("data cleaned")})).fail((function(response){alert("data failed to clean"),alert(response.error)}))})),$(document).ready((function(){$(".spf-save").spf_save(),$(".spf-options").spf_options(),$(".spf-sticky-header").spf_sticky(),$(".spf-nav-options").spf_nav_options(),$(".spf-nav-metabox").spf_nav_metabox(),$(".spf-taxonomy").spf_taxonomy(),$(".spf-page-templates").spf_page_templates(),$(".spf-post-formats").spf_post_formats(),$(".spf-shortcode").spf_shortcode(),$(".spf-search").spf_search(),$(".spf-confirm").spf_confirm(),$(".spf-expand-all").spf_expand_all(),$(".spf-onload").spf_reload_script(),$(".widget").spf_widgets(),$("#menu-to-edit").spf_nav_menu(),$(".spf-field-button_clean.cache_remove .spf--sibling.spf--button").on("click",(function(e){e.preventDefault(),SPF.vars.is_confirm&&window.wp.ajax.post("sptp_clean_transient",{nonce:$("#spf_options_nonce_sptp_settings").val()}).done((function(response){alert("Cache cleaned")})).fail((function(response){alert("Cache failed to clean"),alert(response.error)}))}))}));var $export_type=$(".sptp_what_export").find("input:checked").val();$(".sptp_what_export").on("change",(function(){$export_type=$(this).find("input:checked").val()})),$(".sptp_export .spf--button").click((function(event){event.preventDefault();var $shortcode_ids=$(".sptp_post_ids select").val(),$ex_nonce=$("#spf_options_nonce_sptp_tools").val();if(console.log($ex_nonce),$shortcode_ids.length&&"selected_shortcodes"===$export_type)var data={action:"SPT_export_shortcodes",lcp_ids:$shortcode_ids,nonce:$ex_nonce};else if("all_shortcodes"===$export_type)var data={action:"SPT_export_shortcodes",lcp_ids:"all_shortcodes",nonce:$ex_nonce};else if("all_members"===$export_type)var data={action:"SPT_export_shortcodes",lcp_ids:"all_members",nonce:$ex_nonce};else $(".spf-form-result.spf-form-success").text("No group selected.").show(),setTimeout((function(){$(".spf-form-result.spf-form-success").hide().text("")}),3e3);$.post(ajaxurl,data,(function(resp){if(resp){if(isValidJSONString(resp))var json=JSON.stringify(JSON.parse(resp));else var json=JSON.stringify(resp);var blob=new Blob([json],{type:"application/json"}),link=document.createElement("a"),lcp_time=$.now();link.href=window.URL.createObjectURL(blob),link.download="wp-team-export-"+lcp_time+".json",link.click(),$(".spf-form-result.spf-form-success").text("Exported successfully!").show(),setTimeout((function(){$(".spf-form-result.spf-form-success").hide().text(""),$(".sptp_post_ids select").val("").trigger("chosen:updated")}),3e3)}}))})),$(".sptp_import button.import").click((function(event){event.preventDefault();var sptp_shortcodes=$("#import").prop("files")[0];if(""!=$("#import").val()){var $im_nonce=$("#spf_options_nonce_sptp_tools").val(),reader=new FileReader;reader.readAsText(sptp_shortcodes),reader.onload=function(event){var jsonObj=JSON.stringify(event.target.result);$.ajax({url:ajaxurl,type:"POST",data:{shortcode:jsonObj,action:"SPT_import_shortcodes",nonce:$im_nonce},success:function(resp){console.log(resp),$(".spf-form-result.spf-form-success").text("Imported successfully!").show(),setTimeout((function(){$(".spf-form-result.spf-form-success").hide().text(""),$("#import").val(""),"sptp_member"===resp.data?window.location.replace($("#sptp_member_link_redirect").attr("href")):window.location.replace($("#sptp_shortcode_link_redirect").attr("href"))}),2e3)}})}}else $(".spf-form-result.spf-form-success").text("No exported json file chosen.").show(),setTimeout((function(){$(".spf-form-result.spf-form-success").hide().text("")}),3e3)}));var preview_box=$("#sp__team-preview-box"),preview_display=$("#sptp_preview_display").hide();$(document).on("click","#sp__team-show-preview:contains(Hide)",(function(e){var _this;e.preventDefault(),$(this).html('<i class="fa fa-eye" aria-hidden="true"></i> Show Preview'),preview_box.html(""),preview_display.hide()})),$(document).on("click","#sp__team-show-preview:not(:contains(Hide))",(function(e){e.preventDefault();var previewJS=sptp_admin.previewJS,_data=$("form#post").serialize(),_this=$(this),data={action:"sptp_preview_meta_box",data:_data,ajax_nonce:$("#spf_metabox_noncesptp_preview_display").val()};$.ajax({type:"POST",url:ajaxurl,data:data,error:function(response){console.log(response)},success:function(response){preview_display.show(),preview_box.html(response),$.getScript(previewJS,(function(){_this.html('<i class="fa fa-eye-slash" aria-hidden="true"></i> Hide Preview'),$(document).on("keyup change",".post-type-sptp_generator",(function(e){e.preventDefault(),_this.html('<i class="fa fa-refresh" aria-hidden="true"></i> Update Preview')})),$("html, body").animate({scrollTop:preview_display.offset().top-50},"slow")}))}})})),$(document).on("keyup change",".sptp_member_page_team_settings #spf-form",(function(e){var $button;e.preventDefault(),$(this).find(".spf-save").css({"background-color":"#00C263","pointer-events":"initial"}).val("Save Settings")})),$(".sptp_member_page_team_settings .spf-save").click((function(e){e.preventDefault(),$(this).css({"background-color":"#C5C5C6","pointer-events":"none"}).val("Changes Saved")}))}(jQuery,window,document);
  • team-free/trunk/src/Admin/GutenbergBlock/WP_Team_Gutenberg_Block_Init.php

    r2692012 r2712509  
    168168                return __( '<i></i>', 'team-free' );
    169169            }
    170 
     170            $class_name = '';
     171            if ( ! empty( $attributes['className'] ) ) {
     172                $class_name = 'class="' . $attributes['className'] . '"';
     173            }
    171174            if ( ! $attributes['is_admin'] ) {
    172                 return do_shortcode( '[wpteam id="' . sanitize_text_field( $attributes['shortcode'] ) . '"]' );
     175                return '<div ' . $class_name . ' >' . do_shortcode( '[wpteam id="' . sanitize_text_field( $attributes['shortcode'] ) . '"]' ) . '</div>';
    173176            }
    174177
  • team-free/trunk/src/Admin/Team_Element_Shortcode_Block.php

    r2654156 r2712509  
    11<?php
    2 namespace ShapedPlugin\WPTeam\Admin;
    3 
    42/**
    53 * Elementor shortcode block.
     
    86 * @package   WP_Team_Free
    97 * @subpackage Team_Pro/src/Admin
     8 */
     9
     10namespace ShapedPlugin\WPTeam\Admin;
     11
     12/**
     13 * Team_Element_Shortcode_Block
    1014 */
    1115class Team_Element_Shortcode_Block {
     
    117121    public function init() {
    118122        // Add Plugin actions.
    119         add_action( 'elementor/widgets/widgets_registered', array( $this, 'init_widgets' ) );
     123        add_action( 'elementor/widgets/register', array( $this, 'init_widgets' ) );
    120124    }
    121125
     
    131135    public function init_widgets() {
    132136        // Register widget.
    133         \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new ElementBlock\Shortcode_Widget() );
     137        \Elementor\Plugin::instance()->widgets_manager->register( new ElementBlock\Shortcode_Widget() );
    134138
    135139    }
  • team-free/trunk/src/Admin/Team_Import_Export.php

    r2594102 r2712509  
    2828         *
    2929         * @param  mixed $shortcode_ids Export member and shortcode ids.
    30          * @return array
     30         * @return object
    3131         */
    3232        public function export( $shortcode_ids ) {
     
    176176         * @param  array $shortcodes Import wp-team-pro shortcode array.
    177177         * @throws \Exception Get errors message.
    178          * @return string
     178         * @return object
    179179         */
    180180        public function import( $shortcodes ) {
     
    202202                    }
    203203                    if ( is_wp_error( $new_shortcode_id ) ) {
    204                         throw new Exception( $new_shortcode_id->get_error_message() );
     204                        throw new \Exception( $new_shortcode_id->get_error_message() );
    205205                    }
    206206
     
    214214                        }
    215215                    }
    216                 } catch ( Exception $e ) {
     216                } catch ( \Exception $e ) {
    217217                    array_push( $errors[ $index ], $e->getMessage() );
    218218
     
    231231
    232232            $errors = reset( $errors );
    233             return isset( $errors[0] ) ? new WP_Error( 'import_shortcode_error', $errors[0] ) : $sptp_post_type;
     233            return isset( $errors[0] ) ? new \WP_Error( 'import_shortcode_error', $errors[0] ) : $sptp_post_type;
    234234        }
    235235
  • team-free/trunk/src/Admin/WP_Team_Gutenberg_Block.php

    r2641095 r2712509  
    11<?php
    2 
    3 namespace ShapedPlugin\WPTeam\Admin;
    4 
    5 if ( ! defined( 'ABSPATH' ) ) {
    6     exit; // Exit if accessed directly.
    7 }
    8 
    92/**
    103 * The plugin gutenberg block.
     
    1710 * @author     ShapedPlugin <support@shapedplugin.com>
    1811 */
     12
     13namespace ShapedPlugin\WPTeam\Admin;
     14
     15if ( ! defined( 'ABSPATH' ) ) {
     16    exit; // Exit if accessed directly.
     17}
     18
    1919if ( ! class_exists( 'WP_Team_Gutenberg_Block' ) ) {
    2020
  • team-free/trunk/team-free.php

    r2692012 r2712509  
    1414 * Plugin URI:        https://shapedplugin.com/plugin/wp-team-pro/?ref=1
    1515 * Description:       The most versatile and industry-leading WordPress team showcase plugin built to create and manage team members showcases with excellent design and multiple options.
    16  * Version:           2.2.4
     16 * Version:           2.2.5
    1717 * Author:            ShapedPlugin
    1818 * Author URI:        https://shapedplugin.com
     
    3737define( 'SPT_PLUGIN_FILE', __FILE__ );
    3838define( 'SPT_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
    39 define( 'SPT_PLUGIN_VERSION', '2.2.4' );
     39define( 'SPT_PLUGIN_VERSION', '2.2.5' );
    4040define( 'SPT_PLUGIN_ROOT', plugin_dir_url( __FILE__ ) );
    4141define( 'SPT_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.