History

Add MathML CSS fallback

japborst committed 10 years ago

Commit 4c28cb61 parent f7ec3361 file · +26 −0Browse files

Unified · Split

assets/javascripts/vendor/mathml.js+26−0
@@ -0,0 +1,26 @@
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 * Adapted from: https://github.com/fred-wang/mathml.css */
5/*jslint browser: true*/
6
7(function () {
8 "use strict";
9 window.addEventListener("load", function () {
10 var box, div, link, namespaceURI;
11 // First check whether the page contains any <math> element.
12 namespaceURI = "http://www.w3.org/1998/Math/MathML";
13 // Create a div to test mspace, using Kuma's "offscreen" CSS
14 document.body.insertAdjacentHTML("afterbegin", "<div style='border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px;'><math xmlns='" + namespaceURI + "'><mspace height='23px' width='77px'></mspace></math></div>");
15 div = document.body.firstChild;
16 box = div.firstChild.firstChild.getBoundingClientRect();
17 document.body.removeChild(div);
18 if (Math.abs(box.height - 23) > 1 || Math.abs(box.width - 77) > 1) {
19 // Insert the mathml.css stylesheet.
20 link = document.createElement("link");
21 link.href = "http://fred-wang.github.io/mathml.css/mathml.css";
22 link.rel = "stylesheet";
23 document.head.appendChild(link);
24 }
25 });
26}());