wp/wp-includes/js/dist/a11y.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    80 /******/ 	// __webpack_public_path__
    80 /******/ 	// __webpack_public_path__
    81 /******/ 	__webpack_require__.p = "";
    81 /******/ 	__webpack_require__.p = "";
    82 /******/
    82 /******/
    83 /******/
    83 /******/
    84 /******/ 	// Load entry module and return exports
    84 /******/ 	// Load entry module and return exports
    85 /******/ 	return __webpack_require__(__webpack_require__.s = 380);
    85 /******/ 	return __webpack_require__(__webpack_require__.s = 459);
    86 /******/ })
    86 /******/ })
    87 /************************************************************************/
    87 /************************************************************************/
    88 /******/ ({
    88 /******/ ({
    89 
    89 
    90 /***/ 204:
    90 /***/ 1:
    91 /***/ (function(module, exports) {
    91 /***/ (function(module, exports) {
    92 
    92 
       
    93 (function() { module.exports = this["wp"]["i18n"]; }());
       
    94 
       
    95 /***/ }),
       
    96 
       
    97 /***/ 261:
       
    98 /***/ (function(module, exports) {
       
    99 
    93 (function() { module.exports = this["wp"]["domReady"]; }());
   100 (function() { module.exports = this["wp"]["domReady"]; }());
    94 
   101 
    95 /***/ }),
   102 /***/ }),
    96 
   103 
    97 /***/ 380:
   104 /***/ 459:
    98 /***/ (function(module, __webpack_exports__, __webpack_require__) {
   105 /***/ (function(module, __webpack_exports__, __webpack_require__) {
    99 
   106 
   100 "use strict";
   107 "use strict";
       
   108 // ESM COMPAT FLAG
   101 __webpack_require__.r(__webpack_exports__);
   109 __webpack_require__.r(__webpack_exports__);
   102 
   110 
       
   111 // EXPORTS
       
   112 __webpack_require__.d(__webpack_exports__, "setup", function() { return /* binding */ setup; });
       
   113 __webpack_require__.d(__webpack_exports__, "speak", function() { return /* binding */ speak; });
       
   114 
   103 // EXTERNAL MODULE: external {"this":["wp","domReady"]}
   115 // EXTERNAL MODULE: external {"this":["wp","domReady"]}
   104 var external_this_wp_domReady_ = __webpack_require__(204);
   116 var external_this_wp_domReady_ = __webpack_require__(261);
   105 var external_this_wp_domReady_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_domReady_);
   117 var external_this_wp_domReady_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_domReady_);
   106 
   118 
   107 // CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/addContainer.js
   119 // EXTERNAL MODULE: external {"this":["wp","i18n"]}
       
   120 var external_this_wp_i18n_ = __webpack_require__(1);
       
   121 
       
   122 // CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/add-intro-text.js
       
   123 /**
       
   124  * WordPress dependencies
       
   125  */
       
   126 
       
   127 /**
       
   128  * Build the explanatory text to be placed before the aria live regions.
       
   129  *
       
   130  * This text is initially hidden from assistive technologies by using a `hidden`
       
   131  * HTML attribute which is then removed once a message fills the aria-live regions.
       
   132  *
       
   133  * @return {HTMLParagraphElement} The explanatory text HTML element.
       
   134  */
       
   135 
       
   136 function addIntroText() {
       
   137   var introText = document.createElement('p');
       
   138   introText.id = 'a11y-speak-intro-text';
       
   139   introText.className = 'a11y-speak-intro-text';
       
   140   introText.textContent = Object(external_this_wp_i18n_["__"])('Notifications');
       
   141   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;');
       
   142   introText.setAttribute('hidden', 'hidden');
       
   143   var _document = document,
       
   144       body = _document.body;
       
   145 
       
   146   if (body) {
       
   147     body.appendChild(introText);
       
   148   }
       
   149 
       
   150   return introText;
       
   151 }
       
   152 
       
   153 // CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/add-container.js
   108 /**
   154 /**
   109  * Build the live regions markup.
   155  * Build the live regions markup.
   110  *
   156  *
   111  * @param {string} ariaLive Optional. Value for the 'aria-live' attribute, default 'polite'.
   157  * @param {string} [ariaLive] Value for the 'aria-live' attribute; default: 'polite'.
   112  *
   158  *
   113  * @return {Object} $container The ARIA live region jQuery object.
   159  * @return {HTMLDivElement} The ARIA live region HTML element.
   114  */
   160  */
   115 var addContainer = function addContainer(ariaLive) {
   161 function addContainer() {
   116   ariaLive = ariaLive || 'polite';
   162   var ariaLive = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'polite';
   117   var container = document.createElement('div');
   163   var container = document.createElement('div');
   118   container.id = 'a11y-speak-' + ariaLive;
   164   container.id = "a11y-speak-".concat(ariaLive);
   119   container.className = 'a11y-speak-region';
   165   container.className = 'a11y-speak-region';
   120   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;');
   166   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;');
   121   container.setAttribute('aria-live', ariaLive);
   167   container.setAttribute('aria-live', ariaLive);
   122   container.setAttribute('aria-relevant', 'additions text');
   168   container.setAttribute('aria-relevant', 'additions text');
   123   container.setAttribute('aria-atomic', 'true');
   169   container.setAttribute('aria-atomic', 'true');
   124   document.querySelector('body').appendChild(container);
   170   var _document = document,
       
   171       body = _document.body;
       
   172 
       
   173   if (body) {
       
   174     body.appendChild(container);
       
   175   }
       
   176 
   125   return container;
   177   return container;
   126 };
   178 }
   127 
       
   128 /* harmony default export */ var build_module_addContainer = (addContainer);
       
   129 
   179 
   130 // CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/clear.js
   180 // CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/clear.js
   131 /**
   181 /**
   132  * Clear the a11y-speak-region elements.
   182  * Clears the a11y-speak-region elements and hides the explanatory text.
   133  */
   183  */
   134 var clear = function clear() {
   184 function clear() {
   135   var regions = document.querySelectorAll('.a11y-speak-region');
   185   var regions = document.getElementsByClassName('a11y-speak-region');
       
   186   var introText = document.getElementById('a11y-speak-intro-text');
   136 
   187 
   137   for (var i = 0; i < regions.length; i++) {
   188   for (var i = 0; i < regions.length; i++) {
   138     regions[i].textContent = '';
   189     regions[i].textContent = '';
   139   }
   190   } // Make sure the explanatory text is hidden from assistive technologies.
   140 };
   191 
   141 
   192 
   142 /* harmony default export */ var build_module_clear = (clear);
   193   if (introText) {
   143 
   194     introText.setAttribute('hidden', 'hidden');
   144 // CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/filterMessage.js
   195   }
       
   196 }
       
   197 
       
   198 // CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/filter-message.js
   145 var previousMessage = '';
   199 var previousMessage = '';
   146 /**
   200 /**
   147  * Filter the message to be announced to the screenreader.
   201  * Filter the message to be announced to the screenreader.
   148  *
   202  *
   149  * @param {string} message The message to be announced.
   203  * @param {string} message The message to be announced.
   150  *
   204  *
   151  * @return {string} The filtered message.
   205  * @return {string} The filtered message.
   152  */
   206  */
   153 
   207 
   154 var filterMessage = function filterMessage(message) {
   208 function filterMessage(message) {
   155   /*
   209   /*
   156    * Strip HTML tags (if any) from the message string. Ideally, messages should
   210    * Strip HTML tags (if any) from the message string. Ideally, messages should
   157    * be simple strings, carefully crafted for specific use with A11ySpeak.
   211    * be simple strings, carefully crafted for specific use with A11ySpeak.
   158    * When re-using already existing strings this will ensure simple HTML to be
   212    * When re-using already existing strings this will ensure simple HTML to be
   159    * stripped out and replaced with a space. Browsers will collapse multiple
   213    * stripped out and replaced with a space. Browsers will collapse multiple
   160    * spaces natively.
   214    * spaces natively.
   161    */
   215    */
   162   message = message.replace(/<[^<>]+>/g, ' ');
   216   message = message.replace(/<[^<>]+>/g, ' ');
       
   217   /*
       
   218    * Safari + VoiceOver don't announce repeated, identical strings. We use
       
   219    * a `no-break space` to force them to think identical strings are different.
       
   220    */
   163 
   221 
   164   if (previousMessage === message) {
   222   if (previousMessage === message) {
   165     message += "\xA0";
   223     message += "\xA0";
   166   }
   224   }
   167 
   225 
   168   previousMessage = message;
   226   previousMessage = message;
   169   return message;
   227   return message;
   170 };
   228 }
   171 
       
   172 /* harmony default export */ var build_module_filterMessage = (filterMessage);
       
   173 
   229 
   174 // CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/index.js
   230 // CONCATENATED MODULE: ./node_modules/@wordpress/a11y/build-module/index.js
   175 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setup", function() { return build_module_setup; });
       
   176 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "speak", function() { return build_module_speak; });
       
   177 /**
   231 /**
   178  * WordPress dependencies
   232  * WordPress dependencies
   179  */
   233  */
   180 
   234 
   181 /**
   235 /**
   183  */
   237  */
   184 
   238 
   185 
   239 
   186 
   240 
   187 
   241 
       
   242 
   188 /**
   243 /**
   189  * Create the live regions.
   244  * Create the live regions.
   190  */
   245  */
   191 
   246 
   192 var build_module_setup = function setup() {
   247 function setup() {
       
   248   var introText = document.getElementById('a11y-speak-intro-text');
       
   249   var containerAssertive = document.getElementById('a11y-speak-assertive');
   193   var containerPolite = document.getElementById('a11y-speak-polite');
   250   var containerPolite = document.getElementById('a11y-speak-polite');
   194   var containerAssertive = document.getElementById('a11y-speak-assertive');
   251 
       
   252   if (introText === null) {
       
   253     addIntroText();
       
   254   }
       
   255 
       
   256   if (containerAssertive === null) {
       
   257     addContainer('assertive');
       
   258   }
   195 
   259 
   196   if (containerPolite === null) {
   260   if (containerPolite === null) {
   197     containerPolite = build_module_addContainer('polite');
   261     addContainer('polite');
   198   }
   262   }
   199 
   263 }
   200   if (containerAssertive === null) {
       
   201     containerAssertive = build_module_addContainer('assertive');
       
   202   }
       
   203 };
       
   204 /**
   264 /**
   205  * Run setup on domReady.
   265  * Run setup on domReady.
   206  */
   266  */
   207 
   267 
   208 external_this_wp_domReady_default()(build_module_setup);
   268 external_this_wp_domReady_default()(setup);
   209 /**
   269 /**
   210  * Allows you to easily announce dynamic interface updates to screen readers using ARIA live regions.
   270  * Allows you to easily announce dynamic interface updates to screen readers using ARIA live regions.
   211  * This module is inspired by the `speak` function in wp-a11y.js
   271  * This module is inspired by the `speak` function in `wp-a11y.js`.
   212  *
   272  *
   213  * @param {string} message  The message to be announced by Assistive Technologies.
   273  * @param {string} message  The message to be announced by assistive technologies.
   214  * @param {string} ariaLive Optional. The politeness level for aria-live. Possible values:
   274  * @param {string} [ariaLive] The politeness level for aria-live; default: 'polite'.
   215  *                          polite or assertive. Default polite.
       
   216  *
   275  *
   217  * @example
   276  * @example
   218  * ```js
   277  * ```js
   219  * import { speak } from '@wordpress/a11y';
   278  * import { speak } from '@wordpress/a11y';
   220  *
   279  *
   224  * // For assertive messages that should interrupt what screen readers are currently announcing.
   283  * // For assertive messages that should interrupt what screen readers are currently announcing.
   225  * speak( 'The message you want to send to the ARIA live region', 'assertive' );
   284  * speak( 'The message you want to send to the ARIA live region', 'assertive' );
   226  * ```
   285  * ```
   227  */
   286  */
   228 
   287 
   229 var build_module_speak = function speak(message, ariaLive) {
   288 function speak(message, ariaLive) {
   230   // Clear previous messages to allow repeated strings being read out.
   289   /*
   231   build_module_clear();
   290    * Clear previous messages to allow repeated strings being read out and hide
   232   message = build_module_filterMessage(message);
   291    * the explanatory text from assistive technologies.
       
   292    */
       
   293   clear();
       
   294   message = filterMessage(message);
       
   295   var introText = document.getElementById('a11y-speak-intro-text');
       
   296   var containerAssertive = document.getElementById('a11y-speak-assertive');
   233   var containerPolite = document.getElementById('a11y-speak-polite');
   297   var containerPolite = document.getElementById('a11y-speak-polite');
   234   var containerAssertive = document.getElementById('a11y-speak-assertive');
   298 
   235 
   299   if (containerAssertive && ariaLive === 'assertive') {
   236   if (containerAssertive && 'assertive' === ariaLive) {
       
   237     containerAssertive.textContent = message;
   300     containerAssertive.textContent = message;
   238   } else if (containerPolite) {
   301   } else if (containerPolite) {
   239     containerPolite.textContent = message;
   302     containerPolite.textContent = message;
   240   }
   303   }
   241 };
   304   /*
       
   305    * Make the explanatory text available to assistive technologies by removing
       
   306    * the 'hidden' HTML attribute.
       
   307    */
       
   308 
       
   309 
       
   310   if (introText) {
       
   311     introText.removeAttribute('hidden');
       
   312   }
       
   313 }
   242 
   314 
   243 
   315 
   244 /***/ })
   316 /***/ })
   245 
   317 
   246 /******/ });
   318 /******/ });