mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-25 00:23:52 +00:00
1 line
7.8 KiB
JavaScript
1 line
7.8 KiB
JavaScript
|
!function(a){var b=a.config.menuSettings,c={},d=MathJax.Ajax.config.path;d.a11y||(d.a11y=a.config.root+"/extensions/a11y");var e=MathJax.Extension["auto-collapse"]={version:"1.5.0",config:a.CombineConfig("auto-collapse",{disabled:!1}),dependents:[],Enable:function(d,e){b.autocollapse=!0,e&&(c.autocollapse=!0),this.config.disabled=!1,MathJax.Extension.collapsible.Enable(!1,e),d&&a.Queue(["Reprocess",a],["CollapseWideMath",this])},Disable:function(d,e){b.autocollapse=!1,e&&(c.autocollapse=!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)}d&&a.Queue(["Rerender",a])},Dependent:function(a){this.dependents.push(a)},Startup:function(){var b=MathJax.Extension.collapsible;b&&b.Dependent(this),a.postInputHooks.Add(["Filter",e],150),a.Queue(function(){return e.CollapseWideMath()}),window.addEventListener?window.addEventListener("resize",e.resizeHandler,!1):window.attachEvent?window.attachEvent("onresize",e.resizeHandler):window.onresize=e.resizeHandler},Filter:function(a,b,c){a.enriched&&!this.config.disabled&&("block"===a.root.Get("display")||c.parentNode.childNodes.length<=3)&&(a.root.SRE={action:this.Actions(a.root)})},Actions:function(a){var b=[];return this.getActions(a,0,b),this.sortActions(b)},getActions:function(a,b,c){if(!a.isToken&&a.data){b++;for(var d=0,e=a.data.length;d<e;d++)if(a.data[d]){var f=a.data[d];f.collapsible?(c[b]||(c[b]=[]),c[b].push(f),this.getActions(f.data[1],b,c)):this.getActions(f,b,c)}}},sortActions:function(a){for(var b=[],c=0,d=a.length;c<d;c++)a[c]&&(b=b.concat(a[c].sort(this.sortActionsBy)));return b},sortActionsBy:function(a,b){return a=a.data[1].complexity,b=b.data[1].complexity,a<b?-1:a>b?1:0},CollapseWideMath:function(b){if(!this.config.disabled){this.GetContainerWidths(b);var c=a.getAllJax(b),d={collapse:[],jax:c,m:c.length,i:0,changed:!1};return this.collapseState(d)}},collapseState:function(b){for(var c=b.collapse;b.i<b.m;){var d=b.jax[b.i],e=d.root.SRE;if(b.changed=!1,e&&e.action.length&&(e.cwidth<e.m||e.cwidth>e.M)){var f=this.getActionWidths(d,b);if(f)return f;this.collapseActions(e,b),b.changed&&c.push(d.SourceElement())}b.i++}if(0!==c.length)return 1===c.length&&(c=c[0]),a.Rerender(c)},collapseActions:function(a,b){for(var c=a.width,d=c,e=1e6,f=a.action.length-1;f>=0;f--){var g=a.action[f],h=g.selection;c>a.cwidth?(g.selection=1,d=g.SREwidth,e=c):g.selection=2,c=g.SREwidth,a.DOMupdate?document.getElementById(g.id).setAttribute("selection",g.selection):g.selection!==h&&(b.changed=!0)}a.m=d,a.M=e},getActionWidths:function(a,b){if(!a.root.SRE.actionWidths){MathJax.OutputJax[a.outputJax].getMetrics(a);try{this.computeActionWidths(a)}catch(a){if(!a.restart)throw a;return MathJax.Callback.After(["collapseState",this,b],a.restart)}b.changed=!0}return null},computeActionWidths:function(a){var b,c=a.root.SRE,d=c.action,e={};for(c.width=a.sreGetRootWidth(e),b=d.length-1;b>=0;b--)d[b].selection=2;for(b=d.length-1;b>=0;b--){var f=d[b];null==f.SREwidth&&(f.selection=1,f.SREwidth=a.sreGetActionWidth(e,f))}c.actionWidths=!0},GetContainerWidths:function(b){var c,d,e,f,g,h=a.getAllJax(b),i=MathJax.HTML.Element("span",{style:{display:"block"}}),j=[];for(c=0,d=h.length;c<d;c++)f=h[c],g=f.root,SRE=g.SRE,SRE&&SRE.action.length&&(null==SRE.width&&(f.sreGetMetrics(),SRE.m=SRE.width,SRE.M=1e6),e=f.SourceElement(),e.previousSibling.style.display="none",e.parentNode.insertBefore(i.cloneNode(!1),e),j.push([f,e]));for(c=0,d=j.length;c<d;c++)f=j[c][0],e=j[c][1],e.previousSibling.offsetWidth&&(f.root.SRE.cwidth=e.previousSibling.offsetWidth*f.root.SRE.em);for(c=0,d=j.length;c<d;c++)f=j[c][0],e=j[c][1],e.parentNode.removeChild(e.previousSibling),e.previousSibling.style.display=""},timer:null,running:!1,retry:!1,saved_delay:0,resizeHandler:function(a){if(!e.config.disabled){if(e.running)return void(e.retry=!0);e.timer&&clearTimeout(e.timer),e.timer=setTimeout(e.resizeAction,100)}},resizeAction:function(){e.timer=null,e.running=!0,a.Queue(function(){e.saved_delay=a.processSectionDelay,a.processSectionDelay=0},["CollapseWideMath",e],["resizeChe
|