[ 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: () => (/* reexport */ speak)
  56  });
  57  
  58  ;// 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  ;// ./node_modules/@wordpress/a11y/build-module/script/add-container.js
  62  /**
  63   * Build the live regions markup.
  64   *
  65   * @param {string} [ariaLive] Value for the 'aria-live' attribute; default: 'polite'.
  66   *
  67   * @return {HTMLDivElement} The ARIA live region HTML element.
  68   */
  69  function addContainer(ariaLive = 'polite') {
  70    const container = document.createElement('div');
  71    container.id = `a11y-speak-$ariaLive}`;
  72    container.className = 'a11y-speak-region';
  73    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;');
  74    container.setAttribute('aria-live', ariaLive);
  75    container.setAttribute('aria-relevant', 'additions text');
  76    container.setAttribute('aria-atomic', 'true');
  77    const {
  78      body
  79    } = document;
  80    if (body) {
  81      body.appendChild(container);
  82    }
  83    return container;
  84  }
  85  
  86  ;// external ["wp","i18n"]
  87  const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
  88  ;// ./node_modules/@wordpress/a11y/build-module/script/add-intro-text.js
  89  /**
  90   * WordPress dependencies
  91   */
  92  
  93  
  94  /**
  95   * Build the explanatory text to be placed before the aria live regions.
  96   *
  97   * This text is initially hidden from assistive technologies by using a `hidden`
  98   * HTML attribute which is then removed once a message fills the aria-live regions.
  99   *
 100   * @return {HTMLParagraphElement} The explanatory text HTML element.
 101   */
 102  function addIntroText() {
 103    const introText = document.createElement('p');
 104    introText.id = 'a11y-speak-intro-text';
 105    introText.className = 'a11y-speak-intro-text';
 106    introText.textContent = (0,external_wp_i18n_namespaceObject.__)('Notifications');
 107    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;');
 108    introText.setAttribute('hidden', 'hidden');
 109    const {
 110      body
 111    } = document;
 112    if (body) {
 113      body.appendChild(introText);
 114    }
 115    return introText;
 116  }
 117  
 118  ;// ./node_modules/@wordpress/a11y/build-module/shared/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  ;// ./node_modules/@wordpress/a11y/build-module/shared/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  ;// ./node_modules/@wordpress/a11y/build-module/shared/index.js
 167  /**
 168   * Internal dependencies
 169   */
 170  
 171  
 172  
 173  /**
 174   * Allows you to easily announce dynamic interface updates to screen readers using ARIA live regions.
 175   * This module is inspired by the `speak` function in `wp-a11y.js`.
 176   *
 177   * @param {string}               message    The message to be announced by assistive technologies.
 178   * @param {'polite'|'assertive'} [ariaLive] The politeness level for aria-live; default: 'polite'.
 179   *
 180   * @example
 181   * ```js
 182   * import { speak } from '@wordpress/a11y';
 183   *
 184   * // For polite messages that shouldn't interrupt what screen readers are currently announcing.
 185   * speak( 'The message you want to send to the ARIA live region' );
 186   *
 187   * // For assertive messages that should interrupt what screen readers are currently announcing.
 188   * speak( 'The message you want to send to the ARIA live region', 'assertive' );
 189   * ```
 190   */
 191  function speak(message, ariaLive) {
 192    /*
 193     * Clear previous messages to allow repeated strings being read out and hide
 194     * the explanatory text from assistive technologies.
 195     */
 196    clear();
 197    message = filterMessage(message);
 198    const introText = document.getElementById('a11y-speak-intro-text');
 199    const containerAssertive = document.getElementById('a11y-speak-assertive');
 200    const containerPolite = document.getElementById('a11y-speak-polite');
 201    if (containerAssertive && ariaLive === 'assertive') {
 202      containerAssertive.textContent = message;
 203    } else if (containerPolite) {
 204      containerPolite.textContent = message;
 205    }
 206  
 207    /*
 208     * Make the explanatory text available to assistive technologies by removing
 209     * the 'hidden' HTML attribute.
 210     */
 211    if (introText) {
 212      introText.removeAttribute('hidden');
 213    }
 214  }
 215  
 216  ;// ./node_modules/@wordpress/a11y/build-module/index.js
 217  /**
 218   * WordPress dependencies
 219   */
 220  
 221  
 222  /**
 223   * Internal dependencies
 224   */
 225  
 226  
 227  
 228  
 229  /**
 230   * Create the live regions.
 231   */
 232  function setup() {
 233    const introText = document.getElementById('a11y-speak-intro-text');
 234    const containerAssertive = document.getElementById('a11y-speak-assertive');
 235    const containerPolite = document.getElementById('a11y-speak-polite');
 236    if (introText === null) {
 237      addIntroText();
 238    }
 239    if (containerAssertive === null) {
 240      addContainer('assertive');
 241    }
 242    if (containerPolite === null) {
 243      addContainer('polite');
 244    }
 245  }
 246  
 247  /**
 248   * Run setup on domReady.
 249   */
 250  external_wp_domReady_default()(setup);
 251  
 252  (window.wp = window.wp || {}).a11y = __webpack_exports__;
 253  /******/ })()
 254  ;


Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref