-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[common] added 'speach' module for screen reader
- Loading branch information
1 parent
91de30f
commit d9a44cf
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
| ||
const helper = function() { | ||
let $elem; | ||
|
||
const set_enabled = function(enabled) { | ||
if ( enabled ) { | ||
if ( !$elem ) { | ||
if ( ($elem = $('div[aria-live]')).length == 0 ) { | ||
const tmpl = '<div aria-live="assertive" class="sr-only" style=""></div>' | ||
$elem = $(tmpl).appendTo($('body')); | ||
} | ||
} | ||
} else { | ||
if ( $elem ) { | ||
$elem.remove($elem); | ||
$elem = undefined; | ||
} | ||
} | ||
} | ||
|
||
const set_text_to_speech = function(text) { | ||
if ( !$elem ){ | ||
set_enabled(true); | ||
} | ||
|
||
$elem.text(''); | ||
setTimeout(e => { | ||
$elem.text(text); | ||
}, 0); | ||
} | ||
|
||
return { | ||
setEnabled: set_enabled, | ||
disable: function() { set_enabled(false); }, | ||
speech: set_text_to_speech, | ||
} | ||
} | ||
|
||
!window.Common && (window.Common = {}); | ||
!Common.Utils && (Common.Utils = {}); | ||
|
||
Common.Utils.ScreeenReaderHelper = new helper(); |