diff --git a/a11y-speak.js b/a11y-speak.js index 189460379db588..41dec7ee8610a1 100644 --- a/a11y-speak.js +++ b/a11y-speak.js @@ -76,6 +76,15 @@ var A11ySpeak = function( message, ariaLive ) { // Clear previous messages to allow repeated strings being read out. clear(); + /* + * Strip HTML tags (if any) from the message string. Ideally, messages should + * be simple strings, carefully crafted for specific use with A11ySpeak. + * When re-using already existing strings this will ensure simple HTML to be + * stripped out and replaced with a space. Browsers will collapse multiple + * spaces natively. + */ + message = message.replace( /<[^<>]+>/g, " " ); + if ( containerAssertive && "assertive" === ariaLive ) { containerAssertive.textContent = message; } else if ( containerPolite ) { diff --git a/a11y-speak.min.js b/a11y-speak.min.js index 5525154152558d..3eed26207e8b2e 100644 --- a/a11y-speak.min.js +++ b/a11y-speak.min.js @@ -1 +1 @@ -var containerPolite=null,containerAssertive=null,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){"complete"===document.readyState||"loading"!==document.readyState&&!document.documentElement.doScroll?a():document.addEventListener("DOMContentLoaded",a)};domReady(function(){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