abstract_mathjax.js revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5/** 6 * @fileoverview Implentation of ChromeVox's bridge to MathJax. 7 * 8 */ 9 10goog.provide('cvox.AbstractMathJax'); 11 12goog.require('cvox.MathJaxInterface'); 13 14 15/** 16 * Creates a new instance. 17 * @constructor 18 * @implements {cvox.MathJaxInterface} 19 */ 20cvox.AbstractMathJax = function() { 21}; 22 23 24/** 25 * @override 26 */ 27cvox.AbstractMathJax.prototype.isMathjaxActive = goog.abstractMethod; 28 29 30/** 31 * @override 32 */ 33cvox.AbstractMathJax.prototype.getAllJax = goog.abstractMethod; 34 35 36/** 37 * @override 38 */ 39cvox.AbstractMathJax.prototype.registerSignal = goog.abstractMethod; 40 41 42/** 43 * @override 44 */ 45cvox.AbstractMathJax.prototype.getTex = goog.abstractMethod; 46 47 48/** 49 * @override 50 */ 51cvox.AbstractMathJax.prototype.getAsciiMath = goog.abstractMethod; 52 53 54/** 55 * @override 56 */ 57cvox.AbstractMathJax.prototype.injectScripts = goog.abstractMethod; 58 59 60/** 61 * @override 62 */ 63cvox.AbstractMathJax.prototype.configMediaWiki = goog.abstractMethod; 64 65 66/** 67 * Get MathML represententations for all images that have latex alt text. 68 * @param {function(Node, string)} callback A function taking a MathML node and 69 * an id string. 70 */ 71cvox.AbstractMathJax.prototype.getAllTexs = function(callback) { 72 var allTexs = document. 73 querySelectorAll(cvox.DomUtil.altMathQuerySelector('tex')); 74 for (var i = 0, tex; tex = allTexs[i]; i++) { 75 this.getTex(callback, tex); 76 } 77}; 78 79 80/** 81 * Get MathML represententations for all images that have asciimath alt text. 82 * @param {function(Node, string)} callback A function taking a MathML node and 83 * an id string. 84 */ 85cvox.AbstractMathJax.prototype.getAllAsciiMaths = function(callback) { 86 var allAsciiMaths = document. 87 querySelectorAll(cvox.DomUtil.altMathQuerySelector('asciimath')); 88 for (var i = 0, tex; tex = allAsciiMaths[i]; i++) { 89 this.getAsciiMath(callback, tex); 90 } 91}; 92 93 94/** 95 * Converts a XML markup string to a DOM node and applies a callback function. 96 * The function is generally used in the context of retrieving a MathJax 97 * element's MathML representation and converting it from a string. The callback 98 * is therefore use by MathJax internally in case the requested MathML 99 * representation is not ready yet. 100 * @param {function(Node, string)} callback A function taking a node and an id 101 * string. 102 * @param {string} mml The MathML string. 103 * @param {string} id The Mathjax node id. 104 */ 105cvox.AbstractMathJax.prototype.convertMarkupToDom = function( 106 callback, mml, id) { 107 if (mml) { 108 var dp = new DOMParser; 109 var cleanMml = mml.replace(/>\s+</g, '><'); 110 callback(dp.parseFromString(cleanMml, 'text/xml').firstChild, id); 111 } 112}; 113