123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- goog.provide('goog.a11y.aria.Announcer');
- goog.require('goog.Disposable');
- goog.require('goog.Timer');
- goog.require('goog.a11y.aria');
- goog.require('goog.a11y.aria.LivePriority');
- goog.require('goog.a11y.aria.State');
- goog.require('goog.dom');
- goog.require('goog.dom.TagName');
- goog.require('goog.object');
- goog.a11y.aria.Announcer = function(opt_domHelper) {
- goog.a11y.aria.Announcer.base(this, 'constructor');
-
- this.domHelper_ = opt_domHelper || goog.dom.getDomHelper();
-
- this.liveRegions_ = {};
- };
- goog.inherits(goog.a11y.aria.Announcer, goog.Disposable);
- 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');
- };
- 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, '');
-
- goog.Timer.callOnce(function() {
- goog.dom.setTextContent(liveRegion, message);
- }, 1);
- };
- goog.a11y.aria.Announcer.prototype.getLiveRegion_ = function(priority) {
- var liveRegion = this.liveRegions_[priority];
- if (liveRegion) {
-
- goog.a11y.aria.removeState(liveRegion, goog.a11y.aria.State.HIDDEN);
- return liveRegion;
- }
- liveRegion = this.domHelper_.createElement(goog.dom.TagName.DIV);
-
-
- 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;
- };
|