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