From c1ca8cda15438fa10f17da5d0772624b293d3989 Mon Sep 17 00:00:00 2001 From: omarreiss Date: Wed, 27 Jul 2016 16:26:28 +0200 Subject: [PATCH 1/2] If another a11y-speak region already exists, use that one. --- a11y-speak.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/a11y-speak.js b/a11y-speak.js index bd6d06fe0aea19..4ffb59874b6b1b 100644 --- a/a11y-speak.js +++ b/a11y-speak.js @@ -1,5 +1,4 @@ -var containerPolite = null; -var containerAssertive = null; +var containerPolite, containerAssertive; /** * Build the live regions markup. @@ -43,11 +42,11 @@ var domReady = function( callback ) { * Create the live regions when the DOM is fully loaded. */ domReady( function() { - if ( containerPolite === null ) { + if ( containerPolite = document.getElementById('a11y-speak-polite') === null ) { containerPolite = addContainer( "polite" ); } - if ( containerAssertive === null ) { + if ( containerAssertive = document.getElementById('a11y-speak-assertive') === null ) { containerAssertive = addContainer( "assertive" ); } }); From f0c46999b6bd391a5472cbb817d7646aaf0f8843 Mon Sep 17 00:00:00 2001 From: omarreiss Date: Mon, 1 Aug 2016 15:01:32 +0200 Subject: [PATCH 2/2] improve readability and fix codestyle --- a11y-speak.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/a11y-speak.js b/a11y-speak.js index 4ffb59874b6b1b..189460379db588 100644 --- a/a11y-speak.js +++ b/a11y-speak.js @@ -29,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() { - if ( containerPolite = document.getElementById('a11y-speak-polite') === null ) { + containerPolite = document.getElementById( "a11y-speak-polite" ); + containerAssertive = document.getElementById( "a11y-speak-assertive" ); + + if ( containerPolite === null ) { containerPolite = addContainer( "polite" ); } - - if ( containerAssertive = document.getElementById('a11y-speak-assertive') === null ) { + if ( containerAssertive === null ) { containerAssertive = addContainer( "assertive" ); } -}); +} ); /** * Clear the live regions.