[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/script-modules/a11y/ -> index.js (source)

   1  /******/ // The require scope
   2  /******/ var __webpack_require__ = {};
   3  /******/ 
   4  /************************************************************************/
   5  /******/ /* webpack/runtime/define property getters */
   6  /******/ (() => {
   7  /******/     // define getter functions for harmony exports
   8  /******/     __webpack_require__.d = (exports, definition) => {
   9  /******/         for(var key in definition) {
  10  /******/             if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  11  /******/                 Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  12  /******/             }
  13  /******/         }
  14  /******/     };
  15  /******/ })();
  16  /******/ 
  17  /******/ /* webpack/runtime/hasOwnProperty shorthand */
  18  /******/ (() => {
  19  /******/     __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  20  /******/ })();
  21  /******/ 
  22  /************************************************************************/
  23  var __webpack_exports__ = {};
  24  
  25  // EXPORTS
  26  __webpack_require__.d(__webpack_exports__, {
  27    m: () => (/* binding */ setup),
  28    L: () => (/* reexport */ speak)
  29  });
  30  
  31  ;// CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/shared/clear.js
  32  /**
  33   * Clears the a11y-speak-region elements and hides the explanatory text.
  34   */
  35  function clear() {
  36    const regions = document.getElementsByClassName('a11y-speak-region');
  37    const introText = document.getElementById('a11y-speak-intro-text');
  38    for (let i = 0; i < regions.length; i++) {
  39      regions[i].textContent = '';
  40    }
  41  
  42    // Make sure the explanatory text is hidden from assistive technologies.
  43    if (introText) {
  44      introText.setAttribute('hidden', 'hidden');
  45    }
  46  }
  47  
  48  ;// CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/shared/filter-message.js
  49  let previousMessage = '';
  50  
  51  /**
  52   * Filter the message to be announced to the screenreader.
  53   *
  54   * @param {string} message The message to be announced.
  55   *
  56   * @return {string} The filtered message.
  57   */
  58  function filterMessage(message) {
  59    /*
  60     * Strip HTML tags (if any) from the message string. Ideally, messages should
  61     * be simple strings, carefully crafted for specific use with A11ySpeak.
  62     * When re-using already existing strings this will ensure simple HTML to be
  63     * stripped out and replaced with a space. Browsers will collapse multiple
  64     * spaces natively.
  65     */
  66    message = message.replace(/<[^<>]+>/g, ' ');
  67  
  68    /*
  69     * Safari + VoiceOver don't announce repeated, identical strings. We use
  70     * a `no-break space` to force them to think identical strings are different.
  71     */
  72    if (previousMessage === message) {
  73      message += '\u00A0';
  74    }
  75    previousMessage = message;
  76    return message;
  77  }
  78  
  79  ;// CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/shared/index.js
  80  /**
  81   * Internal dependencies
  82   */
  83  
  84  
  85  
  86  /**
  87   * Allows you to easily announce dynamic interface updates to screen readers using ARIA live regions.
  88   * This module is inspired by the `speak` function in `wp-a11y.js`.
  89   *
  90   * @param {string}               message    The message to be announced by assistive technologies.
  91   * @param {'polite'|'assertive'} [ariaLive] The politeness level for aria-live; default: 'polite'.
  92   *
  93   * @example
  94   * ```js
  95   * import { speak } from '@wordpress/a11y';
  96   *
  97   * // For polite messages that shouldn't interrupt what screen readers are currently announcing.
  98   * speak( 'The message you want to send to the ARIA live region' );
  99   *
 100   * // For assertive messages that should interrupt what screen readers are currently announcing.
 101   * speak( 'The message you want to send to the ARIA live region', 'assertive' );
 102   * ```
 103   */
 104  function speak(message, ariaLive) {
 105    /*
 106     * Clear previous messages to allow repeated strings being read out and hide
 107     * the explanatory text from assistive technologies.
 108     */
 109    clear();
 110    message = filterMessage(message);
 111    const introText = document.getElementById('a11y-speak-intro-text');
 112    const containerAssertive = document.getElementById('a11y-speak-assertive');
 113    const containerPolite = document.getElementById('a11y-speak-polite');
 114    if (containerAssertive && ariaLive === 'assertive') {
 115      containerAssertive.textContent = message;
 116    } else if (containerPolite) {
 117      containerPolite.textContent = message;
 118    }
 119  
 120    /*
 121     * Make the explanatory text available to assistive technologies by removing
 122     * the 'hidden' HTML attribute.
 123     */
 124    if (introText) {
 125      introText.removeAttribute('hidden');
 126    }
 127  }
 128  
 129  ;// CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/module/index.js
 130  /**
 131   * Internal dependencies
 132   */
 133  
 134  
 135  /**
 136   * This no-op function is exported to provide compatibility with the `wp-a11y` Script.
 137   *
 138   * Filters should inject the relevant HTML on page load instead of requiring setup.
 139   */
 140  const setup = () => {};
 141  
 142  var __webpack_exports__setup = __webpack_exports__.m;
 143  var __webpack_exports__speak = __webpack_exports__.L;
 144  export { __webpack_exports__setup as setup, __webpack_exports__speak as speak };


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