| 1 |
/** |
| 2 |
* |
| 3 |
* ----------------------------------------------------------- |
| 4 |
* |
| 5 |
* SPF Framework |
| 6 |
* |
| 7 |
* ----------------------------------------------------------- |
| 8 |
* |
| 9 |
*/ |
| 10 |
;(function ($, window, document, undefined) { |
| 11 |
'use strict' |
| 12 |
|
| 13 |
// |
| 14 |
// Constants |
| 15 |
// |
| 16 |
var SP_PC = SP_PC || {} |
| 17 |
|
| 18 |
SP_PC.funcs = {} |
| 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 |
} |
| 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 |
}, |
| 44 |
|
| 45 |
// Quote regular expression characters |
| 46 |
// |
| 47 |
preg_quote: function (str) { |
| 48 |
return (str + '').replace(/(\[|\-|\])/g, '\\$1') |
| 49 |
}, |
| 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 |
) |
| 60 |
|
| 61 |
$selector.find(':radio').each(function () { |
| 62 |
if (this.checked || this.orginal_checked) { |
| 63 |
this.orginal_checked = true |
| 64 |
} |
| 65 |
}) |
| 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 |
}, |
| 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 |
}, |
| 101 |
|
| 102 |
// |
| 103 |
// Get a cookie |
| 104 |
// |
| 105 |
get_cookie: function (name) { |
| 106 |
var e, |
| 107 |
b, |
| 108 |
cookie = document.cookie, |
| 109 |
p = name + '=' |
| 110 |
|
| 111 |
if (!cookie) { |
| 112 |
return |
| 113 |
} |
| 114 |
|
| 115 |
b = cookie.indexOf('; ' + p) |
| 116 |
|
| 117 |
if (b === -1) { |
| 118 |
b = cookie.indexOf(p) |
| 119 |
|
| 120 |
if (b !== 0) { |
| 121 |
return null |
| 122 |
} |
| 123 |
} else { |
| 124 |
b += 2 |
| 125 |
} |
| 126 |
|
| 127 |
e = cookie.indexOf(';', b) |
| 128 |
|
| 129 |
if (e === -1) { |
| 130 |
e = cookie.length |
| 131 |
} |
| 132 |
|
| 133 |
return decodeURIComponent(cookie.substring(b + p.length, e)) |
| 134 |
}, |
| 135 |
|
| 136 |
// |
| 137 |
// Set a cookie |
| 138 |
// |
| 139 |
set_cookie: function (name, value, expires, path, domain, secure) { |
| 140 |
var d = new Date() |
| 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 |
} |
| 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 |
}, |
| 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 |
} |
| 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')) |
| 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 |
} |
| 184 |
|
| 185 |
this.find(':radio').each(function () { |
| 186 |
this.orginal_checked = this.checked |
| 187 |
}) |
| 188 |
|
| 189 |
return base |
| 190 |
} |
| 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 |
} |
| 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 |
| 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) |
| 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') |
| 238 |
|
| 239 |
if ($last_section !== undefined) { |
| 240 |
$last_section.hide() |
| 241 |
} |
| 242 |
|
| 243 |
var $section = $('#spf-section-' + slug) |
| 244 |
$section.css({ display: 'block' }) |
| 245 |
$section.spf_reload_script() |
| 246 |
|
| 247 |
$hidden.val(slug) |
| 248 |
|
| 249 |
$last_section = $section |
| 250 |
} |
| 251 |
}) |
| 252 |
.trigger('hashchange') |
| 253 |
}) |
| 254 |
} |
| 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 |
| 267 |
|
| 268 |
$links.on('click', function (e) { |
| 269 |
e.preventDefault() |
| 270 |
|
| 271 |
var $link = $(this), |
| 272 |
section_id = $link.data('section') |
| 273 |
|
| 274 |
if ($last_link !== undefined) { |
| 275 |
$last_link.removeClass('spf-section-active') |
| 276 |
} |
| 277 |
|
| 278 |
if ($last_section !== undefined) { |
| 279 |
$last_section.hide() |
| 280 |
} |
| 281 |
|
| 282 |
$link.addClass('spf-section-active') |
| 283 |
|
| 284 |
var $section = $('#spf-section-' + section_id) |
| 285 |
$section.css({ display: 'block' }) |
| 286 |
$section.spf_reload_script() |
| 287 |
|
| 288 |
SP_PC.helper.set_cookie( |
| 289 |
'spf-last-metabox-tab-' + post_id + '-' + unique_id, |
| 290 |
section_id |
| 291 |
) |
| 292 |
|
| 293 |
$last_section = $section |
| 294 |
$last_link = $link |
| 295 |
}) |
| 296 |
|
| 297 |
var get_cookie = SP_PC.helper.get_cookie( |
| 298 |
'spf-last-metabox-tab-' + post_id + '-' + unique_id |
| 299 |
) |
| 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 |
} |
| 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' |
| 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 |
} |
| 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' |
| 344 |
|
| 345 |
// Fallback for classic editor version |
| 346 |
maybe_value = maybe_value === '0' ? 'default' : maybe_value |
| 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 |
} |
| 358 |
|
| 359 |
// |
| 360 |
// Search |
| 361 |
// |
| 362 |
$.fn.spf_search = function () { |
| 363 |
return this.each(function () { |
| 364 |
var $this = $(this), |
| 365 |
$input = $this.find('input') |
| 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') |
| 373 |
|
| 374 |
if (value.length > 3) { |
| 375 |
$fields.addClass('spf-hidden') |
| 376 |
$wrapper.addClass('spf-search-all') |
| 377 |
|
| 378 |
$titles.each(function () { |
| 379 |
var $title = $(this) |
| 380 |
|
| 381 |
if ($title.text().match(new RegExp('.*?' + value + '.*?', 'i'))) { |
| 382 |
var $field = $title.closest('.spf-field') |
| 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 |
} |
| 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 |
) |
| 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 |
} |
| 434 |
|
| 435 |
ticking = true |
| 436 |
}, |
| 437 |
onSticky = function () { |
| 438 |
scrollTop = $window.scrollTop() |
| 439 |
requestTick() |
| 440 |
} |
| 441 |
|
| 442 |
$window.on('scroll resize', onSticky) |
| 443 |
|
| 444 |
onSticky() |
| 445 |
}) |
| 446 |
} |
| 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 |
| 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 |
| 467 |
|
| 468 |
if ($field.data('depend-global')) { |
| 469 |
is_global = true |
| 470 |
} |
| 471 |
|
| 472 |
$.each(controllers, function (index, depend_id) { |
| 473 |
var value = values[index] || '', |
| 474 |
condition = conditions[index] || conditions[0] |
| 475 |
|
| 476 |
rules = rules.createRule( |
| 477 |
'[data-depend-id="' + depend_id + '"]', |
| 478 |
condition, |
| 479 |
value |
| 480 |
) |
| 481 |
|
| 482 |
rules.include($field) |
| 483 |
|
| 484 |
depends.push(depend_id) |
| 485 |
}) |
| 486 |
}) |
| 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 |
} |
| 497 |
|
| 498 |
// |
| 499 |
// Field: accordion |
| 500 |
// |
| 501 |
$.fn.spf_field_accordion = function () { |
| 502 |
return this.each(function () { |
| 503 |
// Keep the accordion open by default. |
| 504 |
|
| 505 |
var $titles = $(this).find('.spf-accordion-title') |
| 506 |
|
| 507 |
//$titles.on('load', function() { |
| 508 |
//var $title_area = $(this), |
| 509 |
// var $content_area = $titles.next(); |
| 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 |
//}); |
| 518 |
|
| 519 |
$titles.on('click', function () { |
| 520 |
var $title = $(this), |
| 521 |
$icon = $title.find('.spf-accordion-icon'), |
| 522 |
$content = $title.next() |
| 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 |
} |
| 529 |
|
| 530 |
if (!$content.data('opened')) { |
| 531 |
$content.spf_reload_script() |
| 532 |
$content.data('opened', true) |
| 533 |
} |
| 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 |
} |
| 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 |
} |
| 580 |
|
| 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 |
} |
| 592 |
|
| 593 |
var base = this, |
| 594 |
$this = $(this), |
| 595 |
$body = $('body'), |
| 596 |
$import = $this.find('.spf-import'), |
| 597 |
$reset = $this.find('.spf-reset') |
| 598 |
|
| 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 |
} |
| 609 |
|
| 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 |
} |
| 623 |
|
| 624 |
$reset.on('click', function (e) { |
| 625 |
e.preventDefault() |
| 626 |
|
| 627 |
if (SP_PC.vars.is_confirm) { |
| 628 |
base.notification(window.spf_vars.i18n.reset_notification) |
| 629 |
|
| 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 |
}) |
| 644 |
|
| 645 |
$import.on('click', function (e) { |
| 646 |
e.preventDefault() |
| 647 |
|
| 648 |
if (SP_PC.vars.is_confirm) { |
| 649 |
base.notification(window.spf_vars.i18n.import_notification) |
| 650 |
|
| 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 |
} |
| 668 |
|
| 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() |
| 677 |
|
| 678 |
// |
| 679 |
// |
| 680 |
// Preview |
| 681 |
var $this = $(this) |
| 682 |
var $preview_block = $this.find('.spf--block-preview') |
| 683 |
|
| 684 |
if ($preview_block.length) { |
| 685 |
var $preview = $this.find('.spf--preview') |
| 686 |
|
| 687 |
// Set preview styles on change |
| 688 |
$this.on( |
| 689 |
'change', |
| 690 |
SP_PC.helper.debounce(function (event) { |
| 691 |
$preview_block.removeClass('hidden') |
| 692 |
|
| 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() |
| 716 |
|
| 717 |
var properties = {} |
| 718 |
|
| 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 |
) |
| 753 |
|
| 754 |
if (!$preview_block.hasClass('hidden')) { |
| 755 |
$this.trigger('change') |
| 756 |
} |
| 757 |
} |
| 758 |
}) |
| 759 |
} |
| 760 |
|
| 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 |
} |
| 769 |
|
| 770 |
var $this = $(this), |
| 771 |
$textarea = $this.find('textarea'), |
| 772 |
$inited = $this.find('.CodeMirror'), |
| 773 |
data_editor = $textarea.data('editor') |
| 774 |
|
| 775 |
if ($inited.length) { |
| 776 |
$inited.remove() |
| 777 |
} |
| 778 |
|
| 779 |
var interval = setInterval(function () { |
| 780 |
if ($this.is(':visible')) { |
| 781 |
var code_editor = CodeMirror.fromTextArea($textarea[0], data_editor) |
| 782 |
|
| 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>') |
| 789 |
|
| 790 |
$('#spf-codemirror-css').after($cssLink) |
| 791 |
|
| 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 |
}) |
| 800 |
|
| 801 |
SP_PC.vars.code_themes.push(data_editor.theme) |
| 802 |
} |
| 803 |
|
| 804 |
CodeMirror.modeURL = data_editor.cdnURL + '/mode/%N/%N.min.js' |
| 805 |
CodeMirror.autoLoadMode(code_editor, data_editor.mode) |
| 806 |
|
| 807 |
code_editor.on('change', function (editor, event) { |
| 808 |
$textarea.val(code_editor.getValue()).trigger('change') |
| 809 |
}) |
| 810 |
|
| 811 |
clearInterval(interval) |
| 812 |
} |
| 813 |
}) |
| 814 |
}) |
| 815 |
} |
| 816 |
|
| 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 |
| 827 |
|
| 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 |
} |
| 837 |
|
| 838 |
settings = $.extend({}, settings, defaults) |
| 839 |
|
| 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) |
| 850 |
|
| 851 |
$inputs.not(this).datepicker('option', option, date) |
| 852 |
} |
| 853 |
}) |
| 854 |
} |
| 855 |
|
| 856 |
$inputs.each(function () { |
| 857 |
var $input = $(this) |
| 858 |
|
| 859 |
if ($input.hasClass('hasDatepicker')) { |
| 860 |
$input.removeAttr('id').removeClass('hasDatepicker') |
| 861 |
} |
| 862 |
|
| 863 |
$input.datepicker(settings) |
| 864 |
}) |
| 865 |
}) |
| 866 |
} |
| 867 |
|
| 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 |
} |
| 878 |
|
| 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 |
| 891 |
|
| 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' |
| 897 |
|
| 898 |
e.preventDefault() |
| 899 |
|
| 900 |
if ( |
| 901 |
typeof window.wp === 'undefined' || |
| 902 |
!window.wp.media || |
| 903 |
!window.wp.media.gallery |
| 904 |
) { |
| 905 |
return |
| 906 |
} |
| 907 |
|
| 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 |
}) |
| 918 |
|
| 919 |
wp_media_frame.open() |
| 920 |
} else { |
| 921 |
wp_media_frame = window.wp.media.gallery.edit( |
| 922 |
'[gallery ids="' + ids + '"]' |
| 923 |
) |
| 924 |
|
| 925 |
if (what === 'add') { |
| 926 |
wp_media_frame.setState('gallery-library') |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
// Media Update |
| 931 |
wp_media_frame.on('update', function (selection) { |
| 932 |
$list.empty() |
| 933 |
|
| 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 |
| 940 |
|
| 941 |
$list.append('<li><img src="' + thumb + '"></li>') |
| 942 |
|
| 943 |
return item.id |
| 944 |
}) |
| 945 |
|
| 946 |
$input.val(selectedIds.join(',')).trigger('change') |
| 947 |
$clear.removeClass('hidden') |
| 948 |
$edit.removeClass('hidden') |
| 949 |
}) |
| 950 |
}) |
| 951 |
|
| 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 |
} |
| 961 |
|
| 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')) |
| 979 |
|
| 980 |
// clear accordion arrows if multi-instance |
| 981 |
if ($wrapper.hasClass('ui-accordion')) { |
| 982 |
$wrapper.find('.ui-accordion-header-icon').remove() |
| 983 |
} |
| 984 |
|
| 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 |
} |
| 996 |
|
| 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 |
} |
| 1010 |
|
| 1011 |
var count = $wrapper.children('.spf-cloneable-item').length |
| 1012 |
pcp_hide_the_taxonomy_relation(count) |
| 1013 |
|
| 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 |
| 1027 |
|
| 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') |
| 1035 |
|
| 1036 |
$first.on('change', function (event) { |
| 1037 |
//$title.text( $first.children("option").filter(":selected").text() ); |
| 1038 |
$title.text($first.val()) |
| 1039 |
}) |
| 1040 |
|
| 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 |
}) |
| 1050 |
|
| 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 |
) |
| 1067 |
|
| 1068 |
//$wrapper.spf_customizer_refresh(); |
| 1069 |
|
| 1070 |
if (is_number) { |
| 1071 |
update_title_numbers($wrapper) |
| 1072 |
} |
| 1073 |
} |
| 1074 |
}) |
| 1075 |
|
| 1076 |
$group.children('.spf-cloneable-add').on('click', function (e) { |
| 1077 |
e.preventDefault() |
| 1078 |
|
| 1079 |
var count = $wrapper.children('.spf-cloneable-item').length |
| 1080 |
|
| 1081 |
$min.hide() |
| 1082 |
|
| 1083 |
if (max && count + 1 > max) { |
| 1084 |
$max.show() |
| 1085 |
return |
| 1086 |
} |
| 1087 |
|
| 1088 |
var new_field_id = unique_id + field_id + '[' + count + ']' |
| 1089 |
|
| 1090 |
var $cloned_item = $hidden.spf_clone(true) |
| 1091 |
|
| 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}); |
| 1112 |
|
| 1113 |
if (is_number) { |
| 1114 |
update_title_numbers($wrapper) |
| 1115 |
} |
| 1116 |
pcp_hide_the_taxonomy_relation(count + 1) |
| 1117 |
}) |
| 1118 |
|
| 1119 |
var event_clone = function (e) { |
| 1120 |
e.preventDefault() |
| 1121 |
|
| 1122 |
var count = $wrapper.children('.spf-cloneable-item').length |
| 1123 |
|
| 1124 |
$min.hide() |
| 1125 |
|
| 1126 |
if (max && count + 1 > max) { |
| 1127 |
$max.show() |
| 1128 |
return |
| 1129 |
} |
| 1130 |
|
| 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 |
) |
| 1144 |
|
| 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 |
}) |
| 1157 |
|
| 1158 |
var $cloned = $('<div class="spf-cloneable-item" />') |
| 1159 |
$cloned.append($cloned_helper) |
| 1160 |
$cloned.append($cloned_title) |
| 1161 |
$cloned.append($cloned_content) |
| 1162 |
|
| 1163 |
$wrapper |
| 1164 |
.children() |
| 1165 |
.eq($parent.index()) |
| 1166 |
.after($cloned) |
| 1167 |
|
| 1168 |
SP_PC.helper.name_nested_replace( |
| 1169 |
$wrapper.children('.spf-cloneable-item'), |
| 1170 |
field_id |
| 1171 |
) |
| 1172 |
|
| 1173 |
$wrapper.accordion('refresh') |
| 1174 |
// $wrapper.spf_customizer_refresh(); |
| 1175 |
// $wrapper.spf_customizer_listen({closest: true}); |
| 1176 |
|
| 1177 |
if (is_number) { |
| 1178 |
update_title_numbers($wrapper) |
| 1179 |
} |
| 1180 |
pcp_hide_the_taxonomy_relation(count + 1) |
| 1181 |
} |
| 1182 |
|
| 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() |
| 1193 |
|
| 1194 |
var count = $wrapper.children('.spf-cloneable-item').length |
| 1195 |
|
| 1196 |
$max.hide() |
| 1197 |
$min.hide() |
| 1198 |
|
| 1199 |
if (min && count - 1 < min) { |
| 1200 |
$min.show() |
| 1201 |
return |
| 1202 |
} |
| 1203 |
|
| 1204 |
$(this) |
| 1205 |
.closest('.spf-cloneable-item') |
| 1206 |
.remove() |
| 1207 |
|
| 1208 |
SP_PC.helper.name_nested_replace( |
| 1209 |
$wrapper.children('.spf-cloneable-item'), |
| 1210 |
field_id |
| 1211 |
) |
| 1212 |
|
| 1213 |
//$wrapper.spf_customizer_refresh(); |
| 1214 |
|
| 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 |
} |
| 1230 |
|
| 1231 |
// |
| 1232 |
// Field: icon |
| 1233 |
// |
| 1234 |
$.fn.spf_field_icon = function () { |
| 1235 |
return this.each(function () { |
| 1236 |
var $this = $(this) |
| 1237 |
|
| 1238 |
$this.on('click', '.spf-icon-add', function (e) { |
| 1239 |
e.preventDefault() |
| 1240 |
|
| 1241 |
var $button = $(this) |
| 1242 |
var $modal = $('#spf-modal-icon') |
| 1243 |
|
| 1244 |
$modal.show() |
| 1245 |
|
| 1246 |
SP_PC.vars.$icon_target = $this |
| 1247 |
|
| 1248 |
if (!SP_PC.vars.icon_modal_loaded) { |
| 1249 |
$modal.find('.spf-modal-loading').show() |
| 1250 |
|
| 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() |
| 1258 |
|
| 1259 |
SP_PC.vars.icon_modal_loaded = true |
| 1260 |
|
| 1261 |
var $load = $modal.find('.spf-modal-load').html(response.content) |
| 1262 |
|
| 1263 |
$load.on('click', 'a', function (e) { |
| 1264 |
e.preventDefault() |
| 1265 |
|
| 1266 |
var icon = $(this).data('spf-icon') |
| 1267 |
|
| 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') |
| 1282 |
|
| 1283 |
$modal.hide() |
| 1284 |
}) |
| 1285 |
|
| 1286 |
$modal.on('change keyup', '.spf-icon-search', function () { |
| 1287 |
var value = $(this).val(), |
| 1288 |
$icons = $load.find('a') |
| 1289 |
|
| 1290 |
$icons.each(function () { |
| 1291 |
var $elem = $(this) |
| 1292 |
|
| 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 |
}) |
| 1302 |
|
| 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 |
}) |
| 1320 |
|
| 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 |
} |
| 1332 |
|
| 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 |
| 1346 |
|
| 1347 |
$upload_button.on('click', function (e) { |
| 1348 |
e.preventDefault() |
| 1349 |
|
| 1350 |
if ( |
| 1351 |
typeof window.wp === 'undefined' || |
| 1352 |
!window.wp.media || |
| 1353 |
!window.wp.media.gallery |
| 1354 |
) { |
| 1355 |
return |
| 1356 |
} |
| 1357 |
|
| 1358 |
if (wp_media_frame) { |
| 1359 |
wp_media_frame.open() |
| 1360 |
return |
| 1361 |
} |
| 1362 |
|
| 1363 |
wp_media_frame = window.wp.media({ |
| 1364 |
library: { |
| 1365 |
type: $library |
| 1366 |
} |
| 1367 |
}) |
| 1368 |
|
| 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' |
| 1376 |
|
| 1377 |
if ( |
| 1378 |
$library.length && |
| 1379 |
$library.indexOf(attributes.subtype) === -1 && |
| 1380 |
$library.indexOf(attributes.type) === -1 |
| 1381 |
) { |
| 1382 |
return |
| 1383 |
} |
| 1384 |
|
| 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) |
| 1391 |
|
| 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 |
} |
| 1406 |
|
| 1407 |
$remove_button.removeClass('hidden') |
| 1408 |
|
| 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 |
}) |
| 1417 |
|
| 1418 |
wp_media_frame.open() |
| 1419 |
}) |
| 1420 |
|
| 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 |
} |
| 1431 |
|
| 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 |
| 1442 |
|
| 1443 |
if ($slider.hasClass('ui-slider')) { |
| 1444 |
$slider.empty() |
| 1445 |
} |
| 1446 |
|
| 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 |
}) |
| 1457 |
|
| 1458 |
$input.keyup(function () { |
| 1459 |
$slider.slider('value', $input.val()) |
| 1460 |
}) |
| 1461 |
}) |
| 1462 |
} |
| 1463 |
|
| 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 |
| 1473 |
|
| 1474 |
$enabled.sortable({ |
| 1475 |
connectWith: $disabled, |
| 1476 |
|
| 1477 |
placeholder: 'ui-sortable-placeholder', |
| 1478 |
|
| 1479 |
update: function (event, ui) { |
| 1480 |
var $el = ui.item.find('input') |
| 1481 |
|
| 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 |
} |
| 1487 |
|
| 1488 |
// $this.spf_customizer_refresh(); |
| 1489 |
} |
| 1490 |
}) |
| 1491 |
|
| 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 |
} |
| 1503 |
|
| 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') |
| 1513 |
|
| 1514 |
if ($inited.length) { |
| 1515 |
$inited.remove() |
| 1516 |
} |
| 1517 |
|
| 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 |
} |
| 1539 |
|
| 1540 |
// |
| 1541 |
// Field: switcher |
| 1542 |
// |
| 1543 |
$.fn.spf_field_switcher = function () { |
| 1544 |
return this.each(function () { |
| 1545 |
var $switcher = $(this).find('.spf--switcher') |
| 1546 |
|
| 1547 |
$switcher.on('click', function () { |
| 1548 |
var value = 0 |
| 1549 |
var $input = $switcher.find('input') |
| 1550 |
|
| 1551 |
if ($switcher.hasClass('spf--active')) { |
| 1552 |
$switcher.removeClass('spf--active') |
| 1553 |
} else { |
| 1554 |
value = 1 |
| 1555 |
$switcher.addClass('spf--active') |
| 1556 |
} |
| 1557 |
|
| 1558 |
$input.val(value).trigger('change') |
| 1559 |
}) |
| 1560 |
}) |
| 1561 |
} |
| 1562 |
|
| 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') |
| 1571 |
|
| 1572 |
$sections.eq(0).spf_reload_script() |
| 1573 |
|
| 1574 |
$links.on('click', function (e) { |
| 1575 |
e.preventDefault() |
| 1576 |
|
| 1577 |
var $link = $(this), |
| 1578 |
index = $link.index(), |
| 1579 |
$section = $sections.eq(index) |
| 1580 |
|
| 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 |
} |
| 1593 |
|
| 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 |
| 1605 |
|
| 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 |
} |
| 1614 |
|
| 1615 |
// |
| 1616 |
// |
| 1617 |
// Sanitize google font styles (weight and style) |
| 1618 |
base.sanitize_style = function (style) { |
| 1619 |
return googlestyles[style] ? googlestyles[style] : style |
| 1620 |
} |
| 1621 |
|
| 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', '') : '' |
| 1629 |
|
| 1630 |
if (weight || style) { |
| 1631 |
font_family = font_family + ':' + weight + style |
| 1632 |
} |
| 1633 |
|
| 1634 |
if (loaded_fonts.indexOf(font_family) === -1) { |
| 1635 |
WebFont.load({ google: { families: [font_family] } }) |
| 1636 |
} |
| 1637 |
|
| 1638 |
loaded_fonts.push(font_family) |
| 1639 |
} |
| 1640 |
} |
| 1641 |
|
| 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() |
| 1656 |
|
| 1657 |
var opts = '' |
| 1658 |
|
| 1659 |
$.each(options, function (key, value) { |
| 1660 |
var selected |
| 1661 |
var name = value |
| 1662 |
|
| 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 |
} |
| 1670 |
|
| 1671 |
if (type === 'subset') { |
| 1672 |
name = base.sanitize_subset(value) |
| 1673 |
} else if (type === 'style') { |
| 1674 |
name = base.sanitize_style(value) |
| 1675 |
} |
| 1676 |
|
| 1677 |
opts += |
| 1678 |
'<option value="' + |
| 1679 |
value + |
| 1680 |
'"' + |
| 1681 |
selected + |
| 1682 |
'>' + |
| 1683 |
name + |
| 1684 |
'</option>' |
| 1685 |
}) |
| 1686 |
|
| 1687 |
$select |
| 1688 |
.append(opts) |
| 1689 |
.trigger('spf.change') |
| 1690 |
.trigger('chosen:updated') |
| 1691 |
} |
| 1692 |
|
| 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 |
: [] |
| 1705 |
|
| 1706 |
// |
| 1707 |
// |
| 1708 |
// Chosen init |
| 1709 |
if ($this.find('.spf--chosen').length) { |
| 1710 |
var $chosen_selects = $this.find('select') |
| 1711 |
|
| 1712 |
$chosen_selects.each(function () { |
| 1713 |
var $chosen_select = $(this), |
| 1714 |
$chosen_inited = $chosen_select.parent().find('.chosen-container') |
| 1715 |
|
| 1716 |
if ($chosen_inited.length) { |
| 1717 |
$chosen_inited.remove() |
| 1718 |
} |
| 1719 |
|
| 1720 |
$chosen_select.chosen({ |
| 1721 |
allow_single_deselect: true, |
| 1722 |
disable_search_threshold: 15, |
| 1723 |
width: '100%' |
| 1724 |
}) |
| 1725 |
}) |
| 1726 |
} |
| 1727 |
|
| 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() |
| 1733 |
|
| 1734 |
// Clear default font family select options |
| 1735 |
$font_family_select |
| 1736 |
.find('option') |
| 1737 |
.not(':first-child') |
| 1738 |
.remove() |
| 1739 |
|
| 1740 |
var opts = '' |
| 1741 |
|
| 1742 |
$.each(webfonts, function (type, group) { |
| 1743 |
// Check for exclude fonts |
| 1744 |
if (exclude_fonts && exclude_fonts.indexOf(type) !== -1) { |
| 1745 |
return |
| 1746 |
} |
| 1747 |
|
| 1748 |
opts += '<optgroup label="' + group.label + '">' |
| 1749 |
|
| 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 |
}) |
| 1765 |
|
| 1766 |
opts += '</optgroup>' |
| 1767 |
}) |
| 1768 |
|
| 1769 |
// Append google font select options |
| 1770 |
$font_family_select.append(opts).trigger('chosen:updated') |
| 1771 |
|
| 1772 |
// |
| 1773 |
// |
| 1774 |
// Font style select |
| 1775 |
var $font_style_block = $this.find('.spf--block-font-style') |
| 1776 |
|
| 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 |
: '' |
| 1782 |
|
| 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() |
| 1787 |
|
| 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 |
} |
| 1796 |
|
| 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' : '' |
| 1812 |
|
| 1813 |
$this.find('.spf--font-weight').val(font_weight) |
| 1814 |
$this.find('.spf--font-style').val(font_style) |
| 1815 |
}) |
| 1816 |
|
| 1817 |
// |
| 1818 |
// |
| 1819 |
// Extra font style select |
| 1820 |
var $extra_font_style_block = $this.find('.spf--block-extra-styles') |
| 1821 |
|
| 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 |
} |
| 1827 |
|
| 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 |
} |
| 1837 |
|
| 1838 |
// |
| 1839 |
// |
| 1840 |
// Backup font family |
| 1841 |
var $backup_font_family_block = $this.find( |
| 1842 |
'.spf--block-backup-font-family' |
| 1843 |
) |
| 1844 |
|
| 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 |
} |
| 1854 |
|
| 1855 |
// Hide extra font style on change |
| 1856 |
if ($extra_font_style_block.length) { |
| 1857 |
$extra_font_style_block.addClass('hidden') |
| 1858 |
} |
| 1859 |
|
| 1860 |
// Hide backup font family on change |
| 1861 |
if ($backup_font_family_block.length) { |
| 1862 |
$backup_font_family_block.addClass('hidden') |
| 1863 |
} |
| 1864 |
|
| 1865 |
var $selected = $font_family_select.find(':selected') |
| 1866 |
var value = $selected.val() |
| 1867 |
var type = $selected.data('type') |
| 1868 |
|
| 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 |
} |
| 1877 |
|
| 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 |
| 1882 |
|
| 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 |
} |
| 1889 |
|
| 1890 |
selected_styles = styles |
| 1891 |
|
| 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 |
| 1899 |
|
| 1900 |
// Append style select options |
| 1901 |
base.append_select_options( |
| 1902 |
$font_style_select, |
| 1903 |
styles, |
| 1904 |
set_style_value, |
| 1905 |
'style' |
| 1906 |
) |
| 1907 |
|
| 1908 |
// Clear first value |
| 1909 |
first_style_value = false |
| 1910 |
|
| 1911 |
// Show style select after appended |
| 1912 |
$font_style_block.removeClass('hidden') |
| 1913 |
|
| 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 |
) |
| 1928 |
|
| 1929 |
// Clear first value |
| 1930 |
first_extra_style_value = false |
| 1931 |
|
| 1932 |
// Show style select after appended |
| 1933 |
$extra_font_style_block.removeClass('hidden') |
| 1934 |
} |
| 1935 |
} |
| 1936 |
|
| 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 |
| 1951 |
|
| 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 |
| 1957 |
|
| 1958 |
base.append_select_options( |
| 1959 |
$subset_select, |
| 1960 |
subsets, |
| 1961 |
set_subset_value, |
| 1962 |
'subset', |
| 1963 |
subset_multi_select |
| 1964 |
) |
| 1965 |
|
| 1966 |
first_subset_select_value = false |
| 1967 |
|
| 1968 |
$subset_block.removeClass('hidden') |
| 1969 |
} |
| 1970 |
} else { |
| 1971 |
// Clear Styles |
| 1972 |
$styles.find(':input').val('') |
| 1973 |
|
| 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 |
} |
| 1982 |
|
| 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 |
} |
| 1992 |
|
| 1993 |
// Update font type input value |
| 1994 |
$type.val(type) |
| 1995 |
}) |
| 1996 |
.trigger('spf.change') |
| 1997 |
|
| 1998 |
// |
| 1999 |
// |
| 2000 |
// Preview |
| 2001 |
var $preview_block = $this.find('.spf--block-preview') |
| 2002 |
|
| 2003 |
if ($preview_block.length) { |
| 2004 |
var $preview = $this.find('.spf--preview') |
| 2005 |
|
| 2006 |
// Set preview styles on change |
| 2007 |
$this.on( |
| 2008 |
'change', |
| 2009 |
SP_PC.helper.debounce(function (event) { |
| 2010 |
$preview_block.removeClass('hidden') |
| 2011 |
|
| 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() |
| 2026 |
|
| 2027 |
if (type === 'google') { |
| 2028 |
base.load_google_font(font_family, font_weight, font_style) |
| 2029 |
} |
| 2030 |
|
| 2031 |
var properties = {} |
| 2032 |
|
| 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 |
} |
| 2069 |
|
| 2070 |
$preview.removeAttr('style') |
| 2071 |
|
| 2072 |
// Customs style attribute |
| 2073 |
if (custom_style) { |
| 2074 |
$preview.attr('style', custom_style) |
| 2075 |
} |
| 2076 |
|
| 2077 |
$preview.css(properties) |
| 2078 |
}, 100) |
| 2079 |
) |
| 2080 |
|
| 2081 |
// Preview black and white backgrounds trigger |
| 2082 |
$preview_block.on('click', function () { |
| 2083 |
$preview.toggleClass('spf--black-background') |
| 2084 |
|
| 2085 |
var $toggle = $preview_block.find('.spf--toggle') |
| 2086 |
|
| 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 |
}) |
| 2093 |
|
| 2094 |
if (!$preview_block.hasClass('hidden')) { |
| 2095 |
$this.trigger('change') |
| 2096 |
} |
| 2097 |
} |
| 2098 |
} |
| 2099 |
|
| 2100 |
base.init() |
| 2101 |
}) |
| 2102 |
} |
| 2103 |
|
| 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 |
| 2118 |
|
| 2119 |
$input.on('change', function (e) { |
| 2120 |
if ($input.val()) { |
| 2121 |
$remove_button.removeClass('hidden') |
| 2122 |
} else { |
| 2123 |
$remove_button.addClass('hidden') |
| 2124 |
} |
| 2125 |
}) |
| 2126 |
|
| 2127 |
$upload_button.on('click', function (e) { |
| 2128 |
e.preventDefault() |
| 2129 |
|
| 2130 |
if ( |
| 2131 |
typeof window.wp === 'undefined' || |
| 2132 |
!window.wp.media || |
| 2133 |
!window.wp.media.gallery |
| 2134 |
) { |
| 2135 |
return |
| 2136 |
} |
| 2137 |
|
| 2138 |
if (wp_media_frame) { |
| 2139 |
wp_media_frame.open() |
| 2140 |
return |
| 2141 |
} |
| 2142 |
|
| 2143 |
wp_media_frame = window.wp.media({ |
| 2144 |
library: { |
| 2145 |
type: $library |
| 2146 |
} |
| 2147 |
}) |
| 2148 |
|
| 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 |
| 2157 |
|
| 2158 |
if ( |
| 2159 |
$library.length && |
| 2160 |
$library.indexOf(attributes.subtype) === -1 && |
| 2161 |
$library.indexOf(attributes.type) === -1 |
| 2162 |
) { |
| 2163 |
return |
| 2164 |
} |
| 2165 |
|
| 2166 |
$input.val(attributes.url).trigger('change') |
| 2167 |
}) |
| 2168 |
|
| 2169 |
wp_media_frame.open() |
| 2170 |
}) |
| 2171 |
|
| 2172 |
$remove_button.on('click', function (e) { |
| 2173 |
e.preventDefault() |
| 2174 |
$input.val('').trigger('change') |
| 2175 |
}) |
| 2176 |
}) |
| 2177 |
} |
| 2178 |
|
| 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 |
} |
| 2191 |
|
| 2192 |
var $this = $(this), |
| 2193 |
$editor = $this.find('.spf-wp-editor'), |
| 2194 |
$textarea = $this.find('textarea') |
| 2195 |
|
| 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 |
| 2200 |
|
| 2201 |
if ($has_wp_editor) { |
| 2202 |
$editor.empty() |
| 2203 |
$editor.append($textarea) |
| 2204 |
$textarea.css('display', '') |
| 2205 |
} |
| 2206 |
|
| 2207 |
// Generate a unique id |
| 2208 |
var uid = SP_PC.helper.uid('spf-editor-') |
| 2209 |
|
| 2210 |
$textarea.attr('id', uid) |
| 2211 |
|
| 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 |
} |
| 2217 |
|
| 2218 |
// Get default editor settings |
| 2219 |
var field_editor_settings = $editor.data('editor-settings') |
| 2220 |
|
| 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 |
} |
| 2231 |
|
| 2232 |
// Callback for old wp editor |
| 2233 |
var wpEditor = wp.oldEditor ? wp.oldEditor : wp.editor |
| 2234 |
|
| 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 |
} |
| 2240 |
|
| 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 |
) |
| 2247 |
|
| 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 |
} |
| 2253 |
|
| 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 |
} |
| 2259 |
|
| 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 |
}) |
| 2267 |
|
| 2268 |
// Add Media buttons |
| 2269 |
if (field_editor_settings.media_buttons && window.spf_media_buttons) { |
| 2270 |
var $editor_buttons = $editor.find('.wp-media-buttons') |
| 2271 |
|
| 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) |
| 2276 |
|
| 2277 |
$media_buttons.find('.spf-shortcode-button').data('editor-id', uid) |
| 2278 |
|
| 2279 |
$editor.prepend($media_buttons) |
| 2280 |
} |
| 2281 |
} |
| 2282 |
}) |
| 2283 |
} |
| 2284 |
|
| 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 |
| 2295 |
|
| 2296 |
if (!confirm_answer) { |
| 2297 |
e.preventDefault() |
| 2298 |
SP_PC.vars.is_confirm = false |
| 2299 |
|
| 2300 |
return false |
| 2301 |
} |
| 2302 |
}) |
| 2303 |
}) |
| 2304 |
} |
| 2305 |
|
| 2306 |
$.fn.serializeObject = function () { |
| 2307 |
var obj = {} |
| 2308 |
|
| 2309 |
$.each(this.serializeArray(), function (i, o) { |
| 2310 |
var n = o.name, |
| 2311 |
v = o.value |
| 2312 |
|
| 2313 |
obj[n] = |
| 2314 |
obj[n] === undefined |
| 2315 |
? v |
| 2316 |
: $.isArray(obj[n]) |
| 2317 |
? obj[n].concat(v) |
| 2318 |
: [obj[n], v] |
| 2319 |
}) |
| 2320 |
|
| 2321 |
return obj |
| 2322 |
} |
| 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 |
| 2334 |
|
| 2335 |
$this.on('click', function (e) { |
| 2336 |
if (!flooding) { |
| 2337 |
var $text = $this.data('save'), |
| 2338 |
$value = $this.val() |
| 2339 |
|
| 2340 |
$buttons.attr('value', $text) |
| 2341 |
|
| 2342 |
if ($this.hasClass('spf-save-ajax')) { |
| 2343 |
e.preventDefault() |
| 2344 |
|
| 2345 |
$panel.addClass('spf-saving') |
| 2346 |
$buttons.prop('disabled', true) |
| 2347 |
|
| 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) |
| 2354 |
|
| 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 |
nonce: $('#spf_pcp_metabox_noncesp_pcp_view_options').val() |
| 3038 |
} |
| 3039 |
$.post(ajaxurl, data, function (response) { |
| 3040 |
$('.sp_pcp_post_taxonomy select').html(response) |
| 3041 |
$('.sp_pcp_post_taxonomy select').trigger('chosen:updated') |
| 3042 |
}) |
| 3043 |
}) |
| 3044 |
// Update terms list on the change of post taxonomy. |
| 3045 |
$(document).on('change', '.sp_pcp_post_taxonomy select', function (e) { |
| 3046 |
e.preventDefault(); |
| 3047 |
var taxSelector = $(this) |
| 3048 |
var data = { |
| 3049 |
action: 'sps_get_terms', // Callback function. |
| 3050 |
pcp_post_taxonomy: $(this).val(), |
| 3051 |
nonce: $('#spf_pcp_metabox_noncesp_pcp_view_options').val() |
| 3052 |
} |
| 3053 |
$.ajax({ |
| 3054 |
type: "POST", |
| 3055 |
url: ajaxurl, |
| 3056 |
data: data, |
| 3057 |
error: function (response) { |
| 3058 |
console.log(response) |
| 3059 |
}, |
| 3060 |
success: function (response) { |
| 3061 |
$(taxSelector) |
| 3062 |
.parent() |
| 3063 |
.parent('.sp_pcp_post_taxonomy') |
| 3064 |
.next('.sp_pcp_taxonomy_terms') |
| 3065 |
.find('select') |
| 3066 |
.html(response) |
| 3067 |
$(taxSelector) |
| 3068 |
.parent() |
| 3069 |
.parent('.sp_pcp_post_taxonomy') |
| 3070 |
.next('.sp_pcp_taxonomy_terms') |
| 3071 |
.find('select') |
| 3072 |
.trigger('chosen:updated') |
| 3073 |
} |
| 3074 |
}) |
| 3075 |
}) |
| 3076 |
|
| 3077 |
// Populate specific post list in the drop-down. |
| 3078 |
var pt_saved_value = $('.sp_pcp_post_type select').val() |
| 3079 |
// Change Include only post_type on change of Post Type field. |
| 3080 |
var data_include_only = $('.sp_pcp_include_only_posts .spf-chosen-ajax').data( |
| 3081 |
'chosen-settings' |
| 3082 |
) |
| 3083 |
// Change Exclude post_type on change of Post Type field. |
| 3084 |
var data_exclude = $('.sp_pcp_exclude_posts .spf-chosen-ajax').data( |
| 3085 |
'chosen-settings' |
| 3086 |
) |
| 3087 |
if ($('.spf-nav').hasClass('spf-nav-metabox')) { |
| 3088 |
data_exclude.data.query_args.post_type = pt_saved_value |
| 3089 |
data_include_only.data.query_args.post_type = pt_saved_value |
| 3090 |
} |
| 3091 |
$('.sp_pcp_post_type select').change(function (event) { |
| 3092 |
event.preventDefault() |
| 3093 |
var pt_value = $(this).val() |
| 3094 |
// Change Include only post_type on change of Post Type field. |
| 3095 |
data_include_only.data.query_args.post_type = pt_value |
| 3096 |
// Change Exclude post_type on change of Post Type field. |
| 3097 |
data_exclude.data.query_args.post_type = pt_value |
| 3098 |
|
| 3099 |
// var data = { |
| 3100 |
// action: 'pcp_get_posts', // Callback function. |
| 3101 |
// pcp_post_type: $(this).val(), // Callback function's value. |
| 3102 |
// } |
| 3103 |
// $.post(ajaxurl, data, function (resp) { |
| 3104 |
// $('.sp_pcp_include_only_posts select').html(resp); |
| 3105 |
// $(".sp_pcp_include_only_posts select").trigger("chosen:updated"); |
| 3106 |
// $('.sp_pcp_exclude_posts select').html(resp); |
| 3107 |
// $(".sp_pcp_exclude_posts select").trigger("chosen:updated"); |
| 3108 |
// }); |
| 3109 |
}) |
| 3110 |
|
| 3111 |
/* Keep the accordion field's first item opened */ |
| 3112 |
$(window).load(function () { |
| 3113 |
$('.pcp-opened-accordion').each(function () { |
| 3114 |
if (!$(this).hasClass('hidden')) { |
| 3115 |
$(this).addClass('pcp_saved_filter') |
| 3116 |
} |
| 3117 |
}) |
| 3118 |
}) |
| 3119 |
$('.spf-field-checkbox.pcp_advanced_filter').change(function (event) { |
| 3120 |
$('.pcp-opened-accordion').each(function () { |
| 3121 |
if ($(this).hasClass('hidden')) { |
| 3122 |
$(this).removeClass('pcp_saved_filter') |
| 3123 |
} else { |
| 3124 |
$(this).addClass('pcp_saved_filter') |
| 3125 |
} |
| 3126 |
if (!$(this).hasClass('pcp_saved_filter')) { |
| 3127 |
if ( |
| 3128 |
$(this) |
| 3129 |
.find('.spf-accordion-title') |
| 3130 |
.siblings('.spf-accordion-content') |
| 3131 |
.hasClass('spf-accordion-open') |
| 3132 |
) { |
| 3133 |
$(this).find('.spf-accordion-title') |
| 3134 |
} else { |
| 3135 |
$(this) |
| 3136 |
.find('.spf-accordion-title') |
| 3137 |
.trigger('click') |
| 3138 |
$(this) |
| 3139 |
.find('.spf-accordion-content') |
| 3140 |
.find('.spf-cloneable-add') |
| 3141 |
.trigger('click') |
| 3142 |
} |
| 3143 |
} |
| 3144 |
}) |
| 3145 |
}) |
| 3146 |
|
| 3147 |
// Pro only tag. |
| 3148 |
$('.pcp-pagination-type li:nth-child(n+2) input' ).attr('disabled', true) |
| 3149 |
|
| 3150 |
$("label:contains((Pro))").css({'pointer-events': 'none', 'opacity': '0.8', 'user-select': 'none'}) |
| 3151 |
$("label:contains((Pro)) input").attr('disabled', true).css( 'opacity', '1') |
| 3152 |
$("select option:contains((Pro))").attr('disabled', true).css( 'opacity', '1') |
| 3153 |
// Image custom size. |
| 3154 |
// Post Meta fields 5th to last. |
| 3155 |
// Post content type with limit. |
| 3156 |
$('.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') |
| 3157 |
.attr('disabled', true) |
| 3158 |
.css('pointer-events', 'none') |
| 3159 |
|
| 3160 |
$('.post_content_sorter .spf--sortable-item:has(div.pcp-pro-only)').css({"pointer-events": "none", "borderColor": "#bebebe"}); |
| 3161 |
$('.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"}); |
| 3162 |
$('.post_content_sorter .spf--sortable-item:has(div.pcp-pro-only)').find('.spf--sortable-helper .fa').css("color", "#777"); |
| 3163 |
|
| 3164 |
|
| 3165 |
|
| 3166 |
var preview_box = $('#spsp-preview-box'); |
| 3167 |
var pcp_display = $('#sp_pcp_display').hide(); |
| 3168 |
|
| 3169 |
// $('#spsp-show-preview:contains(Hide)'). |
| 3170 |
$(document).on('click','#spsp-show-preview:contains(Hide)', function (e) { |
| 3171 |
e.preventDefault(); |
| 3172 |
var _this = $( this ); |
| 3173 |
_this.html('<i class="fa fa-eye" aria-hidden="true"></i> Show Preview'); |
| 3174 |
preview_box.html(''); |
| 3175 |
pcp_display.hide(); |
| 3176 |
}); |
| 3177 |
$(document).on('click', '#spsp-show-preview:not(:contains(Hide))', function (e) { |
| 3178 |
e.preventDefault(); |
| 3179 |
/// console.log(ajaxurl); |
| 3180 |
var _data = $( 'form#post' ).serialize(); |
| 3181 |
var _this = $( this ); |
| 3182 |
// console.log(_data); |
| 3183 |
var $sp_id = $(this).data('id'); |
| 3184 |
var data = { |
| 3185 |
action: 'spf_preview_meta_box', |
| 3186 |
id: $sp_id, |
| 3187 |
data: _data, |
| 3188 |
nonce: $('#spf_pcp_metabox_noncesp_pcp_view_options').val() |
| 3189 |
}; |
| 3190 |
$.ajax({ |
| 3191 |
type: "POST", |
| 3192 |
url: ajaxurl, |
| 3193 |
data: data, |
| 3194 |
error: function (response) { |
| 3195 |
console.log(response) |
| 3196 |
}, |
| 3197 |
success: function (response) { |
| 3198 |
pcp_display.show(); |
| 3199 |
preview_box.html(response); |
| 3200 |
|
| 3201 |
_this.html('<i class="fa fa-eye-slash" aria-hidden="true"></i> Hide Preview'); |
| 3202 |
// console.log(response) |
| 3203 |
$(document).on('change', '#sp_pcp_view_options', function (e) { |
| 3204 |
e.preventDefault(); |
| 3205 |
// if(_this.html().indexOf('Hide')){ |
| 3206 |
_this.html('<i class="fa fa-refresh" aria-hidden="true"></i> Update Preview'); |
| 3207 |
// } |
| 3208 |
|
| 3209 |
// console.log(_this+ ':conatain(hide)'); |
| 3210 |
// console.log($('#spsp-show-preview:contains(Hide)')); |
| 3211 |
}); |
| 3212 |
$(document).on('change', '#spf-section-sp_pcp_layouts_1', function (e) { |
| 3213 |
e.preventDefault(); |
| 3214 |
// if(_this.html().indexOf('Hide')){ |
| 3215 |
_this.html('<i class="fa fa-refresh" aria-hidden="true"></i> Update Preview'); |
| 3216 |
// } |
| 3217 |
|
| 3218 |
}); |
| 3219 |
$("html, body").animate({ scrollTop: pcp_display.offset().top - 50 }, "slow"); |
| 3220 |
// $("html, body").animate({ scrollTop: 50}, "slow"); |
| 3221 |
} |
| 3222 |
}) |
| 3223 |
}); |
| 3224 |
|
| 3225 |
// Smart-post-show export. |
| 3226 |
var $export_type = $('.pcp_what_export').find('input:checked').val(); |
| 3227 |
$('.pcp_what_export').on('change', function () { |
| 3228 |
$export_type = $(this).find('input:checked').val(); |
| 3229 |
}); |
| 3230 |
|
| 3231 |
$('.pcp_export .spf--button').click(function (event) { |
| 3232 |
event.preventDefault(); |
| 3233 |
|
| 3234 |
var $shortcode_ids = $('.pcp_post_ids select').val(); |
| 3235 |
var $ex_nonce = $('#spf_options_noncesp_post_carousel_tools').val(); |
| 3236 |
var selected_shortcode = $export_type === 'selected_shortcodes' ? $shortcode_ids : 'all_shortcodes'; |
| 3237 |
if ($export_type === 'all_shortcodes' || $export_type === 'selected_shortcodes') { |
| 3238 |
var data = { |
| 3239 |
action: 'pcp_export_shortcodes', |
| 3240 |
pcp_ids: selected_shortcode, |
| 3241 |
nonce: $ex_nonce, |
| 3242 |
} |
| 3243 |
} else { |
| 3244 |
$('.spf-form-result.spf-form-success').text('No carousel selected.').show(); |
| 3245 |
setTimeout(function () { |
| 3246 |
$('.spf-form-result.spf-form-success').hide().text(''); |
| 3247 |
}, 3000); |
| 3248 |
} |
| 3249 |
$.post(ajaxurl, data, function (resp) { |
| 3250 |
if (resp) { |
| 3251 |
// Convert JSON Array to string. |
| 3252 |
var json = JSON.stringify(resp); |
| 3253 |
// Convert JSON string to BLOB. |
| 3254 |
json = [json]; |
| 3255 |
var blob = new Blob(json); |
| 3256 |
var link = document.createElement('a'); |
| 3257 |
var pcp_time = $.now(); |
| 3258 |
link.href = window.URL.createObjectURL(blob); |
| 3259 |
link.download = "smart-post-show-" + pcp_time + ".json"; |
| 3260 |
link.click(); |
| 3261 |
$('.spf-form-result.spf-form-success').text('Exported successfully!').show(); |
| 3262 |
setTimeout(function () { |
| 3263 |
$('.spf-form-result.spf-form-success').hide().text(''); |
| 3264 |
$('.pcp_post_ids select').val('').trigger('chosen:updated'); |
| 3265 |
}, 3000); |
| 3266 |
} |
| 3267 |
}); |
| 3268 |
}); |
| 3269 |
// smart-post-show import. |
| 3270 |
$('.pcp_import button.import').click(function (event) { |
| 3271 |
event.preventDefault(); |
| 3272 |
var pcp_shortcodes = $('#import').prop('files')[0]; |
| 3273 |
if ($('#import').val() != '') { |
| 3274 |
var $im_nonce = $('#spf_options_noncesp_post_carousel_tools').val(); |
| 3275 |
var reader = new FileReader(); |
| 3276 |
reader.readAsText(pcp_shortcodes); |
| 3277 |
reader.onload = function (event) { |
| 3278 |
var jsonObj = JSON.stringify(event.target.result); |
| 3279 |
$.ajax({ |
| 3280 |
url: ajaxurl, |
| 3281 |
type: 'POST', |
| 3282 |
data: { |
| 3283 |
shortcode: jsonObj, |
| 3284 |
action: 'pcp_import_shortcodes', |
| 3285 |
nonce: $im_nonce, |
| 3286 |
}, |
| 3287 |
success: function (resp) { |
| 3288 |
$('.spf-form-result.spf-form-success').text('Imported successfully!').show(); |
| 3289 |
setTimeout(function () { |
| 3290 |
$('.spf-form-result.spf-form-success').hide().text(''); |
| 3291 |
$('#import').val(''); |
| 3292 |
window.location.replace($('#pcp_shortcode_link_redirect').attr('href')); |
| 3293 |
}, 2000); |
| 3294 |
} |
| 3295 |
}); |
| 3296 |
} |
| 3297 |
} else { |
| 3298 |
$('.spf-form-result.spf-form-success').text('No exported json file chosen.').show(); |
| 3299 |
setTimeout(function () { |
| 3300 |
$('.spf-form-result.spf-form-success').hide().text(''); |
| 3301 |
}, 3000); |
| 3302 |
} |
| 3303 |
}); |
| 3304 |
|
| 3305 |
})(jQuery, window, document) |