/* * /MathJax/extensions/a11y/explorer.js * * Copyright (c) 2009-2018 The MathJax Consortium * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ MathJax.Hub.Register.StartupHook("Sre Ready",function(){var i,f,d=MathJax.Hub.config.menuSettings,a={};MathJax.Hub.Register.StartupHook("MathEvents Ready",function(){i=MathJax.Extension.MathEvents.Event.False,f=MathJax.Extension.MathEvents.Event.KEY});var c=MathJax.Extension.explorer={version:"1.6.0",dependents:[],defaults:{walker:"table",highlight:"none",background:"blue",foreground:"black",speech:!0,generation:"lazy",subtitle:!1,ruleset:"mathspeak-default"},eagerComplexity:80,prefix:"Assistive-",hook:null,locHook:null,oldrules:null,addMenuOption:function(k,h){d[c.prefix+k]=h},addDefaults:function(){for(var m,l=MathJax.Hub.CombineConfig("explorer",c.defaults),h=Object.keys(l),k=0;m=h[k];k++){void 0===d[c.prefix+m]&&c.addMenuOption(m,l[m])}c.setSpeechOption(),b.Reset()},setOption:function(k,h){d[c.prefix+k]!==h&&(c.addMenuOption(k,h),b.Reset())},getOption:function(h){return d[c.prefix+h]},speechOption:function(h){c.oldrules!==h.value&&(c.setSpeechOption(),b.Regenerate())},setSpeechOption:function(){var k=d[c.prefix+"ruleset"],h=k.split("-");sre.System.getInstance().setupEngine({locale:MathJax.Localization.locale,domain:c.Domain(h[0]),style:h[1]}),c.oldrules=k},Domain:function(h){switch(h){case"chromevox":return"default";case"clearspeak":return"clearspeak";case"mathspeak":default:return"mathspeak"}},Enable:function(k,h){d.explorer=!0,h&&(a.explorer=!0),MathJax.Extension.collapsible.Enable(!1,h),MathJax.Extension.AssistiveMML&&(MathJax.Extension.AssistiveMML.config.disabled=!0,d.assistiveMML=!1,h&&(a.assistiveMML=!1)),this.DisableMenus(!1),this.hook||(this.hook=MathJax.Hub.Register.MessageHook("New Math",["Register",this.Explorer])),this.locHook||(this.locHook=MathJax.Hub.Register.MessageHook("Locale Reset",["RemoveSpeech",this.Explorer])),k&&MathJax.Hub.Queue(["Reprocess",MathJax.Hub])},Disable:function(m,l){d.explorer=!1,l&&(a.explorer=!1),this.DisableMenus(!0),this.hook&&(MathJax.Hub.UnRegister.MessageHook(this.hook),this.hook=null);for(var h=this.dependents.length-1;0<=h;h--){var k=this.dependents[h];k.Disable&&k.Disable(!1,l)}},DisableMenus:function(m){if(MathJax.Menu){var l=MathJax.Menu.menu.FindId("Accessibility","Explorer");if(l){for(var h,k=(l=l.submenu).items,o=2;h=k[o];o++){h.disabled=m}m||!l.FindId("SpeechOutput")||d[c.prefix+"speech"]||(l.FindId("Subtitles").disabled=!0)}}},Dependent:function(h){this.dependents.push(h)}},j=MathJax.Object.Subclass({div:null,inner:null,Init:function(){this.div=j.Create("assertive"),this.inner=MathJax.HTML.addElement(this.div,"div")},Add:function(){j.added||(document.body.appendChild(this.div),j.added=!0)},Show:function(m,l){this.div.classList.add("MJX_LiveRegion_Show");var h=m.getBoundingClientRect(),k=h.bottom+10+window.pageYOffset,q=h.left+window.pageXOffset;this.div.style.top=k+"px",this.div.style.left=q+"px";var p=l.colorString();this.inner.style.backgroundColor=p.background,this.inner.style.color=p.foreground},Hide:function(h){this.div.classList.remove("MJX_LiveRegion_Show")},Clear:function(){this.Update(""),this.inner.style.top="",this.inner.style.backgroundColor=""},Update:function(h){c.getOption("speech")&&j.Update(this.inner,h)}},{ANNOUNCE:"Navigatable Math in page. Explore with enter or shift space and arrow keys. Expand or collapse elements hitting enter.",announced:!1,added:!1,styles:{".MJX_LiveRegion":{position:"absolute",top:"0",height:"1px",width:"1px",padding:"1px",overflow:"hidden"},".MJX_LiveRegion_Show":{top:"0",position:"absolute",width:"auto",height:"auto",padding:"0px 0px",opacity:1,"z-index":"202",left:0,right:0,margin:"0 auto","background-color":"white","box-shadow":"0px 10px 20px #888",border:"2px solid #CCCCCC"}},Create:function(k){var h=MathJax.HTML.Element("div",{className:"MJX_LiveRegion"});return h.setAttribute("aria-live",k),h},Update:MathJax.Hub.Browser.isPC?function(k,h){k.textContent="",setTimeout(function(){k.textContent=h},100)}:function(k,h){k.textContent="",k.textContent=h},Announce:function(){var h;c.getOption("speech")&&(j.announced=!0,MathJax.Ajax.Styles(j.styles),h=j.Create("polite"),document.body.appendChild(h),j.Update(h,j.ANNOUNCE),setTimeout(function(){document.body.removeChild(h)},1000))}});MathJax.Extension.explorer.LiveRegion=j;var g=MathJax.Ajax.fileURL(MathJax.Ajax.config.path.a11y),b=MathJax.Extension.explorer.Explorer={liveRegion:j(),walker:null,highlighter:null,hoverer:null,flamer:null,speechDiv:null,earconFile:g+"/invalid_keypress"+(-1!==["Firefox","Chrome","Opera"].indexOf(MathJax.Hub.Browser.name)?".ogg":".mp3"),expanded:!1,focusoutEvent:MathJax.Hub.Browser.isFirefox?"blur":"focusout",focusinEvent:"focus",ignoreFocusOut:!1,jaxCache:{},messageID:null,Reset:function(){b.FlameEnriched()},Register:function(l){var k,h;!c.hook||(k=document.getElementById(l[1]))&&k.id&&((h=MathJax.Hub.getJaxFor(k.id))&&h.enriched&&(b.StateChange(k.id,h),b.liveRegion.Add(),b.AddEvent(k)))},StateChange:function(l,k){b.GetHighlighter(0.2);var h=b.jaxCache[l];h&&h===k.root||(h&&sre.Walker.resetState(l+"-Frame"),b.jaxCache[l]=k.root)},AddAria:function(h){h.setAttribute("role","application"),h.setAttribute("aria-label","Math")},AddHook:function(e){b.RemoveHook(),b.hook=MathJax.Hub.Register.MessageHook("End Math",function(l){var k=l[1].id+"-Frame",h=document.getElementById(k);e&&k===b.expanded&&(b.ActivateWalker(h,e),h.focus(),b.expanded=!1)})},RemoveHook:function(){b.hook&&(MathJax.Hub.UnRegister.MessageHook(b.hook),b.hook=null)},AddMessage:function(){return MathJax.Message.Set("Generating Speech Output")},RemoveMessage:function(h){h&&MathJax.Message.Clear(h)},AddEvent:function(m){var l,h=m.id+"-Frame",k=m.previousSibling;k&&(l=k.id!==h?k.firstElementChild:k,b.AddAria(l),b.AddMouseEvents(l),"MathJax_MathML"===l.className&&(l=l.firstElementChild),l&&(l.onkeydown=b.Keydown,b.Flame(l),l.addEventListener(b.focusinEvent,function(n){c.hook&&(j.announced||j.Announce())}),l.addEventListener(b.focusoutEvent,function(n){c.hook&&(b.ignoreFocusOut&&(b.ignoreFocusOut=!1,"enter"===b.walker.moved)?n.target.focus():b.walker&&b.DeactivateWalker())}),c.getOption("speech")&&b.AddSpeech(l)))},AddSpeech:function(l){var k=l.id,h=MathJax.Hub.getJaxFor(k).root.toMathML();if(l.getAttribute("haslabel")||b.AddMathLabel(h,k),!l.getAttribute("hasspeech")){switch(MathJax.Hub.config.explorer.generation){case"eager":b.AddSpeechEager(h,k);break;case"mixed":l.querySelectorAll("[data-semantic-complexity]").length>=c.eagerComplexity&&b.AddSpeechEager(h,k)}}},AddSpeechLazy:function(k){var h=new sre.TreeSpeechGenerator();h.setRebuilt(b.walker.getRebuilt()),h.getSpeech(b.walker.rootNode,b.walker.getXml()),k.setAttribute("hasspeech","true")},AddSpeechEager:function(k,h){b.MakeSpeechTask(k,h,sre.TreeSpeechGenerator,function(m,l){m.setAttribute("hasspeech","true")},5)},AddMathLabel:function(k,h){b.MakeSpeechTask(k,h,sre.SummarySpeechGenerator,function(m,l){m.setAttribute("haslabel","true"),m.setAttribute("aria-label",l)},5)},MakeSpeechTask:function(h,q,p,l,m){var k=b.AddMessage();setTimeout(function(){var r=new p(),o=document.getElementById(q),n=new sre.DummyWalker(o,r,b.highlighter,h).speech();n&&l(o,n),b.RemoveMessage(k)},m)},Keydown:function(m){var l=m.keyCode;if(l===f.ESCAPE){if(!b.walker){return}return b.RemoveHook(),b.DeactivateWalker(),void i(m)}if(b.walker&&b.walker.isActive()){l=l===f.RETURN?f.DASH:l,void 0!==b.walker.modifier&&(b.walker.modifier=m.shiftKey);var h=b.walker.move(l);if(null===h){return}if(h){if("expand"===b.walker.moved){if(b.expanded=b.walker.node.id,MathJax.Hub.Browser.isEdge){return b.ignoreFocusOut=!0,void b.DeactivateWalker()}if(MathJax.Hub.Browser.isFirefox||MathJax.Hub.Browser.isMSIE){return void b.DeactivateWalker()}}b.liveRegion.Update(b.walker.speech()),b.Highlight()}else{b.PlayEarcon()}i(m)}else{var k=m.target;if(l===f.SPACE&&!m.shiftKey){return MathJax.Extension.MathEvents.Event.ContextMenu(m,k),void i(m)}if(c.hook&&(l===f.RETURN||l===f.SPACE&&m.shiftKey)){var o=MathJax.Hub.getJaxFor(k);return b.ActivateWalker(k,o),b.AddHook(o),void i(m)}}},GetHighlighter:function(h){b.highlighter=sre.HighlighterFactory.highlighter({color:c.getOption("background"),alpha:h},{color:c.getOption("foreground"),alpha:1},{renderer:MathJax.Hub.outputJax["jax/mml"][0].id,browser:MathJax.Hub.Browser.name})},AddMouseEvents:function(h){sre.HighlighterFactory.addEvents(h,{mouseover:b.MouseOver,mouseout:b.MouseOut},{renderer:MathJax.Hub.outputJax["jax/mml"][0].id,browser:MathJax.Hub.Browser.name})},MouseOver:function(k){var h;"none"!==c.getOption("highlight")&&("hover"===c.getOption("highlight")&&(h=k.currentTarget,b.GetHighlighter(0.1),b.highlighter.highlight([h]),b.hoverer=!0),i(k))},MouseOut:function(h){return b.hoverer&&(b.highlighter.unhighlight(),b.hoverer=!1),i(h)},Flame:function(h){if("flame"===c.getOption("highlight")){return b.GetHighlighter(0.05),b.highlighter.highlightAll(h),void (b.flamer=!0)}},UnFlame:function(){b.flamer&&(b.highlighter.unhighlightAll(),b.flamer=null)},FlameEnriched:function(){b.UnFlame();for(var l,k=0,h=MathJax.Hub.getAllJax();l=h[k];k++){b.Flame(l.SourceElement().previousSibling)}},Walkers:{syntactic:sre.SyntaxWalker,table:sre.TableWalker,semantic:sre.SemanticWalker,none:sre.DummyWalker},ActivateWalker:function(m,l){var h=c.getOption("speech"),k=c.getOption("walker")?b.Walkers[MathJax.Hub.config.explorer.walker]:b.Walkers.none,q=h?new sre.DirectSpeechGenerator():new sre.DummySpeechGenerator(),p=sre.System.getInstance().engineSetup();q.setOptions({locale:p.locale,domain:p.domain,style:p.style,modality:"speech"}),b.GetHighlighter(0.2),b.walker=new k(m,q,b.highlighter,l.root.toMathML()),h&&!m.getAttribute("hasspeech")&&b.AddSpeechLazy(m),b.walker.activate(),h&&(c.getOption("subtitle")&&b.liveRegion.Show(m,b.highlighter),b.liveRegion.Update(b.walker.speech())),b.Highlight(),b.ignoreFocusOut&&setTimeout(function(){b.ignoreFocusOut=!1},500)},DeactivateWalker:function(){var k=sre.System.getInstance().engineSetup(),h="clearspeak"===k.domain?"default":k.style;c.setOption("ruleset",k.domain+"-"+h),b.liveRegion.Clear(),b.liveRegion.Hide(),b.Unhighlight(),b.currentHighlight=null,b.walker.deactivate(),b.walker=null},Highlight:function(){b.Unhighlight(),b.highlighter.highlight(b.walker.getFocus().getNodes())},Unhighlight:function(){b.highlighter.unhighlight()},PlayEarcon:function(){new Audio(b.earconFile).play()},SpeechOutput:function(){b.Reset();["Subtitles"].forEach(function(k){var h=MathJax.Menu.menu.FindId("Accessibility","Explorer",k);h&&(h.disabled=!h.disabled)}),b.Regenerate()},RemoveSpeech:function(){c.setSpeechOption();for(var m,l=0,h=MathJax.Hub.getAllJax();m=h[l];l++){var k=document.getElementById(m.inputID+"-Frame");k&&(k.removeAttribute("hasspeech"),k.removeAttribute("haslabel"))}},Regenerate:function(){for(var m,l=0,h=MathJax.Hub.getAllJax();m=h[l];l++){var k=document.getElementById(m.inputID+"-Frame");k&&(k.removeAttribute("hasspeech"),b.AddSpeech(k))}},Startup:function(){var h=MathJax.Extension.collapsible;h&&h.Dependent(c),c.addDefaults()}};MathJax.Hub.Register.StartupHook("End Extensions",function(){c[!1===d.explorer?"Disable":"Enable"](),MathJax.Hub.Startup.signal.Post("Explorer Ready"),MathJax.Hub.Register.StartupHook("MathMenu Ready",function(){a=MathJax.Menu.cookie;var p,l=MathJax.Menu.ITEM,h=MathJax.Menu.menu,k={action:b.Reset},s={action:c.speechOption},q=l.SUBMENU(["Explorer","Explorer"],l.CHECKBOX(["Active","Active"],"explorer",{action:function(n){c[d.explorer?"Enable":"Disable"](!0,!0),MathJax.Menu.saveCookie()}}),l.RULE(),l.CHECKBOX(["Walker","Walker"],"Assistive-walker"),l.SUBMENU(["Highlight","Highlight"],l.RADIO(["none","None"],"Assistive-highlight",k),l.RADIO(["hover","Hover"],"Assistive-highlight",k),l.RADIO(["flame","Flame"],"Assistive-highlight",k)),l.SUBMENU(["Background","Background"],l.RADIO(["blue","Blue"],"Assistive-background",k),l.RADIO(["red","Red"],"Assistive-background",k),l.RADIO(["green","Green"],"Assistive-background",k),l.RADIO(["yellow","Yellow"],"Assistive-background",k),l.RADIO(["cyan","Cyan"],"Assistive-background",k),l.RADIO(["magenta","Magenta"],"Assistive-background",k),l.RADIO(["white","White"],"Assistive-background",k),l.RADIO(["black","Black"],"Assistive-background",k)),l.SUBMENU(["Foreground","Foreground"],l.RADIO(["black","Black"],"Assistive-foreground",k),l.RADIO(["white","White"],"Assistive-foreground",k),l.RADIO(["magenta","Magenta"],"Assistive-foreground",k),l.RADIO(["cyan","Cyan"],"Assistive-foreground",k),l.RADIO(["yellow","Yellow"],"Assistive-foreground",k),l.RADIO(["green","Green"],"Assistive-foreground",k),l.RADIO(["red","Red"],"Assistive-foreground",k),l.RADIO(["blue","Blue"],"Assistive-foreground",k)),l.RULE(),l.CHECKBOX(["SpeechOutput","Speech Output"],"Assistive-speech",{action:b.SpeechOutput}),l.CHECKBOX(["Subtitles","Subtitles"],"Assistive-subtitle",{disabled:!d["Assistive-speech"]}),l.RULE(),l.SUBMENU(["Mathspeak","Mathspeak Rules"],l.RADIO(["mathspeak-default","Verbose"],"Assistive-ruleset",s),l.RADIO(["mathspeak-brief","Brief"],"Assistive-ruleset",s),l.RADIO(["mathspeak-sbrief","Superbrief"],"Assistive-ruleset",s)),l.RADIO(["clearspeak-default","Clearspeak Rules"],"Assistive-ruleset",s),l.SUBMENU(["Chromevox","ChromeVox Rules"],l.RADIO(["chromevox-default","Verbose"],"Assistive-ruleset",s),l.RADIO(["chromevox-alternative","Alternative"],"Assistive-ruleset",s))),m=(h.FindId("Accessibility")||{}).submenu;m?null!==(p=m.IndexOfId("Explorer"))?m.items[p]=q:(p=m.IndexOfId("CollapsibleMath"),m.items.splice(p+1,0,q)):(p=h.IndexOfId("CollapsibleMath"),h.items.splice(p+1,0,q)),d.explorer||c.DisableMenus(!0)},20)},20)}),MathJax.Hub.Register.StartupHook("SVG Jax Ready",function(){MathJax.Hub.Config({SVG:{addMMLclasses:!0}});var a,b=MathJax.OutputJax.SVG;parseFloat(b.version)<2.7&&(a=b.getJaxFromMath,b.Augment({getJaxFromMath:function(c){return c.parentNode.className.match(/MathJax_SVG_Display/)&&(c=c.parentNode),a.call(this,c)}}))}),MathJax.Ajax.config.path.a11y||(MathJax.Ajax.config.path.a11y=MathJax.Hub.config.root+"/extensions/a11y"),MathJax.Ajax.Require("[a11y]/collapsible.js"),MathJax.Hub.Register.StartupHook("Collapsible Ready",function(){MathJax.Extension.explorer.Explorer.Startup(),MathJax.Ajax.loadComplete("[a11y]/explorer.js")});