[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/script-modules/block-library/query/ -> view.js (source)

   1  import * as __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__ from "@wordpress/interactivity";
   2  /******/ var __webpack_modules__ = ({
   3  
   4  /***/ 438:
   5  /***/ ((module) => {
   6  
   7  module.exports = import("@wordpress/interactivity-router");;
   8  
   9  /***/ })
  10  
  11  /******/ });
  12  /************************************************************************/
  13  /******/ // The module cache
  14  /******/ var __webpack_module_cache__ = {};
  15  /******/ 
  16  /******/ // The require function
  17  /******/ function __webpack_require__(moduleId) {
  18  /******/     // Check if module is in cache
  19  /******/     var cachedModule = __webpack_module_cache__[moduleId];
  20  /******/     if (cachedModule !== undefined) {
  21  /******/         return cachedModule.exports;
  22  /******/     }
  23  /******/     // Create a new module (and put it into the cache)
  24  /******/     var module = __webpack_module_cache__[moduleId] = {
  25  /******/         // no module.id needed
  26  /******/         // no module.loaded needed
  27  /******/         exports: {}
  28  /******/     };
  29  /******/ 
  30  /******/     // Execute the module function
  31  /******/     __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  32  /******/ 
  33  /******/     // Return the exports of the module
  34  /******/     return module.exports;
  35  /******/ }
  36  /******/ 
  37  /************************************************************************/
  38  /******/ /* webpack/runtime/define property getters */
  39  /******/ (() => {
  40  /******/     // define getter functions for harmony exports
  41  /******/     __webpack_require__.d = (exports, definition) => {
  42  /******/         for(var key in definition) {
  43  /******/             if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  44  /******/                 Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  45  /******/             }
  46  /******/         }
  47  /******/     };
  48  /******/ })();
  49  /******/ 
  50  /******/ /* webpack/runtime/hasOwnProperty shorthand */
  51  /******/ (() => {
  52  /******/     __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  53  /******/ })();
  54  /******/ 
  55  /************************************************************************/
  56  var __webpack_exports__ = {};
  57  // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  58  (() => {
  59  
  60  ;// CONCATENATED MODULE: external "@wordpress/interactivity"
  61  var x = (y) => {
  62      var x = {}; __webpack_require__.d(x, y); return x
  63  } 
  64  var y = (x) => (() => (x))
  65  const interactivity_namespaceObject = x({ ["getContext"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getContext), ["getElement"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getElement), ["store"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.store) });
  66  ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-library/build-module/query/view.js
  67  /**
  68   * WordPress dependencies
  69   */
  70  
  71  const isValidLink = ref => ref && ref instanceof window.HTMLAnchorElement && ref.href && (!ref.target || ref.target === '_self') && ref.origin === window.location.origin;
  72  const isValidEvent = event => event.button === 0 &&
  73  // Left clicks only.
  74  !event.metaKey &&
  75  // Open in new tab (Mac).
  76  !event.ctrlKey &&
  77  // Open in new tab (Windows).
  78  !event.altKey &&
  79  // Download.
  80  !event.shiftKey && !event.defaultPrevented;
  81  (0,interactivity_namespaceObject.store)('core/query', {
  82    actions: {
  83      *navigate(event) {
  84        const ctx = (0,interactivity_namespaceObject.getContext)();
  85        const {
  86          ref
  87        } = (0,interactivity_namespaceObject.getElement)();
  88        const queryRef = ref.closest('.wp-block-query[data-wp-router-region]');
  89        if (isValidLink(ref) && isValidEvent(event)) {
  90          event.preventDefault();
  91          const {
  92            actions
  93          } = yield Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 438));
  94          yield actions.navigate(ref.href);
  95          ctx.url = ref.href;
  96  
  97          // Focus the first anchor of the Query block.
  98          const firstAnchor = `.wp-block-post-template a[href]`;
  99          queryRef.querySelector(firstAnchor)?.focus();
 100        }
 101      },
 102      *prefetch() {
 103        const {
 104          ref
 105        } = (0,interactivity_namespaceObject.getElement)();
 106        if (isValidLink(ref)) {
 107          const {
 108            actions
 109          } = yield Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 438));
 110          yield actions.prefetch(ref.href);
 111        }
 112      }
 113    },
 114    callbacks: {
 115      *prefetch() {
 116        const {
 117          url
 118        } = (0,interactivity_namespaceObject.getContext)();
 119        const {
 120          ref
 121        } = (0,interactivity_namespaceObject.getElement)();
 122        if (url && isValidLink(ref)) {
 123          const {
 124            actions
 125          } = yield Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 438));
 126          yield actions.prefetch(ref.href);
 127        }
 128      }
 129    }
 130  }, {
 131    lock: true
 132  });
 133  
 134  })();
 135  


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref