| 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 |
// |
| 572 |
// Field: code_editor |
| 573 |
// |
| 574 |
$.fn.darkify_field_code_editor = function () { |
| 575 |
return this.each(function () { |
| 576 |
|
| 577 |
if (typeof CodeMirror !== 'function') { return; } |
| 578 |
|
| 579 |
var $this = $(this), |
| 580 |
$textarea = $this.find('textarea'), |
| 581 |
$inited = $this.find('.CodeMirror'), |
| 582 |
data_editor = $textarea.data('editor'); |
| 583 |
|
| 584 |
if ($inited.length) { |
| 585 |
$inited.remove(); |
| 586 |
} |
| 587 |
|
| 588 |
var interval = setInterval(function () { |
| 589 |
if ($this.is(':visible')) { |
| 590 |
|
| 591 |
var code_editor = CodeMirror.fromTextArea($textarea[0], data_editor); |
| 592 |
|
| 593 |
// load code-mirror theme css. |
| 594 |
if (data_editor.theme !== 'default' && DARKIFY.vars.code_themes.indexOf(data_editor.theme) === -1) { |
| 595 |
|
| 596 |
var $cssLink = $('<link>'); |
| 597 |
|
| 598 |
$('#darkify-codemirror-css').after($cssLink); |
| 599 |
|
| 600 |
$cssLink.attr({ |
| 601 |
rel: 'stylesheet', |
| 602 |
id: 'darkify-codemirror-' + data_editor.theme + '-css', |
| 603 |
href: data_editor.cdnURL + '/css/' + data_editor.theme + '.min.css', |
| 604 |
type: 'text/css', |
| 605 |
media: 'all' |
| 606 |
}); |
| 607 |
|
| 608 |
DARKIFY.vars.code_themes.push(data_editor.theme); |
| 609 |
|
| 610 |
} |
| 611 |
|
| 612 |
CodeMirror.modeURL = data_editor.cdnURL + '/js/%N.min.js'; |
| 613 |
CodeMirror.autoLoadMode(code_editor, data_editor.mode); |
| 614 |
|
| 615 |
code_editor.on('change', function (editor, event) { |
| 616 |
$textarea.val(code_editor.getValue()).trigger('change'); |
| 617 |
}); |
| 618 |
|
| 619 |
clearInterval(interval); |
| 620 |
|
| 621 |
} |
| 622 |
}); |
| 623 |
|
| 624 |
}); |
| 625 |
}; |
| 626 |
|
| 627 |
// |
| 628 |
// Field: date |
| 629 |
// |
| 630 |
$.fn.darkify_field_date = function () { |
| 631 |
return this.each(function () { |
| 632 |
|
| 633 |
var $this = $(this), |
| 634 |
$inputs = $this.find('input'), |
| 635 |
settings = $this.find('.darkify-date-settings').data('settings'), |
| 636 |
wrapper = '<div class="darkify-datepicker-wrapper"></div>'; |
| 637 |
|
| 638 |
var defaults = { |
| 639 |
showAnim: '', |
| 640 |
beforeShow: function (input, inst) { |
| 641 |
$(inst.dpDiv).addClass('darkify-datepicker-wrapper'); |
| 642 |
}, |
| 643 |
onClose: function (input, inst) { |
| 644 |
$(inst.dpDiv).removeClass('darkify-datepicker-wrapper'); |
| 645 |
}, |
| 646 |
}; |
| 647 |
|
| 648 |
settings = $.extend({}, settings, defaults); |
| 649 |
|
| 650 |
if ($inputs.length === 2) { |
| 651 |
|
| 652 |
settings = $.extend({}, settings, { |
| 653 |
onSelect: function (selectedDate) { |
| 654 |
|
| 655 |
var $this = $(this), |
| 656 |
$from = $inputs.first(), |
| 657 |
option = ($inputs.first().attr('id') === $(this).attr('id')) ? 'minDate' : 'maxDate', |
| 658 |
date = $.datepicker.parseDate(settings.dateFormat, selectedDate); |
| 659 |
|
| 660 |
$inputs.not(this).datepicker('option', option, date); |
| 661 |
|
| 662 |
} |
| 663 |
}); |
| 664 |
|
| 665 |
} |
| 666 |
|
| 667 |
$inputs.each(function () { |
| 668 |
|
| 669 |
var $input = $(this); |
| 670 |
|
| 671 |
if ($input.hasClass('hasDatepicker')) { |
| 672 |
$input.removeAttr('id').removeClass('hasDatepicker'); |
| 673 |
} |
| 674 |
|
| 675 |
$input.datepicker(settings); |
| 676 |
|
| 677 |
}); |
| 678 |
|
| 679 |
}); |
| 680 |
}; |
| 681 |
|
| 682 |
// |
| 683 |
// Field: datetime |
| 684 |
// |
| 685 |
$.fn.darkify_field_datetime = function () { |
| 686 |
return this.each(function () { |
| 687 |
|
| 688 |
var $this = $(this), |
| 689 |
$inputs = $this.find('input'), |
| 690 |
settings = $this.find('.darkify-datetime-settings').data('settings'); |
| 691 |
|
| 692 |
settings = $.extend({}, settings, { |
| 693 |
onReady: function (selectedDates, dateStr, instance) { |
| 694 |
$(instance.calendarContainer).addClass('darkify-flatpickr'); |
| 695 |
}, |
| 696 |
}); |
| 697 |
|
| 698 |
if ($inputs.length === 2) { |
| 699 |
settings = $.extend({}, settings, { |
| 700 |
onChange: function (selectedDates, dateStr, instance) { |
| 701 |
if ($(instance.element).data('type') === 'from') { |
| 702 |
$inputs.last().get(0)._flatpickr.set('minDate', selectedDates[0]); |
| 703 |
} else { |
| 704 |
$inputs.first().get(0)._flatpickr.set('maxDate', selectedDates[0]); |
| 705 |
} |
| 706 |
}, |
| 707 |
}); |
| 708 |
} |
| 709 |
|
| 710 |
$inputs.each(function () { |
| 711 |
$(this).flatpickr(settings); |
| 712 |
}); |
| 713 |
|
| 714 |
}); |
| 715 |
}; |
| 716 |
|
| 717 |
// |
| 718 |
// Field: fieldset |
| 719 |
// |
| 720 |
$.fn.darkify_field_fieldset = function () { |
| 721 |
return this.each(function () { |
| 722 |
$(this).find('.darkify-fieldset-content').darkify_reload_script(); |
| 723 |
}); |
| 724 |
}; |
| 725 |
|
| 726 |
// |
| 727 |
// Field: gallery |
| 728 |
// |
| 729 |
$.fn.darkify_field_gallery = function () { |
| 730 |
return this.each(function () { |
| 731 |
|
| 732 |
var $this = $(this), |
| 733 |
$edit = $this.find('.darkify-edit-gallery'), |
| 734 |
$clear = $this.find('.darkify-clear-gallery'), |
| 735 |
$list = $this.find('ul'), |
| 736 |
$input = $this.find('input'), |
| 737 |
$img = $this.find('img'), |
| 738 |
wp_media_frame; |
| 739 |
|
| 740 |
$this.on('click', '.darkify-button, .darkify-edit-gallery', function (e) { |
| 741 |
|
| 742 |
var $el = $(this), |
| 743 |
ids = $input.val(), |
| 744 |
what = ($el.hasClass('darkify-edit-gallery')) ? 'edit' : 'add', |
| 745 |
state = (what === 'add' && !ids.length) ? 'gallery' : 'gallery-edit'; |
| 746 |
|
| 747 |
e.preventDefault(); |
| 748 |
|
| 749 |
if (typeof window.wp === 'undefined' || !window.wp.media || !window.wp.media.gallery) { return; } |
| 750 |
|
| 751 |
// Open media with state |
| 752 |
if (state === 'gallery') { |
| 753 |
|
| 754 |
wp_media_frame = window.wp.media({ |
| 755 |
library: { |
| 756 |
type: 'image' |
| 757 |
}, |
| 758 |
frame: 'post', |
| 759 |
state: 'gallery', |
| 760 |
multiple: true |
| 761 |
}); |
| 762 |
|
| 763 |
wp_media_frame.open(); |
| 764 |
|
| 765 |
} else { |
| 766 |
|
| 767 |
wp_media_frame = window.wp.media.gallery.edit('[gallery ids="' + ids + '"]'); |
| 768 |
|
| 769 |
if (what === 'add') { |
| 770 |
wp_media_frame.setState('gallery-library'); |
| 771 |
} |
| 772 |
|
| 773 |
} |
| 774 |
|
| 775 |
// Media Update |
| 776 |
wp_media_frame.on('update', function (selection) { |
| 777 |
|
| 778 |
$list.empty(); |
| 779 |
|
| 780 |
var selectedIds = selection.models.map(function (attachment) { |
| 781 |
|
| 782 |
var item = attachment.toJSON(); |
| 783 |
var thumb = (item.sizes && item.sizes.thumbnail && item.sizes.thumbnail.url) ? item.sizes.thumbnail.url : item.url; |
| 784 |
|
| 785 |
$list.append('<li><img src="' + thumb + '"></li>'); |
| 786 |
|
| 787 |
return item.id; |
| 788 |
|
| 789 |
}); |
| 790 |
|
| 791 |
$input.val(selectedIds.join(',')).trigger('change'); |
| 792 |
$clear.removeClass('hidden'); |
| 793 |
$edit.removeClass('hidden'); |
| 794 |
|
| 795 |
}); |
| 796 |
|
| 797 |
}); |
| 798 |
|
| 799 |
$clear.on('click', function (e) { |
| 800 |
e.preventDefault(); |
| 801 |
$list.empty(); |
| 802 |
$input.val('').trigger('change'); |
| 803 |
$clear.addClass('hidden'); |
| 804 |
$edit.addClass('hidden'); |
| 805 |
}); |
| 806 |
|
| 807 |
}); |
| 808 |
|
| 809 |
}; |
| 810 |
|
| 811 |
// |
| 812 |
// Field: group |
| 813 |
// |
| 814 |
$.fn.darkify_field_group = function () { |
| 815 |
return this.each(function () { |
| 816 |
|
| 817 |
var $this = $(this), |
| 818 |
$fieldset = $this.children('.darkify-fieldset'), |
| 819 |
$group = $fieldset.length ? $fieldset : $this, |
| 820 |
$wrapper = $group.children('.darkify-cloneable-wrapper'), |
| 821 |
$hidden = $group.children('.darkify-cloneable-hidden'), |
| 822 |
$max = $group.children('.darkify-cloneable-max'), |
| 823 |
$min = $group.children('.darkify-cloneable-min'), |
| 824 |
title_by = $wrapper.data('title-by'), |
| 825 |
title_prefix = $wrapper.data('title-by-prefix'), |
| 826 |
field_id = $wrapper.data('field-id'), |
| 827 |
is_number = Boolean(Number($wrapper.data('title-number'))), |
| 828 |
max = parseInt($wrapper.data('max')), |
| 829 |
min = parseInt($wrapper.data('min')); |
| 830 |
|
| 831 |
// clear accordion arrows if multi-instance |
| 832 |
if ($wrapper.hasClass('ui-accordion')) { |
| 833 |
$wrapper.find('.ui-accordion-header-icon').remove(); |
| 834 |
} |
| 835 |
|
| 836 |
var update_title_numbers = function ($selector) { |
| 837 |
$selector.find('.darkify-cloneable-title-number').each(function (index) { |
| 838 |
$(this).html(($(this).closest('.darkify-cloneable-item').index() + 1) + '.'); |
| 839 |
}); |
| 840 |
}; |
| 841 |
|
| 842 |
$wrapper.accordion({ |
| 843 |
header: '> .darkify-cloneable-item > .darkify-cloneable-title', |
| 844 |
collapsible: true, |
| 845 |
active: false, |
| 846 |
animate: false, |
| 847 |
heightStyle: 'content', |
| 848 |
icons: { |
| 849 |
'header': 'darkify-cloneable-header-icon fas fa-angle-right', |
| 850 |
'activeHeader': 'darkify-cloneable-header-icon fas fa-angle-down' |
| 851 |
}, |
| 852 |
activate: function (event, ui) { |
| 853 |
|
| 854 |
var $panel = ui.newPanel; |
| 855 |
var $header = ui.newHeader; |
| 856 |
|
| 857 |
if ($panel.length && !$panel.data('opened')) { |
| 858 |
|
| 859 |
var $title = $header.find('.darkify-cloneable-value'); |
| 860 |
var inputs = []; |
| 861 |
|
| 862 |
$.each(title_by, function (key, title_key) { |
| 863 |
inputs.push($panel.find('[data-depend-id="' + title_key + '"]')); |
| 864 |
}); |
| 865 |
|
| 866 |
$.each(inputs, function (key, $input) { |
| 867 |
|
| 868 |
$input.on('change keyup darkify.keyup', function () { |
| 869 |
|
| 870 |
var titles = []; |
| 871 |
|
| 872 |
$.each(inputs, function (key, $input) { |
| 873 |
|
| 874 |
var input_value = $input.val(); |
| 875 |
|
| 876 |
if (input_value) { |
| 877 |
titles.push(input_value); |
| 878 |
} |
| 879 |
|
| 880 |
}); |
| 881 |
|
| 882 |
if (titles.length) { |
| 883 |
$title.text(titles.join(title_prefix)); |
| 884 |
} |
| 885 |
|
| 886 |
}).trigger('darkify.keyup'); |
| 887 |
|
| 888 |
}); |
| 889 |
|
| 890 |
$panel.darkify_reload_script(); |
| 891 |
$panel.data('opened', true); |
| 892 |
$panel.data('retry', false); |
| 893 |
|
| 894 |
} else if ($panel.data('retry')) { |
| 895 |
|
| 896 |
$panel.darkify_reload_script_retry(); |
| 897 |
$panel.data('retry', false); |
| 898 |
|
| 899 |
} |
| 900 |
|
| 901 |
} |
| 902 |
}); |
| 903 |
|
| 904 |
$wrapper.sortable({ |
| 905 |
axis: 'y', |
| 906 |
handle: '.darkify-cloneable-title,.darkify-cloneable-sort', |
| 907 |
helper: 'original', |
| 908 |
cursor: 'move', |
| 909 |
placeholder: 'widget-placeholder', |
| 910 |
start: function (event, ui) { |
| 911 |
|
| 912 |
$wrapper.accordion({ active: false }); |
| 913 |
$wrapper.sortable('refreshPositions'); |
| 914 |
ui.item.children('.darkify-cloneable-content').data('retry', true); |
| 915 |
|
| 916 |
}, |
| 917 |
update: function (event, ui) { |
| 918 |
|
| 919 |
DARKIFY.helper.name_nested_replace($wrapper.children('.darkify-cloneable-item'), field_id); |
| 920 |
$wrapper.darkify_customizer_refresh(); |
| 921 |
|
| 922 |
if (is_number) { |
| 923 |
update_title_numbers($wrapper); |
| 924 |
} |
| 925 |
|
| 926 |
}, |
| 927 |
}); |
| 928 |
|
| 929 |
$group.children('.darkify-cloneable-add').on('click', function (e) { |
| 930 |
|
| 931 |
e.preventDefault(); |
| 932 |
|
| 933 |
var count = $wrapper.children('.darkify-cloneable-item').length; |
| 934 |
|
| 935 |
$min.hide(); |
| 936 |
|
| 937 |
if (max && (count + 1) > max) { |
| 938 |
$max.show(); |
| 939 |
return; |
| 940 |
} |
| 941 |
|
| 942 |
var $cloned_item = $hidden.darkify_clone(true); |
| 943 |
|
| 944 |
$cloned_item.removeClass('darkify-cloneable-hidden'); |
| 945 |
|
| 946 |
$cloned_item.find(':input[name!="_pseudo"]').each(function () { |
| 947 |
this.name = this.name.replace('___', '').replace(field_id + '[0]', field_id + '[' + count + ']'); |
| 948 |
}); |
| 949 |
|
| 950 |
$wrapper.append($cloned_item); |
| 951 |
$wrapper.accordion('refresh'); |
| 952 |
$wrapper.accordion({ active: count }); |
| 953 |
$wrapper.darkify_customizer_refresh(); |
| 954 |
$wrapper.darkify_customizer_listen({ closest: true }); |
| 955 |
|
| 956 |
if (is_number) { |
| 957 |
update_title_numbers($wrapper); |
| 958 |
} |
| 959 |
|
| 960 |
}); |
| 961 |
|
| 962 |
var event_clone = function (e) { |
| 963 |
|
| 964 |
e.preventDefault(); |
| 965 |
|
| 966 |
var count = $wrapper.children('.darkify-cloneable-item').length; |
| 967 |
|
| 968 |
$min.hide(); |
| 969 |
|
| 970 |
if (max && (count + 1) > max) { |
| 971 |
$max.show(); |
| 972 |
return; |
| 973 |
} |
| 974 |
|
| 975 |
var $this = $(this), |
| 976 |
$parent = $this.parent().parent(), |
| 977 |
$cloned_helper = $parent.children('.darkify-cloneable-helper').darkify_clone(true), |
| 978 |
$cloned_title = $parent.children('.darkify-cloneable-title').darkify_clone(), |
| 979 |
$cloned_content = $parent.children('.darkify-cloneable-content').darkify_clone(), |
| 980 |
$cloned_item = $('<div class="darkify-cloneable-item" />'); |
| 981 |
|
| 982 |
$cloned_item.append($cloned_helper); |
| 983 |
$cloned_item.append($cloned_title); |
| 984 |
$cloned_item.append($cloned_content); |
| 985 |
|
| 986 |
$wrapper.children().eq($parent.index()).after($cloned_item); |
| 987 |
|
| 988 |
DARKIFY.helper.name_nested_replace($wrapper.children('.darkify-cloneable-item'), field_id); |
| 989 |
|
| 990 |
$wrapper.accordion('refresh'); |
| 991 |
$wrapper.darkify_customizer_refresh(); |
| 992 |
$wrapper.darkify_customizer_listen({ closest: true }); |
| 993 |
|
| 994 |
if (is_number) { |
| 995 |
update_title_numbers($wrapper); |
| 996 |
} |
| 997 |
|
| 998 |
}; |
| 999 |
|
| 1000 |
$wrapper.children('.darkify-cloneable-item').children('.darkify-cloneable-helper').on('click', '.darkify-cloneable-clone', event_clone); |
| 1001 |
$group.children('.darkify-cloneable-hidden').children('.darkify-cloneable-helper').on('click', '.darkify-cloneable-clone', event_clone); |
| 1002 |
|
| 1003 |
var event_remove = function (e) { |
| 1004 |
|
| 1005 |
e.preventDefault(); |
| 1006 |
|
| 1007 |
var count = $wrapper.children('.darkify-cloneable-item').length; |
| 1008 |
|
| 1009 |
$max.hide(); |
| 1010 |
$min.hide(); |
| 1011 |
|
| 1012 |
if (min && (count - 1) < min) { |
| 1013 |
$min.show(); |
| 1014 |
return; |
| 1015 |
} |
| 1016 |
|
| 1017 |
$(this).closest('.darkify-cloneable-item').remove(); |
| 1018 |
|
| 1019 |
DARKIFY.helper.name_nested_replace($wrapper.children('.darkify-cloneable-item'), field_id); |
| 1020 |
|
| 1021 |
$wrapper.darkify_customizer_refresh(); |
| 1022 |
|
| 1023 |
if (is_number) { |
| 1024 |
update_title_numbers($wrapper); |
| 1025 |
} |
| 1026 |
|
| 1027 |
}; |
| 1028 |
|
| 1029 |
$wrapper.children('.darkify-cloneable-item').children('.darkify-cloneable-helper').on('click', '.darkify-cloneable-remove', event_remove); |
| 1030 |
$group.children('.darkify-cloneable-hidden').children('.darkify-cloneable-helper').on('click', '.darkify-cloneable-remove', event_remove); |
| 1031 |
|
| 1032 |
}); |
| 1033 |
}; |
| 1034 |
|
| 1035 |
// |
| 1036 |
// Field: icon |
| 1037 |
// |
| 1038 |
$.fn.darkify_field_icon = function () { |
| 1039 |
return this.each(function () { |
| 1040 |
|
| 1041 |
var $this = $(this); |
| 1042 |
|
| 1043 |
$this.on('click', '.darkify-icon-add', function (e) { |
| 1044 |
|
| 1045 |
e.preventDefault(); |
| 1046 |
|
| 1047 |
var $button = $(this); |
| 1048 |
var $modal = $('#darkify-modal-icon'); |
| 1049 |
|
| 1050 |
$modal.removeClass('hidden'); |
| 1051 |
|
| 1052 |
DARKIFY.vars.$icon_target = $this; |
| 1053 |
|
| 1054 |
if (!DARKIFY.vars.icon_modal_loaded) { |
| 1055 |
|
| 1056 |
$modal.find('.darkify-modal-loading').show(); |
| 1057 |
|
| 1058 |
window.wp.ajax.post('darkify-get-icons', { |
| 1059 |
nonce: $button.data('nonce') |
| 1060 |
}).done(function (response) { |
| 1061 |
|
| 1062 |
$modal.find('.darkify-modal-loading').hide(); |
| 1063 |
|
| 1064 |
DARKIFY.vars.icon_modal_loaded = true; |
| 1065 |
|
| 1066 |
var $load = $modal.find('.darkify-modal-load').html(response.content); |
| 1067 |
|
| 1068 |
$load.on('click', 'i', function (e) { |
| 1069 |
|
| 1070 |
e.preventDefault(); |
| 1071 |
|
| 1072 |
var icon = $(this).attr('title'); |
| 1073 |
|
| 1074 |
DARKIFY.vars.$icon_target.find('.darkify-icon-preview i').removeAttr('class').addClass(icon); |
| 1075 |
DARKIFY.vars.$icon_target.find('.darkify-icon-preview').removeClass('hidden'); |
| 1076 |
DARKIFY.vars.$icon_target.find('.darkify-icon-remove').removeClass('hidden'); |
| 1077 |
DARKIFY.vars.$icon_target.find('input').val(icon).trigger('change'); |
| 1078 |
|
| 1079 |
$modal.addClass('hidden'); |
| 1080 |
|
| 1081 |
}); |
| 1082 |
|
| 1083 |
$modal.on('change keyup', '.darkify-icon-search', function () { |
| 1084 |
|
| 1085 |
var value = $(this).val(), |
| 1086 |
$icons = $load.find('i'); |
| 1087 |
|
| 1088 |
$icons.each(function () { |
| 1089 |
|
| 1090 |
var $elem = $(this); |
| 1091 |
|
| 1092 |
if ($elem.attr('title').search(new RegExp(value, 'i')) < 0) { |
| 1093 |
$elem.hide(); |
| 1094 |
} else { |
| 1095 |
$elem.show(); |
| 1096 |
} |
| 1097 |
|
| 1098 |
}); |
| 1099 |
|
| 1100 |
}); |
| 1101 |
|
| 1102 |
$modal.on('click', '.darkify-modal-close, .darkify-modal-overlay', function () { |
| 1103 |
$modal.addClass('hidden'); |
| 1104 |
}); |
| 1105 |
|
| 1106 |
}).fail(function (response) { |
| 1107 |
$modal.find('.darkify-modal-loading').hide(); |
| 1108 |
$modal.find('.darkify-modal-load').html(response.error); |
| 1109 |
$modal.on('click', function () { |
| 1110 |
$modal.addClass('hidden'); |
| 1111 |
}); |
| 1112 |
}); |
| 1113 |
} |
| 1114 |
|
| 1115 |
}); |
| 1116 |
|
| 1117 |
$this.on('click', '.darkify-icon-remove', function (e) { |
| 1118 |
e.preventDefault(); |
| 1119 |
$this.find('.darkify-icon-preview').addClass('hidden'); |
| 1120 |
$this.find('input').val('').trigger('change'); |
| 1121 |
$(this).addClass('hidden'); |
| 1122 |
}); |
| 1123 |
|
| 1124 |
}); |
| 1125 |
}; |
| 1126 |
|
| 1127 |
// |
| 1128 |
// Field: map |
| 1129 |
// |
| 1130 |
$.fn.darkify_field_map = function () { |
| 1131 |
return this.each(function () { |
| 1132 |
|
| 1133 |
if (typeof L === 'undefined') { return; } |
| 1134 |
|
| 1135 |
var $this = $(this), |
| 1136 |
$map = $this.find('.darkify--map-osm'), |
| 1137 |
$search_input = $this.find('.darkify--map-search input'), |
| 1138 |
$latitude = $this.find('.darkify--latitude'), |
| 1139 |
$longitude = $this.find('.darkify--longitude'), |
| 1140 |
$zoom = $this.find('.darkify--zoom'), |
| 1141 |
map_data = $map.data('map'); |
| 1142 |
|
| 1143 |
var mapInit = L.map($map.get(0), map_data); |
| 1144 |
|
| 1145 |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
| 1146 |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
| 1147 |
}).addTo(mapInit); |
| 1148 |
|
| 1149 |
var mapMarker = L.marker(map_data.center, { draggable: true }).addTo(mapInit); |
| 1150 |
|
| 1151 |
var update_latlng = function (data) { |
| 1152 |
$latitude.val(data.lat); |
| 1153 |
$longitude.val(data.lng); |
| 1154 |
$zoom.val(mapInit.getZoom()); |
| 1155 |
}; |
| 1156 |
|
| 1157 |
mapInit.on('click', function (data) { |
| 1158 |
mapMarker.setLatLng(data.latlng); |
| 1159 |
update_latlng(data.latlng); |
| 1160 |
}); |
| 1161 |
|
| 1162 |
mapInit.on('zoom', function () { |
| 1163 |
update_latlng(mapMarker.getLatLng()); |
| 1164 |
}); |
| 1165 |
|
| 1166 |
mapMarker.on('drag', function () { |
| 1167 |
update_latlng(mapMarker.getLatLng()); |
| 1168 |
}); |
| 1169 |
|
| 1170 |
if (!$search_input.length) { |
| 1171 |
$search_input = $('[data-depend-id="' + $this.find('.darkify--address-field').data('address-field') + '"]'); |
| 1172 |
} |
| 1173 |
|
| 1174 |
var cache = {}; |
| 1175 |
|
| 1176 |
$search_input.autocomplete({ |
| 1177 |
source: function (request, response) { |
| 1178 |
|
| 1179 |
var term = request.term; |
| 1180 |
|
| 1181 |
if (term in cache) { |
| 1182 |
response(cache[term]); |
| 1183 |
return; |
| 1184 |
} |
| 1185 |
|
| 1186 |
$.get('https://nominatim.openstreetmap.org/search', { |
| 1187 |
format: 'json', |
| 1188 |
q: term, |
| 1189 |
}, function (results) { |
| 1190 |
|
| 1191 |
var data; |
| 1192 |
|
| 1193 |
if (results.length) { |
| 1194 |
data = results.map(function (item) { |
| 1195 |
return { |
| 1196 |
value: item.display_name, |
| 1197 |
label: item.display_name, |
| 1198 |
lat: item.lat, |
| 1199 |
lon: item.lon |
| 1200 |
}; |
| 1201 |
}, 'json'); |
| 1202 |
} else { |
| 1203 |
data = [{ |
| 1204 |
value: 'no-data', |
| 1205 |
label: 'No Results.' |
| 1206 |
}]; |
| 1207 |
} |
| 1208 |
|
| 1209 |
cache[term] = data; |
| 1210 |
response(data); |
| 1211 |
|
| 1212 |
}); |
| 1213 |
|
| 1214 |
}, |
| 1215 |
select: function (event, ui) { |
| 1216 |
|
| 1217 |
if (ui.item.value === 'no-data') { return false; } |
| 1218 |
|
| 1219 |
var latLng = L.latLng(ui.item.lat, ui.item.lon); |
| 1220 |
|
| 1221 |
mapInit.panTo(latLng); |
| 1222 |
mapMarker.setLatLng(latLng); |
| 1223 |
update_latlng(latLng); |
| 1224 |
|
| 1225 |
}, |
| 1226 |
create: function (event, ui) { |
| 1227 |
$(this).autocomplete('widget').addClass('darkify-map-ui-autocomplate'); |
| 1228 |
} |
| 1229 |
}); |
| 1230 |
|
| 1231 |
var input_update_latlng = function () { |
| 1232 |
|
| 1233 |
var latLng = L.latLng($latitude.val(), $longitude.val()); |
| 1234 |
|
| 1235 |
mapInit.panTo(latLng); |
| 1236 |
mapMarker.setLatLng(latLng); |
| 1237 |
|
| 1238 |
}; |
| 1239 |
|
| 1240 |
$latitude.on('change', input_update_latlng); |
| 1241 |
$longitude.on('change', input_update_latlng); |
| 1242 |
|
| 1243 |
}); |
| 1244 |
}; |
| 1245 |
|
| 1246 |
// |
| 1247 |
// Field: link |
| 1248 |
// |
| 1249 |
$.fn.darkify_field_link = function () { |
| 1250 |
return this.each(function () { |
| 1251 |
|
| 1252 |
var $this = $(this), |
| 1253 |
$link = $this.find('.darkify--link'), |
| 1254 |
$add = $this.find('.darkify--add'), |
| 1255 |
$edit = $this.find('.darkify--edit'), |
| 1256 |
$remove = $this.find('.darkify--remove'), |
| 1257 |
$result = $this.find('.darkify--result'), |
| 1258 |
uniqid = DARKIFY.helper.uid('darkify-wplink-textarea-'); |
| 1259 |
|
| 1260 |
$add.on('click', function (e) { |
| 1261 |
|
| 1262 |
e.preventDefault(); |
| 1263 |
|
| 1264 |
window.wpLink.open(uniqid); |
| 1265 |
|
| 1266 |
}); |
| 1267 |
|
| 1268 |
$edit.on('click', function (e) { |
| 1269 |
|
| 1270 |
e.preventDefault(); |
| 1271 |
|
| 1272 |
$add.trigger('click'); |
| 1273 |
|
| 1274 |
$('#wp-link-url').val($this.find('.darkify--url').val()); |
| 1275 |
$('#wp-link-text').val($this.find('.darkify--text').val()); |
| 1276 |
$('#wp-link-target').prop('checked', ($this.find('.darkify--target').val() === '_blank')); |
| 1277 |
|
| 1278 |
}); |
| 1279 |
|
| 1280 |
$remove.on('click', function (e) { |
| 1281 |
|
| 1282 |
e.preventDefault(); |
| 1283 |
|
| 1284 |
$this.find('.darkify--url').val('').trigger('change'); |
| 1285 |
$this.find('.darkify--text').val(''); |
| 1286 |
$this.find('.darkify--target').val(''); |
| 1287 |
|
| 1288 |
$add.removeClass('hidden'); |
| 1289 |
$edit.addClass('hidden'); |
| 1290 |
$remove.addClass('hidden'); |
| 1291 |
$result.parent().addClass('hidden'); |
| 1292 |
|
| 1293 |
}); |
| 1294 |
|
| 1295 |
$link.attr('id', uniqid).on('change', function () { |
| 1296 |
|
| 1297 |
var atts = window.wpLink.getAttrs(), |
| 1298 |
href = atts.href, |
| 1299 |
text = $('#wp-link-text').val(), |
| 1300 |
target = (atts.target) ? atts.target : ''; |
| 1301 |
|
| 1302 |
$this.find('.darkify--url').val(href).trigger('change'); |
| 1303 |
$this.find('.darkify--text').val(text); |
| 1304 |
$this.find('.darkify--target').val(target); |
| 1305 |
|
| 1306 |
$result.html('{url:"' + href + '", text:"' + text + '", target:"' + target + '"}'); |
| 1307 |
|
| 1308 |
$add.addClass('hidden'); |
| 1309 |
$edit.removeClass('hidden'); |
| 1310 |
$remove.removeClass('hidden'); |
| 1311 |
$result.parent().removeClass('hidden'); |
| 1312 |
|
| 1313 |
}); |
| 1314 |
|
| 1315 |
}); |
| 1316 |
|
| 1317 |
}; |
| 1318 |
|
| 1319 |
// |
| 1320 |
// Field: media |
| 1321 |
// |
| 1322 |
$.fn.darkify_field_media = function () { |
| 1323 |
return this.each(function () { |
| 1324 |
|
| 1325 |
var $this = $(this), |
| 1326 |
$upload_button = $this.find('.darkify--button'), |
| 1327 |
$remove_button = $this.find('.darkify--remove'), |
| 1328 |
$library = $upload_button.data('library') && $upload_button.data('library').split(',') || '', |
| 1329 |
$auto_attributes = ($this.hasClass('darkify-assign-field-background')) ? $this.closest('.darkify-field-background').find('.darkify--auto-attributes') : false, |
| 1330 |
wp_media_frame; |
| 1331 |
|
| 1332 |
$upload_button.on('click', function (e) { |
| 1333 |
|
| 1334 |
e.preventDefault(); |
| 1335 |
|
| 1336 |
if (typeof window.wp === 'undefined' || !window.wp.media || !window.wp.media.gallery) { |
| 1337 |
return; |
| 1338 |
} |
| 1339 |
|
| 1340 |
if (wp_media_frame) { |
| 1341 |
wp_media_frame.open(); |
| 1342 |
return; |
| 1343 |
} |
| 1344 |
|
| 1345 |
wp_media_frame = window.wp.media({ |
| 1346 |
library: { |
| 1347 |
type: $library |
| 1348 |
} |
| 1349 |
}); |
| 1350 |
|
| 1351 |
wp_media_frame.on('select', function () { |
| 1352 |
|
| 1353 |
var thumbnail; |
| 1354 |
var attributes = wp_media_frame.state().get('selection').first().attributes; |
| 1355 |
var preview_size = $upload_button.data('preview-size') || 'thumbnail'; |
| 1356 |
|
| 1357 |
if ($library.length && $library.indexOf(attributes.subtype) === -1 && $library.indexOf(attributes.type) === -1) { |
| 1358 |
return; |
| 1359 |
} |
| 1360 |
|
| 1361 |
$this.find('.darkify--id').val(attributes.id); |
| 1362 |
$this.find('.darkify--width').val(attributes.width); |
| 1363 |
$this.find('.darkify--height').val(attributes.height); |
| 1364 |
$this.find('.darkify--alt').val(attributes.alt); |
| 1365 |
$this.find('.darkify--title').val(attributes.title); |
| 1366 |
$this.find('.darkify--description').val(attributes.description); |
| 1367 |
|
| 1368 |
if (typeof attributes.sizes !== 'undefined' && typeof attributes.sizes.thumbnail !== 'undefined' && preview_size === 'thumbnail') { |
| 1369 |
thumbnail = attributes.sizes.thumbnail.url; |
| 1370 |
} else if (typeof attributes.sizes !== 'undefined' && typeof attributes.sizes.full !== 'undefined') { |
| 1371 |
thumbnail = attributes.sizes.full.url; |
| 1372 |
} else if (attributes.type === 'image') { |
| 1373 |
thumbnail = attributes.url; |
| 1374 |
} else { |
| 1375 |
thumbnail = attributes.icon; |
| 1376 |
} |
| 1377 |
|
| 1378 |
if ($auto_attributes) { |
| 1379 |
$auto_attributes.removeClass('darkify--attributes-hidden'); |
| 1380 |
} |
| 1381 |
|
| 1382 |
$remove_button.removeClass('hidden'); |
| 1383 |
|
| 1384 |
$this.find('.darkify--preview').removeClass('hidden'); |
| 1385 |
$this.find('.darkify--src').attr('src', thumbnail); |
| 1386 |
$this.find('.darkify--thumbnail').val(thumbnail); |
| 1387 |
$this.find('.darkify--url').val(attributes.url).trigger('change'); |
| 1388 |
|
| 1389 |
}); |
| 1390 |
|
| 1391 |
wp_media_frame.open(); |
| 1392 |
|
| 1393 |
}); |
| 1394 |
|
| 1395 |
$remove_button.on('click', function (e) { |
| 1396 |
|
| 1397 |
e.preventDefault(); |
| 1398 |
|
| 1399 |
if ($auto_attributes) { |
| 1400 |
$auto_attributes.addClass('darkify--attributes-hidden'); |
| 1401 |
} |
| 1402 |
|
| 1403 |
$remove_button.addClass('hidden'); |
| 1404 |
$this.find('input').val(''); |
| 1405 |
$this.find('.darkify--preview').addClass('hidden'); |
| 1406 |
$this.find('.darkify--url').trigger('change'); |
| 1407 |
|
| 1408 |
}); |
| 1409 |
|
| 1410 |
}); |
| 1411 |
|
| 1412 |
}; |
| 1413 |
|
| 1414 |
// |
| 1415 |
// Field: repeater |
| 1416 |
// |
| 1417 |
$.fn.darkify_field_repeater = function () { |
| 1418 |
return this.each(function () { |
| 1419 |
|
| 1420 |
var $this = $(this), |
| 1421 |
$fieldset = $this.children('.darkify-fieldset'), |
| 1422 |
$repeater = $fieldset.length ? $fieldset : $this, |
| 1423 |
$wrapper = $repeater.children('.darkify-repeater-wrapper'), |
| 1424 |
$hidden = $repeater.children('.darkify-repeater-hidden'), |
| 1425 |
$max = $repeater.children('.darkify-repeater-max'), |
| 1426 |
$min = $repeater.children('.darkify-repeater-min'), |
| 1427 |
field_id = $wrapper.data('field-id'), |
| 1428 |
max = parseInt($wrapper.data('max')), |
| 1429 |
min = parseInt($wrapper.data('min')); |
| 1430 |
|
| 1431 |
$wrapper.children('.darkify-repeater-item').children('.darkify-repeater-content').darkify_reload_script(); |
| 1432 |
|
| 1433 |
$wrapper.sortable({ |
| 1434 |
axis: 'y', |
| 1435 |
handle: '.darkify-repeater-sort', |
| 1436 |
helper: 'original', |
| 1437 |
cursor: 'move', |
| 1438 |
placeholder: 'widget-placeholder', |
| 1439 |
update: function (event, ui) { |
| 1440 |
|
| 1441 |
DARKIFY.helper.name_nested_replace($wrapper.children('.darkify-repeater-item'), field_id); |
| 1442 |
$wrapper.darkify_customizer_refresh(); |
| 1443 |
ui.item.darkify_reload_script_retry(); |
| 1444 |
|
| 1445 |
} |
| 1446 |
}); |
| 1447 |
|
| 1448 |
$repeater.children('.darkify-repeater-add').on('click', function (e) { |
| 1449 |
|
| 1450 |
e.preventDefault(); |
| 1451 |
|
| 1452 |
var count = $wrapper.children('.darkify-repeater-item').length; |
| 1453 |
|
| 1454 |
$min.hide(); |
| 1455 |
|
| 1456 |
if (max && (count + 1) > max) { |
| 1457 |
$max.show(); |
| 1458 |
return; |
| 1459 |
} |
| 1460 |
|
| 1461 |
var $cloned_item = $hidden.darkify_clone(true); |
| 1462 |
|
| 1463 |
$cloned_item.removeClass('darkify-repeater-hidden'); |
| 1464 |
|
| 1465 |
$cloned_item.find(':input[name!="_pseudo"]').each(function () { |
| 1466 |
this.name = this.name.replace('___', '').replace(field_id + '[0]', field_id + '[' + count + ']'); |
| 1467 |
}); |
| 1468 |
|
| 1469 |
$wrapper.append($cloned_item); |
| 1470 |
$cloned_item.children('.darkify-repeater-content').darkify_reload_script(); |
| 1471 |
$wrapper.darkify_customizer_refresh(); |
| 1472 |
$wrapper.darkify_customizer_listen({ closest: true }); |
| 1473 |
|
| 1474 |
}); |
| 1475 |
|
| 1476 |
var event_clone = function (e) { |
| 1477 |
|
| 1478 |
e.preventDefault(); |
| 1479 |
|
| 1480 |
var count = $wrapper.children('.darkify-repeater-item').length; |
| 1481 |
|
| 1482 |
$min.hide(); |
| 1483 |
|
| 1484 |
if (max && (count + 1) > max) { |
| 1485 |
$max.show(); |
| 1486 |
return; |
| 1487 |
} |
| 1488 |
|
| 1489 |
var $this = $(this), |
| 1490 |
$parent = $this.parent().parent().parent(), |
| 1491 |
$cloned_content = $parent.children('.darkify-repeater-content').darkify_clone(), |
| 1492 |
$cloned_helper = $parent.children('.darkify-repeater-helper').darkify_clone(true), |
| 1493 |
$cloned_item = $('<div class="darkify-repeater-item" />'); |
| 1494 |
|
| 1495 |
$cloned_item.append($cloned_content); |
| 1496 |
$cloned_item.append($cloned_helper); |
| 1497 |
|
| 1498 |
$wrapper.children().eq($parent.index()).after($cloned_item); |
| 1499 |
|
| 1500 |
$cloned_item.children('.darkify-repeater-content').darkify_reload_script(); |
| 1501 |
|
| 1502 |
DARKIFY.helper.name_nested_replace($wrapper.children('.darkify-repeater-item'), field_id); |
| 1503 |
|
| 1504 |
$wrapper.darkify_customizer_refresh(); |
| 1505 |
$wrapper.darkify_customizer_listen({ closest: true }); |
| 1506 |
|
| 1507 |
}; |
| 1508 |
|
| 1509 |
$wrapper.children('.darkify-repeater-item').children('.darkify-repeater-helper').on('click', '.darkify-repeater-clone', event_clone); |
| 1510 |
$repeater.children('.darkify-repeater-hidden').children('.darkify-repeater-helper').on('click', '.darkify-repeater-clone', event_clone); |
| 1511 |
|
| 1512 |
var event_remove = function (e) { |
| 1513 |
|
| 1514 |
e.preventDefault(); |
| 1515 |
|
| 1516 |
var count = $wrapper.children('.darkify-repeater-item').length; |
| 1517 |
|
| 1518 |
$max.hide(); |
| 1519 |
$min.hide(); |
| 1520 |
|
| 1521 |
if (min && (count - 1) < min) { |
| 1522 |
$min.show(); |
| 1523 |
return; |
| 1524 |
} |
| 1525 |
|
| 1526 |
$(this).closest('.darkify-repeater-item').remove(); |
| 1527 |
|
| 1528 |
DARKIFY.helper.name_nested_replace($wrapper.children('.darkify-repeater-item'), field_id); |
| 1529 |
|
| 1530 |
$wrapper.darkify_customizer_refresh(); |
| 1531 |
|
| 1532 |
}; |
| 1533 |
|
| 1534 |
$wrapper.children('.darkify-repeater-item').children('.darkify-repeater-helper').on('click', '.darkify-repeater-remove', event_remove); |
| 1535 |
$repeater.children('.darkify-repeater-hidden').children('.darkify-repeater-helper').on('click', '.darkify-repeater-remove', event_remove); |
| 1536 |
|
| 1537 |
}); |
| 1538 |
}; |
| 1539 |
|
| 1540 |
// |
| 1541 |
// Field: slider |
| 1542 |
// |
| 1543 |
$.fn.darkify_field_slider = function () { |
| 1544 |
return this.each(function () { |
| 1545 |
|
| 1546 |
var $this = $(this), |
| 1547 |
$input = $this.find('input'), |
| 1548 |
$slider = $this.find('.darkify-slider-ui'), |
| 1549 |
data = $input.data(), |
| 1550 |
value = $input.val() || 0; |
| 1551 |
|
| 1552 |
if ($slider.hasClass('ui-slider')) { |
| 1553 |
$slider.empty(); |
| 1554 |
} |
| 1555 |
|
| 1556 |
$slider.slider({ |
| 1557 |
range: 'min', |
| 1558 |
value: value, |
| 1559 |
min: data.min || 0, |
| 1560 |
max: data.max || 100, |
| 1561 |
step: data.step || 1, |
| 1562 |
slide: function (e, o) { |
| 1563 |
$input.val(o.value).trigger('change'); |
| 1564 |
} |
| 1565 |
}); |
| 1566 |
|
| 1567 |
$input.on('keyup', function () { |
| 1568 |
$slider.slider('value', $input.val()); |
| 1569 |
}); |
| 1570 |
|
| 1571 |
}); |
| 1572 |
}; |
| 1573 |
|
| 1574 |
// |
| 1575 |
// Field: sortable |
| 1576 |
// |
| 1577 |
$.fn.darkify_field_sortable = function () { |
| 1578 |
return this.each(function () { |
| 1579 |
|
| 1580 |
var $sortable = $(this).find('.darkify-sortable'); |
| 1581 |
|
| 1582 |
$sortable.sortable({ |
| 1583 |
axis: 'y', |
| 1584 |
helper: 'original', |
| 1585 |
cursor: 'move', |
| 1586 |
placeholder: 'widget-placeholder', |
| 1587 |
update: function (event, ui) { |
| 1588 |
$sortable.darkify_customizer_refresh(); |
| 1589 |
} |
| 1590 |
}); |
| 1591 |
|
| 1592 |
$sortable.find('.darkify-sortable-content').darkify_reload_script(); |
| 1593 |
|
| 1594 |
}); |
| 1595 |
}; |
| 1596 |
|
| 1597 |
// |
| 1598 |
// Field: sorter |
| 1599 |
// |
| 1600 |
$.fn.darkify_field_sorter = function () { |
| 1601 |
return this.each(function () { |
| 1602 |
|
| 1603 |
var $this = $(this), |
| 1604 |
$enabled = $this.find('.darkify-enabled'), |
| 1605 |
$has_disabled = $this.find('.darkify-disabled'), |
| 1606 |
$disabled = ($has_disabled.length) ? $has_disabled : false; |
| 1607 |
|
| 1608 |
$enabled.sortable({ |
| 1609 |
connectWith: $disabled, |
| 1610 |
placeholder: 'ui-sortable-placeholder', |
| 1611 |
update: function (event, ui) { |
| 1612 |
|
| 1613 |
var $el = ui.item.find('input'); |
| 1614 |
|
| 1615 |
if (ui.item.parent().hasClass('darkify-enabled')) { |
| 1616 |
$el.attr('name', $el.attr('name').replace('disabled', 'enabled')); |
| 1617 |
} else { |
| 1618 |
$el.attr('name', $el.attr('name').replace('enabled', 'disabled')); |
| 1619 |
} |
| 1620 |
|
| 1621 |
$this.darkify_customizer_refresh(); |
| 1622 |
|
| 1623 |
} |
| 1624 |
}); |
| 1625 |
|
| 1626 |
if ($disabled) { |
| 1627 |
|
| 1628 |
$disabled.sortable({ |
| 1629 |
connectWith: $enabled, |
| 1630 |
placeholder: 'ui-sortable-placeholder', |
| 1631 |
update: function (event, ui) { |
| 1632 |
$this.darkify_customizer_refresh(); |
| 1633 |
} |
| 1634 |
}); |
| 1635 |
|
| 1636 |
} |
| 1637 |
|
| 1638 |
}); |
| 1639 |
}; |
| 1640 |
|
| 1641 |
// |
| 1642 |
// Field: spinner |
| 1643 |
// |
| 1644 |
$.fn.darkify_field_spinner = function () { |
| 1645 |
return this.each(function () { |
| 1646 |
|
| 1647 |
var $this = $(this), |
| 1648 |
$input = $this.find('input'), |
| 1649 |
$inited = $this.find('.ui-button'), |
| 1650 |
data = $input.data(); |
| 1651 |
|
| 1652 |
if ($inited.length) { |
| 1653 |
$inited.remove(); |
| 1654 |
} |
| 1655 |
|
| 1656 |
$input.spinner({ |
| 1657 |
min: data.min || 0, |
| 1658 |
max: data.max || 100, |
| 1659 |
step: data.step || 1, |
| 1660 |
create: function (event, ui) { |
| 1661 |
if (data.unit) { |
| 1662 |
$input.after('<span class="ui-button darkify--unit">' + data.unit + '</span>'); |
| 1663 |
} |
| 1664 |
}, |
| 1665 |
spin: function (event, ui) { |
| 1666 |
$input.val(ui.value).trigger('change'); |
| 1667 |
} |
| 1668 |
}); |
| 1669 |
|
| 1670 |
}); |
| 1671 |
}; |
| 1672 |
|
| 1673 |
// |
| 1674 |
// Field: switcher |
| 1675 |
// |
| 1676 |
$.fn.darkify_field_switcher = function () { |
| 1677 |
return this.each(function () { |
| 1678 |
|
| 1679 |
var $switcher = $(this).find('.darkify--switcher'); |
| 1680 |
|
| 1681 |
$switcher.on('click', function () { |
| 1682 |
|
| 1683 |
var value = 0; |
| 1684 |
var $input = $switcher.find('input'); |
| 1685 |
|
| 1686 |
if ($switcher.hasClass('darkify--active')) { |
| 1687 |
$switcher.removeClass('darkify--active'); |
| 1688 |
} else { |
| 1689 |
value = 1; |
| 1690 |
$switcher.addClass('darkify--active'); |
| 1691 |
} |
| 1692 |
|
| 1693 |
$input.val(value).trigger('change'); |
| 1694 |
|
| 1695 |
}); |
| 1696 |
|
| 1697 |
}); |
| 1698 |
}; |
| 1699 |
|
| 1700 |
// |
| 1701 |
// Field: tabbed |
| 1702 |
// |
| 1703 |
$.fn.darkify_field_tabbed = function () { |
| 1704 |
return this.each(function () { |
| 1705 |
|
| 1706 |
var $this = $(this), |
| 1707 |
$links = $this.find('.darkify-tabbed-nav a'), |
| 1708 |
$contents = $this.find('.darkify-tabbed-content'); |
| 1709 |
|
| 1710 |
$contents.eq(0).darkify_reload_script(); |
| 1711 |
|
| 1712 |
$links.on('click', function (e) { |
| 1713 |
|
| 1714 |
e.preventDefault(); |
| 1715 |
|
| 1716 |
var $link = $(this), |
| 1717 |
index = $link.index(), |
| 1718 |
$content = $contents.eq(index); |
| 1719 |
|
| 1720 |
$link.addClass('darkify-tabbed-active').siblings().removeClass('darkify-tabbed-active'); |
| 1721 |
$content.darkify_reload_script(); |
| 1722 |
$content.removeClass('hidden').siblings().addClass('hidden'); |
| 1723 |
|
| 1724 |
}); |
| 1725 |
|
| 1726 |
}); |
| 1727 |
}; |
| 1728 |
|
| 1729 |
// |
| 1730 |
// Field: typography |
| 1731 |
// |
| 1732 |
$.fn.darkify_field_typography = function () { |
| 1733 |
return this.each(function () { |
| 1734 |
|
| 1735 |
var base = this; |
| 1736 |
var $this = $(this); |
| 1737 |
var loaded_fonts = []; |
| 1738 |
var webfonts = darkify_typography_json.webfonts; |
| 1739 |
var googlestyles = darkify_typography_json.googlestyles; |
| 1740 |
var defaultstyles = darkify_typography_json.defaultstyles; |
| 1741 |
|
| 1742 |
// |
| 1743 |
// |
| 1744 |
// Sanitize google font subset |
| 1745 |
base.sanitize_subset = function (subset) { |
| 1746 |
subset = subset.replace('-ext', ' Extended'); |
| 1747 |
subset = subset.charAt(0).toUpperCase() + subset.slice(1); |
| 1748 |
return subset; |
| 1749 |
}; |
| 1750 |
|
| 1751 |
// |
| 1752 |
// |
| 1753 |
// Sanitize google font styles (weight and style) |
| 1754 |
base.sanitize_style = function (style) { |
| 1755 |
return googlestyles[style] ? googlestyles[style] : style; |
| 1756 |
}; |
| 1757 |
|
| 1758 |
// |
| 1759 |
// |
| 1760 |
// Load google font |
| 1761 |
base.load_google_font = function (font_family, weight, style) { |
| 1762 |
|
| 1763 |
if (font_family && typeof WebFont === 'object') { |
| 1764 |
|
| 1765 |
weight = weight ? weight.replace('normal', '') : ''; |
| 1766 |
style = style ? style.replace('normal', '') : ''; |
| 1767 |
|
| 1768 |
if (weight || style) { |
| 1769 |
font_family = font_family + ':' + weight + style; |
| 1770 |
} |
| 1771 |
|
| 1772 |
if (loaded_fonts.indexOf(font_family) === -1) { |
| 1773 |
WebFont.load({ google: { families: [font_family] } }); |
| 1774 |
} |
| 1775 |
|
| 1776 |
loaded_fonts.push(font_family); |
| 1777 |
|
| 1778 |
} |
| 1779 |
|
| 1780 |
}; |
| 1781 |
|
| 1782 |
// |
| 1783 |
// |
| 1784 |
// Append select options |
| 1785 |
base.append_select_options = function ($select, options, condition, type, is_multi) { |
| 1786 |
|
| 1787 |
$select.find('option').not(':first').remove(); |
| 1788 |
|
| 1789 |
var opts = ''; |
| 1790 |
|
| 1791 |
$.each(options, function (key, value) { |
| 1792 |
|
| 1793 |
var selected; |
| 1794 |
var name = value; |
| 1795 |
|
| 1796 |
// is_multi |
| 1797 |
if (is_multi) { |
| 1798 |
selected = (condition && condition.indexOf(value) !== -1) ? ' selected' : ''; |
| 1799 |
} else { |
| 1800 |
selected = (condition && condition === value) ? ' selected' : ''; |
| 1801 |
} |
| 1802 |
|
| 1803 |
if (type === 'subset') { |
| 1804 |
name = base.sanitize_subset(value); |
| 1805 |
} else if (type === 'style') { |
| 1806 |
name = base.sanitize_style(value); |
| 1807 |
} |
| 1808 |
|
| 1809 |
opts += '<option value="' + value + '"' + selected + '>' + name + '</option>'; |
| 1810 |
|
| 1811 |
}); |
| 1812 |
|
| 1813 |
$select.append(opts).trigger('darkify.change').trigger('chosen:updated'); |
| 1814 |
|
| 1815 |
}; |
| 1816 |
|
| 1817 |
base.init = function () { |
| 1818 |
|
| 1819 |
// |
| 1820 |
// |
| 1821 |
// Constants |
| 1822 |
var selected_styles = []; |
| 1823 |
var $typography = $this.find('.darkify--typography'); |
| 1824 |
var $type = $this.find('.darkify--type'); |
| 1825 |
var $styles = $this.find('.darkify--block-font-style'); |
| 1826 |
var unit = $typography.data('unit'); |
| 1827 |
var line_height_unit = $typography.data('line-height-unit'); |
| 1828 |
var exclude_fonts = $typography.data('exclude') ? $typography.data('exclude').split(',') : []; |
| 1829 |
|
| 1830 |
// |
| 1831 |
// |
| 1832 |
// Chosen init |
| 1833 |
if ($this.find('.darkify--chosen').length) { |
| 1834 |
|
| 1835 |
var $chosen_selects = $this.find('select'); |
| 1836 |
|
| 1837 |
$chosen_selects.each(function () { |
| 1838 |
|
| 1839 |
var $chosen_select = $(this), |
| 1840 |
$chosen_inited = $chosen_select.parent().find('.chosen-container'); |
| 1841 |
|
| 1842 |
if ($chosen_inited.length) { |
| 1843 |
$chosen_inited.remove(); |
| 1844 |
} |
| 1845 |
|
| 1846 |
$chosen_select.chosen({ |
| 1847 |
allow_single_deselect: true, |
| 1848 |
disable_search_threshold: 15, |
| 1849 |
width: '100%' |
| 1850 |
}); |
| 1851 |
|
| 1852 |
}); |
| 1853 |
|
| 1854 |
} |
| 1855 |
|
| 1856 |
// |
| 1857 |
// |
| 1858 |
// Font family select |
| 1859 |
var $font_family_select = $this.find('.darkify--font-family'); |
| 1860 |
var first_font_family = $font_family_select.val(); |
| 1861 |
|
| 1862 |
// Clear default font family select options |
| 1863 |
$font_family_select.find('option').not(':first-child').remove(); |
| 1864 |
|
| 1865 |
var opts = ''; |
| 1866 |
|
| 1867 |
$.each(webfonts, function (type, group) { |
| 1868 |
|
| 1869 |
// Check for exclude fonts |
| 1870 |
if (exclude_fonts && exclude_fonts.indexOf(type) !== -1) { return; } |
| 1871 |
|
| 1872 |
opts += '<optgroup label="' + group.label + '">'; |
| 1873 |
|
| 1874 |
$.each(group.fonts, function (key, value) { |
| 1875 |
|
| 1876 |
// use key if value is object |
| 1877 |
value = (typeof value === 'object') ? key : value; |
| 1878 |
var selected = (value === first_font_family) ? ' selected' : ''; |
| 1879 |
opts += '<option value="' + value + '" data-type="' + type + '"' + selected + '>' + value + '</option>'; |
| 1880 |
|
| 1881 |
}); |
| 1882 |
|
| 1883 |
opts += '</optgroup>'; |
| 1884 |
|
| 1885 |
}); |
| 1886 |
|
| 1887 |
// Append google font select options |
| 1888 |
$font_family_select.append(opts).trigger('chosen:updated'); |
| 1889 |
|
| 1890 |
// |
| 1891 |
// |
| 1892 |
// Font style select |
| 1893 |
var $font_style_block = $this.find('.darkify--block-font-style'); |
| 1894 |
|
| 1895 |
if ($font_style_block.length) { |
| 1896 |
|
| 1897 |
var $font_style_select = $this.find('.darkify--font-style-select'); |
| 1898 |
var first_style_value = $font_style_select.val() ? $font_style_select.val().replace(/normal/g, '') : ''; |
| 1899 |
|
| 1900 |
// |
| 1901 |
// Font Style on on change listener |
| 1902 |
$font_style_select.on('change darkify.change', function (event) { |
| 1903 |
|
| 1904 |
var style_value = $font_style_select.val(); |
| 1905 |
|
| 1906 |
// set a default value |
| 1907 |
if (!style_value && selected_styles && selected_styles.indexOf('normal') === -1) { |
| 1908 |
style_value = selected_styles[0]; |
| 1909 |
} |
| 1910 |
|
| 1911 |
// set font weight, for eg. replacing 800italic to 800 |
| 1912 |
var font_normal = (style_value && style_value !== 'italic' && style_value === 'normal') ? 'normal' : ''; |
| 1913 |
var font_weight = (style_value && style_value !== 'italic' && style_value !== 'normal') ? style_value.replace('italic', '') : font_normal; |
| 1914 |
var font_style = (style_value && style_value.substr(-6) === 'italic') ? 'italic' : ''; |
| 1915 |
|
| 1916 |
$this.find('.darkify--font-weight').val(font_weight); |
| 1917 |
$this.find('.darkify--font-style').val(font_style); |
| 1918 |
|
| 1919 |
}); |
| 1920 |
|
| 1921 |
// |
| 1922 |
// |
| 1923 |
// Extra font style select |
| 1924 |
var $extra_font_style_block = $this.find('.darkify--block-extra-styles'); |
| 1925 |
|
| 1926 |
if ($extra_font_style_block.length) { |
| 1927 |
var $extra_font_style_select = $this.find('.darkify--extra-styles'); |
| 1928 |
var first_extra_style_value = $extra_font_style_select.val(); |
| 1929 |
} |
| 1930 |
|
| 1931 |
} |
| 1932 |
|
| 1933 |
// |
| 1934 |
// |
| 1935 |
// Subsets select |
| 1936 |
var $subset_block = $this.find('.darkify--block-subset'); |
| 1937 |
if ($subset_block.length) { |
| 1938 |
var $subset_select = $this.find('.darkify--subset'); |
| 1939 |
var first_subset_select_value = $subset_select.val(); |
| 1940 |
var subset_multi_select = $subset_select.data('multiple') || false; |
| 1941 |
} |
| 1942 |
|
| 1943 |
// |
| 1944 |
// |
| 1945 |
// Backup font family |
| 1946 |
var $backup_font_family_block = $this.find('.darkify--block-backup-font-family'); |
| 1947 |
|
| 1948 |
// |
| 1949 |
// |
| 1950 |
// Font Family on Change Listener |
| 1951 |
$font_family_select.on('change darkify.change', function (event) { |
| 1952 |
|
| 1953 |
// Hide subsets on change |
| 1954 |
if ($subset_block.length) { |
| 1955 |
$subset_block.addClass('hidden'); |
| 1956 |
} |
| 1957 |
|
| 1958 |
// Hide extra font style on change |
| 1959 |
if ($extra_font_style_block.length) { |
| 1960 |
$extra_font_style_block.addClass('hidden'); |
| 1961 |
} |
| 1962 |
|
| 1963 |
// Hide backup font family on change |
| 1964 |
if ($backup_font_family_block.length) { |
| 1965 |
$backup_font_family_block.addClass('hidden'); |
| 1966 |
} |
| 1967 |
|
| 1968 |
var $selected = $font_family_select.find(':selected'); |
| 1969 |
var value = $selected.val(); |
| 1970 |
var type = $selected.data('type'); |
| 1971 |
|
| 1972 |
if (type && value) { |
| 1973 |
|
| 1974 |
// Show backup fonts if font type google or custom |
| 1975 |
if ((type === 'google' || type === 'custom') && $backup_font_family_block.length) { |
| 1976 |
$backup_font_family_block.removeClass('hidden'); |
| 1977 |
} |
| 1978 |
|
| 1979 |
// Appending font style select options |
| 1980 |
if ($font_style_block.length) { |
| 1981 |
|
| 1982 |
// set styles for multi and normal style selectors |
| 1983 |
var styles = defaultstyles; |
| 1984 |
|
| 1985 |
// Custom or gogle font styles |
| 1986 |
if (type === 'google' && webfonts[type].fonts[value][0]) { |
| 1987 |
styles = webfonts[type].fonts[value][0]; |
| 1988 |
} else if (type === 'custom' && webfonts[type].fonts[value]) { |
| 1989 |
styles = webfonts[type].fonts[value]; |
| 1990 |
} |
| 1991 |
|
| 1992 |
selected_styles = styles; |
| 1993 |
|
| 1994 |
// Set selected style value for avoid load errors |
| 1995 |
var set_auto_style = (styles.indexOf('normal') !== -1) ? 'normal' : styles[0]; |
| 1996 |
var set_style_value = (first_style_value && styles.indexOf(first_style_value) !== -1) ? first_style_value : set_auto_style; |
| 1997 |
|
| 1998 |
// Append style select options |
| 1999 |
base.append_select_options($font_style_select, styles, set_style_value, 'style'); |
| 2000 |
|
| 2001 |
// Clear first value |
| 2002 |
first_style_value = false; |
| 2003 |
|
| 2004 |
// Show style select after appended |
| 2005 |
$font_style_block.removeClass('hidden'); |
| 2006 |
|
| 2007 |
// Appending extra font style select options |
| 2008 |
if (type === 'google' && $extra_font_style_block.length && styles.length > 1) { |
| 2009 |
|
| 2010 |
// Append extra-style select options |
| 2011 |
base.append_select_options($extra_font_style_select, styles, first_extra_style_value, 'style', true); |
| 2012 |
|
| 2013 |
// Clear first value |
| 2014 |
first_extra_style_value = false; |
| 2015 |
|
| 2016 |
// Show style select after appended |
| 2017 |
$extra_font_style_block.removeClass('hidden'); |
| 2018 |
|
| 2019 |
} |
| 2020 |
|
| 2021 |
} |
| 2022 |
|
| 2023 |
// Appending google fonts subsets select options |
| 2024 |
if (type === 'google' && $subset_block.length && webfonts[type].fonts[value][1]) { |
| 2025 |
|
| 2026 |
var subsets = webfonts[type].fonts[value][1]; |
| 2027 |
var set_auto_subset = (subsets.length < 2 && subsets[0] !== 'latin') ? subsets[0] : ''; |
| 2028 |
var set_subset_value = (first_subset_select_value && subsets.indexOf(first_subset_select_value) !== -1) ? first_subset_select_value : set_auto_subset; |
| 2029 |
|
| 2030 |
// check for multiple subset select |
| 2031 |
set_subset_value = (subset_multi_select && first_subset_select_value) ? first_subset_select_value : set_subset_value; |
| 2032 |
|
| 2033 |
base.append_select_options($subset_select, subsets, set_subset_value, 'subset', subset_multi_select); |
| 2034 |
|
| 2035 |
first_subset_select_value = false; |
| 2036 |
|
| 2037 |
$subset_block.removeClass('hidden'); |
| 2038 |
|
| 2039 |
} |
| 2040 |
|
| 2041 |
} else { |
| 2042 |
|
| 2043 |
// Clear Styles |
| 2044 |
$styles.find(':input').val(''); |
| 2045 |
|
| 2046 |
// Clear subsets options if type and value empty |
| 2047 |
if ($subset_block.length) { |
| 2048 |
$subset_select.find('option').not(':first-child').remove(); |
| 2049 |
$subset_select.trigger('chosen:updated'); |
| 2050 |
} |
| 2051 |
|
| 2052 |
// Clear font styles options if type and value empty |
| 2053 |
if ($font_style_block.length) { |
| 2054 |
$font_style_select.find('option').not(':first-child').remove(); |
| 2055 |
$font_style_select.trigger('chosen:updated'); |
| 2056 |
} |
| 2057 |
|
| 2058 |
} |
| 2059 |
|
| 2060 |
// Update font type input value |
| 2061 |
$type.val(type); |
| 2062 |
|
| 2063 |
}).trigger('darkify.change'); |
| 2064 |
|
| 2065 |
// |
| 2066 |
// |
| 2067 |
// Preview |
| 2068 |
var $preview_block = $this.find('.darkify--block-preview'); |
| 2069 |
|
| 2070 |
if ($preview_block.length) { |
| 2071 |
|
| 2072 |
var $preview = $this.find('.darkify--preview'); |
| 2073 |
|
| 2074 |
// Set preview styles on change |
| 2075 |
$this.on('change', DARKIFY.helper.debounce(function (event) { |
| 2076 |
|
| 2077 |
$preview_block.removeClass('hidden'); |
| 2078 |
|
| 2079 |
var font_family = $font_family_select.val(), |
| 2080 |
font_weight = $this.find('.darkify--font-weight').val(), |
| 2081 |
font_style = $this.find('.darkify--font-style').val(), |
| 2082 |
font_size = $this.find('.darkify--font-size').val(), |
| 2083 |
font_variant = $this.find('.darkify--font-variant').val(), |
| 2084 |
line_height = $this.find('.darkify--line-height').val(), |
| 2085 |
text_align = $this.find('.darkify--text-align').val(), |
| 2086 |
text_transform = $this.find('.darkify--text-transform').val(), |
| 2087 |
text_decoration = $this.find('.darkify--text-decoration').val(), |
| 2088 |
text_color = $this.find('.darkify--color').val(), |
| 2089 |
word_spacing = $this.find('.darkify--word-spacing').val(), |
| 2090 |
letter_spacing = $this.find('.darkify--letter-spacing').val(), |
| 2091 |
custom_style = $this.find('.darkify--custom-style').val(), |
| 2092 |
type = $this.find('.darkify--type').val(); |
| 2093 |
|
| 2094 |
if (type === 'google') { |
| 2095 |
base.load_google_font(font_family, font_weight, font_style); |
| 2096 |
} |
| 2097 |
|
| 2098 |
var properties = {}; |
| 2099 |
|
| 2100 |
if (font_family) { properties.fontFamily = font_family; } |
| 2101 |
if (font_weight) { properties.fontWeight = font_weight; } |
| 2102 |
if (font_style) { properties.fontStyle = font_style; } |
| 2103 |
if (font_variant) { properties.fontVariant = font_variant; } |
| 2104 |
if (font_size) { properties.fontSize = font_size + unit; } |
| 2105 |
if (line_height) { properties.lineHeight = line_height + line_height_unit; } |
| 2106 |
if (letter_spacing) { properties.letterSpacing = letter_spacing + unit; } |
| 2107 |
if (word_spacing) { properties.wordSpacing = word_spacing + unit; } |
| 2108 |
if (text_align) { properties.textAlign = text_align; } |
| 2109 |
if (text_transform) { properties.textTransform = text_transform; } |
| 2110 |
if (text_decoration) { properties.textDecoration = text_decoration; } |
| 2111 |
if (text_color) { properties.color = text_color; } |
| 2112 |
|
| 2113 |
$preview.removeAttr('style'); |
| 2114 |
|
| 2115 |
// Customs style attribute |
| 2116 |
if (custom_style) { $preview.attr('style', custom_style); } |
| 2117 |
|
| 2118 |
$preview.css(properties); |
| 2119 |
|
| 2120 |
}, 100)); |
| 2121 |
|
| 2122 |
// Preview black and white backgrounds trigger |
| 2123 |
$preview_block.on('click', function () { |
| 2124 |
|
| 2125 |
$preview.toggleClass('darkify--black-background'); |
| 2126 |
|
| 2127 |
var $toggle = $preview_block.find('.darkify--toggle'); |
| 2128 |
|
| 2129 |
if ($toggle.hasClass('fa-toggle-off')) { |
| 2130 |
$toggle.removeClass('fa-toggle-off').addClass('fa-toggle-on'); |
| 2131 |
} else { |
| 2132 |
$toggle.removeClass('fa-toggle-on').addClass('fa-toggle-off'); |
| 2133 |
} |
| 2134 |
|
| 2135 |
}); |
| 2136 |
|
| 2137 |
if (!$preview_block.hasClass('hidden')) { |
| 2138 |
$this.trigger('change'); |
| 2139 |
} |
| 2140 |
|
| 2141 |
} |
| 2142 |
|
| 2143 |
}; |
| 2144 |
|
| 2145 |
base.init(); |
| 2146 |
|
| 2147 |
}); |
| 2148 |
}; |
| 2149 |
|
| 2150 |
// |
| 2151 |
// Field: upload |
| 2152 |
// |
| 2153 |
$.fn.darkify_field_upload = function () { |
| 2154 |
return this.each(function () { |
| 2155 |
|
| 2156 |
var $this = $(this), |
| 2157 |
$input = $this.find('input'), |
| 2158 |
$upload_button = $this.find('.darkify--button'), |
| 2159 |
$remove_button = $this.find('.darkify--remove'), |
| 2160 |
$preview_wrap = $this.find('.darkify--preview'), |
| 2161 |
$preview_src = $this.find('.darkify--src'), |
| 2162 |
$library = $upload_button.data('library') && $upload_button.data('library').split(',') || '', |
| 2163 |
wp_media_frame; |
| 2164 |
|
| 2165 |
$upload_button.on('click', function (e) { |
| 2166 |
|
| 2167 |
e.preventDefault(); |
| 2168 |
|
| 2169 |
if (typeof window.wp === 'undefined' || !window.wp.media || !window.wp.media.gallery) { |
| 2170 |
return; |
| 2171 |
} |
| 2172 |
|
| 2173 |
if (wp_media_frame) { |
| 2174 |
wp_media_frame.open(); |
| 2175 |
return; |
| 2176 |
} |
| 2177 |
|
| 2178 |
wp_media_frame = window.wp.media({ |
| 2179 |
library: { |
| 2180 |
type: $library |
| 2181 |
}, |
| 2182 |
}); |
| 2183 |
|
| 2184 |
wp_media_frame.on('select', function () { |
| 2185 |
|
| 2186 |
var src; |
| 2187 |
var attributes = wp_media_frame.state().get('selection').first().attributes; |
| 2188 |
|
| 2189 |
if ($library.length && $library.indexOf(attributes.subtype) === -1 && $library.indexOf(attributes.type) === -1) { |
| 2190 |
return; |
| 2191 |
} |
| 2192 |
|
| 2193 |
$input.val(attributes.url).trigger('change'); |
| 2194 |
|
| 2195 |
}); |
| 2196 |
|
| 2197 |
wp_media_frame.open(); |
| 2198 |
|
| 2199 |
}); |
| 2200 |
|
| 2201 |
$remove_button.on('click', function (e) { |
| 2202 |
e.preventDefault(); |
| 2203 |
$input.val('').trigger('change'); |
| 2204 |
}); |
| 2205 |
|
| 2206 |
$input.on('change', function (e) { |
| 2207 |
|
| 2208 |
var $value = $input.val(); |
| 2209 |
|
| 2210 |
if ($value) { |
| 2211 |
$remove_button.removeClass('hidden'); |
| 2212 |
} else { |
| 2213 |
$remove_button.addClass('hidden'); |
| 2214 |
} |
| 2215 |
|
| 2216 |
if ($preview_wrap.length) { |
| 2217 |
|
| 2218 |
if ($.inArray($value.split('.').pop().toLowerCase(), ['jpg', 'jpeg', 'gif', 'png', 'svg', 'webp']) !== -1) { |
| 2219 |
$preview_wrap.removeClass('hidden'); |
| 2220 |
$preview_src.attr('src', $value); |
| 2221 |
} else { |
| 2222 |
$preview_wrap.addClass('hidden'); |
| 2223 |
} |
| 2224 |
|
| 2225 |
} |
| 2226 |
|
| 2227 |
}); |
| 2228 |
|
| 2229 |
}); |
| 2230 |
|
| 2231 |
}; |
| 2232 |
|
| 2233 |
// |
| 2234 |
// Field: wp_editor |
| 2235 |
// |
| 2236 |
$.fn.darkify_field_wp_editor = function () { |
| 2237 |
return this.each(function () { |
| 2238 |
|
| 2239 |
if (typeof window.wp.editor === 'undefined' || typeof window.tinyMCEPreInit === 'undefined' || typeof window.tinyMCEPreInit.mceInit.darkify_wp_editor === 'undefined') { |
| 2240 |
return; |
| 2241 |
} |
| 2242 |
|
| 2243 |
var $this = $(this), |
| 2244 |
$editor = $this.find('.darkify-wp-editor'), |
| 2245 |
$textarea = $this.find('textarea'); |
| 2246 |
|
| 2247 |
// If there is wp-editor remove it for avoid dupliated wp-editor conflicts. |
| 2248 |
var $has_wp_editor = $this.find('.wp-editor-wrap').length || $this.find('.mce-container').length; |
| 2249 |
|
| 2250 |
if ($has_wp_editor) { |
| 2251 |
$editor.empty(); |
| 2252 |
$editor.append($textarea); |
| 2253 |
$textarea.css('display', ''); |
| 2254 |
} |
| 2255 |
|
| 2256 |
// Generate a unique id |
| 2257 |
var uid = DARKIFY.helper.uid('darkify-editor-'); |
| 2258 |
|
| 2259 |
$textarea.attr('id', uid); |
| 2260 |
|
| 2261 |
// Get default editor settings |
| 2262 |
var default_editor_settings = { |
| 2263 |
tinymce: window.tinyMCEPreInit.mceInit.darkify_wp_editor, |
| 2264 |
quicktags: window.tinyMCEPreInit.qtInit.darkify_wp_editor |
| 2265 |
}; |
| 2266 |
|
| 2267 |
// Get default editor settings |
| 2268 |
var field_editor_settings = $editor.data('editor-settings'); |
| 2269 |
|
| 2270 |
// Callback for old wp editor |
| 2271 |
var wpEditor = wp.oldEditor ? wp.oldEditor : wp.editor; |
| 2272 |
|
| 2273 |
if (wpEditor && wpEditor.hasOwnProperty('autop')) { |
| 2274 |
wp.editor.autop = wpEditor.autop; |
| 2275 |
wp.editor.removep = wpEditor.removep; |
| 2276 |
wp.editor.initialize = wpEditor.initialize; |
| 2277 |
} |
| 2278 |
|
| 2279 |
// Add on change event handle |
| 2280 |
var editor_on_change = function (editor) { |
| 2281 |
editor.on('change keyup', function () { |
| 2282 |
var value = (field_editor_settings.wpautop) ? editor.getContent() : wp.editor.removep(editor.getContent()); |
| 2283 |
$textarea.val(value).trigger('change'); |
| 2284 |
}); |
| 2285 |
}; |
| 2286 |
|
| 2287 |
// Extend editor selector and on change event handler |
| 2288 |
default_editor_settings.tinymce = $.extend({}, default_editor_settings.tinymce, { selector: '#' + uid, setup: editor_on_change }); |
| 2289 |
|
| 2290 |
// Override editor tinymce settings |
| 2291 |
if (field_editor_settings.tinymce === false) { |
| 2292 |
default_editor_settings.tinymce = false; |
| 2293 |
$editor.addClass('darkify-no-tinymce'); |
| 2294 |
} |
| 2295 |
|
| 2296 |
// Override editor quicktags settings |
| 2297 |
if (field_editor_settings.quicktags === false) { |
| 2298 |
default_editor_settings.quicktags = false; |
| 2299 |
$editor.addClass('darkify-no-quicktags'); |
| 2300 |
} |
| 2301 |
|
| 2302 |
// Wait until :visible |
| 2303 |
var interval = setInterval(function () { |
| 2304 |
if ($this.is(':visible')) { |
| 2305 |
window.wp.editor.initialize(uid, default_editor_settings); |
| 2306 |
clearInterval(interval); |
| 2307 |
} |
| 2308 |
}); |
| 2309 |
|
| 2310 |
// Add Media buttons |
| 2311 |
if (field_editor_settings.media_buttons && window.darkify_media_buttons) { |
| 2312 |
|
| 2313 |
var $editor_buttons = $editor.find('.wp-media-buttons'); |
| 2314 |
|
| 2315 |
if ($editor_buttons.length) { |
| 2316 |
|
| 2317 |
$editor_buttons.find('.darkify-shortcode-button').data('editor-id', uid); |
| 2318 |
|
| 2319 |
} else { |
| 2320 |
|
| 2321 |
var $media_buttons = $(window.darkify_media_buttons); |
| 2322 |
|
| 2323 |
$media_buttons.find('.darkify-shortcode-button').data('editor-id', uid); |
| 2324 |
|
| 2325 |
$editor.prepend($media_buttons); |
| 2326 |
|
| 2327 |
} |
| 2328 |
|
| 2329 |
} |
| 2330 |
|
| 2331 |
}); |
| 2332 |
|
| 2333 |
}; |
| 2334 |
|
| 2335 |
// |
| 2336 |
// Confirm |
| 2337 |
// |
| 2338 |
$.fn.darkify_confirm = function () { |
| 2339 |
return this.each(function () { |
| 2340 |
$(this).on('click', function (e) { |
| 2341 |
|
| 2342 |
var confirm_text = $(this).data('confirm') || window.darkify_vars.i18n.confirm; |
| 2343 |
var confirm_answer = confirm(confirm_text); |
| 2344 |
|
| 2345 |
if (confirm_answer) { |
| 2346 |
DARKIFY.vars.is_confirm = true; |
| 2347 |
DARKIFY.vars.form_modified = false; |
| 2348 |
} else { |
| 2349 |
e.preventDefault(); |
| 2350 |
return false; |
| 2351 |
} |
| 2352 |
|
| 2353 |
}); |
| 2354 |
}); |
| 2355 |
}; |
| 2356 |
|
| 2357 |
$.fn.serializeObject = function () { |
| 2358 |
|
| 2359 |
var obj = {}; |
| 2360 |
|
| 2361 |
$.each(this.serializeArray(), function (i, o) { |
| 2362 |
var n = o.name, |
| 2363 |
v = o.value; |
| 2364 |
|
| 2365 |
obj[n] = obj[n] === undefined ? v |
| 2366 |
: $.isArray(obj[n]) ? obj[n].concat(v) |
| 2367 |
: [obj[n], v]; |
| 2368 |
}); |
| 2369 |
|
| 2370 |
return obj; |
| 2371 |
|
| 2372 |
}; |
| 2373 |
|
| 2374 |
|
| 2375 |
function darkify_ajax_action() { |
| 2376 |
jQuery.ajax({ |
| 2377 |
url: darkify_vars.ajaxurl, |
| 2378 |
type: "POST", |
| 2379 |
data: { |
| 2380 |
action: "set_options", |
| 2381 |
nonce: darkify_vars.nonce, |
| 2382 |
}, |
| 2383 |
}); |
| 2384 |
} |
| 2385 |
|
| 2386 |
// |
| 2387 |
// Options Save |
| 2388 |
// |
| 2389 |
$.fn.darkify_save = function () { |
| 2390 |
return this.each(function () { |
| 2391 |
|
| 2392 |
var $this = $(this), |
| 2393 |
$buttons = $('.darkify-save'), |
| 2394 |
$panel = $('.darkify-options'), |
| 2395 |
flooding = false, |
| 2396 |
timeout; |
| 2397 |
|
| 2398 |
$this.on('click', function (e) { |
| 2399 |
|
| 2400 |
if (!flooding) { |
| 2401 |
|
| 2402 |
var $text = $this.data('save'), |
| 2403 |
$value = $this.val(); |
| 2404 |
|
| 2405 |
$buttons.attr('value', $text); |
| 2406 |
|
| 2407 |
if ($this.hasClass('darkify-save-ajax')) { |
| 2408 |
|
| 2409 |
e.preventDefault(); |
| 2410 |
|
| 2411 |
$panel.addClass('darkify-saving'); |
| 2412 |
$buttons.prop('disabled', true); |
| 2413 |
darkify_ajax_action(); |
| 2414 |
window.wp.ajax.post('darkify_' + $panel.data('unique') + '_ajax_save', { |
| 2415 |
data: $('#darkify-form').serializeJSONDARKIFY() |
| 2416 |
}) |
| 2417 |
.done(function (response) { |
| 2418 |
|
| 2419 |
// clear errors |
| 2420 |
$('.darkify-error').remove(); |
| 2421 |
|
| 2422 |
if (Object.keys(response.errors).length) { |
| 2423 |
|
| 2424 |
var error_icon = '<i class="darkify-label-error darkify-error">!</i>'; |
| 2425 |
|
| 2426 |
$.each(response.errors, function (key, error_message) { |
| 2427 |
|
| 2428 |
var $field = $('[data-depend-id="' + key + '"]'), |
| 2429 |
$link = $('a[href="#tab=' + $field.closest('.darkify-section').data('section-id') + '"]'), |
| 2430 |
$tab = $link.closest('.darkify-tab-item'); |
| 2431 |
|
| 2432 |
$field.closest('.darkify-fieldset').append('<p class="darkify-error darkify-error-text">' + error_message + '</p>'); |
| 2433 |
|
| 2434 |
if (!$link.find('.darkify-error').length) { |
| 2435 |
$link.append(error_icon); |
| 2436 |
} |
| 2437 |
|
| 2438 |
if (!$tab.find('.darkify-arrow .darkify-error').length) { |
| 2439 |
$tab.find('.darkify-arrow').append(error_icon); |
| 2440 |
} |
| 2441 |
|
| 2442 |
}); |
| 2443 |
|
| 2444 |
} |
| 2445 |
|
| 2446 |
$panel.removeClass('darkify-saving'); |
| 2447 |
$buttons.prop('disabled', false).attr('value', $value); |
| 2448 |
flooding = false; |
| 2449 |
|
| 2450 |
DARKIFY.vars.form_modified = false; |
| 2451 |
DARKIFY.vars.$form_warning.hide(); |
| 2452 |
|
| 2453 |
clearTimeout(timeout); |
| 2454 |
|
| 2455 |
var $result_success = $('.darkify-form-success'); |
| 2456 |
$result_success.empty().append(response.notice).fadeIn('fast', function () { |
| 2457 |
timeout = setTimeout(function () { |
| 2458 |
$result_success.fadeOut('fast'); |
| 2459 |
}, 1000); |
| 2460 |
}); |
| 2461 |
|
| 2462 |
}) |
| 2463 |
.fail(function (response) { |
| 2464 |
alert(response.error); |
| 2465 |
}); |
| 2466 |
|
| 2467 |
} else { |
| 2468 |
|
| 2469 |
DARKIFY.vars.form_modified = false; |
| 2470 |
|
| 2471 |
} |
| 2472 |
|
| 2473 |
} |
| 2474 |
|
| 2475 |
flooding = true; |
| 2476 |
|
| 2477 |
}); |
| 2478 |
|
| 2479 |
}); |
| 2480 |
}; |
| 2481 |
|
| 2482 |
// |
| 2483 |
// Option Framework |
| 2484 |
// |
| 2485 |
$.fn.darkify_options = function () { |
| 2486 |
return this.each(function () { |
| 2487 |
|
| 2488 |
var $this = $(this), |
| 2489 |
$content = $this.find('.darkify-content'), |
| 2490 |
$form_success = $this.find('.darkify-form-success'), |
| 2491 |
$form_warning = $this.find('.darkify-form-warning'), |
| 2492 |
$save_button = $this.find('.darkify-header .darkify-save'); |
| 2493 |
|
| 2494 |
DARKIFY.vars.$form_warning = $form_warning; |
| 2495 |
|
| 2496 |
// Shows a message white leaving theme options without saving |
| 2497 |
if ($form_warning.length) { |
| 2498 |
|
| 2499 |
window.onbeforeunload = function () { |
| 2500 |
return (DARKIFY.vars.form_modified) ? true : undefined; |
| 2501 |
}; |
| 2502 |
|
| 2503 |
$content.on('change keypress', ':input', function () { |
| 2504 |
if (!DARKIFY.vars.form_modified) { |
| 2505 |
$form_success.hide(); |
| 2506 |
$form_warning.fadeIn('fast'); |
| 2507 |
DARKIFY.vars.form_modified = true; |
| 2508 |
} |
| 2509 |
}); |
| 2510 |
|
| 2511 |
} |
| 2512 |
|
| 2513 |
if ($form_success.hasClass('darkify-form-show')) { |
| 2514 |
setTimeout(function () { |
| 2515 |
$form_success.fadeOut('fast'); |
| 2516 |
}, 1000); |
| 2517 |
} |
| 2518 |
|
| 2519 |
$(document).keydown(function (event) { |
| 2520 |
if ((event.ctrlKey || event.metaKey) && event.which === 83) { |
| 2521 |
$save_button.trigger('click'); |
| 2522 |
event.preventDefault(); |
| 2523 |
return false; |
| 2524 |
} |
| 2525 |
}); |
| 2526 |
|
| 2527 |
}); |
| 2528 |
}; |
| 2529 |
|
| 2530 |
// |
| 2531 |
// Taxonomy Framework |
| 2532 |
// |
| 2533 |
$.fn.darkify_taxonomy = function () { |
| 2534 |
return this.each(function () { |
| 2535 |
|
| 2536 |
var $this = $(this), |
| 2537 |
$form = $this.parents('form'); |
| 2538 |
|
| 2539 |
if ($form.attr('id') === 'addtag') { |
| 2540 |
|
| 2541 |
var $submit = $form.find('#submit'), |
| 2542 |
$cloned = $this.children('.darkify-field').darkify_clone(); |
| 2543 |
|
| 2544 |
$submit.on('click', function () { |
| 2545 |
|
| 2546 |
if (!$form.find('.form-required').hasClass('form-invalid')) { |
| 2547 |
|
| 2548 |
$this.data('inited', false); |
| 2549 |
|
| 2550 |
$this.empty(); |
| 2551 |
|
| 2552 |
$this.html($cloned); |
| 2553 |
|
| 2554 |
$cloned = $cloned.darkify_clone(); |
| 2555 |
|
| 2556 |
$this.darkify_reload_script(); |
| 2557 |
|
| 2558 |
} |
| 2559 |
|
| 2560 |
}); |
| 2561 |
|
| 2562 |
} |
| 2563 |
|
| 2564 |
}); |
| 2565 |
}; |
| 2566 |
|
| 2567 |
// |
| 2568 |
// Shortcode Framework |
| 2569 |
// |
| 2570 |
$.fn.darkify_shortcode = function () { |
| 2571 |
|
| 2572 |
var base = this; |
| 2573 |
|
| 2574 |
base.shortcode_parse = function (serialize, key) { |
| 2575 |
|
| 2576 |
var shortcode = ''; |
| 2577 |
|
| 2578 |
$.each(serialize, function (shortcode_key, shortcode_values) { |
| 2579 |
|
| 2580 |
key = (key) ? key : shortcode_key; |
| 2581 |
|
| 2582 |
shortcode += '[' + key; |
| 2583 |
|
| 2584 |
$.each(shortcode_values, function (shortcode_tag, shortcode_value) { |
| 2585 |
|
| 2586 |
if (shortcode_tag === 'content') { |
| 2587 |
|
| 2588 |
shortcode += ']'; |
| 2589 |
shortcode += shortcode_value; |
| 2590 |
shortcode += '[/' + key + ''; |
| 2591 |
|
| 2592 |
} else { |
| 2593 |
|
| 2594 |
shortcode += base.shortcode_tags(shortcode_tag, shortcode_value); |
| 2595 |
|
| 2596 |
} |
| 2597 |
|
| 2598 |
}); |
| 2599 |
|
| 2600 |
shortcode += ']'; |
| 2601 |
|
| 2602 |
}); |
| 2603 |
|
| 2604 |
return shortcode; |
| 2605 |
|
| 2606 |
}; |
| 2607 |
|
| 2608 |
base.shortcode_tags = function (shortcode_tag, shortcode_value) { |
| 2609 |
|
| 2610 |
var shortcode = ''; |
| 2611 |
|
| 2612 |
if (shortcode_value !== '') { |
| 2613 |
|
| 2614 |
if (typeof shortcode_value === 'object' && !$.isArray(shortcode_value)) { |
| 2615 |
|
| 2616 |
$.each(shortcode_value, function (sub_shortcode_tag, sub_shortcode_value) { |
| 2617 |
|
| 2618 |
// sanitize spesific key/value |
| 2619 |
switch (sub_shortcode_tag) { |
| 2620 |
|
| 2621 |
case 'background-image': |
| 2622 |
sub_shortcode_value = (sub_shortcode_value.url) ? sub_shortcode_value.url : ''; |
| 2623 |
break; |
| 2624 |
|
| 2625 |
} |
| 2626 |
|
| 2627 |
if (sub_shortcode_value !== '') { |
| 2628 |
shortcode += ' ' + sub_shortcode_tag + '="' + sub_shortcode_value.toString() + '"'; |
| 2629 |
} |
| 2630 |
|
| 2631 |
}); |
| 2632 |
|
| 2633 |
} else { |
| 2634 |
|
| 2635 |
shortcode += ' ' + shortcode_tag + '="' + shortcode_value.toString() + '"'; |
| 2636 |
|
| 2637 |
} |
| 2638 |
|
| 2639 |
} |
| 2640 |
|
| 2641 |
return shortcode; |
| 2642 |
|
| 2643 |
}; |
| 2644 |
|
| 2645 |
base.insertAtChars = function (_this, currentValue) { |
| 2646 |
|
| 2647 |
var obj = (typeof _this[0].name !== 'undefined') ? _this[0] : _this; |
| 2648 |
|
| 2649 |
if (obj.value.length && typeof obj.selectionStart !== 'undefined') { |
| 2650 |
obj.focus(); |
| 2651 |
return obj.value.substring(0, obj.selectionStart) + currentValue + obj.value.substring(obj.selectionEnd, obj.value.length); |
| 2652 |
} else { |
| 2653 |
obj.focus(); |
| 2654 |
return currentValue; |
| 2655 |
} |
| 2656 |
|
| 2657 |
}; |
| 2658 |
|
| 2659 |
base.send_to_editor = function (html, editor_id) { |
| 2660 |
|
| 2661 |
var tinymce_editor; |
| 2662 |
|
| 2663 |
if (typeof tinymce !== 'undefined') { |
| 2664 |
tinymce_editor = tinymce.get(editor_id); |
| 2665 |
} |
| 2666 |
|
| 2667 |
if (tinymce_editor && !tinymce_editor.isHidden()) { |
| 2668 |
tinymce_editor.execCommand('mceInsertContent', false, html); |
| 2669 |
} else { |
| 2670 |
var $editor = $('#' + editor_id); |
| 2671 |
$editor.val(base.insertAtChars($editor, html)).trigger('change'); |
| 2672 |
} |
| 2673 |
|
| 2674 |
}; |
| 2675 |
|
| 2676 |
return this.each(function () { |
| 2677 |
|
| 2678 |
var $modal = $(this), |
| 2679 |
$load = $modal.find('.darkify-modal-load'), |
| 2680 |
$content = $modal.find('.darkify-modal-content'), |
| 2681 |
$insert = $modal.find('.darkify-modal-insert'), |
| 2682 |
$loading = $modal.find('.darkify-modal-loading'), |
| 2683 |
$select = $modal.find('select'), |
| 2684 |
modal_id = $modal.data('modal-id'), |
| 2685 |
nonce = $modal.data('nonce'), |
| 2686 |
editor_id, |
| 2687 |
target_id, |
| 2688 |
gutenberg_id, |
| 2689 |
sc_key, |
| 2690 |
sc_name, |
| 2691 |
sc_view, |
| 2692 |
sc_group, |
| 2693 |
$cloned, |
| 2694 |
$button; |
| 2695 |
|
| 2696 |
$(document).on('click', '.darkify-shortcode-button[data-modal-id="' + modal_id + '"]', function (e) { |
| 2697 |
|
| 2698 |
e.preventDefault(); |
| 2699 |
|
| 2700 |
$button = $(this); |
| 2701 |
editor_id = $button.data('editor-id') || false; |
| 2702 |
target_id = $button.data('target-id') || false; |
| 2703 |
gutenberg_id = $button.data('gutenberg-id') || false; |
| 2704 |
|
| 2705 |
$modal.removeClass('hidden'); |
| 2706 |
|
| 2707 |
// single usage trigger first shortcode |
| 2708 |
if ($modal.hasClass('darkify-shortcode-single') && sc_name === undefined) { |
| 2709 |
$select.trigger('change'); |
| 2710 |
} |
| 2711 |
|
| 2712 |
}); |
| 2713 |
|
| 2714 |
$select.on('change', function () { |
| 2715 |
|
| 2716 |
var $option = $(this); |
| 2717 |
var $selected = $option.find(':selected'); |
| 2718 |
|
| 2719 |
sc_key = $option.val(); |
| 2720 |
sc_name = $selected.data('shortcode'); |
| 2721 |
sc_view = $selected.data('view') || 'normal'; |
| 2722 |
sc_group = $selected.data('group') || sc_name; |
| 2723 |
|
| 2724 |
$load.empty(); |
| 2725 |
|
| 2726 |
if (sc_key) { |
| 2727 |
|
| 2728 |
$loading.show(); |
| 2729 |
|
| 2730 |
window.wp.ajax.post('darkify-get-shortcode-' + modal_id, { |
| 2731 |
shortcode_key: sc_key, |
| 2732 |
nonce: nonce |
| 2733 |
}) |
| 2734 |
.done(function (response) { |
| 2735 |
|
| 2736 |
$loading.hide(); |
| 2737 |
|
| 2738 |
var $appended = $(response.content).appendTo($load); |
| 2739 |
|
| 2740 |
$insert.parent().removeClass('hidden'); |
| 2741 |
|
| 2742 |
$cloned = $appended.find('.darkify--repeat-shortcode').darkify_clone(); |
| 2743 |
|
| 2744 |
$appended.darkify_reload_script(); |
| 2745 |
$appended.find('.darkify-fields').darkify_reload_script(); |
| 2746 |
|
| 2747 |
}); |
| 2748 |
|
| 2749 |
} else { |
| 2750 |
|
| 2751 |
$insert.parent().addClass('hidden'); |
| 2752 |
|
| 2753 |
} |
| 2754 |
|
| 2755 |
}); |
| 2756 |
|
| 2757 |
$insert.on('click', function (e) { |
| 2758 |
|
| 2759 |
e.preventDefault(); |
| 2760 |
|
| 2761 |
if ($insert.prop('disabled') || $insert.attr('disabled')) { return; } |
| 2762 |
|
| 2763 |
var shortcode = ''; |
| 2764 |
var serialize = $modal.find('.darkify-field:not(.darkify-depend-on)').find(':input:not(.ignore)').serializeObjectDARKIFY(); |
| 2765 |
|
| 2766 |
switch (sc_view) { |
| 2767 |
|
| 2768 |
case 'contents': |
| 2769 |
var contentsObj = (sc_name) ? serialize[sc_name] : serialize; |
| 2770 |
$.each(contentsObj, function (sc_key, sc_value) { |
| 2771 |
var sc_tag = (sc_name) ? sc_name : sc_key; |
| 2772 |
shortcode += '[' + sc_tag + ']' + sc_value + '[/' + sc_tag + ']'; |
| 2773 |
}); |
| 2774 |
break; |
| 2775 |
|
| 2776 |
case 'group': |
| 2777 |
|
| 2778 |
shortcode += '[' + sc_name; |
| 2779 |
$.each(serialize[sc_name], function (sc_key, sc_value) { |
| 2780 |
shortcode += base.shortcode_tags(sc_key, sc_value); |
| 2781 |
}); |
| 2782 |
shortcode += ']'; |
| 2783 |
shortcode += base.shortcode_parse(serialize[sc_group], sc_group); |
| 2784 |
shortcode += '[/' + sc_name + ']'; |
| 2785 |
|
| 2786 |
break; |
| 2787 |
|
| 2788 |
case 'repeater': |
| 2789 |
shortcode += base.shortcode_parse(serialize[sc_group], sc_group); |
| 2790 |
break; |
| 2791 |
|
| 2792 |
default: |
| 2793 |
shortcode += base.shortcode_parse(serialize); |
| 2794 |
break; |
| 2795 |
|
| 2796 |
} |
| 2797 |
|
| 2798 |
shortcode = (shortcode === '') ? '[' + sc_name + ']' : shortcode; |
| 2799 |
|
| 2800 |
if (gutenberg_id) { |
| 2801 |
|
| 2802 |
var content = window.darkify_gutenberg_props.attributes.hasOwnProperty('shortcode') ? window.darkify_gutenberg_props.attributes.shortcode : ''; |
| 2803 |
window.darkify_gutenberg_props.setAttributes({ shortcode: content + shortcode }); |
| 2804 |
|
| 2805 |
} else if (editor_id) { |
| 2806 |
|
| 2807 |
base.send_to_editor(shortcode, editor_id); |
| 2808 |
|
| 2809 |
} else { |
| 2810 |
|
| 2811 |
var $textarea = (target_id) ? $(target_id) : $button.parent().find('textarea'); |
| 2812 |
$textarea.val(base.insertAtChars($textarea, shortcode)).trigger('change'); |
| 2813 |
|
| 2814 |
} |
| 2815 |
|
| 2816 |
$modal.addClass('hidden'); |
| 2817 |
|
| 2818 |
}); |
| 2819 |
|
| 2820 |
$modal.on('click', '.darkify--repeat-button', function (e) { |
| 2821 |
|
| 2822 |
e.preventDefault(); |
| 2823 |
|
| 2824 |
var $repeatable = $modal.find('.darkify--repeatable'); |
| 2825 |
var $new_clone = $cloned.darkify_clone(); |
| 2826 |
var $remove_btn = $new_clone.find('.darkify-repeat-remove'); |
| 2827 |
|
| 2828 |
var $appended = $new_clone.appendTo($repeatable); |
| 2829 |
|
| 2830 |
$new_clone.find('.darkify-fields').darkify_reload_script(); |
| 2831 |
|
| 2832 |
DARKIFY.helper.name_nested_replace($modal.find('.darkify--repeat-shortcode'), sc_group); |
| 2833 |
|
| 2834 |
$remove_btn.on('click', function () { |
| 2835 |
|
| 2836 |
$new_clone.remove(); |
| 2837 |
|
| 2838 |
DARKIFY.helper.name_nested_replace($modal.find('.darkify--repeat-shortcode'), sc_group); |
| 2839 |
|
| 2840 |
}); |
| 2841 |
|
| 2842 |
}); |
| 2843 |
|
| 2844 |
$modal.on('click', '.darkify-modal-close, .darkify-modal-overlay', function () { |
| 2845 |
$modal.addClass('hidden'); |
| 2846 |
}); |
| 2847 |
|
| 2848 |
}); |
| 2849 |
}; |
| 2850 |
|
| 2851 |
// |
| 2852 |
// WP Color Picker |
| 2853 |
// |
| 2854 |
if (typeof Color === 'function') { |
| 2855 |
|
| 2856 |
Color.prototype.toString = function () { |
| 2857 |
|
| 2858 |
if (this._alpha < 1) { |
| 2859 |
return this.toCSS('rgba', this._alpha).replace(/\s+/g, ''); |
| 2860 |
} |
| 2861 |
|
| 2862 |
var hex = parseInt(this._color, 10).toString(16); |
| 2863 |
|
| 2864 |
if (this.error) { return ''; } |
| 2865 |
|
| 2866 |
if (hex.length < 6) { |
| 2867 |
for (var i = 6 - hex.length - 1; i >= 0; i--) { |
| 2868 |
hex = '0' + hex; |
| 2869 |
} |
| 2870 |
} |
| 2871 |
|
| 2872 |
return '#' + hex; |
| 2873 |
|
| 2874 |
}; |
| 2875 |
|
| 2876 |
} |
| 2877 |
|
| 2878 |
DARKIFY.funcs.parse_color = function (color) { |
| 2879 |
|
| 2880 |
var value = color.replace(/\s+/g, ''), |
| 2881 |
trans = (value.indexOf('rgba') !== -1) ? parseFloat(value.replace(/^.*,(.+)\)/, '$1') * 100) : 100, |
| 2882 |
rgba = (trans < 100) ? true : false; |
| 2883 |
|
| 2884 |
return { value: value, transparent: trans, rgba: rgba }; |
| 2885 |
|
| 2886 |
}; |
| 2887 |
|
| 2888 |
$.fn.darkify_color = function () { |
| 2889 |
return this.each(function () { |
| 2890 |
|
| 2891 |
var $input = $(this), |
| 2892 |
picker_color = DARKIFY.funcs.parse_color($input.val()), |
| 2893 |
palette_color = window.darkify_vars.color_palette.length ? window.darkify_vars.color_palette : true, |
| 2894 |
$container; |
| 2895 |
|
| 2896 |
// Destroy and Reinit |
| 2897 |
if ($input.hasClass('wp-color-picker')) { |
| 2898 |
$input.closest('.wp-picker-container').after($input).remove(); |
| 2899 |
} |
| 2900 |
|
| 2901 |
$input.wpColorPicker({ |
| 2902 |
palettes: palette_color, |
| 2903 |
change: function (event, ui) { |
| 2904 |
|
| 2905 |
var ui_color_value = ui.color.toString(); |
| 2906 |
|
| 2907 |
$container.removeClass('darkify--transparent-active'); |
| 2908 |
$container.find('.darkify--transparent-offset').css('background-color', ui_color_value); |
| 2909 |
$input.val(ui_color_value).trigger('change'); |
| 2910 |
|
| 2911 |
}, |
| 2912 |
create: function () { |
| 2913 |
|
| 2914 |
$container = $input.closest('.wp-picker-container'); |
| 2915 |
|
| 2916 |
var a8cIris = $input.data('a8cIris'), |
| 2917 |
$transparent_wrap = $('<div class="darkify--transparent-wrap">' + |
| 2918 |
'<div class="darkify--transparent-slider"></div>' + |
| 2919 |
'<div class="darkify--transparent-offset"></div>' + |
| 2920 |
'<div class="darkify--transparent-text"></div>' + |
| 2921 |
'<div class="darkify--transparent-button">transparent <i class="icofont-toggle-off"></i></div>' + |
| 2922 |
'</div>').appendTo($container.find('.wp-picker-holder')), |
| 2923 |
$transparent_slider = $transparent_wrap.find('.darkify--transparent-slider'), |
| 2924 |
$transparent_text = $transparent_wrap.find('.darkify--transparent-text'), |
| 2925 |
$transparent_offset = $transparent_wrap.find('.darkify--transparent-offset'), |
| 2926 |
$transparent_button = $transparent_wrap.find('.darkify--transparent-button'); |
| 2927 |
|
| 2928 |
if ($input.val() === 'transparent') { |
| 2929 |
$container.addClass('darkify--transparent-active'); |
| 2930 |
} |
| 2931 |
|
| 2932 |
$transparent_button.on('click', function () { |
| 2933 |
if ($input.val() !== 'transparent') { |
| 2934 |
$input.val('transparent').trigger('change').removeClass('iris-error'); |
| 2935 |
$container.addClass('darkify--transparent-active'); |
| 2936 |
} else { |
| 2937 |
$input.val(a8cIris._color.toString()).trigger('change'); |
| 2938 |
$container.removeClass('darkify--transparent-active'); |
| 2939 |
} |
| 2940 |
}); |
| 2941 |
|
| 2942 |
$transparent_slider.slider({ |
| 2943 |
value: picker_color.transparent, |
| 2944 |
step: 1, |
| 2945 |
min: 0, |
| 2946 |
max: 100, |
| 2947 |
slide: function (event, ui) { |
| 2948 |
|
| 2949 |
var slide_value = parseFloat(ui.value / 100); |
| 2950 |
a8cIris._color._alpha = slide_value; |
| 2951 |
$input.wpColorPicker('color', a8cIris._color.toString()); |
| 2952 |
$transparent_text.text((slide_value === 1 || slide_value === 0 ? '' : slide_value)); |
| 2953 |
|
| 2954 |
}, |
| 2955 |
create: function () { |
| 2956 |
|
| 2957 |
var slide_value = parseFloat(picker_color.transparent / 100), |
| 2958 |
text_value = slide_value < 1 ? slide_value : ''; |
| 2959 |
|
| 2960 |
$transparent_text.text(text_value); |
| 2961 |
$transparent_offset.css('background-color', picker_color.value); |
| 2962 |
|
| 2963 |
$container.on('click', '.wp-picker-clear', function () { |
| 2964 |
|
| 2965 |
a8cIris._color._alpha = 1; |
| 2966 |
$transparent_text.text(''); |
| 2967 |
$transparent_slider.slider('option', 'value', 100); |
| 2968 |
$container.removeClass('darkify--transparent-active'); |
| 2969 |
$input.trigger('change'); |
| 2970 |
|
| 2971 |
}); |
| 2972 |
|
| 2973 |
$container.on('click', '.wp-picker-default', function () { |
| 2974 |
|
| 2975 |
var default_color = DARKIFY.funcs.parse_color($input.data('default-color')), |
| 2976 |
default_value = parseFloat(default_color.transparent / 100), |
| 2977 |
default_text = default_value < 1 ? default_value : ''; |
| 2978 |
|
| 2979 |
a8cIris._color._alpha = default_value; |
| 2980 |
$transparent_text.text(default_text); |
| 2981 |
$transparent_slider.slider('option', 'value', default_color.transparent); |
| 2982 |
|
| 2983 |
if (default_color.value === 'transparent') { |
| 2984 |
$input.removeClass('iris-error'); |
| 2985 |
$container.addClass('darkify--transparent-active'); |
| 2986 |
} |
| 2987 |
|
| 2988 |
}); |
| 2989 |
|
| 2990 |
} |
| 2991 |
}); |
| 2992 |
} |
| 2993 |
}); |
| 2994 |
|
| 2995 |
}); |
| 2996 |
}; |
| 2997 |
|
| 2998 |
// |
| 2999 |
// ChosenJS |
| 3000 |
// |
| 3001 |
$.fn.darkify_chosen = function () { |
| 3002 |
return this.each(function () { |
| 3003 |
|
| 3004 |
var $this = $(this), |
| 3005 |
$inited = $this.parent().find('.chosen-container'), |
| 3006 |
is_sortable = $this.hasClass('darkify-chosen-sortable') || false, |
| 3007 |
is_ajax = $this.hasClass('darkify-chosen-ajax') || false, |
| 3008 |
is_multiple = $this.attr('multiple') || false, |
| 3009 |
set_width = is_multiple ? '100%' : 'auto', |
| 3010 |
set_options = $.extend({ |
| 3011 |
allow_single_deselect: true, |
| 3012 |
disable_search_threshold: 10, |
| 3013 |
width: set_width, |
| 3014 |
no_results_text: window.darkify_vars.i18n.no_results_text, |
| 3015 |
}, $this.data('chosen-settings')); |
| 3016 |
|
| 3017 |
if ($inited.length) { |
| 3018 |
$inited.remove(); |
| 3019 |
} |
| 3020 |
|
| 3021 |
// Chosen ajax |
| 3022 |
if (is_ajax) { |
| 3023 |
|
| 3024 |
var set_ajax_options = $.extend({ |
| 3025 |
data: { |
| 3026 |
type: 'post', |
| 3027 |
nonce: '', |
| 3028 |
}, |
| 3029 |
allow_single_deselect: true, |
| 3030 |
disable_search_threshold: -1, |
| 3031 |
width: '100%', |
| 3032 |
min_length: 3, |
| 3033 |
type_delay: 500, |
| 3034 |
typing_text: window.darkify_vars.i18n.typing_text, |
| 3035 |
searching_text: window.darkify_vars.i18n.searching_text, |
| 3036 |
no_results_text: window.darkify_vars.i18n.no_results_text, |
| 3037 |
}, $this.data('chosen-settings')); |
| 3038 |
|
| 3039 |
$this.DARKIFYAjaxChosen(set_ajax_options); |
| 3040 |
|
| 3041 |
} else { |
| 3042 |
|
| 3043 |
$this.chosen(set_options); |
| 3044 |
|
| 3045 |
} |
| 3046 |
|
| 3047 |
// Chosen keep options order |
| 3048 |
if (is_multiple) { |
| 3049 |
|
| 3050 |
var $hidden_select = $this.parent().find('.darkify-hide-select'); |
| 3051 |
var $hidden_value = $hidden_select.val() || []; |
| 3052 |
|
| 3053 |
$this.on('change', function (obj, result) { |
| 3054 |
|
| 3055 |
if (result && result.selected) { |
| 3056 |
$hidden_select.append('<option value="' + result.selected + '" selected="selected">' + result.selected + '</option>'); |
| 3057 |
} else if (result && result.deselected) { |
| 3058 |
$hidden_select.find('option[value="' + result.deselected + '"]').remove(); |
| 3059 |
} |
| 3060 |
|
| 3061 |
// Force customize refresh |
| 3062 |
if (window.wp.customize !== undefined && $hidden_select.children().length === 0 && $hidden_select.data('customize-setting-link')) { |
| 3063 |
window.wp.customize.control($hidden_select.data('customize-setting-link')).setting.set(''); |
| 3064 |
} |
| 3065 |
|
| 3066 |
$hidden_select.trigger('change'); |
| 3067 |
|
| 3068 |
}); |
| 3069 |
|
| 3070 |
// Chosen order abstract |
| 3071 |
$this.DARKIFYChosenOrder($hidden_value, true); |
| 3072 |
|
| 3073 |
} |
| 3074 |
|
| 3075 |
// Chosen sortable |
| 3076 |
if (is_sortable) { |
| 3077 |
|
| 3078 |
var $chosen_container = $this.parent().find('.chosen-container'); |
| 3079 |
var $chosen_choices = $chosen_container.find('.chosen-choices'); |
| 3080 |
|
| 3081 |
$chosen_choices.bind('mousedown', function (event) { |
| 3082 |
if ($(event.target).is('span')) { |
| 3083 |
event.stopPropagation(); |
| 3084 |
} |
| 3085 |
}); |
| 3086 |
|
| 3087 |
$chosen_choices.sortable({ |
| 3088 |
items: 'li:not(.search-field)', |
| 3089 |
helper: 'orginal', |
| 3090 |
cursor: 'move', |
| 3091 |
placeholder: 'search-choice-placeholder', |
| 3092 |
start: function (e, ui) { |
| 3093 |
ui.placeholder.width(ui.item.innerWidth()); |
| 3094 |
ui.placeholder.height(ui.item.innerHeight()); |
| 3095 |
}, |
| 3096 |
update: function (e, ui) { |
| 3097 |
|
| 3098 |
var select_options = ''; |
| 3099 |
var chosen_object = $this.data('chosen'); |
| 3100 |
var $prev_select = $this.parent().find('.darkify-hide-select'); |
| 3101 |
|
| 3102 |
$chosen_choices.find('.search-choice-close').each(function () { |
| 3103 |
var option_array_index = $(this).data('option-array-index'); |
| 3104 |
$.each(chosen_object.results_data, function (index, data) { |
| 3105 |
if (data.array_index === option_array_index) { |
| 3106 |
select_options += '<option value="' + data.value + '" selected>' + data.value + '</option>'; |
| 3107 |
} |
| 3108 |
}); |
| 3109 |
}); |
| 3110 |
|
| 3111 |
$prev_select.children().remove(); |
| 3112 |
$prev_select.append(select_options); |
| 3113 |
$prev_select.trigger('change'); |
| 3114 |
|
| 3115 |
} |
| 3116 |
}); |
| 3117 |
|
| 3118 |
} |
| 3119 |
|
| 3120 |
}); |
| 3121 |
}; |
| 3122 |
|
| 3123 |
// |
| 3124 |
// Helper Checkbox Checker |
| 3125 |
// |
| 3126 |
$.fn.darkify_checkbox = function () { |
| 3127 |
return this.each(function () { |
| 3128 |
|
| 3129 |
var $this = $(this), |
| 3130 |
$input = $this.find('.darkify--input'), |
| 3131 |
$checkbox = $this.find('.darkify--checkbox'); |
| 3132 |
|
| 3133 |
$checkbox.on('click', function () { |
| 3134 |
$input.val(Number($checkbox.prop('checked'))).trigger('change'); |
| 3135 |
}); |
| 3136 |
|
| 3137 |
}); |
| 3138 |
}; |
| 3139 |
|
| 3140 |
// |
| 3141 |
// Helper Check/Uncheck All |
| 3142 |
// |
| 3143 |
$.fn.darkify_checkbox_all = function () { |
| 3144 |
return this.each(function () { |
| 3145 |
|
| 3146 |
var $this = $(this); |
| 3147 |
|
| 3148 |
$this.on('click', function () { |
| 3149 |
|
| 3150 |
var $inputs = $this.closest('.darkify-field-checkbox').find(':input'), |
| 3151 |
uncheck = false; |
| 3152 |
|
| 3153 |
$inputs.each(function () { |
| 3154 |
if (!$(this).prop('checked')) { |
| 3155 |
uncheck = true; |
| 3156 |
} |
| 3157 |
}); |
| 3158 |
|
| 3159 |
if (uncheck) { |
| 3160 |
$inputs.prop('checked', 'checked'); |
| 3161 |
$inputs.attr('checked', 'checked'); |
| 3162 |
} else { |
| 3163 |
$inputs.prop('checked', ''); |
| 3164 |
$inputs.removeAttr('checked'); |
| 3165 |
} |
| 3166 |
|
| 3167 |
$inputs.first().trigger('change'); |
| 3168 |
|
| 3169 |
}); |
| 3170 |
|
| 3171 |
}); |
| 3172 |
}; |
| 3173 |
|
| 3174 |
// |
| 3175 |
// Siblings |
| 3176 |
// |
| 3177 |
$.fn.darkify_siblings = function () { |
| 3178 |
return this.each(function () { |
| 3179 |
|
| 3180 |
var $this = $(this), |
| 3181 |
$siblings = $this.find('.darkify--sibling:not(.darkify-pro-only)'), |
| 3182 |
multiple = $this.data('multiple') || false; |
| 3183 |
$this.find('.darkify--sibling.darkify-pro-only').find('input').prop('disable', true) |
| 3184 |
$siblings.on('click', function () { |
| 3185 |
|
| 3186 |
var $sibling = $(this); |
| 3187 |
|
| 3188 |
if (multiple) { |
| 3189 |
|
| 3190 |
if ($sibling.hasClass('darkify--active')) { |
| 3191 |
$sibling.removeClass('darkify--active'); |
| 3192 |
$sibling.find('input').prop('checked', false).trigger('change'); |
| 3193 |
} else { |
| 3194 |
$sibling.addClass('darkify--active'); |
| 3195 |
$sibling.find('input').prop('checked', true).trigger('change'); |
| 3196 |
} |
| 3197 |
|
| 3198 |
} else { |
| 3199 |
|
| 3200 |
$this.find('input').prop('checked', false); |
| 3201 |
$sibling.find('input').prop('checked', true).trigger('change'); |
| 3202 |
$sibling.addClass('darkify--active').siblings().removeClass('darkify--active'); |
| 3203 |
|
| 3204 |
} |
| 3205 |
|
| 3206 |
}); |
| 3207 |
|
| 3208 |
}); |
| 3209 |
}; |
| 3210 |
|
| 3211 |
// |
| 3212 |
// Help Tooltip |
| 3213 |
// |
| 3214 |
$.fn.darkify_help = function () { |
| 3215 |
return this.each(function () { |
| 3216 |
|
| 3217 |
var $this = $(this), |
| 3218 |
$tooltip, |
| 3219 |
offset_left; |
| 3220 |
|
| 3221 |
$this.on({ |
| 3222 |
mouseenter: function () { |
| 3223 |
|
| 3224 |
$tooltip = $('<div class="darkify-tooltip"></div>').html($this.find('.darkify-help-text').html()).appendTo('body'); |
| 3225 |
offset_left = (DARKIFY.vars.is_rtl) ? ($this.offset().left + 24) : ($this.offset().left - $tooltip.outerWidth()); |
| 3226 |
|
| 3227 |
$tooltip.css({ |
| 3228 |
top: $this.offset().top - (($tooltip.outerHeight() / 2) - 14), |
| 3229 |
left: offset_left, |
| 3230 |
}); |
| 3231 |
|
| 3232 |
}, |
| 3233 |
mouseleave: function () { |
| 3234 |
|
| 3235 |
if ($tooltip !== undefined) { |
| 3236 |
$tooltip.remove(); |
| 3237 |
} |
| 3238 |
|
| 3239 |
} |
| 3240 |
|
| 3241 |
}); |
| 3242 |
|
| 3243 |
}); |
| 3244 |
}; |
| 3245 |
|
| 3246 |
// |
| 3247 |
// Customize Refresh |
| 3248 |
// |
| 3249 |
$.fn.darkify_customizer_refresh = function () { |
| 3250 |
return this.each(function () { |
| 3251 |
|
| 3252 |
var $this = $(this), |
| 3253 |
$complex = $this.closest('.darkify-customize-complex'); |
| 3254 |
|
| 3255 |
if ($complex.length) { |
| 3256 |
|
| 3257 |
var unique_id = $complex.data('unique-id'); |
| 3258 |
|
| 3259 |
if (unique_id === undefined) { |
| 3260 |
return; |
| 3261 |
} |
| 3262 |
|
| 3263 |
var $input = $complex.find(':input'), |
| 3264 |
option_id = $complex.data('option-id'), |
| 3265 |
obj = $input.serializeObjectDARKIFY(), |
| 3266 |
data = (!$.isEmptyObject(obj) && obj[unique_id] && obj[unique_id][option_id]) ? obj[unique_id][option_id] : '', |
| 3267 |
control = window.wp.customize.control(unique_id + '[' + option_id + ']'); |
| 3268 |
|
| 3269 |
// clear the value to force refresh. |
| 3270 |
control.setting._value = null; |
| 3271 |
|
| 3272 |
control.setting.set(data); |
| 3273 |
|
| 3274 |
} else { |
| 3275 |
|
| 3276 |
$this.find(':input').first().trigger('change'); |
| 3277 |
|
| 3278 |
} |
| 3279 |
|
| 3280 |
$(document).trigger('darkify-customizer-refresh', $this); |
| 3281 |
|
| 3282 |
}); |
| 3283 |
}; |
| 3284 |
|
| 3285 |
// |
| 3286 |
// Customize Listen Form Elements |
| 3287 |
// |
| 3288 |
$.fn.darkify_customizer_listen = function (options) { |
| 3289 |
|
| 3290 |
var settings = $.extend({ |
| 3291 |
closest: false, |
| 3292 |
}, options); |
| 3293 |
|
| 3294 |
return this.each(function () { |
| 3295 |
|
| 3296 |
if (window.wp.customize === undefined) { return; } |
| 3297 |
|
| 3298 |
var $this = (settings.closest) ? $(this).closest('.darkify-customize-complex') : $(this), |
| 3299 |
$input = $this.find(':input'), |
| 3300 |
unique_id = $this.data('unique-id'), |
| 3301 |
option_id = $this.data('option-id'); |
| 3302 |
|
| 3303 |
if (unique_id === undefined) { |
| 3304 |
return; |
| 3305 |
} |
| 3306 |
|
| 3307 |
$input.on('change keyup darkify.change', function () { |
| 3308 |
|
| 3309 |
var obj = $this.find(':input').serializeObjectDARKIFY(); |
| 3310 |
var val = (!$.isEmptyObject(obj) && obj[unique_id] && obj[unique_id][option_id]) ? obj[unique_id][option_id] : ''; |
| 3311 |
|
| 3312 |
window.wp.customize.control(unique_id + '[' + option_id + ']').setting.set(val); |
| 3313 |
|
| 3314 |
}); |
| 3315 |
|
| 3316 |
}); |
| 3317 |
}; |
| 3318 |
|
| 3319 |
// |
| 3320 |
// Customizer Listener for Reload JS |
| 3321 |
// |
| 3322 |
$(document).on('expanded', '.control-section', function () { |
| 3323 |
|
| 3324 |
var $this = $(this); |
| 3325 |
|
| 3326 |
if ($this.hasClass('open') && !$this.data('inited')) { |
| 3327 |
|
| 3328 |
var $fields = $this.find('.darkify-customize-field'); |
| 3329 |
var $complex = $this.find('.darkify-customize-complex'); |
| 3330 |
|
| 3331 |
if ($fields.length) { |
| 3332 |
$this.darkify_dependency(); |
| 3333 |
$fields.darkify_reload_script({ dependency: false }); |
| 3334 |
$complex.darkify_customizer_listen(); |
| 3335 |
} |
| 3336 |
|
| 3337 |
$this.data('inited', true); |
| 3338 |
|
| 3339 |
} |
| 3340 |
|
| 3341 |
}); |
| 3342 |
|
| 3343 |
// |
| 3344 |
// Window on resize |
| 3345 |
// |
| 3346 |
DARKIFY.vars.$window.on('resize darkify.resize', DARKIFY.helper.debounce(function (event) { |
| 3347 |
|
| 3348 |
var window_width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? DARKIFY.vars.$window.width() : window.innerWidth; |
| 3349 |
|
| 3350 |
if (window_width <= 782 && !DARKIFY.vars.onloaded) { |
| 3351 |
$('.darkify-section').darkify_reload_script(); |
| 3352 |
DARKIFY.vars.onloaded = true; |
| 3353 |
} |
| 3354 |
|
| 3355 |
}, 200)).trigger('darkify.resize'); |
| 3356 |
|
| 3357 |
// |
| 3358 |
// Widgets Framework |
| 3359 |
// |
| 3360 |
$.fn.darkify_widgets = function () { |
| 3361 |
return this.each(function () { |
| 3362 |
|
| 3363 |
$(document).on('widget-added widget-updated', function (event, $widget) { |
| 3364 |
|
| 3365 |
var $fields = $widget.find('.darkify-fields'); |
| 3366 |
|
| 3367 |
if ($fields.length) { |
| 3368 |
$fields.darkify_reload_script(); |
| 3369 |
} |
| 3370 |
|
| 3371 |
}); |
| 3372 |
|
| 3373 |
$(document).on('click', '.widget-top', function (event) { |
| 3374 |
|
| 3375 |
var $fields = $(this).parent().find('.darkify-fields'); |
| 3376 |
|
| 3377 |
if ($fields.length) { |
| 3378 |
$fields.darkify_reload_script(); |
| 3379 |
} |
| 3380 |
|
| 3381 |
}); |
| 3382 |
|
| 3383 |
$('.widgets-sortables, .control-section-sidebar').on('sortstop', function (event, ui) { |
| 3384 |
ui.item.find('.darkify-fields').darkify_reload_script_retry(); |
| 3385 |
}); |
| 3386 |
|
| 3387 |
}); |
| 3388 |
}; |
| 3389 |
|
| 3390 |
// |
| 3391 |
// Nav Menu Options Framework |
| 3392 |
// |
| 3393 |
$.fn.darkify_nav_menu = function () { |
| 3394 |
return this.each(function () { |
| 3395 |
|
| 3396 |
var $navmenu = $(this); |
| 3397 |
|
| 3398 |
$navmenu.on('click', 'a.item-edit', function () { |
| 3399 |
$(this).closest('li.menu-item').find('.darkify-fields').darkify_reload_script(); |
| 3400 |
}); |
| 3401 |
|
| 3402 |
$navmenu.on('sortstop', function (event, ui) { |
| 3403 |
ui.item.find('.darkify-fields').darkify_reload_script_retry(); |
| 3404 |
}); |
| 3405 |
|
| 3406 |
}); |
| 3407 |
}; |
| 3408 |
|
| 3409 |
// |
| 3410 |
// Retry Plugins |
| 3411 |
// |
| 3412 |
$.fn.darkify_reload_script_retry = function () { |
| 3413 |
return this.each(function () { |
| 3414 |
|
| 3415 |
var $this = $(this); |
| 3416 |
|
| 3417 |
if ($this.data('inited')) { |
| 3418 |
$this.children('.darkify-field-wp_editor').darkify_field_wp_editor(); |
| 3419 |
} |
| 3420 |
|
| 3421 |
}); |
| 3422 |
}; |
| 3423 |
|
| 3424 |
// |
| 3425 |
// Reload Plugins |
| 3426 |
// |
| 3427 |
$.fn.darkify_reload_script = function (options) { |
| 3428 |
|
| 3429 |
var settings = $.extend({ |
| 3430 |
dependency: true, |
| 3431 |
}, options); |
| 3432 |
|
| 3433 |
return this.each(function () { |
| 3434 |
|
| 3435 |
var $this = $(this); |
| 3436 |
|
| 3437 |
// Avoid for conflicts |
| 3438 |
if (!$this.data('inited')) { |
| 3439 |
|
| 3440 |
// Field plugins |
| 3441 |
$this.children('.darkify-field-accordion').darkify_field_accordion(); |
| 3442 |
$this.children('.darkify-field-backup').darkify_field_backup(); |
| 3443 |
$this.children('.darkify-field-background').darkify_field_background(); |
| 3444 |
$this.children('.darkify-field-code_editor').darkify_field_code_editor(); |
| 3445 |
$this.children('.darkify-field-date').darkify_field_date(); |
| 3446 |
$this.children('.darkify-field-datetime').darkify_field_datetime(); |
| 3447 |
$this.children('.darkify-field-fieldset').darkify_field_fieldset(); |
| 3448 |
$this.children('.darkify-field-gallery').darkify_field_gallery(); |
| 3449 |
$this.children('.darkify-field-group').darkify_field_group(); |
| 3450 |
$this.children('.darkify-field-icon').darkify_field_icon(); |
| 3451 |
$this.children('.darkify-field-link').darkify_field_link(); |
| 3452 |
$this.children('.darkify-field-media').darkify_field_media(); |
| 3453 |
$this.children('.darkify-field-map').darkify_field_map(); |
| 3454 |
$this.children('.darkify-field-repeater').darkify_field_repeater(); |
| 3455 |
$this.children('.darkify-field-slider').darkify_field_slider(); |
| 3456 |
$this.children('.darkify-field-sortable').darkify_field_sortable(); |
| 3457 |
$this.children('.darkify-field-sorter').darkify_field_sorter(); |
| 3458 |
$this.children('.darkify-field-spinner').darkify_field_spinner(); |
| 3459 |
$this.children('.darkify-field-switcher').darkify_field_switcher(); |
| 3460 |
$this.children('.darkify-field-tabbed').darkify_field_tabbed(); |
| 3461 |
$this.children('.darkify-field-typography').darkify_field_typography(); |
| 3462 |
$this.children('.darkify-field-upload').darkify_field_upload(); |
| 3463 |
$this.children('.darkify-field-wp_editor').darkify_field_wp_editor(); |
| 3464 |
|
| 3465 |
// Field colors |
| 3466 |
$this.children('.darkify-field-border').find('.darkify-color').darkify_color(); |
| 3467 |
$this.children('.darkify-field-background').find('.darkify-color').darkify_color(); |
| 3468 |
$this.children('.darkify-field-color').find('.darkify-color').darkify_color(); |
| 3469 |
$this.children('.darkify-field-color_group').find('.darkify-color').darkify_color(); |
| 3470 |
$this.children('.darkify-field-link_color').find('.darkify-color').darkify_color(); |
| 3471 |
$this.children('.darkify-field-typography').find('.darkify-color').darkify_color(); |
| 3472 |
|
| 3473 |
// Field chosenjs |
| 3474 |
$this.children('.darkify-field-select').find('.darkify-chosen').darkify_chosen(); |
| 3475 |
|
| 3476 |
// Field Checkbox |
| 3477 |
$this.children('.darkify-field-checkbox').find('.darkify-checkbox').darkify_checkbox(); |
| 3478 |
$this.children('.darkify-field-checkbox').find('.darkify-checkbox-all').darkify_checkbox_all(); |
| 3479 |
|
| 3480 |
// Field Siblings |
| 3481 |
$this.children('.darkify-field-button_set').find('.darkify-siblings').darkify_siblings(); |
| 3482 |
$this.children('.darkify-field-image_select').find('.darkify-siblings').darkify_siblings(); |
| 3483 |
$this.children('.darkify-field-layout_preset').find('.darkify-siblings').darkify_siblings(); |
| 3484 |
$this.children('.darkify-field-palette').find('.darkify-siblings').darkify_siblings(); |
| 3485 |
|
| 3486 |
// Help Tooptip |
| 3487 |
$this.children('.darkify-field').find('.darkify-help').darkify_help(); |
| 3488 |
|
| 3489 |
if (settings.dependency) { |
| 3490 |
$this.darkify_dependency(); |
| 3491 |
} |
| 3492 |
|
| 3493 |
$this.data('inited', true); |
| 3494 |
|
| 3495 |
$(document).trigger('darkify-reload-script', $this); |
| 3496 |
|
| 3497 |
} |
| 3498 |
|
| 3499 |
}); |
| 3500 |
}; |
| 3501 |
|
| 3502 |
// |
| 3503 |
// Document ready and run scripts |
| 3504 |
// |
| 3505 |
$(document).ready(function () { |
| 3506 |
|
| 3507 |
$('.darkify-save').darkify_save(); |
| 3508 |
$('.darkify-options').darkify_options(); |
| 3509 |
$('.darkify-sticky-header').darkify_sticky(); |
| 3510 |
$('.darkify-nav-options').darkify_nav_options(); |
| 3511 |
$('.darkify-nav-metabox').darkify_nav_metabox(); |
| 3512 |
$('.darkify-taxonomy').darkify_taxonomy(); |
| 3513 |
$('.darkify-page-templates').darkify_page_templates(); |
| 3514 |
$('.darkify-post-formats').darkify_post_formats(); |
| 3515 |
$('.darkify-shortcode').darkify_shortcode(); |
| 3516 |
$('.darkify-search').darkify_search(); |
| 3517 |
$('.darkify-confirm').darkify_confirm(); |
| 3518 |
$('.darkify-expand-all').darkify_expand_all(); |
| 3519 |
$('.darkify-onload').darkify_reload_script(); |
| 3520 |
$('#widgets-editor').darkify_widgets(); |
| 3521 |
$('#widgets-right').darkify_widgets(); |
| 3522 |
$('#menu-to-edit').darkify_nav_menu(); |
| 3523 |
|
| 3524 |
}); |
| 3525 |
|
| 3526 |
})(jQuery, window, document); |
| 3527 |
(function ($) { |
| 3528 |
"use strict"; |
| 3529 |
$(document).on("click", "#switcher_shortcode_copy", function (e) { |
| 3530 |
e.preventDefault(); |
| 3531 |
/* Get the text field */ |
| 3532 |
$(this).siblings("#switcher_shortcode").select(); |
| 3533 |
/* Select the text field */ |
| 3534 |
document.execCommand("copy"); |
| 3535 |
$(".switcher_shortcode_after_copy").animate( |
| 3536 |
{ |
| 3537 |
opacity: 1, |
| 3538 |
bottom: 25, |
| 3539 |
}, |
| 3540 |
300 |
| 3541 |
); |
| 3542 |
setTimeout(function () { |
| 3543 |
jQuery(".switcher_shortcode_after_copy").animate( |
| 3544 |
{ |
| 3545 |
opacity: 0, |
| 3546 |
}, |
| 3547 |
200 |
| 3548 |
); |
| 3549 |
jQuery(".switcher_shortcode_after_copy").animate( |
| 3550 |
{ |
| 3551 |
bottom: 0, |
| 3552 |
}, |
| 3553 |
0 |
| 3554 |
); |
| 3555 |
}, 2000); |
| 3556 |
}); |
| 3557 |
|
| 3558 |
// Disable Fields // |
| 3559 |
$("select option:contains((Pro))").attr('disabled', true).css('opacity', '1') |
| 3560 |
// Disable and style the switcher element |
| 3561 |
$(".switcher_pro_only .darkify--switcher") |
| 3562 |
.attr("disabled", "disabled") |
| 3563 |
.addClass("only_pro_switcher") |
| 3564 |
.css({ background: "#B0BCC4" }); |
| 3565 |
|
| 3566 |
// Apply common styling to elements with the 'only_pro_switcher' class |
| 3567 |
$(".only_pro_switcher").css({ |
| 3568 |
"pointer-events": "none", |
| 3569 |
color: "#8796A1", |
| 3570 |
position: "relative", |
| 3571 |
}); |
| 3572 |
|
| 3573 |
// Pro only tag. |
| 3574 |
$('.darkffy-pagination-type li:nth-child(n+2) input').attr('disabled', true) |
| 3575 |
$("label:contains((Pro))").css({ 'pointer-events': 'none', 'opacity': '0.8', 'user-select': 'none' }) |
| 3576 |
$("label:contains((Pro)) input").attr('disabled', true).css('opacity', '1') |
| 3577 |
$("select option:contains((Pro))").attr('disabled', true).css('opacity', '1') |
| 3578 |
|
| 3579 |
})(jQuery); |