Adding mapbox-gl branch
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
/**
|
||||
* @fileoverview Announcer that allows messages to be spoken by assistive
|
||||
* technologies.
|
||||
*/
|
||||
|
||||
goog.provide('goog.a11y.aria.Announcer');
|
||||
|
||||
goog.require('goog.Disposable');
|
||||
goog.require('goog.a11y.aria');
|
||||
goog.require('goog.a11y.aria.LivePriority');
|
||||
goog.require('goog.a11y.aria.State');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.object');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class that allows messages to be spoken by assistive technologies that the
|
||||
* user may have active.
|
||||
*
|
||||
* @param {goog.dom.DomHelper=} opt_domHelper DOM helper.
|
||||
* @constructor
|
||||
* @extends {goog.Disposable}
|
||||
* @final
|
||||
*/
|
||||
goog.a11y.aria.Announcer = function(opt_domHelper) {
|
||||
goog.a11y.aria.Announcer.base(this, 'constructor');
|
||||
|
||||
/**
|
||||
* @type {goog.dom.DomHelper}
|
||||
* @private
|
||||
*/
|
||||
this.domHelper_ = opt_domHelper || goog.dom.getDomHelper();
|
||||
|
||||
/**
|
||||
* Map of priority to live region elements to use for communicating updates.
|
||||
* Elements are created on demand.
|
||||
* @type {Object<goog.a11y.aria.LivePriority, !Element>}
|
||||
* @private
|
||||
*/
|
||||
this.liveRegions_ = {};
|
||||
};
|
||||
goog.inherits(goog.a11y.aria.Announcer, goog.Disposable);
|
||||
|
||||
|
||||
/** @override */
|
||||
goog.a11y.aria.Announcer.prototype.disposeInternal = function() {
|
||||
goog.object.forEach(
|
||||
this.liveRegions_, this.domHelper_.removeNode, this.domHelper_);
|
||||
this.liveRegions_ = null;
|
||||
this.domHelper_ = null;
|
||||
goog.a11y.aria.Announcer.base(this, 'disposeInternal');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Announce a message to be read by any assistive technologies the user may
|
||||
* have active.
|
||||
* @param {string} message The message to announce to screen readers.
|
||||
* @param {goog.a11y.aria.LivePriority=} opt_priority The priority of the
|
||||
* message. Defaults to POLITE.
|
||||
*/
|
||||
goog.a11y.aria.Announcer.prototype.say = function(message, opt_priority) {
|
||||
var priority = opt_priority || goog.a11y.aria.LivePriority.POLITE;
|
||||
var liveRegion = this.getLiveRegion_(priority);
|
||||
goog.dom.setTextContent(liveRegion, message);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns an aria-live region that can be used to communicate announcements.
|
||||
* @param {!goog.a11y.aria.LivePriority} priority The required priority.
|
||||
* @return {!Element} A live region of the requested priority.
|
||||
* @private
|
||||
*/
|
||||
goog.a11y.aria.Announcer.prototype.getLiveRegion_ = function(priority) {
|
||||
// Removing the previous live region ensures that the newest message is always
|
||||
// read without delay, even if the message is an exact duplicate of the prior
|
||||
// message.
|
||||
this.removeLiveRegion_(priority);
|
||||
|
||||
var liveRegion = this.domHelper_.createElement('div');
|
||||
// Note that IE has a habit of declaring things that aren't display:none as
|
||||
// invisible to third-party tools like JAWs, so we can't just use height:0.
|
||||
liveRegion.style.position = 'absolute';
|
||||
liveRegion.style.top = '-1000px';
|
||||
liveRegion.style.height = '1px';
|
||||
liveRegion.style.overflow = 'hidden';
|
||||
goog.a11y.aria.setState(liveRegion, goog.a11y.aria.State.LIVE,
|
||||
priority);
|
||||
goog.a11y.aria.setState(liveRegion, goog.a11y.aria.State.ATOMIC,
|
||||
'true');
|
||||
this.domHelper_.getDocument().body.appendChild(liveRegion);
|
||||
this.liveRegions_[priority] = liveRegion;
|
||||
return liveRegion;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Removes any previous live region that was used to communicate announcements.
|
||||
* @param {!goog.a11y.aria.LivePriority} priority The required priority.
|
||||
* @private
|
||||
*/
|
||||
goog.a11y.aria.Announcer.prototype.removeLiveRegion_ = function(priority) {
|
||||
var liveRegion = this.liveRegions_[priority];
|
||||
if (liveRegion) {
|
||||
this.domHelper_.removeNode(liveRegion);
|
||||
delete this.liveRegions_[priority];
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<!--
|
||||
Author: attila@google.com (Attila Bodis)
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.a11y.aria announcer
|
||||
</title>
|
||||
<script src="../../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.a11y.aria.AnnouncerTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="sandbox">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,129 @@
|
||||
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
goog.provide('goog.a11y.aria.AnnouncerTest');
|
||||
goog.setTestOnly('goog.a11y.aria.AnnouncerTest');
|
||||
|
||||
goog.require('goog.a11y.aria');
|
||||
goog.require('goog.a11y.aria.Announcer');
|
||||
goog.require('goog.a11y.aria.LivePriority');
|
||||
goog.require('goog.a11y.aria.State');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.iframe');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
var sandbox;
|
||||
var someDiv;
|
||||
var someSpan;
|
||||
|
||||
function setUp() {
|
||||
sandbox = goog.dom.getElement('sandbox');
|
||||
someDiv = goog.dom.createDom('div', {id: 'someDiv'}, 'DIV');
|
||||
someSpan = goog.dom.createDom('span', {id: 'someSpan'}, 'SPAN');
|
||||
sandbox.appendChild(someDiv);
|
||||
someDiv.appendChild(someSpan);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
sandbox.innerHTML = '';
|
||||
someDiv = null;
|
||||
someSpan = null;
|
||||
}
|
||||
|
||||
function testAnnouncerAndDispose() {
|
||||
var text = 'test content';
|
||||
var announcer = new goog.a11y.aria.Announcer(goog.dom.getDomHelper());
|
||||
announcer.say(text);
|
||||
checkLiveRegionContains(text, 'polite');
|
||||
goog.dispose(announcer);
|
||||
}
|
||||
|
||||
function testAnnouncerTwice() {
|
||||
var text = 'test content1';
|
||||
var text2 = 'test content2';
|
||||
var announcer = new goog.a11y.aria.Announcer(goog.dom.getDomHelper());
|
||||
announcer.say(text);
|
||||
announcer.say(text2);
|
||||
checkLiveRegionContains(text2, 'polite');
|
||||
goog.dispose(announcer);
|
||||
}
|
||||
|
||||
function testAnnouncerTwiceSameMessage() {
|
||||
var text = 'test content';
|
||||
var announcer = new goog.a11y.aria.Announcer(goog.dom.getDomHelper());
|
||||
announcer.say(text);
|
||||
var firstLiveRegion = getLiveRegion('polite');
|
||||
announcer.say(text);
|
||||
var secondLiveRegion = getLiveRegion('polite');
|
||||
assertNotEquals(firstLiveRegion, secondLiveRegion);
|
||||
checkLiveRegionContains(text, 'polite');
|
||||
goog.dispose(announcer);
|
||||
}
|
||||
|
||||
function testAnnouncerAssertive() {
|
||||
var text = 'test content';
|
||||
var announcer = new goog.a11y.aria.Announcer(goog.dom.getDomHelper());
|
||||
announcer.say(text, goog.a11y.aria.LivePriority.ASSERTIVE);
|
||||
checkLiveRegionContains(text, 'assertive');
|
||||
goog.dispose(announcer);
|
||||
}
|
||||
|
||||
function testAnnouncerInIframe() {
|
||||
var text = 'test content';
|
||||
var frame = goog.dom.iframe.createWithContent(sandbox);
|
||||
var helper = goog.dom.getDomHelper(
|
||||
goog.dom.getFrameContentDocument(frame).body);
|
||||
var announcer = new goog.a11y.aria.Announcer(helper);
|
||||
announcer.say(text, 'polite', helper);
|
||||
checkLiveRegionContains(text, 'polite', helper);
|
||||
goog.dispose(announcer);
|
||||
}
|
||||
|
||||
function testAnnouncerWithAriaHidden() {
|
||||
var text = 'test content1';
|
||||
var text2 = 'test content2';
|
||||
var announcer = new goog.a11y.aria.Announcer(goog.dom.getDomHelper());
|
||||
announcer.say(text);
|
||||
// Set aria-hidden attribute on the live region (simulates a modal dialog
|
||||
// being opened).
|
||||
var liveRegion = getLiveRegion('polite');
|
||||
goog.a11y.aria.setState(liveRegion, goog.a11y.aria.State.HIDDEN, true);
|
||||
|
||||
// Announce a new message and make sure that the aria-hidden was removed.
|
||||
announcer.say(text2);
|
||||
checkLiveRegionContains(text2, 'polite');
|
||||
liveRegion = getLiveRegion('polite');
|
||||
assertEquals('',
|
||||
goog.a11y.aria.getState(liveRegion, goog.a11y.aria.State.HIDDEN));
|
||||
goog.dispose(announcer);
|
||||
}
|
||||
|
||||
function getLiveRegion(priority, opt_domHelper) {
|
||||
var dom = opt_domHelper || goog.dom.getDomHelper();
|
||||
var divs = dom.getElementsByTagNameAndClass('div', null);
|
||||
var liveRegions = [];
|
||||
goog.array.forEach(divs, function(div) {
|
||||
if (goog.a11y.aria.getState(div, 'live') == priority) {
|
||||
liveRegions.push(div);
|
||||
}
|
||||
});
|
||||
assertEquals(1, liveRegions.length);
|
||||
return liveRegions[0];
|
||||
}
|
||||
|
||||
function checkLiveRegionContains(text, priority, opt_domHelper) {
|
||||
var liveRegion = getLiveRegion(priority, opt_domHelper);
|
||||
assertEquals(text, goog.dom.getTextContent(liveRegion));
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
/**
|
||||
* @fileoverview Utilities for adding, removing and setting ARIA roles and
|
||||
* states as defined by W3C ARIA standard: http://www.w3.org/TR/wai-aria/
|
||||
* All modern browsers have some form of ARIA support, so no browser checks are
|
||||
* performed when adding ARIA to components.
|
||||
*
|
||||
*/
|
||||
|
||||
goog.provide('goog.a11y.aria');
|
||||
|
||||
goog.require('goog.a11y.aria.Role');
|
||||
goog.require('goog.a11y.aria.State');
|
||||
goog.require('goog.a11y.aria.datatables');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.object');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
* ARIA states/properties prefix.
|
||||
* @private
|
||||
*/
|
||||
goog.a11y.aria.ARIA_PREFIX_ = 'aria-';
|
||||
|
||||
|
||||
/**
|
||||
* ARIA role attribute.
|
||||
* @private
|
||||
*/
|
||||
goog.a11y.aria.ROLE_ATTRIBUTE_ = 'role';
|
||||
|
||||
|
||||
/**
|
||||
* A list of tag names for which we don't need to set ARIA role and states
|
||||
* because they have well supported semantics for screen readers or because
|
||||
* they don't contain content to be made accessible.
|
||||
* @private
|
||||
*/
|
||||
goog.a11y.aria.TAGS_WITH_ASSUMED_ROLES_ = [
|
||||
goog.dom.TagName.A,
|
||||
goog.dom.TagName.AREA,
|
||||
goog.dom.TagName.BUTTON,
|
||||
goog.dom.TagName.HEAD,
|
||||
goog.dom.TagName.INPUT,
|
||||
goog.dom.TagName.LINK,
|
||||
goog.dom.TagName.MENU,
|
||||
goog.dom.TagName.META,
|
||||
goog.dom.TagName.OPTGROUP,
|
||||
goog.dom.TagName.OPTION,
|
||||
goog.dom.TagName.PROGRESS,
|
||||
goog.dom.TagName.STYLE,
|
||||
goog.dom.TagName.SELECT,
|
||||
goog.dom.TagName.SOURCE,
|
||||
goog.dom.TagName.TEXTAREA,
|
||||
goog.dom.TagName.TITLE,
|
||||
goog.dom.TagName.TRACK
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Sets the role of an element. If the roleName is
|
||||
* empty string or null, the role for the element is removed.
|
||||
* We encourage clients to call the goog.a11y.aria.removeRole
|
||||
* method instead of setting null and empty string values.
|
||||
* Special handling for this case is added to ensure
|
||||
* backword compatibility with existing code.
|
||||
*
|
||||
* @param {!Element} element DOM node to set role of.
|
||||
* @param {!goog.a11y.aria.Role|string} roleName role name(s).
|
||||
*/
|
||||
goog.a11y.aria.setRole = function(element, roleName) {
|
||||
if (!roleName) {
|
||||
// Setting the ARIA role to empty string is not allowed
|
||||
// by the ARIA standard.
|
||||
goog.a11y.aria.removeRole(element);
|
||||
} else {
|
||||
if (goog.asserts.ENABLE_ASSERTS) {
|
||||
goog.asserts.assert(goog.object.containsValue(
|
||||
goog.a11y.aria.Role, roleName), 'No such ARIA role ' + roleName);
|
||||
}
|
||||
element.setAttribute(goog.a11y.aria.ROLE_ATTRIBUTE_, roleName);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets role of an element.
|
||||
* @param {!Element} element DOM element to get role of.
|
||||
* @return {goog.a11y.aria.Role} ARIA Role name.
|
||||
*/
|
||||
goog.a11y.aria.getRole = function(element) {
|
||||
var role = element.getAttribute(goog.a11y.aria.ROLE_ATTRIBUTE_);
|
||||
return /** @type {goog.a11y.aria.Role} */ (role) || null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Removes role of an element.
|
||||
* @param {!Element} element DOM element to remove the role from.
|
||||
*/
|
||||
goog.a11y.aria.removeRole = function(element) {
|
||||
element.removeAttribute(goog.a11y.aria.ROLE_ATTRIBUTE_);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the state or property of an element.
|
||||
* @param {!Element} element DOM node where we set state.
|
||||
* @param {!(goog.a11y.aria.State|string)} 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.
|
||||
*/
|
||||
goog.a11y.aria.setState = function(element, stateName, value) {
|
||||
if (goog.isArray(value)) {
|
||||
value = value.join(' ');
|
||||
}
|
||||
var attrStateName = goog.a11y.aria.getAriaAttributeName_(stateName);
|
||||
if (value === '' || value == undefined) {
|
||||
var defaultValueMap = goog.a11y.aria.datatables.getDefaultValuesMap();
|
||||
// Work around for browsers that don't properly support ARIA.
|
||||
// According to the ARIA W3C standard, user agents should allow
|
||||
// setting empty value which results in setting the default value
|
||||
// for the ARIA state if such exists. The exact text from the ARIA W3C
|
||||
// standard (http://www.w3.org/TR/wai-aria/states_and_properties):
|
||||
// "When a value is indicated as the default, the user agent
|
||||
// MUST follow the behavior prescribed by this value when the state or
|
||||
// property is empty or undefined."
|
||||
// The defaultValueMap contains the default values for the ARIA states
|
||||
// and has as a key the goog.a11y.aria.State constant for the state.
|
||||
if (stateName in defaultValueMap) {
|
||||
element.setAttribute(attrStateName, defaultValueMap[stateName]);
|
||||
} else {
|
||||
element.removeAttribute(attrStateName);
|
||||
}
|
||||
} else {
|
||||
element.setAttribute(attrStateName, value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Toggles the ARIA attribute of an element.
|
||||
* Meant for attributes with a true/false value, but works with any attribute.
|
||||
* If the attribute does not have a true/false value, the following rules apply:
|
||||
* A not empty attribute will be removed.
|
||||
* An empty attribute will be set to true.
|
||||
* @param {!Element} el DOM node for which to set attribute.
|
||||
* @param {!(goog.a11y.aria.State|string)} attr ARIA attribute being set.
|
||||
* Automatically adds prefix 'aria-' to the attribute name if the attribute
|
||||
* is not an extra attribute.
|
||||
*/
|
||||
goog.a11y.aria.toggleState = function(el, attr) {
|
||||
var val = goog.a11y.aria.getState(el, attr);
|
||||
if (!goog.string.isEmptyOrWhitespace(goog.string.makeSafe(val)) &&
|
||||
!(val == 'true' || val == 'false')) {
|
||||
goog.a11y.aria.removeState(el, /** @type {!goog.a11y.aria.State} */ (attr));
|
||||
return;
|
||||
}
|
||||
goog.a11y.aria.setState(el, attr, val == 'true' ? 'false' : 'true');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Remove the state or property for the element.
|
||||
* @param {!Element} element DOM node where we set state.
|
||||
* @param {!goog.a11y.aria.State} stateName State name.
|
||||
*/
|
||||
goog.a11y.aria.removeState = function(element, stateName) {
|
||||
element.removeAttribute(goog.a11y.aria.getAriaAttributeName_(stateName));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets value of specified state or property.
|
||||
* @param {!Element} element DOM node to get state from.
|
||||
* @param {!goog.a11y.aria.State|string} stateName State name.
|
||||
* @return {string} Value of the state attribute.
|
||||
*/
|
||||
goog.a11y.aria.getState = function(element, stateName) {
|
||||
// TODO(user): return properly typed value result --
|
||||
// boolean, number, string, null. We should be able to chain
|
||||
// getState(...) and setState(...) methods.
|
||||
|
||||
var attr =
|
||||
/** @type {string|number|boolean} */ (element.getAttribute(
|
||||
goog.a11y.aria.getAriaAttributeName_(stateName)));
|
||||
var isNullOrUndefined = attr == null || attr == undefined;
|
||||
return isNullOrUndefined ? '' : String(attr);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the activedescendant element for the input element by
|
||||
* using the activedescendant ARIA property of the given element.
|
||||
* @param {!Element} element DOM node to get activedescendant
|
||||
* element for.
|
||||
* @return {?Element} DOM node of the activedescendant, if found.
|
||||
*/
|
||||
goog.a11y.aria.getActiveDescendant = function(element) {
|
||||
var id = goog.a11y.aria.getState(
|
||||
element, goog.a11y.aria.State.ACTIVEDESCENDANT);
|
||||
return goog.dom.getOwnerDocument(element).getElementById(id);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the activedescendant ARIA property value for an element.
|
||||
* If the activeElement is not null, it should have an id set.
|
||||
* @param {!Element} element DOM node to set activedescendant ARIA property to.
|
||||
* @param {?Element} activeElement DOM node being set as activedescendant.
|
||||
*/
|
||||
goog.a11y.aria.setActiveDescendant = function(element, activeElement) {
|
||||
var id = '';
|
||||
if (activeElement) {
|
||||
id = activeElement.id;
|
||||
goog.asserts.assert(id, 'The active element should have an id.');
|
||||
}
|
||||
|
||||
goog.a11y.aria.setState(element, goog.a11y.aria.State.ACTIVEDESCENDANT, id);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets the label of the given element.
|
||||
* @param {!Element} element DOM node to get label from.
|
||||
* @return {string} label The label.
|
||||
*/
|
||||
goog.a11y.aria.getLabel = function(element) {
|
||||
return goog.a11y.aria.getState(element, goog.a11y.aria.State.LABEL);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the label of the given element.
|
||||
* @param {!Element} element DOM node to set label to.
|
||||
* @param {string} label The label to set.
|
||||
*/
|
||||
goog.a11y.aria.setLabel = function(element, label) {
|
||||
goog.a11y.aria.setState(element, goog.a11y.aria.State.LABEL, label);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that the element has a role set if it's not an HTML element whose
|
||||
* semantics is well supported by most screen readers.
|
||||
* Only to be used internally by the ARIA library in goog.a11y.aria.*.
|
||||
* @param {!Element} element The element to assert an ARIA role set.
|
||||
* @param {!goog.array.ArrayLike<string>} allowedRoles The child roles of
|
||||
* the roles.
|
||||
*/
|
||||
goog.a11y.aria.assertRoleIsSetInternalUtil = function(element, allowedRoles) {
|
||||
if (goog.array.contains(goog.a11y.aria.TAGS_WITH_ASSUMED_ROLES_,
|
||||
element.tagName)) {
|
||||
return;
|
||||
}
|
||||
var elementRole = /** @type {string}*/ (goog.a11y.aria.getRole(element));
|
||||
goog.asserts.assert(elementRole != null,
|
||||
'The element ARIA role cannot be null.');
|
||||
|
||||
goog.asserts.assert(goog.array.contains(allowedRoles, elementRole),
|
||||
'Non existing or incorrect role set for element.' +
|
||||
'The role set is "' + elementRole +
|
||||
'". The role should be any of "' + allowedRoles +
|
||||
'". Check the ARIA specification for more details ' +
|
||||
'http://www.w3.org/TR/wai-aria/roles.');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets the boolean value of an ARIA state/property.
|
||||
* @param {!Element} element The element to get the ARIA state for.
|
||||
* @param {!goog.a11y.aria.State|string} stateName the ARIA state name.
|
||||
* @return {?boolean} Boolean value for the ARIA state value or null if
|
||||
* the state value is not 'true', not 'false', or not set.
|
||||
*/
|
||||
goog.a11y.aria.getStateBoolean = function(element, stateName) {
|
||||
var attr =
|
||||
/** @type {string|boolean} */ (element.getAttribute(
|
||||
goog.a11y.aria.getAriaAttributeName_(stateName)));
|
||||
goog.asserts.assert(
|
||||
goog.isBoolean(attr) || attr == null || attr == 'true' ||
|
||||
attr == 'false');
|
||||
if (attr == null) {
|
||||
return attr;
|
||||
}
|
||||
return goog.isBoolean(attr) ? attr : attr == 'true';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number value of an ARIA state/property.
|
||||
* @param {!Element} element The element to get the ARIA state for.
|
||||
* @param {!goog.a11y.aria.State|string} stateName the ARIA state name.
|
||||
* @return {?number} Number value for the ARIA state value or null if
|
||||
* the state value is not a number or not set.
|
||||
*/
|
||||
goog.a11y.aria.getStateNumber = function(element, stateName) {
|
||||
var attr =
|
||||
/** @type {string|number} */ (element.getAttribute(
|
||||
goog.a11y.aria.getAriaAttributeName_(stateName)));
|
||||
goog.asserts.assert((attr == null || !isNaN(Number(attr))) &&
|
||||
!goog.isBoolean(attr));
|
||||
return attr == null ? null : Number(attr);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets the string value of an ARIA state/property.
|
||||
* @param {!Element} element The element to get the ARIA state for.
|
||||
* @param {!goog.a11y.aria.State|string} stateName the ARIA state name.
|
||||
* @return {?string} String value for the ARIA state value or null if
|
||||
* the state value is empty string or not set.
|
||||
*/
|
||||
goog.a11y.aria.getStateString = function(element, stateName) {
|
||||
var attr = element.getAttribute(
|
||||
goog.a11y.aria.getAriaAttributeName_(stateName));
|
||||
goog.asserts.assert((attr == null || goog.isString(attr)) &&
|
||||
isNaN(Number(attr)) && attr != 'true' && attr != 'false');
|
||||
return attr == null ? null : attr;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets array of strings value of the specified state or
|
||||
* property for the element.
|
||||
* Only to be used internally by the ARIA library in goog.a11y.aria.*.
|
||||
* @param {!Element} element DOM node to get state from.
|
||||
* @param {!goog.a11y.aria.State} stateName State name.
|
||||
* @return {!goog.array.ArrayLike<string>} string Array
|
||||
* value of the state attribute.
|
||||
*/
|
||||
goog.a11y.aria.getStringArrayStateInternalUtil = function(element, stateName) {
|
||||
var attrValue = element.getAttribute(
|
||||
goog.a11y.aria.getAriaAttributeName_(stateName));
|
||||
return goog.a11y.aria.splitStringOnWhitespace_(attrValue);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Splits the input stringValue on whitespace.
|
||||
* @param {string} stringValue The value of the string to split.
|
||||
* @return {!goog.array.ArrayLike<string>} string Array
|
||||
* value as result of the split.
|
||||
* @private
|
||||
*/
|
||||
goog.a11y.aria.splitStringOnWhitespace_ = function(stringValue) {
|
||||
return stringValue ? stringValue.split(/\s+/) : [];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Adds the 'aria-' prefix to ariaName.
|
||||
* @param {string} ariaName ARIA state/property name.
|
||||
* @private
|
||||
* @return {string} The ARIA attribute name with added 'aria-' prefix.
|
||||
* @throws {Error} If no such attribute exists.
|
||||
*/
|
||||
goog.a11y.aria.getAriaAttributeName_ = function(ariaName) {
|
||||
if (goog.asserts.ENABLE_ASSERTS) {
|
||||
goog.asserts.assert(ariaName, 'ARIA attribute cannot be empty.');
|
||||
goog.asserts.assert(goog.object.containsValue(
|
||||
goog.a11y.aria.State, ariaName),
|
||||
'No such ARIA attribute ' + ariaName);
|
||||
}
|
||||
return goog.a11y.aria.ARIA_PREFIX_ + ariaName;
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<!--
|
||||
Author: attila@google.com (Attila Bodis)
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.a11y.aria
|
||||
</title>
|
||||
<script src="../../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.a11y.ariaTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="sandbox">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,269 @@
|
||||
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.goog.provide('goog.a11y.ariaTest');
|
||||
|
||||
goog.provide('goog.a11y.ariaTest');
|
||||
goog.setTestOnly('goog.a11y.ariaTest');
|
||||
|
||||
goog.require('goog.a11y.aria');
|
||||
goog.require('goog.a11y.aria.Role');
|
||||
goog.require('goog.a11y.aria.State');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
var aria = goog.a11y.aria;
|
||||
var Role = goog.a11y.aria.Role;
|
||||
var State = goog.a11y.aria.State;
|
||||
var sandbox;
|
||||
var someDiv;
|
||||
var someSpan;
|
||||
var htmlButton;
|
||||
|
||||
function setUp() {
|
||||
sandbox = goog.dom.getElement('sandbox');
|
||||
someDiv = goog.dom.createDom(
|
||||
goog.dom.TagName.DIV, {id: 'someDiv'}, 'DIV');
|
||||
someSpan = goog.dom.createDom(
|
||||
goog.dom.TagName.SPAN, {id: 'someSpan'}, 'SPAN');
|
||||
htmlButton = goog.dom.createDom(
|
||||
goog.dom.TagName.BUTTON, {id: 'someButton'}, 'BUTTON');
|
||||
goog.dom.appendChild(sandbox, someDiv);
|
||||
goog.dom.appendChild(someDiv, someSpan);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
goog.dom.removeChildren(sandbox);
|
||||
someDiv = null;
|
||||
someSpan = null;
|
||||
htmlButton = null;
|
||||
}
|
||||
|
||||
function testGetSetRole() {
|
||||
assertNull('someDiv\'s role should be null', aria.getRole(someDiv));
|
||||
assertNull('someSpan\'s role should be null', aria.getRole(someSpan));
|
||||
|
||||
aria.setRole(someDiv, Role.MENU);
|
||||
aria.setRole(someSpan, Role.MENU_ITEM);
|
||||
|
||||
assertEquals('someDiv\'s role should be MENU',
|
||||
Role.MENU, aria.getRole(someDiv));
|
||||
assertEquals('someSpan\'s role should be MENU_ITEM',
|
||||
Role.MENU_ITEM, aria.getRole(someSpan));
|
||||
|
||||
var div = goog.dom.createElement(goog.dom.TagName.DIV);
|
||||
goog.dom.appendChild(sandbox, div);
|
||||
goog.dom.appendChild(div, goog.dom.createDom(goog.dom.TagName.SPAN,
|
||||
{id: 'anotherSpan', role: Role.CHECKBOX}));
|
||||
assertEquals('anotherSpan\'s role should be CHECKBOX',
|
||||
Role.CHECKBOX, aria.getRole(goog.dom.getElement('anotherSpan')));
|
||||
}
|
||||
|
||||
function testGetSetToggleState() {
|
||||
assertThrows('Should throw because no state is specified.',
|
||||
function() {
|
||||
aria.getState(someDiv);
|
||||
});
|
||||
assertThrows('Should throw because no state is specified.',
|
||||
function() {
|
||||
aria.getState(someDiv);
|
||||
});
|
||||
aria.setState(someDiv, State.LABELLEDBY, 'someSpan');
|
||||
|
||||
assertEquals('someDiv\'s labelledby state should be "someSpan"',
|
||||
'someSpan', aria.getState(someDiv, State.LABELLEDBY));
|
||||
|
||||
// Test setting for aria-activedescendant with empty value.
|
||||
assertFalse(someDiv.hasAttribute ?
|
||||
someDiv.hasAttribute('aria-activedescendant') :
|
||||
!!someDiv.getAttribute('aria-activedescendant'));
|
||||
aria.setState(someDiv, State.ACTIVEDESCENDANT, 'someSpan');
|
||||
assertEquals('someSpan', aria.getState(someDiv, State.ACTIVEDESCENDANT));
|
||||
aria.setState(someDiv, State.ACTIVEDESCENDANT, '');
|
||||
assertFalse(someDiv.hasAttribute ?
|
||||
someDiv.hasAttribute('aria-activedescendant') :
|
||||
!!someDiv.getAttribute('aria-activedescendant'));
|
||||
|
||||
// Test setting state that has a default value to empty value.
|
||||
assertFalse(someDiv.hasAttribute ?
|
||||
someDiv.hasAttribute('aria-relevant') :
|
||||
!!someDiv.getAttribute('aria-relevant'));
|
||||
aria.setState(someDiv, State.RELEVANT, aria.RelevantValues.TEXT);
|
||||
assertEquals(
|
||||
aria.RelevantValues.TEXT, aria.getState(someDiv, State.RELEVANT));
|
||||
aria.setState(someDiv, State.RELEVANT, '');
|
||||
assertEquals(
|
||||
aria.RelevantValues.ADDITIONS + ' ' + aria.RelevantValues.TEXT,
|
||||
aria.getState(someDiv, State.RELEVANT));
|
||||
|
||||
// Test toggling an attribute that has a true/false value.
|
||||
aria.setState(someDiv, State.EXPANDED, false);
|
||||
assertEquals('false', aria.getState(someDiv, State.EXPANDED));
|
||||
aria.toggleState(someDiv, State.EXPANDED);
|
||||
assertEquals('true', aria.getState(someDiv, State.EXPANDED));
|
||||
aria.setState(someDiv, State.EXPANDED, true);
|
||||
assertEquals('true', aria.getState(someDiv, State.EXPANDED));
|
||||
aria.toggleState(someDiv, State.EXPANDED);
|
||||
assertEquals('false', aria.getState(someDiv, State.EXPANDED));
|
||||
|
||||
// Test toggling an attribute that does not have a true/false value.
|
||||
aria.setState(someDiv, State.RELEVANT, aria.RelevantValues.TEXT);
|
||||
assertEquals(
|
||||
aria.RelevantValues.TEXT, aria.getState(someDiv, State.RELEVANT));
|
||||
aria.toggleState(someDiv, State.RELEVANT);
|
||||
assertEquals('', aria.getState(someDiv, State.RELEVANT));
|
||||
aria.removeState(someDiv, State.RELEVANT);
|
||||
assertEquals('', aria.getState(someDiv, State.RELEVANT));
|
||||
// This is not a valid value, but this is what happens if toggle is misused.
|
||||
aria.toggleState(someDiv, State.RELEVANT);
|
||||
assertEquals('true', aria.getState(someDiv, State.RELEVANT));
|
||||
}
|
||||
|
||||
function testGetStateString() {
|
||||
aria.setState(someDiv, State.LABEL, 'test_label');
|
||||
aria.setState(
|
||||
someSpan, State.LABEL, aria.getStateString(someDiv, State.LABEL));
|
||||
assertEquals(aria.getState(someDiv, State.LABEL),
|
||||
aria.getState(someSpan, State.LABEL));
|
||||
assertEquals('The someDiv\'s enum value should be "test_label".',
|
||||
'test_label', aria.getState(someDiv, State.LABEL));
|
||||
assertEquals('The someSpan\'s enum value should be "copy move".',
|
||||
'test_label', aria.getStateString(someSpan, State.LABEL));
|
||||
aria.setState(someDiv, State.MULTILINE, true);
|
||||
var thrown = false;
|
||||
try {
|
||||
aria.getStateString(someDiv, State.MULTILINE);
|
||||
} catch (e) {
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue('invalid use of getStateString on boolean.', thrown);
|
||||
aria.setState(someDiv, State.LIVE, aria.LivePriority.ASSERTIVE);
|
||||
thrown = false;
|
||||
aria.setState(someDiv, State.LEVEL, 1);
|
||||
try {
|
||||
aria.getStateString(someDiv, State.LEVEL);
|
||||
} catch (e) {
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue('invalid use of getStateString on numbers.', thrown);
|
||||
}
|
||||
|
||||
|
||||
function testGetStateStringArray() {
|
||||
aria.setState(someDiv, State.LABELLEDBY, ['1', '2']);
|
||||
aria.setState(someSpan, State.LABELLEDBY,
|
||||
aria.getStringArrayStateInternalUtil(someDiv, State.LABELLEDBY));
|
||||
assertEquals(aria.getState(someDiv, State.LABELLEDBY),
|
||||
aria.getState(someSpan, State.LABELLEDBY));
|
||||
|
||||
assertEquals('The someDiv\'s enum value should be "1 2".', '1 2',
|
||||
aria.getState(someDiv, State.LABELLEDBY));
|
||||
assertEquals('The someSpan\'s enum value should be "1 2".', '1 2',
|
||||
aria.getState(someSpan, State.LABELLEDBY));
|
||||
|
||||
assertSameElements('The someDiv\'s enum value should be "1 2".',
|
||||
['1', '2'],
|
||||
aria.getStringArrayStateInternalUtil(someDiv, State.LABELLEDBY));
|
||||
assertSameElements('The someSpan\'s enum value should be "1 2".',
|
||||
['1', '2'],
|
||||
aria.getStringArrayStateInternalUtil(someSpan, State.LABELLEDBY));
|
||||
}
|
||||
|
||||
|
||||
function testGetStateNumber() {
|
||||
aria.setState(someDiv, State.LEVEL, 1);
|
||||
aria.setState(
|
||||
someSpan, State.LEVEL, aria.getStateNumber(someDiv, State.LEVEL));
|
||||
assertEquals(aria.getState(someDiv, State.LEVEL),
|
||||
aria.getState(someSpan, State.LEVEL));
|
||||
assertEquals('The someDiv\'s enum value should be "1".', '1',
|
||||
aria.getState(someDiv, State.LEVEL));
|
||||
assertEquals('The someSpan\'s enum value should be "1".', '1',
|
||||
aria.getState(someSpan, State.LEVEL));
|
||||
assertEquals('The someDiv\'s enum value should be "1".', 1,
|
||||
aria.getStateNumber(someDiv, State.LEVEL));
|
||||
assertEquals('The someSpan\'s enum value should be "1".', 1,
|
||||
aria.getStateNumber(someSpan, State.LEVEL));
|
||||
aria.setState(someDiv, State.MULTILINE, true);
|
||||
var thrown = false;
|
||||
try {
|
||||
aria.getStateNumber(someDiv, State.MULTILINE);
|
||||
} catch (e) {
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue('invalid use of getStateNumber on boolean.', thrown);
|
||||
aria.setState(someDiv, State.LIVE, aria.LivePriority.ASSERTIVE);
|
||||
thrown = false;
|
||||
try {
|
||||
aria.getStateBoolean(someDiv, State.LIVE);
|
||||
} catch (e) {
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue('invalid use of getStateNumber on strings.', thrown);
|
||||
}
|
||||
|
||||
function testGetStateBoolean() {
|
||||
assertNull(aria.getStateBoolean(someDiv, State.MULTILINE));
|
||||
|
||||
aria.setState(someDiv, State.MULTILINE, false);
|
||||
assertFalse(aria.getStateBoolean(someDiv, State.MULTILINE));
|
||||
|
||||
aria.setState(someDiv, State.MULTILINE, true);
|
||||
aria.setState(someSpan, State.MULTILINE,
|
||||
aria.getStateBoolean(someDiv, State.MULTILINE));
|
||||
assertEquals(aria.getState(someDiv, State.MULTILINE),
|
||||
aria.getState(someSpan, State.MULTILINE));
|
||||
assertEquals('The someDiv\'s enum value should be "true".', 'true',
|
||||
aria.getState(someDiv, State.MULTILINE));
|
||||
assertEquals('The someSpan\'s enum value should be "true".', 'true',
|
||||
aria.getState(someSpan, State.MULTILINE));
|
||||
assertEquals('The someDiv\'s enum value should be "true".', true,
|
||||
aria.getStateBoolean(someDiv, State.MULTILINE));
|
||||
assertEquals('The someSpan\'s enum value should be "true".', true,
|
||||
aria.getStateBoolean(someSpan, State.MULTILINE));
|
||||
aria.setState(someDiv, State.LEVEL, 1);
|
||||
var thrown = false;
|
||||
try {
|
||||
aria.getStateBoolean(someDiv, State.LEVEL);
|
||||
} catch (e) {
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue('invalid use of getStateBoolean on numbers.', thrown);
|
||||
aria.setState(someDiv, State.LIVE, aria.LivePriority.ASSERTIVE);
|
||||
thrown = false;
|
||||
try {
|
||||
aria.getStateBoolean(someDiv, State.LIVE);
|
||||
} catch (e) {
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue('invalid use of getStateBoolean on strings.', thrown);
|
||||
}
|
||||
|
||||
function testGetSetActiveDescendant() {
|
||||
aria.setActiveDescendant(someDiv, null);
|
||||
assertNull('someDiv\'s activedescendant should be null',
|
||||
aria.getActiveDescendant(someDiv));
|
||||
|
||||
aria.setActiveDescendant(someDiv, someSpan);
|
||||
|
||||
assertEquals('someDiv\'s active descendant should be "someSpan"',
|
||||
someSpan, aria.getActiveDescendant(someDiv));
|
||||
}
|
||||
|
||||
function testGetSetLabel() {
|
||||
assertEquals('someDiv\'s label should be ""', '', aria.getLabel(someDiv));
|
||||
|
||||
aria.setLabel(someDiv, 'somelabel');
|
||||
assertEquals('someDiv\'s label should be "somelabel"', 'somelabel',
|
||||
aria.getLabel(someDiv));
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
// Copyright 2013 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
/**
|
||||
* @fileoverview The file contains generated enumerations for ARIA states
|
||||
* and properties as defined by W3C ARIA standard:
|
||||
* http://www.w3.org/TR/wai-aria/.
|
||||
*
|
||||
* This is auto-generated code. Do not manually edit! For more details
|
||||
* about how to edit it via the generator check go/closure-ariagen.
|
||||
*/
|
||||
|
||||
goog.provide('goog.a11y.aria.AutoCompleteValues');
|
||||
goog.provide('goog.a11y.aria.CheckedValues');
|
||||
goog.provide('goog.a11y.aria.DropEffectValues');
|
||||
goog.provide('goog.a11y.aria.ExpandedValues');
|
||||
goog.provide('goog.a11y.aria.GrabbedValues');
|
||||
goog.provide('goog.a11y.aria.InvalidValues');
|
||||
goog.provide('goog.a11y.aria.LivePriority');
|
||||
goog.provide('goog.a11y.aria.OrientationValues');
|
||||
goog.provide('goog.a11y.aria.PressedValues');
|
||||
goog.provide('goog.a11y.aria.RelevantValues');
|
||||
goog.provide('goog.a11y.aria.SelectedValues');
|
||||
goog.provide('goog.a11y.aria.SortValues');
|
||||
goog.provide('goog.a11y.aria.State');
|
||||
|
||||
|
||||
/**
|
||||
* ARIA states and properties.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.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',
|
||||
|
||||
// ARIA property that, if true, indicates that all of a changed region should
|
||||
// be presented, instead of only parts. Value: one of {true, false}.
|
||||
ATOMIC: 'atomic',
|
||||
|
||||
// ARIA property to specify that input completion is provided. Value:
|
||||
// one of {'inline', 'list', 'both', 'none'}.
|
||||
AUTOCOMPLETE: 'autocomplete',
|
||||
|
||||
// ARIA state to indicate that an element and its subtree are being updated.
|
||||
// Value: one of {true, false}.
|
||||
BUSY: 'busy',
|
||||
|
||||
// ARIA state for a checked item. Value: one of {'true', 'false', 'mixed',
|
||||
// undefined}.
|
||||
CHECKED: 'checked',
|
||||
|
||||
// ARIA property that identifies the element or elements whose contents or
|
||||
// presence are controlled by this element.
|
||||
// Value: space-separated IDs of other elements.
|
||||
CONTROLS: 'controls',
|
||||
|
||||
// ARIA property that identifies the element or elements that describe
|
||||
// this element. Value: space-separated IDs of other elements.
|
||||
DESCRIBEDBY: 'describedby',
|
||||
|
||||
// ARIA state for a disabled item. Value: one of {true, false}.
|
||||
DISABLED: 'disabled',
|
||||
|
||||
// ARIA property that indicates what functions can be performed when a
|
||||
// dragged object is released on the drop target. Value: one of
|
||||
// {'copy', 'move', 'link', 'execute', 'popup', 'none'}.
|
||||
DROPEFFECT: 'dropeffect',
|
||||
|
||||
// ARIA state for setting whether the element like a tree node is expanded.
|
||||
// Value: one of {true, false, undefined}.
|
||||
EXPANDED: 'expanded',
|
||||
|
||||
// ARIA property that identifies the next element (or elements) in the
|
||||
// recommended reading order of content. Value: space-separated ids of
|
||||
// elements to flow to.
|
||||
FLOWTO: 'flowto',
|
||||
|
||||
// ARIA state that indicates an element's "grabbed" state in drag-and-drop.
|
||||
// Value: one of {true, false, undefined}.
|
||||
GRABBED: 'grabbed',
|
||||
|
||||
// ARIA property indicating whether the element has a popup.
|
||||
// Value: one of {true, false}.
|
||||
HASPOPUP: 'haspopup',
|
||||
|
||||
// ARIA state indicating that the element is not visible or perceivable
|
||||
// to any user. Value: one of {true, false}.
|
||||
HIDDEN: 'hidden',
|
||||
|
||||
// ARIA state indicating that the entered value does not conform. Value:
|
||||
// one of {false, true, 'grammar', 'spelling'}
|
||||
INVALID: 'invalid',
|
||||
|
||||
// ARIA property that provides a label to override any other text, value, or
|
||||
// contents used to describe this element. Value: string.
|
||||
LABEL: 'label',
|
||||
|
||||
// ARIA property for setting the element which labels another element.
|
||||
// Value: space-separated IDs of elements.
|
||||
LABELLEDBY: 'labelledby',
|
||||
|
||||
// ARIA property for setting the level of an element in the hierarchy.
|
||||
// Value: integer.
|
||||
LEVEL: 'level',
|
||||
|
||||
// ARIA property indicating that an element will be updated, and
|
||||
// describes the types of updates the user agents, assistive technologies,
|
||||
// and user can expect from the live region. Value: one of {'off', 'polite',
|
||||
// 'assertive'}.
|
||||
LIVE: 'live',
|
||||
|
||||
// ARIA property indicating whether a text box can accept multiline input.
|
||||
// Value: one of {true, false}.
|
||||
MULTILINE: 'multiline',
|
||||
|
||||
// ARIA property indicating if the user may select more than one item.
|
||||
// Value: one of {true, false}.
|
||||
MULTISELECTABLE: 'multiselectable',
|
||||
|
||||
// ARIA property indicating if the element is horizontal or vertical.
|
||||
// Value: one of {'vertical', 'horizontal'}.
|
||||
ORIENTATION: 'orientation',
|
||||
|
||||
// ARIA property creating a visual, functional, or contextual parent/child
|
||||
// relationship when the DOM hierarchy can't be used to represent it.
|
||||
// Value: Space-separated IDs of elements.
|
||||
OWNS: 'owns',
|
||||
|
||||
// ARIA property that defines an element's number of position in a list.
|
||||
// Value: integer.
|
||||
POSINSET: 'posinset',
|
||||
|
||||
// ARIA state for a pressed item.
|
||||
// Value: one of {true, false, undefined, 'mixed'}.
|
||||
PRESSED: 'pressed',
|
||||
|
||||
// ARIA property indicating that an element is not editable.
|
||||
// Value: one of {true, false}.
|
||||
READONLY: 'readonly',
|
||||
|
||||
// ARIA property indicating that change notifications within this subtree
|
||||
// of a live region should be announced. Value: one of {'additions',
|
||||
// 'removals', 'text', 'all', 'additions text'}.
|
||||
RELEVANT: 'relevant',
|
||||
|
||||
// ARIA property indicating that user input is required on this element
|
||||
// before a form may be submitted. Value: one of {true, false}.
|
||||
REQUIRED: 'required',
|
||||
|
||||
// ARIA state for setting the currently selected item in the list.
|
||||
// Value: one of {true, false, undefined}.
|
||||
SELECTED: 'selected',
|
||||
|
||||
// ARIA property defining the number of items in a list. Value: integer.
|
||||
SETSIZE: 'setsize',
|
||||
|
||||
// ARIA property indicating if items are sorted. Value: one of {'ascending',
|
||||
// 'descending', 'none', 'other'}.
|
||||
SORT: 'sort',
|
||||
|
||||
// ARIA property for slider maximum value. Value: number.
|
||||
VALUEMAX: 'valuemax',
|
||||
|
||||
// ARIA property for slider minimum value. Value: number.
|
||||
VALUEMIN: 'valuemin',
|
||||
|
||||
// ARIA property for slider active value. Value: number.
|
||||
VALUENOW: 'valuenow',
|
||||
|
||||
// ARIA property for slider active value represented as text.
|
||||
// Value: string.
|
||||
VALUETEXT: 'valuetext'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for AutoCompleteValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.AutoCompleteValues = {
|
||||
// The system provides text after the caret as a suggestion
|
||||
// for how to complete the field.
|
||||
INLINE: 'inline',
|
||||
// A list of choices appears from which the user can choose,
|
||||
// but the edit box retains focus.
|
||||
LIST: 'list',
|
||||
// A list of choices appears and the currently selected suggestion
|
||||
// also appears inline.
|
||||
BOTH: 'both',
|
||||
// No input completion suggestions are provided.
|
||||
NONE: 'none'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for DropEffectValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.DropEffectValues = {
|
||||
// A duplicate of the source object will be dropped into the target.
|
||||
COPY: 'copy',
|
||||
// The source object will be removed from its current location
|
||||
// and dropped into the target.
|
||||
MOVE: 'move',
|
||||
// A reference or shortcut to the dragged object
|
||||
// will be created in the target object.
|
||||
LINK: 'link',
|
||||
// A function supported by the drop target is
|
||||
// executed, using the drag source as an input.
|
||||
EXECUTE: 'execute',
|
||||
// There is a popup menu or dialog that allows the user to choose
|
||||
// one of the drag operations (copy, move, link, execute) and any other
|
||||
// drag functionality, such as cancel.
|
||||
POPUP: 'popup',
|
||||
// No operation can be performed; effectively
|
||||
// cancels the drag operation if an attempt is made to drop on this object.
|
||||
NONE: 'none'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for LivePriority.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.LivePriority = {
|
||||
// Updates to the region will not be presented to the user
|
||||
// unless the assitive technology is currently focused on that region.
|
||||
OFF: 'off',
|
||||
// (Background change) Assistive technologies SHOULD announce
|
||||
// updates at the next graceful opportunity, such as at the end of
|
||||
// speaking the current sentence or when the user pauses typing.
|
||||
POLITE: 'polite',
|
||||
// This information has the highest priority and assistive
|
||||
// technologies SHOULD notify the user immediately.
|
||||
// Because an interruption may disorient users or cause them to not complete
|
||||
// their current task, authors SHOULD NOT use the assertive value unless the
|
||||
// interruption is imperative.
|
||||
ASSERTIVE: 'assertive'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for OrientationValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.OrientationValues = {
|
||||
// The element is oriented vertically.
|
||||
VERTICAL: 'vertical',
|
||||
// The element is oriented horizontally.
|
||||
HORIZONTAL: 'horizontal'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for RelevantValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.RelevantValues = {
|
||||
// Element nodes are added to the DOM within the live region.
|
||||
ADDITIONS: 'additions',
|
||||
// Text or element nodes within the live region are removed from the DOM.
|
||||
REMOVALS: 'removals',
|
||||
// Text is added to any DOM descendant nodes of the live region.
|
||||
TEXT: 'text',
|
||||
// Equivalent to the combination of all values, "additions removals text".
|
||||
ALL: 'all'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for SortValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.SortValues = {
|
||||
// Items are sorted in ascending order by this column.
|
||||
ASCENDING: 'ascending',
|
||||
// Items are sorted in descending order by this column.
|
||||
DESCENDING: 'descending',
|
||||
// There is no defined sort applied to the column.
|
||||
NONE: 'none',
|
||||
// A sort algorithm other than ascending or descending has been applied.
|
||||
OTHER: 'other'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for CheckedValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.CheckedValues = {
|
||||
// The selectable element is checked.
|
||||
TRUE: 'true',
|
||||
// The selectable element is not checked.
|
||||
FALSE: 'false',
|
||||
// Indicates a mixed mode value for a tri-state
|
||||
// checkbox or menuitemcheckbox.
|
||||
MIXED: 'mixed',
|
||||
// The element does not support being checked.
|
||||
UNDEFINED: 'undefined'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for ExpandedValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.ExpandedValues = {
|
||||
// The element, or another grouping element it controls, is expanded.
|
||||
TRUE: 'true',
|
||||
// The element, or another grouping element it controls, is collapsed.
|
||||
FALSE: 'false',
|
||||
// The element, or another grouping element
|
||||
// it controls, is neither expandable nor collapsible; all its
|
||||
// child elements are shown or there are no child elements.
|
||||
UNDEFINED: 'undefined'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for GrabbedValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.GrabbedValues = {
|
||||
// Indicates that the element has been "grabbed" for dragging.
|
||||
TRUE: 'true',
|
||||
// Indicates that the element supports being dragged.
|
||||
FALSE: 'false',
|
||||
// Indicates that the element does not support being dragged.
|
||||
UNDEFINED: 'undefined'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for InvalidValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.InvalidValues = {
|
||||
// There are no detected errors in the value.
|
||||
FALSE: 'false',
|
||||
// The value entered by the user has failed validation.
|
||||
TRUE: 'true',
|
||||
// A grammatical error was detected.
|
||||
GRAMMAR: 'grammar',
|
||||
// A spelling error was detected.
|
||||
SPELLING: 'spelling'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for PressedValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.PressedValues = {
|
||||
// The element is pressed.
|
||||
TRUE: 'true',
|
||||
// The element supports being pressed but is not currently pressed.
|
||||
FALSE: 'false',
|
||||
// Indicates a mixed mode value for a tri-state toggle button.
|
||||
MIXED: 'mixed',
|
||||
// The element does not support being pressed.
|
||||
UNDEFINED: 'undefined'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ARIA state values for SelectedValues.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.SelectedValues = {
|
||||
// The selectable element is selected.
|
||||
TRUE: 'true',
|
||||
// The selectable element is not selected.
|
||||
FALSE: 'false',
|
||||
// The element is not selectable.
|
||||
UNDEFINED: 'undefined'
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
// Copyright 2013 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @fileoverview The file contains data tables generated from the ARIA
|
||||
* standard schema http://www.w3.org/TR/wai-aria/.
|
||||
*
|
||||
* This is auto-generated code. Do not manually edit!
|
||||
*/
|
||||
|
||||
goog.provide('goog.a11y.aria.datatables');
|
||||
|
||||
goog.require('goog.a11y.aria.State');
|
||||
goog.require('goog.object');
|
||||
|
||||
|
||||
/**
|
||||
* A map that contains mapping between an ARIA state and the default value
|
||||
* for it. Note that not all ARIA states have default values.
|
||||
*
|
||||
* @type {Object<!(goog.a11y.aria.State|string), (string|boolean|number)>}
|
||||
*/
|
||||
goog.a11y.aria.DefaultStateValueMap_;
|
||||
|
||||
|
||||
/**
|
||||
* A method that creates a map that contains mapping between an ARIA state and
|
||||
* the default value for it. Note that not all ARIA states have default values.
|
||||
*
|
||||
* @return {!Object<!(goog.a11y.aria.State|string), (string|boolean|number)>}
|
||||
* The names for each of the notification methods.
|
||||
*/
|
||||
goog.a11y.aria.datatables.getDefaultValuesMap = function() {
|
||||
if (!goog.a11y.aria.DefaultStateValueMap_) {
|
||||
goog.a11y.aria.DefaultStateValueMap_ = goog.object.create(
|
||||
goog.a11y.aria.State.ATOMIC, false,
|
||||
goog.a11y.aria.State.AUTOCOMPLETE, 'none',
|
||||
goog.a11y.aria.State.DROPEFFECT, 'none',
|
||||
goog.a11y.aria.State.HASPOPUP, false,
|
||||
goog.a11y.aria.State.LIVE, 'off',
|
||||
goog.a11y.aria.State.MULTILINE, false,
|
||||
goog.a11y.aria.State.MULTISELECTABLE, false,
|
||||
goog.a11y.aria.State.ORIENTATION, 'vertical',
|
||||
goog.a11y.aria.State.READONLY, false,
|
||||
goog.a11y.aria.State.RELEVANT, 'additions text',
|
||||
goog.a11y.aria.State.REQUIRED, false,
|
||||
goog.a11y.aria.State.SORT, 'none',
|
||||
goog.a11y.aria.State.BUSY, false,
|
||||
goog.a11y.aria.State.DISABLED, false,
|
||||
goog.a11y.aria.State.HIDDEN, false,
|
||||
goog.a11y.aria.State.INVALID, 'false');
|
||||
}
|
||||
|
||||
return goog.a11y.aria.DefaultStateValueMap_;
|
||||
};
|
||||
@@ -0,0 +1,216 @@
|
||||
// Copyright 2013 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
/**
|
||||
* @fileoverview The file contains generated enumerations for ARIA roles
|
||||
* as defined by W3C ARIA standard: http://www.w3.org/TR/wai-aria/.
|
||||
*
|
||||
* This is auto-generated code. Do not manually edit! For more details
|
||||
* about how to edit it via the generator check go/closure-ariagen.
|
||||
*/
|
||||
|
||||
goog.provide('goog.a11y.aria.Role');
|
||||
|
||||
|
||||
/**
|
||||
* ARIA role values.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.a11y.aria.Role = {
|
||||
// ARIA role for an alert element that doesn't need to be explicitly closed.
|
||||
ALERT: 'alert',
|
||||
|
||||
// ARIA role for an alert dialog element that takes focus and must be closed.
|
||||
ALERTDIALOG: 'alertdialog',
|
||||
|
||||
// ARIA role for an application that implements its own keyboard navigation.
|
||||
APPLICATION: 'application',
|
||||
|
||||
// ARIA role for an article.
|
||||
ARTICLE: 'article',
|
||||
|
||||
// ARIA role for a banner containing mostly site content, not page content.
|
||||
BANNER: 'banner',
|
||||
|
||||
// ARIA role for a button element.
|
||||
BUTTON: 'button',
|
||||
|
||||
// ARIA role for a checkbox button element; use with the CHECKED state.
|
||||
CHECKBOX: 'checkbox',
|
||||
|
||||
// ARIA role for a column header of a table or grid.
|
||||
COLUMNHEADER: 'columnheader',
|
||||
|
||||
// ARIA role for a combo box element.
|
||||
COMBOBOX: 'combobox',
|
||||
|
||||
// ARIA role for a supporting section of the document.
|
||||
COMPLEMENTARY: 'complementary',
|
||||
|
||||
// ARIA role for a large perceivable region that contains information
|
||||
// about the parent document.
|
||||
CONTENTINFO: 'contentinfo',
|
||||
|
||||
// ARIA role for a definition of a term or concept.
|
||||
DEFINITION: 'definition',
|
||||
|
||||
// ARIA role for a dialog, some descendant must take initial focus.
|
||||
DIALOG: 'dialog',
|
||||
|
||||
// ARIA role for a directory, like a table of contents.
|
||||
DIRECTORY: 'directory',
|
||||
|
||||
// ARIA role for a part of a page that's a document, not a web application.
|
||||
DOCUMENT: 'document',
|
||||
|
||||
// ARIA role for a landmark region logically considered one form.
|
||||
FORM: 'form',
|
||||
|
||||
// ARIA role for an interactive control of tabular data.
|
||||
GRID: 'grid',
|
||||
|
||||
// ARIA role for a cell in a grid.
|
||||
GRIDCELL: 'gridcell',
|
||||
|
||||
// ARIA role for a group of related elements like tree item siblings.
|
||||
GROUP: 'group',
|
||||
|
||||
// ARIA role for a heading element.
|
||||
HEADING: 'heading',
|
||||
|
||||
// ARIA role for a container of elements that together comprise one image.
|
||||
IMG: 'img',
|
||||
|
||||
// ARIA role for a link.
|
||||
LINK: 'link',
|
||||
|
||||
// ARIA role for a list of non-interactive list items.
|
||||
LIST: 'list',
|
||||
|
||||
// ARIA role for a listbox.
|
||||
LISTBOX: 'listbox',
|
||||
|
||||
// ARIA role for a list item.
|
||||
LISTITEM: 'listitem',
|
||||
|
||||
// ARIA role for a live region where new information is added.
|
||||
LOG: 'log',
|
||||
|
||||
// ARIA landmark role for the main content in a document. Use only once.
|
||||
MAIN: 'main',
|
||||
|
||||
// ARIA role for a live region of non-essential information that changes.
|
||||
MARQUEE: 'marquee',
|
||||
|
||||
// ARIA role for a mathematical expression.
|
||||
MATH: 'math',
|
||||
|
||||
// ARIA role for a popup menu.
|
||||
MENU: 'menu',
|
||||
|
||||
// ARIA role for a menubar element containing menu elements.
|
||||
MENUBAR: 'menubar',
|
||||
|
||||
// ARIA role for menu item elements.
|
||||
MENU_ITEM: 'menuitem',
|
||||
|
||||
// ARIA role for a checkbox box element inside a menu.
|
||||
MENU_ITEM_CHECKBOX: 'menuitemcheckbox',
|
||||
|
||||
// ARIA role for a radio button element inside a menu.
|
||||
MENU_ITEM_RADIO: 'menuitemradio',
|
||||
|
||||
// ARIA landmark role for a collection of navigation links.
|
||||
NAVIGATION: 'navigation',
|
||||
|
||||
// ARIA role for a section ancillary to the main content.
|
||||
NOTE: 'note',
|
||||
|
||||
// ARIA role for option items that are children of combobox, listbox, menu,
|
||||
// radiogroup, or tree elements.
|
||||
OPTION: 'option',
|
||||
|
||||
// ARIA role for ignorable cosmetic elements with no semantic significance.
|
||||
PRESENTATION: 'presentation',
|
||||
|
||||
// ARIA role for a progress bar element.
|
||||
PROGRESSBAR: 'progressbar',
|
||||
|
||||
// ARIA role for a radio button element.
|
||||
RADIO: 'radio',
|
||||
|
||||
// ARIA role for a group of connected radio button elements.
|
||||
RADIOGROUP: 'radiogroup',
|
||||
|
||||
// ARIA role for an important region of the page.
|
||||
REGION: 'region',
|
||||
|
||||
// ARIA role for a row of cells in a grid.
|
||||
ROW: 'row',
|
||||
|
||||
// ARIA role for a group of one or more rows in a grid.
|
||||
ROWGROUP: 'rowgroup',
|
||||
|
||||
// ARIA role for a row header of a table or grid.
|
||||
ROWHEADER: 'rowheader',
|
||||
|
||||
// ARIA role for a scrollbar element.
|
||||
SCROLLBAR: 'scrollbar',
|
||||
|
||||
// ARIA landmark role for a part of the page providing search functionality.
|
||||
SEARCH: 'search',
|
||||
|
||||
// ARIA role for a menu separator.
|
||||
SEPARATOR: 'separator',
|
||||
|
||||
// ARIA role for a slider.
|
||||
SLIDER: 'slider',
|
||||
|
||||
// ARIA role for a spin button.
|
||||
SPINBUTTON: 'spinbutton',
|
||||
|
||||
// ARIA role for a live region with advisory info less severe than an alert.
|
||||
STATUS: 'status',
|
||||
|
||||
// ARIA role for a tab button.
|
||||
TAB: 'tab',
|
||||
|
||||
// ARIA role for a tab bar (i.e. a list of tab buttons).
|
||||
TAB_LIST: 'tablist',
|
||||
|
||||
// ARIA role for a tab page (i.e. the element holding tab contents).
|
||||
TAB_PANEL: 'tabpanel',
|
||||
|
||||
// ARIA role for a textbox element.
|
||||
TEXTBOX: 'textbox',
|
||||
|
||||
// ARIA role for an element displaying elapsed time or time remaining.
|
||||
TIMER: 'timer',
|
||||
|
||||
// ARIA role for a toolbar element.
|
||||
TOOLBAR: 'toolbar',
|
||||
|
||||
// ARIA role for a tooltip element.
|
||||
TOOLTIP: 'tooltip',
|
||||
|
||||
// ARIA role for a tree.
|
||||
TREE: 'tree',
|
||||
|
||||
// ARIA role for a grid whose rows can be expanded and collapsed like a tree.
|
||||
TREEGRID: 'treegrid',
|
||||
|
||||
// ARIA role for a tree item that sometimes may be expanded or collapsed.
|
||||
TREEITEM: 'treeitem'
|
||||
};
|
||||
Reference in New Issue
Block a user