Migrate core/utils/aria.js to goog.module

This commit is contained in:
Maribeth Bottorff
2021-07-14 17:33:01 -07:00
parent 0ceee1b775
commit 9afd937568
2 changed files with 21 additions and 19 deletions

View File

@@ -16,27 +16,22 @@
* @name Blockly.utils.aria
* @namespace
*/
goog.provide('Blockly.utils.aria');
goog.module('Blockly.utils.aria');
goog.module.declareLegacyNamespace();
/**
* ARIA states/properties prefix.
* @private
*/
Blockly.utils.aria.ARIA_PREFIX_ = 'aria-';
/** ARIA states/properties prefix. */
const ARIA_PREFIX = 'aria-';
/**
* ARIA role attribute.
* @private
*/
Blockly.utils.aria.ROLE_ATTRIBUTE_ = 'role';
/** ARIA role attribute. */
const ROLE_ATTRIBUTE = 'role';
/**
* ARIA role values.
* Copied from Closure's goog.a11y.aria.Role
* @enum {string}
*/
Blockly.utils.aria.Role = {
const Role = {
// ARIA role for an interactive control of tabular data.
GRID: 'grid',
@@ -80,7 +75,7 @@ Blockly.utils.aria.Role = {
* Copied from Closure's goog.a11y.aria.State
* @enum {string}
*/
Blockly.utils.aria.State = {
const State = {
// ARIA property for setting the currently active descendant of an element,
// for example the selected item in a list box. Value: ID of an element.
ACTIVEDESCENDANT: 'activedescendant',
@@ -148,24 +143,31 @@ Blockly.utils.aria.State = {
* @param {!Element} element DOM node to set role of.
* @param {!Blockly.utils.aria.Role} roleName Role name.
*/
Blockly.utils.aria.setRole = function(element, roleName) {
element.setAttribute(Blockly.utils.aria.ROLE_ATTRIBUTE_, roleName);
const setRole = function(element, roleName) {
element.setAttribute(ROLE_ATTRIBUTE, roleName);
};
/**
* Sets the state or property of an element.
* Copied from Closure's goog.a11y.aria
* @param {!Element} element DOM node where we set state.
* @param {!Blockly.utils.aria.State} stateName State attribute being set.
* @param {!State} stateName State attribute being set.
* Automatically adds prefix 'aria-' to the state name if the attribute is
* not an extra attribute.
* @param {string|boolean|number|!Array<string>} value Value
* for the state attribute.
*/
Blockly.utils.aria.setState = function(element, stateName, value) {
const setState = function(element, stateName, value) {
if (Array.isArray(value)) {
value = value.join(' ');
}
const attrStateName = Blockly.utils.aria.ARIA_PREFIX_ + stateName;
const attrStateName = ARIA_PREFIX + stateName;
element.setAttribute(attrStateName, value);
};
exports = {
Role,
State,
setRole,
setState,
};

View File

@@ -169,7 +169,7 @@ goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants
goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']);
goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'});
goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']);
goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []);
goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []);
goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []);
goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'});