From 4c28cb6dbdd22b58cee98d1824c0f1f59d45d97d Mon Sep 17 00:00:00 2001 From: japborst Date: Mon, 26 Sep 2016 11:36:58 +0200 Subject: [PATCH] Add MathML CSS fallback --- assets/javascripts/vendor/mathml.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 assets/javascripts/vendor/mathml.js diff --git a/assets/javascripts/vendor/mathml.js b/assets/javascripts/vendor/mathml.js new file mode 100644 index 00000000..d9961c68 --- /dev/null +++ b/assets/javascripts/vendor/mathml.js @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Adapted from: https://github.com/fred-wang/mathml.css */ +/*jslint browser: true*/ + +(function () { + "use strict"; + window.addEventListener("load", function () { + var box, div, link, namespaceURI; + // First check whether the page contains any element. + namespaceURI = "http://www.w3.org/1998/Math/MathML"; + // Create a div to test mspace, using Kuma's "offscreen" CSS + document.body.insertAdjacentHTML("afterbegin", "
"); + div = document.body.firstChild; + box = div.firstChild.firstChild.getBoundingClientRect(); + document.body.removeChild(div); + if (Math.abs(box.height - 23) > 1 || Math.abs(box.width - 77) > 1) { + // Insert the mathml.css stylesheet. + link = document.createElement("link"); + link.href = "http://fred-wang.github.io/mathml.css/mathml.css"; + link.rel = "stylesheet"; + document.head.appendChild(link); + } + }); +}());