Skip to content

Commit

Permalink
Merge pull request #8 from Yoast/stories/OR/shared-regions
Browse files Browse the repository at this point in the history
Share ARIA live regions between multiple instances of A11ySpeak
  • Loading branch information
atimmer committed Aug 26, 2016
2 parents 2a12bfd + f0c4699 commit 20c58f4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions a11y-speak.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var containerPolite = null;
var containerAssertive = null;
var containerPolite, containerAssertive;

/**
* Build the live regions markup.
Expand Down Expand Up @@ -30,27 +29,31 @@ var addContainer = function( ariaLive ) {
* Specify a function to execute when the DOM is fully loaded.
*
* @param {Function} callback A function to execute after the DOM is ready.
*
* @returns {void}
*/
var domReady = function( callback ) {
if ( document.readyState === "complete" || ( document.readyState !== "loading" && ! document.documentElement.doScroll ) ) {
callback();
} else {
document.addEventListener( "DOMContentLoaded", callback );
if ( document.readyState === "complete" || ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
return callback();
}

document.addEventListener( "DOMContentLoaded", callback );
};

/**
* Create the live regions when the DOM is fully loaded.
*/
domReady( function() {
containerPolite = document.getElementById( "a11y-speak-polite" );
containerAssertive = document.getElementById( "a11y-speak-assertive" );

if ( containerPolite === null ) {
containerPolite = addContainer( "polite" );
}

if ( containerAssertive === null ) {
containerAssertive = addContainer( "assertive" );
}
});
} );

/**
* Clear the live regions.
Expand Down

0 comments on commit 20c58f4

Please sign in to comment.