discourse-math/public/mathjax/extensions/a11y/collapsible.js

1 line
10 KiB
JavaScript
Raw Normal View History

2017-07-06 16:50:38 -04:00
!function(a){var b,c=a.config.menuSettings,d={},e=1e7,f="data-semantic-complexity",g=MathJax.Ajax.config.path;g.a11y||(g.a11y=a.config.root+"/extensions/a11y");var h=MathJax.Extension.collapsible={version:"1.2.2",config:a.CombineConfig("collapsible",{disabled:!1}),dependents:[],COMPLEXATTR:f,COMPLEXITY:{TEXT:.5,TOKEN:.5,CHILD:1,SCRIPT:.8,SQRT:2,SUBSUP:2,UNDEROVER:2,FRACTION:2,ACTION:2,PHANTOM:0,XML:2,GLYPH:2},COLLAPSE:{identifier:3,number:3,text:10,infixop:15,relseq:15,multirel:15,fenced:18,bigop:20,integral:20,fraction:12,sqrt:9,root:12,vector:15,matrix:15,cases:15,superscript:9,subscript:9,subsup:9,punctuated:{endpunct:e,startpunct:e,default:12}},MARKER:{identifier:"x",number:"#",text:"...",appl:{"limit function":"lim",default:"f()"},fraction:"/",sqrt:"\u221a",root:"\u221a",superscript:"\u25fd\u02d9",subscript:"\u25fd.",subsup:"\u25fd:",vector:{binomial:"(:)",determinant:"|:|",default:"\u27e8:\u27e9"},matrix:{squarematrix:"[::]",rowvector:"\u27e8\u22ef\u27e9",columnvector:"\u27e8\u22ee\u27e9",determinant:"|::|",default:"(::)"},cases:"{:",infixop:{addition:"+",subtraction:"\u2212",multiplication:"\u22c5",implicit:"\u22c5",default:"+"},punctuated:{text:"...",default:","}},Enable:function(b,e){c.collapsible=!0,e&&(d.collapsible=!0),this.config.disabled=!1,MathJax.Extension["semantic-enrich"].Enable(!1,e),b&&a.Queue(["Reprocess",a])},Disable:function(b,e){c.collapsible=!1,e&&(d.collapsible=!1),this.config.disabled=!0;for(var f=this.dependents.length-1;f>=0;f--){var g=this.dependents[f];g.Disable&&g.Disable(!1,e)}b&&a.Queue(["Reprocess",a])},Dependent:function(a){this.dependents.push(a)},Startup:function(){b=MathJax.ElementJax.mml;var c=MathJax.Extension["semantic-enrich"];c&&c.Dependent(this),a.postInputHooks.Add(["Filter",h],100)},Filter:function(a,b,c){a.enriched&&!this.config.disabled&&(a.root=a.root.Collapse(),a.root.inputID=c.id)},Marker:function(a){return b.mtext("\u25c2"+a+"\u25b8").With({mathcolor:"blue",attr:{},attrNames:[]})},MakeAction:function(a,c){var d=b.maction(a).With({id:this.getActionID(),actiontype:"toggle",complexity:a.getComplexity(),collapsible:!0,attrNames:["id","actiontype","selection",f],attr:{},selection:2});if(d.attr[f]=d.complexity,"math"===c.type){for(var e,g=b.mrow().With({data:c.data,complexity:c.complexity,attrNames:[],attr:{}}),h=c.attrNames.length-1;e=c.attrNames[h];h--)"data-semantic-"===e.substr(0,14)&&(g.attr[e]=c.attr[e],g.attrNames.push(e),delete c.attr[e],c.attrNames.splice(h,1));g.complexity=c.complexity,d.Append(g),c.data=[],c.Append(d),c.complexity=d.complexity,d=c}else d.Append(c);return d},actionID:1,getActionID:function(){return"MJX-Collapse-"+this.actionID++},Collapse:function(a){a.getComplexity();var b=(a.attr||{})["data-semantic-type"];if(b)if(this["Collapse_"+b])a=this["Collapse_"+b](a);else if(this.COLLAPSE[b]&&this.MARKER[b]){var c=a.attr["data-semantic-role"],d=this.COLLAPSE[b];if("number"!=typeof d&&(d=d[c]||d.default),a.complexity>d){var e=this.MARKER[b];"string"!=typeof e&&(e=e[c]||e.default),a=this.MakeAction(this.Marker(e),a)}}return a},UncollapseChild:function(a,b,c){if(null==c&&(c=1),this.SplitAttribute(a,"children").length===c){var d=1===a.data.length&&a.data[0].inferred?a.data[0]:a;if(d&&d.data[b]&&d.data[b].collapsible)return d.SetData(b,d.data[b].data[1]),a.complexity=d.complexity=null,a.getComplexity(),1}return 0},FindChildText:function(a,b){var c=this.FindChild(a,b);return c?(c.CoreMO()||c).data.join(""):"?"},FindChild:function(a,b){if(a){if(a.attr&&a.attr["data-semantic-id"]===b)return a;if(!a.isToken)for(var c=0,d=a.data.length;c<d;c++){var e=this.FindChild(a.data[c],b);if(e)return e}}return null},SplitAttribute:function(a,b){return(a.attr["data-semantic-"+b]||"").split(/,/)},Collapse_fenced:function(a){if(this.UncollapseChild(a,1),a.complexity>this.COLLAPSE.fenced&&"leftright"===a.attr["data-semantic-role"]){var b=a.data[0].data.join("")+a.data[a.data.length-1].data.join("");a=this.MakeAction(this.Marker(b),a)}return a},Collapse_appl:function(a){if(this.UncollapseChild(a,2,2)){var b=this.MARKER.appl;b=b[a.attr["data-semantic-role"]]||b.default,a=this.Mak