3
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
Code distributed by Google as part of the polymer project is also
8
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11
<link rel="import" href="../polymer/polymer.html">
14
`iron-a11y-announcer` is a singleton element that is intended to add a11y
15
to features that require on-demand announcement from screen readers. In
16
order to make use of the announcer, it is best to request its availability
17
in the announcing element.
25
attached: function() {
26
// This will create the singleton element if it has not
28
Polymer.IronA11yAnnouncer.requestAvailability();
32
After the `iron-a11y-announcer` has been made available, elements can
33
make announces by firing bubbling `iron-announce` events.
37
this.fire('iron-announce', {
38
text: 'This is an announcement!'
39
}, { bubbles: true });
41
Note: announcements are only audible if you have a screen reader enabled.
47
<dom-module id="iron-a11y-announcer">
50
display: inline-block;
52
clip: rect(0px,0px,0px,0px);
57
<div aria-live$="[[mode]]">[[_text]]</div>
65
Polymer.IronA11yAnnouncer = Polymer({
66
is: 'iron-a11y-announcer',
71
* The value of mode is used to set the `aria-live` attribute
72
* for the element that will be announced. Valid values are: `off`,
73
* `polite` and `assertive`.
87
if (!Polymer.IronA11yAnnouncer.instance) {
88
Polymer.IronA11yAnnouncer.instance = this;
91
document.body.addEventListener('iron-announce', this._onIronAnnounce.bind(this));
95
* Cause a text string to be announced by screen readers.
97
* @param {string} text The text that should be announced.
99
announce: function(text) {
101
this.async(function() {
106
_onIronAnnounce: function(event) {
107
if (event.detail && event.detail.text) {
108
this.announce(event.detail.text);
113
Polymer.IronA11yAnnouncer.instance = null;
115
Polymer.IronA11yAnnouncer.requestAvailability = function() {
116
if (!Polymer.IronA11yAnnouncer.instance) {
117
Polymer.IronA11yAnnouncer.instance = document.createElement('iron-a11y-announcer');
120
document.body.appendChild(Polymer.IronA11yAnnouncer.instance);