MDL-43856 MathJax: Improvements to the MathJax filter
[moodle.git] / filter / mathjaxloader / yui / build / moodle-filter_mathjaxloader-loader / moodle-filter_mathjaxloader-loader.js
blobea088053a1252d3f0fe90822fff862bd79da8a95
1 YUI.add('moodle-filter_mathjaxloader-loader', function (Y, NAME) {
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
18 /**
19  * Mathjax JS Loader.
20  *
21  * @package    filter_mathjaxloader
22  * @copyright  2014 Damyon Wiese  <damyon@moodle.com>
23  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24  */
25 M.filter_mathjaxloader = M.filter_mathjaxloader || {
26     init: function(params) {
28         // Add a js configuration object to the head.
29         // See "http://docs.mathjax.org/en/latest/dynamic.html#ajax-mathjax"
30         var script = document.createElement("script");
31         script.type = "text/x-mathjax-config";
32         script[(window.opera ? "innerHTML" : "text")] = params.mathjaxconfig;
33         document.getElementsByTagName("head")[0].appendChild(script);
35         MathJax.Localization.setLocale(params.lang);
37         Y.all('.filter_mathjaxloader_equation').each(function(node) {
38             MathJax.Hub.Queue(["Typeset",MathJax.Hub,node.getDOMNode()]);
39         });
40         MathJax.Hub.Configured();
42         // Listen for events triggered when new text is added to a page that needs
43         // processing by a filter.
45         Y.on(M.core.event.FILTER_CONTENT_UPDATED, this.contentUpdated, this);
46     },
48     /**
49      * Handle content updated events - typeset the new content.
50      * @method contentUpdated
51      * @param Y.Event - Custom event with "nodes" indicating the root of the updated nodes.
52      */
53     contentUpdated: function(event) {
54         event.nodes.each(function (node) {
55             node.all('.filter_mathjaxloader_equation').each(function(node) {
56                 MathJax.Hub.Queue(["Typeset",MathJax.Hub,node.getDOMNode()]);
57             });
58         });
59     }
63 }, '@VERSION@', {"requires": ["moodle-core-event", "mathjax"]});