Skip to content

Commit

Permalink
Merge pull request #12 from Yoast/stories/af/11-repeated-messages-saf…
Browse files Browse the repository at this point in the history
…ari-voiceover

Append a no-break space to repeated messages.
  • Loading branch information
moorscode authored Apr 19, 2017
2 parents a968fff + 969f3bc commit 4e77280
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions a11y-speak.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var containerPolite, containerAssertive;
var containerPolite, containerAssertive, previousMessage = "";

/**
* Build the live regions markup.
Expand All @@ -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 );
Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion a11y-speak.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e77280

Please sign in to comment.