diff options
| author | hallgren <hallgren@chalmers.se> | 2015-05-27 13:28:40 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2015-05-27 13:28:40 +0000 |
| commit | 75aa394dc14bb26703f0043a0b41e1e076d38198 (patch) | |
| tree | 471e102aea1a8b81a813d0380f7df6184bc4bcd9 /src/www/minibar/minibar_support.js | |
| parent | baf9fc576c8242485b9bb019b3eed670f954cbcc (diff) | |
minibar: moved 2 reusable functions from minibar_translations.js to minibar_support.js
Diffstat (limited to 'src/www/minibar/minibar_support.js')
| -rw-r--r-- | src/www/minibar/minibar_support.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/www/minibar/minibar_support.js b/src/www/minibar/minibar_support.js index 412271842..1448df8a2 100644 --- a/src/www/minibar/minibar_support.js +++ b/src/www/minibar/minibar_support.js @@ -61,3 +61,35 @@ function open_popup(url,target) { } function opener_element(id) { with(window.opener) return element(id); } + +function supportsSVG() { + return document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") +} + +function speech_buttons(to3,to2,txt) { + var voices = window.speechSynthesis && window.speechSynthesis.getVoices() || [] + var dvs = voices.filter(function(v){return v.default}) + if(to2) + var pick=function (v) { return v.lang==to2 } + else { + var to2dash=alangcode(to3)+"-" + var pick=function(v) { return hasPrefix(v.lang,to2dash) } + } + function btn(v) { + var u=new SpeechSynthesisUtterance(txt) + u.lang=v.lang // how to use v.voiceURI or v.name? + + function speak() { + speechSynthesis.cancel() + speechSynthesis.speak(u) + } + return button(v.lang,speak) + } + //console.log(voices.length,"voices") + var vs=dvs.filter(pick) + if(vs.length==0) vs=voices.filter(pick) + //console.log(vs.length,"voices for "+to3+" "+to2) + var btns=vs.map(btn) + //console.log(btns.length,"voice buttons") + return wrap("span",btns) +} |
