Home | History | Annotate | Download | only in interface
      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 
     10 goog.provide('cvox.AbstractMathJax');
     11 
     12 goog.require('cvox.MathJaxInterface');
     13 
     14 
     15 /**
     16  * Creates a new instance.
     17  * @constructor
     18  * @implements {cvox.MathJaxInterface}
     19  */
     20 cvox.AbstractMathJax = function() {
     21 };
     22 
     23 
     24 /**
     25  * @override
     26  */
     27 cvox.AbstractMathJax.prototype.isMathjaxActive = goog.abstractMethod;
     28 
     29 
     30 /**
     31  * @override
     32  */
     33 cvox.AbstractMathJax.prototype.getAllJax = goog.abstractMethod;
     34 
     35 
     36 /**
     37  * @override
     38  */
     39 cvox.AbstractMathJax.prototype.registerSignal = goog.abstractMethod;
     40 
     41 
     42 /**
     43  * @override
     44  */
     45 cvox.AbstractMathJax.prototype.getTex = goog.abstractMethod;
     46 
     47 
     48 /**
     49  * @override
     50  */
     51 cvox.AbstractMathJax.prototype.getAsciiMath = goog.abstractMethod;
     52 
     53 
     54 /**
     55  * @override
     56  */
     57 cvox.AbstractMathJax.prototype.injectScripts = goog.abstractMethod;
     58 
     59 
     60 /**
     61  * @override
     62  */
     63 cvox.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  */
     71 cvox.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  */
     85 cvox.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  */
    105 cvox.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