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