pro
1 year ago
acf-escaped-html-notice.js
1 year ago
acf-escaped-html-notice.js.map
1 year ago
acf-escaped-html-notice.min.js
1 year ago
acf-field-group.js
1 year ago
acf-field-group.js.map
1 year ago
acf-field-group.min.js
1 year ago
acf-input.js
1 year ago
acf-input.js.map
1 year ago
acf-input.min.js
1 year ago
acf-internal-post-type.js
1 year ago
acf-internal-post-type.js.map
1 year ago
acf-internal-post-type.min.js
1 year ago
acf.js
1 year ago
acf.js.map
1 year ago
acf.min.js
1 year ago
index.php
1 year ago
acf.js
4502 lines
| 1 | /******/ (() => { // webpackBootstrap |
| 2 | /******/ var __webpack_modules__ = ({ |
| 3 | |
| 4 | /***/ "./assets/src/js/_acf-hooks.js": |
| 5 | /*!*************************************!*\ |
| 6 | !*** ./assets/src/js/_acf-hooks.js ***! |
| 7 | \*************************************/ |
| 8 | /***/ (() => { |
| 9 | |
| 10 | (function (window, undefined) { |
| 11 | 'use strict'; |
| 12 | |
| 13 | /** |
| 14 | * Handles managing all events for whatever you plug it into. Priorities for hooks are based on lowest to highest in |
| 15 | * that, lowest priority hooks are fired first. |
| 16 | */ |
| 17 | var EventManager = function () { |
| 18 | /** |
| 19 | * Maintain a reference to the object scope so our public methods never get confusing. |
| 20 | */ |
| 21 | var MethodsAvailable = { |
| 22 | removeFilter: removeFilter, |
| 23 | applyFilters: applyFilters, |
| 24 | addFilter: addFilter, |
| 25 | removeAction: removeAction, |
| 26 | doAction: doAction, |
| 27 | addAction: addAction, |
| 28 | storage: getStorage |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * Contains the hooks that get registered with this EventManager. The array for storage utilizes a "flat" |
| 33 | * object literal such that looking up the hook utilizes the native object literal hash. |
| 34 | */ |
| 35 | var STORAGE = { |
| 36 | actions: {}, |
| 37 | filters: {} |
| 38 | }; |
| 39 | function getStorage() { |
| 40 | return STORAGE; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Adds an action to the event manager. |
| 45 | * |
| 46 | * @param action Must contain namespace.identifier |
| 47 | * @param callback Must be a valid callback function before this action is added |
| 48 | * @param [priority=10] Used to control when the function is executed in relation to other callbacks bound to the same hook |
| 49 | * @param [context] Supply a value to be used for this |
| 50 | */ |
| 51 | function addAction(action, callback, priority, context) { |
| 52 | if (typeof action === 'string' && typeof callback === 'function') { |
| 53 | priority = parseInt(priority || 10, 10); |
| 54 | _addHook('actions', action, callback, priority, context); |
| 55 | } |
| 56 | return MethodsAvailable; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Performs an action if it exists. You can pass as many arguments as you want to this function; the only rule is |
| 61 | * that the first argument must always be the action. |
| 62 | */ |
| 63 | function doAction(/* action, arg1, arg2, ... */ |
| 64 | ) { |
| 65 | var args = Array.prototype.slice.call(arguments); |
| 66 | var action = args.shift(); |
| 67 | if (typeof action === 'string') { |
| 68 | _runHook('actions', action, args); |
| 69 | } |
| 70 | return MethodsAvailable; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Removes the specified action if it contains a namespace.identifier & exists. |
| 75 | * |
| 76 | * @param action The action to remove |
| 77 | * @param [callback] Callback function to remove |
| 78 | */ |
| 79 | function removeAction(action, callback) { |
| 80 | if (typeof action === 'string') { |
| 81 | _removeHook('actions', action, callback); |
| 82 | } |
| 83 | return MethodsAvailable; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Adds a filter to the event manager. |
| 88 | * |
| 89 | * @param filter Must contain namespace.identifier |
| 90 | * @param callback Must be a valid callback function before this action is added |
| 91 | * @param [priority=10] Used to control when the function is executed in relation to other callbacks bound to the same hook |
| 92 | * @param [context] Supply a value to be used for this |
| 93 | */ |
| 94 | function addFilter(filter, callback, priority, context) { |
| 95 | if (typeof filter === 'string' && typeof callback === 'function') { |
| 96 | priority = parseInt(priority || 10, 10); |
| 97 | _addHook('filters', filter, callback, priority, context); |
| 98 | } |
| 99 | return MethodsAvailable; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Performs a filter if it exists. You should only ever pass 1 argument to be filtered. The only rule is that |
| 104 | * the first argument must always be the filter. |
| 105 | */ |
| 106 | function applyFilters(/* filter, filtered arg, arg2, ... */ |
| 107 | ) { |
| 108 | var args = Array.prototype.slice.call(arguments); |
| 109 | var filter = args.shift(); |
| 110 | if (typeof filter === 'string') { |
| 111 | return _runHook('filters', filter, args); |
| 112 | } |
| 113 | return MethodsAvailable; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Removes the specified filter if it contains a namespace.identifier & exists. |
| 118 | * |
| 119 | * @param filter The action to remove |
| 120 | * @param [callback] Callback function to remove |
| 121 | */ |
| 122 | function removeFilter(filter, callback) { |
| 123 | if (typeof filter === 'string') { |
| 124 | _removeHook('filters', filter, callback); |
| 125 | } |
| 126 | return MethodsAvailable; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Removes the specified hook by resetting the value of it. |
| 131 | * |
| 132 | * @param type Type of hook, either 'actions' or 'filters' |
| 133 | * @param hook The hook (namespace.identifier) to remove |
| 134 | * @private |
| 135 | */ |
| 136 | function _removeHook(type, hook, callback, context) { |
| 137 | if (!STORAGE[type][hook]) { |
| 138 | return; |
| 139 | } |
| 140 | if (!callback) { |
| 141 | STORAGE[type][hook] = []; |
| 142 | } else { |
| 143 | var handlers = STORAGE[type][hook]; |
| 144 | var i; |
| 145 | if (!context) { |
| 146 | for (i = handlers.length; i--;) { |
| 147 | if (handlers[i].callback === callback) { |
| 148 | handlers.splice(i, 1); |
| 149 | } |
| 150 | } |
| 151 | } else { |
| 152 | for (i = handlers.length; i--;) { |
| 153 | var handler = handlers[i]; |
| 154 | if (handler.callback === callback && handler.context === context) { |
| 155 | handlers.splice(i, 1); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Adds the hook to the appropriate storage container |
| 164 | * |
| 165 | * @param type 'actions' or 'filters' |
| 166 | * @param hook The hook (namespace.identifier) to add to our event manager |
| 167 | * @param callback The function that will be called when the hook is executed. |
| 168 | * @param priority The priority of this hook. Must be an integer. |
| 169 | * @param [context] A value to be used for this |
| 170 | * @private |
| 171 | */ |
| 172 | function _addHook(type, hook, callback, priority, context) { |
| 173 | var hookObject = { |
| 174 | callback: callback, |
| 175 | priority: priority, |
| 176 | context: context |
| 177 | }; |
| 178 | |
| 179 | // Utilize 'prop itself' : http://jsperf.com/hasownproperty-vs-in-vs-undefined/19 |
| 180 | var hooks = STORAGE[type][hook]; |
| 181 | if (hooks) { |
| 182 | hooks.push(hookObject); |
| 183 | hooks = _hookInsertSort(hooks); |
| 184 | } else { |
| 185 | hooks = [hookObject]; |
| 186 | } |
| 187 | STORAGE[type][hook] = hooks; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Use an insert sort for keeping our hooks organized based on priority. This function is ridiculously faster |
| 192 | * than bubble sort, etc: http://jsperf.com/javascript-sort |
| 193 | * |
| 194 | * @param hooks The custom array containing all of the appropriate hooks to perform an insert sort on. |
| 195 | * @private |
| 196 | */ |
| 197 | function _hookInsertSort(hooks) { |
| 198 | var tmpHook, j, prevHook; |
| 199 | for (var i = 1, len = hooks.length; i < len; i++) { |
| 200 | tmpHook = hooks[i]; |
| 201 | j = i; |
| 202 | while ((prevHook = hooks[j - 1]) && prevHook.priority > tmpHook.priority) { |
| 203 | hooks[j] = hooks[j - 1]; |
| 204 | --j; |
| 205 | } |
| 206 | hooks[j] = tmpHook; |
| 207 | } |
| 208 | return hooks; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Runs the specified hook. If it is an action, the value is not modified but if it is a filter, it is. |
| 213 | * |
| 214 | * @param type 'actions' or 'filters' |
| 215 | * @param hook The hook ( namespace.identifier ) to be ran. |
| 216 | * @param args Arguments to pass to the action/filter. If it's a filter, args is actually a single parameter. |
| 217 | * @private |
| 218 | */ |
| 219 | function _runHook(type, hook, args) { |
| 220 | var handlers = STORAGE[type][hook]; |
| 221 | if (!handlers) { |
| 222 | return type === 'filters' ? args[0] : false; |
| 223 | } |
| 224 | var i = 0, |
| 225 | len = handlers.length; |
| 226 | if (type === 'filters') { |
| 227 | for (; i < len; i++) { |
| 228 | args[0] = handlers[i].callback.apply(handlers[i].context, args); |
| 229 | } |
| 230 | } else { |
| 231 | for (; i < len; i++) { |
| 232 | handlers[i].callback.apply(handlers[i].context, args); |
| 233 | } |
| 234 | } |
| 235 | return type === 'filters' ? args[0] : true; |
| 236 | } |
| 237 | |
| 238 | // return all of the publicly available methods |
| 239 | return MethodsAvailable; |
| 240 | }; |
| 241 | |
| 242 | // instantiate |
| 243 | acf.hooks = new EventManager(); |
| 244 | })(window); |
| 245 | |
| 246 | /***/ }), |
| 247 | |
| 248 | /***/ "./assets/src/js/_acf-modal.js": |
| 249 | /*!*************************************!*\ |
| 250 | !*** ./assets/src/js/_acf-modal.js ***! |
| 251 | \*************************************/ |
| 252 | /***/ (() => { |
| 253 | |
| 254 | (function ($, undefined) { |
| 255 | acf.models.Modal = acf.Model.extend({ |
| 256 | data: { |
| 257 | title: '', |
| 258 | content: '', |
| 259 | toolbar: '' |
| 260 | }, |
| 261 | events: { |
| 262 | 'click .acf-modal-close': 'onClickClose' |
| 263 | }, |
| 264 | setup: function (props) { |
| 265 | $.extend(this.data, props); |
| 266 | this.$el = $(); |
| 267 | this.render(); |
| 268 | }, |
| 269 | initialize: function () { |
| 270 | this.open(); |
| 271 | }, |
| 272 | render: function () { |
| 273 | // Extract vars. |
| 274 | var title = this.get('title'); |
| 275 | var content = this.get('content'); |
| 276 | var toolbar = this.get('toolbar'); |
| 277 | |
| 278 | // Create element. |
| 279 | var $el = $(['<div>', '<div class="acf-modal">', '<div class="acf-modal-title">', '<h2>' + title + '</h2>', '<button class="acf-modal-close" type="button"><span class="dashicons dashicons-no"></span></button>', '</div>', '<div class="acf-modal-content">' + content + '</div>', '<div class="acf-modal-toolbar">' + toolbar + '</div>', '</div>', '<div class="acf-modal-backdrop acf-modal-close"></div>', '</div>'].join('')); |
| 280 | |
| 281 | // Update DOM. |
| 282 | if (this.$el) { |
| 283 | this.$el.replaceWith($el); |
| 284 | } |
| 285 | this.$el = $el; |
| 286 | |
| 287 | // Trigger action. |
| 288 | acf.doAction('append', $el); |
| 289 | }, |
| 290 | update: function (props) { |
| 291 | this.data = acf.parseArgs(props, this.data); |
| 292 | this.render(); |
| 293 | }, |
| 294 | title: function (title) { |
| 295 | this.$('.acf-modal-title h2').html(title); |
| 296 | }, |
| 297 | content: function (content) { |
| 298 | this.$('.acf-modal-content').html(content); |
| 299 | }, |
| 300 | toolbar: function (toolbar) { |
| 301 | this.$('.acf-modal-toolbar').html(toolbar); |
| 302 | }, |
| 303 | open: function () { |
| 304 | $('body').append(this.$el); |
| 305 | }, |
| 306 | close: function () { |
| 307 | this.remove(); |
| 308 | }, |
| 309 | onClickClose: function (e, $el) { |
| 310 | e.preventDefault(); |
| 311 | this.close(); |
| 312 | }, |
| 313 | /** |
| 314 | * Places focus within the popup. |
| 315 | */ |
| 316 | focus: function () { |
| 317 | this.$el.find('.acf-icon').first().trigger('focus'); |
| 318 | }, |
| 319 | /** |
| 320 | * Locks focus within the modal. |
| 321 | * |
| 322 | * @param {boolean} locked True to lock focus, false to unlock. |
| 323 | */ |
| 324 | lockFocusToModal: function (locked) { |
| 325 | let inertElement = $('#wpwrap'); |
| 326 | if (!inertElement.length) { |
| 327 | return; |
| 328 | } |
| 329 | inertElement[0].inert = locked; |
| 330 | inertElement.attr('aria-hidden', locked); |
| 331 | }, |
| 332 | /** |
| 333 | * Returns focus to the element that opened the popup |
| 334 | * if it still exists in the DOM. |
| 335 | */ |
| 336 | returnFocusToOrigin: function () { |
| 337 | if (this.data.openedBy instanceof $ && this.data.openedBy.closest('body').length > 0) { |
| 338 | this.data.openedBy.trigger('focus'); |
| 339 | } |
| 340 | } |
| 341 | }); |
| 342 | |
| 343 | /** |
| 344 | * Returns a new modal. |
| 345 | * |
| 346 | * @date 21/4/20 |
| 347 | * @since ACF 5.9.0 |
| 348 | * |
| 349 | * @param object props The modal props. |
| 350 | * @return object |
| 351 | */ |
| 352 | acf.newModal = function (props) { |
| 353 | return new acf.models.Modal(props); |
| 354 | }; |
| 355 | })(jQuery); |
| 356 | |
| 357 | /***/ }), |
| 358 | |
| 359 | /***/ "./assets/src/js/_acf-model.js": |
| 360 | /*!*************************************!*\ |
| 361 | !*** ./assets/src/js/_acf-model.js ***! |
| 362 | \*************************************/ |
| 363 | /***/ (() => { |
| 364 | |
| 365 | (function ($, undefined) { |
| 366 | // Cached regex to split keys for `addEvent`. |
| 367 | var delegateEventSplitter = /^(\S+)\s*(.*)$/; |
| 368 | |
| 369 | /** |
| 370 | * extend |
| 371 | * |
| 372 | * Helper function to correctly set up the prototype chain for subclasses |
| 373 | * Heavily inspired by backbone.js |
| 374 | * |
| 375 | * @date 14/12/17 |
| 376 | * @since ACF 5.6.5 |
| 377 | * |
| 378 | * @param object protoProps New properties for this object. |
| 379 | * @return function. |
| 380 | */ |
| 381 | |
| 382 | var extend = function (protoProps) { |
| 383 | // vars |
| 384 | var Parent = this; |
| 385 | var Child; |
| 386 | |
| 387 | // The constructor function for the new subclass is either defined by you |
| 388 | // (the "constructor" property in your `extend` definition), or defaulted |
| 389 | // by us to simply call the parent constructor. |
| 390 | if (protoProps && protoProps.hasOwnProperty('constructor')) { |
| 391 | Child = protoProps.constructor; |
| 392 | } else { |
| 393 | Child = function () { |
| 394 | return Parent.apply(this, arguments); |
| 395 | }; |
| 396 | } |
| 397 | |
| 398 | // Add static properties to the constructor function, if supplied. |
| 399 | $.extend(Child, Parent); |
| 400 | |
| 401 | // Set the prototype chain to inherit from `parent`, without calling |
| 402 | // `parent`'s constructor function and add the prototype properties. |
| 403 | Child.prototype = Object.create(Parent.prototype); |
| 404 | $.extend(Child.prototype, protoProps); |
| 405 | Child.prototype.constructor = Child; |
| 406 | |
| 407 | // Set a convenience property in case the parent's prototype is needed later. |
| 408 | //Child.prototype.__parent__ = Parent.prototype; |
| 409 | |
| 410 | // return |
| 411 | return Child; |
| 412 | }; |
| 413 | |
| 414 | /** |
| 415 | * Model |
| 416 | * |
| 417 | * Base class for all inheritence |
| 418 | * |
| 419 | * @date 14/12/17 |
| 420 | * @since ACF 5.6.5 |
| 421 | * |
| 422 | * @param object props |
| 423 | * @return function. |
| 424 | */ |
| 425 | |
| 426 | var Model = acf.Model = function () { |
| 427 | // generate uique client id |
| 428 | this.cid = acf.uniqueId('acf'); |
| 429 | |
| 430 | // set vars to avoid modifying prototype |
| 431 | this.data = $.extend(true, {}, this.data); |
| 432 | |
| 433 | // pass props to setup function |
| 434 | this.setup.apply(this, arguments); |
| 435 | |
| 436 | // store on element (allow this.setup to create this.$el) |
| 437 | if (this.$el && !this.$el.data('acf')) { |
| 438 | this.$el.data('acf', this); |
| 439 | } |
| 440 | |
| 441 | // initialize |
| 442 | var initialize = function () { |
| 443 | this.initialize(); |
| 444 | this.addEvents(); |
| 445 | this.addActions(); |
| 446 | this.addFilters(); |
| 447 | }; |
| 448 | |
| 449 | // initialize on action |
| 450 | if (this.wait && !acf.didAction(this.wait)) { |
| 451 | this.addAction(this.wait, initialize); |
| 452 | |
| 453 | // initialize now |
| 454 | } else { |
| 455 | initialize.apply(this); |
| 456 | } |
| 457 | }; |
| 458 | |
| 459 | // Attach all inheritable methods to the Model prototype. |
| 460 | $.extend(Model.prototype, { |
| 461 | // Unique model id |
| 462 | id: '', |
| 463 | // Unique client id |
| 464 | cid: '', |
| 465 | // jQuery element |
| 466 | $el: null, |
| 467 | // Data specific to this instance |
| 468 | data: {}, |
| 469 | // toggle used when changing data |
| 470 | busy: false, |
| 471 | changed: false, |
| 472 | // Setup events hooks |
| 473 | events: {}, |
| 474 | actions: {}, |
| 475 | filters: {}, |
| 476 | // class used to avoid nested event triggers |
| 477 | eventScope: '', |
| 478 | // action to wait until initialize |
| 479 | wait: false, |
| 480 | // action priority default |
| 481 | priority: 10, |
| 482 | /** |
| 483 | * get |
| 484 | * |
| 485 | * Gets a specific data value |
| 486 | * |
| 487 | * @date 14/12/17 |
| 488 | * @since ACF 5.6.5 |
| 489 | * |
| 490 | * @param string name |
| 491 | * @return mixed |
| 492 | */ |
| 493 | |
| 494 | get: function (name) { |
| 495 | return this.data[name]; |
| 496 | }, |
| 497 | /** |
| 498 | * has |
| 499 | * |
| 500 | * Returns `true` if the data exists and is not null |
| 501 | * |
| 502 | * @date 14/12/17 |
| 503 | * @since ACF 5.6.5 |
| 504 | * |
| 505 | * @param string name |
| 506 | * @return boolean |
| 507 | */ |
| 508 | |
| 509 | has: function (name) { |
| 510 | return this.get(name) != null; |
| 511 | }, |
| 512 | /** |
| 513 | * set |
| 514 | * |
| 515 | * Sets a specific data value |
| 516 | * |
| 517 | * @date 14/12/17 |
| 518 | * @since ACF 5.6.5 |
| 519 | * |
| 520 | * @param string name |
| 521 | * @param mixed value |
| 522 | * @return this |
| 523 | */ |
| 524 | |
| 525 | set: function (name, value, silent) { |
| 526 | // bail if unchanged |
| 527 | var prevValue = this.get(name); |
| 528 | if (prevValue == value) { |
| 529 | return this; |
| 530 | } |
| 531 | |
| 532 | // set data |
| 533 | this.data[name] = value; |
| 534 | |
| 535 | // trigger events |
| 536 | if (!silent) { |
| 537 | this.changed = true; |
| 538 | this.trigger('changed:' + name, [value, prevValue]); |
| 539 | this.trigger('changed', [name, value, prevValue]); |
| 540 | } |
| 541 | |
| 542 | // return |
| 543 | return this; |
| 544 | }, |
| 545 | /** |
| 546 | * inherit |
| 547 | * |
| 548 | * Inherits the data from a jQuery element |
| 549 | * |
| 550 | * @date 14/12/17 |
| 551 | * @since ACF 5.6.5 |
| 552 | * |
| 553 | * @param jQuery $el |
| 554 | * @return this |
| 555 | */ |
| 556 | |
| 557 | inherit: function (data) { |
| 558 | // allow jQuery |
| 559 | if (data instanceof jQuery) { |
| 560 | data = data.data(); |
| 561 | } |
| 562 | |
| 563 | // extend |
| 564 | $.extend(this.data, data); |
| 565 | |
| 566 | // return |
| 567 | return this; |
| 568 | }, |
| 569 | /** |
| 570 | * prop |
| 571 | * |
| 572 | * mimics the jQuery prop function |
| 573 | * |
| 574 | * @date 4/6/18 |
| 575 | * @since ACF 5.6.9 |
| 576 | * |
| 577 | * @param type $var Description. Default. |
| 578 | * @return type Description. |
| 579 | */ |
| 580 | |
| 581 | prop: function () { |
| 582 | return this.$el.prop.apply(this.$el, arguments); |
| 583 | }, |
| 584 | /** |
| 585 | * setup |
| 586 | * |
| 587 | * Run during constructor function |
| 588 | * |
| 589 | * @date 14/12/17 |
| 590 | * @since ACF 5.6.5 |
| 591 | * |
| 592 | * @param n/a |
| 593 | * @return n/a |
| 594 | */ |
| 595 | |
| 596 | setup: function (props) { |
| 597 | $.extend(this, props); |
| 598 | }, |
| 599 | /** |
| 600 | * initialize |
| 601 | * |
| 602 | * Also run during constructor function |
| 603 | * |
| 604 | * @date 14/12/17 |
| 605 | * @since ACF 5.6.5 |
| 606 | * |
| 607 | * @param n/a |
| 608 | * @return n/a |
| 609 | */ |
| 610 | |
| 611 | initialize: function () {}, |
| 612 | /** |
| 613 | * addElements |
| 614 | * |
| 615 | * Adds multiple jQuery elements to this object |
| 616 | * |
| 617 | * @date 9/5/18 |
| 618 | * @since ACF 5.6.9 |
| 619 | * |
| 620 | * @param type $var Description. Default. |
| 621 | * @return type Description. |
| 622 | */ |
| 623 | |
| 624 | addElements: function (elements) { |
| 625 | elements = elements || this.elements || null; |
| 626 | if (!elements || !Object.keys(elements).length) return false; |
| 627 | for (var i in elements) { |
| 628 | this.addElement(i, elements[i]); |
| 629 | } |
| 630 | }, |
| 631 | /** |
| 632 | * addElement |
| 633 | * |
| 634 | * description |
| 635 | * |
| 636 | * @date 9/5/18 |
| 637 | * @since ACF 5.6.9 |
| 638 | * |
| 639 | * @param type $var Description. Default. |
| 640 | * @return type Description. |
| 641 | */ |
| 642 | |
| 643 | addElement: function (name, selector) { |
| 644 | this['$' + name] = this.$(selector); |
| 645 | }, |
| 646 | /** |
| 647 | * addEvents |
| 648 | * |
| 649 | * Adds multiple event handlers |
| 650 | * |
| 651 | * @date 14/12/17 |
| 652 | * @since ACF 5.6.5 |
| 653 | * |
| 654 | * @param object events {event1 : callback, event2 : callback, etc } |
| 655 | * @return n/a |
| 656 | */ |
| 657 | |
| 658 | addEvents: function (events) { |
| 659 | events = events || this.events || null; |
| 660 | if (!events) return false; |
| 661 | for (var key in events) { |
| 662 | var match = key.match(delegateEventSplitter); |
| 663 | this.on(match[1], match[2], events[key]); |
| 664 | } |
| 665 | }, |
| 666 | /** |
| 667 | * removeEvents |
| 668 | * |
| 669 | * Removes multiple event handlers |
| 670 | * |
| 671 | * @date 14/12/17 |
| 672 | * @since ACF 5.6.5 |
| 673 | * |
| 674 | * @param object events {event1 : callback, event2 : callback, etc } |
| 675 | * @return n/a |
| 676 | */ |
| 677 | |
| 678 | removeEvents: function (events) { |
| 679 | events = events || this.events || null; |
| 680 | if (!events) return false; |
| 681 | for (var key in events) { |
| 682 | var match = key.match(delegateEventSplitter); |
| 683 | this.off(match[1], match[2], events[key]); |
| 684 | } |
| 685 | }, |
| 686 | /** |
| 687 | * getEventTarget |
| 688 | * |
| 689 | * Returns a jQuery element to trigger an event on. |
| 690 | * |
| 691 | * @date 5/6/18 |
| 692 | * @since ACF 5.6.9 |
| 693 | * |
| 694 | * @param jQuery $el The default jQuery element. Optional. |
| 695 | * @param string event The event name. Optional. |
| 696 | * @return jQuery |
| 697 | */ |
| 698 | |
| 699 | getEventTarget: function ($el, event) { |
| 700 | return $el || this.$el || $(document); |
| 701 | }, |
| 702 | /** |
| 703 | * validateEvent |
| 704 | * |
| 705 | * Returns true if the event target's closest $el is the same as this.$el |
| 706 | * Requires both this.el and this.$el to be defined |
| 707 | * |
| 708 | * @date 5/6/18 |
| 709 | * @since ACF 5.6.9 |
| 710 | * |
| 711 | * @param type $var Description. Default. |
| 712 | * @return type Description. |
| 713 | */ |
| 714 | |
| 715 | validateEvent: function (e) { |
| 716 | if (this.eventScope) { |
| 717 | return $(e.target).closest(this.eventScope).is(this.$el); |
| 718 | } else { |
| 719 | return true; |
| 720 | } |
| 721 | }, |
| 722 | /** |
| 723 | * proxyEvent |
| 724 | * |
| 725 | * Returns a new event callback function scoped to this model |
| 726 | * |
| 727 | * @date 29/3/18 |
| 728 | * @since ACF 5.6.9 |
| 729 | * |
| 730 | * @param function callback |
| 731 | * @return function |
| 732 | */ |
| 733 | |
| 734 | proxyEvent: function (callback) { |
| 735 | return this.proxy(function (e) { |
| 736 | // validate |
| 737 | if (!this.validateEvent(e)) { |
| 738 | return; |
| 739 | } |
| 740 | |
| 741 | // construct args |
| 742 | var args = acf.arrayArgs(arguments); |
| 743 | var extraArgs = args.slice(1); |
| 744 | var eventArgs = [e, $(e.currentTarget)].concat(extraArgs); |
| 745 | |
| 746 | // callback |
| 747 | callback.apply(this, eventArgs); |
| 748 | }); |
| 749 | }, |
| 750 | /** |
| 751 | * on |
| 752 | * |
| 753 | * Adds an event handler similar to jQuery |
| 754 | * Uses the instance 'cid' to namespace event |
| 755 | * |
| 756 | * @date 14/12/17 |
| 757 | * @since ACF 5.6.5 |
| 758 | * |
| 759 | * @param string name |
| 760 | * @param string callback |
| 761 | * @return n/a |
| 762 | */ |
| 763 | |
| 764 | on: function (a1, a2, a3, a4) { |
| 765 | // vars |
| 766 | var $el, event, selector, callback, args; |
| 767 | |
| 768 | // find args |
| 769 | if (a1 instanceof jQuery) { |
| 770 | // 1. args( $el, event, selector, callback ) |
| 771 | if (a4) { |
| 772 | $el = a1; |
| 773 | event = a2; |
| 774 | selector = a3; |
| 775 | callback = a4; |
| 776 | |
| 777 | // 2. args( $el, event, callback ) |
| 778 | } else { |
| 779 | $el = a1; |
| 780 | event = a2; |
| 781 | callback = a3; |
| 782 | } |
| 783 | } else { |
| 784 | // 3. args( event, selector, callback ) |
| 785 | if (a3) { |
| 786 | event = a1; |
| 787 | selector = a2; |
| 788 | callback = a3; |
| 789 | |
| 790 | // 4. args( event, callback ) |
| 791 | } else { |
| 792 | event = a1; |
| 793 | callback = a2; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | // element |
| 798 | $el = this.getEventTarget($el); |
| 799 | |
| 800 | // modify callback |
| 801 | if (typeof callback === 'string') { |
| 802 | callback = this.proxyEvent(this[callback]); |
| 803 | } |
| 804 | |
| 805 | // modify event |
| 806 | event = event + '.' + this.cid; |
| 807 | |
| 808 | // args |
| 809 | if (selector) { |
| 810 | args = [event, selector, callback]; |
| 811 | } else { |
| 812 | args = [event, callback]; |
| 813 | } |
| 814 | |
| 815 | // on() |
| 816 | $el.on.apply($el, args); |
| 817 | }, |
| 818 | /** |
| 819 | * off |
| 820 | * |
| 821 | * Removes an event handler similar to jQuery |
| 822 | * |
| 823 | * @date 14/12/17 |
| 824 | * @since ACF 5.6.5 |
| 825 | * |
| 826 | * @param string name |
| 827 | * @param string callback |
| 828 | * @return n/a |
| 829 | */ |
| 830 | |
| 831 | off: function (a1, a2, a3) { |
| 832 | // vars |
| 833 | var $el, event, selector, args; |
| 834 | |
| 835 | // find args |
| 836 | if (a1 instanceof jQuery) { |
| 837 | // 1. args( $el, event, selector ) |
| 838 | if (a3) { |
| 839 | $el = a1; |
| 840 | event = a2; |
| 841 | selector = a3; |
| 842 | |
| 843 | // 2. args( $el, event ) |
| 844 | } else { |
| 845 | $el = a1; |
| 846 | event = a2; |
| 847 | } |
| 848 | } else { |
| 849 | // 3. args( event, selector ) |
| 850 | if (a2) { |
| 851 | event = a1; |
| 852 | selector = a2; |
| 853 | |
| 854 | // 4. args( event ) |
| 855 | } else { |
| 856 | event = a1; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | // element |
| 861 | $el = this.getEventTarget($el); |
| 862 | |
| 863 | // modify event |
| 864 | event = event + '.' + this.cid; |
| 865 | |
| 866 | // args |
| 867 | if (selector) { |
| 868 | args = [event, selector]; |
| 869 | } else { |
| 870 | args = [event]; |
| 871 | } |
| 872 | |
| 873 | // off() |
| 874 | $el.off.apply($el, args); |
| 875 | }, |
| 876 | /** |
| 877 | * trigger |
| 878 | * |
| 879 | * Triggers an event similar to jQuery |
| 880 | * |
| 881 | * @date 14/12/17 |
| 882 | * @since ACF 5.6.5 |
| 883 | * |
| 884 | * @param string name |
| 885 | * @param string callback |
| 886 | * @return n/a |
| 887 | */ |
| 888 | |
| 889 | trigger: function (name, args, bubbles) { |
| 890 | var $el = this.getEventTarget(); |
| 891 | if (bubbles) { |
| 892 | $el.trigger.apply($el, arguments); |
| 893 | } else { |
| 894 | $el.triggerHandler.apply($el, arguments); |
| 895 | } |
| 896 | return this; |
| 897 | }, |
| 898 | /** |
| 899 | * addActions |
| 900 | * |
| 901 | * Adds multiple action handlers |
| 902 | * |
| 903 | * @date 14/12/17 |
| 904 | * @since ACF 5.6.5 |
| 905 | * |
| 906 | * @param object actions {action1 : callback, action2 : callback, etc } |
| 907 | * @return n/a |
| 908 | */ |
| 909 | |
| 910 | addActions: function (actions) { |
| 911 | actions = actions || this.actions || null; |
| 912 | if (!actions) return false; |
| 913 | for (var i in actions) { |
| 914 | this.addAction(i, actions[i]); |
| 915 | } |
| 916 | }, |
| 917 | /** |
| 918 | * removeActions |
| 919 | * |
| 920 | * Removes multiple action handlers |
| 921 | * |
| 922 | * @date 14/12/17 |
| 923 | * @since ACF 5.6.5 |
| 924 | * |
| 925 | * @param object actions {action1 : callback, action2 : callback, etc } |
| 926 | * @return n/a |
| 927 | */ |
| 928 | |
| 929 | removeActions: function (actions) { |
| 930 | actions = actions || this.actions || null; |
| 931 | if (!actions) return false; |
| 932 | for (var i in actions) { |
| 933 | this.removeAction(i, actions[i]); |
| 934 | } |
| 935 | }, |
| 936 | /** |
| 937 | * addAction |
| 938 | * |
| 939 | * Adds an action using the wp.hooks library |
| 940 | * |
| 941 | * @date 14/12/17 |
| 942 | * @since ACF 5.6.5 |
| 943 | * |
| 944 | * @param string name |
| 945 | * @param string callback |
| 946 | * @return n/a |
| 947 | */ |
| 948 | |
| 949 | addAction: function (name, callback, priority) { |
| 950 | //console.log('addAction', name, priority); |
| 951 | // defaults |
| 952 | priority = priority || this.priority; |
| 953 | |
| 954 | // modify callback |
| 955 | if (typeof callback === 'string') { |
| 956 | callback = this[callback]; |
| 957 | } |
| 958 | |
| 959 | // add |
| 960 | acf.addAction(name, callback, priority, this); |
| 961 | }, |
| 962 | /** |
| 963 | * removeAction |
| 964 | * |
| 965 | * Remove an action using the wp.hooks library |
| 966 | * |
| 967 | * @date 14/12/17 |
| 968 | * @since ACF 5.6.5 |
| 969 | * |
| 970 | * @param string name |
| 971 | * @param string callback |
| 972 | * @return n/a |
| 973 | */ |
| 974 | |
| 975 | removeAction: function (name, callback) { |
| 976 | acf.removeAction(name, this[callback]); |
| 977 | }, |
| 978 | /** |
| 979 | * addFilters |
| 980 | * |
| 981 | * Adds multiple filter handlers |
| 982 | * |
| 983 | * @date 14/12/17 |
| 984 | * @since ACF 5.6.5 |
| 985 | * |
| 986 | * @param object filters {filter1 : callback, filter2 : callback, etc } |
| 987 | * @return n/a |
| 988 | */ |
| 989 | |
| 990 | addFilters: function (filters) { |
| 991 | filters = filters || this.filters || null; |
| 992 | if (!filters) return false; |
| 993 | for (var i in filters) { |
| 994 | this.addFilter(i, filters[i]); |
| 995 | } |
| 996 | }, |
| 997 | /** |
| 998 | * addFilter |
| 999 | * |
| 1000 | * Adds a filter using the wp.hooks library |
| 1001 | * |
| 1002 | * @date 14/12/17 |
| 1003 | * @since ACF 5.6.5 |
| 1004 | * |
| 1005 | * @param string name |
| 1006 | * @param string callback |
| 1007 | * @return n/a |
| 1008 | */ |
| 1009 | |
| 1010 | addFilter: function (name, callback, priority) { |
| 1011 | // defaults |
| 1012 | priority = priority || this.priority; |
| 1013 | |
| 1014 | // modify callback |
| 1015 | if (typeof callback === 'string') { |
| 1016 | callback = this[callback]; |
| 1017 | } |
| 1018 | |
| 1019 | // add |
| 1020 | acf.addFilter(name, callback, priority, this); |
| 1021 | }, |
| 1022 | /** |
| 1023 | * removeFilters |
| 1024 | * |
| 1025 | * Removes multiple filter handlers |
| 1026 | * |
| 1027 | * @date 14/12/17 |
| 1028 | * @since ACF 5.6.5 |
| 1029 | * |
| 1030 | * @param object filters {filter1 : callback, filter2 : callback, etc } |
| 1031 | * @return n/a |
| 1032 | */ |
| 1033 | |
| 1034 | removeFilters: function (filters) { |
| 1035 | filters = filters || this.filters || null; |
| 1036 | if (!filters) return false; |
| 1037 | for (var i in filters) { |
| 1038 | this.removeFilter(i, filters[i]); |
| 1039 | } |
| 1040 | }, |
| 1041 | /** |
| 1042 | * removeFilter |
| 1043 | * |
| 1044 | * Remove a filter using the wp.hooks library |
| 1045 | * |
| 1046 | * @date 14/12/17 |
| 1047 | * @since ACF 5.6.5 |
| 1048 | * |
| 1049 | * @param string name |
| 1050 | * @param string callback |
| 1051 | * @return n/a |
| 1052 | */ |
| 1053 | |
| 1054 | removeFilter: function (name, callback) { |
| 1055 | acf.removeFilter(name, this[callback]); |
| 1056 | }, |
| 1057 | /** |
| 1058 | * $ |
| 1059 | * |
| 1060 | * description |
| 1061 | * |
| 1062 | * @date 16/12/17 |
| 1063 | * @since ACF 5.6.5 |
| 1064 | * |
| 1065 | * @param type $var Description. Default. |
| 1066 | * @return type Description. |
| 1067 | */ |
| 1068 | |
| 1069 | $: function (selector) { |
| 1070 | return this.$el.find(selector); |
| 1071 | }, |
| 1072 | /** |
| 1073 | * remove |
| 1074 | * |
| 1075 | * Removes the element and listenters |
| 1076 | * |
| 1077 | * @date 19/12/17 |
| 1078 | * @since ACF 5.6.5 |
| 1079 | * |
| 1080 | * @param type $var Description. Default. |
| 1081 | * @return type Description. |
| 1082 | */ |
| 1083 | |
| 1084 | remove: function () { |
| 1085 | this.removeEvents(); |
| 1086 | this.removeActions(); |
| 1087 | this.removeFilters(); |
| 1088 | this.$el.remove(); |
| 1089 | }, |
| 1090 | /** |
| 1091 | * setTimeout |
| 1092 | * |
| 1093 | * description |
| 1094 | * |
| 1095 | * @date 16/1/18 |
| 1096 | * @since ACF 5.6.5 |
| 1097 | * |
| 1098 | * @param type $var Description. Default. |
| 1099 | * @return type Description. |
| 1100 | */ |
| 1101 | |
| 1102 | setTimeout: function (callback, milliseconds) { |
| 1103 | return setTimeout(this.proxy(callback), milliseconds); |
| 1104 | }, |
| 1105 | /** |
| 1106 | * time |
| 1107 | * |
| 1108 | * used for debugging |
| 1109 | * |
| 1110 | * @date 7/3/18 |
| 1111 | * @since ACF 5.6.9 |
| 1112 | * |
| 1113 | * @param type $var Description. Default. |
| 1114 | * @return type Description. |
| 1115 | */ |
| 1116 | |
| 1117 | time: function () { |
| 1118 | console.time(this.id || this.cid); |
| 1119 | }, |
| 1120 | /** |
| 1121 | * timeEnd |
| 1122 | * |
| 1123 | * used for debugging |
| 1124 | * |
| 1125 | * @date 7/3/18 |
| 1126 | * @since ACF 5.6.9 |
| 1127 | * |
| 1128 | * @param type $var Description. Default. |
| 1129 | * @return type Description. |
| 1130 | */ |
| 1131 | |
| 1132 | timeEnd: function () { |
| 1133 | console.timeEnd(this.id || this.cid); |
| 1134 | }, |
| 1135 | /** |
| 1136 | * show |
| 1137 | * |
| 1138 | * description |
| 1139 | * |
| 1140 | * @date 15/3/18 |
| 1141 | * @since ACF 5.6.9 |
| 1142 | * |
| 1143 | * @param type $var Description. Default. |
| 1144 | * @return type Description. |
| 1145 | */ |
| 1146 | |
| 1147 | show: function () { |
| 1148 | acf.show(this.$el); |
| 1149 | }, |
| 1150 | /** |
| 1151 | * hide |
| 1152 | * |
| 1153 | * description |
| 1154 | * |
| 1155 | * @date 15/3/18 |
| 1156 | * @since ACF 5.6.9 |
| 1157 | * |
| 1158 | * @param type $var Description. Default. |
| 1159 | * @return type Description. |
| 1160 | */ |
| 1161 | |
| 1162 | hide: function () { |
| 1163 | acf.hide(this.$el); |
| 1164 | }, |
| 1165 | /** |
| 1166 | * proxy |
| 1167 | * |
| 1168 | * Returns a new function scoped to this model |
| 1169 | * |
| 1170 | * @date 29/3/18 |
| 1171 | * @since ACF 5.6.9 |
| 1172 | * |
| 1173 | * @param function callback |
| 1174 | * @return function |
| 1175 | */ |
| 1176 | |
| 1177 | proxy: function (callback) { |
| 1178 | return $.proxy(callback, this); |
| 1179 | } |
| 1180 | }); |
| 1181 | |
| 1182 | // Set up inheritance for the model |
| 1183 | Model.extend = extend; |
| 1184 | |
| 1185 | // Global model storage |
| 1186 | acf.models = {}; |
| 1187 | |
| 1188 | /** |
| 1189 | * acf.getInstance |
| 1190 | * |
| 1191 | * This function will get an instance from an element |
| 1192 | * |
| 1193 | * @date 5/3/18 |
| 1194 | * @since ACF 5.6.9 |
| 1195 | * |
| 1196 | * @param type $var Description. Default. |
| 1197 | * @return type Description. |
| 1198 | */ |
| 1199 | |
| 1200 | acf.getInstance = function ($el) { |
| 1201 | return $el.data('acf'); |
| 1202 | }; |
| 1203 | |
| 1204 | /** |
| 1205 | * acf.getInstances |
| 1206 | * |
| 1207 | * This function will get an array of instances from multiple elements |
| 1208 | * |
| 1209 | * @date 5/3/18 |
| 1210 | * @since ACF 5.6.9 |
| 1211 | * |
| 1212 | * @param type $var Description. Default. |
| 1213 | * @return type Description. |
| 1214 | */ |
| 1215 | |
| 1216 | acf.getInstances = function ($el) { |
| 1217 | var instances = []; |
| 1218 | $el.each(function () { |
| 1219 | instances.push(acf.getInstance($(this))); |
| 1220 | }); |
| 1221 | return instances; |
| 1222 | }; |
| 1223 | })(jQuery); |
| 1224 | |
| 1225 | /***/ }), |
| 1226 | |
| 1227 | /***/ "./assets/src/js/_acf-notice.js": |
| 1228 | /*!**************************************!*\ |
| 1229 | !*** ./assets/src/js/_acf-notice.js ***! |
| 1230 | \**************************************/ |
| 1231 | /***/ (() => { |
| 1232 | |
| 1233 | (function ($, undefined) { |
| 1234 | var Notice = acf.Model.extend({ |
| 1235 | data: { |
| 1236 | text: '', |
| 1237 | type: '', |
| 1238 | timeout: 0, |
| 1239 | dismiss: true, |
| 1240 | target: false, |
| 1241 | location: 'before', |
| 1242 | close: function () {} |
| 1243 | }, |
| 1244 | events: { |
| 1245 | 'click .acf-notice-dismiss': 'onClickClose' |
| 1246 | }, |
| 1247 | tmpl: function () { |
| 1248 | return '<div class="acf-notice"></div>'; |
| 1249 | }, |
| 1250 | setup: function (props) { |
| 1251 | $.extend(this.data, props); |
| 1252 | this.$el = $(this.tmpl()); |
| 1253 | }, |
| 1254 | initialize: function () { |
| 1255 | // render |
| 1256 | this.render(); |
| 1257 | |
| 1258 | // show |
| 1259 | this.show(); |
| 1260 | }, |
| 1261 | render: function () { |
| 1262 | // class |
| 1263 | this.type(this.get('type')); |
| 1264 | |
| 1265 | // text |
| 1266 | this.html('<p>' + this.get('text') + '</p>'); |
| 1267 | |
| 1268 | // close |
| 1269 | if (this.get('dismiss')) { |
| 1270 | this.$el.append('<a href="#" class="acf-notice-dismiss acf-icon -cancel small"></a>'); |
| 1271 | this.$el.addClass('-dismiss'); |
| 1272 | } |
| 1273 | |
| 1274 | // timeout |
| 1275 | var timeout = this.get('timeout'); |
| 1276 | if (timeout) { |
| 1277 | this.away(timeout); |
| 1278 | } |
| 1279 | }, |
| 1280 | update: function (props) { |
| 1281 | // update |
| 1282 | $.extend(this.data, props); |
| 1283 | |
| 1284 | // re-initialize |
| 1285 | this.initialize(); |
| 1286 | |
| 1287 | // refresh events |
| 1288 | this.removeEvents(); |
| 1289 | this.addEvents(); |
| 1290 | }, |
| 1291 | show: function () { |
| 1292 | var $target = this.get('target'); |
| 1293 | var location = this.get('location'); |
| 1294 | if ($target) { |
| 1295 | if (location === 'after') { |
| 1296 | $target.append(this.$el); |
| 1297 | } else { |
| 1298 | $target.prepend(this.$el); |
| 1299 | } |
| 1300 | } |
| 1301 | }, |
| 1302 | hide: function () { |
| 1303 | this.$el.remove(); |
| 1304 | }, |
| 1305 | away: function (timeout) { |
| 1306 | this.setTimeout(function () { |
| 1307 | acf.remove(this.$el); |
| 1308 | }, timeout); |
| 1309 | }, |
| 1310 | type: function (type) { |
| 1311 | // remove prev type |
| 1312 | var prevType = this.get('type'); |
| 1313 | if (prevType) { |
| 1314 | this.$el.removeClass('-' + prevType); |
| 1315 | } |
| 1316 | |
| 1317 | // add new type |
| 1318 | this.$el.addClass('-' + type); |
| 1319 | |
| 1320 | // backwards compatibility |
| 1321 | if (type == 'error') { |
| 1322 | this.$el.addClass('acf-error-message'); |
| 1323 | } |
| 1324 | }, |
| 1325 | html: function (html) { |
| 1326 | this.$el.html(acf.escHtml(html)); |
| 1327 | }, |
| 1328 | text: function (text) { |
| 1329 | this.$('p').html(acf.escHtml(text)); |
| 1330 | }, |
| 1331 | onClickClose: function (e, $el) { |
| 1332 | e.preventDefault(); |
| 1333 | this.get('close').apply(this, arguments); |
| 1334 | this.remove(); |
| 1335 | } |
| 1336 | }); |
| 1337 | acf.newNotice = function (props) { |
| 1338 | // ensure object |
| 1339 | if (typeof props !== 'object') { |
| 1340 | props = { |
| 1341 | text: props |
| 1342 | }; |
| 1343 | } |
| 1344 | |
| 1345 | // instantiate |
| 1346 | return new Notice(props); |
| 1347 | }; |
| 1348 | var noticeManager = new acf.Model({ |
| 1349 | wait: 'prepare', |
| 1350 | priority: 1, |
| 1351 | initialize: function () { |
| 1352 | const $notices = $('.acf-admin-notice'); |
| 1353 | $notices.each(function () { |
| 1354 | if ($(this).data('persisted')) { |
| 1355 | let dismissed = acf.getPreference('dismissed-notices'); |
| 1356 | if (dismissed && typeof dismissed == 'object' && dismissed.includes($(this).data('persist-id'))) { |
| 1357 | $(this).remove(); |
| 1358 | } else { |
| 1359 | $(this).show(); |
| 1360 | $(this).on('click', '.notice-dismiss', function (e) { |
| 1361 | dismissed = acf.getPreference('dismissed-notices'); |
| 1362 | if (!dismissed || typeof dismissed != 'object') { |
| 1363 | dismissed = []; |
| 1364 | } |
| 1365 | dismissed.push($(this).closest('.acf-admin-notice').data('persist-id')); |
| 1366 | acf.setPreference('dismissed-notices', dismissed); |
| 1367 | }); |
| 1368 | } |
| 1369 | } |
| 1370 | }); |
| 1371 | } |
| 1372 | }); |
| 1373 | })(jQuery); |
| 1374 | |
| 1375 | /***/ }), |
| 1376 | |
| 1377 | /***/ "./assets/src/js/_acf-panel.js": |
| 1378 | /*!*************************************!*\ |
| 1379 | !*** ./assets/src/js/_acf-panel.js ***! |
| 1380 | \*************************************/ |
| 1381 | /***/ (() => { |
| 1382 | |
| 1383 | (function ($, undefined) { |
| 1384 | var panel = new acf.Model({ |
| 1385 | events: { |
| 1386 | 'click .acf-panel-title': 'onClick' |
| 1387 | }, |
| 1388 | onClick: function (e, $el) { |
| 1389 | e.preventDefault(); |
| 1390 | this.toggle($el.parent()); |
| 1391 | }, |
| 1392 | isOpen: function ($el) { |
| 1393 | return $el.hasClass('-open'); |
| 1394 | }, |
| 1395 | toggle: function ($el) { |
| 1396 | this.isOpen($el) ? this.close($el) : this.open($el); |
| 1397 | }, |
| 1398 | open: function ($el) { |
| 1399 | $el.addClass('-open'); |
| 1400 | $el.find('.acf-panel-title i').attr('class', 'dashicons dashicons-arrow-down'); |
| 1401 | }, |
| 1402 | close: function ($el) { |
| 1403 | $el.removeClass('-open'); |
| 1404 | $el.find('.acf-panel-title i').attr('class', 'dashicons dashicons-arrow-right'); |
| 1405 | } |
| 1406 | }); |
| 1407 | })(jQuery); |
| 1408 | |
| 1409 | /***/ }), |
| 1410 | |
| 1411 | /***/ "./assets/src/js/_acf-popup.js": |
| 1412 | /*!*************************************!*\ |
| 1413 | !*** ./assets/src/js/_acf-popup.js ***! |
| 1414 | \*************************************/ |
| 1415 | /***/ (() => { |
| 1416 | |
| 1417 | (function ($, undefined) { |
| 1418 | acf.models.Popup = acf.Model.extend({ |
| 1419 | data: { |
| 1420 | title: '', |
| 1421 | content: '', |
| 1422 | width: 0, |
| 1423 | height: 0, |
| 1424 | loading: false, |
| 1425 | openedBy: null |
| 1426 | }, |
| 1427 | events: { |
| 1428 | 'click [data-event="close"]': 'onClickClose', |
| 1429 | 'click .acf-close-popup': 'onClickClose', |
| 1430 | 'keydown': 'onPressEscapeClose' |
| 1431 | }, |
| 1432 | setup: function (props) { |
| 1433 | $.extend(this.data, props); |
| 1434 | this.$el = $(this.tmpl()); |
| 1435 | }, |
| 1436 | initialize: function () { |
| 1437 | this.render(); |
| 1438 | this.open(); |
| 1439 | this.focus(); |
| 1440 | this.lockFocusToPopup(true); |
| 1441 | }, |
| 1442 | tmpl: function () { |
| 1443 | return ['<div id="acf-popup" role="dialog" tabindex="-1">', '<div class="acf-popup-box acf-box">', '<div class="title"><h3></h3><a href="#" class="acf-icon -cancel grey" data-event="close" aria-label="' + acf.__('Close modal') + '"></a></div>', '<div class="inner"></div>', '<div class="loading"><i class="acf-loading"></i></div>', '</div>', '<div class="bg" data-event="close"></div>', '</div>'].join(''); |
| 1444 | }, |
| 1445 | render: function () { |
| 1446 | // Extract Vars. |
| 1447 | var title = this.get('title'); |
| 1448 | var content = this.get('content'); |
| 1449 | var loading = this.get('loading'); |
| 1450 | var width = this.get('width'); |
| 1451 | var height = this.get('height'); |
| 1452 | |
| 1453 | // Update. |
| 1454 | this.title(title); |
| 1455 | this.content(content); |
| 1456 | if (width) { |
| 1457 | this.$('.acf-popup-box').css('width', width); |
| 1458 | } |
| 1459 | if (height) { |
| 1460 | this.$('.acf-popup-box').css('min-height', height); |
| 1461 | } |
| 1462 | this.loading(loading); |
| 1463 | |
| 1464 | // Trigger action. |
| 1465 | acf.doAction('append', this.$el); |
| 1466 | }, |
| 1467 | /** |
| 1468 | * Places focus within the popup. |
| 1469 | */ |
| 1470 | focus: function () { |
| 1471 | this.$el.find('.acf-icon').first().trigger('focus'); |
| 1472 | }, |
| 1473 | /** |
| 1474 | * Locks focus within the popup. |
| 1475 | * |
| 1476 | * @param {boolean} locked True to lock focus, false to unlock. |
| 1477 | */ |
| 1478 | lockFocusToPopup: function (locked) { |
| 1479 | let inertElement = $('#wpwrap'); |
| 1480 | if (!inertElement.length) { |
| 1481 | return; |
| 1482 | } |
| 1483 | inertElement[0].inert = locked; |
| 1484 | inertElement.attr('aria-hidden', locked); |
| 1485 | }, |
| 1486 | update: function (props) { |
| 1487 | this.data = acf.parseArgs(props, this.data); |
| 1488 | this.render(); |
| 1489 | }, |
| 1490 | title: function (title) { |
| 1491 | this.$('.title:first h3').html(title); |
| 1492 | }, |
| 1493 | content: function (content) { |
| 1494 | this.$('.inner:first').html(content); |
| 1495 | }, |
| 1496 | loading: function (show) { |
| 1497 | var $loading = this.$('.loading:first'); |
| 1498 | show ? $loading.show() : $loading.hide(); |
| 1499 | }, |
| 1500 | open: function () { |
| 1501 | $('body').append(this.$el); |
| 1502 | }, |
| 1503 | close: function () { |
| 1504 | this.lockFocusToPopup(false); |
| 1505 | this.returnFocusToOrigin(); |
| 1506 | this.remove(); |
| 1507 | }, |
| 1508 | onClickClose: function (e, $el) { |
| 1509 | e.preventDefault(); |
| 1510 | this.close(); |
| 1511 | }, |
| 1512 | /** |
| 1513 | * Closes the popup when the escape key is pressed. |
| 1514 | * |
| 1515 | * @param {KeyboardEvent} e |
| 1516 | */ |
| 1517 | onPressEscapeClose: function (e) { |
| 1518 | if (e.key === 'Escape') { |
| 1519 | this.close(); |
| 1520 | } |
| 1521 | }, |
| 1522 | /** |
| 1523 | * Returns focus to the element that opened the popup |
| 1524 | * if it still exists in the DOM. |
| 1525 | */ |
| 1526 | returnFocusToOrigin: function () { |
| 1527 | if (this.data.openedBy instanceof $ && this.data.openedBy.closest('body').length > 0) { |
| 1528 | this.data.openedBy.trigger('focus'); |
| 1529 | } |
| 1530 | } |
| 1531 | }); |
| 1532 | |
| 1533 | /** |
| 1534 | * newPopup |
| 1535 | * |
| 1536 | * Creates a new Popup with the supplied props |
| 1537 | * |
| 1538 | * @date 17/12/17 |
| 1539 | * @since ACF 5.6.5 |
| 1540 | * |
| 1541 | * @param object props |
| 1542 | * @return object |
| 1543 | */ |
| 1544 | |
| 1545 | acf.newPopup = function (props) { |
| 1546 | return new acf.models.Popup(props); |
| 1547 | }; |
| 1548 | })(jQuery); |
| 1549 | |
| 1550 | /***/ }), |
| 1551 | |
| 1552 | /***/ "./assets/src/js/_acf-tooltip.js": |
| 1553 | /*!***************************************!*\ |
| 1554 | !*** ./assets/src/js/_acf-tooltip.js ***! |
| 1555 | \***************************************/ |
| 1556 | /***/ (() => { |
| 1557 | |
| 1558 | (function ($, undefined) { |
| 1559 | acf.newTooltip = function (props) { |
| 1560 | // ensure object |
| 1561 | if (typeof props !== 'object') { |
| 1562 | props = { |
| 1563 | text: props |
| 1564 | }; |
| 1565 | } |
| 1566 | |
| 1567 | // confirmRemove |
| 1568 | if (props.confirmRemove !== undefined) { |
| 1569 | props.textConfirm = acf.__('Remove'); |
| 1570 | props.textCancel = acf.__('Cancel'); |
| 1571 | return new TooltipConfirm(props); |
| 1572 | |
| 1573 | // confirm |
| 1574 | } else if (props.confirm !== undefined) { |
| 1575 | return new TooltipConfirm(props); |
| 1576 | |
| 1577 | // default |
| 1578 | } else { |
| 1579 | return new Tooltip(props); |
| 1580 | } |
| 1581 | }; |
| 1582 | var Tooltip = acf.Model.extend({ |
| 1583 | data: { |
| 1584 | text: '', |
| 1585 | timeout: 0, |
| 1586 | target: null |
| 1587 | }, |
| 1588 | tmpl: function () { |
| 1589 | return '<div class="acf-tooltip"></div>'; |
| 1590 | }, |
| 1591 | setup: function (props) { |
| 1592 | $.extend(this.data, props); |
| 1593 | this.$el = $(this.tmpl()); |
| 1594 | }, |
| 1595 | initialize: function () { |
| 1596 | // render |
| 1597 | this.render(); |
| 1598 | |
| 1599 | // append |
| 1600 | this.show(); |
| 1601 | |
| 1602 | // position |
| 1603 | this.position(); |
| 1604 | |
| 1605 | // timeout |
| 1606 | var timeout = this.get('timeout'); |
| 1607 | if (timeout) { |
| 1608 | setTimeout($.proxy(this.fade, this), timeout); |
| 1609 | } |
| 1610 | }, |
| 1611 | update: function (props) { |
| 1612 | $.extend(this.data, props); |
| 1613 | this.initialize(); |
| 1614 | }, |
| 1615 | render: function () { |
| 1616 | this.$el.text(this.get('text')); |
| 1617 | }, |
| 1618 | show: function () { |
| 1619 | $('body').append(this.$el); |
| 1620 | }, |
| 1621 | hide: function () { |
| 1622 | this.$el.remove(); |
| 1623 | }, |
| 1624 | fade: function () { |
| 1625 | // add class |
| 1626 | this.$el.addClass('acf-fade-up'); |
| 1627 | |
| 1628 | // remove |
| 1629 | this.setTimeout(function () { |
| 1630 | this.remove(); |
| 1631 | }, 250); |
| 1632 | }, |
| 1633 | html: function (html) { |
| 1634 | this.$el.html(html); |
| 1635 | }, |
| 1636 | position: function () { |
| 1637 | // vars |
| 1638 | var $tooltip = this.$el; |
| 1639 | var $target = this.get('target'); |
| 1640 | if (!$target) return; |
| 1641 | |
| 1642 | // Reset position. |
| 1643 | $tooltip.removeClass('right left bottom top').css({ |
| 1644 | top: 0, |
| 1645 | left: 0 |
| 1646 | }); |
| 1647 | |
| 1648 | // Declare tollerance to edge of screen. |
| 1649 | var tolerance = 10; |
| 1650 | |
| 1651 | // Find target position. |
| 1652 | var targetWidth = $target.outerWidth(); |
| 1653 | var targetHeight = $target.outerHeight(); |
| 1654 | var targetTop = $target.offset().top; |
| 1655 | var targetLeft = $target.offset().left; |
| 1656 | |
| 1657 | // Find tooltip position. |
| 1658 | var tooltipWidth = $tooltip.outerWidth(); |
| 1659 | var tooltipHeight = $tooltip.outerHeight(); |
| 1660 | var tooltipTop = $tooltip.offset().top; // Should be 0, but WP media grid causes this to be 32 (toolbar padding). |
| 1661 | |
| 1662 | // Assume default top alignment. |
| 1663 | var top = targetTop - tooltipHeight - tooltipTop; |
| 1664 | var left = targetLeft + targetWidth / 2 - tooltipWidth / 2; |
| 1665 | |
| 1666 | // Check if too far left. |
| 1667 | if (left < tolerance) { |
| 1668 | $tooltip.addClass('right'); |
| 1669 | left = targetLeft + targetWidth; |
| 1670 | top = targetTop + targetHeight / 2 - tooltipHeight / 2 - tooltipTop; |
| 1671 | |
| 1672 | // Check if too far right. |
| 1673 | } else if (left + tooltipWidth + tolerance > $(window).width()) { |
| 1674 | $tooltip.addClass('left'); |
| 1675 | left = targetLeft - tooltipWidth; |
| 1676 | top = targetTop + targetHeight / 2 - tooltipHeight / 2 - tooltipTop; |
| 1677 | |
| 1678 | // Check if too far up. |
| 1679 | } else if (top - $(window).scrollTop() < tolerance) { |
| 1680 | $tooltip.addClass('bottom'); |
| 1681 | top = targetTop + targetHeight - tooltipTop; |
| 1682 | |
| 1683 | // No colision with edges. |
| 1684 | } else { |
| 1685 | $tooltip.addClass('top'); |
| 1686 | } |
| 1687 | |
| 1688 | // update css |
| 1689 | $tooltip.css({ |
| 1690 | top: top, |
| 1691 | left: left |
| 1692 | }); |
| 1693 | } |
| 1694 | }); |
| 1695 | var TooltipConfirm = Tooltip.extend({ |
| 1696 | data: { |
| 1697 | text: '', |
| 1698 | textConfirm: '', |
| 1699 | textCancel: '', |
| 1700 | target: null, |
| 1701 | targetConfirm: true, |
| 1702 | confirm: function () {}, |
| 1703 | cancel: function () {}, |
| 1704 | context: false |
| 1705 | }, |
| 1706 | events: { |
| 1707 | 'click [data-event="cancel"]': 'onCancel', |
| 1708 | 'click [data-event="confirm"]': 'onConfirm' |
| 1709 | }, |
| 1710 | addEvents: function () { |
| 1711 | // add events |
| 1712 | acf.Model.prototype.addEvents.apply(this); |
| 1713 | |
| 1714 | // vars |
| 1715 | var $document = $(document); |
| 1716 | var $target = this.get('target'); |
| 1717 | |
| 1718 | // add global 'cancel' click event |
| 1719 | // - use timeout to avoid the current 'click' event triggering the onCancel function |
| 1720 | this.setTimeout(function () { |
| 1721 | this.on($document, 'click', 'onCancel'); |
| 1722 | }); |
| 1723 | |
| 1724 | // add target 'confirm' click event |
| 1725 | // - allow setting to control this feature |
| 1726 | if (this.get('targetConfirm')) { |
| 1727 | this.on($target, 'click', 'onConfirm'); |
| 1728 | } |
| 1729 | }, |
| 1730 | removeEvents: function () { |
| 1731 | // remove events |
| 1732 | acf.Model.prototype.removeEvents.apply(this); |
| 1733 | |
| 1734 | // vars |
| 1735 | var $document = $(document); |
| 1736 | var $target = this.get('target'); |
| 1737 | |
| 1738 | // remove custom events |
| 1739 | this.off($document, 'click'); |
| 1740 | this.off($target, 'click'); |
| 1741 | }, |
| 1742 | render: function () { |
| 1743 | // defaults |
| 1744 | var text = this.get('text') || acf.__('Are you sure?'); |
| 1745 | var textConfirm = this.get('textConfirm') || acf.__('Yes'); |
| 1746 | var textCancel = this.get('textCancel') || acf.__('No'); |
| 1747 | |
| 1748 | // html |
| 1749 | var html = [text, '<a href="#" data-event="confirm">' + textConfirm + '</a>', '<a href="#" data-event="cancel">' + textCancel + '</a>'].join(' '); |
| 1750 | |
| 1751 | // html |
| 1752 | this.html(html); |
| 1753 | |
| 1754 | // class |
| 1755 | this.$el.addClass('-confirm'); |
| 1756 | }, |
| 1757 | onCancel: function (e, $el) { |
| 1758 | // prevent default |
| 1759 | e.preventDefault(); |
| 1760 | e.stopImmediatePropagation(); |
| 1761 | |
| 1762 | // callback |
| 1763 | var callback = this.get('cancel'); |
| 1764 | var context = this.get('context') || this; |
| 1765 | callback.apply(context, arguments); |
| 1766 | |
| 1767 | //remove |
| 1768 | this.remove(); |
| 1769 | }, |
| 1770 | onConfirm: function (e, $el) { |
| 1771 | // Prevent event from propagating completely to allow "targetConfirm" to be clicked. |
| 1772 | e.preventDefault(); |
| 1773 | e.stopImmediatePropagation(); |
| 1774 | |
| 1775 | // callback |
| 1776 | var callback = this.get('confirm'); |
| 1777 | var context = this.get('context') || this; |
| 1778 | callback.apply(context, arguments); |
| 1779 | |
| 1780 | //remove |
| 1781 | this.remove(); |
| 1782 | } |
| 1783 | }); |
| 1784 | |
| 1785 | // storage |
| 1786 | acf.models.Tooltip = Tooltip; |
| 1787 | acf.models.TooltipConfirm = TooltipConfirm; |
| 1788 | |
| 1789 | /** |
| 1790 | * tooltipManager |
| 1791 | * |
| 1792 | * description |
| 1793 | * |
| 1794 | * @date 17/4/18 |
| 1795 | * @since ACF 5.6.9 |
| 1796 | * |
| 1797 | * @param type $var Description. Default. |
| 1798 | * @return type Description. |
| 1799 | */ |
| 1800 | |
| 1801 | var tooltipHoverHelper = new acf.Model({ |
| 1802 | tooltip: false, |
| 1803 | events: { |
| 1804 | 'mouseenter .acf-js-tooltip': 'showTitle', |
| 1805 | 'mouseup .acf-js-tooltip': 'hideTitle', |
| 1806 | 'mouseleave .acf-js-tooltip': 'hideTitle', |
| 1807 | 'focus .acf-js-tooltip': 'showTitle', |
| 1808 | 'blur .acf-js-tooltip': 'hideTitle', |
| 1809 | 'keyup .acf-js-tooltip': 'onKeyUp' |
| 1810 | }, |
| 1811 | showTitle: function (e, $el) { |
| 1812 | // vars |
| 1813 | var title = $el.attr('title'); |
| 1814 | |
| 1815 | // bail early if no title |
| 1816 | if (!title) { |
| 1817 | return; |
| 1818 | } |
| 1819 | |
| 1820 | // clear title to avoid default browser tooltip |
| 1821 | $el.attr('title', ''); |
| 1822 | |
| 1823 | // create |
| 1824 | if (!this.tooltip) { |
| 1825 | this.tooltip = acf.newTooltip({ |
| 1826 | text: title, |
| 1827 | target: $el |
| 1828 | }); |
| 1829 | |
| 1830 | // update |
| 1831 | } else { |
| 1832 | this.tooltip.update({ |
| 1833 | text: title, |
| 1834 | target: $el |
| 1835 | }); |
| 1836 | } |
| 1837 | }, |
| 1838 | hideTitle: function (e, $el) { |
| 1839 | // hide tooltip |
| 1840 | this.tooltip.hide(); |
| 1841 | |
| 1842 | // restore title |
| 1843 | $el.attr('title', this.tooltip.get('text')); |
| 1844 | }, |
| 1845 | onKeyUp: function (e, $el) { |
| 1846 | if ('Escape' === e.key) { |
| 1847 | this.hideTitle(e, $el); |
| 1848 | } |
| 1849 | } |
| 1850 | }); |
| 1851 | })(jQuery); |
| 1852 | |
| 1853 | /***/ }), |
| 1854 | |
| 1855 | /***/ "./assets/src/js/_acf.js": |
| 1856 | /*!*******************************!*\ |
| 1857 | !*** ./assets/src/js/_acf.js ***! |
| 1858 | \*******************************/ |
| 1859 | /***/ (() => { |
| 1860 | |
| 1861 | (function ($, undefined) { |
| 1862 | /** |
| 1863 | * acf |
| 1864 | * |
| 1865 | * description |
| 1866 | * |
| 1867 | * @date 14/12/17 |
| 1868 | * @since ACF 5.6.5 |
| 1869 | * |
| 1870 | * @param type $var Description. Default. |
| 1871 | * @return type Description. |
| 1872 | */ |
| 1873 | |
| 1874 | // The global acf object |
| 1875 | var acf = {}; |
| 1876 | |
| 1877 | // Set as a browser global |
| 1878 | window.acf = acf; |
| 1879 | |
| 1880 | /** @var object Data sent from PHP */ |
| 1881 | acf.data = {}; |
| 1882 | |
| 1883 | /** |
| 1884 | * get |
| 1885 | * |
| 1886 | * Gets a specific data value |
| 1887 | * |
| 1888 | * @date 14/12/17 |
| 1889 | * @since ACF 5.6.5 |
| 1890 | * |
| 1891 | * @param string name |
| 1892 | * @return mixed |
| 1893 | */ |
| 1894 | |
| 1895 | acf.get = function (name) { |
| 1896 | return this.data[name] || null; |
| 1897 | }; |
| 1898 | |
| 1899 | /** |
| 1900 | * has |
| 1901 | * |
| 1902 | * Returns `true` if the data exists and is not null |
| 1903 | * |
| 1904 | * @date 14/12/17 |
| 1905 | * @since ACF 5.6.5 |
| 1906 | * |
| 1907 | * @param string name |
| 1908 | * @return boolean |
| 1909 | */ |
| 1910 | |
| 1911 | acf.has = function (name) { |
| 1912 | return this.get(name) !== null; |
| 1913 | }; |
| 1914 | |
| 1915 | /** |
| 1916 | * set |
| 1917 | * |
| 1918 | * Sets a specific data value |
| 1919 | * |
| 1920 | * @date 14/12/17 |
| 1921 | * @since ACF 5.6.5 |
| 1922 | * |
| 1923 | * @param string name |
| 1924 | * @param mixed value |
| 1925 | * @return this |
| 1926 | */ |
| 1927 | |
| 1928 | acf.set = function (name, value) { |
| 1929 | this.data[name] = value; |
| 1930 | return this; |
| 1931 | }; |
| 1932 | |
| 1933 | /** |
| 1934 | * uniqueId |
| 1935 | * |
| 1936 | * Returns a unique ID |
| 1937 | * |
| 1938 | * @date 9/11/17 |
| 1939 | * @since ACF 5.6.3 |
| 1940 | * |
| 1941 | * @param string prefix Optional prefix. |
| 1942 | * @return string |
| 1943 | */ |
| 1944 | |
| 1945 | var idCounter = 0; |
| 1946 | acf.uniqueId = function (prefix) { |
| 1947 | var id = ++idCounter + ''; |
| 1948 | return prefix ? prefix + id : id; |
| 1949 | }; |
| 1950 | |
| 1951 | /** |
| 1952 | * acf.uniqueArray |
| 1953 | * |
| 1954 | * Returns a new array with only unique values |
| 1955 | * Credit: https://stackoverflow.com/questions/1960473/get-all-unique-values-in-an-array-remove-duplicates |
| 1956 | * |
| 1957 | * @date 23/3/18 |
| 1958 | * @since ACF 5.6.9 |
| 1959 | * |
| 1960 | * @param type $var Description. Default. |
| 1961 | * @return type Description. |
| 1962 | */ |
| 1963 | |
| 1964 | acf.uniqueArray = function (array) { |
| 1965 | function onlyUnique(value, index, self) { |
| 1966 | return self.indexOf(value) === index; |
| 1967 | } |
| 1968 | return array.filter(onlyUnique); |
| 1969 | }; |
| 1970 | |
| 1971 | /** |
| 1972 | * uniqid |
| 1973 | * |
| 1974 | * Returns a unique ID (PHP version) |
| 1975 | * |
| 1976 | * @date 9/11/17 |
| 1977 | * @since ACF 5.6.3 |
| 1978 | * @source http://locutus.io/php/misc/uniqid/ |
| 1979 | * |
| 1980 | * @param string prefix Optional prefix. |
| 1981 | * @return string |
| 1982 | */ |
| 1983 | |
| 1984 | var uniqidSeed = ''; |
| 1985 | acf.uniqid = function (prefix, moreEntropy) { |
| 1986 | // discuss at: http://locutus.io/php/uniqid/ |
| 1987 | // original by: Kevin van Zonneveld (http://kvz.io) |
| 1988 | // revised by: Kankrelune (http://www.webfaktory.info/) |
| 1989 | // note 1: Uses an internal counter (in locutus global) to avoid collision |
| 1990 | // example 1: var $id = uniqid() |
| 1991 | // example 1: var $result = $id.length === 13 |
| 1992 | // returns 1: true |
| 1993 | // example 2: var $id = uniqid('foo') |
| 1994 | // example 2: var $result = $id.length === (13 + 'foo'.length) |
| 1995 | // returns 2: true |
| 1996 | // example 3: var $id = uniqid('bar', true) |
| 1997 | // example 3: var $result = $id.length === (23 + 'bar'.length) |
| 1998 | // returns 3: true |
| 1999 | if (typeof prefix === 'undefined') { |
| 2000 | prefix = ''; |
| 2001 | } |
| 2002 | var retId; |
| 2003 | var formatSeed = function (seed, reqWidth) { |
| 2004 | seed = parseInt(seed, 10).toString(16); // to hex str |
| 2005 | if (reqWidth < seed.length) { |
| 2006 | // so long we split |
| 2007 | return seed.slice(seed.length - reqWidth); |
| 2008 | } |
| 2009 | if (reqWidth > seed.length) { |
| 2010 | // so short we pad |
| 2011 | return Array(1 + (reqWidth - seed.length)).join('0') + seed; |
| 2012 | } |
| 2013 | return seed; |
| 2014 | }; |
| 2015 | if (!uniqidSeed) { |
| 2016 | // init seed with big random int |
| 2017 | uniqidSeed = Math.floor(Math.random() * 0x75bcd15); |
| 2018 | } |
| 2019 | uniqidSeed++; |
| 2020 | retId = prefix; // start with prefix, add current milliseconds hex string |
| 2021 | retId += formatSeed(parseInt(new Date().getTime() / 1000, 10), 8); |
| 2022 | retId += formatSeed(uniqidSeed, 5); // add seed hex string |
| 2023 | if (moreEntropy) { |
| 2024 | // for more entropy we add a float lower to 10 |
| 2025 | retId += (Math.random() * 10).toFixed(8).toString(); |
| 2026 | } |
| 2027 | return retId; |
| 2028 | }; |
| 2029 | |
| 2030 | /** |
| 2031 | * strReplace |
| 2032 | * |
| 2033 | * Performs a string replace |
| 2034 | * |
| 2035 | * @date 14/12/17 |
| 2036 | * @since ACF 5.6.5 |
| 2037 | * |
| 2038 | * @param string search |
| 2039 | * @param string replace |
| 2040 | * @param string subject |
| 2041 | * @return string |
| 2042 | */ |
| 2043 | |
| 2044 | acf.strReplace = function (search, replace, subject) { |
| 2045 | return subject.split(search).join(replace); |
| 2046 | }; |
| 2047 | |
| 2048 | /** |
| 2049 | * strCamelCase |
| 2050 | * |
| 2051 | * Converts a string into camelCase |
| 2052 | * Thanks to https://stackoverflow.com/questions/2970525/converting-any-string-into-camel-case |
| 2053 | * |
| 2054 | * @date 14/12/17 |
| 2055 | * @since ACF 5.6.5 |
| 2056 | * |
| 2057 | * @param string str |
| 2058 | * @return string |
| 2059 | */ |
| 2060 | |
| 2061 | acf.strCamelCase = function (str) { |
| 2062 | var matches = str.match(/([a-zA-Z0-9]+)/g); |
| 2063 | return matches ? matches.map(function (s, i) { |
| 2064 | var c = s.charAt(0); |
| 2065 | return (i === 0 ? c.toLowerCase() : c.toUpperCase()) + s.slice(1); |
| 2066 | }).join('') : ''; |
| 2067 | }; |
| 2068 | |
| 2069 | /** |
| 2070 | * strPascalCase |
| 2071 | * |
| 2072 | * Converts a string into PascalCase |
| 2073 | * Thanks to https://stackoverflow.com/questions/1026069/how-do-i-make-the-first-letter-of-a-string-uppercase-in-javascript |
| 2074 | * |
| 2075 | * @date 14/12/17 |
| 2076 | * @since ACF 5.6.5 |
| 2077 | * |
| 2078 | * @param string str |
| 2079 | * @return string |
| 2080 | */ |
| 2081 | |
| 2082 | acf.strPascalCase = function (str) { |
| 2083 | var camel = acf.strCamelCase(str); |
| 2084 | return camel.charAt(0).toUpperCase() + camel.slice(1); |
| 2085 | }; |
| 2086 | |
| 2087 | /** |
| 2088 | * acf.strSlugify |
| 2089 | * |
| 2090 | * Converts a string into a HTML class friendly slug |
| 2091 | * |
| 2092 | * @date 21/3/18 |
| 2093 | * @since ACF 5.6.9 |
| 2094 | * |
| 2095 | * @param string str |
| 2096 | * @return string |
| 2097 | */ |
| 2098 | |
| 2099 | acf.strSlugify = function (str) { |
| 2100 | return acf.strReplace('_', '-', str.toLowerCase()); |
| 2101 | }; |
| 2102 | acf.strSanitize = function (str, toLowerCase = true) { |
| 2103 | // chars (https://jsperf.com/replace-foreign-characters) |
| 2104 | var map = { |
| 2105 | À: 'A', |
| 2106 | Á: 'A', |
| 2107 | Â: 'A', |
| 2108 | Ã: 'A', |
| 2109 | Ä: 'A', |
| 2110 | � |
| 2111 | : 'A', |
| 2112 | Æ: 'AE', |
| 2113 | Ç: 'C', |
| 2114 | È: 'E', |
| 2115 | É: 'E', |
| 2116 | Ê: 'E', |
| 2117 | Ë: 'E', |
| 2118 | Ì: 'I', |
| 2119 | Í: 'I', |
| 2120 | Î: 'I', |
| 2121 | Ï: 'I', |
| 2122 | Ð: 'D', |
| 2123 | Ñ: 'N', |
| 2124 | Ò: 'O', |
| 2125 | Ó: 'O', |
| 2126 | Ô: 'O', |
| 2127 | Õ: 'O', |
| 2128 | Ö: 'O', |
| 2129 | Ø: 'O', |
| 2130 | Ù: 'U', |
| 2131 | Ú: 'U', |
| 2132 | Û: 'U', |
| 2133 | Ü: 'U', |
| 2134 | Ý: 'Y', |
| 2135 | ß: 's', |
| 2136 | à: 'a', |
| 2137 | á: 'a', |
| 2138 | â: 'a', |
| 2139 | ã: 'a', |
| 2140 | ä: 'a', |
| 2141 | å: 'a', |
| 2142 | æ: 'ae', |
| 2143 | ç: 'c', |
| 2144 | è: 'e', |
| 2145 | é: 'e', |
| 2146 | ê: 'e', |
| 2147 | ë: 'e', |
| 2148 | ì: 'i', |
| 2149 | í: 'i', |
| 2150 | î: 'i', |
| 2151 | ï: 'i', |
| 2152 | ñ: 'n', |
| 2153 | ò: 'o', |
| 2154 | ó: 'o', |
| 2155 | ô: 'o', |
| 2156 | õ: 'o', |
| 2157 | ö: 'o', |
| 2158 | ø: 'o', |
| 2159 | ù: 'u', |
| 2160 | ú: 'u', |
| 2161 | û: 'u', |
| 2162 | ü: 'u', |
| 2163 | ý: 'y', |
| 2164 | ÿ: 'y', |
| 2165 | Ā: 'A', |
| 2166 | ā: 'a', |
| 2167 | Ă: 'A', |
| 2168 | ă: 'a', |
| 2169 | Ą: 'A', |
| 2170 | � |
| 2171 | : 'a', |
| 2172 | Ć: 'C', |
| 2173 | ć: 'c', |
| 2174 | Ĉ: 'C', |
| 2175 | ĉ: 'c', |
| 2176 | Ċ: 'C', |
| 2177 | ċ: 'c', |
| 2178 | Č: 'C', |
| 2179 | č: 'c', |
| 2180 | Ď: 'D', |
| 2181 | ď: 'd', |
| 2182 | Đ: 'D', |
| 2183 | đ: 'd', |
| 2184 | Ē: 'E', |
| 2185 | ē: 'e', |
| 2186 | Ĕ: 'E', |
| 2187 | ĕ: 'e', |
| 2188 | Ė: 'E', |
| 2189 | ė: 'e', |
| 2190 | Ę: 'E', |
| 2191 | ę: 'e', |
| 2192 | Ě: 'E', |
| 2193 | ě: 'e', |
| 2194 | Ĝ: 'G', |
| 2195 | ĝ: 'g', |
| 2196 | Ğ: 'G', |
| 2197 | ğ: 'g', |
| 2198 | Ġ: 'G', |
| 2199 | ġ: 'g', |
| 2200 | Ģ: 'G', |
| 2201 | ģ: 'g', |
| 2202 | Ĥ: 'H', |
| 2203 | ĥ: 'h', |
| 2204 | Ħ: 'H', |
| 2205 | ħ: 'h', |
| 2206 | Ĩ: 'I', |
| 2207 | ĩ: 'i', |
| 2208 | Ī: 'I', |
| 2209 | ī: 'i', |
| 2210 | Ĭ: 'I', |
| 2211 | ĭ: 'i', |
| 2212 | Į: 'I', |
| 2213 | į: 'i', |
| 2214 | İ: 'I', |
| 2215 | ı: 'i', |
| 2216 | IJ: 'IJ', |
| 2217 | ij: 'ij', |
| 2218 | Ĵ: 'J', |
| 2219 | ĵ: 'j', |
| 2220 | Ķ: 'K', |
| 2221 | ķ: 'k', |
| 2222 | Ĺ: 'L', |
| 2223 | ĺ: 'l', |
| 2224 | Ļ: 'L', |
| 2225 | ļ: 'l', |
| 2226 | Ľ: 'L', |
| 2227 | ľ: 'l', |
| 2228 | Ŀ: 'L', |
| 2229 | ŀ: 'l', |
| 2230 | Ł: 'l', |
| 2231 | ł: 'l', |
| 2232 | Ń: 'N', |
| 2233 | ń: 'n', |
| 2234 | � |
| 2235 | : 'N', |
| 2236 | ņ: 'n', |
| 2237 | Ň: 'N', |
| 2238 | ň: 'n', |
| 2239 | ʼn: 'n', |
| 2240 | Ō: 'O', |
| 2241 | ō: 'o', |
| 2242 | Ŏ: 'O', |
| 2243 | ŏ: 'o', |
| 2244 | Ő: 'O', |
| 2245 | ő: 'o', |
| 2246 | Œ: 'OE', |
| 2247 | œ: 'oe', |
| 2248 | Ŕ: 'R', |
| 2249 | ŕ: 'r', |
| 2250 | Ŗ: 'R', |
| 2251 | ŗ: 'r', |
| 2252 | Ř: 'R', |
| 2253 | ř: 'r', |
| 2254 | Ś: 'S', |
| 2255 | ś: 's', |
| 2256 | Ŝ: 'S', |
| 2257 | ŝ: 's', |
| 2258 | Ş: 'S', |
| 2259 | ş: 's', |
| 2260 | Š: 'S', |
| 2261 | š: 's', |
| 2262 | Ţ: 'T', |
| 2263 | ţ: 't', |
| 2264 | Ť: 'T', |
| 2265 | ť: 't', |
| 2266 | Ŧ: 'T', |
| 2267 | ŧ: 't', |
| 2268 | Ũ: 'U', |
| 2269 | ũ: 'u', |
| 2270 | Ū: 'U', |
| 2271 | ū: 'u', |
| 2272 | Ŭ: 'U', |
| 2273 | ŭ: 'u', |
| 2274 | Ů: 'U', |
| 2275 | ů: 'u', |
| 2276 | Ű: 'U', |
| 2277 | ű: 'u', |
| 2278 | Ų: 'U', |
| 2279 | ų: 'u', |
| 2280 | Ŵ: 'W', |
| 2281 | ŵ: 'w', |
| 2282 | Ŷ: 'Y', |
| 2283 | ŷ: 'y', |
| 2284 | Ÿ: 'Y', |
| 2285 | Ź: 'Z', |
| 2286 | ź: 'z', |
| 2287 | Ż: 'Z', |
| 2288 | ż: 'z', |
| 2289 | Ž: 'Z', |
| 2290 | ž: 'z', |
| 2291 | ſ: 's', |
| 2292 | ƒ: 'f', |
| 2293 | Ơ: 'O', |
| 2294 | ơ: 'o', |
| 2295 | Ư: 'U', |
| 2296 | ư: 'u', |
| 2297 | Ǎ: 'A', |
| 2298 | ǎ: 'a', |
| 2299 | Ǐ: 'I', |
| 2300 | ǐ: 'i', |
| 2301 | Ǒ: 'O', |
| 2302 | ǒ: 'o', |
| 2303 | Ǔ: 'U', |
| 2304 | ǔ: 'u', |
| 2305 | Ǖ: 'U', |
| 2306 | ǖ: 'u', |
| 2307 | Ǘ: 'U', |
| 2308 | ǘ: 'u', |
| 2309 | Ǚ: 'U', |
| 2310 | ǚ: 'u', |
| 2311 | Ǜ: 'U', |
| 2312 | ǜ: 'u', |
| 2313 | Ǻ: 'A', |
| 2314 | ǻ: 'a', |
| 2315 | Ǽ: 'AE', |
| 2316 | ǽ: 'ae', |
| 2317 | Ǿ: 'O', |
| 2318 | ǿ: 'o', |
| 2319 | // extra |
| 2320 | ' ': '_', |
| 2321 | "'": '', |
| 2322 | '?': '', |
| 2323 | '/': '', |
| 2324 | '\\': '', |
| 2325 | '.': '', |
| 2326 | ',': '', |
| 2327 | '`': '', |
| 2328 | '>': '', |
| 2329 | '<': '', |
| 2330 | '"': '', |
| 2331 | '[': '', |
| 2332 | ']': '', |
| 2333 | '|': '', |
| 2334 | '{': '', |
| 2335 | '}': '', |
| 2336 | '(': '', |
| 2337 | ')': '' |
| 2338 | }; |
| 2339 | |
| 2340 | // vars |
| 2341 | var nonWord = /\W/g; |
| 2342 | var mapping = function (c) { |
| 2343 | return map[c] !== undefined ? map[c] : c; |
| 2344 | }; |
| 2345 | |
| 2346 | // replace |
| 2347 | str = str.replace(nonWord, mapping); |
| 2348 | |
| 2349 | // lowercase |
| 2350 | if (toLowerCase) { |
| 2351 | str = str.toLowerCase(); |
| 2352 | } |
| 2353 | |
| 2354 | // return |
| 2355 | return str; |
| 2356 | }; |
| 2357 | |
| 2358 | /** |
| 2359 | * acf.strMatch |
| 2360 | * |
| 2361 | * Returns the number of characters that match between two strings |
| 2362 | * |
| 2363 | * @date 1/2/18 |
| 2364 | * @since ACF 5.6.5 |
| 2365 | * |
| 2366 | * @param type $var Description. Default. |
| 2367 | * @return type Description. |
| 2368 | */ |
| 2369 | |
| 2370 | acf.strMatch = function (s1, s2) { |
| 2371 | // vars |
| 2372 | var val = 0; |
| 2373 | var min = Math.min(s1.length, s2.length); |
| 2374 | |
| 2375 | // loop |
| 2376 | for (var i = 0; i < min; i++) { |
| 2377 | if (s1[i] !== s2[i]) { |
| 2378 | break; |
| 2379 | } |
| 2380 | val++; |
| 2381 | } |
| 2382 | |
| 2383 | // return |
| 2384 | return val; |
| 2385 | }; |
| 2386 | |
| 2387 | /** |
| 2388 | * Escapes HTML entities from a string. |
| 2389 | * |
| 2390 | * @date 08/06/2020 |
| 2391 | * @since ACF 5.9.0 |
| 2392 | * |
| 2393 | * @param string string The input string. |
| 2394 | * @return string |
| 2395 | */ |
| 2396 | acf.strEscape = function (string) { |
| 2397 | var htmlEscapes = { |
| 2398 | '&': '&', |
| 2399 | '<': '<', |
| 2400 | '>': '>', |
| 2401 | '"': '"', |
| 2402 | "'": ''' |
| 2403 | }; |
| 2404 | return ('' + string).replace(/[&<>"']/g, function (chr) { |
| 2405 | return htmlEscapes[chr]; |
| 2406 | }); |
| 2407 | }; |
| 2408 | |
| 2409 | // Tests. |
| 2410 | //console.log( acf.strEscape('Test 1') ); |
| 2411 | //console.log( acf.strEscape('Test & 1') ); |
| 2412 | //console.log( acf.strEscape('Test\'s & 1') ); |
| 2413 | //console.log( acf.strEscape('<script>js</script>') ); |
| 2414 | |
| 2415 | /** |
| 2416 | * Unescapes HTML entities from a string. |
| 2417 | * |
| 2418 | * @date 08/06/2020 |
| 2419 | * @since ACF 5.9.0 |
| 2420 | * |
| 2421 | * @param string string The input string. |
| 2422 | * @return string |
| 2423 | */ |
| 2424 | acf.strUnescape = function (string) { |
| 2425 | var htmlUnescapes = { |
| 2426 | '&': '&', |
| 2427 | '<': '<', |
| 2428 | '>': '>', |
| 2429 | '"': '"', |
| 2430 | ''': "'" |
| 2431 | }; |
| 2432 | return ('' + string).replace(/&|<|>|"|'/g, function (entity) { |
| 2433 | return htmlUnescapes[entity]; |
| 2434 | }); |
| 2435 | }; |
| 2436 | |
| 2437 | // Tests. |
| 2438 | //console.log( acf.strUnescape( acf.strEscape('Test 1') ) ); |
| 2439 | //console.log( acf.strUnescape( acf.strEscape('Test & 1') ) ); |
| 2440 | //console.log( acf.strUnescape( acf.strEscape('Test\'s & 1') ) ); |
| 2441 | //console.log( acf.strUnescape( acf.strEscape('<script>js</script>') ) ); |
| 2442 | |
| 2443 | /** |
| 2444 | * Escapes HTML entities from a string. |
| 2445 | * |
| 2446 | * @date 08/06/2020 |
| 2447 | * @since ACF 5.9.0 |
| 2448 | * |
| 2449 | * @param string string The input string. |
| 2450 | * @return string |
| 2451 | */ |
| 2452 | acf.escAttr = acf.strEscape; |
| 2453 | |
| 2454 | /** |
| 2455 | * Encodes <script> tags for safe HTML output. |
| 2456 | * |
| 2457 | * @date 08/06/2020 |
| 2458 | * @since ACF 5.9.0 |
| 2459 | * |
| 2460 | * @param string string The input string. |
| 2461 | * @return string |
| 2462 | */ |
| 2463 | acf.escHtml = function (string) { |
| 2464 | return ('' + string).replace(/<script|<\/script/g, function (html) { |
| 2465 | return acf.strEscape(html); |
| 2466 | }); |
| 2467 | }; |
| 2468 | |
| 2469 | // Tests. |
| 2470 | //console.log( acf.escHtml('<script>js</script>') ); |
| 2471 | //console.log( acf.escHtml( acf.strEscape('<script>js</script>') ) ); |
| 2472 | //console.log( acf.escHtml( '<script>js1</script><script>js2</script>' ) ); |
| 2473 | |
| 2474 | /** |
| 2475 | * Encode a string potentially containing HTML into it's HTML entities equivalent. |
| 2476 | * |
| 2477 | * @since ACF 6.3.6 |
| 2478 | * |
| 2479 | * @param {string} string String to encode. |
| 2480 | * @return {string} The encoded string |
| 2481 | */ |
| 2482 | acf.encode = function (string) { |
| 2483 | return $('<textarea/>').text(string).html(); |
| 2484 | }; |
| 2485 | |
| 2486 | /** |
| 2487 | * Decode a HTML encoded string into it's original form. |
| 2488 | * |
| 2489 | * @since ACF 5.6.5 |
| 2490 | * |
| 2491 | * @param {string} string String to encode. |
| 2492 | * @return {string} The encoded string |
| 2493 | */ |
| 2494 | acf.decode = function (string) { |
| 2495 | return $('<textarea/>').html(string).text(); |
| 2496 | }; |
| 2497 | |
| 2498 | /** |
| 2499 | * parseArgs |
| 2500 | * |
| 2501 | * Merges together defaults and args much like the WP wp_parse_args function |
| 2502 | * |
| 2503 | * @date 14/12/17 |
| 2504 | * @since ACF 5.6.5 |
| 2505 | * |
| 2506 | * @param object args |
| 2507 | * @param object defaults |
| 2508 | * @return object |
| 2509 | */ |
| 2510 | |
| 2511 | acf.parseArgs = function (args, defaults) { |
| 2512 | if (typeof args !== 'object') args = {}; |
| 2513 | if (typeof defaults !== 'object') defaults = {}; |
| 2514 | return $.extend({}, defaults, args); |
| 2515 | }; |
| 2516 | |
| 2517 | /** |
| 2518 | * __ |
| 2519 | * |
| 2520 | * Retrieve the translation of $text. |
| 2521 | * |
| 2522 | * @date 16/4/18 |
| 2523 | * @since ACF 5.6.9 |
| 2524 | * |
| 2525 | * @param string text Text to translate. |
| 2526 | * @return string Translated text. |
| 2527 | */ |
| 2528 | |
| 2529 | if (window.acfL10n == undefined) { |
| 2530 | acfL10n = {}; |
| 2531 | } |
| 2532 | acf.__ = function (text) { |
| 2533 | return acfL10n[text] || text; |
| 2534 | }; |
| 2535 | |
| 2536 | /** |
| 2537 | * _x |
| 2538 | * |
| 2539 | * Retrieve translated string with gettext context. |
| 2540 | * |
| 2541 | * @date 16/4/18 |
| 2542 | * @since ACF 5.6.9 |
| 2543 | * |
| 2544 | * @param string text Text to translate. |
| 2545 | * @param string context Context information for the translators. |
| 2546 | * @return string Translated text. |
| 2547 | */ |
| 2548 | |
| 2549 | acf._x = function (text, context) { |
| 2550 | return acfL10n[text + '.' + context] || acfL10n[text] || text; |
| 2551 | }; |
| 2552 | |
| 2553 | /** |
| 2554 | * _n |
| 2555 | * |
| 2556 | * Retrieve the plural or single form based on the amount. |
| 2557 | * |
| 2558 | * @date 16/4/18 |
| 2559 | * @since ACF 5.6.9 |
| 2560 | * |
| 2561 | * @param string single Single text to translate. |
| 2562 | * @param string plural Plural text to translate. |
| 2563 | * @param int number The number to compare against. |
| 2564 | * @return string Translated text. |
| 2565 | */ |
| 2566 | |
| 2567 | acf._n = function (single, plural, number) { |
| 2568 | if (number == 1) { |
| 2569 | return acf.__(single); |
| 2570 | } else { |
| 2571 | return acf.__(plural); |
| 2572 | } |
| 2573 | }; |
| 2574 | acf.isArray = function (a) { |
| 2575 | return Array.isArray(a); |
| 2576 | }; |
| 2577 | acf.isObject = function (a) { |
| 2578 | return typeof a === 'object'; |
| 2579 | }; |
| 2580 | |
| 2581 | /** |
| 2582 | * serialize |
| 2583 | * |
| 2584 | * description |
| 2585 | * |
| 2586 | * @date 24/12/17 |
| 2587 | * @since ACF 5.6.5 |
| 2588 | * |
| 2589 | * @param type $var Description. Default. |
| 2590 | * @return type Description. |
| 2591 | */ |
| 2592 | |
| 2593 | var buildObject = function (obj, name, value) { |
| 2594 | // replace [] with placeholder |
| 2595 | name = name.replace('[]', '[%%index%%]'); |
| 2596 | |
| 2597 | // vars |
| 2598 | var keys = name.match(/([^\[\]])+/g); |
| 2599 | if (!keys) return; |
| 2600 | var length = keys.length; |
| 2601 | var ref = obj; |
| 2602 | |
| 2603 | // loop |
| 2604 | for (var i = 0; i < length; i++) { |
| 2605 | // vars |
| 2606 | var key = String(keys[i]); |
| 2607 | |
| 2608 | // value |
| 2609 | if (i == length - 1) { |
| 2610 | // %%index%% |
| 2611 | if (key === '%%index%%') { |
| 2612 | ref.push(value); |
| 2613 | |
| 2614 | // default |
| 2615 | } else { |
| 2616 | ref[key] = value; |
| 2617 | } |
| 2618 | |
| 2619 | // path |
| 2620 | } else { |
| 2621 | // array |
| 2622 | if (keys[i + 1] === '%%index%%') { |
| 2623 | if (!acf.isArray(ref[key])) { |
| 2624 | ref[key] = []; |
| 2625 | } |
| 2626 | |
| 2627 | // object |
| 2628 | } else { |
| 2629 | if (!acf.isObject(ref[key])) { |
| 2630 | ref[key] = {}; |
| 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | // crawl |
| 2635 | ref = ref[key]; |
| 2636 | } |
| 2637 | } |
| 2638 | }; |
| 2639 | acf.serialize = function ($el, prefix) { |
| 2640 | // vars |
| 2641 | var obj = {}; |
| 2642 | var inputs = acf.serializeArray($el); |
| 2643 | |
| 2644 | // prefix |
| 2645 | if (prefix !== undefined) { |
| 2646 | // filter and modify |
| 2647 | inputs = inputs.filter(function (item) { |
| 2648 | return item.name.indexOf(prefix) === 0; |
| 2649 | }).map(function (item) { |
| 2650 | item.name = item.name.slice(prefix.length); |
| 2651 | return item; |
| 2652 | }); |
| 2653 | } |
| 2654 | |
| 2655 | // loop |
| 2656 | for (var i = 0; i < inputs.length; i++) { |
| 2657 | buildObject(obj, inputs[i].name, inputs[i].value); |
| 2658 | } |
| 2659 | |
| 2660 | // return |
| 2661 | return obj; |
| 2662 | }; |
| 2663 | |
| 2664 | /** |
| 2665 | * acf.serializeArray |
| 2666 | * |
| 2667 | * Similar to $.serializeArray() but works with a parent wrapping element. |
| 2668 | * |
| 2669 | * @date 19/8/18 |
| 2670 | * @since ACF 5.7.3 |
| 2671 | * |
| 2672 | * @param jQuery $el The element or form to serialize. |
| 2673 | * @return array |
| 2674 | */ |
| 2675 | |
| 2676 | acf.serializeArray = function ($el) { |
| 2677 | return $el.find('select, textarea, input').serializeArray(); |
| 2678 | }; |
| 2679 | |
| 2680 | /** |
| 2681 | * acf.serializeForAjax |
| 2682 | * |
| 2683 | * Returns an object containing name => value data ready to be encoded for Ajax. |
| 2684 | * |
| 2685 | * @date 17/12/18 |
| 2686 | * @since ACF 5.8.0 |
| 2687 | * |
| 2688 | * @param jQUery $el The element or form to serialize. |
| 2689 | * @return object |
| 2690 | */ |
| 2691 | acf.serializeForAjax = function ($el) { |
| 2692 | // vars |
| 2693 | var data = {}; |
| 2694 | var index = {}; |
| 2695 | |
| 2696 | // Serialize inputs. |
| 2697 | var inputs = acf.serializeArray($el); |
| 2698 | |
| 2699 | // Loop over inputs and build data. |
| 2700 | inputs.map(function (item) { |
| 2701 | // Append to array. |
| 2702 | if (item.name.slice(-2) === '[]') { |
| 2703 | data[item.name] = data[item.name] || []; |
| 2704 | data[item.name].push(item.value); |
| 2705 | // Append |
| 2706 | } else { |
| 2707 | data[item.name] = item.value; |
| 2708 | } |
| 2709 | }); |
| 2710 | |
| 2711 | // return |
| 2712 | return data; |
| 2713 | }; |
| 2714 | |
| 2715 | /** |
| 2716 | * addAction |
| 2717 | * |
| 2718 | * Wrapper for acf.hooks.addAction |
| 2719 | * |
| 2720 | * @date 14/12/17 |
| 2721 | * @since ACF 5.6.5 |
| 2722 | * |
| 2723 | * @param n/a |
| 2724 | * @return this |
| 2725 | */ |
| 2726 | |
| 2727 | /* |
| 2728 | var prefixAction = function( action ){ |
| 2729 | return 'acf_' + action; |
| 2730 | } |
| 2731 | */ |
| 2732 | |
| 2733 | acf.addAction = function (action, callback, priority, context) { |
| 2734 | //action = prefixAction(action); |
| 2735 | acf.hooks.addAction.apply(this, arguments); |
| 2736 | return this; |
| 2737 | }; |
| 2738 | |
| 2739 | /** |
| 2740 | * removeAction |
| 2741 | * |
| 2742 | * Wrapper for acf.hooks.removeAction |
| 2743 | * |
| 2744 | * @date 14/12/17 |
| 2745 | * @since ACF 5.6.5 |
| 2746 | * |
| 2747 | * @param n/a |
| 2748 | * @return this |
| 2749 | */ |
| 2750 | |
| 2751 | acf.removeAction = function (action, callback) { |
| 2752 | //action = prefixAction(action); |
| 2753 | acf.hooks.removeAction.apply(this, arguments); |
| 2754 | return this; |
| 2755 | }; |
| 2756 | |
| 2757 | /** |
| 2758 | * doAction |
| 2759 | * |
| 2760 | * Wrapper for acf.hooks.doAction |
| 2761 | * |
| 2762 | * @date 14/12/17 |
| 2763 | * @since ACF 5.6.5 |
| 2764 | * |
| 2765 | * @param n/a |
| 2766 | * @return this |
| 2767 | */ |
| 2768 | |
| 2769 | var actionHistory = {}; |
| 2770 | //var currentAction = false; |
| 2771 | acf.doAction = function (action) { |
| 2772 | //action = prefixAction(action); |
| 2773 | //currentAction = action; |
| 2774 | actionHistory[action] = 1; |
| 2775 | acf.hooks.doAction.apply(this, arguments); |
| 2776 | actionHistory[action] = 0; |
| 2777 | return this; |
| 2778 | }; |
| 2779 | |
| 2780 | /** |
| 2781 | * doingAction |
| 2782 | * |
| 2783 | * Return true if doing action |
| 2784 | * |
| 2785 | * @date 14/12/17 |
| 2786 | * @since ACF 5.6.5 |
| 2787 | * |
| 2788 | * @param n/a |
| 2789 | * @return this |
| 2790 | */ |
| 2791 | |
| 2792 | acf.doingAction = function (action) { |
| 2793 | //action = prefixAction(action); |
| 2794 | return actionHistory[action] === 1; |
| 2795 | }; |
| 2796 | |
| 2797 | /** |
| 2798 | * didAction |
| 2799 | * |
| 2800 | * Wrapper for acf.hooks.doAction |
| 2801 | * |
| 2802 | * @date 14/12/17 |
| 2803 | * @since ACF 5.6.5 |
| 2804 | * |
| 2805 | * @param n/a |
| 2806 | * @return this |
| 2807 | */ |
| 2808 | |
| 2809 | acf.didAction = function (action) { |
| 2810 | //action = prefixAction(action); |
| 2811 | return actionHistory[action] !== undefined; |
| 2812 | }; |
| 2813 | |
| 2814 | /** |
| 2815 | * currentAction |
| 2816 | * |
| 2817 | * Wrapper for acf.hooks.doAction |
| 2818 | * |
| 2819 | * @date 14/12/17 |
| 2820 | * @since ACF 5.6.5 |
| 2821 | * |
| 2822 | * @param n/a |
| 2823 | * @return this |
| 2824 | */ |
| 2825 | |
| 2826 | acf.currentAction = function () { |
| 2827 | for (var k in actionHistory) { |
| 2828 | if (actionHistory[k]) { |
| 2829 | return k; |
| 2830 | } |
| 2831 | } |
| 2832 | return false; |
| 2833 | }; |
| 2834 | |
| 2835 | /** |
| 2836 | * addFilter |
| 2837 | * |
| 2838 | * Wrapper for acf.hooks.addFilter |
| 2839 | * |
| 2840 | * @date 14/12/17 |
| 2841 | * @since ACF 5.6.5 |
| 2842 | * |
| 2843 | * @param n/a |
| 2844 | * @return this |
| 2845 | */ |
| 2846 | |
| 2847 | acf.addFilter = function (action) { |
| 2848 | //action = prefixAction(action); |
| 2849 | acf.hooks.addFilter.apply(this, arguments); |
| 2850 | return this; |
| 2851 | }; |
| 2852 | |
| 2853 | /** |
| 2854 | * removeFilter |
| 2855 | * |
| 2856 | * Wrapper for acf.hooks.removeFilter |
| 2857 | * |
| 2858 | * @date 14/12/17 |
| 2859 | * @since ACF 5.6.5 |
| 2860 | * |
| 2861 | * @param n/a |
| 2862 | * @return this |
| 2863 | */ |
| 2864 | |
| 2865 | acf.removeFilter = function (action) { |
| 2866 | //action = prefixAction(action); |
| 2867 | acf.hooks.removeFilter.apply(this, arguments); |
| 2868 | return this; |
| 2869 | }; |
| 2870 | |
| 2871 | /** |
| 2872 | * applyFilters |
| 2873 | * |
| 2874 | * Wrapper for acf.hooks.applyFilters |
| 2875 | * |
| 2876 | * @date 14/12/17 |
| 2877 | * @since ACF 5.6.5 |
| 2878 | * |
| 2879 | * @param n/a |
| 2880 | * @return this |
| 2881 | */ |
| 2882 | |
| 2883 | acf.applyFilters = function (action) { |
| 2884 | //action = prefixAction(action); |
| 2885 | return acf.hooks.applyFilters.apply(this, arguments); |
| 2886 | }; |
| 2887 | |
| 2888 | /** |
| 2889 | * getArgs |
| 2890 | * |
| 2891 | * description |
| 2892 | * |
| 2893 | * @date 15/12/17 |
| 2894 | * @since ACF 5.6.5 |
| 2895 | * |
| 2896 | * @param type $var Description. Default. |
| 2897 | * @return type Description. |
| 2898 | */ |
| 2899 | |
| 2900 | acf.arrayArgs = function (args) { |
| 2901 | return Array.prototype.slice.call(args); |
| 2902 | }; |
| 2903 | |
| 2904 | /** |
| 2905 | * extendArgs |
| 2906 | * |
| 2907 | * description |
| 2908 | * |
| 2909 | * @date 15/12/17 |
| 2910 | * @since ACF 5.6.5 |
| 2911 | * |
| 2912 | * @param type $var Description. Default. |
| 2913 | * @return type Description. |
| 2914 | */ |
| 2915 | |
| 2916 | /* |
| 2917 | acf.extendArgs = function( ){ |
| 2918 | var args = Array.prototype.slice.call( arguments ); |
| 2919 | var realArgs = args.shift(); |
| 2920 | |
| 2921 | Array.prototype.push.call(arguments, 'bar') |
| 2922 | return Array.prototype.push.apply( args, arguments ); |
| 2923 | }; |
| 2924 | */ |
| 2925 | |
| 2926 | // Preferences |
| 2927 | // - use try/catch to avoid JS error if cookies are disabled on front-end form |
| 2928 | try { |
| 2929 | var preferences = JSON.parse(localStorage.getItem('acf')) || {}; |
| 2930 | } catch (e) { |
| 2931 | var preferences = {}; |
| 2932 | } |
| 2933 | |
| 2934 | /** |
| 2935 | * getPreferenceName |
| 2936 | * |
| 2937 | * Gets the true preference name. |
| 2938 | * Converts "this.thing" to "thing-123" if editing post 123. |
| 2939 | * |
| 2940 | * @date 11/11/17 |
| 2941 | * @since ACF 5.6.5 |
| 2942 | * |
| 2943 | * @param string name |
| 2944 | * @return string |
| 2945 | */ |
| 2946 | |
| 2947 | var getPreferenceName = function (name) { |
| 2948 | if (name.substr(0, 5) === 'this.') { |
| 2949 | name = name.substr(5) + '-' + acf.get('post_id'); |
| 2950 | } |
| 2951 | return name; |
| 2952 | }; |
| 2953 | |
| 2954 | /** |
| 2955 | * acf.getPreference |
| 2956 | * |
| 2957 | * Gets a preference setting or null if not set. |
| 2958 | * |
| 2959 | * @date 11/11/17 |
| 2960 | * @since ACF 5.6.5 |
| 2961 | * |
| 2962 | * @param string name |
| 2963 | * @return mixed |
| 2964 | */ |
| 2965 | |
| 2966 | acf.getPreference = function (name) { |
| 2967 | name = getPreferenceName(name); |
| 2968 | return preferences[name] || null; |
| 2969 | }; |
| 2970 | |
| 2971 | /** |
| 2972 | * acf.setPreference |
| 2973 | * |
| 2974 | * Sets a preference setting. |
| 2975 | * |
| 2976 | * @date 11/11/17 |
| 2977 | * @since ACF 5.6.5 |
| 2978 | * |
| 2979 | * @param string name |
| 2980 | * @param mixed value |
| 2981 | * @return n/a |
| 2982 | */ |
| 2983 | |
| 2984 | acf.setPreference = function (name, value) { |
| 2985 | name = getPreferenceName(name); |
| 2986 | if (value === null) { |
| 2987 | delete preferences[name]; |
| 2988 | } else { |
| 2989 | preferences[name] = value; |
| 2990 | } |
| 2991 | localStorage.setItem('acf', JSON.stringify(preferences)); |
| 2992 | }; |
| 2993 | |
| 2994 | /** |
| 2995 | * acf.removePreference |
| 2996 | * |
| 2997 | * Removes a preference setting. |
| 2998 | * |
| 2999 | * @date 11/11/17 |
| 3000 | * @since ACF 5.6.5 |
| 3001 | * |
| 3002 | * @param string name |
| 3003 | * @return n/a |
| 3004 | */ |
| 3005 | |
| 3006 | acf.removePreference = function (name) { |
| 3007 | acf.setPreference(name, null); |
| 3008 | }; |
| 3009 | |
| 3010 | /** |
| 3011 | * remove |
| 3012 | * |
| 3013 | * Removes an element with fade effect |
| 3014 | * |
| 3015 | * @date 1/1/18 |
| 3016 | * @since ACF 5.6.5 |
| 3017 | * |
| 3018 | * @param type $var Description. Default. |
| 3019 | * @return type Description. |
| 3020 | */ |
| 3021 | |
| 3022 | acf.remove = function (props) { |
| 3023 | // allow jQuery |
| 3024 | if (props instanceof jQuery) { |
| 3025 | props = { |
| 3026 | target: props |
| 3027 | }; |
| 3028 | } |
| 3029 | |
| 3030 | // defaults |
| 3031 | props = acf.parseArgs(props, { |
| 3032 | target: false, |
| 3033 | endHeight: 0, |
| 3034 | complete: function () {} |
| 3035 | }); |
| 3036 | |
| 3037 | // action |
| 3038 | acf.doAction('remove', props.target); |
| 3039 | |
| 3040 | // tr |
| 3041 | if (props.target.is('tr')) { |
| 3042 | removeTr(props); |
| 3043 | |
| 3044 | // div |
| 3045 | } else { |
| 3046 | removeDiv(props); |
| 3047 | } |
| 3048 | }; |
| 3049 | |
| 3050 | /** |
| 3051 | * removeDiv |
| 3052 | * |
| 3053 | * description |
| 3054 | * |
| 3055 | * @date 16/2/18 |
| 3056 | * @since ACF 5.6.9 |
| 3057 | * |
| 3058 | * @param type $var Description. Default. |
| 3059 | * @return type Description. |
| 3060 | */ |
| 3061 | |
| 3062 | var removeDiv = function (props) { |
| 3063 | // vars |
| 3064 | var $el = props.target; |
| 3065 | var height = $el.height(); |
| 3066 | var width = $el.width(); |
| 3067 | var margin = $el.css('margin'); |
| 3068 | var outerHeight = $el.outerHeight(true); |
| 3069 | var style = $el.attr('style') + ''; // needed to copy |
| 3070 | |
| 3071 | // wrap |
| 3072 | $el.wrap('<div class="acf-temp-remove" style="height:' + outerHeight + 'px"></div>'); |
| 3073 | var $wrap = $el.parent(); |
| 3074 | |
| 3075 | // set pos |
| 3076 | $el.css({ |
| 3077 | height: height, |
| 3078 | width: width, |
| 3079 | margin: margin, |
| 3080 | position: 'absolute' |
| 3081 | }); |
| 3082 | |
| 3083 | // fade wrap |
| 3084 | setTimeout(function () { |
| 3085 | $wrap.css({ |
| 3086 | opacity: 0, |
| 3087 | height: props.endHeight |
| 3088 | }); |
| 3089 | }, 50); |
| 3090 | |
| 3091 | // remove |
| 3092 | setTimeout(function () { |
| 3093 | $el.attr('style', style); |
| 3094 | $wrap.remove(); |
| 3095 | props.complete(); |
| 3096 | }, 301); |
| 3097 | }; |
| 3098 | |
| 3099 | /** |
| 3100 | * removeTr |
| 3101 | * |
| 3102 | * description |
| 3103 | * |
| 3104 | * @date 16/2/18 |
| 3105 | * @since ACF 5.6.9 |
| 3106 | * |
| 3107 | * @param type $var Description. Default. |
| 3108 | * @return type Description. |
| 3109 | */ |
| 3110 | |
| 3111 | var removeTr = function (props) { |
| 3112 | // vars |
| 3113 | var $tr = props.target; |
| 3114 | var height = $tr.height(); |
| 3115 | var children = $tr.children().length; |
| 3116 | |
| 3117 | // create dummy td |
| 3118 | var $td = $('<td class="acf-temp-remove" style="padding:0; height:' + height + 'px" colspan="' + children + '"></td>'); |
| 3119 | |
| 3120 | // fade away tr |
| 3121 | $tr.addClass('acf-remove-element'); |
| 3122 | |
| 3123 | // update HTML after fade animation |
| 3124 | setTimeout(function () { |
| 3125 | $tr.html($td); |
| 3126 | }, 251); |
| 3127 | |
| 3128 | // allow .acf-temp-remove to exist before changing CSS |
| 3129 | setTimeout(function () { |
| 3130 | // remove class |
| 3131 | $tr.removeClass('acf-remove-element'); |
| 3132 | |
| 3133 | // collapse |
| 3134 | $td.css({ |
| 3135 | height: props.endHeight |
| 3136 | }); |
| 3137 | }, 300); |
| 3138 | |
| 3139 | // remove |
| 3140 | setTimeout(function () { |
| 3141 | $tr.remove(); |
| 3142 | props.complete(); |
| 3143 | }, 451); |
| 3144 | }; |
| 3145 | |
| 3146 | /** |
| 3147 | * duplicate |
| 3148 | * |
| 3149 | * description |
| 3150 | * |
| 3151 | * @date 3/1/18 |
| 3152 | * @since ACF 5.6.5 |
| 3153 | * |
| 3154 | * @param type $var Description. Default. |
| 3155 | * @return type Description. |
| 3156 | */ |
| 3157 | |
| 3158 | acf.duplicate = function (args) { |
| 3159 | // allow jQuery |
| 3160 | if (args instanceof jQuery) { |
| 3161 | args = { |
| 3162 | target: args |
| 3163 | }; |
| 3164 | } |
| 3165 | |
| 3166 | // defaults |
| 3167 | args = acf.parseArgs(args, { |
| 3168 | target: false, |
| 3169 | search: '', |
| 3170 | replace: '', |
| 3171 | rename: true, |
| 3172 | before: function ($el) {}, |
| 3173 | after: function ($el, $el2) {}, |
| 3174 | append: function ($el, $el2) { |
| 3175 | $el.after($el2); |
| 3176 | } |
| 3177 | }); |
| 3178 | |
| 3179 | // compatibility |
| 3180 | args.target = args.target || args.$el; |
| 3181 | |
| 3182 | // vars |
| 3183 | var $el = args.target; |
| 3184 | |
| 3185 | // search |
| 3186 | args.search = args.search || $el.attr('data-id'); |
| 3187 | args.replace = args.replace || acf.uniqid(); |
| 3188 | |
| 3189 | // before |
| 3190 | // - allow acf to modify DOM |
| 3191 | // - fixes bug where select field option is not selected |
| 3192 | args.before($el); |
| 3193 | acf.doAction('before_duplicate', $el); |
| 3194 | |
| 3195 | // clone |
| 3196 | var $el2 = $el.clone(); |
| 3197 | |
| 3198 | // rename |
| 3199 | if (args.rename) { |
| 3200 | acf.rename({ |
| 3201 | target: $el2, |
| 3202 | search: args.search, |
| 3203 | replace: args.replace, |
| 3204 | replacer: typeof args.rename === 'function' ? args.rename : null |
| 3205 | }); |
| 3206 | } |
| 3207 | |
| 3208 | // remove classes |
| 3209 | $el2.removeClass('acf-clone'); |
| 3210 | $el2.find('.ui-sortable').removeClass('ui-sortable'); |
| 3211 | |
| 3212 | // remove any initialised select2s prevent the duplicated object stealing the previous select2. |
| 3213 | $el2.find('[data-select2-id]').removeAttr('data-select2-id'); |
| 3214 | $el2.find('.select2').remove(); |
| 3215 | |
| 3216 | // subfield select2 renames happen after init and contain a duplicated ID. force change those IDs to prevent this. |
| 3217 | $el2.find('.acf-is-subfields select[data-ui="1"]').each(function () { |
| 3218 | $(this).prop('id', $(this).prop('id').replace('acf_fields', acf.uniqid('duplicated_') + '_acf_fields')); |
| 3219 | }); |
| 3220 | |
| 3221 | // remove tab wrapper to ensure proper init |
| 3222 | $el2.find('.acf-field-settings > .acf-tab-wrap').remove(); |
| 3223 | |
| 3224 | // after |
| 3225 | // - allow acf to modify DOM |
| 3226 | args.after($el, $el2); |
| 3227 | acf.doAction('after_duplicate', $el, $el2); |
| 3228 | |
| 3229 | // append |
| 3230 | args.append($el, $el2); |
| 3231 | |
| 3232 | /** |
| 3233 | * Fires after an element has been duplicated and appended to the DOM. |
| 3234 | * |
| 3235 | * @date 30/10/19 |
| 3236 | * @since ACF 5.8.7 |
| 3237 | * |
| 3238 | * @param jQuery $el The original element. |
| 3239 | * @param jQuery $el2 The duplicated element. |
| 3240 | */ |
| 3241 | acf.doAction('duplicate', $el, $el2); |
| 3242 | |
| 3243 | // append |
| 3244 | acf.doAction('append', $el2); |
| 3245 | |
| 3246 | // return |
| 3247 | return $el2; |
| 3248 | }; |
| 3249 | |
| 3250 | /** |
| 3251 | * rename |
| 3252 | * |
| 3253 | * description |
| 3254 | * |
| 3255 | * @date 7/1/18 |
| 3256 | * @since ACF 5.6.5 |
| 3257 | * |
| 3258 | * @param type $var Description. Default. |
| 3259 | * @return type Description. |
| 3260 | */ |
| 3261 | |
| 3262 | acf.rename = function (args) { |
| 3263 | // Allow jQuery param. |
| 3264 | if (args instanceof jQuery) { |
| 3265 | args = { |
| 3266 | target: args |
| 3267 | }; |
| 3268 | } |
| 3269 | |
| 3270 | // Apply default args. |
| 3271 | args = acf.parseArgs(args, { |
| 3272 | target: false, |
| 3273 | destructive: false, |
| 3274 | search: '', |
| 3275 | replace: '', |
| 3276 | replacer: null |
| 3277 | }); |
| 3278 | |
| 3279 | // Extract args. |
| 3280 | var $el = args.target; |
| 3281 | |
| 3282 | // Provide backup for empty args. |
| 3283 | if (!args.search) { |
| 3284 | args.search = $el.attr('data-id'); |
| 3285 | } |
| 3286 | if (!args.replace) { |
| 3287 | args.replace = acf.uniqid('acf'); |
| 3288 | } |
| 3289 | if (!args.replacer) { |
| 3290 | args.replacer = function (name, value, search, replace) { |
| 3291 | return value.replace(search, replace); |
| 3292 | }; |
| 3293 | } |
| 3294 | |
| 3295 | // Callback function for jQuery replacing. |
| 3296 | var withReplacer = function (name) { |
| 3297 | return function (i, value) { |
| 3298 | return args.replacer(name, value, args.search, args.replace); |
| 3299 | }; |
| 3300 | }; |
| 3301 | |
| 3302 | // Destructive Replace. |
| 3303 | if (args.destructive) { |
| 3304 | var html = acf.strReplace(args.search, args.replace, $el.outerHTML()); |
| 3305 | $el.replaceWith(html); |
| 3306 | |
| 3307 | // Standard Replace. |
| 3308 | } else { |
| 3309 | $el.attr('data-id', args.replace); |
| 3310 | $el.find('[id*="' + args.search + '"]').attr('id', withReplacer('id')); |
| 3311 | $el.find('[for*="' + args.search + '"]').attr('for', withReplacer('for')); |
| 3312 | $el.find('[name*="' + args.search + '"]').attr('name', withReplacer('name')); |
| 3313 | } |
| 3314 | |
| 3315 | // return |
| 3316 | return $el; |
| 3317 | }; |
| 3318 | |
| 3319 | /** |
| 3320 | * Prepares AJAX data prior to being sent. |
| 3321 | * |
| 3322 | * @since ACF 5.6.5 |
| 3323 | * |
| 3324 | * @param Object data The data to prepare |
| 3325 | * @param boolean use_global_nonce Should we ignore any nonce provided in the data object and force ACF's global nonce for this request |
| 3326 | * @return Object The prepared data. |
| 3327 | */ |
| 3328 | acf.prepareForAjax = function (data, use_global_nonce = false) { |
| 3329 | // Set a default nonce if we don't have one already. |
| 3330 | if (use_global_nonce || 'undefined' === typeof data.nonce) { |
| 3331 | data.nonce = acf.get('nonce'); |
| 3332 | } |
| 3333 | data.post_id = acf.get('post_id'); |
| 3334 | if (acf.has('language')) { |
| 3335 | data.lang = acf.get('language'); |
| 3336 | } |
| 3337 | |
| 3338 | // Filter for 3rd party customization. |
| 3339 | data = acf.applyFilters('prepare_for_ajax', data); |
| 3340 | return data; |
| 3341 | }; |
| 3342 | |
| 3343 | /** |
| 3344 | * acf.startButtonLoading |
| 3345 | * |
| 3346 | * description |
| 3347 | * |
| 3348 | * @date 5/1/18 |
| 3349 | * @since ACF 5.6.5 |
| 3350 | * |
| 3351 | * @param type $var Description. Default. |
| 3352 | * @return type Description. |
| 3353 | */ |
| 3354 | |
| 3355 | acf.startButtonLoading = function ($el) { |
| 3356 | $el.prop('disabled', true); |
| 3357 | $el.after(' <i class="acf-loading"></i>'); |
| 3358 | }; |
| 3359 | acf.stopButtonLoading = function ($el) { |
| 3360 | $el.prop('disabled', false); |
| 3361 | $el.next('.acf-loading').remove(); |
| 3362 | }; |
| 3363 | |
| 3364 | /** |
| 3365 | * acf.showLoading |
| 3366 | * |
| 3367 | * description |
| 3368 | * |
| 3369 | * @date 12/1/18 |
| 3370 | * @since ACF 5.6.5 |
| 3371 | * |
| 3372 | * @param type $var Description. Default. |
| 3373 | * @return type Description. |
| 3374 | */ |
| 3375 | |
| 3376 | acf.showLoading = function ($el) { |
| 3377 | $el.append('<div class="acf-loading-overlay"><i class="acf-loading"></i></div>'); |
| 3378 | }; |
| 3379 | acf.hideLoading = function ($el) { |
| 3380 | $el.children('.acf-loading-overlay').remove(); |
| 3381 | }; |
| 3382 | |
| 3383 | /** |
| 3384 | * acf.updateUserSetting |
| 3385 | * |
| 3386 | * description |
| 3387 | * |
| 3388 | * @date 5/1/18 |
| 3389 | * @since ACF 5.6.5 |
| 3390 | * |
| 3391 | * @param type $var Description. Default. |
| 3392 | * @return type Description. |
| 3393 | */ |
| 3394 | |
| 3395 | acf.updateUserSetting = function (name, value) { |
| 3396 | var ajaxData = { |
| 3397 | action: 'acf/ajax/user_setting', |
| 3398 | name: name, |
| 3399 | value: value |
| 3400 | }; |
| 3401 | $.ajax({ |
| 3402 | url: acf.get('ajaxurl'), |
| 3403 | data: acf.prepareForAjax(ajaxData), |
| 3404 | type: 'post', |
| 3405 | dataType: 'html' |
| 3406 | }); |
| 3407 | }; |
| 3408 | |
| 3409 | /** |
| 3410 | * acf.val |
| 3411 | * |
| 3412 | * description |
| 3413 | * |
| 3414 | * @date 8/1/18 |
| 3415 | * @since ACF 5.6.5 |
| 3416 | * |
| 3417 | * @param type $var Description. Default. |
| 3418 | * @return type Description. |
| 3419 | */ |
| 3420 | |
| 3421 | acf.val = function ($input, value, silent) { |
| 3422 | // vars |
| 3423 | var prevValue = $input.val(); |
| 3424 | |
| 3425 | // bail if no change |
| 3426 | if (value === prevValue) { |
| 3427 | return false; |
| 3428 | } |
| 3429 | |
| 3430 | // update value |
| 3431 | $input.val(value); |
| 3432 | |
| 3433 | // prevent select elements displaying blank value if option doesn't exist |
| 3434 | if ($input.is('select') && $input.val() === null) { |
| 3435 | $input.val(prevValue); |
| 3436 | return false; |
| 3437 | } |
| 3438 | |
| 3439 | // update with trigger |
| 3440 | if (silent !== true) { |
| 3441 | $input.trigger('change'); |
| 3442 | } |
| 3443 | |
| 3444 | // return |
| 3445 | return true; |
| 3446 | }; |
| 3447 | |
| 3448 | /** |
| 3449 | * acf.show |
| 3450 | * |
| 3451 | * description |
| 3452 | * |
| 3453 | * @date 9/2/18 |
| 3454 | * @since ACF 5.6.5 |
| 3455 | * |
| 3456 | * @param type $var Description. Default. |
| 3457 | * @return type Description. |
| 3458 | */ |
| 3459 | |
| 3460 | acf.show = function ($el, lockKey) { |
| 3461 | // unlock |
| 3462 | if (lockKey) { |
| 3463 | acf.unlock($el, 'hidden', lockKey); |
| 3464 | } |
| 3465 | |
| 3466 | // bail early if $el is still locked |
| 3467 | if (acf.isLocked($el, 'hidden')) { |
| 3468 | //console.log( 'still locked', getLocks( $el, 'hidden' )); |
| 3469 | return false; |
| 3470 | } |
| 3471 | |
| 3472 | // $el is hidden, remove class and return true due to change in visibility |
| 3473 | if ($el.hasClass('acf-hidden')) { |
| 3474 | $el.removeClass('acf-hidden'); |
| 3475 | return true; |
| 3476 | |
| 3477 | // $el is visible, return false due to no change in visibility |
| 3478 | } else { |
| 3479 | return false; |
| 3480 | } |
| 3481 | }; |
| 3482 | |
| 3483 | /** |
| 3484 | * acf.hide |
| 3485 | * |
| 3486 | * description |
| 3487 | * |
| 3488 | * @date 9/2/18 |
| 3489 | * @since ACF 5.6.5 |
| 3490 | * |
| 3491 | * @param type $var Description. Default. |
| 3492 | * @return type Description. |
| 3493 | */ |
| 3494 | |
| 3495 | acf.hide = function ($el, lockKey) { |
| 3496 | // lock |
| 3497 | if (lockKey) { |
| 3498 | acf.lock($el, 'hidden', lockKey); |
| 3499 | } |
| 3500 | |
| 3501 | // $el is hidden, return false due to no change in visibility |
| 3502 | if ($el.hasClass('acf-hidden')) { |
| 3503 | return false; |
| 3504 | |
| 3505 | // $el is visible, add class and return true due to change in visibility |
| 3506 | } else { |
| 3507 | $el.addClass('acf-hidden'); |
| 3508 | return true; |
| 3509 | } |
| 3510 | }; |
| 3511 | |
| 3512 | /** |
| 3513 | * acf.isHidden |
| 3514 | * |
| 3515 | * description |
| 3516 | * |
| 3517 | * @date 9/2/18 |
| 3518 | * @since ACF 5.6.5 |
| 3519 | * |
| 3520 | * @param type $var Description. Default. |
| 3521 | * @return type Description. |
| 3522 | */ |
| 3523 | |
| 3524 | acf.isHidden = function ($el) { |
| 3525 | return $el.hasClass('acf-hidden'); |
| 3526 | }; |
| 3527 | |
| 3528 | /** |
| 3529 | * acf.isVisible |
| 3530 | * |
| 3531 | * description |
| 3532 | * |
| 3533 | * @date 9/2/18 |
| 3534 | * @since ACF 5.6.5 |
| 3535 | * |
| 3536 | * @param type $var Description. Default. |
| 3537 | * @return type Description. |
| 3538 | */ |
| 3539 | |
| 3540 | acf.isVisible = function ($el) { |
| 3541 | return !acf.isHidden($el); |
| 3542 | }; |
| 3543 | |
| 3544 | /** |
| 3545 | * enable |
| 3546 | * |
| 3547 | * description |
| 3548 | * |
| 3549 | * @date 12/3/18 |
| 3550 | * @since ACF 5.6.9 |
| 3551 | * |
| 3552 | * @param type $var Description. Default. |
| 3553 | * @return type Description. |
| 3554 | */ |
| 3555 | |
| 3556 | var enable = function ($el, lockKey) { |
| 3557 | // check class. Allow .acf-disabled to overrule all JS |
| 3558 | if ($el.hasClass('acf-disabled')) { |
| 3559 | return false; |
| 3560 | } |
| 3561 | |
| 3562 | // unlock |
| 3563 | if (lockKey) { |
| 3564 | acf.unlock($el, 'disabled', lockKey); |
| 3565 | } |
| 3566 | |
| 3567 | // bail early if $el is still locked |
| 3568 | if (acf.isLocked($el, 'disabled')) { |
| 3569 | return false; |
| 3570 | } |
| 3571 | |
| 3572 | // $el is disabled, remove prop and return true due to change |
| 3573 | if ($el.prop('disabled')) { |
| 3574 | $el.prop('disabled', false); |
| 3575 | return true; |
| 3576 | |
| 3577 | // $el is enabled, return false due to no change |
| 3578 | } else { |
| 3579 | return false; |
| 3580 | } |
| 3581 | }; |
| 3582 | |
| 3583 | /** |
| 3584 | * acf.enable |
| 3585 | * |
| 3586 | * description |
| 3587 | * |
| 3588 | * @date 9/2/18 |
| 3589 | * @since ACF 5.6.5 |
| 3590 | * |
| 3591 | * @param type $var Description. Default. |
| 3592 | * @return type Description. |
| 3593 | */ |
| 3594 | |
| 3595 | acf.enable = function ($el, lockKey) { |
| 3596 | // enable single input |
| 3597 | if ($el.attr('name')) { |
| 3598 | return enable($el, lockKey); |
| 3599 | } |
| 3600 | |
| 3601 | // find and enable child inputs |
| 3602 | // return true if any inputs have changed |
| 3603 | var results = false; |
| 3604 | $el.find('[name]').each(function () { |
| 3605 | var result = enable($(this), lockKey); |
| 3606 | if (result) { |
| 3607 | results = true; |
| 3608 | } |
| 3609 | }); |
| 3610 | return results; |
| 3611 | }; |
| 3612 | |
| 3613 | /** |
| 3614 | * disable |
| 3615 | * |
| 3616 | * description |
| 3617 | * |
| 3618 | * @date 12/3/18 |
| 3619 | * @since ACF 5.6.9 |
| 3620 | * |
| 3621 | * @param type $var Description. Default. |
| 3622 | * @return type Description. |
| 3623 | */ |
| 3624 | |
| 3625 | var disable = function ($el, lockKey) { |
| 3626 | // lock |
| 3627 | if (lockKey) { |
| 3628 | acf.lock($el, 'disabled', lockKey); |
| 3629 | } |
| 3630 | |
| 3631 | // $el is disabled, return false due to no change |
| 3632 | if ($el.prop('disabled')) { |
| 3633 | return false; |
| 3634 | |
| 3635 | // $el is enabled, add prop and return true due to change |
| 3636 | } else { |
| 3637 | $el.prop('disabled', true); |
| 3638 | return true; |
| 3639 | } |
| 3640 | }; |
| 3641 | |
| 3642 | /** |
| 3643 | * acf.disable |
| 3644 | * |
| 3645 | * description |
| 3646 | * |
| 3647 | * @date 9/2/18 |
| 3648 | * @since ACF 5.6.5 |
| 3649 | * |
| 3650 | * @param type $var Description. Default. |
| 3651 | * @return type Description. |
| 3652 | */ |
| 3653 | |
| 3654 | acf.disable = function ($el, lockKey) { |
| 3655 | // disable single input |
| 3656 | if ($el.attr('name')) { |
| 3657 | return disable($el, lockKey); |
| 3658 | } |
| 3659 | |
| 3660 | // find and enable child inputs |
| 3661 | // return true if any inputs have changed |
| 3662 | var results = false; |
| 3663 | $el.find('[name]').each(function () { |
| 3664 | var result = disable($(this), lockKey); |
| 3665 | if (result) { |
| 3666 | results = true; |
| 3667 | } |
| 3668 | }); |
| 3669 | return results; |
| 3670 | }; |
| 3671 | |
| 3672 | /** |
| 3673 | * acf.isset |
| 3674 | * |
| 3675 | * description |
| 3676 | * |
| 3677 | * @date 10/1/18 |
| 3678 | * @since ACF 5.6.5 |
| 3679 | * |
| 3680 | * @param type $var Description. Default. |
| 3681 | * @return type Description. |
| 3682 | */ |
| 3683 | |
| 3684 | acf.isset = function (obj /*, level1, level2, ... */) { |
| 3685 | for (var i = 1; i < arguments.length; i++) { |
| 3686 | if (!obj || !obj.hasOwnProperty(arguments[i])) { |
| 3687 | return false; |
| 3688 | } |
| 3689 | obj = obj[arguments[i]]; |
| 3690 | } |
| 3691 | return true; |
| 3692 | }; |
| 3693 | |
| 3694 | /** |
| 3695 | * acf.isget |
| 3696 | * |
| 3697 | * description |
| 3698 | * |
| 3699 | * @date 10/1/18 |
| 3700 | * @since ACF 5.6.5 |
| 3701 | * |
| 3702 | * @param type $var Description. Default. |
| 3703 | * @return type Description. |
| 3704 | */ |
| 3705 | |
| 3706 | acf.isget = function (obj /*, level1, level2, ... */) { |
| 3707 | for (var i = 1; i < arguments.length; i++) { |
| 3708 | if (!obj || !obj.hasOwnProperty(arguments[i])) { |
| 3709 | return null; |
| 3710 | } |
| 3711 | obj = obj[arguments[i]]; |
| 3712 | } |
| 3713 | return obj; |
| 3714 | }; |
| 3715 | |
| 3716 | /** |
| 3717 | * acf.getFileInputData |
| 3718 | * |
| 3719 | * description |
| 3720 | * |
| 3721 | * @date 10/1/18 |
| 3722 | * @since ACF 5.6.5 |
| 3723 | * |
| 3724 | * @param type $var Description. Default. |
| 3725 | * @return type Description. |
| 3726 | */ |
| 3727 | |
| 3728 | acf.getFileInputData = function ($input, callback) { |
| 3729 | // vars |
| 3730 | var value = $input.val(); |
| 3731 | |
| 3732 | // bail early if no value |
| 3733 | if (!value) { |
| 3734 | return false; |
| 3735 | } |
| 3736 | |
| 3737 | // data |
| 3738 | var data = { |
| 3739 | url: value |
| 3740 | }; |
| 3741 | |
| 3742 | // modern browsers |
| 3743 | var file = $input[0].files.length ? acf.isget($input[0].files, 0) : false; |
| 3744 | if (file) { |
| 3745 | // update data |
| 3746 | data.size = file.size; |
| 3747 | data.type = file.type; |
| 3748 | |
| 3749 | // image |
| 3750 | if (file.type.indexOf('image') > -1) { |
| 3751 | // vars |
| 3752 | var windowURL = window.URL || window.webkitURL; |
| 3753 | var img = new Image(); |
| 3754 | img.onload = function () { |
| 3755 | // update |
| 3756 | data.width = this.width; |
| 3757 | data.height = this.height; |
| 3758 | callback(data); |
| 3759 | }; |
| 3760 | img.src = windowURL.createObjectURL(file); |
| 3761 | } else { |
| 3762 | callback(data); |
| 3763 | } |
| 3764 | } else { |
| 3765 | callback(data); |
| 3766 | } |
| 3767 | }; |
| 3768 | |
| 3769 | /** |
| 3770 | * acf.isAjaxSuccess |
| 3771 | * |
| 3772 | * description |
| 3773 | * |
| 3774 | * @date 18/1/18 |
| 3775 | * @since ACF 5.6.5 |
| 3776 | * |
| 3777 | * @param type $var Description. Default. |
| 3778 | * @return type Description. |
| 3779 | */ |
| 3780 | |
| 3781 | acf.isAjaxSuccess = function (json) { |
| 3782 | return json && json.success; |
| 3783 | }; |
| 3784 | |
| 3785 | /** |
| 3786 | * acf.getAjaxMessage |
| 3787 | * |
| 3788 | * description |
| 3789 | * |
| 3790 | * @date 18/1/18 |
| 3791 | * @since ACF 5.6.5 |
| 3792 | * |
| 3793 | * @param type $var Description. Default. |
| 3794 | * @return type Description. |
| 3795 | */ |
| 3796 | |
| 3797 | acf.getAjaxMessage = function (json) { |
| 3798 | return acf.isget(json, 'data', 'message'); |
| 3799 | }; |
| 3800 | |
| 3801 | /** |
| 3802 | * acf.getAjaxError |
| 3803 | * |
| 3804 | * description |
| 3805 | * |
| 3806 | * @date 18/1/18 |
| 3807 | * @since ACF 5.6.5 |
| 3808 | * |
| 3809 | * @param type $var Description. Default. |
| 3810 | * @return type Description. |
| 3811 | */ |
| 3812 | |
| 3813 | acf.getAjaxError = function (json) { |
| 3814 | return acf.isget(json, 'data', 'error'); |
| 3815 | }; |
| 3816 | |
| 3817 | /** |
| 3818 | * Returns the error message from an XHR object. |
| 3819 | * |
| 3820 | * @date 17/3/20 |
| 3821 | * @since ACF 5.8.9 |
| 3822 | * |
| 3823 | * @param object xhr The XHR object. |
| 3824 | * @return (string) |
| 3825 | */ |
| 3826 | acf.getXhrError = function (xhr) { |
| 3827 | if (xhr.responseJSON) { |
| 3828 | // Responses via `return new WP_Error();` |
| 3829 | if (xhr.responseJSON.message) { |
| 3830 | return xhr.responseJSON.message; |
| 3831 | } |
| 3832 | |
| 3833 | // Responses via `wp_send_json_error();`. |
| 3834 | if (xhr.responseJSON.data && xhr.responseJSON.data.error) { |
| 3835 | return xhr.responseJSON.data.error; |
| 3836 | } |
| 3837 | } else if (xhr.statusText) { |
| 3838 | return xhr.statusText; |
| 3839 | } |
| 3840 | return ''; |
| 3841 | }; |
| 3842 | |
| 3843 | /** |
| 3844 | * acf.renderSelect |
| 3845 | * |
| 3846 | * Renders the innter html for a select field. |
| 3847 | * |
| 3848 | * @date 19/2/18 |
| 3849 | * @since ACF 5.6.9 |
| 3850 | * |
| 3851 | * @param jQuery $select The select element. |
| 3852 | * @param array choices An array of choices. |
| 3853 | * @return void |
| 3854 | */ |
| 3855 | |
| 3856 | acf.renderSelect = function ($select, choices) { |
| 3857 | // vars |
| 3858 | var value = $select.val(); |
| 3859 | var values = []; |
| 3860 | |
| 3861 | // callback |
| 3862 | var crawl = function (items) { |
| 3863 | // vars |
| 3864 | var itemsHtml = ''; |
| 3865 | |
| 3866 | // loop |
| 3867 | items.map(function (item) { |
| 3868 | // vars |
| 3869 | var text = item.text || item.label || ''; |
| 3870 | var id = item.id || item.value || ''; |
| 3871 | |
| 3872 | // append |
| 3873 | values.push(id); |
| 3874 | |
| 3875 | // optgroup |
| 3876 | if (item.children) { |
| 3877 | itemsHtml += '<optgroup label="' + acf.escAttr(text) + '">' + crawl(item.children) + '</optgroup>'; |
| 3878 | |
| 3879 | // option |
| 3880 | } else { |
| 3881 | itemsHtml += '<option value="' + acf.escAttr(id) + '"' + (item.disabled ? ' disabled="disabled"' : '') + '>' + acf.strEscape(text) + '</option>'; |
| 3882 | } |
| 3883 | }); |
| 3884 | // return |
| 3885 | return itemsHtml; |
| 3886 | }; |
| 3887 | |
| 3888 | // update HTML |
| 3889 | $select.html(crawl(choices)); |
| 3890 | |
| 3891 | // update value |
| 3892 | if (values.indexOf(value) > -1) { |
| 3893 | $select.val(value); |
| 3894 | } |
| 3895 | |
| 3896 | // return selected value |
| 3897 | return $select.val(); |
| 3898 | }; |
| 3899 | |
| 3900 | /** |
| 3901 | * acf.lock |
| 3902 | * |
| 3903 | * Creates a "lock" on an element for a given type and key |
| 3904 | * |
| 3905 | * @date 22/2/18 |
| 3906 | * @since ACF 5.6.9 |
| 3907 | * |
| 3908 | * @param jQuery $el The element to lock. |
| 3909 | * @param string type The type of lock such as "condition" or "visibility". |
| 3910 | * @param string key The key that will be used to unlock. |
| 3911 | * @return void |
| 3912 | */ |
| 3913 | |
| 3914 | var getLocks = function ($el, type) { |
| 3915 | return $el.data('acf-lock-' + type) || []; |
| 3916 | }; |
| 3917 | var setLocks = function ($el, type, locks) { |
| 3918 | $el.data('acf-lock-' + type, locks); |
| 3919 | }; |
| 3920 | acf.lock = function ($el, type, key) { |
| 3921 | var locks = getLocks($el, type); |
| 3922 | var i = locks.indexOf(key); |
| 3923 | if (i < 0) { |
| 3924 | locks.push(key); |
| 3925 | setLocks($el, type, locks); |
| 3926 | } |
| 3927 | }; |
| 3928 | |
| 3929 | /** |
| 3930 | * acf.unlock |
| 3931 | * |
| 3932 | * Unlocks a "lock" on an element for a given type and key |
| 3933 | * |
| 3934 | * @date 22/2/18 |
| 3935 | * @since ACF 5.6.9 |
| 3936 | * |
| 3937 | * @param jQuery $el The element to lock. |
| 3938 | * @param string type The type of lock such as "condition" or "visibility". |
| 3939 | * @param string key The key that will be used to unlock. |
| 3940 | * @return void |
| 3941 | */ |
| 3942 | |
| 3943 | acf.unlock = function ($el, type, key) { |
| 3944 | var locks = getLocks($el, type); |
| 3945 | var i = locks.indexOf(key); |
| 3946 | if (i > -1) { |
| 3947 | locks.splice(i, 1); |
| 3948 | setLocks($el, type, locks); |
| 3949 | } |
| 3950 | |
| 3951 | // return true if is unlocked (no locks) |
| 3952 | return locks.length === 0; |
| 3953 | }; |
| 3954 | |
| 3955 | /** |
| 3956 | * acf.isLocked |
| 3957 | * |
| 3958 | * Returns true if a lock exists for a given type |
| 3959 | * |
| 3960 | * @date 22/2/18 |
| 3961 | * @since ACF 5.6.9 |
| 3962 | * |
| 3963 | * @param jQuery $el The element to lock. |
| 3964 | * @param string type The type of lock such as "condition" or "visibility". |
| 3965 | * @return void |
| 3966 | */ |
| 3967 | |
| 3968 | acf.isLocked = function ($el, type) { |
| 3969 | return getLocks($el, type).length > 0; |
| 3970 | }; |
| 3971 | |
| 3972 | /** |
| 3973 | * acf.isGutenberg |
| 3974 | * |
| 3975 | * Returns true if the Gutenberg editor is being used. |
| 3976 | * |
| 3977 | * @since ACF 5.8.0 |
| 3978 | * |
| 3979 | * @return bool |
| 3980 | */ |
| 3981 | acf.isGutenberg = function () { |
| 3982 | return !!(window.wp && wp.data && wp.data.select && wp.data.select('core/editor')); |
| 3983 | }; |
| 3984 | |
| 3985 | /** |
| 3986 | * acf.isGutenbergPostEditor |
| 3987 | * |
| 3988 | * Returns true if the Gutenberg post editor is being used. |
| 3989 | * |
| 3990 | * @since ACF 6.2.2 |
| 3991 | * |
| 3992 | * @return bool |
| 3993 | */ |
| 3994 | acf.isGutenbergPostEditor = function () { |
| 3995 | return !!(window.wp && wp.data && wp.data.select && wp.data.select('core/edit-post')); |
| 3996 | }; |
| 3997 | |
| 3998 | /** |
| 3999 | * acf.objectToArray |
| 4000 | * |
| 4001 | * Returns an array of items from the given object. |
| 4002 | * |
| 4003 | * @date 20/11/18 |
| 4004 | * @since ACF 5.8.0 |
| 4005 | * |
| 4006 | * @param object obj The object of items. |
| 4007 | * @return array |
| 4008 | */ |
| 4009 | acf.objectToArray = function (obj) { |
| 4010 | return Object.keys(obj).map(function (key) { |
| 4011 | return obj[key]; |
| 4012 | }); |
| 4013 | }; |
| 4014 | |
| 4015 | /** |
| 4016 | * acf.debounce |
| 4017 | * |
| 4018 | * Returns a debounced version of the passed function which will postpone its execution until after `wait` milliseconds have elapsed since the last time it was invoked. |
| 4019 | * |
| 4020 | * @date 28/8/19 |
| 4021 | * @since ACF 5.8.1 |
| 4022 | * |
| 4023 | * @param function callback The callback function. |
| 4024 | * @return int wait The number of milliseconds to wait. |
| 4025 | */ |
| 4026 | acf.debounce = function (callback, wait) { |
| 4027 | var timeout; |
| 4028 | return function () { |
| 4029 | var context = this; |
| 4030 | var args = arguments; |
| 4031 | var later = function () { |
| 4032 | callback.apply(context, args); |
| 4033 | }; |
| 4034 | clearTimeout(timeout); |
| 4035 | timeout = setTimeout(later, wait); |
| 4036 | }; |
| 4037 | }; |
| 4038 | |
| 4039 | /** |
| 4040 | * acf.throttle |
| 4041 | * |
| 4042 | * Returns a throttled version of the passed function which will allow only one execution per `limit` time period. |
| 4043 | * |
| 4044 | * @date 28/8/19 |
| 4045 | * @since ACF 5.8.1 |
| 4046 | * |
| 4047 | * @param function callback The callback function. |
| 4048 | * @return int wait The number of milliseconds to wait. |
| 4049 | */ |
| 4050 | acf.throttle = function (callback, limit) { |
| 4051 | var busy = false; |
| 4052 | return function () { |
| 4053 | if (busy) return; |
| 4054 | busy = true; |
| 4055 | setTimeout(function () { |
| 4056 | busy = false; |
| 4057 | }, limit); |
| 4058 | callback.apply(this, arguments); |
| 4059 | }; |
| 4060 | }; |
| 4061 | |
| 4062 | /** |
| 4063 | * acf.isInView |
| 4064 | * |
| 4065 | * Returns true if the given element is in view. |
| 4066 | * |
| 4067 | * @date 29/8/19 |
| 4068 | * @since ACF 5.8.1 |
| 4069 | * |
| 4070 | * @param elem el The dom element to inspect. |
| 4071 | * @return bool |
| 4072 | */ |
| 4073 | acf.isInView = function (el) { |
| 4074 | if (el instanceof jQuery) { |
| 4075 | el = el[0]; |
| 4076 | } |
| 4077 | var rect = el.getBoundingClientRect(); |
| 4078 | return rect.top !== rect.bottom && rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth); |
| 4079 | }; |
| 4080 | |
| 4081 | /** |
| 4082 | * acf.onceInView |
| 4083 | * |
| 4084 | * Watches for a dom element to become visible in the browser and then excecutes the passed callback. |
| 4085 | * |
| 4086 | * @date 28/8/19 |
| 4087 | * @since ACF 5.8.1 |
| 4088 | * |
| 4089 | * @param dom el The dom element to inspect. |
| 4090 | * @param function callback The callback function. |
| 4091 | */ |
| 4092 | acf.onceInView = function () { |
| 4093 | // Define list. |
| 4094 | var items = []; |
| 4095 | var id = 0; |
| 4096 | |
| 4097 | // Define check function. |
| 4098 | var check = function () { |
| 4099 | items.forEach(function (item) { |
| 4100 | if (acf.isInView(item.el)) { |
| 4101 | item.callback.apply(this); |
| 4102 | pop(item.id); |
| 4103 | } |
| 4104 | }); |
| 4105 | }; |
| 4106 | |
| 4107 | // And create a debounced version. |
| 4108 | var debounced = acf.debounce(check, 300); |
| 4109 | |
| 4110 | // Define add function. |
| 4111 | var push = function (el, callback) { |
| 4112 | // Add event listener. |
| 4113 | if (!items.length) { |
| 4114 | $(window).on('scroll resize', debounced).on('acfrefresh orientationchange', check); |
| 4115 | } |
| 4116 | |
| 4117 | // Append to list. |
| 4118 | items.push({ |
| 4119 | id: id++, |
| 4120 | el: el, |
| 4121 | callback: callback |
| 4122 | }); |
| 4123 | }; |
| 4124 | |
| 4125 | // Define remove function. |
| 4126 | var pop = function (id) { |
| 4127 | // Remove from list. |
| 4128 | items = items.filter(function (item) { |
| 4129 | return item.id !== id; |
| 4130 | }); |
| 4131 | |
| 4132 | // Clean up listener. |
| 4133 | if (!items.length) { |
| 4134 | $(window).off('scroll resize', debounced).off('acfrefresh orientationchange', check); |
| 4135 | } |
| 4136 | }; |
| 4137 | |
| 4138 | // Define returned function. |
| 4139 | return function (el, callback) { |
| 4140 | // Allow jQuery object. |
| 4141 | if (el instanceof jQuery) el = el[0]; |
| 4142 | |
| 4143 | // Execute callback if already in view or add to watch list. |
| 4144 | if (acf.isInView(el)) { |
| 4145 | callback.apply(this); |
| 4146 | } else { |
| 4147 | push(el, callback); |
| 4148 | } |
| 4149 | }; |
| 4150 | }(); |
| 4151 | |
| 4152 | /** |
| 4153 | * acf.once |
| 4154 | * |
| 4155 | * Creates a function that is restricted to invoking `func` once. |
| 4156 | * |
| 4157 | * @date 2/9/19 |
| 4158 | * @since ACF 5.8.1 |
| 4159 | * |
| 4160 | * @param function func The function to restrict. |
| 4161 | * @return function |
| 4162 | */ |
| 4163 | acf.once = function (func) { |
| 4164 | var i = 0; |
| 4165 | return function () { |
| 4166 | if (i++ > 0) { |
| 4167 | return func = undefined; |
| 4168 | } |
| 4169 | return func.apply(this, arguments); |
| 4170 | }; |
| 4171 | }; |
| 4172 | |
| 4173 | /** |
| 4174 | * Focuses attention to a specific element. |
| 4175 | * |
| 4176 | * @date 05/05/2020 |
| 4177 | * @since ACF 5.9.0 |
| 4178 | * |
| 4179 | * @param jQuery $el The jQuery element to focus. |
| 4180 | * @return void |
| 4181 | */ |
| 4182 | acf.focusAttention = function ($el) { |
| 4183 | var wait = 1000; |
| 4184 | |
| 4185 | // Apply class to focus attention. |
| 4186 | $el.addClass('acf-attention -focused'); |
| 4187 | |
| 4188 | // Scroll to element if needed. |
| 4189 | var scrollTime = 500; |
| 4190 | if (!acf.isInView($el)) { |
| 4191 | $('body, html').animate({ |
| 4192 | scrollTop: $el.offset().top - $(window).height() / 2 |
| 4193 | }, scrollTime); |
| 4194 | wait += scrollTime; |
| 4195 | } |
| 4196 | |
| 4197 | // Remove class after $wait amount of time. |
| 4198 | var fadeTime = 250; |
| 4199 | setTimeout(function () { |
| 4200 | $el.removeClass('-focused'); |
| 4201 | setTimeout(function () { |
| 4202 | $el.removeClass('acf-attention'); |
| 4203 | }, fadeTime); |
| 4204 | }, wait); |
| 4205 | }; |
| 4206 | |
| 4207 | /** |
| 4208 | * Description |
| 4209 | * |
| 4210 | * @date 05/05/2020 |
| 4211 | * @since ACF 5.9.0 |
| 4212 | * |
| 4213 | * @param type Var Description. |
| 4214 | * @return type Description. |
| 4215 | */ |
| 4216 | acf.onFocus = function ($el, callback) { |
| 4217 | // Only run once per element. |
| 4218 | // if( $el.data('acf.onFocus') ) { |
| 4219 | // return false; |
| 4220 | // } |
| 4221 | |
| 4222 | // Vars. |
| 4223 | var ignoreBlur = false; |
| 4224 | var focus = false; |
| 4225 | |
| 4226 | // Functions. |
| 4227 | var onFocus = function () { |
| 4228 | ignoreBlur = true; |
| 4229 | setTimeout(function () { |
| 4230 | ignoreBlur = false; |
| 4231 | }, 1); |
| 4232 | setFocus(true); |
| 4233 | }; |
| 4234 | var onBlur = function () { |
| 4235 | if (!ignoreBlur) { |
| 4236 | setFocus(false); |
| 4237 | } |
| 4238 | }; |
| 4239 | var addEvents = function () { |
| 4240 | $(document).on('click', onBlur); |
| 4241 | //$el.on('acfBlur', onBlur); |
| 4242 | $el.on('blur', 'input, select, textarea', onBlur); |
| 4243 | }; |
| 4244 | var removeEvents = function () { |
| 4245 | $(document).off('click', onBlur); |
| 4246 | //$el.off('acfBlur', onBlur); |
| 4247 | $el.off('blur', 'input, select, textarea', onBlur); |
| 4248 | }; |
| 4249 | var setFocus = function (value) { |
| 4250 | if (focus === value) { |
| 4251 | return; |
| 4252 | } |
| 4253 | if (value) { |
| 4254 | addEvents(); |
| 4255 | } else { |
| 4256 | removeEvents(); |
| 4257 | } |
| 4258 | focus = value; |
| 4259 | callback(value); |
| 4260 | }; |
| 4261 | |
| 4262 | // Add events and set data. |
| 4263 | $el.on('click', onFocus); |
| 4264 | //$el.on('acfFocus', onFocus); |
| 4265 | $el.on('focus', 'input, select, textarea', onFocus); |
| 4266 | //$el.data('acf.onFocus', true); |
| 4267 | }; |
| 4268 | |
| 4269 | /** |
| 4270 | * Disable form submit buttons |
| 4271 | * |
| 4272 | * @since ACF 6.2.3 |
| 4273 | * |
| 4274 | * @param event e |
| 4275 | * @returns void |
| 4276 | */ |
| 4277 | acf.disableForm = function (e) { |
| 4278 | // Disable submit button. |
| 4279 | if (e.submitter) e.submitter.classList.add('disabled'); |
| 4280 | }; |
| 4281 | |
| 4282 | /* |
| 4283 | * exists |
| 4284 | * |
| 4285 | * This function will return true if a jQuery selection exists |
| 4286 | * |
| 4287 | * @type function |
| 4288 | * @date 8/09/2014 |
| 4289 | * @since ACF 5.0.0 |
| 4290 | * |
| 4291 | * @param n/a |
| 4292 | * @return (boolean) |
| 4293 | */ |
| 4294 | |
| 4295 | $.fn.exists = function () { |
| 4296 | return $(this).length > 0; |
| 4297 | }; |
| 4298 | |
| 4299 | /* |
| 4300 | * outerHTML |
| 4301 | * |
| 4302 | * This function will return a string containing the HTML of the selected element |
| 4303 | * |
| 4304 | * @type function |
| 4305 | * @date 19/11/2013 |
| 4306 | * @since ACF 5.0.0 |
| 4307 | * |
| 4308 | * @param $.fn |
| 4309 | * @return (string) |
| 4310 | */ |
| 4311 | |
| 4312 | $.fn.outerHTML = function () { |
| 4313 | return $(this).get(0).outerHTML; |
| 4314 | }; |
| 4315 | |
| 4316 | /* |
| 4317 | * indexOf |
| 4318 | * |
| 4319 | * This function will provide compatibility for ie8 |
| 4320 | * |
| 4321 | * @type function |
| 4322 | * @date 5/3/17 |
| 4323 | * @since ACF 5.5.10 |
| 4324 | * |
| 4325 | * @param n/a |
| 4326 | * @return n/a |
| 4327 | */ |
| 4328 | |
| 4329 | if (!Array.prototype.indexOf) { |
| 4330 | Array.prototype.indexOf = function (val) { |
| 4331 | return $.inArray(val, this); |
| 4332 | }; |
| 4333 | } |
| 4334 | |
| 4335 | /** |
| 4336 | * Returns true if value is a number or a numeric string. |
| 4337 | * |
| 4338 | * @date 30/11/20 |
| 4339 | * @since ACF 5.9.4 |
| 4340 | * @link https://stackoverflow.com/questions/9716468/pure-javascript-a-function-like-jquerys-isnumeric/9716488#9716488 |
| 4341 | * |
| 4342 | * @param mixed n The variable being evaluated. |
| 4343 | * @return bool. |
| 4344 | */ |
| 4345 | acf.isNumeric = function (n) { |
| 4346 | return !isNaN(parseFloat(n)) && isFinite(n); |
| 4347 | }; |
| 4348 | |
| 4349 | /** |
| 4350 | * Triggers a "refresh" action used by various Components to redraw the DOM. |
| 4351 | * |
| 4352 | * @date 26/05/2020 |
| 4353 | * @since ACF 5.9.0 |
| 4354 | * |
| 4355 | * @param void |
| 4356 | * @return void |
| 4357 | */ |
| 4358 | acf.refresh = acf.debounce(function () { |
| 4359 | $(window).trigger('acfrefresh'); |
| 4360 | acf.doAction('refresh'); |
| 4361 | }, 0); |
| 4362 | |
| 4363 | /** |
| 4364 | * Log something to console if we're in debug mode. |
| 4365 | * |
| 4366 | * @since ACF 6.3 |
| 4367 | */ |
| 4368 | acf.debug = function () { |
| 4369 | if (acf.get('debug')) console.log.apply(null, arguments); |
| 4370 | }; |
| 4371 | |
| 4372 | // Set up actions from events |
| 4373 | $(document).ready(function () { |
| 4374 | acf.doAction('ready'); |
| 4375 | }); |
| 4376 | $(window).on('load', function () { |
| 4377 | // Use timeout to ensure action runs after Gutenberg has modified DOM elements during "DOMContentLoaded". |
| 4378 | setTimeout(function () { |
| 4379 | acf.doAction('load'); |
| 4380 | }); |
| 4381 | }); |
| 4382 | $(window).on('beforeunload', function () { |
| 4383 | acf.doAction('unload'); |
| 4384 | }); |
| 4385 | $(window).on('resize', function () { |
| 4386 | acf.doAction('resize'); |
| 4387 | }); |
| 4388 | $(document).on('sortstart', function (event, ui) { |
| 4389 | acf.doAction('sortstart', ui.item, ui.placeholder); |
| 4390 | }); |
| 4391 | $(document).on('sortstop', function (event, ui) { |
| 4392 | acf.doAction('sortstop', ui.item, ui.placeholder); |
| 4393 | }); |
| 4394 | })(jQuery); |
| 4395 | |
| 4396 | /***/ }) |
| 4397 | |
| 4398 | /******/ }); |
| 4399 | /************************************************************************/ |
| 4400 | /******/ // The module cache |
| 4401 | /******/ var __webpack_module_cache__ = {}; |
| 4402 | /******/ |
| 4403 | /******/ // The require function |
| 4404 | /******/ function __webpack_require__(moduleId) { |
| 4405 | /******/ // Check if module is in cache |
| 4406 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 4407 | /******/ if (cachedModule !== undefined) { |
| 4408 | /******/ return cachedModule.exports; |
| 4409 | /******/ } |
| 4410 | /******/ // Create a new module (and put it into the cache) |
| 4411 | /******/ var module = __webpack_module_cache__[moduleId] = { |
| 4412 | /******/ // no module.id needed |
| 4413 | /******/ // no module.loaded needed |
| 4414 | /******/ exports: {} |
| 4415 | /******/ }; |
| 4416 | /******/ |
| 4417 | /******/ // Execute the module function |
| 4418 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 4419 | /******/ |
| 4420 | /******/ // Return the exports of the module |
| 4421 | /******/ return module.exports; |
| 4422 | /******/ } |
| 4423 | /******/ |
| 4424 | /************************************************************************/ |
| 4425 | /******/ /* webpack/runtime/compat get default export */ |
| 4426 | /******/ (() => { |
| 4427 | /******/ // getDefaultExport function for compatibility with non-harmony modules |
| 4428 | /******/ __webpack_require__.n = (module) => { |
| 4429 | /******/ var getter = module && module.__esModule ? |
| 4430 | /******/ () => (module['default']) : |
| 4431 | /******/ () => (module); |
| 4432 | /******/ __webpack_require__.d(getter, { a: getter }); |
| 4433 | /******/ return getter; |
| 4434 | /******/ }; |
| 4435 | /******/ })(); |
| 4436 | /******/ |
| 4437 | /******/ /* webpack/runtime/define property getters */ |
| 4438 | /******/ (() => { |
| 4439 | /******/ // define getter functions for harmony exports |
| 4440 | /******/ __webpack_require__.d = (exports, definition) => { |
| 4441 | /******/ for(var key in definition) { |
| 4442 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 4443 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 4444 | /******/ } |
| 4445 | /******/ } |
| 4446 | /******/ }; |
| 4447 | /******/ })(); |
| 4448 | /******/ |
| 4449 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 4450 | /******/ (() => { |
| 4451 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
| 4452 | /******/ })(); |
| 4453 | /******/ |
| 4454 | /******/ /* webpack/runtime/make namespace object */ |
| 4455 | /******/ (() => { |
| 4456 | /******/ // define __esModule on exports |
| 4457 | /******/ __webpack_require__.r = (exports) => { |
| 4458 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 4459 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 4460 | /******/ } |
| 4461 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 4462 | /******/ }; |
| 4463 | /******/ })(); |
| 4464 | /******/ |
| 4465 | /************************************************************************/ |
| 4466 | var __webpack_exports__ = {}; |
| 4467 | // This entry need to be wrapped in an IIFE because it need to be in strict mode. |
| 4468 | (() => { |
| 4469 | "use strict"; |
| 4470 | /*!******************************!*\ |
| 4471 | !*** ./assets/src/js/acf.js ***! |
| 4472 | \******************************/ |
| 4473 | __webpack_require__.r(__webpack_exports__); |
| 4474 | /* harmony import */ var _acf_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./_acf.js */ "./assets/src/js/_acf.js"); |
| 4475 | /* harmony import */ var _acf_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_acf_js__WEBPACK_IMPORTED_MODULE_0__); |
| 4476 | /* harmony import */ var _acf_hooks_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./_acf-hooks.js */ "./assets/src/js/_acf-hooks.js"); |
| 4477 | /* harmony import */ var _acf_hooks_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_acf_hooks_js__WEBPACK_IMPORTED_MODULE_1__); |
| 4478 | /* harmony import */ var _acf_model_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./_acf-model.js */ "./assets/src/js/_acf-model.js"); |
| 4479 | /* harmony import */ var _acf_model_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_acf_model_js__WEBPACK_IMPORTED_MODULE_2__); |
| 4480 | /* harmony import */ var _acf_popup_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./_acf-popup.js */ "./assets/src/js/_acf-popup.js"); |
| 4481 | /* harmony import */ var _acf_popup_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_acf_popup_js__WEBPACK_IMPORTED_MODULE_3__); |
| 4482 | /* harmony import */ var _acf_modal_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./_acf-modal.js */ "./assets/src/js/_acf-modal.js"); |
| 4483 | /* harmony import */ var _acf_modal_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_acf_modal_js__WEBPACK_IMPORTED_MODULE_4__); |
| 4484 | /* harmony import */ var _acf_panel_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./_acf-panel.js */ "./assets/src/js/_acf-panel.js"); |
| 4485 | /* harmony import */ var _acf_panel_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_acf_panel_js__WEBPACK_IMPORTED_MODULE_5__); |
| 4486 | /* harmony import */ var _acf_notice_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./_acf-notice.js */ "./assets/src/js/_acf-notice.js"); |
| 4487 | /* harmony import */ var _acf_notice_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_acf_notice_js__WEBPACK_IMPORTED_MODULE_6__); |
| 4488 | /* harmony import */ var _acf_tooltip_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./_acf-tooltip.js */ "./assets/src/js/_acf-tooltip.js"); |
| 4489 | /* harmony import */ var _acf_tooltip_js__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_acf_tooltip_js__WEBPACK_IMPORTED_MODULE_7__); |
| 4490 | |
| 4491 | |
| 4492 | |
| 4493 | |
| 4494 | |
| 4495 | |
| 4496 | |
| 4497 | |
| 4498 | })(); |
| 4499 | |
| 4500 | /******/ })() |
| 4501 | ; |
| 4502 | //# sourceMappingURL=acf.js.map |