diff --git a/a11y-speak.js b/a11y-speak.js index 41dec7ee8610a..2383cb2da5908 100644 --- a/a11y-speak.js +++ b/a11y-speak.js @@ -1,4 +1,4 @@ -var containerPolite, containerAssertive; +var containerPolite, containerAssertive, previousMessage = ""; /** * Build the live regions markup. @@ -14,7 +14,7 @@ var addContainer = function( ariaLive ) { container.id = "a11y-speak-" + ariaLive; container.className = "a11y-speak-region"; - var screenReaderTextStyle = "clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden;"; + var screenReaderTextStyle = "clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden; word-wrap: normal;"; container.setAttribute( "style", screenReaderTextStyle ); container.setAttribute( "aria-live", ariaLive ); @@ -85,6 +85,12 @@ var A11ySpeak = function( message, ariaLive ) { */ message = message.replace( /<[^<>]+>/g, " " ); + if ( previousMessage === message ) { + message = message + "\u00A0"; + } + + previousMessage = message; + if ( containerAssertive && "assertive" === ariaLive ) { containerAssertive.textContent = message; } else if ( containerPolite ) { diff --git a/a11y-speak.min.js b/a11y-speak.min.js index 3eed26207e8b2..dc74062b687db 100644 --- a/a11y-speak.min.js +++ b/a11y-speak.min.js @@ -1 +1 @@ -var containerPolite,containerAssertive,addContainer=function(a){a=a||"polite";var b=document.createElement("div");b.id="a11y-speak-"+a,b.className="a11y-speak-region";var c="clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden;";return b.setAttribute("style",c),b.setAttribute("aria-live",a),b.setAttribute("aria-relevant","additions text"),b.setAttribute("aria-atomic","true"),document.querySelector("body").appendChild(b),b},domReady=function(a){return"complete"===document.readyState||"loading"!==document.readyState&&!document.documentElement.doScroll?a():void document.addEventListener("DOMContentLoaded",a)};domReady(function(){containerPolite=document.getElementById("a11y-speak-polite"),containerAssertive=document.getElementById("a11y-speak-assertive"),null===containerPolite&&(containerPolite=addContainer("polite")),null===containerAssertive&&(containerAssertive=addContainer("assertive"))});var clear=function(){for(var a=document.querySelectorAll(".a11y-speak-region"),b=0;b]+>/g," "),containerAssertive&&"assertive"===b?containerAssertive.textContent=a:containerPolite&&(containerPolite.textContent=a)};module.exports=A11ySpeak; \ No newline at end of file +var containerPolite,containerAssertive,previousMessage="",addContainer=function(a){a=a||"polite";var b=document.createElement("div");b.id="a11y-speak-"+a,b.className="a11y-speak-region";var c="clip: rect(1px, 1px, 1px, 1px); position: absolute; height: 1px; width: 1px; overflow: hidden; word-wrap: normal;";return b.setAttribute("style",c),b.setAttribute("aria-live",a),b.setAttribute("aria-relevant","additions text"),b.setAttribute("aria-atomic","true"),document.querySelector("body").appendChild(b),b},domReady=function(a){return"complete"===document.readyState||"loading"!==document.readyState&&!document.documentElement.doScroll?a():void document.addEventListener("DOMContentLoaded",a)};domReady(function(){containerPolite=document.getElementById("a11y-speak-polite"),containerAssertive=document.getElementById("a11y-speak-assertive"),null===containerPolite&&(containerPolite=addContainer("polite")),null===containerAssertive&&(containerAssertive=addContainer("assertive"))});var clear=function(){for(var a=document.querySelectorAll(".a11y-speak-region"),b=0;b]+>/g," "),previousMessage===a&&(a+=" "),previousMessage=a,containerAssertive&&"assertive"===b?containerAssertive.textContent=a:containerPolite&&(containerPolite.textContent=a)};module.exports=A11ySpeak; \ No newline at end of file