2018-06-28 04:30:15 +02:00
|
|
|
/**
|
|
|
|
* @output wp-includes/js/wp-a11y.js
|
|
|
|
*/
|
|
|
|
|
2017-09-08 20:42:49 +02:00
|
|
|
/** @namespace wp */
|
2015-03-01 20:11:27 +01:00
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
|
|
|
( function ( wp, $ ) {
|
|
|
|
'use strict';
|
|
|
|
|
2015-06-30 06:35:24 +02:00
|
|
|
var $containerPolite,
|
2017-04-19 21:53:42 +02:00
|
|
|
$containerAssertive,
|
|
|
|
previousMessage = '';
|
2015-03-01 20:11:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the ARIA live notification area text node.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
2015-06-30 06:35:24 +02:00
|
|
|
* @since 4.3.0 Introduced the 'ariaLive' argument.
|
2015-03-01 20:11:27 +01:00
|
|
|
*
|
File Editors: Introduce sandboxed live editing of PHP files with rollbacks for both themes and plugins.
* Edits to active plugins which cause PHP fatal errors will no longer auto-deactivate the plugin. Supersedes #39766.
* Introduce sandboxed PHP file edits for active themes, preventing accidental whitescreening of a user's site when introducing a fatal error.
* After writing a change to a PHP file for an active theme or plugin, perform loopback requests on the file editor admin screens and the homepage to check for fatal errors. If a fatal error is encountered, roll back the edited file and display the error to the user to fix and try again.
* Introduce a secure way to scrape PHP fatal errors from a site via `wp_start_scraping_edited_file_errors()` and `wp_finalize_scraping_edited_file_errors()`.
* Moves file modifications from `theme-editor.php` and `plugin-editor.php` to common `wp_edit_theme_plugin_file()` function.
* Refactor themes and plugin editors to submit file changes via Ajax instead of doing full page refreshes when JS is available.
* Use `get` method for theme/plugin dropdowns.
* Improve styling of plugin editors, including width of plugin/theme dropdowns.
* Improve notices API for theme/plugin editor JS component.
* Strip common base directory from plugin file list. See #24048.
* Factor out functions to list editable file types in `wp_get_theme_file_editable_extensions()` and `wp_get_plugin_file_editable_extensions()`.
* Scroll to line in editor that has linting error when attempting to save. See #41886.
* Add checkbox to dismiss lint errors to proceed with saving. See #41887.
* Only style the Update File button as disabled instead of actually disabling it for accessibility reasons.
* Ensure that value from CodeMirror is used instead of `textarea` when CodeMirror is present.
* Add "Are you sure?" check when leaving editor when there are unsaved changes.
Supersedes [41560].
See #39766, #24048, #41886.
Props westonruter, Clorith, melchoyce, johnbillion, jjj, jdgrimes, azaozz.
Fixes #21622, #41887.
Built from https://develop.svn.wordpress.org/trunk@41721
git-svn-id: http://core.svn.wordpress.org/trunk@41555 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-10-04 02:20:45 +02:00
|
|
|
* @param {String} message The message to be announced by Assistive Technologies.
|
|
|
|
* @param {String} [ariaLive] The politeness level for aria-live. Possible values:
|
|
|
|
* polite or assertive. Default polite.
|
|
|
|
* @returns {void}
|
2015-03-01 20:11:27 +01:00
|
|
|
*/
|
2015-06-30 06:35:24 +02:00
|
|
|
function speak( message, ariaLive ) {
|
|
|
|
// Clear previous messages to allow repeated strings being read out.
|
|
|
|
clear();
|
|
|
|
|
2016-07-20 16:26:28 +02:00
|
|
|
// Ensure only text is sent to screen readers.
|
|
|
|
message = $( '<p>' ).html( message ).text();
|
|
|
|
|
2017-04-19 21:53:42 +02:00
|
|
|
/*
|
|
|
|
* Safari 10+VoiceOver don't announce repeated, identical strings. We use
|
|
|
|
* a `no-break space` to force them to think identical strings are different.
|
|
|
|
* See ticket #36853.
|
|
|
|
*/
|
|
|
|
if ( previousMessage === message ) {
|
|
|
|
message = message + '\u00A0';
|
|
|
|
}
|
|
|
|
|
|
|
|
previousMessage = message;
|
|
|
|
|
2015-06-30 06:35:24 +02:00
|
|
|
if ( $containerAssertive && 'assertive' === ariaLive ) {
|
|
|
|
$containerAssertive.text( message );
|
|
|
|
} else if ( $containerPolite ) {
|
|
|
|
$containerPolite.text( message );
|
2015-03-01 20:11:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 06:35:24 +02:00
|
|
|
/**
|
|
|
|
* Build the live regions markup.
|
|
|
|
*
|
|
|
|
* @since 4.3.0
|
|
|
|
*
|
2015-07-13 19:58:24 +02:00
|
|
|
* @param {String} ariaLive Optional. Value for the 'aria-live' attribute, default 'polite'.
|
2015-06-30 06:35:24 +02:00
|
|
|
*
|
|
|
|
* @return {Object} $container The ARIA live region jQuery object.
|
|
|
|
*/
|
|
|
|
function addContainer( ariaLive ) {
|
|
|
|
ariaLive = ariaLive || 'polite';
|
|
|
|
|
|
|
|
var $container = $( '<div>', {
|
|
|
|
'id': 'wp-a11y-speak-' + ariaLive,
|
|
|
|
'aria-live': ariaLive,
|
|
|
|
'aria-relevant': 'additions text',
|
|
|
|
'aria-atomic': 'true',
|
|
|
|
'class': 'screen-reader-text wp-a11y-speak-region'
|
|
|
|
});
|
|
|
|
|
|
|
|
$( document.body ).append( $container );
|
|
|
|
return $container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the live regions.
|
|
|
|
*
|
|
|
|
* @since 4.3.0
|
|
|
|
*/
|
|
|
|
function clear() {
|
|
|
|
$( '.wp-a11y-speak-region' ).text( '' );
|
|
|
|
}
|
|
|
|
|
2015-03-01 20:11:27 +01:00
|
|
|
/**
|
|
|
|
* Initialize wp.a11y and define ARIA live notification area.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
2015-06-30 06:35:24 +02:00
|
|
|
* @since 4.3.0 Added the assertive live region.
|
2015-03-01 20:11:27 +01:00
|
|
|
*/
|
|
|
|
$( document ).ready( function() {
|
2015-06-30 06:35:24 +02:00
|
|
|
$containerPolite = $( '#wp-a11y-speak-polite' );
|
|
|
|
$containerAssertive = $( '#wp-a11y-speak-assertive' );
|
|
|
|
|
|
|
|
if ( ! $containerPolite.length ) {
|
|
|
|
$containerPolite = addContainer( 'polite' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $containerAssertive.length ) {
|
|
|
|
$containerAssertive = addContainer( 'assertive' );
|
2015-03-01 20:11:27 +01:00
|
|
|
}
|
2015-06-30 06:35:24 +02:00
|
|
|
});
|
2015-03-01 20:11:27 +01:00
|
|
|
|
2017-09-08 20:42:49 +02:00
|
|
|
/** @namespace wp.a11y */
|
2015-03-01 20:11:27 +01:00
|
|
|
wp.a11y = wp.a11y || {};
|
|
|
|
wp.a11y.speak = speak;
|
|
|
|
|
2015-06-30 06:35:24 +02:00
|
|
|
}( window.wp, window.jQuery ));
|