Debian Codegraph @

unpacked/extensions/a11y/auto-collapse.js

raw
1 !function(c) {
2 var s = c.config.menuSettings, r = {}, t = MathJax.Ajax.config.path;
3 t.a11y || (t.a11y = c.config.root + "/extensions/a11y");
4 var l = MathJax.Extension["auto-collapse"] = {
5 version: "1.6.0",
6 config: c.CombineConfig("auto-collapse", {
7 disabled: !1
8 }),
9 dependents: [],
10 Enable: function(t, e) {
11 s.autocollapse = !0, e && (r.autocollapse = !0), this.config.disabled = !1, MathJax.Extension.collapsible.Enable(!1, e),
12 t && c.Queue([ "Reprocess", c ], [ "CollapseWideMath", this ]);
13 },
14 Disable: function(t, e) {
15 s.autocollapse = !1, e && (r.autocollapse = !1), this.config.disabled = !0;
16 for (var n = this.dependents.length - 1; 0 <= n; n--) {
17 var o = this.dependents[n];
18 o.Disable && o.Disable(!1, e);
19 }
20 t && c.Queue([ "Rerender", c ]);
21 },
22 Dependent: function(t) {
23 this.dependents.push(t);
24 },
25 Startup: function() {
26 var t = MathJax.Extension.collapsible;
27 t && t.Dependent(this), c.postInputHooks.Add([ "Filter", l ], 150), c.Queue(function() {
28 return l.CollapseWideMath();
29 }), window.addEventListener ? window.addEventListener("resize", l.resizeHandler, !1) : window.attachEvent ? window.attachEvent("onresize", l.resizeHandler) : window.onresize = l.resizeHandler;
30 },
31 Filter: function(t, e, n) {
32 t.enriched && !this.config.disabled && ("block" === t.root.Get("display") || n.parentNode.childNodes.length <= 3) && (t.root.SRE = {
33 action: this.Actions(t.root)
34 });
35 },
36 Actions: function(t) {
37 var e = [];
38 return this.getActions(t, 0, e), this.sortActions(e);
39 },
40 getActions: function(t, e, n) {
41 if (!t.isToken && t.data) {
42 e++;
43 for (var o, i = 0, a = t.data.length; i < a; i++) {
44 t.data[i] && ((o = t.data[i]).collapsible ? (n[e] || (n[e] = []), n[e].push(o),
45 this.getActions(o.data[1], e, n)) : this.getActions(o, e, n));
46 }
47 }
48 },
49 sortActions: function(t) {
50 for (var e = [], n = 0, o = t.length; n < o; n++) t[n] && (e = e.concat(t[n].sort(this.sortActionsBy)));
51 return e;
52 },
53 sortActionsBy: function(t, e) {
54 return (t = t.data[1].complexity) < (e = e.data[1].complexity) ? -1 : e < t ? 1 : 0;
55 },
56 CollapseWideMath: function(t) {
57 if (!this.config.disabled) {
58 this.GetContainerWidths(t);
59 var e = c.getAllJax(t), n = {
60 collapse: [],
61 jax: e,
62 m: e.length,
63 i: 0,
64 changed: !1
65 };
66 return this.collapseState(n);
67 }
68 },
69 collapseState: function(t) {
70 for (var e = t.collapse; t.i < t.m; ) {
71 var n = t.jax[t.i], o = n.root.SRE;
72 if (t.changed = !1, o && o.action.length && (o.cwidth < o.m || o.cwidth > o.M)) {
73 var i = this.getActionWidths(n, t);
74 if (i) return i;
75 this.collapseActions(o, t), t.changed && e.push(n.SourceElement());
76 }
77 t.i++;
78 }
79 if (0 !== e.length) return 1 === e.length && (e = e[0]), c.Rerender(e);
80 },
81 collapseActions: function(t, e) {
82 for (var n = t.width, o = n, i = 1e6, a = t.action.length - 1; 0 <= a; a--) {
83 var s = t.action[a], r = s.selection;
84 n > t.cwidth ? (s.selection = 1, o = s.SREwidth, i = n) : s.selection = 2, n = s.SREwidth,
85 t.DOMupdate ? document.getElementById(s.id).setAttribute("selection", s.selection) : s.selection !== r && (e.changed = !0);
86 }
87 t.m = o, t.M = i;
88 },
89 getActionWidths: function(t, e) {
90 if (!t.root.SRE.actionWidths) {
91 MathJax.OutputJax[t.outputJax].getMetrics(t);
92 try {
93 this.computeActionWidths(t);
94 } catch (t) {
95 if (!t.restart) throw t;
96 return MathJax.Callback.After([ "collapseState", this, e ], t.restart);
97 }
98 e.changed = !0;
99 }
100 return null;
101 },
102 computeActionWidths: function(t) {
103 var e, n = t.root.SRE, o = n.action, i = {};
104 for (n.width = t.sreGetRootWidth(i), e = o.length - 1; 0 <= e; e--) o[e].selection = 2;
105 for (e = o.length - 1; 0 <= e; e--) {
106 var a = o[e];
107 null == a.SREwidth && (a.selection = 1, a.SREwidth = t.sreGetActionWidth(i, a));
108 }
109 n.actionWidths = !0;
110 },
111 GetContainerWidths: function(t) {
112 for (var e, n, o, i = c.getAllJax(t), a = MathJax.HTML.Element("span", {
113 style: {
114 display: "block"
115 }
116 }), s = [], r = 0, l = i.length; r < l; r++) o = (n = i[r]).root, SRE = o.SRE, SRE && SRE.action.length && (null == SRE.width && (n.sreGetMetrics(),
117 SRE.m = SRE.width, SRE.M = 1e6), (e = n.SourceElement()).previousSibling.style.display = "none",
118 e.parentNode.insertBefore(a.cloneNode(!1), e), s.push([ n, e ]));
119 for (r = 0, l = s.length; r < l; r++) n = s[r][0], (e = s[r][1]).previousSibling.offsetWidth && (n.root.SRE.cwidth = e.previousSibling.offsetWidth * n.root.SRE.em);
120 for (r = 0, l = s.length; r < l; r++) n = s[r][0], (e = s[r][1]).parentNode.removeChild(e.previousSibling),
121 e.previousSibling.style.display = "";
122 },
123 timer: null,
124 running: !1,
125 retry: !1,
126 saved_delay: 0,
127 resizeHandler: function(t) {
128 l.config.disabled || (l.running ? l.retry = !0 : (l.timer && clearTimeout(l.timer),
129 l.timer = setTimeout(l.resizeAction, 100)));
130 },
131 resizeAction: function() {
132 l.timer = null, l.running = !0, c.Queue(function() {
133 l.saved_delay = c.processSectionDelay, c.processSectionDelay = 0;
134 }, [ "CollapseWideMath", l ], [ "resizeCheck", l ]);
135 },
136 resizeCheck: function() {
137 l.running = !1, c.processSectionDelay = l.saved_delay, l.retry && (l.retry = !1,
138 setTimeout(l.resizeHandler, 0));
139 }
140 };
141 c.Register.StartupHook("End Extensions", function() {
142 null == s.autocollapse ? s.autocollapse = !l.config.disabled : l.config.disabled = !s.autocollapse,
143 c.Register.StartupHook("MathMenu Ready", function() {
144 r = MathJax.Menu.cookie;
145 var t, e = MathJax.Menu.ITEM, n = MathJax.Menu.menu, o = e.CHECKBOX([ "AutoCollapse", "Auto Collapse" ], "autocollapse", {
146 action: function(t) {
147 l[s.autocollapse ? "Enable" : "Disable"](!0, !0), MathJax.Menu.saveCookie();
148 }
149 }), i = (n.FindId("Accessibility") || {}).submenu;
150 i ? null !== (t = i.IndexOfId("AutoCollapse")) ? i.items[t] = o : (t = i.IndexOfId("CollapsibleMath"),
151 i.items.splice(t + 1, 0, o)) : (t = n.IndexOfId("CollapsibleMath"), n.items.splice(t + 1, 0, o));
152 function a() {
153 l[s.autocollapse ? "Enable" : "Disable"]();
154 }
155 MathJax.Extension.collapse ? a() : MathJax.Hub.Register.StartupHook("Auto Collapse Ready", a);
156 }, 25);
157 }, 25);
158 }(MathJax.Hub), MathJax.ElementJax.Augment({
159 sreGetMetrics: function() {
160 MathJax.OutputJax[this.outputJax].sreGetMetrics(this, this.root.SRE);
161 },
162 sreGetRootWidth: function(t) {
163 return MathJax.OutputJax[this.outputJax].sreGetRootWidth(this, t);
164 },
165 sreGetActionWidth: function(t, e) {
166 return MathJax.OutputJax[this.outputJax].sreGetActionWidth(this, t, e);
167 }
168 }), MathJax.OutputJax.Augment({
169 getMetrics: function() {},
170 sreGetMetrics: function(t, e) {
171 e.cwidth = 1e6, e.width = 0, e.em = 12;
172 },
173 sreGetRootWidth: function(t, e) {
174 return 0;
175 },
176 sreGetActionWidth: function(t, e, n) {
177 return 0;
178 }
179 }), MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready", function() {
180 MathJax.OutputJax["HTML-CSS"].Augment({
181 sreGetMetrics: function(t, e) {
182 e.width = t.root.data[0].HTMLspanElement().parentNode.bbox.w, e.em = 1 / t.HTMLCSS.em / t.HTMLCSS.scale;
183 },
184 sreGetRootWidth: function(t, e) {
185 var n = t.root.data[0].HTMLspanElement();
186 return e.box = n.parentNode, e.box.bbox.w;
187 },
188 sreGetActionWidth: function(t, e, n) {
189 return t.root.data[0].toHTML(e.box).bbox.w;
190 }
191 });
192 }), MathJax.Hub.Register.StartupHook("SVG Jax Ready", function() {
193 MathJax.OutputJax.SVG.Augment({
194 getMetrics: function(t) {
195 this.em = MathJax.ElementJax.mml.mbase.prototype.em = t.SVG.em, this.ex = t.SVG.ex,
196 this.linebreakWidth = t.SVG.lineWidth, this.cwidth = t.SVG.cwidth;
197 },
198 sreGetMetrics: function(t, e) {
199 e.width = t.root.SVGdata.w / 1e3, e.em = 1 / t.SVG.em;
200 },
201 sreGetRootWidth: function(t, e) {
202 return e.span = document.getElementById(t.inputID + "-Frame"), t.root.SVGdata.w / 1e3;
203 },
204 sreGetActionWidth: function(t, e, n) {
205 this.mathDiv = e.span, e.span.appendChild(this.textSVG);
206 try {
207 t.root.data[0].toSVG();
208 } catch (t) {
209 var o = t;
210 }
211 if (e.span.removeChild(this.textSVG), o) throw o;
212 return t.root.data[0].SVGdata.w / 1e3;
213 }
214 });
215 }), MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready", function() {
216 MathJax.OutputJax.CommonHTML.Augment({
217 sreGetMetrics: function(t, e) {
218 e.width = t.root.CHTML.w, e.em = 1 / t.CHTML.em / t.CHTML.scale;
219 },
220 sreGetRootWidth: function(t, e) {
221 return e.span = document.getElementById(t.inputID + "-Frame").firstChild, e.tmp = document.createElement("span"),
222 e.tmp.className = e.span.className, t.root.CHTML.w / t.CHTML.scale;
223 },
224 sreGetActionWidth: function(t, e, n) {
225 e.span.parentNode.replaceChild(e.tmp, e.span), MathJax.OutputJax.CommonHTML.CHTMLnode = e.tmp;
226 try {
227 t.root.data[0].toCommonHTML(e.tmp);
228 } catch (t) {
229 var o = t;
230 }
231 if (e.tmp.parentNode.replaceChild(e.span, e.tmp), o) throw o;
232 return t.root.data[0].CHTML.w / t.CHTML.scale;
233 }
234 });
235 }), MathJax.Hub.Register.StartupHook("NativeMML Jax Ready", function() {
236 MathJax.OutputJax.NativeMML.Augment({
237 sreGetMetrics: function(t, e) {
238 var n = document.getElementById(t.inputID + "-Frame");
239 e.width = n.offsetWidth, e.em = 1, e.DOMupdate = !0;
240 },
241 sreGetRootWidth: function(t, e) {
242 return e.span = document.getElementById(t.inputID + "-Frame").firstChild, e.span.offsetWidth;
243 },
244 sreGetActionWidth: function(t, e, n) {
245 return document.getElementById(n.id).setAttribute("selection", 1), e.span.offsetWidth;
246 }
247 });
248 }), MathJax.Ajax.Require("[a11y]/collapsible.js"), MathJax.Hub.Register.StartupHook("Collapsible Ready", function() {
249 MathJax.Extension["auto-collapse"].Startup(), MathJax.Hub.Startup.signal.Post("Auto Collapse Ready"),
250 MathJax.Ajax.loadComplete("[a11y]/auto-collapse.js");
251 });