mathml.js 1.1 KB

12345678910111213141516171819202122232425
  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. (function () {
  6. window.addEventListener("load", function () {
  7. var box, div, link, namespaceURI;
  8. // First check whether the page contains any <math> element.
  9. namespaceURI = "http://www.w3.org/1998/Math/MathML";
  10. // Create a div to test mspace, using Kuma's "offscreen" CSS
  11. document.body.insertAdjacentHTML(
  12. "afterbegin",
  13. "<div style='border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px;'><math xmlns='" +
  14. namespaceURI +
  15. "'><mspace height='23px' width='77px'></mspace></math></div>",
  16. );
  17. div = document.body.firstChild;
  18. box = div.firstChild.firstChild.getBoundingClientRect();
  19. document.body.removeChild(div);
  20. if (Math.abs(box.height - 23) > 1 || Math.abs(box.width - 77) > 1) {
  21. window.supportsMathML = false;
  22. }
  23. });
  24. })();