diff --git a/README.md b/README.md index 214e2cc..ba91e38 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Accessibility +## Accessibility >Add **accessibility toolbar** to your website with one line of code! ![Alt text](https://raw.githubusercontent.com/ranbuch/accessibility/master/accessibility.png "accessibility icon") @@ -33,11 +33,12 @@ initialize component: new Accessibility(); }, false);` -### LIMITATIONS: +### LIMITATIONS & KNOWN ISSUES: * Works with html5 brousers only (no IE8 and below) -* Text to speech works in supported brousers and languages only +* Text to speech & speech to text works in supported brousers and languages only +* Gray hues is disabled in firefox due to a bug in firefox browser and will be enabled when it will be fixed -### multi language example: +### MULTI LANGUAGE EXAMPLE: `var labels = {` `menuTitle: 'title (in my language)', @@ -52,9 +53,10 @@ initialize component: `var options = { labels: labels };` `options.textToSpeechLang = 'en-US'; // or any other language` +`options.speechToTextLang = 'en-US'; // or any other language` `new Accessibility(options);` -### disable features example: +### DISABLE FEATURES EXAMPLE: `options.modules = {` `increaseText: [true/false],` `decreaseText: [true/false],` @@ -67,10 +69,14 @@ initialize component: >When the default is **true** -### text size manipulation approaches +### TEXT SIZE MANIPULATION APPROACHES: If text increase / decrease isn't working for your size your probablly not using responsive font size units (sutch as em, rem etc.). In that case you can initialize the accessibility tool like this: `new Accessibility({textPixelMode: true})` -### LICENSE +### ANIMATIONS: +cancel menu buttons animations: +`new Accessibility({animations: {buttons: false}})` + +### LICENSE: [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://spdx.org/licenses/MIT) \ No newline at end of file diff --git a/dist/accessibility.min.js b/dist/accessibility.min.js index 58586a0..19f6364 100644 --- a/dist/accessibility.min.js +++ b/dist/accessibility.min.js @@ -1 +1 @@ -!function(e){function t(i){if(n[i])return n[i].exports;var s=n[i]={exports:{},id:i,loaded:!1};return e[i].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}var s=n(1),o=i(s);window.Accessibility=o["default"]},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n-1&&(c["default"].warn("grayHues isn't supported in firefox"),this.options.modules.grayHues=!1)}},{key:"injectCss",value:function(){var e="\n ._access-icon {\n position: fixed;\n background-repeat: no-repeat;\n background-size: contain;\n cursor: pointer;\n opacity: 0;\n transition-duration: .5s;\n }\n ._access-menu {\n position: fixed;\n width: "+this.options.menu.dimensions.width.size+this.options.menu.dimensions.width.units+";\n height: "+this.options.menu.dimensions.height.size+this.options.menu.dimensions.height.units+";\n transition-duration: .5s;\n z-index: "+this.options.icon.zIndex+"1;\n opacity: 1;\n background-color: #fff;\n color: #000;\n border-radius: 3px;\n border: solid 2px gray;\n font-family: "+this.options.menu.fontFamily+";\n min-width: 300px;\n box-shadow: -2px -2px 3px #aaa;\n max-height: 100vh;\n "+("rtl"==getComputedStyle(this.body).direction?"text-indent: -5px":"")+"\n }\n ._access-menu.close {\n z-index: -1;\n width: 0;\n opacity: 0;\n background-color: transparent;\n }\n ._access-menu.bottom {\n bottom: 0;\n }\n ._access-menu.top {\n top: 0;\n }\n ._access-menu.left {\n left: 0;\n }\n ._access-menu.close.left {\n left: -"+this.options.menu.dimensions.width.size+this.options.menu.dimensions.width.units+";\n }\n ._access-menu.right {\n right: 0;\n }\n ._access-menu.close.right {\n right: -"+this.options.menu.dimensions.width.size+this.options.menu.dimensions.width.units+";\n }\n ._access-menu ._text-center {\n text-align: center;\n }\n ._access-menu h3 {\n font-size: 24px !important; \n margin-top: 20px;\n margin-bottom: 20px;\n padding: 0;\n }\n ._access-menu ._menu-close-btn {\n left: 5px;\n color: #d63c3c;\n }\n ._access-menu ._menu-reset-btn {\n right: 5px;\n color: #4054b2;\n }\n ._access-menu ._menu-btn {\n position: absolute;\n top: 5px;\n cursor: pointer;\n font-size: 24px !important;\n font-weight: bold;\n }\n ._access-menu ul {\n padding: 0;\n position: relative;\n font-size: 18px !important;\n margin: 0;\n }\n ._access-menu ul li {\n list-style-type: none;\n cursor: pointer;\n -ms-user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n user-select: none;\n border: solid 1px black;\n padding: 10px 0 10px 30px;\n margin: 5px;\n border-radius: 4px;\n transition-duration: .3s;\n font-size: 18px !important;\n line-height: 18px !important;\n text-indent: 5px;\n }\n ._access-menu ul li.active, ._access-menu ul li.active:hover {\n color: #fff;\n background-color: #000;\n }\n ._access-menu ul li:hover {\n color: #fff;\n background-color: #444;\n }\n ._access-menu ul li.not-supported {\n display: none;\n }\n ._access-menu ul li:before {\n content: ' ';\n font-family: 'Material Icons';\n text-rendering: optimizeLegibility;\n font-feature-settings: \"liga\" 1;\n font-style: normal;\n text-transform: none;\n line-height: 1;\n font-size: 24px !important;\n width: 24px;\n height: 24px;\n display: inline-block;\n overflow: hidden;\n -webkit-font-smoothing: antialiased;\n left: 8px;\n position: absolute;\n color: rgba(100,100,100,0.7);\n }\n ._access-menu ul li:hover:before, ._access-menu ul li.active:before {\n color: rgba(200,200,200,0.7);\n }\n ._access-menu ul li[data-access-action=\"increaseText\"]:before {\n content: 'zoom_in';\n }\n ._access-menu ul li[data-access-action=\"decreaseText\"]:before {\n content: 'zoom_out';\n }\n ._access-menu ul li[data-access-action=\"invertColors\"]:before {\n content: 'invert_colors';\n }\n ._access-menu ul li[data-access-action=\"grayHues\"]:before {\n content: 'format_color_reset';\n }\n ._access-menu ul li[data-access-action=\"underlineLinks\"]:before {\n content: 'format_underlined';\n }\n ._access-menu ul li[data-access-action=\"textToSpeech\"]:before {\n content: 'record_voice_over';\n }\n ._access-menu ul li[data-access-action=\"speechToText\"]:before {\n content: 'mic';\n }\n ",t="_access-main-css";c["default"].injectStyle(e,{className:t}),c["default"].deployedObjects.set("."+t,!1)}},{key:"injectIcon",value:function(){var e="width: "+this.options.icon.dimensions.width.size+this.options.icon.dimensions.width.units+";height: "+this.options.icon.dimensions.height.size+this.options.icon.dimensions.height.units+";font-size: "+this.options.icon.dimensions.width.size+this.options.icon.dimensions.width.units+";background-color: "+this.options.icon.backgroundColor+";color: "+this.options.icon.color;for(var t in this.options.icon.position)e+=";"+t+":"+this.options.icon.position[t].size+this.options.icon.position[t].units;e+=";z-index: "+this.options.icon.zIndex;var n=c["default"].jsonToHtml({type:"i",attrs:{"class":"_access-icon material-icons _access",style:e},children:[{type:"#text",text:"accessible"}]});return this.body.appendChild(n),c["default"].deployedObjects.set("._access-icon",!1),n}},{key:"injectMenu",value:function(){var e=this,t=c["default"].jsonToHtml({type:"div",attrs:{"class":"_access-menu close _access"},children:[{type:"h3",attrs:{"class":"_text-center"},children:[{type:"i",attrs:{"class":"_menu-close-btn _menu-btn material-icons"},children:[{type:"#text",text:"close"}]},{type:"#text",text:this.options.labels.menuTitle},{type:"i",attrs:{"class":"_menu-reset-btn _menu-btn material-icons"},children:[{type:"#text",text:"refresh"}]}]},{type:"ul",children:[{type:"li",attrs:{"data-access-action":"increaseText"},children:[{type:"#text",text:this.options.labels.increaseText}]},{type:"li",attrs:{"data-access-action":"decreaseText"},children:[{type:"#text",text:this.options.labels.decreaseText}]},{type:"li",attrs:{"data-access-action":"invertColors"},children:[{type:"#text",text:this.options.labels.invertColors}]},{type:"li",attrs:{"data-access-action":"grayHues"},children:[{type:"#text",text:this.options.labels.grayHues}]},{type:"li",attrs:{"data-access-action":"underlineLinks"},children:[{type:"#text",text:this.options.labels.underlineLinks}]},{type:"li",attrs:{"data-access-action":"textToSpeech"},children:[{type:"#text",text:this.options.labels.textToSpeech}]},{type:"li",attrs:{"data-access-action":"speechToText"},children:[{type:"#text",text:this.options.labels.speechToText}]}]}]});for(var n in this.options.icon.position)t.classList.add(n);this.body.appendChild(t),c["default"].deployedObjects.set("._access-menu",!1);var i=document.querySelector("._access-menu ._menu-close-btn");i.addEventListener("click",function(){e.toggleMenu()},!1);var s=document.querySelector("._access-menu ._menu-reset-btn");return s.addEventListener("click",function(){e.resetAll()},!1),t}},{key:"addListeners",value:function(){for(var e=this,t=document.querySelectorAll("._access-menu ul li"),n=0;n-1&&(n[i].getAttribute("data-init-font-size")||n[i].setAttribute("data-init-font-size",s),s=1*s.replace("px","")+t,n[i].style.fontSize=s+"px")}else{var o=c["default"].getFormattedDim(getComputedStyle(this.body).fontSize);"undefined"==typeof this.initialValues.body.fontSize&&(this.initialValues.body.fontSize=o.size+o.sufix),o&&o.sufix&&!isNaN(1*o.size)&&(this.body.style.fontSize=1*o.size+t+o.sufix)}}},{key:"speechToText",value:function(){var e=this;"webkitSpeechRecognition"in window&&(this.recognition=new webkitSpeechRecognition,this.recognition.continuous=!0,this.recognition.interimResults=!0,this.recognition.onstart=function(){console.log("listening . . ."),e.speechToTextTarget&&e.speechToTextTarget.parentElement.classList.add("_access-listening")},this.recognition.onresult=function(t){console.log("onresult listening");var n="";if("undefined"!=typeof t.results){for(var i=t.resultIndex;i-1?t(e,"%"):e.indexOf("px")>-1?t(e,"px"):e.indexOf("em")>-1?t(e,"em"):e.indexOf("rem")>-1?t(e,"rem"):e.indexOf("pt")>-1?t(e,"pt"):"auto"==e?t(e,""):void 0},extend:function(e,t){for(var i in e)"object"===n(e[i])?t&&t[i]&&(e[i]=o.extend(e[i],t[i])):"object"===("undefined"==typeof t?"undefined":n(t))&&"undefined"!=typeof t[i]&&(e[i]=t[i]);return e},injectIconsCss:function(){var e="https://fonts.googleapis.com/icon?family=Material+Icons",t=document.getElementsByTagName("head")[0],n=document.createElement("link");n.type="text/css",n.rel="stylesheet",n.href=e,n.className="_access-material-icons",o.deployedObjects.set("."+n.className,!0),t.appendChild(n)},warn:function(e){var t="Accessibility: ";console.warn?console.warn(t+e):console.log(t+e)},deployedObjects:{get:function(e){return s.get(e)},contains:function(e){return s.has(e)},set:function(e,t){s.set(e,t)},remove:function(e){s["delete"](e)},getAll:function(){return s}}};t["default"]=o}]); \ No newline at end of file +!function(e){function t(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}var o=n(1),s=i(o);window.Accessibility=s["default"]},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},a=function(){function e(e,t){for(var n=0;n-1&&(r["default"].warn("grayHues isn't supported in firefox"),this.options.modules.grayHues=!1)}},{key:"injectCss",value:function(){var e="\n ._access-icon {\n position: fixed;\n background-repeat: no-repeat;\n background-size: contain;\n cursor: pointer;\n opacity: 0;\n transition-duration: .5s;\n }\n ._access-menu {\n position: fixed;\n width: "+this.options.menu.dimensions.width.size+this.options.menu.dimensions.width.units+";\n height: "+this.options.menu.dimensions.height.size+this.options.menu.dimensions.height.units+";\n transition-duration: .5s;\n z-index: "+this.options.icon.zIndex+"1;\n opacity: 1;\n background-color: #fff;\n color: #000;\n border-radius: 3px;\n border: solid 2px gray;\n font-family: "+this.options.menu.fontFamily+";\n min-width: 300px;\n box-shadow: -2px -2px 3px #aaa;\n max-height: 100vh;\n "+("rtl"==getComputedStyle(this.body).direction?"text-indent: -5px":"")+"\n }\n ._access-menu.close {\n z-index: -1;\n width: 0;\n opacity: 0;\n background-color: transparent;\n }\n ._access-menu.bottom {\n bottom: 0;\n }\n ._access-menu.top {\n top: 0;\n }\n ._access-menu.left {\n left: 0;\n }\n ._access-menu.close.left {\n left: -"+this.options.menu.dimensions.width.size+this.options.menu.dimensions.width.units+";\n }\n ._access-menu.right {\n right: 0;\n }\n ._access-menu.close.right {\n right: -"+this.options.menu.dimensions.width.size+this.options.menu.dimensions.width.units+";\n }\n ._access-menu ._text-center {\n text-align: center;\n }\n ._access-menu h3 {\n font-size: 24px !important; \n margin-top: 20px;\n margin-bottom: 20px;\n padding: 0;\n }\n ._access-menu ._menu-close-btn {\n left: 5px;\n color: #d63c3c;\n }\n ._access-menu ._menu-reset-btn {\n right: 5px;\n color: #4054b2;\n }\n ._access-menu ._menu-btn {\n position: absolute;\n top: 5px;\n cursor: pointer;\n font-size: 24px !important;\n font-weight: bold;\n }\n ._access-menu ul {\n padding: 0;\n position: relative;\n font-size: 18px !important;\n margin: 0;\n }\n ._access-menu ul li {\n list-style-type: none;\n cursor: pointer;\n -ms-user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n user-select: none;\n border: solid 1px black;\n padding: 10px 0 10px 30px;\n margin: 5px;\n border-radius: 4px;\n transition-duration: .5s;\n transition-timing-function: ease-in-out;\n font-size: 18px !important;\n line-height: 18px !important;\n text-indent: 5px;\n background: #E0E1E2;\n color: rgba(0,0,0,.6);\n }\n ._access-menu ul.before-collapse li:nth-child(1) {\n transform: translate3d(0px, -45px, 0px);\n }\n ._access-menu ul.before-collapse li:nth-child(2) {\n transform: translate3d(0px, -90px, 0px);\n }\n ._access-menu ul.before-collapse li:nth-child(3) {\n transform: translate3d(0px, -135px, 0px);\n }\n ._access-menu ul.before-collapse li:nth-child(4) {\n transform: translate3d(0px, -180px, 0px);\n }\n ._access-menu ul.before-collapse li:nth-child(5) {\n transform: translate3d(0px, -225px, 0px);\n }\n ._access-menu ul.before-collapse li:nth-child(6) {\n transform: translate3d(0px, -270px, 0px);\n }\n ._access-menu ul.before-collapse li:nth-child(7) {\n transform: translate3d(0px, -315px, 0px);\n }\n ._access-menu ul li.active, ._access-menu ul li.active:hover {\n color: #fff;\n background-color: #000;\n }\n ._access-menu ul li:hover {\n color: rgba(0,0,0,.8);\n background-color: #CACBCD;\n }\n ._access-menu ul li.not-supported {\n display: none;\n }\n ._access-menu ul li:before {\n content: ' ';\n font-family: 'Material Icons';\n text-rendering: optimizeLegibility;\n font-feature-settings: \"liga\" 1;\n font-style: normal;\n text-transform: none;\n line-height: 1;\n font-size: 24px !important;\n width: 24px;\n height: 24px;\n display: inline-block;\n overflow: hidden;\n -webkit-font-smoothing: antialiased;\n left: 8px;\n position: absolute;\n color: rgba(0,0,0,.6);\n }\n ._access-menu ul li:hover:before {\n color: rgba(0,0,0,.8);\n }\n ._access-menu ul li.active:before {\n color: #fff;\n }\n ._access-menu ul li[data-access-action=\"increaseText\"]:before {\n content: 'zoom_in';\n }\n ._access-menu ul li[data-access-action=\"decreaseText\"]:before {\n content: 'zoom_out';\n }\n ._access-menu ul li[data-access-action=\"invertColors\"]:before {\n content: 'invert_colors';\n }\n ._access-menu ul li[data-access-action=\"grayHues\"]:before {\n content: 'format_color_reset';\n }\n ._access-menu ul li[data-access-action=\"underlineLinks\"]:before {\n content: 'format_underlined';\n }\n ._access-menu ul li[data-access-action=\"textToSpeech\"]:before {\n content: 'record_voice_over';\n }\n ._access-menu ul li[data-access-action=\"speechToText\"]:before {\n content: 'mic';\n }\n ",t="_access-main-css";r["default"].injectStyle(e,{className:t}),r["default"].deployedObjects.set("."+t,!1)}},{key:"injectIcon",value:function(){var e="width: "+this.options.icon.dimensions.width.size+this.options.icon.dimensions.width.units+";height: "+this.options.icon.dimensions.height.size+this.options.icon.dimensions.height.units+";font-size: "+this.options.icon.dimensions.width.size+this.options.icon.dimensions.width.units+";background-color: "+this.options.icon.backgroundColor+";color: "+this.options.icon.color;for(var t in this.options.icon.position)e+=";"+t+":"+this.options.icon.position[t].size+this.options.icon.position[t].units;e+=";z-index: "+this.options.icon.zIndex;var n=r["default"].jsonToHtml({type:"i",attrs:{"class":"_access-icon material-icons _access",style:e},children:[{type:"#text",text:"accessible"}]});return this.body.appendChild(n),r["default"].deployedObjects.set("._access-icon",!1),n}},{key:"injectMenu",value:function(){var e=this,t=r["default"].jsonToHtml({type:"div",attrs:{"class":"_access-menu close _access"},children:[{type:"h3",attrs:{"class":"_text-center"},children:[{type:"i",attrs:{"class":"_menu-close-btn _menu-btn material-icons"},children:[{type:"#text",text:"close"}]},{type:"#text",text:this.options.labels.menuTitle},{type:"i",attrs:{"class":"_menu-reset-btn _menu-btn material-icons"},children:[{type:"#text",text:"refresh"}]}]},{type:"ul",attrs:{"class":this.options.animations.buttons?"before-collapse":""},children:[{type:"li",attrs:{"data-access-action":"increaseText"},children:[{type:"#text",text:this.options.labels.increaseText}]},{type:"li",attrs:{"data-access-action":"decreaseText"},children:[{type:"#text",text:this.options.labels.decreaseText}]},{type:"li",attrs:{"data-access-action":"invertColors"},children:[{type:"#text",text:this.options.labels.invertColors}]},{type:"li",attrs:{"data-access-action":"grayHues"},children:[{type:"#text",text:this.options.labels.grayHues}]},{type:"li",attrs:{"data-access-action":"underlineLinks"},children:[{type:"#text",text:this.options.labels.underlineLinks}]},{type:"li",attrs:{"data-access-action":"textToSpeech"},children:[{type:"#text",text:this.options.labels.textToSpeech}]},{type:"li",attrs:{"data-access-action":"speechToText"},children:[{type:"#text",text:this.options.labels.speechToText}]}]}]});for(var n in this.options.icon.position)t.classList.add(n);this.body.appendChild(t),r["default"].deployedObjects.set("._access-menu",!1);var i=document.querySelector("._access-menu ._menu-close-btn");i.addEventListener("click",function(){e.toggleMenu()},!1);var o=document.querySelector("._access-menu ._menu-reset-btn");return o.addEventListener("click",function(){e.resetAll()},!1),t}},{key:"addListeners",value:function(){for(var e=this,t=document.querySelectorAll("._access-menu ul li"),n=0;n-1&&(n[i].getAttribute("data-init-font-size")||n[i].setAttribute("data-init-font-size",o),o=1*o.replace("px","")+t,n[i].style.fontSize=o+"px")}else{var s=r["default"].getFormattedDim(getComputedStyle(this.body).fontSize);"undefined"==typeof this.initialValues.body.fontSize&&(this.initialValues.body.fontSize=s.size+s.sufix),s&&s.sufix&&!isNaN(1*s.size)&&(this.body.style.fontSize=1*s.size+t+s.sufix)}}},{key:"speechToText",value:function(){var e=this;"webkitSpeechRecognition"in window&&(this.recognition=new webkitSpeechRecognition,this.recognition.continuous=!0,this.recognition.interimResults=!0,this.recognition.onstart=function(){e.body.classList.add("_access-listening")},this.recognition.onend=function(){e.body.classList.remove("_access-listening")},this.recognition.onresult=function(t){var n="";if("undefined"!=typeof t.results){for(var i=t.resultIndex;i-1?t(e,"%"):e.indexOf("px")>-1?t(e,"px"):e.indexOf("em")>-1?t(e,"em"):e.indexOf("rem")>-1?t(e,"rem"):e.indexOf("pt")>-1?t(e,"pt"):"auto"==e?t(e,""):void 0},extend:function(e,t){for(var i in e)"object"===n(e[i])?t&&t[i]&&(e[i]=s.extend(e[i],t[i])):"object"===("undefined"==typeof t?"undefined":n(t))&&"undefined"!=typeof t[i]&&(e[i]=t[i]);return e},injectIconsCss:function(){var e="https://fonts.googleapis.com/icon?family=Material+Icons",t=document.getElementsByTagName("head")[0],n=document.createElement("link");n.type="text/css",n.rel="stylesheet",n.href=e,n.className="_access-material-icons",s.deployedObjects.set("."+n.className,!0),t.appendChild(n)},warn:function(e){var t="Accessibility: ";console.warn?console.warn(t+e):console.log(t+e)},deployedObjects:{get:function(e){return o.get(e)},contains:function(e){return o.has(e)},set:function(e,t){o.set(e,t)},remove:function(e){o["delete"](e)},getAll:function(){return o}}};t["default"]=s}]); \ No newline at end of file diff --git a/package.json b/package.json index d03e25c..30d3bb1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "accessibility", - "version": "0.1.1", + "version": "0.1.11", "description": "add accessibility to your website", "main": "accessibility.js", "scripts": { diff --git a/src/main.js b/src/main.js index 9cabfde..b13a425 100644 --- a/src/main.js +++ b/src/main.js @@ -37,6 +37,9 @@ let _options = { textToSpeechLang: 'en-US', speechToTextLang: 'en-US', textPixelMode: false, + animations: { + buttons: true + }, modules: { increaseText: true, decreaseText: true, @@ -165,18 +168,42 @@ class Accessibility { padding: 10px 0 10px 30px; margin: 5px; border-radius: 4px; - transition-duration: .3s; + transition-duration: .5s; + transition-timing-function: ease-in-out; font-size: 18px !important; line-height: 18px !important; text-indent: 5px; + background: #E0E1E2; + color: rgba(0,0,0,.6); + } + ._access-menu ul.before-collapse li:nth-child(1) { + transform: translate3d(0px, -45px, 0px); + } + ._access-menu ul.before-collapse li:nth-child(2) { + transform: translate3d(0px, -90px, 0px); + } + ._access-menu ul.before-collapse li:nth-child(3) { + transform: translate3d(0px, -135px, 0px); + } + ._access-menu ul.before-collapse li:nth-child(4) { + transform: translate3d(0px, -180px, 0px); + } + ._access-menu ul.before-collapse li:nth-child(5) { + transform: translate3d(0px, -225px, 0px); + } + ._access-menu ul.before-collapse li:nth-child(6) { + transform: translate3d(0px, -270px, 0px); + } + ._access-menu ul.before-collapse li:nth-child(7) { + transform: translate3d(0px, -315px, 0px); } ._access-menu ul li.active, ._access-menu ul li.active:hover { color: #fff; background-color: #000; } ._access-menu ul li:hover { - color: #fff; - background-color: #444; + color: rgba(0,0,0,.8); + background-color: #CACBCD; } ._access-menu ul li.not-supported { display: none; @@ -197,10 +224,13 @@ class Accessibility { -webkit-font-smoothing: antialiased; left: 8px; position: absolute; - color: rgba(100,100,100,0.7); + color: rgba(0,0,0,.6); } - ._access-menu ul li:hover:before, ._access-menu ul li.active:before { - color: rgba(200,200,200,0.7); + ._access-menu ul li:hover:before { + color: rgba(0,0,0,.8); + } + ._access-menu ul li.active:before { + color: #fff; } ._access-menu ul li[data-access-action="increaseText"]:before { content: 'zoom_in'; @@ -315,6 +345,9 @@ class Accessibility { }, { type: 'ul', + attrs: { + 'class': (this.options.animations.buttons ? 'before-collapse' : '') + }, children: [ { type: 'li', @@ -502,13 +535,19 @@ class Accessibility { this.recognition.interimResults = true; this.recognition.onstart = () => { // TODO red color on mic icon - console.log('listening . . .'); - if (this.speechToTextTarget) - this.speechToTextTarget.parentElement.classList.add('_access-listening'); + //console.log('listening . . .'); + // if (this.speechToTextTarget) + // this.speechToTextTarget.parentElement.classList.add('_access-listening'); + this.body.classList.add('_access-listening'); + }; + + this.recognition.onend = () => { + this.body.classList.remove('_access-listening'); + //console.log('onend listening'); }; this.recognition.onresult = (event) => { - console.log('onresult listening'); + ///console.log('onresult listening'); let finalTranscript = ''; if (typeof (event.results) == 'undefined') { return; @@ -564,6 +603,9 @@ class Accessibility { let className = '_access-speech-to-text'; // window.event.preventDefault(); // window.event.stopPropagation(); + if (typeof self.recognition === 'object' && typeof self.recognition.stop === 'function') + self.recognition.stop(); + self.speechToTextTarget = window.event.target; self.speechToText(window.event.target.innerText); } @@ -579,7 +621,9 @@ class Accessibility { } toggleMenu() { - this.menu.classList.toggle('close'); + if (this.options.animations && this.options.animations.buttons) + this.menu.querySelector('ul').classList.toggle('before-collapse'); + setTimeout(() => {this.menu.classList.toggle('close');}, 10); } invoke(action) { @@ -743,6 +787,7 @@ class Accessibility { let remove = () => { if (this.recognition) { this.recognition.stop(); + this.body.classList.remove('_access-listening'); } let style = document.querySelector('.' + className); if (style) { @@ -767,19 +812,22 @@ class Accessibility { this.initialValues.speechToText = !this.initialValues.speechToText; if (this.initialValues.speechToText) { let css = ` - ._access-mic:after { + body:after { content: 'mic'; font-family: 'Material Icons'; position: absolute; - z-index: 1000; - top: 0; - right: 0; - width: 24px; - height: 24px; - font-size: 24px; + z-index: 1100; + top: 1vw; + right: 1vw; + width: 36px; + height: 36px; + font-size: 36px; + line-height: 36px; + border-radius: 50%; + background: rgba(255,255,255,0.7); } - ._access-listening:after { + body._access-listening:after { animation: _access-listening-animation 2s infinite; } @@ -792,6 +840,10 @@ class Accessibility { common.deployedObjects.set('.' + className, true); let inputs = document.querySelectorAll('input[type="text"], input[type="search"], textarea, [contenteditable]'); for (let i = 0; i < inputs.length; i++) { + inputs[i].addEventListener('blur', () => { + if (typeof this.recognition === 'object' && typeof this.recognition.stop === 'function') + this.recognition.stop(); + }, false); inputs[i].addEventListener('focus', this.listen, false); inputs[i].parentElement.classList.add('_access-mic'); }