From 9afd937568cb7302cbc50b7f1d63bed33a7575fa Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Wed, 14 Jul 2021 17:33:01 -0700 Subject: [PATCH] Migrate core/utils/aria.js to goog.module --- core/utils/aria.js | 38 ++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/core/utils/aria.js b/core/utils/aria.js index b75b7e3cd..464ba77b0 100644 --- a/core/utils/aria.js +++ b/core/utils/aria.js @@ -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} 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, +}; diff --git a/tests/deps.js b/tests/deps.js index ecc86147d..3f6eae7a5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -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'});