[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  /******/ (() => { // webpackBootstrap
   2  /******/     "use strict";
   3  /******/     // The require scope
   4  /******/     var __webpack_require__ = {};
   5  /******/     
   6  /************************************************************************/
   7  /******/     /* webpack/runtime/compat get default export */
   8  /******/     (() => {
   9  /******/         // getDefaultExport function for compatibility with non-harmony modules
  10  /******/         __webpack_require__.n = (module) => {
  11  /******/             var getter = module && module.__esModule ?
  12  /******/                 () => (module['default']) :
  13  /******/                 () => (module);
  14  /******/             __webpack_require__.d(getter, { a: getter });
  15  /******/             return getter;
  16  /******/         };
  17  /******/     })();
  18  /******/     
  19  /******/     /* webpack/runtime/define property getters */
  20  /******/     (() => {
  21  /******/         // define getter functions for harmony exports
  22  /******/         __webpack_require__.d = (exports, definition) => {
  23  /******/             for(var key in definition) {
  24  /******/                 if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  25  /******/                     Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  26  /******/                 }
  27  /******/             }
  28  /******/         };
  29  /******/     })();
  30  /******/     
  31  /******/     /* webpack/runtime/hasOwnProperty shorthand */
  32  /******/     (() => {
  33  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  34  /******/     })();
  35  /******/     
  36  /******/     /* webpack/runtime/make namespace object */
  37  /******/     (() => {
  38  /******/         // define __esModule on exports
  39  /******/         __webpack_require__.r = (exports) => {
  40  /******/             if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  41  /******/                 Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  42  /******/             }
  43  /******/             Object.defineProperty(exports, '__esModule', { value: true });
  44  /******/         };
  45  /******/     })();
  46  /******/     
  47  /************************************************************************/
  48  var __webpack_exports__ = {};
  49  // ESM COMPAT FLAG
  50  __webpack_require__.r(__webpack_exports__);
  51  
  52  // EXPORTS
  53  __webpack_require__.d(__webpack_exports__, {
  54    setup: () => (/* binding */ setup),
  55    speak: () => (/* binding */ speak)
  56  });
  57  
  58  ;// CONCATENATED MODULE: external ["wp","domReady"]
  59  const external_wp_domReady_namespaceObject = window["wp"]["domReady"];
  60  var external_wp_domReady_default = /*#__PURE__*/__webpack_require__.n(external_wp_domReady_namespaceObject);
  61  ;// CONCATENATED MODULE: external ["wp","i18n"]
  62  const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
  63  ;// CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/add-intro-text.js
  64  /**
  65   * WordPress dependencies
  66   */
  67  
  68  
  69  /**
  70   * Build the explanatory text to be placed before the aria live regions.
  71   *
  72   * This text is initially hidden from assistive technologies by using a `hidden`
  73   * HTML attribute which is then removed once a message fills the aria-live regions.
  74   *
  75   * @return {HTMLParagraphElement} The explanatory text HTML element.
  76   */
  77  function addIntroText() {
  78    const introText = document.createElement('p');
  79    introText.id = 'a11y-speak-intro-text';
  80    introText.className = 'a11y-speak-intro-text';
  81    introText.textContent = (0,external_wp_i18n_namespaceObject.__)('Notifications');
  82    introText.setAttribute('style', 'position: absolute;' + 'margin: -1px;' + 'padding: 0;' + 'height: 1px;' + 'width: 1px;' + 'overflow: hidden;' + 'clip: rect(1px, 1px, 1px, 1px);' + '-webkit-clip-path: inset(50%);' + 'clip-path: inset(50%);' + 'border: 0;' + 'word-wrap: normal !important;');
  83    introText.setAttribute('hidden', 'hidden');
  84    const {
  85      body
  86    } = document;
  87    if (body) {
  88      body.appendChild(introText);
  89    }
  90    return introText;
  91  }
  92  
  93  ;// CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/add-container.js
  94  /**
  95   * Build the live regions markup.
  96   *
  97   * @param {string} [ariaLive] Value for the 'aria-live' attribute; default: 'polite'.
  98   *
  99   * @return {HTMLDivElement} The ARIA live region HTML element.
 100   */
 101  function addContainer(ariaLive = 'polite') {
 102    const container = document.createElement('div');
 103    container.id = `a11y-speak-$ariaLive}`;
 104    container.className = 'a11y-speak-region';
 105    container.setAttribute('style', 'position: absolute;' + 'margin: -1px;' + 'padding: 0;' + 'height: 1px;' + 'width: 1px;' + 'overflow: hidden;' + 'clip: rect(1px, 1px, 1px, 1px);' + '-webkit-clip-path: inset(50%);' + 'clip-path: inset(50%);' + 'border: 0;' + 'word-wrap: normal !important;');
 106    container.setAttribute('aria-live', ariaLive);
 107    container.setAttribute('aria-relevant', 'additions text');
 108    container.setAttribute('aria-atomic', 'true');
 109    const {
 110      body
 111    } = document;
 112    if (body) {
 113      body.appendChild(container);
 114    }
 115    return container;
 116  }
 117  
 118  ;// CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/clear.js
 119  /**
 120   * Clears the a11y-speak-region elements and hides the explanatory text.
 121   */
 122  function clear() {
 123    const regions = document.getElementsByClassName('a11y-speak-region');
 124    const introText = document.getElementById('a11y-speak-intro-text');
 125    for (let i = 0; i < regions.length; i++) {
 126      regions[i].textContent = '';
 127    }
 128  
 129    // Make sure the explanatory text is hidden from assistive technologies.
 130    if (introText) {
 131      introText.setAttribute('hidden', 'hidden');
 132    }
 133  }
 134  
 135  ;// CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/filter-message.js
 136  let previousMessage = '';
 137  
 138  /**
 139   * Filter the message to be announced to the screenreader.
 140   *
 141   * @param {string} message The message to be announced.
 142   *
 143   * @return {string} The filtered message.
 144   */
 145  function filterMessage(message) {
 146    /*
 147     * Strip HTML tags (if any) from the message string. Ideally, messages should
 148     * be simple strings, carefully crafted for specific use with A11ySpeak.
 149     * When re-using already existing strings this will ensure simple HTML to be
 150     * stripped out and replaced with a space. Browsers will collapse multiple
 151     * spaces natively.
 152     */
 153    message = message.replace(/<[^<>]+>/g, ' ');
 154  
 155    /*
 156     * Safari + VoiceOver don't announce repeated, identical strings. We use
 157     * a `no-break space` to force them to think identical strings are different.
 158     */
 159    if (previousMessage === message) {
 160      message += '\u00A0';
 161    }
 162    previousMessage = message;
 163    return message;
 164  }
 165  
 166  ;// CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/index.js
 167  /**
 168   * WordPress dependencies
 169   */
 170  
 171  
 172  /**
 173   * Internal dependencies
 174   */
 175  
 176  
 177  
 178  
 179  
 180  /**
 181   * Create the live regions.
 182   */
 183  function setup() {
 184    const introText = document.getElementById('a11y-speak-intro-text');
 185    const containerAssertive = document.getElementById('a11y-speak-assertive');
 186    const containerPolite = document.getElementById('a11y-speak-polite');
 187    if (introText === null) {
 188      addIntroText();
 189    }
 190    if (containerAssertive === null) {
 191      addContainer('assertive');
 192    }
 193    if (containerPolite === null) {
 194      addContainer('polite');
 195    }
 196  }
 197  
 198  /**
 199   * Run setup on domReady.
 200   */
 201  external_wp_domReady_default()(setup);
 202  
 203  /**
 204   * Allows you to easily announce dynamic interface updates to screen readers using ARIA live regions.
 205   * This module is inspired by the `speak` function in `wp-a11y.js`.
 206   *
 207   * @param {string} message    The message to be announced by assistive technologies.
 208   * @param {string} [ariaLive] The politeness level for aria-live; default: 'polite'.
 209   *
 210   * @example
 211   * ```js
 212   * import { speak } from '@wordpress/a11y';
 213   *
 214   * // For polite messages that shouldn't interrupt what screen readers are currently announcing.
 215   * speak( 'The message you want to send to the ARIA live region' );
 216   *
 217   * // For assertive messages that should interrupt what screen readers are currently announcing.
 218   * speak( 'The message you want to send to the ARIA live region', 'assertive' );
 219   * ```
 220   */
 221  function speak(message, ariaLive) {
 222    /*
 223     * Clear previous messages to allow repeated strings being read out and hide
 224     * the explanatory text from assistive technologies.
 225     */
 226    clear();
 227    message = filterMessage(message);
 228    const introText = document.getElementById('a11y-speak-intro-text');
 229    const containerAssertive = document.getElementById('a11y-speak-assertive');
 230    const containerPolite = document.getElementById('a11y-speak-polite');
 231    if (containerAssertive && ariaLive === 'assertive') {
 232      containerAssertive.textContent = message;
 233    } else if (containerPolite) {
 234      containerPolite.textContent = message;
 235    }
 236  
 237    /*
 238     * Make the explanatory text available to assistive technologies by removing
 239     * the 'hidden' HTML attribute.
 240     */
 241    if (introText) {
 242      introText.removeAttribute('hidden');
 243    }
 244  }
 245  
 246  (window.wp = window.wp || {}).a11y = __webpack_exports__;
 247  /******/ })()
 248  ;


Generated : Thu Apr 18 08:20:02 2024 Cross-referenced by PHPXref