MDL-43856 MathJax: Add a mathjax loader filter.

This commit is contained in:
Damyon Wiese 2013-11-20 16:47:16 +08:00
parent bc348632e1
commit 7f6753151e
15 changed files with 558 additions and 0 deletions

View file

@ -0,0 +1,46 @@
YUI.add('moodle-filter_mathjax-loader', function (Y, NAME) {
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mathjax JS Loader.
*
* @package filter_mathjax
* @copyright 2014 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
M.filter_mathjax = M.filter_mathjax || {
init : function(params) {
// Add an inline configuration tag to the head.
var config = Y.Node.create('<script type="text/x-mathjax-config"></script>');
config.setHTML(params.mathjaxconfig);
Y.one('head').append(config);
// Load the mathjax library.
Y.Get.js(params.mathjaxurl, function() {
// Tell mathjax to call back for the language files.
debugger;
MathJax.Localization.addTranslation(params.lang,null,{
menuTitle: params.langdescription,
directory: M.cfg.wwwroot + "/filter/mathjax/language.php?lang="
});
});
}
};
}, '@VERSION@', {"requires": ["get", "node"]});

View file

@ -0,0 +1 @@
YUI.add("moodle-filter_mathjax-loader",function(e,t){M.filter_mathjax=M.filter_mathjax||{init:function(t){var n=e.Node.create('<script type="text/x-mathjax-config"></script>');n.setHTML(t.mathjaxconfig),e.one("head").append(n),e.Get.js(t.mathjaxurl,function(){debugger;MathJax.Localization.addTranslation(t.lang,null,{menuTitle:t.langdescription,directory:M.cfg.wwwroot+"/filter/mathjax/language.php?lang="})})}}},"@VERSION@",{requires:["get","node"]});

View file

@ -0,0 +1,46 @@
YUI.add('moodle-filter_mathjax-loader', function (Y, NAME) {
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mathjax JS Loader.
*
* @package filter_mathjax
* @copyright 2014 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
M.filter_mathjax = M.filter_mathjax || {
init : function(params) {
// Add an inline configuration tag to the head.
var config = Y.Node.create('<script type="text/x-mathjax-config"></script>');
config.setHTML(params.mathjaxconfig);
Y.one('head').append(config);
// Load the mathjax library.
Y.Get.js(params.mathjaxurl, function() {
// Tell mathjax to call back for the language files.
debugger;
MathJax.Localization.addTranslation(params.lang,null,{
menuTitle: params.langdescription,
directory: M.cfg.wwwroot + "/filter/mathjax/language.php?lang="
});
});
}
};
}, '@VERSION@', {"requires": ["get", "node"]});

View file

@ -0,0 +1,45 @@
YUI.add('moodle-filter_mathjaxloader-loader', function (Y, NAME) {
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mathjax JS Loader.
*
* @package filter_mathjaxloader
* @copyright 2014 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
M.filter_mathjaxloader = M.filter_mathjaxloader || {
init: function(params) {
// Add a js configuration object to the head.
// See "http://docs.mathjax.org/en/latest/dynamic.html#ajax-mathjax"
var script = document.createElement("script");
script.type = "text/x-mathjax-config";
script[(window.opera ? "innerHTML" : "text")] = params.mathjaxconfig;
document.getElementsByTagName("head")[0].appendChild(script);
MathJax.Localization.setLocale(params.lang);
Y.all('.filter_mathjaxloader_equation').each(function(node) {
MathJax.Hub.Queue(["Typeset",MathJax.Hub,node.getDOMNode()]);
});
MathJax.Hub.Configured();
}
};
}, '@VERSION@', {"requires": ["mathjax"]});

View file

@ -0,0 +1 @@
YUI.add("moodle-filter_mathjaxloader-loader",function(e,t){M.filter_mathjaxloader=M.filter_mathjaxloader||{init:function(t){var n=document.createElement("script");n.type="text/x-mathjax-config",n[window.opera?"innerHTML":"text"]=t.mathjaxconfig,document.getElementsByTagName("head")[0].appendChild(n),MathJax.Localization.setLocale(t.lang),e.all(".filter_mathjaxloader_equation").each(function(e){MathJax.Hub.Queue(["Typeset",MathJax.Hub,e.getDOMNode()])}),MathJax.Hub.Configured()}}},"@VERSION@",{requires:["mathjax"]});

View file

@ -0,0 +1,45 @@
YUI.add('moodle-filter_mathjaxloader-loader', function (Y, NAME) {
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mathjax JS Loader.
*
* @package filter_mathjaxloader
* @copyright 2014 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
M.filter_mathjaxloader = M.filter_mathjaxloader || {
init: function(params) {
// Add a js configuration object to the head.
// See "http://docs.mathjax.org/en/latest/dynamic.html#ajax-mathjax"
var script = document.createElement("script");
script.type = "text/x-mathjax-config";
script[(window.opera ? "innerHTML" : "text")] = params.mathjaxconfig;
document.getElementsByTagName("head")[0].appendChild(script);
MathJax.Localization.setLocale(params.lang);
Y.all('.filter_mathjaxloader_equation').each(function(node) {
MathJax.Hub.Queue(["Typeset",MathJax.Hub,node.getDOMNode()]);
});
MathJax.Hub.Configured();
}
};
}, '@VERSION@', {"requires": ["mathjax"]});

View file

@ -0,0 +1,10 @@
{
"name": "moodle-filter_mathjaxloader-loader",
"builds": {
"moodle-filter_mathjaxloader-loader": {
"jsfiles": [
"loader.js"
]
}
}
}

View file

@ -0,0 +1,40 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mathjax JS Loader.
*
* @package filter_mathjaxloader
* @copyright 2014 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
M.filter_mathjaxloader = M.filter_mathjaxloader || {
init: function(params) {
// Add a js configuration object to the head.
// See "http://docs.mathjax.org/en/latest/dynamic.html#ajax-mathjax"
var script = document.createElement("script");
script.type = "text/x-mathjax-config";
script[(window.opera ? "innerHTML" : "text")] = params.mathjaxconfig;
document.getElementsByTagName("head")[0].appendChild(script);
MathJax.Localization.setLocale(params.lang);
Y.all('.filter_mathjaxloader_equation').each(function(node) {
MathJax.Hub.Queue(["Typeset",MathJax.Hub,node.getDOMNode()]);
});
MathJax.Hub.Configured();
}
};

View file

@ -0,0 +1,7 @@
{
"moodle-filter_mathjaxloader-loader": {
"requires": [
"mathjax"
]
}
}