PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.2.10
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.2.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
← All changes | admin/views/sp-framework/assets/js/spf.js +2806 -2300 2.4.21 → 2.2.10 View file →
@@ -6,2646 +6,3152 @@
6 6 *
7 7 * -----------------------------------------------------------
8 8 *
9 9 */
10 -; (function ($, window, document, undefined) {
11 - 'use strict'
10 +;(function ($, window, document, undefined) {
11 + 'use strict'
12 12
13 - //
14 - // Constants
15 - //
16 - var SP_PC = SP_PC || {}
13 + //
14 + // Constants
15 + //
16 + var SP_PC = SP_PC || {}
17 17
18 - SP_PC.funcs = {}
18 + SP_PC.funcs = {}
19 19
20 - SP_PC.vars = {
21 - onloaded: false,
22 - $body: $('body'),
23 - $window: $(window),
24 - $document: $(document),
25 - is_rtl: $('body').hasClass('rtl'),
26 - code_themes: []
27 - }
20 + SP_PC.vars = {
21 + onloaded: false,
22 + $body: $('body'),
23 + $window: $(window),
24 + $document: $(document),
25 + is_rtl: $('body').hasClass('rtl'),
26 + code_themes: []
27 + }
28 28
29 - //
30 - // Helper Functions
31 - //
32 - SP_PC.helper = {
33 - //
34 - // Generate UID
35 - //
36 - uid: function (prefix) {
37 - return (
38 - (prefix || '') +
39 - Math.random()
40 - .toString(36)
41 - .substr(2, 9)
42 - )
43 - },
29 + //
30 + // Helper Functions
31 + //
32 + SP_PC.helper = {
33 + //
34 + // Generate UID
35 + //
36 + uid: function (prefix) {
37 + return (
38 + (prefix || '') +
39 + Math.random()
40 + .toString(36)
41 + .substr(2, 9)
42 + )
43 + },
44 44
45 - // Quote regular expression characters
46 - //
47 - preg_quote: function (str) {
48 - return (str + '').replace(/(\[|\-|\])/g, '\\$1')
49 - },
45 + // Quote regular expression characters
46 + //
47 + preg_quote: function (str) {
48 + return (str + '').replace(/(\[|\-|\])/g, '\\$1')
49 + },
50 50
51 - //
52 - // Rename input names
53 - //
54 - name_nested_replace: function ($selector, field_id) {
55 - var checks = []
56 - var regex = new RegExp(
57 - '(' + SP_PC.helper.preg_quote(field_id) + ')\\[(\\d+)\\]',
58 - 'g'
59 - )
51 + //
52 + // Rename input names
53 + //
54 + name_nested_replace: function ($selector, field_id) {
55 + var checks = []
56 + var regex = new RegExp(
57 + '(' + SP_PC.helper.preg_quote(field_id) + ')\\[(\\d+)\\]',
58 + 'g'
59 + )
60 60
61 - $selector.find(':radio').each(function () {
62 - if (this.checked || this.orginal_checked) {
63 - this.orginal_checked = true
64 - }
65 - })
61 + $selector.find(':radio').each(function () {
62 + if (this.checked || this.orginal_checked) {
63 + this.orginal_checked = true
64 + }
65 + })
66 66
67 - $selector.each(function (index) {
68 - $(this)
69 - .find(':input')
70 - .each(function () {
71 - this.name = this.name.replace(regex, field_id + '[' + index + ']')
72 - if (this.orginal_checked) {
73 - this.checked = true
74 - }
75 - })
76 - })
77 - },
67 + $selector.each(function (index) {
68 + $(this)
69 + .find(':input')
70 + .each(function () {
71 + this.name = this.name.replace(regex, field_id + '[' + index + ']')
72 + if (this.orginal_checked) {
73 + this.checked = true
74 + }
75 + })
76 + })
77 + },
78 78
79 - //
80 - // Debounce
81 - //
82 - debounce: function (callback, threshold, immediate) {
83 - var timeout
84 - return function () {
85 - var context = this,
86 - args = arguments
87 - var later = function () {
88 - timeout = null
89 - if (!immediate) {
90 - callback.apply(context, args)
91 - }
92 - }
93 - var callNow = immediate && !timeout
94 - clearTimeout(timeout)
95 - timeout = setTimeout(later, threshold)
96 - if (callNow) {
97 - callback.apply(context, args)
98 - }
99 - }
100 - },
79 + //
80 + // Debounce
81 + //
82 + debounce: function (callback, threshold, immediate) {
83 + var timeout
84 + return function () {
85 + var context = this,
86 + args = arguments
87 + var later = function () {
88 + timeout = null
89 + if (!immediate) {
90 + callback.apply(context, args)
91 + }
92 + }
93 + var callNow = immediate && !timeout
94 + clearTimeout(timeout)
95 + timeout = setTimeout(later, threshold)
96 + if (callNow) {
97 + callback.apply(context, args)
98 + }
99 + }
100 + },
101 101
102 - //
103 - // Get a cookie
104 - //
105 - get_cookie: function (name) {
106 - var e,
107 - b,
108 - cookie = document.cookie,
109 - p = name + '='
102 + //
103 + // Get a cookie
104 + //
105 + get_cookie: function (name) {
106 + var e,
107 + b,
108 + cookie = document.cookie,
109 + p = name + '='
110 110
111 - if (!cookie) {
112 - return
113 - }
111 + if (!cookie) {
112 + return
113 + }
114 114
115 - b = cookie.indexOf('; ' + p)
115 + b = cookie.indexOf('; ' + p)
116 116
117 - if (b === -1) {
118 - b = cookie.indexOf(p)
117 + if (b === -1) {
118 + b = cookie.indexOf(p)
119 119
120 - if (b !== 0) {
121 - return null
122 - }
123 - } else {
124 - b += 2
125 - }
120 + if (b !== 0) {
121 + return null
122 + }
123 + } else {
124 + b += 2
125 + }
126 126
127 - e = cookie.indexOf(';', b)
127 + e = cookie.indexOf(';', b)
128 128
129 - if (e === -1) {
130 - e = cookie.length
131 - }
129 + if (e === -1) {
130 + e = cookie.length
131 + }
132 132
133 - return decodeURIComponent(cookie.substring(b + p.length, e))
134 - },
133 + return decodeURIComponent(cookie.substring(b + p.length, e))
134 + },
135 135
136 - //
137 - // Set a cookie
138 - //
139 - set_cookie: function (name, value, expires, path, domain, secure) {
140 - var d = new Date()
136 + //
137 + // Set a cookie
138 + //
139 + set_cookie: function (name, value, expires, path, domain, secure) {
140 + var d = new Date()
141 141
142 - if (typeof expires === 'object' && expires.toGMTString) {
143 - expires = expires.toGMTString()
144 - } else if (parseInt(expires, 10)) {
145 - d.setTime(d.getTime() + parseInt(expires, 10) * 1000)
146 - expires = d.toGMTString()
147 - } else {
148 - expires = ''
149 - }
142 + if (typeof expires === 'object' && expires.toGMTString) {
143 + expires = expires.toGMTString()
144 + } else if (parseInt(expires, 10)) {
145 + d.setTime(d.getTime() + parseInt(expires, 10) * 1000)
146 + expires = d.toGMTString()
147 + } else {
148 + expires = ''
149 + }
150 150
151 - document.cookie =
152 - name +
153 - '=' +
154 - encodeURIComponent(value) +
155 - (expires ? '; expires=' + expires : '') +
156 - (path ? '; path=' + path : '') +
157 - (domain ? '; domain=' + domain : '') +
158 - (secure ? '; secure' : '')
159 - },
151 + document.cookie =
152 + name +
153 + '=' +
154 + encodeURIComponent(value) +
155 + (expires ? '; expires=' + expires : '') +
156 + (path ? '; path=' + path : '') +
157 + (domain ? '; domain=' + domain : '') +
158 + (secure ? '; secure' : '')
159 + },
160 160
161 - //
162 - // Remove a cookie
163 - //
164 - remove_cookie: function (name, path, domain, secure) {
165 - SP_PC.helper.set_cookie(name, '', -1000, path, domain, secure)
166 - }
167 - }
161 + //
162 + // Remove a cookie
163 + //
164 + remove_cookie: function (name, path, domain, secure) {
165 + SP_PC.helper.set_cookie(name, '', -1000, path, domain, secure)
166 + }
167 + }
168 168
169 - //
170 - // Custom clone for textarea and select clone() bug
171 - //
172 - $.fn.spf_clone = function () {
173 - var base = $.fn.clone.apply(this, arguments),
174 - clone = this.find('select').add(this.filter('select')),
175 - cloned = base.find('select').add(base.filter('select'))
169 + //
170 + // Custom clone for textarea and select clone() bug
171 + //
172 + $.fn.spf_clone = function () {
173 + var base = $.fn.clone.apply(this, arguments),
174 + clone = this.find('select').add(this.filter('select')),
175 + cloned = base.find('select').add(base.filter('select'))
176 176
177 - for (var i = 0; i < clone.length; ++i) {
178 - for (var j = 0; j < clone[i].options.length; ++j) {
179 - if (clone[i].options[j].selected === true) {
180 - cloned[i].options[j].selected = true
181 - }
182 - }
183 - }
177 + for (var i = 0; i < clone.length; ++i) {
178 + for (var j = 0; j < clone[i].options.length; ++j) {
179 + if (clone[i].options[j].selected === true) {
180 + cloned[i].options[j].selected = true
181 + }
182 + }
183 + }
184 184
185 - this.find(':radio').each(function () {
186 - this.orginal_checked = this.checked
187 - })
185 + this.find(':radio').each(function () {
186 + this.orginal_checked = this.checked
187 + })
188 188
189 - return base
190 - }
189 + return base
190 + }
191 191
192 - //
193 - // Expand All Options
194 - //
195 - $.fn.spf_expand_all = function () {
196 - return this.each(function () {
197 - $(this).on('click', function (e) {
198 - e.preventDefault()
199 - $('.spf-wrapper').toggleClass('spf-show-all')
200 - $('.spf-section').spf_reload_script()
201 - $(this)
202 - .find('.fa')
203 - .toggleClass('fa-indent')
204 - .toggleClass('fa-outdent')
205 - })
206 - })
207 - }
192 + //
193 + // Expand All Options
194 + //
195 + $.fn.spf_expand_all = function () {
196 + return this.each(function () {
197 + $(this).on('click', function (e) {
198 + e.preventDefault()
199 + $('.spf-wrapper').toggleClass('spf-show-all')
200 + $('.spf-section').spf_reload_script()
201 + $(this)
202 + .find('.fa')
203 + .toggleClass('fa-indent')
204 + .toggleClass('fa-outdent')
205 + })
206 + })
207 + }
208 208
209 - //
210 - // Options Navigation
211 - //
212 - $.fn.spf_nav_options = function () {
213 - return this.each(function () {
214 - var $nav = $(this),
215 - $links = $nav.find('a'),
216 - $hidden = $nav.closest('.spf').find('.spf-section-id'),
217 - $last_section
209 + //
210 + // Options Navigation
211 + //
212 + $.fn.spf_nav_options = function () {
213 + return this.each(function () {
214 + var $nav = $(this),
215 + $links = $nav.find('a'),
216 + $hidden = $nav.closest('.spf').find('.spf-section-id'),
217 + $last_section
218 218
219 - $(window)
220 - .on('hashchange', function () {
221 - var hash = window.location.hash.match(new RegExp('tab=([^&]*)'))
222 - var slug = hash
223 - ? hash[1]
224 - : $links
225 - .first()
226 - .attr('href')
227 - .replace('#tab=', '')
228 - var $link = $('#spf-tab-link-' + slug)
219 + $(window)
220 + .on('hashchange', function () {
221 + var hash = window.location.hash.match(new RegExp('tab=([^&]*)'))
222 + var slug = hash
223 + ? hash[1]
224 + : $links
225 + .first()
226 + .attr('href')
227 + .replace('#tab=', '')
228 + var $link = $('#spf-tab-link-' + slug)
229 229
230 - if ($link.length > 0) {
231 - $link
232 - .closest('.spf-tab-depth-0')
233 - .addClass('spf-tab-active')
234 - .siblings()
235 - .removeClass('spf-tab-active')
236 - $links.removeClass('spf-section-active')
237 - $link.addClass('spf-section-active')
230 + if ($link.length > 0) {
231 + $link
232 + .closest('.spf-tab-depth-0')
233 + .addClass('spf-tab-active')
234 + .siblings()
235 + .removeClass('spf-tab-active')
236 + $links.removeClass('spf-section-active')
237 + $link.addClass('spf-section-active')
238 238
239 - if ($last_section !== undefined) {
240 - $last_section.hide()
241 - }
239 + if ($last_section !== undefined) {
240 + $last_section.hide()
241 + }
242 242
243 - var $section = $('#spf-section-' + slug)
244 - $section.css({ display: 'block' })
245 - $section.spf_reload_script()
243 + var $section = $('#spf-section-' + slug)
244 + $section.css({ display: 'block' })
245 + $section.spf_reload_script()
246 246
247 - $hidden.val(slug)
247 + $hidden.val(slug)
248 248
249 - $last_section = $section
250 - }
251 - })
252 - .trigger('hashchange')
253 - })
254 - }
249 + $last_section = $section
250 + }
251 + })
252 + .trigger('hashchange')
253 + })
254 + }
255 255
256 - //
257 - // Metabox Tabs
258 - //
259 - $.fn.spf_nav_metabox = function () {
260 - return this.each(function () {
261 - var $nav = $(this),
262 - $links = $nav.find('a'),
263 - unique_id = $nav.data('unique'),
264 - post_id = $('#post_ID').val() || 'global',
265 - $last_section,
266 - $last_link
256 + //
257 + // Metabox Tabs
258 + //
259 + $.fn.spf_nav_metabox = function () {
260 + return this.each(function () {
261 + var $nav = $(this),
262 + $links = $nav.find('a'),
263 + unique_id = $nav.data('unique'),
264 + post_id = $('#post_ID').val() || 'global',
265 + $last_section,
266 + $last_link
267 267
268 - $links.on('click', function (e) {
269 - e.preventDefault()
268 + $links.on('click', function (e) {
269 + e.preventDefault()
270 270
271 - var $link = $(this),
272 - section_id = $link.data('section')
271 + var $link = $(this),
272 + section_id = $link.data('section')
273 273
274 - if ($last_link !== undefined) {
275 - $last_link.removeClass('spf-section-active')
276 - }
274 + if ($last_link !== undefined) {
275 + $last_link.removeClass('spf-section-active')
276 + }
277 277
278 - if ($last_section !== undefined) {
279 - $last_section.hide()
280 - }
278 + if ($last_section !== undefined) {
279 + $last_section.hide()
280 + }
281 281
282 - $link.addClass('spf-section-active')
282 + $link.addClass('spf-section-active')
283 283
284 - var $section = $('#spf-section-' + section_id)
285 - $section.css({ display: 'block' })
286 - $section.spf_reload_script()
284 + var $section = $('#spf-section-' + section_id)
285 + $section.css({ display: 'block' })
286 + $section.spf_reload_script()
287 287
288 - SP_PC.helper.set_cookie(
289 - 'spf-last-metabox-tab-' + post_id + '-' + unique_id,
290 - section_id
291 - )
288 + SP_PC.helper.set_cookie(
289 + 'spf-last-metabox-tab-' + post_id + '-' + unique_id,
290 + section_id
291 + )
292 292
293 - $last_section = $section
294 - $last_link = $link
295 - })
293 + $last_section = $section
294 + $last_link = $link
295 + })
296 296
297 - var get_cookie = SP_PC.helper.get_cookie(
298 - 'spf-last-metabox-tab-' + post_id + '-' + unique_id
299 - )
297 + var get_cookie = SP_PC.helper.get_cookie(
298 + 'spf-last-metabox-tab-' + post_id + '-' + unique_id
299 + )
300 300
301 - if (get_cookie) {
302 - $nav.find('a[data-section="' + get_cookie + '"]').trigger('click')
303 - } else {
304 - $links.first('a').trigger('click')
305 - }
306 - })
307 - }
301 + if (get_cookie) {
302 + $nav.find('a[data-section="' + get_cookie + '"]').trigger('click')
303 + } else {
304 + $links.first('a').trigger('click')
305 + }
306 + })
307 + }
308 308
309 - //
310 - // Metabox Page Templates Listener
311 - //
312 - $.fn.spf_page_templates = function () {
313 - if (this.length) {
314 - $(document).on(
315 - 'change',
316 - '.editor-page-attributes__template select, #page_template',
317 - function () {
318 - var maybe_value = $(this).val() || 'default'
309 + //
310 + // Metabox Page Templates Listener
311 + //
312 + $.fn.spf_page_templates = function () {
313 + if (this.length) {
314 + $(document).on(
315 + 'change',
316 + '.editor-page-attributes__template select, #page_template',
317 + function () {
318 + var maybe_value = $(this).val() || 'default'
319 319
320 - $('.spf-page-templates')
321 - .removeClass('spf-show')
322 - .addClass('spf-hide')
323 - $(
324 - '.spf-page-' +
325 - maybe_value.toLowerCase().replace(/[^a-zA-Z0-9]+/g, '-')
326 - )
327 - .removeClass('spf-hide')
328 - .addClass('spf-show')
329 - }
330 - )
331 - }
332 - }
320 + $('.spf-page-templates')
321 + .removeClass('spf-show')
322 + .addClass('spf-hide')
323 + $(
324 + '.spf-page-' +
325 + maybe_value.toLowerCase().replace(/[^a-zA-Z0-9]+/g, '-')
326 + )
327 + .removeClass('spf-hide')
328 + .addClass('spf-show')
329 + }
330 + )
331 + }
332 + }
333 333
334 - //
335 - // Metabox Post Formats Listener
336 - //
337 - $.fn.spf_post_formats = function () {
338 - if (this.length) {
339 - $(document).on(
340 - 'change',
341 - '.editor-post-format select, #formatdiv input[name="post_format"]',
342 - function () {
343 - var maybe_value = $(this).val() || 'default'
334 + //
335 + // Metabox Post Formats Listener
336 + //
337 + $.fn.spf_post_formats = function () {
338 + if (this.length) {
339 + $(document).on(
340 + 'change',
341 + '.editor-post-format select, #formatdiv input[name="post_format"]',
342 + function () {
343 + var maybe_value = $(this).val() || 'default'
344 344
345 - // Fallback for classic editor version
346 - maybe_value = maybe_value === '0' ? 'default' : maybe_value
345 + // Fallback for classic editor version
346 + maybe_value = maybe_value === '0' ? 'default' : maybe_value
347 347
348 - $('.spf-post-formats')
349 - .removeClass('spf-show')
350 - .addClass('spf-hide')
351 - $('.spf-post-format-' + maybe_value)
352 - .removeClass('spf-hide')
353 - .addClass('spf-show')
354 - }
355 - )
356 - }
357 - }
348 + $('.spf-post-formats')
349 + .removeClass('spf-show')
350 + .addClass('spf-hide')
351 + $('.spf-post-format-' + maybe_value)
352 + .removeClass('spf-hide')
353 + .addClass('spf-show')
354 + }
355 + )
356 + }
357 + }
358 358
359 - //
360 - // Search
361 - //
362 - $.fn.spf_search = function () {
363 - return this.each(function () {
364 - var $this = $(this),
365 - $input = $this.find('input')
359 + //
360 + // Search
361 + //
362 + $.fn.spf_search = function () {
363 + return this.each(function () {
364 + var $this = $(this),
365 + $input = $this.find('input')
366 366
367 - $input.on('change keyup', function () {
368 - var value = $(this).val(),
369 - $wrapper = $('.spf-wrapper'),
370 - $section = $wrapper.find('.spf-section'),
371 - $fields = $section.find('> .spf-field:not(.hidden)'),
372 - $titles = $fields.find('> .spf-title, .spf-search-tags')
367 + $input.on('change keyup', function () {
368 + var value = $(this).val(),
369 + $wrapper = $('.spf-wrapper'),
370 + $section = $wrapper.find('.spf-section'),
371 + $fields = $section.find('> .spf-field:not(.hidden)'),
372 + $titles = $fields.find('> .spf-title, .spf-search-tags')
373 373
374 - if (value.length > 3) {
375 - $fields.addClass('spf-hidden')
376 - $wrapper.addClass('spf-search-all')
374 + if (value.length > 3) {
375 + $fields.addClass('spf-hidden')
376 + $wrapper.addClass('spf-search-all')
377 377
378 - $titles.each(function () {
379 - var $title = $(this)
378 + $titles.each(function () {
379 + var $title = $(this)
380 380
381 - if ($title.text().match(new RegExp('.*?' + value + '.*?', 'i'))) {
382 - var $field = $title.closest('.spf-field')
381 + if ($title.text().match(new RegExp('.*?' + value + '.*?', 'i'))) {
382 + var $field = $title.closest('.spf-field')
383 383
384 - $field.removeClass('spf-hidden')
385 - $field.parent().spf_reload_script()
386 - }
387 - })
388 - } else {
389 - $fields.removeClass('spf-hidden')
390 - $wrapper.removeClass('spf-search-all')
391 - }
392 - })
393 - })
394 - }
384 + $field.removeClass('spf-hidden')
385 + $field.parent().spf_reload_script()
386 + }
387 + })
388 + } else {
389 + $fields.removeClass('spf-hidden')
390 + $wrapper.removeClass('spf-search-all')
391 + }
392 + })
393 + })
394 + }
395 395
396 - //
397 - // Sticky Header
398 - //
399 - $.fn.spf_sticky = function () {
400 - return this.each(function () {
401 - var $this = $(this),
402 - $window = $(window),
403 - $inner = $this.find('.spf-header-inner'),
404 - padding =
405 - parseInt($inner.css('padding-left')) +
406 - parseInt($inner.css('padding-right')),
407 - offset = 32,
408 - scrollTop = 0,
409 - lastTop = 0,
410 - ticking = false,
411 - stickyUpdate = function () {
412 - var offsetTop = $this.offset().top,
413 - stickyTop = Math.max(offset, offsetTop - scrollTop),
414 - winWidth = Math.max(
415 - document.documentElement.clientWidth,
416 - window.innerWidth || 0
417 - )
396 + //
397 + // Sticky Header
398 + //
399 + $.fn.spf_sticky = function () {
400 + return this.each(function () {
401 + var $this = $(this),
402 + $window = $(window),
403 + $inner = $this.find('.spf-header-inner'),
404 + padding =
405 + parseInt($inner.css('padding-left')) +
406 + parseInt($inner.css('padding-right')),
407 + offset = 32,
408 + scrollTop = 0,
409 + lastTop = 0,
410 + ticking = false,
411 + stickyUpdate = function () {
412 + var offsetTop = $this.offset().top,
413 + stickyTop = Math.max(offset, offsetTop - scrollTop),
414 + winWidth = Math.max(
415 + document.documentElement.clientWidth,
416 + window.innerWidth || 0
417 + )
418 418
419 - if (stickyTop <= offset && winWidth > 782) {
420 - $inner.css({ width: $this.outerWidth() - padding })
421 - $this.css({ height: $this.outerHeight() }).addClass('spf-sticky')
422 - } else {
423 - $inner.removeAttr('style')
424 - $this.removeAttr('style').removeClass('spf-sticky')
425 - }
426 - },
427 - requestTick = function () {
428 - if (!ticking) {
429 - requestAnimationFrame(function () {
430 - stickyUpdate()
431 - ticking = false
432 - })
433 - }
419 + if (stickyTop <= offset && winWidth > 782) {
420 + $inner.css({ width: $this.outerWidth() - padding })
421 + $this.css({ height: $this.outerHeight() }).addClass('spf-sticky')
422 + } else {
423 + $inner.removeAttr('style')
424 + $this.removeAttr('style').removeClass('spf-sticky')
425 + }
426 + },
427 + requestTick = function () {
428 + if (!ticking) {
429 + requestAnimationFrame(function () {
430 + stickyUpdate()
431 + ticking = false
432 + })
433 + }
434 434
435 - ticking = true
436 - },
437 - onSticky = function () {
438 - scrollTop = $window.scrollTop()
439 - requestTick()
440 - }
435 + ticking = true
436 + },
437 + onSticky = function () {
438 + scrollTop = $window.scrollTop()
439 + requestTick()
440 + }
441 441
442 - $window.on('scroll resize', onSticky)
442 + $window.on('scroll resize', onSticky)
443 443
444 - onSticky()
445 - })
446 - }
444 + onSticky()
445 + })
446 + }
447 447
448 - //
449 - // Dependency System
450 - //
451 - $.fn.spf_dependency = function () {
452 - return this.each(function () {
453 - var $this = $(this),
454 - ruleset = $.spf_deps.createRuleset(),
455 - depends = [],
456 - is_global = false
448 + //
449 + // Dependency System
450 + //
451 + $.fn.spf_dependency = function () {
452 + return this.each(function () {
453 + var $this = $(this),
454 + ruleset = $.spf_deps.createRuleset(),
455 + depends = [],
456 + is_global = false
457 457
458 - $this.children('[data-controller]').each(function () {
459 - var $field = $(this),
460 - controllers = $field.data('controller').split('|'),
461 - conditions = $field.data('condition').split('|'),
462 - values = $field
463 - .data('value')
464 - .toString()
465 - .split('|'),
466 - rules = ruleset
458 + $this.children('[data-controller]').each(function () {
459 + var $field = $(this),
460 + controllers = $field.data('controller').split('|'),
461 + conditions = $field.data('condition').split('|'),
462 + values = $field
463 + .data('value')
464 + .toString()
465 + .split('|'),
466 + rules = ruleset
467 467
468 - if ($field.data('depend-global')) {
469 - is_global = true
470 - }
468 + if ($field.data('depend-global')) {
469 + is_global = true
470 + }
471 471
472 - $.each(controllers, function (index, depend_id) {
473 - var value = values[index] || '',
474 - condition = conditions[index] || conditions[0]
472 + $.each(controllers, function (index, depend_id) {
473 + var value = values[index] || '',
474 + condition = conditions[index] || conditions[0]
475 475
476 - rules = rules.createRule(
477 - '[data-depend-id="' + depend_id + '"]',
478 - condition,
479 - value
480 - )
476 + rules = rules.createRule(
477 + '[data-depend-id="' + depend_id + '"]',
478 + condition,
479 + value
480 + )
481 481
482 - rules.include($field)
482 + rules.include($field)
483 483
484 - depends.push(depend_id)
485 - })
486 - })
484 + depends.push(depend_id)
485 + })
486 + })
487 487
488 - if (depends.length) {
489 - if (is_global) {
490 - $.spf_deps.enable(SP_PC.vars.$body, ruleset, depends)
491 - } else {
492 - $.spf_deps.enable($this, ruleset, depends)
493 - }
494 - }
495 - })
496 - }
488 + if (depends.length) {
489 + if (is_global) {
490 + $.spf_deps.enable(SP_PC.vars.$body, ruleset, depends)
491 + } else {
492 + $.spf_deps.enable($this, ruleset, depends)
493 + }
494 + }
495 + })
496 + }
497 497
498 - //
499 - // Field: accordion
500 - //
501 - $.fn.spf_field_accordion = function () {
502 - return this.each(function () {
503 - // Keep the accordion open by default.
498 + //
499 + // Field: accordion
500 + //
501 + $.fn.spf_field_accordion = function () {
502 + return this.each(function () {
503 + // Keep the accordion open by default.
504 504
505 - var $titles = $(this).find('.spf-accordion-title')
505 + var $titles = $(this).find('.spf-accordion-title')
506 506
507 - //$titles.on('load', function() {
508 - //var $title_area = $(this),
509 - // var $content_area = $titles.next();
507 + //$titles.on('load', function() {
508 + //var $title_area = $(this),
509 + // var $content_area = $titles.next();
510 510
511 - //$content_area.addClass('spf-accordion-open');
512 - // if (!$content_area.data('opened')) {
513 - // $content_area.spf_reload_script();
514 - // $content_area.data('opened', true);
515 - // }
516 - // $content_area.addClass('spf-accordion-open');
517 - //});
511 + //$content_area.addClass('spf-accordion-open');
512 + // if (!$content_area.data('opened')) {
513 + // $content_area.spf_reload_script();
514 + // $content_area.data('opened', true);
515 + // }
516 + // $content_area.addClass('spf-accordion-open');
517 + //});
518 518
519 - $titles.on('click', function () {
520 - var $title = $(this),
521 - $icon = $title.find('.spf-accordion-icon'),
522 - $content = $title.next()
519 + $titles.on('click', function () {
520 + var $title = $(this),
521 + $icon = $title.find('.spf-accordion-icon'),
522 + $content = $title.next()
523 523
524 - if ($icon.hasClass('fa-angle-right')) {
525 - $icon.removeClass('fa-angle-right').addClass('fa-angle-down')
526 - } else {
527 - $icon.removeClass('fa-angle-down').addClass('fa-angle-right')
528 - }
524 + if ($icon.hasClass('fa-angle-right')) {
525 + $icon.removeClass('fa-angle-right').addClass('fa-angle-down')
526 + } else {
527 + $icon.removeClass('fa-angle-down').addClass('fa-angle-right')
528 + }
529 529
530 - if (!$content.data('opened')) {
531 - $content.spf_reload_script()
532 - $content.data('opened', true)
533 - }
530 + if (!$content.data('opened')) {
531 + $content.spf_reload_script()
532 + $content.data('opened', true)
533 + }
534 534
535 - $content.toggleClass('spf-accordion-open')
536 - })
537 - /* var $sortable = $(this).find('.spf-accordion-items');
538 - $sortable.sortable({
539 - axis: 'y',
540 - helper: 'original',
541 - cursor: 'move',
542 - placeholder: 'widget-placeholder',
543 - update: function( event, ui ) {
544 - $sortable.spf_customizer_refresh();
545 - }
546 - });
547 - $sortable.find('.spf-accordion-content').spf_reload_script();*/
548 - })
549 - }
535 + $content.toggleClass('spf-accordion-open')
536 + })
537 + /* var $sortable = $(this).find('.spf-accordion-items');
538 + $sortable.sortable({
539 + axis: 'y',
540 + helper: 'original',
541 + cursor: 'move',
542 + placeholder: 'widget-placeholder',
543 + update: function( event, ui ) {
544 + $sortable.spf_customizer_refresh();
545 + }
546 + });
547 + $sortable.find('.spf-accordion-content').spf_reload_script();*/
548 + })
549 + }
550 550
551 - //
552 - // Field: sortable
553 - //
554 - $.fn.spf_field_sortable = function () {
555 - return this.each(function () {
556 - var $sortable = $(this).find('.spf--sortable')
557 - // Post content sort only with handle
558 - if ($(this).hasClass('post_content_sorter')) {
559 - $sortable.sortable({
560 - axis: 'y',
561 - helper: 'original',
562 - handle: '.spf--sortable-helper',
563 - cursor: 'move',
564 - placeholder: 'widget-placeholder'
565 - // update: function( event, ui ) {
566 - // $sortable.spf_customizer_refresh();
567 - // }
568 - })
569 - } else {
570 - $sortable.sortable({
571 - axis: 'y',
572 - helper: 'original',
573 - cursor: 'move',
574 - placeholder: 'widget-placeholder'
575 - // update: function( event, ui ) {
576 - // $sortable.spf_customizer_refresh();
577 - // }
578 - })
579 - }
551 + //
552 + // Field: sortable
553 + //
554 + $.fn.spf_field_sortable = function () {
555 + return this.each(function () {
556 + var $sortable = $(this).find('.spf--sortable')
557 + // Post content sort only with handle
558 + if ($(this).hasClass('post_content_sorter')) {
559 + $sortable.sortable({
560 + axis: 'y',
561 + helper: 'original',
562 + handle: '.spf--sortable-helper',
563 + cursor: 'move',
564 + placeholder: 'widget-placeholder'
565 + // update: function( event, ui ) {
566 + // $sortable.spf_customizer_refresh();
567 + // }
568 + })
569 + } else {
570 + $sortable.sortable({
571 + axis: 'y',
572 + helper: 'original',
573 + cursor: 'move',
574 + placeholder: 'widget-placeholder'
575 + // update: function( event, ui ) {
576 + // $sortable.spf_customizer_refresh();
577 + // }
578 + })
579 + }
580 580
581 - $sortable.find('.spf--sortable-content').spf_reload_script()
582 - })
583 - }
581 + $sortable.find('.spf--sortable-content').spf_reload_script()
582 + })
583 + }
584 + //
585 + // Field: backup
586 + //
587 + $.fn.spf_field_backup = function () {
588 + return this.each(function () {
589 + if (window.wp.customize === undefined) {
590 + return
591 + }
584 592
585 - //
586 - // Field: code_editor
587 - //
588 - $.fn.spf_field_code_editor = function () {
589 - return this.each(function () {
590 - if (typeof CodeMirror !== 'function') {
591 - return
592 - }
593 + var base = this,
594 + $this = $(this),
595 + $body = $('body'),
596 + $import = $this.find('.spf-import'),
597 + $reset = $this.find('.spf-reset')
593 598
594 - var $this = $(this),
595 - $textarea = $this.find('textarea'),
596 - $inited = $this.find('.CodeMirror'),
597 - data_editor = $textarea.data('editor')
599 + base.notification = function (message_text) {
600 + if (wp.customize.notifications && wp.customize.OverlayNotification) {
601 + // clear if there is any saved data.
602 + if (!wp.customize.state('saved').get()) {
603 + wp.customize.state('changesetStatus').set('trash')
604 + wp.customize.each(function (setting) {
605 + setting._dirty = false
606 + })
607 + wp.customize.state('saved').set(true)
608 + }
598 609
599 - if ($inited.length) {
600 - $inited.remove()
601 - }
610 + // then show a notification overlay
611 + wp.customize.notifications.add(
612 + new wp.customize.OverlayNotification(
613 + 'spf_field_backup_notification',
614 + {
615 + type: 'info',
616 + message: message_text,
617 + loading: true
618 + }
619 + )
620 + )
621 + }
622 + }
602 623
603 - var interval = setInterval(function () {
604 - if ($this.is(':visible')) {
605 - var code_editor = CodeMirror.fromTextArea($textarea[0], data_editor)
624 + $reset.on('click', function (e) {
625 + e.preventDefault()
606 626
607 - // load code-mirror theme css.
608 - if (
609 - data_editor.theme !== 'default' &&
610 - SP_PC.vars.code_themes.indexOf(data_editor.theme) === -1
611 - ) {
612 - var $cssLink = $('<link>')
627 + if (SP_PC.vars.is_confirm) {
628 + base.notification(window.spf_vars.i18n.reset_notification)
613 629
614 - $('#spf-codemirror-css').after($cssLink)
630 + window.wp.ajax
631 + .post('spf-reset', {
632 + unique: $reset.data('unique'),
633 + nonce: $reset.data('nonce')
634 + })
635 + .done(function (response) {
636 + window.location.reload(true)
637 + })
638 + .fail(function (response) {
639 + alert(response.error)
640 + wp.customize.notifications.remove('spf_field_backup_notification')
641 + })
642 + }
643 + })
615 644
616 - $cssLink.attr({
617 - rel: 'stylesheet',
618 - id: 'spf-codemirror-' + data_editor.theme + '-css',
619 - href:
620 - data_editor.cdnURL + '/theme/' + data_editor.theme + '.min.css',
621 - type: 'text/css',
622 - media: 'all'
623 - })
645 + $import.on('click', function (e) {
646 + e.preventDefault()
624 647
625 - SP_PC.vars.code_themes.push(data_editor.theme)
626 - }
648 + if (SP_PC.vars.is_confirm) {
649 + base.notification(window.spf_vars.i18n.import_notification)
627 650
628 - CodeMirror.modeURL = data_editor.cdnURL + '/mode/%N/%N.min.js'
629 - CodeMirror.autoLoadMode(code_editor, data_editor.mode)
651 + window.wp.ajax
652 + .post('spf-import', {
653 + unique: $import.data('unique'),
654 + nonce: $import.data('nonce'),
655 + import_data: $this.find('.spf-import-data').val()
656 + })
657 + .done(function (response) {
658 + window.location.reload(true)
659 + })
660 + .fail(function (response) {
661 + alert(response.error)
662 + wp.customize.notifications.remove('spf_field_backup_notification')
663 + })
664 + }
665 + })
666 + })
667 + }
630 668
631 - code_editor.on('change', function (editor, event) {
632 - $textarea.val(code_editor.getValue()).trigger('change')
633 - })
669 + //
670 + // Field: background
671 + //
672 + $.fn.spf_field_background = function () {
673 + return this.each(function () {
674 + $(this)
675 + .find('.spf--media')
676 + .spf_reload_script()
634 677
635 - clearInterval(interval)
636 - }
637 - })
638 - })
639 - }
678 + //
679 + //
680 + // Preview
681 + var $this = $(this)
682 + var $preview_block = $this.find('.spf--block-preview')
640 683
641 - //
642 - // Field: fieldset
643 - //
644 - $.fn.spf_field_fieldset = function () {
645 - return this.each(function () {
646 - $(this)
647 - .find('.spf-fieldset-content')
648 - .spf_reload_script()
649 - })
650 - }
684 + if ($preview_block.length) {
685 + var $preview = $this.find('.spf--preview')
651 686
652 - //
653 - // Field: group
654 - //
655 - $.fn.spf_field_group = function () {
656 - return this.each(function () {
657 - var $this = $(this),
658 - $fieldset = $this.children('.spf-fieldset'),
659 - $group = $fieldset.length ? $fieldset : $this,
660 - $wrapper = $group.children('.spf-cloneable-wrapper'),
661 - $hidden = $group.children('.spf-cloneable-hidden'),
662 - $max = $group.children('.spf-cloneable-max'),
663 - $min = $group.children('.spf-cloneable-min'),
664 - field_id = $wrapper.data('field-id'),
665 - unique_id = $wrapper.data('unique-id'),
666 - is_number = Boolean(Number($wrapper.data('title-number'))),
667 - max = parseInt($wrapper.data('max')),
668 - min = parseInt($wrapper.data('min'))
687 + // Set preview styles on change
688 + $this.on(
689 + 'change',
690 + SP_PC.helper.debounce(function (event) {
691 + $preview_block.removeClass('hidden')
669 692
670 - // clear accordion arrows if multi-instance
671 - if ($wrapper.hasClass('ui-accordion')) {
672 - $wrapper.find('.ui-accordion-header-icon').remove()
673 - }
693 + var $this = $(this),
694 + background_color = $this
695 + .find('.spf-fieldset .spf--block:nth-child(1n) label input')
696 + .val(),
697 + background_grd_color = $this
698 + .find('.spf-fieldset .spf--block:nth-child(2n) label input')
699 + .val(),
700 + background_grd_direction = $this
701 + .find('.spf-fieldset .spf--gradient select')
702 + .val(),
703 + background_image = $this.find('.spf--media input').val(),
704 + background_position = $this
705 + .find('.spf-fieldset .spf--block:nth-child(7n) select')
706 + .val(),
707 + background_repeat = $this
708 + .find('.spf-fieldset .spf--block:nth-child(8n) select')
709 + .val(),
710 + background_attachment = $this
711 + .find('.spf-fieldset .spf--block:nth-child(9n) select')
712 + .val(),
713 + background_size = $this
714 + .find('.spf-fieldset .spf--block:nth-child(10n) select')
715 + .val()
674 716
675 - var update_title_numbers = function ($selector) {
676 - $selector.find('.spf-cloneable-title-number').each(function (index) {
677 - $(this).html(
678 - $(this)
679 - .closest('.spf-cloneable-item')
680 - .index() +
681 - 1 +
682 - '.'
683 - )
684 - })
685 - }
717 + var properties = {}
686 718
687 - // Hide the taxonomy relation field. -- Shamim
688 - var $pcp_group_parent = $this.parent()
689 - var pcp_hide_the_taxonomy_relation = function (count_tax) {
690 - if (count_tax < 2) {
691 - $($pcp_group_parent)
692 - .find('.pcp_relate_among_taxonomies')
693 - .hide()
694 - } else {
695 - $($pcp_group_parent)
696 - .find('.pcp_relate_among_taxonomies')
697 - .show()
698 - }
699 - }
719 + if (background_color) {
720 + properties.backgroundColor = background_color
721 + }
722 + if (background_grd_direction) {
723 + properties.backgroundImage =
724 + 'linear-gradient(' +
725 + background_grd_direction +
726 + ', ' +
727 + background_color +
728 + ', ' +
729 + background_grd_color +
730 + ')'
731 + }
732 + if (background_image) {
733 + if (background_image) {
734 + properties.backgroundImage = 'url(' + background_image + ')'
735 + }
736 + if (background_repeat) {
737 + properties.backgroundRepeat = background_repeat
738 + }
739 + if (background_position) {
740 + properties.backgroundPosition = background_position
741 + }
742 + if (background_attachment) {
743 + properties.backgroundAttachment = background_attachment
744 + }
745 + if (background_size) {
746 + properties.backgroundSize = background_size
747 + }
748 + }
749 + $preview.removeAttr('style')
750 + $preview.css(properties)
751 + }, 100)
752 + )
700 753
701 - var count = $wrapper.children('.spf-cloneable-item').length
702 - pcp_hide_the_taxonomy_relation(count)
754 + if (!$preview_block.hasClass('hidden')) {
755 + $this.trigger('change')
756 + }
757 + }
758 + })
759 + }
703 760
704 - $wrapper.accordion({
705 - header: '> .spf-cloneable-item > .spf-cloneable-title',
706 - collapsible: true,
707 - active: false,
708 - animate: false,
709 - heightStyle: 'content',
710 - icons: {
711 - header: 'spf-cloneable-header-icon fa fa-angle-right',
712 - activeHeader: 'spf-cloneable-header-icon fa fa-angle-down'
713 - },
714 - activate: function (event, ui) {
715 - var $panel = ui.newPanel
716 - var $header = ui.newHeader
761 + //
762 + // Field: code_editor
763 + //
764 + $.fn.spf_field_code_editor = function () {
765 + return this.each(function () {
766 + if (typeof CodeMirror !== 'function') {
767 + return
768 + }
717 769
718 - if ($panel.length && !$panel.data('opened')) {
719 - var $fields = $panel.children()
720 - var $first = $fields
721 - .first()
722 - .find('select')
723 - .first()
724 - var $title = $header.find('.spf-cloneable-value')
770 + var $this = $(this),
771 + $textarea = $this.find('textarea'),
772 + $inited = $this.find('.CodeMirror'),
773 + data_editor = $textarea.data('editor')
725 774
726 - $first.on('change', function (event) {
727 - //$title.text( $first.children("option").filter(":selected").text() );
728 - $title.text($first.val())
729 - })
775 + if ($inited.length) {
776 + $inited.remove()
777 + }
730 778
731 - $panel.spf_reload_script()
732 - $panel.data('opened', true)
733 - $panel.data('retry', false)
734 - } else if ($panel.data('retry')) {
735 - $panel.spf_reload_script_retry()
736 - $panel.data('retry', false)
737 - }
738 - }
739 - })
779 + var interval = setInterval(function () {
780 + if ($this.is(':visible')) {
781 + var code_editor = CodeMirror.fromTextArea($textarea[0], data_editor)
740 782
741 - $wrapper.sortable({
742 - axis: 'y',
743 - handle: '.spf-cloneable-title,.spf-cloneable-sort',
744 - helper: 'original',
745 - cursor: 'move',
746 - placeholder: 'widget-placeholder',
747 - start: function (event, ui) {
748 - $wrapper.accordion({ active: false })
749 - $wrapper.sortable('refreshPositions')
750 - ui.item.children('.spf-cloneable-content').data('retry', true)
751 - },
752 - update: function (event, ui) {
753 - SP_PC.helper.name_nested_replace(
754 - $wrapper.children('.spf-cloneable-item'),
755 - field_id
756 - )
783 + // load code-mirror theme css.
784 + if (
785 + data_editor.theme !== 'default' &&
786 + SP_PC.vars.code_themes.indexOf(data_editor.theme) === -1
787 + ) {
788 + var $cssLink = $('<link>')
757 789
758 - //$wrapper.spf_customizer_refresh();
790 + $('#spf-codemirror-css').after($cssLink)
759 791
760 - if (is_number) {
761 - update_title_numbers($wrapper)
762 - }
763 - }
764 - })
792 + $cssLink.attr({
793 + rel: 'stylesheet',
794 + id: 'spf-codemirror-' + data_editor.theme + '-css',
795 + href:
796 + data_editor.cdnURL + '/theme/' + data_editor.theme + '.min.css',
797 + type: 'text/css',
798 + media: 'all'
799 + })
765 800
766 - $group.children('.spf-cloneable-add').on('click', function (e) {
767 - e.preventDefault()
801 + SP_PC.vars.code_themes.push(data_editor.theme)
802 + }
768 803
769 - var count = $wrapper.children('.spf-cloneable-item').length
804 + CodeMirror.modeURL = data_editor.cdnURL + '/mode/%N/%N.min.js'
805 + CodeMirror.autoLoadMode(code_editor, data_editor.mode)
770 806
771 - $min.hide()
807 + code_editor.on('change', function (editor, event) {
808 + $textarea.val(code_editor.getValue()).trigger('change')
809 + })
772 810
773 - if (max && count + 1 > max) {
774 - $max.show()
775 - return
776 - }
811 + clearInterval(interval)
812 + }
813 + })
814 + })
815 + }
777 816
778 - var new_field_id = unique_id + field_id + '[' + count + ']'
817 + //
818 + // Field: date
819 + //
820 + $.fn.spf_field_date = function () {
821 + return this.each(function () {
822 + var $this = $(this),
823 + $inputs = $this.find('input'),
824 + settings = $this.find('.spf-date-settings').data('settings'),
825 + wrapper = '<div class="spf-datepicker-wrapper"></div>',
826 + $datepicker
779 827
780 - var $cloned_item = $hidden.spf_clone(true)
828 + var defaults = {
829 + showAnim: '',
830 + beforeShow: function (input, inst) {
831 + $(inst.dpDiv).addClass('spf-datepicker-wrapper')
832 + },
833 + onClose: function (input, inst) {
834 + $(inst.dpDiv).removeClass('spf-datepicker-wrapper')
835 + }
836 + }
781 837
782 - $cloned_item.removeClass('spf-cloneable-hidden')
783 - // $cloned_item.find(':input').each( function() {
784 - // this.name = new_field_id + this.name.replace( ( this.name.startsWith('_nonce') ? '_nonce' : unique_id ), '');
785 - // });
786 - $cloned_item.find(':input[name!="_pseudo"]').each(function () {
787 - this.name =
788 - new_field_id +
789 - this.name.replace(
790 - this.name.startsWith('_nonce') ? '_nonce' : unique_id,
791 - ''
792 - )
793 - })
794 - $cloned_item.find('.spf-data-wrapper').each(function () {
795 - $(this).attr('data-unique-id', new_field_id)
796 - })
797 - $wrapper.append($cloned_item)
798 - $wrapper.accordion('refresh')
799 - $wrapper.accordion({ active: count })
800 - // $wrapper.spf_customizer_refresh();
801 - // $wrapper.spf_customizer_listen({closest: true});
838 + settings = $.extend({}, settings, defaults)
802 839
803 - if (is_number) {
804 - update_title_numbers($wrapper)
805 - }
806 - pcp_hide_the_taxonomy_relation(count + 1)
807 - })
840 + if ($inputs.length === 2) {
841 + settings = $.extend({}, settings, {
842 + onSelect: function (selectedDate) {
843 + var $this = $(this),
844 + $from = $inputs.first(),
845 + option =
846 + $inputs.first().attr('id') === $(this).attr('id')
847 + ? 'minDate'
848 + : 'maxDate',
849 + date = $.datepicker.parseDate(settings.dateFormat, selectedDate)
808 850
809 - var event_clone = function (e) {
810 - e.preventDefault()
851 + $inputs.not(this).datepicker('option', option, date)
852 + }
853 + })
854 + }
811 855
812 - var count = $wrapper.children('.spf-cloneable-item').length
856 + $inputs.each(function () {
857 + var $input = $(this)
813 858
814 - $min.hide()
859 + if ($input.hasClass('hasDatepicker')) {
860 + $input.removeAttr('id').removeClass('hasDatepicker')
861 + }
815 862
816 - if (max && count + 1 > max) {
817 - $max.show()
818 - return
819 - }
863 + $input.datepicker(settings)
864 + })
865 + })
866 + }
820 867
821 - var $this = $(this),
822 - $parent = $this.parent().parent(),
823 - $cloned_helper = $parent
824 - .children('.spf-cloneable-helper')
825 - .spf_clone(true),
826 - $cloned_title = $parent.children('.spf-cloneable-title').spf_clone(),
827 - $cloned_content = $parent
828 - .children('.spf-cloneable-content')
829 - .spf_clone(),
830 - cloned_regex = new RegExp(
831 - '(' + SP_PC.helper.preg_quote(field_id) + ')\\[(\\d+)\\]',
832 - 'g'
833 - )
868 + //
869 + // Field: fieldset
870 + //
871 + $.fn.spf_field_fieldset = function () {
872 + return this.each(function () {
873 + $(this)
874 + .find('.spf-fieldset-content')
875 + .spf_reload_script()
876 + })
877 + }
834 878
835 - $cloned_content.find('.spf-data-wrapper').each(function () {
836 - var $this = $(this)
837 - $this.attr(
838 - 'data-unique-id',
839 - $this
840 - .attr('data-unique-id')
841 - .replace(
842 - cloned_regex,
843 - field_id + '[' + ($parent.index() + 1) + ']'
844 - )
845 - )
846 - })
879 + //
880 + // Field: gallery
881 + //
882 + $.fn.spf_field_gallery = function () {
883 + return this.each(function () {
884 + var $this = $(this),
885 + $edit = $this.find('.spf-edit-gallery'),
886 + $clear = $this.find('.spf-clear-gallery'),
887 + $list = $this.find('ul.sp-gallery-images'),
888 + $input = $this.find('input'),
889 + $img = $this.find('img'),
890 + wp_media_frame
847 891
848 - var $cloned = $('<div class="spf-cloneable-item" />')
849 - $cloned.append($cloned_helper)
850 - $cloned.append($cloned_title)
851 - $cloned.append($cloned_content)
892 + $this.on('click', '.spf-button, .spf-edit-gallery', function (e) {
893 + var $el = $(this),
894 + ids = $input.val(),
895 + what = $el.hasClass('spf-edit-gallery') ? 'edit' : 'add',
896 + state = what === 'add' && !ids.length ? 'gallery' : 'gallery-edit'
852 897
853 - $wrapper
854 - .children()
855 - .eq($parent.index())
856 - .after($cloned)
898 + e.preventDefault()
857 899
858 - SP_PC.helper.name_nested_replace(
859 - $wrapper.children('.spf-cloneable-item'),
860 - field_id
861 - )
900 + if (
901 + typeof window.wp === 'undefined' ||
902 + !window.wp.media ||
903 + !window.wp.media.gallery
904 + ) {
905 + return
906 + }
862 907
863 - $wrapper.accordion('refresh')
864 - // $wrapper.spf_customizer_refresh();
865 - // $wrapper.spf_customizer_listen({closest: true});
908 + // Open media with state
909 + if (state === 'gallery') {
910 + wp_media_frame = window.wp.media({
911 + library: {
912 + type: 'image'
913 + },
914 + frame: 'post',
915 + state: 'gallery',
916 + multiple: true
917 + })
866 918
867 - if (is_number) {
868 - update_title_numbers($wrapper)
869 - }
870 - pcp_hide_the_taxonomy_relation(count + 1)
871 - }
919 + wp_media_frame.open()
920 + } else {
921 + wp_media_frame = window.wp.media.gallery.edit(
922 + '[gallery ids="' + ids + '"]'
923 + )
872 924
873 - $wrapper
874 - .children('.spf-cloneable-item')
875 - .children('.spf-cloneable-helper')
876 - .on('click', '.spf-cloneable-clone', event_clone)
877 - $group
878 - .children('.spf-cloneable-hidden')
879 - .children('.spf-cloneable-helper')
880 - .on('click', '.spf-cloneable-clone', event_clone)
881 - var event_remove = function (e) {
882 - e.preventDefault()
925 + if (what === 'add') {
926 + wp_media_frame.setState('gallery-library')
927 + }
928 + }
883 929
884 - var count = $wrapper.children('.spf-cloneable-item').length
930 + // Media Update
931 + wp_media_frame.on('update', function (selection) {
932 + $list.empty()
885 933
886 - $max.hide()
887 - $min.hide()
934 + var selectedIds = selection.models.map(function (attachment) {
935 + var item = attachment.toJSON()
936 + var thumb =
937 + item.sizes && item.sizes.thumbnail && item.sizes.thumbnail.url
938 + ? item.sizes.thumbnail.url
939 + : item.url
888 940
889 - if (min && count - 1 < min) {
890 - $min.show()
891 - return
892 - }
941 + $list.append('<li><img src="' + thumb + '"></li>')
893 942
894 - $(this)
895 - .closest('.spf-cloneable-item')
896 - .remove()
943 + return item.id
944 + })
897 945
898 - SP_PC.helper.name_nested_replace(
899 - $wrapper.children('.spf-cloneable-item'),
900 - field_id
901 - )
946 + $input.val(selectedIds.join(',')).trigger('change')
947 + $clear.removeClass('hidden')
948 + $edit.removeClass('hidden')
949 + })
950 + })
902 951
903 - //$wrapper.spf_customizer_refresh();
952 + $clear.on('click', function (e) {
953 + e.preventDefault()
954 + $list.empty()
955 + $input.val('').trigger('change')
956 + $clear.addClass('hidden')
957 + $edit.addClass('hidden')
958 + })
959 + })
960 + }
904 961
905 - if (is_number) {
906 - update_title_numbers($wrapper)
907 - }
908 - pcp_hide_the_taxonomy_relation(count - 1)
909 - }
910 - $wrapper
911 - .children('.spf-cloneable-item')
912 - .children('.spf-cloneable-helper')
913 - .on('click', '.spf-cloneable-remove', event_remove)
914 - $group
915 - .children('.spf-cloneable-hidden')
916 - .children('.spf-cloneable-helper')
917 - .on('click', '.spf-cloneable-remove', event_remove)
918 - })
919 - }
962 + //
963 + // Field: group
964 + //
965 + $.fn.spf_field_group = function () {
966 + return this.each(function () {
967 + var $this = $(this),
968 + $fieldset = $this.children('.spf-fieldset'),
969 + $group = $fieldset.length ? $fieldset : $this,
970 + $wrapper = $group.children('.spf-cloneable-wrapper'),
971 + $hidden = $group.children('.spf-cloneable-hidden'),
972 + $max = $group.children('.spf-cloneable-max'),
973 + $min = $group.children('.spf-cloneable-min'),
974 + field_id = $wrapper.data('field-id'),
975 + unique_id = $wrapper.data('unique-id'),
976 + is_number = Boolean(Number($wrapper.data('title-number'))),
977 + max = parseInt($wrapper.data('max')),
978 + min = parseInt($wrapper.data('min'))
920 979
921 - //
922 - // Field: icon
923 - //
924 - $.fn.spf_field_icon = function () {
925 - return this.each(function () {
926 - var $this = $(this)
980 + // clear accordion arrows if multi-instance
981 + if ($wrapper.hasClass('ui-accordion')) {
982 + $wrapper.find('.ui-accordion-header-icon').remove()
983 + }
927 984
928 - $this.on('click', '.spf-icon-add', function (e) {
929 - e.preventDefault()
985 + var update_title_numbers = function ($selector) {
986 + $selector.find('.spf-cloneable-title-number').each(function (index) {
987 + $(this).html(
988 + $(this)
989 + .closest('.spf-cloneable-item')
990 + .index() +
991 + 1 +
992 + '.'
993 + )
994 + })
995 + }
930 996
931 - var $button = $(this)
932 - var $modal = $('#spf-modal-icon')
997 + // Hide the taxonomy relation field. -- Shamim
998 + var $pcp_group_parent = $this.parent()
999 + var pcp_hide_the_taxonomy_relation = function (count_tax) {
1000 + if (count_tax < 2) {
1001 + $($pcp_group_parent)
1002 + .find('.pcp_relate_among_taxonomies')
1003 + .hide()
1004 + } else {
1005 + $($pcp_group_parent)
1006 + .find('.pcp_relate_among_taxonomies')
1007 + .show()
1008 + }
1009 + }
933 1010
934 - $modal.show()
1011 + var count = $wrapper.children('.spf-cloneable-item').length
1012 + pcp_hide_the_taxonomy_relation(count)
935 1013
936 - SP_PC.vars.$icon_target = $this
1014 + $wrapper.accordion({
1015 + header: '> .spf-cloneable-item > .spf-cloneable-title',
1016 + collapsible: true,
1017 + active: false,
1018 + animate: false,
1019 + heightStyle: 'content',
1020 + icons: {
1021 + header: 'spf-cloneable-header-icon fa fa-angle-right',
1022 + activeHeader: 'spf-cloneable-header-icon fa fa-angle-down'
1023 + },
1024 + activate: function (event, ui) {
1025 + var $panel = ui.newPanel
1026 + var $header = ui.newHeader
937 1027
938 - if (!SP_PC.vars.icon_modal_loaded) {
939 - $modal.find('.spf-modal-loading').show()
1028 + if ($panel.length && !$panel.data('opened')) {
1029 + var $fields = $panel.children()
1030 + var $first = $fields
1031 + .first()
1032 + .find('select')
1033 + .first()
1034 + var $title = $header.find('.spf-cloneable-value')
940 1035
941 - // window.wp.ajax.post( 'spf-get-icons', { nonce: $button.data('nonce') } ).done( function( response ) {
942 - window.wp.ajax
943 - .post('spf-get-icons', {
944 - nonce: $button.data('nonce')
945 - })
946 - .done(function (response) {
947 - $modal.find('.spf-modal-loading').hide()
1036 + $first.on('change', function (event) {
1037 + //$title.text( $first.children("option").filter(":selected").text() );
1038 + $title.text($first.val())
1039 + })
948 1040
949 - SP_PC.vars.icon_modal_loaded = true
1041 + $panel.spf_reload_script()
1042 + $panel.data('opened', true)
1043 + $panel.data('retry', false)
1044 + } else if ($panel.data('retry')) {
1045 + $panel.spf_reload_script_retry()
1046 + $panel.data('retry', false)
1047 + }
1048 + }
1049 + })
950 1050
951 - var $load = $modal.find('.spf-modal-load').html(response.content)
1051 + $wrapper.sortable({
1052 + axis: 'y',
1053 + handle: '.spf-cloneable-title,.spf-cloneable-sort',
1054 + helper: 'original',
1055 + cursor: 'move',
1056 + placeholder: 'widget-placeholder',
1057 + start: function (event, ui) {
1058 + $wrapper.accordion({ active: false })
1059 + $wrapper.sortable('refreshPositions')
1060 + ui.item.children('.spf-cloneable-content').data('retry', true)
1061 + },
1062 + update: function (event, ui) {
1063 + SP_PC.helper.name_nested_replace(
1064 + $wrapper.children('.spf-cloneable-item'),
1065 + field_id
1066 + )
952 1067
953 - $load.on('click', 'a', function (e) {
954 - e.preventDefault()
1068 + //$wrapper.spf_customizer_refresh();
955 1069
956 - var icon = $(this).data('spf-icon')
1070 + if (is_number) {
1071 + update_title_numbers($wrapper)
1072 + }
1073 + }
1074 + })
957 1075
958 - SP_PC.vars.$icon_target
959 - .find('i')
960 - .removeAttr('class')
961 - .addClass(icon)
962 - SP_PC.vars.$icon_target
963 - .find('input')
964 - .val(icon)
965 - .trigger('change')
966 - SP_PC.vars.$icon_target
967 - .find('.spf-icon-preview')
968 - .removeClass('hidden')
969 - SP_PC.vars.$icon_target
970 - .find('.spf-icon-remove')
971 - .removeClass('hidden')
1076 + $group.children('.spf-cloneable-add').on('click', function (e) {
1077 + e.preventDefault()
972 1078
973 - $modal.hide()
974 - })
1079 + var count = $wrapper.children('.spf-cloneable-item').length
975 1080
976 - $modal.on('change keyup', '.spf-icon-search', function () {
977 - var value = $(this).val(),
978 - $icons = $load.find('a')
1081 + $min.hide()
979 1082
980 - $icons.each(function () {
981 - var $elem = $(this)
1083 + if (max && count + 1 > max) {
1084 + $max.show()
1085 + return
1086 + }
982 1087
983 - if (
984 - $elem.data('spf-icon').search(new RegExp(value, 'i')) < 0
985 - ) {
986 - $elem.hide()
987 - } else {
988 - $elem.show()
989 - }
990 - })
991 - })
1088 + var new_field_id = unique_id + field_id + '[' + count + ']'
992 1089
993 - $modal.on(
994 - 'click',
995 - '.spf-modal-close, .spf-modal-overlay',
996 - function () {
997 - $modal.hide()
998 - }
999 - )
1000 - })
1001 - .fail(function (response) {
1002 - $modal.find('.spf-modal-loading').hide()
1003 - $modal.find('.spf-modal-load').html(response.error)
1004 - $modal.on('click', function () {
1005 - $modal.hide()
1006 - })
1007 - })
1008 - }
1009 - })
1090 + var $cloned_item = $hidden.spf_clone(true)
1010 1091
1011 - $this.on('click', '.spf-icon-remove', function (e) {
1012 - e.preventDefault()
1013 - $this.find('.spf-icon-preview').addClass('hidden')
1014 - $this
1015 - .find('input')
1016 - .val('')
1017 - .trigger('change')
1018 - $(this).addClass('hidden')
1019 - })
1020 - })
1021 - }
1092 + $cloned_item.removeClass('spf-cloneable-hidden')
1093 + // $cloned_item.find(':input').each( function() {
1094 + // this.name = new_field_id + this.name.replace( ( this.name.startsWith('_nonce') ? '_nonce' : unique_id ), '');
1095 + // });
1096 + $cloned_item.find(':input[name!="_pseudo"]').each(function () {
1097 + this.name =
1098 + new_field_id +
1099 + this.name.replace(
1100 + this.name.startsWith('_nonce') ? '_nonce' : unique_id,
1101 + ''
1102 + )
1103 + })
1104 + $cloned_item.find('.spf-data-wrapper').each(function () {
1105 + $(this).attr('data-unique-id', new_field_id)
1106 + })
1107 + $wrapper.append($cloned_item)
1108 + $wrapper.accordion('refresh')
1109 + $wrapper.accordion({ active: count })
1110 + // $wrapper.spf_customizer_refresh();
1111 + // $wrapper.spf_customizer_listen({closest: true});
1022 1112
1023 - //
1024 - // Field: slider
1025 - //
1026 - $.fn.spf_field_slider = function () {
1027 - return this.each(function () {
1028 - var $this = $(this),
1029 - $input = $this.find('input'),
1030 - $slider = $this.find('.spf-slider-ui'),
1031 - data = $input.data(),
1032 - value = $input.val() || 0
1113 + if (is_number) {
1114 + update_title_numbers($wrapper)
1115 + }
1116 + pcp_hide_the_taxonomy_relation(count + 1)
1117 + })
1033 1118
1034 - if ($slider.hasClass('ui-slider')) {
1035 - $slider.empty()
1036 - }
1119 + var event_clone = function (e) {
1120 + e.preventDefault()
1037 1121
1038 - $slider.slider({
1039 - range: 'min',
1040 - value: value,
1041 - min: data.min,
1042 - max: data.max,
1043 - step: data.step,
1044 - slide: function (e, o) {
1045 - $input.val(o.value).trigger('change')
1046 - }
1047 - })
1122 + var count = $wrapper.children('.spf-cloneable-item').length
1048 1123
1049 - $input.keyup(function () {
1050 - $slider.slider('value', $input.val())
1051 - })
1052 - })
1053 - }
1124 + $min.hide()
1054 1125
1055 - //
1056 - // Field: c
1057 - //
1058 - $.fn.spf_field_sorter = function () {
1059 - return this.each(function () {
1060 - var $this = $(this),
1061 - $enabled = $this.find('.spf-enabled'),
1062 - $has_disabled = $this.find('.spf-disabled'),
1063 - $disabled = $has_disabled.length ? $has_disabled : false
1126 + if (max && count + 1 > max) {
1127 + $max.show()
1128 + return
1129 + }
1064 1130
1065 - $enabled.sortable({
1066 - connectWith: $disabled,
1131 + var $this = $(this),
1132 + $parent = $this.parent().parent(),
1133 + $cloned_helper = $parent
1134 + .children('.spf-cloneable-helper')
1135 + .spf_clone(true),
1136 + $cloned_title = $parent.children('.spf-cloneable-title').spf_clone(),
1137 + $cloned_content = $parent
1138 + .children('.spf-cloneable-content')
1139 + .spf_clone(),
1140 + cloned_regex = new RegExp(
1141 + '(' + SP_PC.helper.preg_quote(field_id) + ')\\[(\\d+)\\]',
1142 + 'g'
1143 + )
1067 1144
1068 - placeholder: 'ui-sortable-placeholder',
1145 + $cloned_content.find('.spf-data-wrapper').each(function () {
1146 + var $this = $(this)
1147 + $this.attr(
1148 + 'data-unique-id',
1149 + $this
1150 + .attr('data-unique-id')
1151 + .replace(
1152 + cloned_regex,
1153 + field_id + '[' + ($parent.index() + 1) + ']'
1154 + )
1155 + )
1156 + })
1069 1157
1070 - update: function (event, ui) {
1071 - var $el = ui.item.find('input')
1158 + var $cloned = $('<div class="spf-cloneable-item" />')
1159 + $cloned.append($cloned_helper)
1160 + $cloned.append($cloned_title)
1161 + $cloned.append($cloned_content)
1072 1162
1073 - if (ui.item.parent().hasClass('spf-enabled')) {
1074 - $el.attr('name', $el.attr('name').replace('disabled', 'enabled'))
1075 - } else {
1076 - $el.attr('name', $el.attr('name').replace('enabled', 'disabled'))
1077 - }
1163 + $wrapper
1164 + .children()
1165 + .eq($parent.index())
1166 + .after($cloned)
1078 1167
1079 - // $this.spf_customizer_refresh();
1080 - }
1081 - })
1168 + SP_PC.helper.name_nested_replace(
1169 + $wrapper.children('.spf-cloneable-item'),
1170 + field_id
1171 + )
1082 1172
1083 - if ($disabled) {
1084 - $disabled.sortable({
1085 - connectWith: $enabled,
1086 - placeholder: 'ui-sortable-placeholder'
1087 - // update: function( event, ui ) {
1088 - // $this.spf_customizer_refresh();
1089 - // }
1090 - })
1091 - }
1092 - })
1093 - }
1173 + $wrapper.accordion('refresh')
1174 + // $wrapper.spf_customizer_refresh();
1175 + // $wrapper.spf_customizer_listen({closest: true});
1094 1176
1095 - //
1096 - // Field: spinner
1097 - //
1098 - $.fn.spf_field_spinner = function () {
1099 - return this.each(function () {
1100 - var $this = $(this),
1101 - $input = $this.find('input'),
1102 - $inited = $this.find('.ui-spinner-button'),
1103 - $unit = $input.data('unit')
1177 + if (is_number) {
1178 + update_title_numbers($wrapper)
1179 + }
1180 + pcp_hide_the_taxonomy_relation(count + 1)
1181 + }
1104 1182
1105 - if ($inited.length) {
1106 - $inited.remove()
1107 - }
1183 + $wrapper
1184 + .children('.spf-cloneable-item')
1185 + .children('.spf-cloneable-helper')
1186 + .on('click', '.spf-cloneable-clone', event_clone)
1187 + $group
1188 + .children('.spf-cloneable-hidden')
1189 + .children('.spf-cloneable-helper')
1190 + .on('click', '.spf-cloneable-clone', event_clone)
1191 + var event_remove = function (e) {
1192 + e.preventDefault()
1108 1193
1109 - $input.spinner({
1110 - max: $input.data('max') || 100,
1111 - min: $input.data('min') || 0,
1112 - step: $input.data('step') || 1,
1113 - create: function (event, ui) {
1114 - if ($unit.length) {
1115 - $this
1116 - .find('.ui-spinner-up')
1117 - .after(
1118 - '<span class="ui-button-text-only spf--unit">' +
1119 - $unit +
1120 - '</span>'
1121 - )
1122 - }
1123 - },
1124 - spin: function (event, ui) {
1125 - $input.val(ui.value).trigger('change')
1126 - }
1127 - })
1128 - })
1129 - }
1194 + var count = $wrapper.children('.spf-cloneable-item').length
1130 1195
1131 - //
1132 - // Field: switcher
1133 - //
1134 - $.fn.spf_field_switcher = function () {
1135 - return this.each(function () {
1136 - var $switcher = $(this).find('.spf--switcher')
1196 + $max.hide()
1197 + $min.hide()
1137 1198
1138 - $switcher.on('click', function () {
1139 - var value = 0
1140 - var $input = $switcher.find('input')
1199 + if (min && count - 1 < min) {
1200 + $min.show()
1201 + return
1202 + }
1141 1203
1142 - if ($switcher.hasClass('spf--active')) {
1143 - $switcher.removeClass('spf--active')
1144 - } else {
1145 - value = 1
1146 - $switcher.addClass('spf--active')
1147 - }
1204 + $(this)
1205 + .closest('.spf-cloneable-item')
1206 + .remove()
1148 1207
1149 - $input.val(value).trigger('change')
1150 - })
1151 - })
1152 - }
1208 + SP_PC.helper.name_nested_replace(
1209 + $wrapper.children('.spf-cloneable-item'),
1210 + field_id
1211 + )
1153 1212
1154 - //
1155 - // Field: typography
1156 - //
1157 - $.fn.spf_field_typography = function () {
1158 - return this.each(function () {
1159 - var base = this
1160 - var $this = $(this)
1161 - var loaded_fonts = []
1162 - var webfonts = spf_typography_json.webfonts
1163 - var googlestyles = spf_typography_json.googlestyles
1164 - var defaultstyles = spf_typography_json.defaultstyles
1213 + //$wrapper.spf_customizer_refresh();
1165 1214
1166 - //
1167 - //
1168 - // Sanitize google font subset
1169 - base.sanitize_subset = function (subset) {
1170 - subset = subset.replace('-ext', ' Extended')
1171 - subset = subset.charAt(0).toUpperCase() + subset.slice(1)
1172 - return subset
1173 - }
1215 + if (is_number) {
1216 + update_title_numbers($wrapper)
1217 + }
1218 + pcp_hide_the_taxonomy_relation(count - 1)
1219 + }
1220 + $wrapper
1221 + .children('.spf-cloneable-item')
1222 + .children('.spf-cloneable-helper')
1223 + .on('click', '.spf-cloneable-remove', event_remove)
1224 + $group
1225 + .children('.spf-cloneable-hidden')
1226 + .children('.spf-cloneable-helper')
1227 + .on('click', '.spf-cloneable-remove', event_remove)
1228 + })
1229 + }
1174 1230
1175 - //
1176 - //
1177 - // Sanitize google font styles (weight and style)
1178 - base.sanitize_style = function (style) {
1179 - return googlestyles[style] ? googlestyles[style] : style
1180 - }
1231 + //
1232 + // Field: icon
1233 + //
1234 + $.fn.spf_field_icon = function () {
1235 + return this.each(function () {
1236 + var $this = $(this)
1181 1237
1182 - //
1183 - //
1184 - // Load google font
1185 - base.load_google_font = function (font_family, weight, style) {
1186 - if (font_family && typeof WebFont === 'object') {
1187 - weight = weight ? weight.replace('normal', '') : ''
1188 - style = style ? style.replace('normal', '') : ''
1238 + $this.on('click', '.spf-icon-add', function (e) {
1239 + e.preventDefault()
1189 1240
1190 - if (weight || style) {
1191 - font_family = font_family + ':' + weight + style
1192 - }
1241 + var $button = $(this)
1242 + var $modal = $('#spf-modal-icon')
1193 1243
1194 - if (loaded_fonts.indexOf(font_family) === -1) {
1195 - WebFont.load({ google: { families: [font_family] } })
1196 - }
1244 + $modal.show()
1197 1245
1198 - loaded_fonts.push(font_family)
1199 - }
1200 - }
1246 + SP_PC.vars.$icon_target = $this
1201 1247
1202 - //
1203 - //
1204 - // Append select options
1205 - base.append_select_options = function (
1206 - $select,
1207 - options,
1208 - condition,
1209 - type,
1210 - is_multi
1211 - ) {
1212 - $select
1213 - .find('option')
1214 - .not(':first')
1215 - .remove()
1248 + if (!SP_PC.vars.icon_modal_loaded) {
1249 + $modal.find('.spf-modal-loading').show()
1216 1250
1217 - var opts = ''
1251 + // window.wp.ajax.post( 'spf-get-icons', { nonce: $button.data('nonce') } ).done( function( response ) {
1252 + window.wp.ajax
1253 + .post('spf-get-icons', {
1254 + nonce: $button.data('nonce')
1255 + })
1256 + .done(function (response) {
1257 + $modal.find('.spf-modal-loading').hide()
1218 1258
1219 - $.each(options, function (key, value) {
1220 - var selected
1221 - var name = value
1259 + SP_PC.vars.icon_modal_loaded = true
1222 1260
1223 - // is_multi
1224 - if (is_multi) {
1225 - selected =
1226 - condition && condition.indexOf(value) !== -1 ? ' selected' : ''
1227 - } else {
1228 - selected = condition && condition === value ? ' selected' : ''
1229 - }
1261 + var $load = $modal.find('.spf-modal-load').html(response.content)
1230 1262
1231 - if (type === 'subset') {
1232 - name = base.sanitize_subset(value)
1233 - } else if (type === 'style') {
1234 - name = base.sanitize_style(value)
1235 - }
1263 + $load.on('click', 'a', function (e) {
1264 + e.preventDefault()
1236 1265
1237 - opts +=
1238 - '<option value="' +
1239 - value +
1240 - '"' +
1241 - selected +
1242 - '>' +
1243 - name +
1244 - '</option>'
1245 - })
1266 + var icon = $(this).data('spf-icon')
1246 1267
1247 - $select
1248 - .append(opts)
1249 - .trigger('spf.change')
1250 - .trigger('chosen:updated')
1251 - }
1268 + SP_PC.vars.$icon_target
1269 + .find('i')
1270 + .removeAttr('class')
1271 + .addClass(icon)
1272 + SP_PC.vars.$icon_target
1273 + .find('input')
1274 + .val(icon)
1275 + .trigger('change')
1276 + SP_PC.vars.$icon_target
1277 + .find('.spf-icon-preview')
1278 + .removeClass('hidden')
1279 + SP_PC.vars.$icon_target
1280 + .find('.spf-icon-remove')
1281 + .removeClass('hidden')
1252 1282
1253 - base.init = function () {
1254 - //
1255 - //
1256 - // Constants
1257 - var selected_styles = []
1258 - var $typography = $this.find('.spf--typography')
1259 - var $type = $this.find('.spf--type')
1260 - var $styles = $this.find('.spf--block-font-style')
1261 - var unit = $typography.data('unit')
1262 - var exclude_fonts = $typography.data('exclude')
1263 - ? $typography.data('exclude').split(',')
1264 - : []
1283 + $modal.hide()
1284 + })
1265 1285
1266 - //
1267 - //
1268 - // Chosen init
1269 - if ($this.find('.spf--chosen').length) {
1270 - var $chosen_selects = $this.find('select')
1286 + $modal.on('change keyup', '.spf-icon-search', function () {
1287 + var value = $(this).val(),
1288 + $icons = $load.find('a')
1271 1289
1272 - $chosen_selects.each(function () {
1273 - var $chosen_select = $(this),
1274 - $chosen_inited = $chosen_select.parent().find('.chosen-container')
1290 + $icons.each(function () {
1291 + var $elem = $(this)
1275 1292
1276 - if ($chosen_inited.length) {
1277 - $chosen_inited.remove()
1278 - }
1293 + if (
1294 + $elem.data('spf-icon').search(new RegExp(value, 'i')) < 0
1295 + ) {
1296 + $elem.hide()
1297 + } else {
1298 + $elem.show()
1299 + }
1300 + })
1301 + })
1279 1302
1280 - $chosen_select.chosen({
1281 - allow_single_deselect: true,
1282 - disable_search_threshold: 15,
1283 - width: '100%'
1284 - })
1285 - })
1286 - }
1303 + $modal.on(
1304 + 'click',
1305 + '.spf-modal-close, .spf-modal-overlay',
1306 + function () {
1307 + $modal.hide()
1308 + }
1309 + )
1310 + })
1311 + .fail(function (response) {
1312 + $modal.find('.spf-modal-loading').hide()
1313 + $modal.find('.spf-modal-load').html(response.error)
1314 + $modal.on('click', function () {
1315 + $modal.hide()
1316 + })
1317 + })
1318 + }
1319 + })
1287 1320
1288 - //
1289 - //
1290 - // Font family select
1291 - var $font_family_select = $this.find('.spf--font-family')
1292 - var first_font_family = $font_family_select.val()
1321 + $this.on('click', '.spf-icon-remove', function (e) {
1322 + e.preventDefault()
1323 + $this.find('.spf-icon-preview').addClass('hidden')
1324 + $this
1325 + .find('input')
1326 + .val('')
1327 + .trigger('change')
1328 + $(this).addClass('hidden')
1329 + })
1330 + })
1331 + }
1293 1332
1294 - // Clear default font family select options
1295 - $font_family_select
1296 - .find('option')
1297 - .not(':first-child')
1298 - .remove()
1333 + //
1334 + // Field: media
1335 + //
1336 + $.fn.spf_field_media = function () {
1337 + return this.each(function () {
1338 + var $this = $(this),
1339 + $upload_button = $this.find('.spf--button'),
1340 + $remove_button = $this.find('.spf--remove'),
1341 + $library =
1342 + ($upload_button.data('library') &&
1343 + $upload_button.data('library').split(',')) ||
1344 + '',
1345 + wp_media_frame
1299 1346
1300 - var opts = ''
1347 + $upload_button.on('click', function (e) {
1348 + e.preventDefault()
1301 1349
1302 - $.each(webfonts, function (type, group) {
1303 - // Check for exclude fonts
1304 - if (exclude_fonts && exclude_fonts.indexOf(type) !== -1) {
1305 - return
1306 - }
1350 + if (
1351 + typeof window.wp === 'undefined' ||
1352 + !window.wp.media ||
1353 + !window.wp.media.gallery
1354 + ) {
1355 + return
1356 + }
1307 1357
1308 - opts += '<optgroup label="' + group.label + '">'
1358 + if (wp_media_frame) {
1359 + wp_media_frame.open()
1360 + return
1361 + }
1309 1362
1310 - $.each(group.fonts, function (key, value) {
1311 - // use key if value is object
1312 - value = typeof value === 'object' ? key : value
1313 - var selected = value === first_font_family ? ' selected' : ''
1314 - opts +=
1315 - '<option value="' +
1316 - value +
1317 - '" data-type="' +
1318 - type +
1319 - '"' +
1320 - selected +
1321 - '>' +
1322 - value +
1323 - '</option>'
1324 - })
1363 + wp_media_frame = window.wp.media({
1364 + library: {
1365 + type: $library
1366 + }
1367 + })
1325 1368
1326 - opts += '</optgroup>'
1327 - })
1369 + wp_media_frame.on('select', function () {
1370 + var thumbnail
1371 + var attributes = wp_media_frame
1372 + .state()
1373 + .get('selection')
1374 + .first().attributes
1375 + var preview_size = $upload_button.data('preview-size') || 'thumbnail'
1328 1376
1329 - // Append google font select options
1330 - $font_family_select.append(opts).trigger('chosen:updated')
1377 + if (
1378 + $library.length &&
1379 + $library.indexOf(attributes.subtype) === -1 &&
1380 + $library.indexOf(attributes.type) === -1
1381 + ) {
1382 + return
1383 + }
1331 1384
1332 - //
1333 - //
1334 - // Font style select
1335 - var $font_style_block = $this.find('.spf--block-font-style')
1385 + $this.find('.spf--id').val(attributes.id)
1386 + $this.find('.spf--width').val(attributes.width)
1387 + $this.find('.spf--height').val(attributes.height)
1388 + $this.find('.spf--alt').val(attributes.alt)
1389 + $this.find('.spf--title').val(attributes.title)
1390 + $this.find('.spf--description').val(attributes.description)
1336 1391
1337 - if ($font_style_block.length) {
1338 - var $font_style_select = $this.find('.spf--font-style-select')
1339 - var first_style_value = $font_style_select.val()
1340 - ? $font_style_select.val().replace(/normal/g, '')
1341 - : ''
1392 + if (
1393 + typeof attributes.sizes !== 'undefined' &&
1394 + typeof attributes.sizes.thumbnail !== 'undefined' &&
1395 + preview_size === 'thumbnail'
1396 + ) {
1397 + thumbnail = attributes.sizes.thumbnail.url
1398 + } else if (
1399 + typeof attributes.sizes !== 'undefined' &&
1400 + typeof attributes.sizes.full !== 'undefined'
1401 + ) {
1402 + thumbnail = attributes.sizes.full.url
1403 + } else {
1404 + thumbnail = attributes.icon
1405 + }
1342 1406
1343 - //
1344 - // Font Style on on change listener
1345 - $font_style_select.on('change spf.change', function (event) {
1346 - var style_value = $font_style_select.val()
1407 + $remove_button.removeClass('hidden')
1347 1408
1348 - // set a default value
1349 - if (
1350 - !style_value &&
1351 - selected_styles &&
1352 - selected_styles.indexOf('normal') === -1
1353 - ) {
1354 - style_value = selected_styles[0]
1355 - }
1409 + $this.find('.spf--preview').removeClass('hidden')
1410 + $this.find('.spf--src').attr('src', thumbnail)
1411 + $this.find('.spf--thumbnail').val(thumbnail)
1412 + $this
1413 + .find('.spf--url')
1414 + .val(attributes.url)
1415 + .trigger('change')
1416 + })
1356 1417
1357 - // set font weight, for eg. replacing 800italic to 800
1358 - var font_normal =
1359 - style_value &&
1360 - style_value !== 'italic' &&
1361 - style_value === 'normal'
1362 - ? 'normal'
1363 - : ''
1364 - var font_weight =
1365 - style_value &&
1366 - style_value !== 'italic' &&
1367 - style_value !== 'normal'
1368 - ? style_value.replace('italic', '')
1369 - : font_normal
1370 - var font_style =
1371 - style_value && style_value.substr(-6) === 'italic' ? 'italic' : ''
1418 + wp_media_frame.open()
1419 + })
1372 1420
1373 - $this.find('.spf--font-weight').val(font_weight)
1374 - $this.find('.spf--font-style').val(font_style)
1375 - })
1421 + $remove_button.on('click', function (e) {
1422 + e.preventDefault()
1423 + $remove_button.addClass('hidden')
1424 + $this.find('input').val('')
1425 + $this.find('.spf--preview').addClass('hidden')
1426 + $this.find('.spf--thumbnail')
1427 + $this.find('.spf--url').trigger('change')
1428 + })
1429 + })
1430 + }
1376 1431
1377 - //
1378 - //
1379 - // Extra font style select
1380 - var $extra_font_style_block = $this.find('.spf--block-extra-styles')
1432 + //
1433 + // Field: slider
1434 + //
1435 + $.fn.spf_field_slider = function () {
1436 + return this.each(function () {
1437 + var $this = $(this),
1438 + $input = $this.find('input'),
1439 + $slider = $this.find('.spf-slider-ui'),
1440 + data = $input.data(),
1441 + value = $input.val() || 0
1381 1442
1382 - if ($extra_font_style_block.length) {
1383 - var $extra_font_style_select = $this.find('.spf--extra-styles')
1384 - var first_extra_style_value = $extra_font_style_select.val()
1385 - }
1386 - }
1443 + if ($slider.hasClass('ui-slider')) {
1444 + $slider.empty()
1445 + }
1387 1446
1388 - //
1389 - //
1390 - // Subsets select
1391 - var $subset_block = $this.find('.spf--block-subset')
1392 - if ($subset_block.length) {
1393 - var $subset_select = $this.find('.spf--subset')
1394 - var first_subset_select_value = $subset_select.val()
1395 - var subset_multi_select = $subset_select.data('multiple') || false
1396 - }
1447 + $slider.slider({
1448 + range: 'min',
1449 + value: value,
1450 + min: data.min,
1451 + max: data.max,
1452 + step: data.step,
1453 + slide: function (e, o) {
1454 + $input.val(o.value).trigger('change')
1455 + }
1456 + })
1397 1457
1398 - //
1399 - //
1400 - // Backup font family
1401 - var $backup_font_family_block = $this.find(
1402 - '.spf--block-backup-font-family'
1403 - )
1458 + $input.keyup(function () {
1459 + $slider.slider('value', $input.val())
1460 + })
1461 + })
1462 + }
1404 1463
1405 - //
1406 - //
1407 - // Font Family on Change Listener
1408 - $font_family_select
1409 - .on('change spf.change', function (event) {
1410 - // Hide subsets on change
1411 - if ($subset_block.length) {
1412 - $subset_block.addClass('hidden')
1413 - }
1464 + //
1465 + // Field: c
1466 + //
1467 + $.fn.spf_field_sorter = function () {
1468 + return this.each(function () {
1469 + var $this = $(this),
1470 + $enabled = $this.find('.spf-enabled'),
1471 + $has_disabled = $this.find('.spf-disabled'),
1472 + $disabled = $has_disabled.length ? $has_disabled : false
1414 1473
1415 - // Hide extra font style on change
1416 - if ($extra_font_style_block.length) {
1417 - $extra_font_style_block.addClass('hidden')
1418 - }
1474 + $enabled.sortable({
1475 + connectWith: $disabled,
1419 1476
1420 - // Hide backup font family on change
1421 - if ($backup_font_family_block.length) {
1422 - $backup_font_family_block.addClass('hidden')
1423 - }
1477 + placeholder: 'ui-sortable-placeholder',
1424 1478
1425 - var $selected = $font_family_select.find(':selected')
1426 - var value = $selected.val()
1427 - var type = $selected.data('type')
1479 + update: function (event, ui) {
1480 + var $el = ui.item.find('input')
1428 1481
1429 - if (type && value) {
1430 - // Show backup fonts if font type google or custom
1431 - if (
1432 - (type === 'google' || type === 'custom') &&
1433 - $backup_font_family_block.length
1434 - ) {
1435 - $backup_font_family_block.removeClass('hidden')
1436 - }
1482 + if (ui.item.parent().hasClass('spf-enabled')) {
1483 + $el.attr('name', $el.attr('name').replace('disabled', 'enabled'))
1484 + } else {
1485 + $el.attr('name', $el.attr('name').replace('enabled', 'disabled'))
1486 + }
1437 1487
1438 - // Appending font style select options
1439 - if ($font_style_block.length) {
1440 - // set styles for multi and normal style selectors
1441 - var styles = defaultstyles
1488 + // $this.spf_customizer_refresh();
1489 + }
1490 + })
1442 1491
1443 - // Custom or gogle font styles
1444 - if (type === 'google' && webfonts[type].fonts[value][0]) {
1445 - styles = webfonts[type].fonts[value][0]
1446 - } else if (type === 'custom' && webfonts[type].fonts[value]) {
1447 - styles = webfonts[type].fonts[value]
1448 - }
1492 + if ($disabled) {
1493 + $disabled.sortable({
1494 + connectWith: $enabled,
1495 + placeholder: 'ui-sortable-placeholder'
1496 + // update: function( event, ui ) {
1497 + // $this.spf_customizer_refresh();
1498 + // }
1499 + })
1500 + }
1501 + })
1502 + }
1449 1503
1450 - selected_styles = styles
1504 + //
1505 + // Field: spinner
1506 + //
1507 + $.fn.spf_field_spinner = function () {
1508 + return this.each(function () {
1509 + var $this = $(this),
1510 + $input = $this.find('input'),
1511 + $inited = $this.find('.ui-spinner-button'),
1512 + $unit = $input.data('unit')
1451 1513
1452 - // Set selected style value for avoid load errors
1453 - var set_auto_style =
1454 - styles.indexOf('normal') !== -1 ? 'normal' : styles[0]
1455 - var set_style_value =
1456 - first_style_value && styles.indexOf(first_style_value) !== -1
1457 - ? first_style_value
1458 - : set_auto_style
1514 + if ($inited.length) {
1515 + $inited.remove()
1516 + }
1459 1517
1460 - // Append style select options
1461 - base.append_select_options(
1462 - $font_style_select,
1463 - styles,
1464 - set_style_value,
1465 - 'style'
1466 - )
1518 + $input.spinner({
1519 + max: $input.data('max') || 100,
1520 + min: $input.data('min') || 0,
1521 + step: $input.data('step') || 1,
1522 + create: function (event, ui) {
1523 + if ($unit.length) {
1524 + $this
1525 + .find('.ui-spinner-up')
1526 + .after(
1527 + '<span class="ui-button-text-only spf--unit">' +
1528 + $unit +
1529 + '</span>'
1530 + )
1531 + }
1532 + },
1533 + spin: function (event, ui) {
1534 + $input.val(ui.value).trigger('change')
1535 + }
1536 + })
1537 + })
1538 + }
1467 1539
1468 - // Clear first value
1469 - first_style_value = false
1540 + //
1541 + // Field: switcher
1542 + //
1543 + $.fn.spf_field_switcher = function () {
1544 + return this.each(function () {
1545 + var $switcher = $(this).find('.spf--switcher')
1470 1546
1471 - // Show style select after appended
1472 - $font_style_block.removeClass('hidden')
1547 + $switcher.on('click', function () {
1548 + var value = 0
1549 + var $input = $switcher.find('input')
1473 1550
1474 - // Appending extra font style select options
1475 - if (
1476 - type === 'google' &&
1477 - $extra_font_style_block.length &&
1478 - styles.length > 1
1479 - ) {
1480 - // Append extra-style select options
1481 - base.append_select_options(
1482 - $extra_font_style_select,
1483 - styles,
1484 - first_extra_style_value,
1485 - 'style',
1486 - true
1487 - )
1551 + if ($switcher.hasClass('spf--active')) {
1552 + $switcher.removeClass('spf--active')
1553 + } else {
1554 + value = 1
1555 + $switcher.addClass('spf--active')
1556 + }
1488 1557
1489 - // Clear first value
1490 - first_extra_style_value = false
1558 + $input.val(value).trigger('change')
1559 + })
1560 + })
1561 + }
1491 1562
1492 - // Show style select after appended
1493 - $extra_font_style_block.removeClass('hidden')
1494 - }
1495 - }
1563 + //
1564 + // Field: tabbed
1565 + //
1566 + $.fn.spf_field_tabbed = function () {
1567 + return this.each(function () {
1568 + var $this = $(this),
1569 + $links = $this.find('.spf-tabbed-nav a'),
1570 + $sections = $this.find('.spf-tabbed-section')
1496 1571
1497 - // Appending google fonts subsets select options
1498 - if (
1499 - type === 'google' &&
1500 - $subset_block.length &&
1501 - webfonts[type].fonts[value][1]
1502 - ) {
1503 - var subsets = webfonts[type].fonts[value][1]
1504 - var set_auto_subset =
1505 - subsets.length < 2 && subsets[0] !== 'latin' ? subsets[0] : ''
1506 - var set_subset_value =
1507 - first_subset_select_value &&
1508 - subsets.indexOf(first_subset_select_value) !== -1
1509 - ? first_subset_select_value
1510 - : set_auto_subset
1572 + $sections.eq(0).spf_reload_script()
1511 1573
1512 - // check for multiple subset select
1513 - set_subset_value =
1514 - subset_multi_select && first_subset_select_value
1515 - ? first_subset_select_value
1516 - : set_subset_value
1574 + $links.on('click', function (e) {
1575 + e.preventDefault()
1517 1576
1518 - base.append_select_options(
1519 - $subset_select,
1520 - subsets,
1521 - set_subset_value,
1522 - 'subset',
1523 - subset_multi_select
1524 - )
1577 + var $link = $(this),
1578 + index = $link.index(),
1579 + $section = $sections.eq(index)
1525 1580
1526 - first_subset_select_value = false
1581 + $link
1582 + .addClass('spf-tabbed-active')
1583 + .siblings()
1584 + .removeClass('spf-tabbed-active')
1585 + $section.spf_reload_script()
1586 + $section
1587 + .removeClass('hidden')
1588 + .siblings()
1589 + .addClass('hidden')
1590 + })
1591 + })
1592 + }
1527 1593
1528 - $subset_block.removeClass('hidden')
1529 - }
1530 - } else {
1531 - // Clear Styles
1532 - $styles.find(':input').val('')
1594 + //
1595 + // Field: typography
1596 + //
1597 + $.fn.spf_field_typography = function () {
1598 + return this.each(function () {
1599 + var base = this
1600 + var $this = $(this)
1601 + var loaded_fonts = []
1602 + var webfonts = spf_typography_json.webfonts
1603 + var googlestyles = spf_typography_json.googlestyles
1604 + var defaultstyles = spf_typography_json.defaultstyles
1533 1605
1534 - // Clear subsets options if type and value empty
1535 - if ($subset_block.length) {
1536 - $subset_select
1537 - .find('option')
1538 - .not(':first-child')
1539 - .remove()
1540 - $subset_select.trigger('chosen:updated')
1541 - }
1606 + //
1607 + //
1608 + // Sanitize google font subset
1609 + base.sanitize_subset = function (subset) {
1610 + subset = subset.replace('-ext', ' Extended')
1611 + subset = subset.charAt(0).toUpperCase() + subset.slice(1)
1612 + return subset
1613 + }
1542 1614
1543 - // Clear font styles options if type and value empty
1544 - if ($font_style_block.length) {
1545 - $font_style_select
1546 - .find('option')
1547 - .not(':first-child')
1548 - .remove()
1549 - $font_style_select.trigger('chosen:updated')
1550 - }
1551 - }
1615 + //
1616 + //
1617 + // Sanitize google font styles (weight and style)
1618 + base.sanitize_style = function (style) {
1619 + return googlestyles[style] ? googlestyles[style] : style
1620 + }
1552 1621
1553 - // Update font type input value
1554 - $type.val(type)
1555 - })
1556 - .trigger('spf.change')
1622 + //
1623 + //
1624 + // Load google font
1625 + base.load_google_font = function (font_family, weight, style) {
1626 + if (font_family && typeof WebFont === 'object') {
1627 + weight = weight ? weight.replace('normal', '') : ''
1628 + style = style ? style.replace('normal', '') : ''
1557 1629
1558 - //
1559 - //
1560 - // Preview
1561 - var $preview_block = $this.find('.spf--block-preview')
1630 + if (weight || style) {
1631 + font_family = font_family + ':' + weight + style
1632 + }
1562 1633
1563 - if ($preview_block.length) {
1564 - var $preview = $this.find('.spf--preview')
1634 + if (loaded_fonts.indexOf(font_family) === -1) {
1635 + WebFont.load({ google: { families: [font_family] } })
1636 + }
1565 1637
1566 - // Set preview styles on change
1567 - $this.on(
1568 - 'change',
1569 - SP_PC.helper.debounce(function (event) {
1570 - $preview_block.removeClass('hidden')
1638 + loaded_fonts.push(font_family)
1639 + }
1640 + }
1571 1641
1572 - var font_family = $font_family_select.val(),
1573 - font_weight = $this.find('.spf--font-weight').val(),
1574 - font_style = $this.find('.spf--font-style').val(),
1575 - font_size = $this.find('.spf--font-size').val(),
1576 - font_variant = $this.find('.spf--font-variant').val(),
1577 - line_height = $this.find('.spf--line-height').val(),
1578 - text_align = $this.find('.spf--text-align').val(),
1579 - text_transform = $this.find('.spf--text-transform').val(),
1580 - text_decoration = $this.find('.spf--text-decoration').val(),
1581 - text_color = $this.find('.spf--color').val(),
1582 - word_spacing = $this.find('.spf--word-spacing').val(),
1583 - letter_spacing = $this.find('.spf--letter-spacing').val(),
1584 - custom_style = $this.find('.spf--custom-style').val(),
1585 - type = $this.find('.spf--type').val()
1642 + //
1643 + //
1644 + // Append select options
1645 + base.append_select_options = function (
1646 + $select,
1647 + options,
1648 + condition,
1649 + type,
1650 + is_multi
1651 + ) {
1652 + $select
1653 + .find('option')
1654 + .not(':first')
1655 + .remove()
1586 1656
1587 - if (type === 'google') {
1588 - base.load_google_font(font_family, font_weight, font_style)
1589 - }
1657 + var opts = ''
1590 1658
1591 - var properties = {}
1659 + $.each(options, function (key, value) {
1660 + var selected
1661 + var name = value
1592 1662
1593 - if (font_family) {
1594 - properties.fontFamily = font_family
1595 - }
1596 - if (font_weight) {
1597 - properties.fontWeight = font_weight
1598 - }
1599 - if (font_style) {
1600 - properties.fontStyle = font_style
1601 - }
1602 - if (font_variant) {
1603 - properties.fontVariant = font_variant
1604 - }
1605 - if (font_size) {
1606 - properties.fontSize = font_size + unit
1607 - }
1608 - if (line_height) {
1609 - properties.lineHeight = line_height + unit
1610 - }
1611 - if (letter_spacing) {
1612 - properties.letterSpacing = letter_spacing + unit
1613 - }
1614 - if (word_spacing) {
1615 - properties.wordSpacing = word_spacing + unit
1616 - }
1617 - if (text_align) {
1618 - properties.textAlign = text_align
1619 - }
1620 - if (text_transform) {
1621 - properties.textTransform = text_transform
1622 - }
1623 - if (text_decoration) {
1624 - properties.textDecoration = text_decoration
1625 - }
1626 - if (text_color) {
1627 - properties.color = text_color
1628 - }
1663 + // is_multi
1664 + if (is_multi) {
1665 + selected =
1666 + condition && condition.indexOf(value) !== -1 ? ' selected' : ''
1667 + } else {
1668 + selected = condition && condition === value ? ' selected' : ''
1669 + }
1629 1670
1630 - $preview.removeAttr('style')
1671 + if (type === 'subset') {
1672 + name = base.sanitize_subset(value)
1673 + } else if (type === 'style') {
1674 + name = base.sanitize_style(value)
1675 + }
1631 1676
1632 - // Customs style attribute
1633 - if (custom_style) {
1634 - $preview.attr('style', custom_style)
1635 - }
1677 + opts +=
1678 + '<option value="' +
1679 + value +
1680 + '"' +
1681 + selected +
1682 + '>' +
1683 + name +
1684 + '</option>'
1685 + })
1636 1686
1637 - $preview.css(properties)
1638 - }, 100)
1639 - )
1687 + $select
1688 + .append(opts)
1689 + .trigger('spf.change')
1690 + .trigger('chosen:updated')
1691 + }
1640 1692
1641 - // Preview black and white backgrounds trigger
1642 - $preview_block.on('click', function () {
1643 - $preview.toggleClass('spf--black-background')
1693 + base.init = function () {
1694 + //
1695 + //
1696 + // Constants
1697 + var selected_styles = []
1698 + var $typography = $this.find('.spf--typography')
1699 + var $type = $this.find('.spf--type')
1700 + var $styles = $this.find('.spf--block-font-style')
1701 + var unit = $typography.data('unit')
1702 + var exclude_fonts = $typography.data('exclude')
1703 + ? $typography.data('exclude').split(',')
1704 + : []
1644 1705
1645 - var $toggle = $preview_block.find('.spf--toggle')
1706 + //
1707 + //
1708 + // Chosen init
1709 + if ($this.find('.spf--chosen').length) {
1710 + var $chosen_selects = $this.find('select')
1646 1711
1647 - if ($toggle.hasClass('fa-toggle-off')) {
1648 - $toggle.removeClass('fa-toggle-off').addClass('fa-toggle-on')
1649 - } else {
1650 - $toggle.removeClass('fa-toggle-on').addClass('fa-toggle-off')
1651 - }
1652 - })
1712 + $chosen_selects.each(function () {
1713 + var $chosen_select = $(this),
1714 + $chosen_inited = $chosen_select.parent().find('.chosen-container')
1653 1715
1654 - if (!$preview_block.hasClass('hidden')) {
1655 - $this.trigger('change')
1656 - }
1657 - }
1658 - }
1716 + if ($chosen_inited.length) {
1717 + $chosen_inited.remove()
1718 + }
1659 1719
1660 - base.init()
1661 - })
1662 - }
1720 + $chosen_select.chosen({
1721 + allow_single_deselect: true,
1722 + disable_search_threshold: 15,
1723 + width: '100%'
1724 + })
1725 + })
1726 + }
1663 1727
1664 - //
1665 - // Confirm
1666 - //
1667 - $.fn.spf_confirm = function () {
1668 - return this.each(function () {
1669 - $(this).on('click', function (e) {
1670 - var confirm_text =
1671 - $(this).data('confirm') || window.spf_vars.i18n.confirm
1672 - var confirm_answer = confirm(confirm_text)
1673 - SP_PC.vars.is_confirm = true
1728 + //
1729 + //
1730 + // Font family select
1731 + var $font_family_select = $this.find('.spf--font-family')
1732 + var first_font_family = $font_family_select.val()
1674 1733
1675 - if (!confirm_answer) {
1676 - e.preventDefault()
1677 - SP_PC.vars.is_confirm = false
1734 + // Clear default font family select options
1735 + $font_family_select
1736 + .find('option')
1737 + .not(':first-child')
1738 + .remove()
1678 1739
1679 - return false
1680 - }
1681 - })
1682 - })
1683 - }
1740 + var opts = ''
1684 1741
1685 - $.fn.serializeObject = function () {
1686 - var obj = {}
1742 + $.each(webfonts, function (type, group) {
1743 + // Check for exclude fonts
1744 + if (exclude_fonts && exclude_fonts.indexOf(type) !== -1) {
1745 + return
1746 + }
1687 1747
1688 - $.each(this.serializeArray(), function (i, o) {
1689 - var n = o.name,
1690 - v = o.value
1748 + opts += '<optgroup label="' + group.label + '">'
1691 1749
1692 - obj[n] =
1693 - obj[n] === undefined
1694 - ? v
1695 - : $.isArray(obj[n])
1696 - ? obj[n].concat(v)
1697 - : [obj[n], v]
1698 - })
1750 + $.each(group.fonts, function (key, value) {
1751 + // use key if value is object
1752 + value = typeof value === 'object' ? key : value
1753 + var selected = value === first_font_family ? ' selected' : ''
1754 + opts +=
1755 + '<option value="' +
1756 + value +
1757 + '" data-type="' +
1758 + type +
1759 + '"' +
1760 + selected +
1761 + '>' +
1762 + value +
1763 + '</option>'
1764 + })
1699 1765
1700 - return obj
1701 - }
1766 + opts += '</optgroup>'
1767 + })
1702 1768
1703 - //
1704 - // Options Save
1705 - //
1706 - $.fn.spf_save = function () {
1707 - return this.each(function () {
1708 - var $this = $(this),
1709 - $buttons = $('.spf-save'),
1710 - $panel = $('.spf-options'),
1711 - flooding = false,
1712 - timeout
1769 + // Append google font select options
1770 + $font_family_select.append(opts).trigger('chosen:updated')
1713 1771
1714 - $this.on('click', function (e) {
1715 - if (!flooding) {
1716 - var $text = $this.data('save'),
1717 - $value = $this.val()
1772 + //
1773 + //
1774 + // Font style select
1775 + var $font_style_block = $this.find('.spf--block-font-style')
1718 1776
1719 - $buttons.attr('value', $text)
1777 + if ($font_style_block.length) {
1778 + var $font_style_select = $this.find('.spf--font-style-select')
1779 + var first_style_value = $font_style_select.val()
1780 + ? $font_style_select.val().replace(/normal/g, '')
1781 + : ''
1720 1782
1721 - if ($this.hasClass('spf-save-ajax')) {
1722 - e.preventDefault()
1783 + //
1784 + // Font Style on on change listener
1785 + $font_style_select.on('change spf.change', function (event) {
1786 + var style_value = $font_style_select.val()
1723 1787
1724 - $panel.addClass('spf-saving')
1725 - $buttons.prop('disabled', true)
1788 + // set a default value
1789 + if (
1790 + !style_value &&
1791 + selected_styles &&
1792 + selected_styles.indexOf('normal') === -1
1793 + ) {
1794 + style_value = selected_styles[0]
1795 + }
1726 1796
1727 - window.wp.ajax
1728 - .post('spf_' + $panel.data('unique') + '_ajax_save', {
1729 - data: $('#spf-form').serializeJSONSP_PC()
1730 - })
1731 - .done(function (response) {
1732 - clearTimeout(timeout)
1797 + // set font weight, for eg. replacing 800italic to 800
1798 + var font_normal =
1799 + style_value &&
1800 + style_value !== 'italic' &&
1801 + style_value === 'normal'
1802 + ? 'normal'
1803 + : ''
1804 + var font_weight =
1805 + style_value &&
1806 + style_value !== 'italic' &&
1807 + style_value !== 'normal'
1808 + ? style_value.replace('italic', '')
1809 + : font_normal
1810 + var font_style =
1811 + style_value && style_value.substr(-6) === 'italic' ? 'italic' : ''
1733 1812
1734 - var $result_success = $('.spf-form-success')
1813 + $this.find('.spf--font-weight').val(font_weight)
1814 + $this.find('.spf--font-style').val(font_style)
1815 + })
1735 1816
1736 - $result_success
1737 - .empty()
1738 - .append(response.notice)
1739 - .slideDown('fast', function () {
1740 - timeout = setTimeout(function () {
1741 - $result_success.slideUp('fast')
1742 - }, 2000)
1743 - })
1817 + //
1818 + //
1819 + // Extra font style select
1820 + var $extra_font_style_block = $this.find('.spf--block-extra-styles')
1744 1821
1745 - // clear errors
1746 - $('.spf-error').remove()
1822 + if ($extra_font_style_block.length) {
1823 + var $extra_font_style_select = $this.find('.spf--extra-styles')
1824 + var first_extra_style_value = $extra_font_style_select.val()
1825 + }
1826 + }
1747 1827
1748 - var $append_errors = $('.spf-form-error')
1828 + //
1829 + //
1830 + // Subsets select
1831 + var $subset_block = $this.find('.spf--block-subset')
1832 + if ($subset_block.length) {
1833 + var $subset_select = $this.find('.spf--subset')
1834 + var first_subset_select_value = $subset_select.val()
1835 + var subset_multi_select = $subset_select.data('multiple') || false
1836 + }
1749 1837
1750 - $append_errors.empty().hide()
1838 + //
1839 + //
1840 + // Backup font family
1841 + var $backup_font_family_block = $this.find(
1842 + '.spf--block-backup-font-family'
1843 + )
1751 1844
1752 - if (Object.keys(response.errors).length) {
1753 - var error_icon = '<i class="spf-label-error spf-error">!</i>'
1845 + //
1846 + //
1847 + // Font Family on Change Listener
1848 + $font_family_select
1849 + .on('change spf.change', function (event) {
1850 + // Hide subsets on change
1851 + if ($subset_block.length) {
1852 + $subset_block.addClass('hidden')
1853 + }
1754 1854
1755 - $.each(response.errors, function (key, error_message) {
1756 - var $field = $('[data-depend-id="' + key + '"]'),
1757 - $link = $(
1758 - '#spf-tab-link-' +
1759 - ($field.closest('.spf-section').index() + 1)
1760 - ),
1761 - $tab = $link.closest('.spf-tab-depth-0')
1855 + // Hide extra font style on change
1856 + if ($extra_font_style_block.length) {
1857 + $extra_font_style_block.addClass('hidden')
1858 + }
1762 1859
1763 - $field
1764 - .closest('.spf-fieldset')
1765 - .append(
1766 - '<p class="spf-text-error spf-error">' +
1767 - error_message +
1768 - '</p>'
1769 - )
1860 + // Hide backup font family on change
1861 + if ($backup_font_family_block.length) {
1862 + $backup_font_family_block.addClass('hidden')
1863 + }
1770 1864
1771 - if (!$link.find('.spf-error').length) {
1772 - $link.append(error_icon)
1773 - }
1865 + var $selected = $font_family_select.find(':selected')
1866 + var value = $selected.val()
1867 + var type = $selected.data('type')
1774 1868
1775 - if (!$tab.find('.spf-arrow .spf-error').length) {
1776 - $tab.find('.spf-arrow').append(error_icon)
1777 - }
1869 + if (type && value) {
1870 + // Show backup fonts if font type google or custom
1871 + if (
1872 + (type === 'google' || type === 'custom') &&
1873 + $backup_font_family_block.length
1874 + ) {
1875 + $backup_font_family_block.removeClass('hidden')
1876 + }
1778 1877
1779 - console.log(error_message)
1878 + // Appending font style select options
1879 + if ($font_style_block.length) {
1880 + // set styles for multi and normal style selectors
1881 + var styles = defaultstyles
1780 1882
1781 - $append_errors.append(
1782 - '<div>' + error_icon + ' ' + error_message + '</div>'
1783 - )
1784 - })
1883 + // Custom or gogle font styles
1884 + if (type === 'google' && webfonts[type].fonts[value][0]) {
1885 + styles = webfonts[type].fonts[value][0]
1886 + } else if (type === 'custom' && webfonts[type].fonts[value]) {
1887 + styles = webfonts[type].fonts[value]
1888 + }
1785 1889
1786 - $append_errors.show()
1787 - }
1890 + selected_styles = styles
1788 1891
1789 - $panel.removeClass('spf-saving')
1790 - $buttons.prop('disabled', false).attr('value', $value)
1791 - flooding = false
1792 - })
1793 - .fail(function (response) {
1794 - alert(response.error)
1795 - })
1796 - }
1797 - }
1892 + // Set selected style value for avoid load errors
1893 + var set_auto_style =
1894 + styles.indexOf('normal') !== -1 ? 'normal' : styles[0]
1895 + var set_style_value =
1896 + first_style_value && styles.indexOf(first_style_value) !== -1
1897 + ? first_style_value
1898 + : set_auto_style
1798 1899
1799 - flooding = true
1800 - })
1801 - })
1802 - }
1900 + // Append style select options
1901 + base.append_select_options(
1902 + $font_style_select,
1903 + styles,
1904 + set_style_value,
1905 + 'style'
1906 + )
1803 1907
1804 - //
1805 - // WP Color Picker
1806 - //
1807 - if (typeof Color === 'function') {
1808 - Color.fn.toString = function () {
1809 - if (this._alpha < 1) {
1810 - return this.toCSS('rgba', this._alpha).replace(/\s+/g, '')
1811 - }
1908 + // Clear first value
1909 + first_style_value = false
1812 1910
1813 - var hex = parseInt(this._color, 10).toString(16)
1911 + // Show style select after appended
1912 + $font_style_block.removeClass('hidden')
1814 1913
1815 - if (this.error) {
1816 - return ''
1817 - }
1914 + // Appending extra font style select options
1915 + if (
1916 + type === 'google' &&
1917 + $extra_font_style_block.length &&
1918 + styles.length > 1
1919 + ) {
1920 + // Append extra-style select options
1921 + base.append_select_options(
1922 + $extra_font_style_select,
1923 + styles,
1924 + first_extra_style_value,
1925 + 'style',
1926 + true
1927 + )
1818 1928
1819 - if (hex.length < 6) {
1820 - for (var i = 6 - hex.length - 1; i >= 0; i--) {
1821 - hex = '0' + hex
1822 - }
1823 - }
1929 + // Clear first value
1930 + first_extra_style_value = false
1824 1931
1825 - return '#' + hex
1826 - }
1827 - }
1932 + // Show style select after appended
1933 + $extra_font_style_block.removeClass('hidden')
1934 + }
1935 + }
1828 1936
1829 - SP_PC.funcs.parse_color = function (color) {
1830 - var value = color.replace(/\s+/g, ''),
1831 - trans =
1832 - value.indexOf('rgba') !== -1
1833 - ? parseFloat(value.replace(/^.*,(.+)\)/, '$1') * 100)
1834 - : 100,
1835 - rgba = trans < 100 ? true : false
1937 + // Appending google fonts subsets select options
1938 + if (
1939 + type === 'google' &&
1940 + $subset_block.length &&
1941 + webfonts[type].fonts[value][1]
1942 + ) {
1943 + var subsets = webfonts[type].fonts[value][1]
1944 + var set_auto_subset =
1945 + subsets.length < 2 && subsets[0] !== 'latin' ? subsets[0] : ''
1946 + var set_subset_value =
1947 + first_subset_select_value &&
1948 + subsets.indexOf(first_subset_select_value) !== -1
1949 + ? first_subset_select_value
1950 + : set_auto_subset
1836 1951
1837 - return { value: value, transparent: trans, rgba: rgba }
1838 - }
1952 + // check for multiple subset select
1953 + set_subset_value =
1954 + subset_multi_select && first_subset_select_value
1955 + ? first_subset_select_value
1956 + : set_subset_value
1839 1957
1840 - $.fn.spf_color = function () {
1841 - return this.each(function () {
1842 - var $input = $(this),
1843 - picker_color = SP_PC.funcs.parse_color($input.val()),
1844 - palette_color = window.spf_vars.color_palette.length
1845 - ? window.spf_vars.color_palette
1846 - : true,
1847 - $container
1958 + base.append_select_options(
1959 + $subset_select,
1960 + subsets,
1961 + set_subset_value,
1962 + 'subset',
1963 + subset_multi_select
1964 + )
1848 1965
1849 - // Destroy and Re-init.
1850 - if ($input.hasClass('wp-color-picker')) {
1851 - $input
1852 - .closest('.wp-picker-container')
1853 - .after($input)
1854 - .remove()
1855 - }
1966 + first_subset_select_value = false
1856 1967
1857 - $input.wpColorPicker({
1858 - palettes: palette_color,
1859 - change: function (event, ui) {
1860 - var ui_color_value = ui.color.toString()
1968 + $subset_block.removeClass('hidden')
1969 + }
1970 + } else {
1971 + // Clear Styles
1972 + $styles.find(':input').val('')
1861 1973
1862 - $container.removeClass('spf--transparent-active')
1863 - $container
1864 - .find('.spf--transparent-offset')
1865 - .css('background-color', ui_color_value)
1866 - $input.val(ui_color_value).trigger('change')
1867 - },
1868 - create: function () {
1869 - $container = $input.closest('.wp-picker-container')
1974 + // Clear subsets options if type and value empty
1975 + if ($subset_block.length) {
1976 + $subset_select
1977 + .find('option')
1978 + .not(':first-child')
1979 + .remove()
1980 + $subset_select.trigger('chosen:updated')
1981 + }
1870 1982
1871 - var a8cIris = $input.data('a8cIris'),
1872 - $transparent_wrap = $(
1873 - '<div class="spf--transparent-wrap">' +
1874 - '<div class="spf--transparent-slider"></div>' +
1875 - '<div class="spf--transparent-offset"></div>' +
1876 - '<div class="spf--transparent-text"></div>' +
1877 - '<div class="spf--transparent-button">transparent <i class="fa fa-toggle-off"></i></div>' +
1878 - '</div>'
1879 - ).appendTo($container.find('.wp-picker-holder')),
1880 - $transparent_slider = $transparent_wrap.find(
1881 - '.spf--transparent-slider'
1882 - ),
1883 - $transparent_text = $transparent_wrap.find(
1884 - '.spf--transparent-text'
1885 - ),
1886 - $transparent_offset = $transparent_wrap.find(
1887 - '.spf--transparent-offset'
1888 - ),
1889 - $transparent_button = $transparent_wrap.find(
1890 - '.spf--transparent-button'
1891 - )
1983 + // Clear font styles options if type and value empty
1984 + if ($font_style_block.length) {
1985 + $font_style_select
1986 + .find('option')
1987 + .not(':first-child')
1988 + .remove()
1989 + $font_style_select.trigger('chosen:updated')
1990 + }
1991 + }
1892 1992
1893 - if ($input.val() === 'transparent') {
1894 - $container.addClass('spf--transparent-active')
1895 - }
1993 + // Update font type input value
1994 + $type.val(type)
1995 + })
1996 + .trigger('spf.change')
1896 1997
1897 - $transparent_button.on('click', function () {
1898 - if ($input.val() !== 'transparent') {
1899 - $input
1900 - .val('transparent')
1901 - .trigger('change')
1902 - .removeClass('iris-error')
1903 - $container.addClass('spf--transparent-active')
1904 - } else {
1905 - $input.val(a8cIris._color.toString()).trigger('change')
1906 - $container.removeClass('spf--transparent-active')
1907 - }
1908 - })
1998 + //
1999 + //
2000 + // Preview
2001 + var $preview_block = $this.find('.spf--block-preview')
1909 2002
1910 - $transparent_slider.slider({
1911 - value: picker_color.transparent,
1912 - step: 1,
1913 - min: 0,
1914 - max: 100,
1915 - slide: function (event, ui) {
1916 - var slide_value = parseFloat(ui.value / 100)
1917 - a8cIris._color._alpha = slide_value
1918 - $input.wpColorPicker('color', a8cIris._color.toString())
1919 - $transparent_text.text(
1920 - slide_value === 1 || slide_value === 0 ? '' : slide_value
1921 - )
1922 - },
1923 - create: function () {
1924 - var slide_value = parseFloat(picker_color.transparent / 100),
1925 - text_value = slide_value < 1 ? slide_value : ''
2003 + if ($preview_block.length) {
2004 + var $preview = $this.find('.spf--preview')
1926 2005
1927 - $transparent_text.text(text_value)
1928 - $transparent_offset.css('background-color', picker_color.value)
2006 + // Set preview styles on change
2007 + $this.on(
2008 + 'change',
2009 + SP_PC.helper.debounce(function (event) {
2010 + $preview_block.removeClass('hidden')
1929 2011
1930 - $container.on('click', '.wp-picker-clear', function () {
1931 - a8cIris._color._alpha = 1
1932 - $transparent_text.text('')
1933 - $transparent_slider.slider('option', 'value', 100)
1934 - $container.removeClass('spf--transparent-active')
1935 - $input.trigger('change')
1936 - })
2012 + var font_family = $font_family_select.val(),
2013 + font_weight = $this.find('.spf--font-weight').val(),
2014 + font_style = $this.find('.spf--font-style').val(),
2015 + font_size = $this.find('.spf--font-size').val(),
2016 + font_variant = $this.find('.spf--font-variant').val(),
2017 + line_height = $this.find('.spf--line-height').val(),
2018 + text_align = $this.find('.spf--text-align').val(),
2019 + text_transform = $this.find('.spf--text-transform').val(),
2020 + text_decoration = $this.find('.spf--text-decoration').val(),
2021 + text_color = $this.find('.spf--color').val(),
2022 + word_spacing = $this.find('.spf--word-spacing').val(),
2023 + letter_spacing = $this.find('.spf--letter-spacing').val(),
2024 + custom_style = $this.find('.spf--custom-style').val(),
2025 + type = $this.find('.spf--type').val()
1937 2026
1938 - $container.on('click', '.wp-picker-default', function () {
1939 - var default_color = SP_PC.funcs.parse_color(
1940 - $input.data('default-color')
1941 - ),
1942 - default_value = parseFloat(default_color.transparent / 100),
1943 - default_text = default_value < 1 ? default_value : ''
2027 + if (type === 'google') {
2028 + base.load_google_font(font_family, font_weight, font_style)
2029 + }
1944 2030
1945 - a8cIris._color._alpha = default_value
1946 - $transparent_text.text(default_text)
1947 - $transparent_slider.slider(
1948 - 'option',
1949 - 'value',
1950 - default_color.transparent
1951 - )
1952 - })
1953 - }
1954 - })
1955 - }
1956 - })
1957 - })
1958 - }
2031 + var properties = {}
1959 2032
1960 - //
1961 - // Number (only allow numeric inputs)
1962 - //
1963 - $.fn.spf_number = function () {
1964 - return this.each(function () {
1965 - $(this).on('keypress', function (e) {
1966 - if (
1967 - e.keyCode !== 0 &&
1968 - e.keyCode !== 8 &&
1969 - e.keyCode !== 45 &&
1970 - e.keyCode !== 46 &&
1971 - (e.keyCode < 48 || e.keyCode > 57)
1972 - ) {
1973 - return false
1974 - }
1975 - })
1976 - })
1977 - }
2033 + if (font_family) {
2034 + properties.fontFamily = font_family
2035 + }
2036 + if (font_weight) {
2037 + properties.fontWeight = font_weight
2038 + }
2039 + if (font_style) {
2040 + properties.fontStyle = font_style
2041 + }
2042 + if (font_variant) {
2043 + properties.fontVariant = font_variant
2044 + }
2045 + if (font_size) {
2046 + properties.fontSize = font_size + unit
2047 + }
2048 + if (line_height) {
2049 + properties.lineHeight = line_height + unit
2050 + }
2051 + if (letter_spacing) {
2052 + properties.letterSpacing = letter_spacing + unit
2053 + }
2054 + if (word_spacing) {
2055 + properties.wordSpacing = word_spacing + unit
2056 + }
2057 + if (text_align) {
2058 + properties.textAlign = text_align
2059 + }
2060 + if (text_transform) {
2061 + properties.textTransform = text_transform
2062 + }
2063 + if (text_decoration) {
2064 + properties.textDecoration = text_decoration
2065 + }
2066 + if (text_color) {
2067 + properties.color = text_color
2068 + }
1978 2069
1979 - //
1980 - // ChosenJS
1981 - //
1982 - $.fn.spf_chosen = function () {
1983 - return this.each(function () {
1984 - var $this = $(this),
1985 - $inited = $this.parent().find('.chosen-container'),
1986 - is_sortable = $this.hasClass('spf-chosen-sortable') || false,
1987 - is_ajax = $this.hasClass('spf-chosen-ajax') || false,
1988 - is_multiple = $this.attr('multiple') || false,
1989 - set_width = is_multiple ? 'auto' : 'auto',
1990 - set_options = $.extend(
1991 - {
1992 - allow_single_deselect: true,
1993 - disable_search_threshold: 10,
1994 - width: set_width,
1995 - no_results_text: window.spf_vars.i18n.no_results_text
1996 - },
1997 - $this.data('chosen-settings')
1998 - )
2070 + $preview.removeAttr('style')
1999 2071
2000 - if ($inited.length) {
2001 - $inited.remove()
2002 - }
2072 + // Customs style attribute
2073 + if (custom_style) {
2074 + $preview.attr('style', custom_style)
2075 + }
2003 2076
2004 - // Chosen ajax
2005 - if (is_ajax) {
2006 - var set_ajax_options = $.extend(
2007 - {
2008 - data: {
2009 - type: 'post',
2010 - nonce: ''
2011 - },
2012 - allow_single_deselect: true,
2013 - disable_search_threshold: -1,
2014 - width: '100%',
2015 - min_length: 3,
2016 - type_delay: 500,
2017 - typing_text: window.spf_vars.i18n.typing_text,
2018 - searching_text: window.spf_vars.i18n.searching_text,
2019 - no_results_text: window.spf_vars.i18n.no_results_text
2020 - },
2021 - $this.data('chosen-settings')
2022 - )
2077 + $preview.css(properties)
2078 + }, 100)
2079 + )
2023 2080
2024 - $this.SP_PCAjaxChosen(set_ajax_options)
2025 - } else {
2026 - $this.chosen(set_options)
2027 - }
2081 + // Preview black and white backgrounds trigger
2082 + $preview_block.on('click', function () {
2083 + $preview.toggleClass('spf--black-background')
2028 2084
2029 - // Chosen keep options order
2030 - if (is_multiple) {
2031 - var $hidden_select = $this.parent().find('.spf-hidden-select')
2032 - var $hidden_value = $hidden_select.val() || []
2085 + var $toggle = $preview_block.find('.spf--toggle')
2033 2086
2034 - $this.on('change', function (obj, result) {
2035 - if (result && result.selected) {
2036 - $hidden_select.append(
2037 - '<option value="' +
2038 - result.selected +
2039 - '" selected="selected">' +
2040 - result.selected +
2041 - '</option>'
2042 - )
2043 - } else if (result && result.deselected) {
2044 - $hidden_select
2045 - .find('option[value="' + result.deselected + '"]')
2046 - .remove()
2047 - }
2087 + if ($toggle.hasClass('fa-toggle-off')) {
2088 + $toggle.removeClass('fa-toggle-off').addClass('fa-toggle-on')
2089 + } else {
2090 + $toggle.removeClass('fa-toggle-on').addClass('fa-toggle-off')
2091 + }
2092 + })
2048 2093
2049 - // Force customize refresh
2050 - if (
2051 - $hidden_select.children().length === 0 &&
2052 - window.wp.customize !== undefined
2053 - ) {
2054 - window.wp.customize
2055 - .control($hidden_select.data('customize-setting-link'))
2056 - .setting.set('')
2057 - }
2094 + if (!$preview_block.hasClass('hidden')) {
2095 + $this.trigger('change')
2096 + }
2097 + }
2098 + }
2058 2099
2059 - $hidden_select.trigger('change')
2060 - })
2100 + base.init()
2101 + })
2102 + }
2061 2103
2062 - // Chosen order abstract
2063 - $this.SP_PCChosenOrder($hidden_value, true)
2064 - }
2104 + //
2105 + // Field: upload
2106 + //
2107 + $.fn.spf_field_upload = function () {
2108 + return this.each(function () {
2109 + var $this = $(this),
2110 + $input = $this.find('input'),
2111 + $upload_button = $this.find('.spf--button'),
2112 + $remove_button = $this.find('.spf--remove'),
2113 + $library =
2114 + ($upload_button.data('library') &&
2115 + $upload_button.data('library').split(',')) ||
2116 + '',
2117 + wp_media_frame
2065 2118
2066 - // Chosen sortable
2067 - if (is_sortable) {
2068 - var $chosen_container = $this.parent().find('.chosen-container')
2069 - var $chosen_choices = $chosen_container.find('.chosen-choices')
2119 + $input.on('change', function (e) {
2120 + if ($input.val()) {
2121 + $remove_button.removeClass('hidden')
2122 + } else {
2123 + $remove_button.addClass('hidden')
2124 + }
2125 + })
2070 2126
2071 - $chosen_choices.bind('mousedown', function (event) {
2072 - if ($(event.target).is('span')) {
2073 - event.stopPropagation()
2074 - }
2075 - })
2127 + $upload_button.on('click', function (e) {
2128 + e.preventDefault()
2076 2129
2077 - $chosen_choices.sortable({
2078 - items: 'li:not(.search-field)',
2079 - helper: 'orginal',
2080 - cursor: 'move',
2081 - placeholder: 'search-choice-placeholder',
2082 - start: function (e, ui) {
2083 - ui.placeholder.width(ui.item.innerWidth())
2084 - ui.placeholder.height(ui.item.innerHeight())
2085 - },
2086 - update: function (e, ui) {
2087 - var select_options = ''
2088 - var chosen_object = $this.data('chosen')
2089 - var $prev_select = $this.parent().find('.spf-hidden-select')
2130 + if (
2131 + typeof window.wp === 'undefined' ||
2132 + !window.wp.media ||
2133 + !window.wp.media.gallery
2134 + ) {
2135 + return
2136 + }
2090 2137
2091 - $chosen_choices.find('.search-choice-close').each(function () {
2092 - var option_array_index = $(this).data('option-array-index')
2093 - $.each(chosen_object.results_data, function (index, data) {
2094 - if (data.array_index === option_array_index) {
2095 - select_options +=
2096 - '<option value="' +
2097 - data.value +
2098 - '" selected>' +
2099 - data.value +
2100 - '</option>'
2101 - }
2102 - })
2103 - })
2138 + if (wp_media_frame) {
2139 + wp_media_frame.open()
2140 + return
2141 + }
2104 2142
2105 - $prev_select.children().remove()
2106 - $prev_select.append(select_options)
2107 - $prev_select.trigger('change')
2108 - }
2109 - })
2110 - }
2111 - })
2112 - }
2143 + wp_media_frame = window.wp.media({
2144 + library: {
2145 + type: $library
2146 + }
2147 + })
2113 2148
2114 - //
2115 - // Helper Checkbox Checker
2116 - //
2117 - $.fn.spf_checkbox = function () {
2118 - return this.each(function () {
2119 - var $this = $(this),
2120 - $input = $this.find('.spf--input'),
2121 - $checkbox = $this.find('.spf--checkbox')
2149 + // wp_media_frame.on( 'select', function() {
2150 + // $input.val( wp_media_frame.state().get('selection').first().attributes.url ).trigger('change');
2151 + // });
2152 + wp_media_frame.on('select', function () {
2153 + var attributes = wp_media_frame
2154 + .state()
2155 + .get('selection')
2156 + .first().attributes
2122 2157
2123 - $checkbox.on('click', function () {
2124 - $input.val(Number($checkbox.prop('checked'))).trigger('change')
2125 - })
2126 - })
2127 - }
2158 + if (
2159 + $library.length &&
2160 + $library.indexOf(attributes.subtype) === -1 &&
2161 + $library.indexOf(attributes.type) === -1
2162 + ) {
2163 + return
2164 + }
2128 2165
2129 - //
2130 - // Siblings
2131 - //
2132 - $.fn.spf_siblings = function () {
2133 - return this.each(function () {
2134 - var $this = $(this),
2135 - $siblings = $this.find('.spf--sibling'),
2136 - multiple = $this.data('multiple') || false
2166 + $input.val(attributes.url).trigger('change')
2167 + })
2137 2168
2138 - $siblings.on('click', function () {
2139 - var $sibling = $(this)
2169 + wp_media_frame.open()
2170 + })
2140 2171
2141 - if (multiple) {
2142 - if ($sibling.hasClass('spf--active')) {
2143 - $sibling.removeClass('spf--active')
2144 - $sibling
2145 - .find('input')
2146 - .prop('checked', false)
2147 - .trigger('change')
2148 - } else {
2149 - $sibling.addClass('spf--active')
2150 - $sibling
2151 - .find('input')
2152 - .prop('checked', true)
2153 - .trigger('change')
2154 - }
2155 - } else {
2156 - $this.find('input').prop('checked', false)
2157 - $sibling
2158 - .find('input')
2159 - .prop('checked', true)
2160 - .trigger('change')
2161 - $sibling
2162 - .addClass('spf--active')
2163 - .siblings()
2164 - .removeClass('spf--active')
2165 - }
2166 - })
2167 - })
2168 - }
2172 + $remove_button.on('click', function (e) {
2173 + e.preventDefault()
2174 + $input.val('').trigger('change')
2175 + })
2176 + })
2177 + }
2169 2178
2170 - //
2171 - // Help Tooltip
2172 - //
2173 - $.fn.spf_help = function () {
2174 - return this.each(function () {
2175 - var $this = $(this),
2176 - $tooltip,
2177 - offset_left
2179 + //
2180 + // Field: wp_editor
2181 + //
2182 + $.fn.spf_field_wp_editor = function () {
2183 + return this.each(function () {
2184 + if (
2185 + typeof window.wp.editor === 'undefined' ||
2186 + typeof window.tinyMCEPreInit === 'undefined' ||
2187 + typeof window.tinyMCEPreInit.mceInit.spf_wp_editor === 'undefined'
2188 + ) {
2189 + return
2190 + }
2178 2191
2179 - $this.on({
2180 - mouseenter: function () {
2181 - $tooltip = $('<div class="spf-tooltip"></div>')
2182 - .html($this.find('.spf-help-text').html())
2183 - .appendTo('body')
2184 - offset_left = SP_PC.vars.is_rtl
2185 - ? $this.offset().left - $tooltip.outerWidth()
2186 - : $this.offset().left + 24
2192 + var $this = $(this),
2193 + $editor = $this.find('.spf-wp-editor'),
2194 + $textarea = $this.find('textarea')
2187 2195
2188 - $tooltip.css({
2189 - top: $this.offset().top - ($tooltip.outerHeight() / 2 - 14),
2190 - left: offset_left
2191 - })
2192 - },
2193 - mouseleave: function () {
2194 - if ($tooltip !== undefined) {
2195 - $tooltip.remove()
2196 - }
2197 - }
2198 - })
2199 - })
2200 - }
2196 + // If there is wp-editor remove it for avoid dupliated wp-editor conflicts.
2197 + var $has_wp_editor =
2198 + $this.find('.wp-editor-wrap').length ||
2199 + $this.find('.mce-container').length
2201 2200
2202 - //
2203 - // Window on resize
2204 - //
2205 - SP_PC.vars.$window
2206 - .on(
2207 - 'resize spf.resize',
2208 - SP_PC.helper.debounce(function (event) {
2209 - var window_width =
2210 - navigator.userAgent.indexOf('AppleWebKit/') > -1
2211 - ? SP_PC.vars.$window.width()
2212 - : window.innerWidth
2201 + if ($has_wp_editor) {
2202 + $editor.empty()
2203 + $editor.append($textarea)
2204 + $textarea.css('display', '')
2205 + }
2213 2206
2214 - if (window_width <= 782 && !SP_PC.vars.onloaded) {
2215 - $('.spf-section').spf_reload_script()
2216 - SP_PC.vars.onloaded = true
2217 - }
2218 - }, 200)
2219 - )
2220 - .trigger('spf.resize')
2207 + // Generate a unique id
2208 + var uid = SP_PC.helper.uid('spf-editor-')
2221 2209
2222 - //
2223 - // Widgets Framework
2224 - //
2225 - $.fn.spf_widgets = function () {
2226 - if (this.length) {
2227 - $(document).on('widget-added widget-updated', function (event, $widget) {
2228 - $widget.find('.spf-fields').spf_reload_script()
2229 - })
2210 + $textarea.attr('id', uid)
2230 2211
2231 - $('.widgets-sortables, .control-section-sidebar').on(
2232 - 'sortstop',
2233 - function (event, ui) {
2234 - ui.item.find('.spf-fields').spf_reload_script_retry()
2235 - }
2236 - )
2212 + // Get default editor settings
2213 + var default_editor_settings = {
2214 + tinymce: window.tinyMCEPreInit.mceInit.spf_wp_editor,
2215 + quicktags: window.tinyMCEPreInit.qtInit.spf_wp_editor
2216 + }
2237 2217
2238 - $(document).on('click', '.widget-top', function (event) {
2239 - $(this)
2240 - .parent()
2241 - .find('.spf-fields')
2242 - .spf_reload_script()
2243 - })
2244 - }
2245 - }
2218 + // Get default editor settings
2219 + var field_editor_settings = $editor.data('editor-settings')
2246 2220
2247 - //
2248 - // Retry Plugins
2249 - //
2250 - $.fn.spf_reload_script_retry = function () {
2251 - return this.each(function () {
2252 - var $this = $(this)
2253 - })
2254 - }
2221 + // Add on change event handle
2222 + var editor_on_change = function (editor) {
2223 + editor.on(
2224 + 'change',
2225 + SP_PC.helper.debounce(function () {
2226 + editor.save()
2227 + $textarea.trigger('change')
2228 + }, 250)
2229 + )
2230 + }
2255 2231
2256 - //
2257 - // Reload Plugins
2258 - //
2259 - $.fn.spf_reload_script = function (options) {
2260 - var settings = $.extend(
2261 - {
2262 - dependency: true
2263 - },
2264 - options
2265 - )
2232 + // Callback for old wp editor
2233 + var wpEditor = wp.oldEditor ? wp.oldEditor : wp.editor
2266 2234
2267 - return this.each(function () {
2268 - var $this = $(this)
2269 - // Avoid for conflicts
2270 - if (!$this.data('inited')) {
2271 - // Field plugins
2272 - $this.children('.spf-field-accordion').spf_field_accordion()
2273 - $this.children('.spf-field-code_editor').spf_field_code_editor()
2274 - $this.children('.spf-field-fieldset').spf_field_fieldset()
2275 - $this.children('.spf-field-group').spf_field_group()
2276 - $this.children('.spf-field-icon').spf_field_icon()
2277 - $this.children('.spf-field-slider').spf_field_slider()
2278 - $this.children('.spf-field-sortable').spf_field_sortable()
2279 - $this.children('.spf-field-sorter').spf_field_sorter()
2280 - $this.children('.spf-field-spinner').spf_field_spinner()
2281 - $this.children('.spf-field-switcher').spf_field_switcher()
2282 - $this.children('.spf-field-typography').spf_field_typography()
2235 + if (wpEditor && wpEditor.hasOwnProperty('autop')) {
2236 + wp.editor.autop = wpEditor.autop
2237 + wp.editor.removep = wpEditor.removep
2238 + wp.editor.initialize = wpEditor.initialize
2239 + }
2283 2240
2284 - // Field colors
2285 - $this
2286 - .children('.spf-field-border')
2287 - .find('.spf-color')
2288 - .spf_color()
2289 - $this
2290 - .children('.spf-field-background')
2291 - .find('.spf-color')
2292 - .spf_color()
2293 - $this
2294 - .children('.spf-field-color')
2295 - .find('.spf-color')
2296 - .spf_color()
2297 - $this
2298 - .children('.spf-field-color_group')
2299 - .find('.spf-color')
2300 - .spf_color()
2301 - $this
2302 - .children('.spf-field-link_color')
2303 - .find('.spf-color')
2304 - .spf_color()
2305 - $this
2306 - .children('.spf-field-typography')
2307 - .find('.spf-color')
2308 - .spf_color()
2241 + // Extend editor selector and on change event handler
2242 + default_editor_settings.tinymce = $.extend(
2243 + {},
2244 + default_editor_settings.tinymce,
2245 + { selector: '#' + uid, setup: editor_on_change }
2246 + )
2309 2247
2310 - // Field chosenjs
2311 - $this
2312 - .children('.spf-field-select')
2313 - .find('.spf-chosen')
2314 - .spf_chosen()
2248 + // Override editor tinymce settings
2249 + if (field_editor_settings.tinymce === false) {
2250 + default_editor_settings.tinymce = false
2251 + $editor.addClass('spf-no-tinymce')
2252 + }
2315 2253
2316 - // Field Checkbox
2317 - $this
2318 - .children('.spf-field-checkbox')
2319 - .find('.spf-checkbox')
2320 - .spf_checkbox()
2254 + // Override editor quicktags settings
2255 + if (field_editor_settings.quicktags === false) {
2256 + default_editor_settings.quicktags = false
2257 + $editor.addClass('spf-no-quicktags')
2258 + }
2321 2259
2322 - // Field Siblings
2323 - $this
2324 - .children('.spf-field-button_set')
2325 - .find('.spf-siblings')
2326 - .spf_siblings()
2327 - $this
2328 - .children('.spf-field-layout_preset')
2329 - .find('.spf-siblings')
2330 - .spf_siblings()
2331 - $this
2332 - .children('.spf-field-palette')
2333 - .find('.spf-siblings')
2334 - .spf_siblings()
2260 + // Wait until :visible
2261 + var interval = setInterval(function () {
2262 + if ($this.is(':visible')) {
2263 + window.wp.editor.initialize(uid, default_editor_settings)
2264 + clearInterval(interval)
2265 + }
2266 + })
2335 2267
2336 - // Help Tooltip
2337 - $this
2338 - .children('.spf-field')
2339 - .find('.spf-help')
2340 - .spf_help()
2268 + // Add Media buttons
2269 + if (field_editor_settings.media_buttons && window.spf_media_buttons) {
2270 + var $editor_buttons = $editor.find('.wp-media-buttons')
2341 2271
2342 - if (settings.dependency) {
2343 - $this.spf_dependency()
2344 - }
2272 + if ($editor_buttons.length) {
2273 + $editor_buttons.find('.spf-shortcode-button').data('editor-id', uid)
2274 + } else {
2275 + var $media_buttons = $(window.spf_media_buttons)
2345 2276
2346 - $this.data('inited', true)
2277 + $media_buttons.find('.spf-shortcode-button').data('editor-id', uid)
2347 2278
2348 - $(document).trigger('spf-reload-script', $this)
2349 - }
2350 - })
2351 - }
2279 + $editor.prepend($media_buttons)
2280 + }
2281 + }
2282 + })
2283 + }
2352 2284
2353 - //
2354 - // Document ready and run scripts.
2355 - //
2356 - $(document).ready(function () {
2357 - $('.spf-save').spf_save()
2358 - $('.spf-confirm').spf_confirm()
2359 - $('.spf-nav-options').spf_nav_options()
2360 - $('.spf-nav-metabox').spf_nav_metabox()
2361 - $('.spf-expand-all').spf_expand_all()
2362 - $('.spf-search').spf_search()
2363 - $('.spf-sticky-header').spf_sticky()
2364 - $('.spf-page-templates').spf_page_templates()
2365 - $('.spf-post-formats').spf_post_formats()
2366 - $('.spf-onload').spf_reload_script()
2367 - $('.widget').spf_widgets()
2368 - })
2285 + //
2286 + // Confirm
2287 + //
2288 + $.fn.spf_confirm = function () {
2289 + return this.each(function () {
2290 + $(this).on('click', function (e) {
2291 + var confirm_text =
2292 + $(this).data('confirm') || window.spf_vars.i18n.confirm
2293 + var confirm_answer = confirm(confirm_text)
2294 + SP_PC.vars.is_confirm = true
2369 2295
2370 - // ======================================================
2371 - // Post
2372 - // ------------------------------------------------------
2373 - // Trigger taxonomy list when post type is selected.
2374 - $('.sp_pcp_post_type select').on('change', function (event) {
2375 - event.preventDefault()
2376 - var data = {
2377 - action: 'sps_get_taxonomies',
2378 - pcp_post_types: $(this).val(),
2379 - nonce: $('#spf_pcp_metabox_noncesp_pcp_view_options').val()
2380 - }
2381 - $.post(ajaxurl, data, function (response) {
2382 - $('.sp_pcp_post_taxonomy select').html(response)
2383 - $('.sp_pcp_post_taxonomy select').trigger('chosen:updated')
2384 - })
2385 - })
2386 - // Update terms list on the change of post taxonomy.
2387 - $(document).on('change', '.sp_pcp_post_taxonomy select', function (e) {
2388 - e.preventDefault();
2389 - var taxSelector = $(this)
2390 - var data = {
2391 - action: 'sps_get_terms', // Callback function.
2392 - pcp_post_taxonomy: $(this).val(),
2393 - nonce: $('#spf_pcp_metabox_noncesp_pcp_view_options').val()
2394 - }
2395 - $.ajax({
2396 - type: "POST",
2397 - url: ajaxurl,
2398 - data: data,
2399 - error: function (response) {
2400 - console.log(response)
2401 - },
2402 - success: function (response) {
2403 - $(taxSelector)
2404 - .parent()
2405 - .parent('.sp_pcp_post_taxonomy')
2406 - .next('.sp_pcp_taxonomy_terms')
2407 - .find('select')
2408 - .html(response)
2409 - $(taxSelector)
2410 - .parent()
2411 - .parent('.sp_pcp_post_taxonomy')
2412 - .next('.sp_pcp_taxonomy_terms')
2413 - .find('select')
2414 - .trigger('chosen:updated')
2415 - }
2416 - })
2417 - })
2296 + if (!confirm_answer) {
2297 + e.preventDefault()
2298 + SP_PC.vars.is_confirm = false
2418 2299
2419 - // Populate specific post list in the drop-down.
2420 - var pt_saved_value = $('.sp_pcp_post_type select').val()
2421 - // Change Include only post_type on change of Post Type field.
2422 - var data_include_only = $('.sp_pcp_include_only_posts .spf-chosen-ajax').data(
2423 - 'chosen-settings'
2424 - )
2425 - // Change Exclude post_type on change of Post Type field.
2426 - var data_exclude = $('.sp_pcp_exclude_posts .spf-chosen-ajax').data(
2427 - 'chosen-settings'
2428 - )
2429 - if ($('.spf-nav').hasClass('spf-nav-metabox')) {
2430 - data_exclude.data.query_args.post_type = pt_saved_value
2431 - data_include_only.data.query_args.post_type = pt_saved_value
2432 - }
2433 - $('.sp_pcp_post_type select').on('change', function (event) {
2434 - event.preventDefault()
2435 - var pt_value = $(this).val()
2436 - // Change Include only post_type on change of Post Type field.
2437 - data_include_only.data.query_args.post_type = pt_value
2438 - // Change Exclude post_type on change of Post Type field.
2439 - data_exclude.data.query_args.post_type = pt_value
2440 - })
2300 + return false
2301 + }
2302 + })
2303 + })
2304 + }
2441 2305
2442 - /* Keep the accordion field's first item opened */
2443 - $(window).on('load', function () {
2444 - $('.pcp-opened-accordion').each(function () {
2445 - if (!$(this).hasClass('hidden')) {
2446 - $(this).addClass('pcp_saved_filter')
2447 - }
2448 - })
2449 - })
2450 - $('.spf-field-checkbox.pcp_advanced_filter').on('change', function (event) {
2451 - $('.pcp-opened-accordion').each(function () {
2452 - if ($(this).hasClass('hidden')) {
2453 - $(this).removeClass('pcp_saved_filter')
2454 - } else {
2455 - $(this).addClass('pcp_saved_filter')
2456 - }
2457 - if (!$(this).hasClass('pcp_saved_filter')) {
2458 - if (
2459 - $(this)
2460 - .find('.spf-accordion-title')
2461 - .siblings('.spf-accordion-content')
2462 - .hasClass('spf-accordion-open')
2463 - ) {
2464 - $(this).find('.spf-accordion-title')
2465 - } else {
2466 - $(this)
2467 - .find('.spf-accordion-title')
2468 - .trigger('click')
2469 - $(this)
2470 - .find('.spf-accordion-content')
2471 - .find('.spf-cloneable-add')
2472 - .trigger('click')
2473 - }
2474 - }
2475 - })
2476 - })
2306 + $.fn.serializeObject = function () {
2307 + var obj = {}
2477 2308
2478 - // Pro only tag.
2479 - $('.pcp-pagination-type li:nth-child(n+2) input').attr('disabled', true)
2480 - $("label:contains((Pro))").css({ 'pointer-events': 'none', 'opacity': '0.8', 'user-select': 'none' })
2481 - $("label:contains((Pro)) input").attr('disabled', true).css('opacity', '1')
2482 - $("select option:contains((Pro))").attr('disabled', true).css('opacity', '1')
2483 - // Image custom size.
2484 - // Post Meta fields 5th to last.
2485 - // Post content type with limit.
2309 + $.each(this.serializeArray(), function (i, o) {
2310 + var n = o.name,
2311 + v = o.value
2486 2312
2487 - $('.post_content_sorter .spf--sortable-item:has(div.pcp-pro-only)').css({ "pointer-events": "none", "borderColor": "#bebebe" });
2488 - $('.post_content_sorter .spf--sortable-item:has(div.pcp-pro-only)').find('h4.spf-accordion-title, .spf--sortable-helper').css({ "backgroundColor": "#f0f0f0", "color": "#777", "marginLeft": "0", "paddingRight": "0" });
2489 - $('.post_content_sorter .spf--sortable-item:has(div.pcp-pro-only)').find('.spf--sortable-helper .fa').css("color", "#777");
2313 + obj[n] =
2314 + obj[n] === undefined
2315 + ? v
2316 + : $.isArray(obj[n])
2317 + ? obj[n].concat(v)
2318 + : [obj[n], v]
2319 + })
2490 2320
2321 + return obj
2322 + }
2491 2323
2324 + //
2325 + // Options Save
2326 + //
2327 + $.fn.spf_save = function () {
2328 + return this.each(function () {
2329 + var $this = $(this),
2330 + $buttons = $('.spf-save'),
2331 + $panel = $('.spf-options'),
2332 + flooding = false,
2333 + timeout
2492 2334
2493 - var preview_box = $('#spsp-preview-box');
2494 - var pcp_display = $('#sp_pcp_display').hide();
2335 + $this.on('click', function (e) {
2336 + if (!flooding) {
2337 + var $text = $this.data('save'),
2338 + $value = $this.val()
2495 2339
2496 - // $('#spsp-show-preview:contains(Hide)').
2497 - $(document).on('click', '#spsp-show-preview:contains(Hide)', function (e) {
2498 - e.preventDefault();
2499 - var _this = $(this);
2500 - _this.html('<i class="fa fa-eye" aria-hidden="true"></i> Show Preview');
2501 - preview_box.html('');
2502 - pcp_display.hide();
2503 - });
2504 - $(document).on('click', '#spsp-show-preview:not(:contains(Hide))', function (e) {
2505 - e.preventDefault();
2506 - var previewJS = window.spf_vars.previewJS;
2507 - var _data = $('form#post').serialize();
2508 - var _this = $(this);
2509 - var $sp_id = $(this).data('id');
2510 - var data = {
2511 - action: 'spf_preview_meta_box',
2512 - id: $sp_id,
2513 - data: _data,
2514 - nonce: $('#spf_pcp_metabox_noncesp_pcp_view_options').val()
2515 - };
2516 - $.ajax({
2517 - type: "POST",
2518 - url: ajaxurl,
2519 - data: data,
2520 - error: function (response) {
2521 - console.log(response)
2522 - },
2523 - success: function (response) {
2524 - pcp_display.show();
2525 - preview_box.html(response);
2526 - $.getScript(previewJS, function () {
2527 - _this.html('<i class="fa fa-eye-slash" aria-hidden="true"></i> Hide Preview');
2528 - $(document).on('change', '#sp_pcp_view_options', function (e) {
2529 - e.preventDefault();
2530 - _this.html('<i class="fa fa-refresh" aria-hidden="true"></i> Update Preview');
2531 - });
2532 - $(document).on('change', '#spf-section-sp_pcp_layouts_1', function (e) {
2533 - e.preventDefault();
2534 - _this.html('<i class="fa fa-refresh" aria-hidden="true"></i> Update Preview');
2535 - });
2536 - $("html, body").animate({ scrollTop: pcp_display.offset().top - 50 }, "slow");
2537 - })
2538 - }
2539 - })
2540 - });
2340 + $buttons.attr('value', $text)
2541 2341
2542 - function isValidJSONString(str) {
2543 - try {
2544 - JSON.parse(str);
2545 - } catch (e) {
2546 - return false;
2547 - }
2548 - return true;
2549 - }
2550 - // Smart-post-show export.
2551 - var $export_type = $('.pcp_what_export').find('input:checked').val();
2552 - $('.pcp_what_export').on('change', function () {
2553 - $export_type = $(this).find('input:checked').val();
2554 - });
2342 + if ($this.hasClass('spf-save-ajax')) {
2343 + e.preventDefault()
2555 2344
2556 - $('.pcp_export .spf--button').on('click', function (event) {
2557 - event.preventDefault();
2345 + $panel.addClass('spf-saving')
2346 + $buttons.prop('disabled', true)
2558 2347
2559 - var $shortcode_ids = $('.pcp_post_ids select').val();
2560 - var $ex_nonce = $('#spf_options_noncesp_post_carousel_tools').val();
2561 - var selected_shortcode = $export_type === 'selected_shortcodes' ? $shortcode_ids : 'all_shortcodes';
2562 - if ($export_type === 'all_shortcodes' || $export_type === 'selected_shortcodes') {
2563 - var data = {
2564 - action: 'pcp_export_shortcodes',
2565 - pcp_ids: selected_shortcode,
2566 - nonce: $ex_nonce,
2567 - }
2568 - } else {
2569 - $('.spf-form-result.spf-form-success').text('No carousel selected.').show();
2570 - setTimeout(function () {
2571 - $('.spf-form-result.spf-form-success').hide().text('');
2572 - }, 3000);
2573 - }
2574 - $.post(ajaxurl, data, function (resp) {
2575 - if (resp) {
2576 - // Convert JSON Array to string.
2577 - if (isValidJSONString(resp)) {
2578 - var json = JSON.stringify(JSON.parse(resp));
2579 - } else {
2580 - var json = JSON.stringify(resp);
2581 - }
2582 - // Convert JSON string to BLOB.
2583 - var blob = new Blob([json], { type: 'application/json' });
2584 - var link = document.createElement('a');
2585 - var pcp_time = $.now();
2586 - link.href = window.URL.createObjectURL(blob);
2587 - link.download = "smart-post-show-" + pcp_time + ".json";
2588 - link.click();
2589 - $('.spf-form-result.spf-form-success').text('Exported successfully!').show();
2590 - setTimeout(function () {
2591 - $('.spf-form-result.spf-form-success').hide().text('');
2592 - $('.pcp_post_ids select').val('').trigger('chosen:updated');
2593 - }, 3000);
2594 - }
2595 - });
2596 - });
2597 - // smart-post-show import.
2598 - $('.pcp_import button.import').on('click',function (event) {
2599 - event.preventDefault();
2600 - var $this = $(this),
2601 - this_text = $this.text(),
2602 - pcp_shortcodes = $('#import').prop('files')[0];
2603 - if ($('#import').val() != '') {
2604 - $this.prop('disabled',true).css( 'opacity', '0.7' );
2605 - var $im_nonce = $('#spf_options_noncesp_post_carousel_tools').val();
2606 - var reader = new FileReader();
2607 - reader.readAsText(pcp_shortcodes);
2608 - reader.onload = function (event) {
2609 - var jsonObj = JSON.stringify(event.target.result);
2610 - $.ajax({
2611 - url: ajaxurl,
2612 - type: 'POST',
2613 - data: {
2614 - shortcode: jsonObj,
2615 - action: 'pcp_import_shortcodes',
2616 - nonce: $im_nonce,
2617 - },
2618 - success: function (resp) {
2619 - $('.spf-form-result.spf-form-success').text('Imported successfully!').show();
2620 - setTimeout(function () {
2621 - $('.spf-form-result.spf-form-success').hide().text('');
2622 - $('#import').val('');
2623 - $this.prop('disabled',false).css( 'opacity', '1' );
2624 - window.location.replace($('#pcp_shortcode_link_redirect').attr('href'));
2625 - }, 2000);
2626 - },
2627 - error: function(error){
2628 - $('#import').val('');
2629 - $this.prop('disabled',false).css( 'opacity', '1' );
2630 - }
2631 - });
2632 - }
2633 - } else {
2634 - $('.spf-form-result.spf-form-success').text('No exported json file chosen.').show();
2635 - setTimeout(function () {
2636 - $('.spf-form-result.spf-form-success').hide().text('');
2637 - }, 3000);
2638 - }
2639 - });
2348 + window.wp.ajax
2349 + .post('spf_' + $panel.data('unique') + '_ajax_save', {
2350 + data: $('#spf-form').serializeJSONSP_PC()
2351 + })
2352 + .done(function (response) {
2353 + clearTimeout(timeout)
2640 2354
2641 - $(document).on('keyup change', '.sp_post_carousel_page_pcp_settings #spf-form', function (e) {
2642 - e.preventDefault();
2643 - var $button = $(this).find('.spf-save');
2644 - $button.css({ "background-color": "#00C263", "pointer-events": "initial" }).val('Save Settings');
2645 - });
2646 - $('.sp_post_carousel_page_pcp_settings .spf-save').on('click', function (e) {
2647 - e.preventDefault();
2648 - $(this).css({ "background-color": "#C5C5C6", "pointer-events": "none" }).val('Changes Saved');
2649 - })
2355 + var $result_success = $('.spf-form-success')
2356 +
2357 + $result_success
2358 + .empty()
2359 + .append(response.notice)
2360 + .slideDown('fast', function () {
2361 + timeout = setTimeout(function () {
2362 + $result_success.slideUp('fast')
2363 + }, 2000)
2364 + })
2365 +
2366 + // clear errors
2367 + $('.spf-error').remove()
2368 +
2369 + var $append_errors = $('.spf-form-error')
2370 +
2371 + $append_errors.empty().hide()
2372 +
2373 + if (Object.keys(response.errors).length) {
2374 + var error_icon = '<i class="spf-label-error spf-error">!</i>'
2375 +
2376 + $.each(response.errors, function (key, error_message) {
2377 + var $field = $('[data-depend-id="' + key + '"]'),
2378 + $link = $(
2379 + '#spf-tab-link-' +
2380 + ($field.closest('.spf-section').index() + 1)
2381 + ),
2382 + $tab = $link.closest('.spf-tab-depth-0')
2383 +
2384 + $field
2385 + .closest('.spf-fieldset')
2386 + .append(
2387 + '<p class="spf-text-error spf-error">' +
2388 + error_message +
2389 + '</p>'
2390 + )
2391 +
2392 + if (!$link.find('.spf-error').length) {
2393 + $link.append(error_icon)
2394 + }
2395 +
2396 + if (!$tab.find('.spf-arrow .spf-error').length) {
2397 + $tab.find('.spf-arrow').append(error_icon)
2398 + }
2399 +
2400 + console.log(error_message)
2401 +
2402 + $append_errors.append(
2403 + '<div>' + error_icon + ' ' + error_message + '</div>'
2404 + )
2405 + })
2406 +
2407 + $append_errors.show()
2408 + }
2409 +
2410 + $panel.removeClass('spf-saving')
2411 + $buttons.prop('disabled', false).attr('value', $value)
2412 + flooding = false
2413 + })
2414 + .fail(function (response) {
2415 + alert(response.error)
2416 + })
2417 + }
2418 + }
2419 +
2420 + flooding = true
2421 + })
2422 + })
2423 + }
2424 +
2425 + //
2426 + // WP Color Picker
2427 + //
2428 + if (typeof Color === 'function') {
2429 + Color.fn.toString = function () {
2430 + if (this._alpha < 1) {
2431 + return this.toCSS('rgba', this._alpha).replace(/\s+/g, '')
2432 + }
2433 +
2434 + var hex = parseInt(this._color, 10).toString(16)
2435 +
2436 + if (this.error) {
2437 + return ''
2438 + }
2439 +
2440 + if (hex.length < 6) {
2441 + for (var i = 6 - hex.length - 1; i >= 0; i--) {
2442 + hex = '0' + hex
2443 + }
2444 + }
2445 +
2446 + return '#' + hex
2447 + }
2448 + }
2449 +
2450 + SP_PC.funcs.parse_color = function (color) {
2451 + var value = color.replace(/\s+/g, ''),
2452 + trans =
2453 + value.indexOf('rgba') !== -1
2454 + ? parseFloat(value.replace(/^.*,(.+)\)/, '$1') * 100)
2455 + : 100,
2456 + rgba = trans < 100 ? true : false
2457 +
2458 + return { value: value, transparent: trans, rgba: rgba }
2459 + }
2460 +
2461 + $.fn.spf_color = function () {
2462 + return this.each(function () {
2463 + var $input = $(this),
2464 + picker_color = SP_PC.funcs.parse_color($input.val()),
2465 + palette_color = window.spf_vars.color_palette.length
2466 + ? window.spf_vars.color_palette
2467 + : true,
2468 + $container
2469 +
2470 + // Destroy and Re-init.
2471 + if ($input.hasClass('wp-color-picker')) {
2472 + $input
2473 + .closest('.wp-picker-container')
2474 + .after($input)
2475 + .remove()
2476 + }
2477 +
2478 + $input.wpColorPicker({
2479 + palettes: palette_color,
2480 + change: function (event, ui) {
2481 + var ui_color_value = ui.color.toString()
2482 +
2483 + $container.removeClass('spf--transparent-active')
2484 + $container
2485 + .find('.spf--transparent-offset')
2486 + .css('background-color', ui_color_value)
2487 + $input.val(ui_color_value).trigger('change')
2488 + },
2489 + create: function () {
2490 + $container = $input.closest('.wp-picker-container')
2491 +
2492 + var a8cIris = $input.data('a8cIris'),
2493 + $transparent_wrap = $(
2494 + '<div class="spf--transparent-wrap">' +
2495 + '<div class="spf--transparent-slider"></div>' +
2496 + '<div class="spf--transparent-offset"></div>' +
2497 + '<div class="spf--transparent-text"></div>' +
2498 + '<div class="spf--transparent-button">transparent <i class="fa fa-toggle-off"></i></div>' +
2499 + '</div>'
2500 + ).appendTo($container.find('.wp-picker-holder')),
2501 + $transparent_slider = $transparent_wrap.find(
2502 + '.spf--transparent-slider'
2503 + ),
2504 + $transparent_text = $transparent_wrap.find(
2505 + '.spf--transparent-text'
2506 + ),
2507 + $transparent_offset = $transparent_wrap.find(
2508 + '.spf--transparent-offset'
2509 + ),
2510 + $transparent_button = $transparent_wrap.find(
2511 + '.spf--transparent-button'
2512 + )
2513 +
2514 + if ($input.val() === 'transparent') {
2515 + $container.addClass('spf--transparent-active')
2516 + }
2517 +
2518 + $transparent_button.on('click', function () {
2519 + if ($input.val() !== 'transparent') {
2520 + $input
2521 + .val('transparent')
2522 + .trigger('change')
2523 + .removeClass('iris-error')
2524 + $container.addClass('spf--transparent-active')
2525 + } else {
2526 + $input.val(a8cIris._color.toString()).trigger('change')
2527 + $container.removeClass('spf--transparent-active')
2528 + }
2529 + })
2530 +
2531 + $transparent_slider.slider({
2532 + value: picker_color.transparent,
2533 + step: 1,
2534 + min: 0,
2535 + max: 100,
2536 + slide: function (event, ui) {
2537 + var slide_value = parseFloat(ui.value / 100)
2538 + a8cIris._color._alpha = slide_value
2539 + $input.wpColorPicker('color', a8cIris._color.toString())
2540 + $transparent_text.text(
2541 + slide_value === 1 || slide_value === 0 ? '' : slide_value
2542 + )
2543 + },
2544 + create: function () {
2545 + var slide_value = parseFloat(picker_color.transparent / 100),
2546 + text_value = slide_value < 1 ? slide_value : ''
2547 +
2548 + $transparent_text.text(text_value)
2549 + $transparent_offset.css('background-color', picker_color.value)
2550 +
2551 + $container.on('click', '.wp-picker-clear', function () {
2552 + a8cIris._color._alpha = 1
2553 + $transparent_text.text('')
2554 + $transparent_slider.slider('option', 'value', 100)
2555 + $container.removeClass('spf--transparent-active')
2556 + $input.trigger('change')
2557 + })
2558 +
2559 + $container.on('click', '.wp-picker-default', function () {
2560 + var default_color = SP_PC.funcs.parse_color(
2561 + $input.data('default-color')
2562 + ),
2563 + default_value = parseFloat(default_color.transparent / 100),
2564 + default_text = default_value < 1 ? default_value : ''
2565 +
2566 + a8cIris._color._alpha = default_value
2567 + $transparent_text.text(default_text)
2568 + $transparent_slider.slider(
2569 + 'option',
2570 + 'value',
2571 + default_color.transparent
2572 + )
2573 + })
2574 + }
2575 + })
2576 + }
2577 + })
2578 + })
2579 + }
2580 +
2581 + //
2582 + // Number (only allow numeric inputs)
2583 + //
2584 + $.fn.spf_number = function () {
2585 + return this.each(function () {
2586 + $(this).on('keypress', function (e) {
2587 + if (
2588 + e.keyCode !== 0 &&
2589 + e.keyCode !== 8 &&
2590 + e.keyCode !== 45 &&
2591 + e.keyCode !== 46 &&
2592 + (e.keyCode < 48 || e.keyCode > 57)
2593 + ) {
2594 + return false
2595 + }
2596 + })
2597 + })
2598 + }
2599 +
2600 + //
2601 + // ChosenJS
2602 + //
2603 + $.fn.spf_chosen = function () {
2604 + return this.each(function () {
2605 + var $this = $(this),
2606 + $inited = $this.parent().find('.chosen-container'),
2607 + is_sortable = $this.hasClass('spf-chosen-sortable') || false,
2608 + is_ajax = $this.hasClass('spf-chosen-ajax') || false,
2609 + is_multiple = $this.attr('multiple') || false,
2610 + set_width = is_multiple ? 'auto' : 'auto',
2611 + set_options = $.extend(
2612 + {
2613 + allow_single_deselect: true,
2614 + disable_search_threshold: 10,
2615 + width: set_width,
2616 + no_results_text: window.spf_vars.i18n.no_results_text
2617 + },
2618 + $this.data('chosen-settings')
2619 + )
2620 +
2621 + if ($inited.length) {
2622 + $inited.remove()
2623 + }
2624 +
2625 + // Chosen ajax
2626 + if (is_ajax) {
2627 + var set_ajax_options = $.extend(
2628 + {
2629 + data: {
2630 + type: 'post',
2631 + nonce: ''
2632 + },
2633 + allow_single_deselect: true,
2634 + disable_search_threshold: -1,
2635 + width: '100%',
2636 + min_length: 3,
2637 + type_delay: 500,
2638 + typing_text: window.spf_vars.i18n.typing_text,
2639 + searching_text: window.spf_vars.i18n.searching_text,
2640 + no_results_text: window.spf_vars.i18n.no_results_text
2641 + },
2642 + $this.data('chosen-settings')
2643 + )
2644 +
2645 + $this.SP_PCAjaxChosen(set_ajax_options)
2646 + } else {
2647 + $this.chosen(set_options)
2648 + }
2649 +
2650 + // Chosen keep options order
2651 + if (is_multiple) {
2652 + var $hidden_select = $this.parent().find('.spf-hidden-select')
2653 + var $hidden_value = $hidden_select.val() || []
2654 +
2655 + $this.on('change', function (obj, result) {
2656 + if (result && result.selected) {
2657 + $hidden_select.append(
2658 + '<option value="' +
2659 + result.selected +
2660 + '" selected="selected">' +
2661 + result.selected +
2662 + '</option>'
2663 + )
2664 + } else if (result && result.deselected) {
2665 + $hidden_select
2666 + .find('option[value="' + result.deselected + '"]')
2667 + .remove()
2668 + }
2669 +
2670 + // Force customize refresh
2671 + if (
2672 + $hidden_select.children().length === 0 &&
2673 + window.wp.customize !== undefined
2674 + ) {
2675 + window.wp.customize
2676 + .control($hidden_select.data('customize-setting-link'))
2677 + .setting.set('')
2678 + }
2679 +
2680 + $hidden_select.trigger('change')
2681 + })
2682 +
2683 + // Chosen order abstract
2684 + $this.SP_PCChosenOrder($hidden_value, true)
2685 + }
2686 +
2687 + // Chosen sortable
2688 + if (is_sortable) {
2689 + var $chosen_container = $this.parent().find('.chosen-container')
2690 + var $chosen_choices = $chosen_container.find('.chosen-choices')
2691 +
2692 + $chosen_choices.bind('mousedown', function (event) {
2693 + if ($(event.target).is('span')) {
2694 + event.stopPropagation()
2695 + }
2696 + })
2697 +
2698 + $chosen_choices.sortable({
2699 + items: 'li:not(.search-field)',
2700 + helper: 'orginal',
2701 + cursor: 'move',
2702 + placeholder: 'search-choice-placeholder',
2703 + start: function (e, ui) {
2704 + ui.placeholder.width(ui.item.innerWidth())
2705 + ui.placeholder.height(ui.item.innerHeight())
2706 + },
2707 + update: function (e, ui) {
2708 + var select_options = ''
2709 + var chosen_object = $this.data('chosen')
2710 + var $prev_select = $this.parent().find('.spf-hidden-select')
2711 +
2712 + $chosen_choices.find('.search-choice-close').each(function () {
2713 + var option_array_index = $(this).data('option-array-index')
2714 + $.each(chosen_object.results_data, function (index, data) {
2715 + if (data.array_index === option_array_index) {
2716 + select_options +=
2717 + '<option value="' +
2718 + data.value +
2719 + '" selected>' +
2720 + data.value +
2721 + '</option>'
2722 + }
2723 + })
2724 + })
2725 +
2726 + $prev_select.children().remove()
2727 + $prev_select.append(select_options)
2728 + $prev_select.trigger('change')
2729 + }
2730 + })
2731 + }
2732 + })
2733 + }
2734 +
2735 + //
2736 + // Helper Checkbox Checker
2737 + //
2738 + $.fn.spf_checkbox = function () {
2739 + return this.each(function () {
2740 + var $this = $(this),
2741 + $input = $this.find('.spf--input'),
2742 + $checkbox = $this.find('.spf--checkbox')
2743 +
2744 + $checkbox.on('click', function () {
2745 + $input.val(Number($checkbox.prop('checked'))).trigger('change')
2746 + })
2747 + })
2748 + }
2749 +
2750 + //
2751 + // Siblings
2752 + //
2753 + $.fn.spf_siblings = function () {
2754 + return this.each(function () {
2755 + var $this = $(this),
2756 + $siblings = $this.find('.spf--sibling'),
2757 + multiple = $this.data('multiple') || false
2758 +
2759 + $siblings.on('click', function () {
2760 + var $sibling = $(this)
2761 +
2762 + if (multiple) {
2763 + if ($sibling.hasClass('spf--active')) {
2764 + $sibling.removeClass('spf--active')
2765 + $sibling
2766 + .find('input')
2767 + .prop('checked', false)
2768 + .trigger('change')
2769 + } else {
2770 + $sibling.addClass('spf--active')
2771 + $sibling
2772 + .find('input')
2773 + .prop('checked', true)
2774 + .trigger('change')
2775 + }
2776 + } else {
2777 + $this.find('input').prop('checked', false)
2778 + $sibling
2779 + .find('input')
2780 + .prop('checked', true)
2781 + .trigger('change')
2782 + $sibling
2783 + .addClass('spf--active')
2784 + .siblings()
2785 + .removeClass('spf--active')
2786 + }
2787 + })
2788 + })
2789 + }
2790 +
2791 + //
2792 + // Help Tooltip
2793 + //
2794 + $.fn.spf_help = function () {
2795 + return this.each(function () {
2796 + var $this = $(this),
2797 + $tooltip,
2798 + offset_left
2799 +
2800 + $this.on({
2801 + mouseenter: function () {
2802 + $tooltip = $('<div class="spf-tooltip"></div>')
2803 + .html($this.find('.spf-help-text').html())
2804 + .appendTo('body')
2805 + offset_left = SP_PC.vars.is_rtl
2806 + ? $this.offset().left - $tooltip.outerWidth()
2807 + : $this.offset().left + 24
2808 +
2809 + $tooltip.css({
2810 + top: $this.offset().top - ($tooltip.outerHeight() / 2 - 14),
2811 + left: offset_left
2812 + })
2813 + },
2814 + mouseleave: function () {
2815 + if ($tooltip !== undefined) {
2816 + $tooltip.remove()
2817 + }
2818 + }
2819 + })
2820 + })
2821 + }
2822 +
2823 + //
2824 + // Window on resize
2825 + //
2826 + SP_PC.vars.$window
2827 + .on(
2828 + 'resize spf.resize',
2829 + SP_PC.helper.debounce(function (event) {
2830 + var window_width =
2831 + navigator.userAgent.indexOf('AppleWebKit/') > -1
2832 + ? SP_PC.vars.$window.width()
2833 + : window.innerWidth
2834 +
2835 + if (window_width <= 782 && !SP_PC.vars.onloaded) {
2836 + $('.spf-section').spf_reload_script()
2837 + SP_PC.vars.onloaded = true
2838 + }
2839 + }, 200)
2840 + )
2841 + .trigger('spf.resize')
2842 +
2843 + //
2844 + // Widgets Framework
2845 + //
2846 + $.fn.spf_widgets = function () {
2847 + if (this.length) {
2848 + $(document).on('widget-added widget-updated', function (event, $widget) {
2849 + $widget.find('.spf-fields').spf_reload_script()
2850 + })
2851 +
2852 + $('.widgets-sortables, .control-section-sidebar').on(
2853 + 'sortstop',
2854 + function (event, ui) {
2855 + ui.item.find('.spf-fields').spf_reload_script_retry()
2856 + }
2857 + )
2858 +
2859 + $(document).on('click', '.widget-top', function (event) {
2860 + $(this)
2861 + .parent()
2862 + .find('.spf-fields')
2863 + .spf_reload_script()
2864 + })
2865 + }
2866 + }
2867 +
2868 + //
2869 + // Retry Plugins
2870 + //
2871 + $.fn.spf_reload_script_retry = function () {
2872 + return this.each(function () {
2873 + var $this = $(this)
2874 + if ($this.data('inited')) {
2875 + $this.children('.spf-field-wp_editor').spf_field_wp_editor()
2876 + }
2877 + })
2878 + }
2879 +
2880 + //
2881 + // Reload Plugins
2882 + //
2883 + $.fn.spf_reload_script = function (options) {
2884 + var settings = $.extend(
2885 + {
2886 + dependency: true
2887 + },
2888 + options
2889 + )
2890 +
2891 + return this.each(function () {
2892 + var $this = $(this)
2893 + // Avoid for conflicts
2894 + if (!$this.data('inited')) {
2895 + // Field plugins
2896 + $this.children('.spf-field-accordion').spf_field_accordion()
2897 + $this.children('.spf-field-backup').spf_field_backup()
2898 + $this.children('.spf-field-background_adv').spf_field_background()
2899 + $this.children('.spf-field-background').spf_field_background()
2900 + $this.children('.spf-field-code_editor').spf_field_code_editor()
2901 + $this.children('.spf-field-date').spf_field_date()
2902 + $this.children('.spf-field-fieldset').spf_field_fieldset()
2903 + $this.children('.spf-field-gallery').spf_field_gallery()
2904 + $this.children('.spf-field-group').spf_field_group()
2905 + $this.children('.spf-field-icon').spf_field_icon()
2906 + $this.children('.spf-field-media').spf_field_media()
2907 + $this.children('.spf-field-slider').spf_field_slider()
2908 + $this.children('.spf-field-sortable').spf_field_sortable()
2909 + $this.children('.spf-field-sorter').spf_field_sorter()
2910 + $this.children('.spf-field-spinner').spf_field_spinner()
2911 + $this.children('.spf-field-switcher').spf_field_switcher()
2912 + $this.children('.spf-field-tabbed').spf_field_tabbed()
2913 + $this.children('.spf-field-typography').spf_field_typography()
2914 + $this.children('.spf-field-upload').spf_field_upload()
2915 + $this.children('.spf-field-wp_editor').spf_field_wp_editor()
2916 +
2917 + // Field colors
2918 + $this
2919 + .children('.spf-field-box_shadow')
2920 + .find('.spf-color')
2921 + .spf_color()
2922 + $this
2923 + .children('.spf-field-border')
2924 + .find('.spf-color')
2925 + .spf_color()
2926 + $this
2927 + .children('.spf-field-dimensions_advanced')
2928 + .find('.spf-color')
2929 + .spf_color()
2930 + $this
2931 + .children('.spf-field-background_adv')
2932 + .find('.spf-color')
2933 + .spf_color()
2934 + $this
2935 + .children('.spf-field-background')
2936 + .find('.spf-color')
2937 + .spf_color()
2938 + $this
2939 + .children('.spf-field-color')
2940 + .find('.spf-color')
2941 + .spf_color()
2942 + $this
2943 + .children('.spf-field-color_group')
2944 + .find('.spf-color')
2945 + .spf_color()
2946 + $this
2947 + .children('.spf-field-link_color')
2948 + .find('.spf-color')
2949 + .spf_color()
2950 + $this
2951 + .children('.spf-field-typography')
2952 + .find('.spf-color')
2953 + .spf_color()
2954 +
2955 + // Field allows only number
2956 + // $this.children('.spf-field-dimensions').find('.spf-number').spf_number();
2957 + // $this.children('.spf-field-slider').find('.spf-number').spf_number();
2958 + // $this.children('.spf-field-spacing').find('.spf-number').spf_number();
2959 + // $this.children('.spf-field-column').find('.spf-number').spf_number();
2960 + // $this.children('.spf-field-dimensions_advanced').find('.spf-number').spf_number();
2961 + // $this.children('.spf-field-spinner').find('.spf-number').spf_number();
2962 + // $this.children('.spf-field-typography').find('.spf-number').spf_number();
2963 +
2964 + // Field chosenjs
2965 + $this
2966 + .children('.spf-field-select')
2967 + .find('.spf-chosen')
2968 + .spf_chosen()
2969 +
2970 + // Field Checkbox
2971 + $this
2972 + .children('.spf-field-checkbox')
2973 + .find('.spf-checkbox')
2974 + .spf_checkbox()
2975 +
2976 + // Field Siblings
2977 + $this
2978 + .children('.spf-field-button_set')
2979 + .find('.spf-siblings')
2980 + .spf_siblings()
2981 + $this
2982 + .children('.spf-field-image_select')
2983 + .find('.spf-siblings')
2984 + .spf_siblings()
2985 + $this
2986 + .children('.spf-field-layout_preset')
2987 + .find('.spf-siblings')
2988 + .spf_siblings()
2989 + $this
2990 + .children('.spf-field-palette')
2991 + .find('.spf-siblings')
2992 + .spf_siblings()
2993 +
2994 + // Help Tooltip
2995 + $this
2996 + .children('.spf-field')
2997 + .find('.spf-help')
2998 + .spf_help()
2999 +
3000 + if (settings.dependency) {
3001 + $this.spf_dependency()
3002 + }
3003 +
3004 + $this.data('inited', true)
3005 +
3006 + $(document).trigger('spf-reload-script', $this)
3007 + }
3008 + })
3009 + }
3010 +
3011 + //
3012 + // Document ready and run scripts.
3013 + //
3014 + $(document).ready(function () {
3015 + $('.spf-save').spf_save()
3016 + $('.spf-confirm').spf_confirm()
3017 + $('.spf-nav-options').spf_nav_options()
3018 + $('.spf-nav-metabox').spf_nav_metabox()
3019 + $('.spf-expand-all').spf_expand_all()
3020 + $('.spf-search').spf_search()
3021 + $('.spf-sticky-header').spf_sticky()
3022 + $('.spf-page-templates').spf_page_templates()
3023 + $('.spf-post-formats').spf_post_formats()
3024 + $('.spf-onload').spf_reload_script()
3025 + $('.widget').spf_widgets()
3026 + })
3027 +
3028 + // ======================================================
3029 + // Post
3030 + // ------------------------------------------------------
3031 + // Trigger taxonomy list when post type is selected.
3032 + $('.sp_pcp_post_type select').change(function (event) {
3033 + event.preventDefault()
3034 + var data = {
3035 + action: 'sps_get_taxonomies',
3036 + pcp_post_types: $(this).val(),
3037 + ajax_nonce: $('#spf_pcp_metabox_noncesp_pcp_view_options').val()
3038 + }
3039 + $.post(ajaxurl, data, function (resp) {
3040 + $('.sp_pcp_post_taxonomy select').html(resp)
3041 + $('.sp_pcp_post_taxonomy select').trigger('chosen:updated')
3042 + })
3043 + })
3044 +
3045 + // Update terms list on the change of post taxonomy.
3046 + $('.sp_pcp_post_taxonomy select').change(function (event) {
3047 + event.preventDefault()
3048 + var taxSelector = $(this)
3049 + var data = {
3050 + action: 'sps_get_terms', // Callback function.
3051 + pcp_post_taxonomy: $(this).val(),
3052 + ajax_nonce: $('#spf_pcp_metabox_noncesp_pcp_view_options').val()
3053 + }
3054 + $.post(ajaxurl, data, function (resp) {
3055 + $(taxSelector)
3056 + .parent()
3057 + .parent('.sp_pcp_post_taxonomy')
3058 + .next('.sp_pcp_taxonomy_terms')
3059 + .find('select')
3060 + .html(resp)
3061 + $(taxSelector)
3062 + .parent()
3063 + .parent('.sp_pcp_post_taxonomy')
3064 + .next('.sp_pcp_taxonomy_terms')
3065 + .find('select')
3066 + .trigger('chosen:updated')
3067 + })
3068 + })
3069 +
3070 + // Populate specific post list in the drop-down.
3071 + var pt_saved_value = $('.sp_pcp_post_type select').val()
3072 + // Change Include only post_type on change of Post Type field.
3073 + var data_include_only = $('.sp_pcp_include_only_posts .spf-chosen-ajax').data(
3074 + 'chosen-settings'
3075 + )
3076 + // Change Exclude post_type on change of Post Type field.
3077 + var data_exclude = $('.sp_pcp_exclude_posts .spf-chosen-ajax').data(
3078 + 'chosen-settings'
3079 + )
3080 + if ($('.spf-nav').hasClass('spf-nav-metabox')) {
3081 + data_exclude.data.query_args.post_type = pt_saved_value
3082 + data_include_only.data.query_args.post_type = pt_saved_value
3083 + }
3084 + $('.sp_pcp_post_type select').change(function (event) {
3085 + event.preventDefault()
3086 + var pt_value = $(this).val()
3087 + // Change Include only post_type on change of Post Type field.
3088 + data_include_only.data.query_args.post_type = pt_value
3089 + // Change Exclude post_type on change of Post Type field.
3090 + data_exclude.data.query_args.post_type = pt_value
3091 +
3092 + // var data = {
3093 + // action: 'pcp_get_posts', // Callback function.
3094 + // pcp_post_type: $(this).val(), // Callback function's value.
3095 + // }
3096 + // $.post(ajaxurl, data, function (resp) {
3097 + // $('.sp_pcp_include_only_posts select').html(resp);
3098 + // $(".sp_pcp_include_only_posts select").trigger("chosen:updated");
3099 + // $('.sp_pcp_exclude_posts select').html(resp);
3100 + // $(".sp_pcp_exclude_posts select").trigger("chosen:updated");
3101 + // });
3102 + })
3103 +
3104 + /* Keep the accordion field's first item opened */
3105 + $(window).load(function () {
3106 + $('.pcp-opened-accordion').each(function () {
3107 + if (!$(this).hasClass('hidden')) {
3108 + $(this).addClass('pcp_saved_filter')
3109 + }
3110 + })
3111 + })
3112 + $('.spf-field-checkbox.pcp_advanced_filter').change(function (event) {
3113 + $('.pcp-opened-accordion').each(function () {
3114 + if ($(this).hasClass('hidden')) {
3115 + $(this).removeClass('pcp_saved_filter')
3116 + } else {
3117 + $(this).addClass('pcp_saved_filter')
3118 + }
3119 + if (!$(this).hasClass('pcp_saved_filter')) {
3120 + if (
3121 + $(this)
3122 + .find('.spf-accordion-title')
3123 + .siblings('.spf-accordion-content')
3124 + .hasClass('spf-accordion-open')
3125 + ) {
3126 + $(this).find('.spf-accordion-title')
3127 + } else {
3128 + $(this)
3129 + .find('.spf-accordion-title')
3130 + .trigger('click')
3131 + $(this)
3132 + .find('.spf-accordion-content')
3133 + .find('.spf-cloneable-add')
3134 + .trigger('click')
3135 + }
3136 + }
3137 + })
3138 + })
3139 +
3140 + // Pro only tag.
3141 + $('.pcp-pagination-type li:nth-child(n+2) input' ).attr('disabled', true)
3142 +
3143 + $("label:contains((Pro))").css({'pointer-events': 'none', 'opacity': '0.8', 'user-select': 'none'})
3144 + $("label:contains((Pro)) input").attr('disabled', true).css( 'opacity', '1')
3145 + $("select option:contains((Pro))").attr('disabled', true).css( 'opacity', '1')
3146 + // Image custom size.
3147 + // Post Meta fields 5th to last.
3148 + // Post content type with limit.
3149 + $('.post_content_sorter .spf-field-image_sizes select option:last-child, .pcp_disabled input, .pcp-meta-select select option:nth-child(n+5), .pcp-post-content-type select option:last-child')
3150 + .attr('disabled', true)
3151 + .css('pointer-events', 'none')
3152 +
3153 + $('.post_content_sorter .spf--sortable-item:has(div.pcp-pro-only)').css({"pointer-events": "none", "borderColor": "#bebebe"});
3154 + $('.post_content_sorter .spf--sortable-item:has(div.pcp-pro-only)').find('h4.spf-accordion-title, .spf--sortable-helper').css({"backgroundColor": "#f0f0f0", "color": "#777", "marginLeft": "0", "paddingRight": "0"});
3155 + $('.post_content_sorter .spf--sortable-item:has(div.pcp-pro-only)').find('.spf--sortable-helper .fa').css("color", "#777");
2650 3156
2651 3157 })(jQuery, window, document)