[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> hooks.js (source)

   1  this["wp"] = this["wp"] || {}; this["wp"]["hooks"] =
   2  /******/ (function(modules) { // webpackBootstrap
   3  /******/     // The module cache
   4  /******/     var installedModules = {};
   5  /******/
   6  /******/     // The require function
   7  /******/ 	function __webpack_require__(moduleId) {
   8  /******/
   9  /******/         // Check if module is in cache
  10  /******/         if(installedModules[moduleId]) {
  11  /******/             return installedModules[moduleId].exports;
  12  /******/         }
  13  /******/         // Create a new module (and put it into the cache)
  14  /******/         var module = installedModules[moduleId] = {
  15  /******/             i: moduleId,
  16  /******/             l: false,
  17  /******/             exports: {}
  18  /******/         };
  19  /******/
  20  /******/         // Execute the module function
  21  /******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22  /******/
  23  /******/         // Flag the module as loaded
  24  /******/         module.l = true;
  25  /******/
  26  /******/         // Return the exports of the module
  27  /******/         return module.exports;
  28  /******/     }
  29  /******/
  30  /******/
  31  /******/     // expose the modules object (__webpack_modules__)
  32  /******/     __webpack_require__.m = modules;
  33  /******/
  34  /******/     // expose the module cache
  35  /******/     __webpack_require__.c = installedModules;
  36  /******/
  37  /******/     // define getter function for harmony exports
  38  /******/     __webpack_require__.d = function(exports, name, getter) {
  39  /******/         if(!__webpack_require__.o(exports, name)) {
  40  /******/             Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41  /******/         }
  42  /******/     };
  43  /******/
  44  /******/     // define __esModule on exports
  45  /******/     __webpack_require__.r = function(exports) {
  46  /******/         if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47  /******/             Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48  /******/         }
  49  /******/         Object.defineProperty(exports, '__esModule', { value: true });
  50  /******/     };
  51  /******/
  52  /******/     // create a fake namespace object
  53  /******/     // mode & 1: value is a module id, require it
  54  /******/     // mode & 2: merge all properties of value into the ns
  55  /******/     // mode & 4: return value when already ns object
  56  /******/     // mode & 8|1: behave like require
  57  /******/     __webpack_require__.t = function(value, mode) {
  58  /******/         if(mode & 1) value = __webpack_require__(value);
  59  /******/         if(mode & 8) return value;
  60  /******/         if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61  /******/         var ns = Object.create(null);
  62  /******/         __webpack_require__.r(ns);
  63  /******/         Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64  /******/         if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65  /******/         return ns;
  66  /******/     };
  67  /******/
  68  /******/     // getDefaultExport function for compatibility with non-harmony modules
  69  /******/     __webpack_require__.n = function(module) {
  70  /******/         var getter = module && module.__esModule ?
  71  /******/ 			function getDefault() { return module['default']; } :
  72  /******/ 			function getModuleExports() { return module; };
  73  /******/         __webpack_require__.d(getter, 'a', getter);
  74  /******/         return getter;
  75  /******/     };
  76  /******/
  77  /******/     // Object.prototype.hasOwnProperty.call
  78  /******/     __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79  /******/
  80  /******/     // __webpack_public_path__
  81  /******/     __webpack_require__.p = "";
  82  /******/
  83  /******/
  84  /******/     // Load entry module and return exports
  85  /******/     return __webpack_require__(__webpack_require__.s = 352);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 352:
  91  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  92  
  93  "use strict";
  94  __webpack_require__.r(__webpack_exports__);
  95  
  96  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/validateNamespace.js
  97  /**
  98   * Validate a namespace string.
  99   *
 100   * @param  {string} namespace The namespace to validate - should take the form
 101   *                            `vendor/plugin/function`.
 102   *
 103   * @return {boolean}             Whether the namespace is valid.
 104   */
 105  function validateNamespace(namespace) {
 106    if ('string' !== typeof namespace || '' === namespace) {
 107      // eslint-disable-next-line no-console
 108      console.error('The namespace must be a non-empty string.');
 109      return false;
 110    }
 111  
 112    if (!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(namespace)) {
 113      // eslint-disable-next-line no-console
 114      console.error('The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.');
 115      return false;
 116    }
 117  
 118    return true;
 119  }
 120  
 121  /* harmony default export */ var build_module_validateNamespace = (validateNamespace);
 122  
 123  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/validateHookName.js
 124  /**
 125   * Validate a hookName string.
 126   *
 127   * @param  {string} hookName The hook name to validate. Should be a non empty string containing
 128   *                           only numbers, letters, dashes, periods and underscores. Also,
 129   *                           the hook name cannot begin with `__`.
 130   *
 131   * @return {boolean}            Whether the hook name is valid.
 132   */
 133  function validateHookName(hookName) {
 134    if ('string' !== typeof hookName || '' === hookName) {
 135      // eslint-disable-next-line no-console
 136      console.error('The hook name must be a non-empty string.');
 137      return false;
 138    }
 139  
 140    if (/^__/.test(hookName)) {
 141      // eslint-disable-next-line no-console
 142      console.error('The hook name cannot begin with `__`.');
 143      return false;
 144    }
 145  
 146    if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(hookName)) {
 147      // eslint-disable-next-line no-console
 148      console.error('The hook name can only contain numbers, letters, dashes, periods and underscores.');
 149      return false;
 150    }
 151  
 152    return true;
 153  }
 154  
 155  /* harmony default export */ var build_module_validateHookName = (validateHookName);
 156  
 157  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createAddHook.js
 158  /**
 159   * Internal dependencies
 160   */
 161  
 162  
 163  
 164  /**
 165   * Returns a function which, when invoked, will add a hook.
 166   *
 167   * @param  {Object}   hooks Stored hooks, keyed by hook name.
 168   *
 169   * @return {Function}       Function that adds a new hook.
 170   */
 171  
 172  function createAddHook(hooks) {
 173    /**
 174     * Adds the hook to the appropriate hooks container.
 175     *
 176     * @param {string}   hookName  Name of hook to add
 177     * @param {string}   namespace The unique namespace identifying the callback in the form `vendor/plugin/function`.
 178     * @param {Function} callback  Function to call when the hook is run
 179     * @param {?number}  priority  Priority of this hook (default=10)
 180     */
 181    return function addHook(hookName, namespace, callback) {
 182      var priority = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10;
 183  
 184      if (!build_module_validateHookName(hookName)) {
 185        return;
 186      }
 187  
 188      if (!build_module_validateNamespace(namespace)) {
 189        return;
 190      }
 191  
 192      if ('function' !== typeof callback) {
 193        // eslint-disable-next-line no-console
 194        console.error('The hook callback must be a function.');
 195        return;
 196      } // Validate numeric priority
 197  
 198  
 199      if ('number' !== typeof priority) {
 200        // eslint-disable-next-line no-console
 201        console.error('If specified, the hook priority must be a number.');
 202        return;
 203      }
 204  
 205      var handler = {
 206        callback: callback,
 207        priority: priority,
 208        namespace: namespace
 209      };
 210  
 211      if (hooks[hookName]) {
 212        // Find the correct insert index of the new hook.
 213        var handlers = hooks[hookName].handlers;
 214        var i;
 215  
 216        for (i = handlers.length; i > 0; i--) {
 217          if (priority >= handlers[i - 1].priority) {
 218            break;
 219          }
 220        }
 221  
 222        if (i === handlers.length) {
 223          // If append, operate via direct assignment.
 224          handlers[i] = handler;
 225        } else {
 226          // Otherwise, insert before index via splice.
 227          handlers.splice(i, 0, handler);
 228        } // We may also be currently executing this hook.  If the callback
 229        // we're adding would come after the current callback, there's no
 230        // problem; otherwise we need to increase the execution index of
 231        // any other runs by 1 to account for the added element.
 232  
 233  
 234        (hooks.__current || []).forEach(function (hookInfo) {
 235          if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
 236            hookInfo.currentIndex++;
 237          }
 238        });
 239      } else {
 240        // This is the first hook of its type.
 241        hooks[hookName] = {
 242          handlers: [handler],
 243          runs: 0
 244        };
 245      }
 246  
 247      if (hookName !== 'hookAdded') {
 248        doAction('hookAdded', hookName, namespace, callback, priority);
 249      }
 250    };
 251  }
 252  
 253  /* harmony default export */ var build_module_createAddHook = (createAddHook);
 254  
 255  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createRemoveHook.js
 256  /**
 257   * Internal dependencies
 258   */
 259  
 260  
 261  
 262  /**
 263   * Returns a function which, when invoked, will remove a specified hook or all
 264   * hooks by the given name.
 265   *
 266   * @param  {Object}   hooks      Stored hooks, keyed by hook name.
 267   * @param  {boolean}     removeAll  Whether to remove all callbacks for a hookName, without regard to namespace. Used to create `removeAll*` functions.
 268   *
 269   * @return {Function}            Function that removes hooks.
 270   */
 271  
 272  function createRemoveHook(hooks, removeAll) {
 273    /**
 274     * Removes the specified callback (or all callbacks) from the hook with a
 275     * given hookName and namespace.
 276     *
 277     * @param {string}    hookName  The name of the hook to modify.
 278     * @param {string}    namespace The unique namespace identifying the callback in the form `vendor/plugin/function`.
 279     *
 280     * @return {number}             The number of callbacks removed.
 281     */
 282    return function removeHook(hookName, namespace) {
 283      if (!build_module_validateHookName(hookName)) {
 284        return;
 285      }
 286  
 287      if (!removeAll && !build_module_validateNamespace(namespace)) {
 288        return;
 289      } // Bail if no hooks exist by this name
 290  
 291  
 292      if (!hooks[hookName]) {
 293        return 0;
 294      }
 295  
 296      var handlersRemoved = 0;
 297  
 298      if (removeAll) {
 299        handlersRemoved = hooks[hookName].handlers.length;
 300        hooks[hookName] = {
 301          runs: hooks[hookName].runs,
 302          handlers: []
 303        };
 304      } else {
 305        // Try to find the specified callback to remove.
 306        var handlers = hooks[hookName].handlers;
 307  
 308        var _loop = function _loop(i) {
 309          if (handlers[i].namespace === namespace) {
 310            handlers.splice(i, 1);
 311            handlersRemoved++; // This callback may also be part of a hook that is
 312            // currently executing.  If the callback we're removing
 313            // comes after the current callback, there's no problem;
 314            // otherwise we need to decrease the execution index of any
 315            // other runs by 1 to account for the removed element.
 316  
 317            (hooks.__current || []).forEach(function (hookInfo) {
 318              if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
 319                hookInfo.currentIndex--;
 320              }
 321            });
 322          }
 323        };
 324  
 325        for (var i = handlers.length - 1; i >= 0; i--) {
 326          _loop(i);
 327        }
 328      }
 329  
 330      if (hookName !== 'hookRemoved') {
 331        doAction('hookRemoved', hookName, namespace);
 332      }
 333  
 334      return handlersRemoved;
 335    };
 336  }
 337  
 338  /* harmony default export */ var build_module_createRemoveHook = (createRemoveHook);
 339  
 340  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createHasHook.js
 341  /**
 342   * Returns a function which, when invoked, will return whether any handlers are
 343   * attached to a particular hook.
 344   *
 345   * @param  {Object}   hooks Stored hooks, keyed by hook name.
 346   *
 347   * @return {Function}       Function that returns whether any handlers are
 348   *                          attached to a particular hook.
 349   */
 350  function createHasHook(hooks) {
 351    /**
 352     * Returns how many handlers are attached for the given hook.
 353     *
 354     * @param  {string}  hookName The name of the hook to check for.
 355     *
 356     * @return {boolean} Whether there are handlers that are attached to the given hook.
 357     */
 358    return function hasHook(hookName) {
 359      return hookName in hooks;
 360    };
 361  }
 362  
 363  /* harmony default export */ var build_module_createHasHook = (createHasHook);
 364  
 365  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createRunHook.js
 366  /**
 367   * Returns a function which, when invoked, will execute all callbacks
 368   * registered to a hook of the specified type, optionally returning the final
 369   * value of the call chain.
 370   *
 371   * @param  {Object}   hooks          Stored hooks, keyed by hook name.
 372   * @param  {?boolean}    returnFirstArg Whether each hook callback is expected to
 373   *                                   return its first argument.
 374   *
 375   * @return {Function}                Function that runs hook callbacks.
 376   */
 377  function createRunHook(hooks, returnFirstArg) {
 378    /**
 379     * Runs all callbacks for the specified hook.
 380     *
 381     * @param  {string} hookName The name of the hook to run.
 382     * @param  {...*}   args     Arguments to pass to the hook callbacks.
 383     *
 384     * @return {*}               Return value of runner, if applicable.
 385     */
 386    return function runHooks(hookName) {
 387      if (!hooks[hookName]) {
 388        hooks[hookName] = {
 389          handlers: [],
 390          runs: 0
 391        };
 392      }
 393  
 394      hooks[hookName].runs++;
 395      var handlers = hooks[hookName].handlers;
 396  
 397      for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
 398        args[_key - 1] = arguments[_key];
 399      }
 400  
 401      if (!handlers || !handlers.length) {
 402        return returnFirstArg ? args[0] : undefined;
 403      }
 404  
 405      var hookInfo = {
 406        name: hookName,
 407        currentIndex: 0
 408      };
 409  
 410      hooks.__current.push(hookInfo);
 411  
 412      while (hookInfo.currentIndex < handlers.length) {
 413        var handler = handlers[hookInfo.currentIndex];
 414        var result = handler.callback.apply(null, args);
 415  
 416        if (returnFirstArg) {
 417          args[0] = result;
 418        }
 419  
 420        hookInfo.currentIndex++;
 421      }
 422  
 423      hooks.__current.pop();
 424  
 425      if (returnFirstArg) {
 426        return args[0];
 427      }
 428    };
 429  }
 430  
 431  /* harmony default export */ var build_module_createRunHook = (createRunHook);
 432  
 433  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createCurrentHook.js
 434  /**
 435   * Returns a function which, when invoked, will return the name of the
 436   * currently running hook, or `null` if no hook of the given type is currently
 437   * running.
 438   *
 439   * @param  {Object}   hooks          Stored hooks, keyed by hook name.
 440   *
 441   * @return {Function}                Function that returns the current hook.
 442   */
 443  function createCurrentHook(hooks) {
 444    /**
 445     * Returns the name of the currently running hook, or `null` if no hook of
 446     * the given type is currently running.
 447     *
 448     * @return {?string}             The name of the currently running hook, or
 449     *                               `null` if no hook is currently running.
 450     */
 451    return function currentHook() {
 452      if (!hooks.__current || !hooks.__current.length) {
 453        return null;
 454      }
 455  
 456      return hooks.__current[hooks.__current.length - 1].name;
 457    };
 458  }
 459  
 460  /* harmony default export */ var build_module_createCurrentHook = (createCurrentHook);
 461  
 462  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createDoingHook.js
 463  /**
 464   * Returns a function which, when invoked, will return whether a hook is
 465   * currently being executed.
 466   *
 467   * @param  {Object}   hooks Stored hooks, keyed by hook name.
 468   *
 469   * @return {Function}       Function that returns whether a hook is currently
 470   *                          being executed.
 471   */
 472  function createDoingHook(hooks) {
 473    /**
 474     * Returns whether a hook is currently being executed.
 475     *
 476     * @param  {?string} hookName The name of the hook to check for.  If
 477     *                            omitted, will check for any hook being executed.
 478     *
 479     * @return {boolean}             Whether the hook is being executed.
 480     */
 481    return function doingHook(hookName) {
 482      // If the hookName was not passed, check for any current hook.
 483      if ('undefined' === typeof hookName) {
 484        return 'undefined' !== typeof hooks.__current[0];
 485      } // Return the __current hook.
 486  
 487  
 488      return hooks.__current[0] ? hookName === hooks.__current[0].name : false;
 489    };
 490  }
 491  
 492  /* harmony default export */ var build_module_createDoingHook = (createDoingHook);
 493  
 494  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createDidHook.js
 495  /**
 496   * Internal dependencies
 497   */
 498  
 499  /**
 500   * Returns a function which, when invoked, will return the number of times a
 501   * hook has been called.
 502   *
 503   * @param  {Object}   hooks Stored hooks, keyed by hook name.
 504   *
 505   * @return {Function}       Function that returns a hook's call count.
 506   */
 507  
 508  function createDidHook(hooks) {
 509    /**
 510     * Returns the number of times an action has been fired.
 511     *
 512     * @param  {string} hookName The hook name to check.
 513     *
 514     * @return {number}          The number of times the hook has run.
 515     */
 516    return function didHook(hookName) {
 517      if (!build_module_validateHookName(hookName)) {
 518        return;
 519      }
 520  
 521      return hooks[hookName] && hooks[hookName].runs ? hooks[hookName].runs : 0;
 522    };
 523  }
 524  
 525  /* harmony default export */ var build_module_createDidHook = (createDidHook);
 526  
 527  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createHooks.js
 528  /**
 529   * Internal dependencies
 530   */
 531  
 532  
 533  
 534  
 535  
 536  
 537  
 538  /**
 539   * Returns an instance of the hooks object.
 540   *
 541   * @return {Object} Object that contains all hooks.
 542   */
 543  
 544  function createHooks() {
 545    var actions = Object.create(null);
 546    var filters = Object.create(null);
 547    actions.__current = [];
 548    filters.__current = [];
 549    return {
 550      addAction: build_module_createAddHook(actions),
 551      addFilter: build_module_createAddHook(filters),
 552      removeAction: build_module_createRemoveHook(actions),
 553      removeFilter: build_module_createRemoveHook(filters),
 554      hasAction: build_module_createHasHook(actions),
 555      hasFilter: build_module_createHasHook(filters),
 556      removeAllActions: build_module_createRemoveHook(actions, true),
 557      removeAllFilters: build_module_createRemoveHook(filters, true),
 558      doAction: build_module_createRunHook(actions),
 559      applyFilters: build_module_createRunHook(filters, true),
 560      currentAction: build_module_createCurrentHook(actions),
 561      currentFilter: build_module_createCurrentHook(filters),
 562      doingAction: build_module_createDoingHook(actions),
 563      doingFilter: build_module_createDoingHook(filters),
 564      didAction: build_module_createDidHook(actions),
 565      didFilter: build_module_createDidHook(filters),
 566      actions: actions,
 567      filters: filters
 568    };
 569  }
 570  
 571  /* harmony default export */ var build_module_createHooks = (createHooks);
 572  
 573  // CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/index.js
 574  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addAction", function() { return addAction; });
 575  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addFilter", function() { return addFilter; });
 576  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeAction", function() { return removeAction; });
 577  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeFilter", function() { return removeFilter; });
 578  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasAction", function() { return hasAction; });
 579  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasFilter", function() { return hasFilter; });
 580  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeAllActions", function() { return removeAllActions; });
 581  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeAllFilters", function() { return removeAllFilters; });
 582  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doAction", function() { return doAction; });
 583  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "applyFilters", function() { return applyFilters; });
 584  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "currentAction", function() { return currentAction; });
 585  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "currentFilter", function() { return currentFilter; });
 586  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doingAction", function() { return doingAction; });
 587  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doingFilter", function() { return doingFilter; });
 588  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "didAction", function() { return didAction; });
 589  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "didFilter", function() { return didFilter; });
 590  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "actions", function() { return build_module_actions; });
 591  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "filters", function() { return build_module_filters; });
 592  /* concated harmony reexport createHooks */__webpack_require__.d(__webpack_exports__, "createHooks", function() { return build_module_createHooks; });
 593  /**
 594   * Internal dependencies
 595   */
 596  
 597  
 598  var _createHooks = build_module_createHooks(),
 599      addAction = _createHooks.addAction,
 600      addFilter = _createHooks.addFilter,
 601      removeAction = _createHooks.removeAction,
 602      removeFilter = _createHooks.removeFilter,
 603      hasAction = _createHooks.hasAction,
 604      hasFilter = _createHooks.hasFilter,
 605      removeAllActions = _createHooks.removeAllActions,
 606      removeAllFilters = _createHooks.removeAllFilters,
 607      doAction = _createHooks.doAction,
 608      applyFilters = _createHooks.applyFilters,
 609      currentAction = _createHooks.currentAction,
 610      currentFilter = _createHooks.currentFilter,
 611      doingAction = _createHooks.doingAction,
 612      doingFilter = _createHooks.doingFilter,
 613      didAction = _createHooks.didAction,
 614      didFilter = _createHooks.didFilter,
 615      build_module_actions = _createHooks.actions,
 616      build_module_filters = _createHooks.filters;
 617  
 618  
 619  
 620  
 621  /***/ })
 622  
 623  /******/ });


Generated: Thu Sep 19 01:00:03 2019 Cross-referenced by PHPXref 0.7.1