@angular2-material/core
Version:
Angular 2 Material core
57 lines (55 loc) • 3.16 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
import { Injectable, OpaqueToken, Optional, Inject } from '@angular/core';
export var LIVE_ANNOUNCER_ELEMENT_TOKEN = new OpaqueToken('mdLiveAnnouncerElement');
export var MdLiveAnnouncer = (function () {
function MdLiveAnnouncer(elementToken) {
// We inject the live element as `any` because the constructor signature cannot reference
// browser globals (HTMLElement) on non-browser environments, since having a class decorator
// causes TypeScript to preserve the constructor signature types.
this._liveElement = elementToken || this._createLiveElement();
}
/**
* @param message Message to be announced to the screenreader
* @param politeness The politeness of the announcer element.
*/
MdLiveAnnouncer.prototype.announce = function (message, politeness) {
var _this = this;
if (politeness === void 0) { politeness = 'polite'; }
this._liveElement.textContent = '';
// TODO: ensure changing the politeness works on all environments we support.
this._liveElement.setAttribute('aria-live', politeness);
// This 100ms timeout is necessary for some browser + screen-reader combinations:
// - Both JAWS and NVDA over IE11 will not announce anything without a non-zero timeout.
// - With Chrome and IE11 with NVDA or JAWS, a repeated (identical) message won't be read a
// second time without clearing and then using a non-zero delay.
// (using JAWS 17 at time of this writing).
setTimeout(function () { return _this._liveElement.textContent = message; }, 100);
};
MdLiveAnnouncer.prototype._createLiveElement = function () {
var liveEl = document.createElement('div');
liveEl.classList.add('md-live-announcer');
liveEl.setAttribute('aria-atomic', 'true');
liveEl.setAttribute('aria-live', 'polite');
document.body.appendChild(liveEl);
return liveEl;
};
MdLiveAnnouncer = __decorate([
Injectable(),
__param(0, Optional()),
__param(0, Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN)),
__metadata('design:paramtypes', [Object])
], MdLiveAnnouncer);
return MdLiveAnnouncer;
}());
//# sourceMappingURL=live-announcer.js.map