commit c9578c7a0b7a5eadeebcab0a05e53676342098c6
parent 9ee925dfbbfb86f1698c5f26c54a0427fea15896
Author: Davide P. Cervone <dpvc@union.edu>
Date: Sat, 6 Apr 2013 20:04:48 -0400
Add localization submenu, and set locale via menu. Allow locale= configuration parameter on script to load MathJax.js. Load MathMenu domain automatically (so it is ready when needed).
Diffstat:
2 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/unpacked/MathJax.js b/unpacked/MathJax.js
@@ -1055,7 +1055,7 @@ MathJax.HTML = {
MathJax.Localization = {
- locale: "fr",
+ locale: "en",
directory: "[MathJax]/localization",
strings: {
en: {isLoaded: true}, // nothing needs to be loaded for this
@@ -1283,6 +1283,7 @@ MathJax.Localization = {
setLocale: function(locale) {
// don't set it if there isn't a definition for it
if (this.strings[locale]) {this.locale = locale}
+ if (MathJax.Menu) {this.loadDomain("MathMenu")}
},
//
@@ -1634,6 +1635,7 @@ MathJax.Hub = {
renderer: "", // set when Jax are loaded
font: "Auto", // what font HTML-CSS should use
context: "MathJax", // or "Browser" for pass-through to browser menu
+ locale: "en", // the language to use for messages
mpContext: false, // true means pass menu events to MathPlayer in IE
mpMouse: false, // true means pass mouse events to MathPlayer in IE
texHints: true // include class names for TeXAtom elements
@@ -2131,15 +2133,23 @@ MathJax.Hub.Startup = {
Config: function () {
this.queue.Push(["Post",this.signal,"Begin Config"]);
//
+ // If a locale is given as a parameter,
+ // set the locale and the default menu value for the locale
+ //
+ if (this.params.locale) {
+ MathJax.Localization.locale = this.params.locale;
+ MathJax.Hub.config.menuSettings.locale = this.params.locale;
+ }
+ //
// Check for user cookie configuration
//
var user = MathJax.HTML.Cookie.Get("user");
if (user.URL || user.Config) {
if (confirm(
MathJax.Localization._("CookieConfig",
- "MathJax has found a user-configuration cookie that includes code to"+
- "be run. Do you want to run it?\n\n"+
- "(You should press Cancel unless you set up the cookie yourself.)")
+ "MathJax has found a user-configuration cookie that includes code to "+
+ "be run. Do you want to run it?\n\n"+
+ "(You should press Cancel unless you set up the cookie yourself.)")
)) {
if (user.URL) {this.queue.Push(["Require",MathJax.Ajax,user.URL])}
if (user.Config) {this.queue.Push(new Function(user.Config))}
@@ -2207,6 +2217,7 @@ MathJax.Hub.Startup = {
//
// Read cookie and set up menu defaults
+ // (set the locale according to the cookie)
// (adjust the jax to accommodate renderer preferences)
//
Cookie: function () {
@@ -2214,6 +2225,8 @@ MathJax.Hub.Startup = {
["Post",this.signal,"Begin Cookie"],
["Get",MathJax.HTML.Cookie,"menu",MathJax.Hub.config.menuSettings],
[function (config) {
+ if (config.menuSettings.locale)
+ {MathJax.Localization.locale = config.menuSettings.locale}
var renderer = config.menuSettings.renderer, jax = config.jax;
if (renderer) {
var name = "output/"+renderer; jax.sort();
@@ -2332,7 +2345,16 @@ MathJax.Hub.Startup = {
MenuZoom: function () {
if (!MathJax.Extension.MathMenu) {
setTimeout(
- MathJax.Callback(["Require",MathJax.Ajax,"[MathJax]/extensions/MathMenu.js",{}]),
+ function () {
+ MathJax.Callback.Queue(
+ ["Require",MathJax.Ajax,"[MathJax]/extensions/MathMenu.js",{}],
+ ["loadDomain",MathJax.Localization,"MathMenu"]
+ )
+ },1000
+ );
+ } else {
+ setTimeout(
+ MathJax.Callback(["loadDomain",MathJax.Localization,"MathMenu"]),
1000
);
}
diff --git a/unpacked/extensions/MathMenu.js b/unpacked/extensions/MathMenu.js
@@ -56,6 +56,7 @@
showFontMenu: false, // show the "Font Preference" menu?
showContext: false, // show the "Context Menu" menu?
showDiscoverable: false, // show the "Discoverable" menu?
+ showLocale: true, // show the "Locale" menu?
windowSettings: { // for source window
status: "no", toolbar: "no", locationbar: "no", menubar: "no",
@@ -882,6 +883,15 @@
};
/*
+ * Handle selection of locale
+ */
+ MENU.Locale = function () {
+ MathJax.Localization.setLocale(CONFIG.settings.locale);
+ // FIXME: Rerender the page? (To force error messages to change?)
+ // Just rerender error messages?
+ }
+
+ /*
* Handle setting MathPlayer events
*/
MENU.MPEvents = function (item) {
@@ -1019,7 +1029,12 @@
),
ITEM.COMMAND(["Scale","Scale All Math ..."],MENU.Scale),
ITEM.RULE().With({hidden:!CONFIG.showDiscoverable, name:["","discover_rule"]}),
- ITEM.CHECKBOX(["Discoverable","Highlight on Hover"], "discoverable", {hidden:!CONFIG.showDiscoverable})
+ ITEM.CHECKBOX(["Discoverable","Highlight on Hover"], "discoverable", {hidden:!CONFIG.showDiscoverable}),
+ ITEM.RULE().With({hidden:!CONFIG.showLocale, name:["","locale_rule"]}),
+ ITEM.SUBMENU(["Locale","Locale"], {hidden:!CONFIG.showLocale},
+ ITEM.RADIO("en", "locale", {action: MENU.Locale}),
+ ITEM.RADIO("fr", "locale", {action: MENU.Locale})
+ )
),
ITEM.RULE(),
ITEM.COMMAND(["About","About MathJax"],MENU.About),
@@ -1059,10 +1074,15 @@
MENU.menu.Find("Math Settings","Contextual Menu").hidden = !show;
};
MENU.showDiscoverable = function (show) {
- MENU.cookie.showContext = CONFIG.showContext = show; MENU.saveCookie();
+ MENU.cookie.showDiscoverable = CONFIG.showDiscoverable = show; MENU.saveCookie();
MENU.menu.Find("Math Settings","Highlight on Hover").hidden = !show;
MENU.menu.Find("Math Settings","discover_rule").hidden = !show;
};
+ MENU.showLocale = function (show) {
+ MENU.cookie.showLocale = CONFIG.showLocale = show; MENU.saveCookie();
+ MENU.menu.Find("Math Settings","Locale").hidden = !show;
+ MENU.menu.Find("Math Settings","locale_rule").hidden = !show;
+ };
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
if (!MathJax.OutputJax["HTML-CSS"].config.imageFont)