From c4d47bb10ded2604c5284d61641d2381d2db0b2e Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sun, 7 Apr 2013 10:44:29 -0400 Subject: [PATCH] Add callback to loadDomain to make it easier to use --- unpacked/MathJax.js | 22 +++++++++++++--------- unpacked/extensions/FontWarnings.js | 8 ++------ unpacked/extensions/v1.0-warning.js | 1 + 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/unpacked/MathJax.js b/unpacked/MathJax.js index adcf16590..c2377bb18 100644 --- a/unpacked/MathJax.js +++ b/unpacked/MathJax.js @@ -1209,7 +1209,8 @@ MathJax.Localization = { // Load a langauge data file from the proper // directory and file. // - loadFile: function (file,data) { + loadFile: function (file,data,callback) { + callback = MathJax.Callback(callback||{}); file = (data.file || file); // the data's file name or the default name if (!file.match(/\.js$/)) {file += ".js"} // add .js if needed // @@ -1227,7 +1228,7 @@ MathJax.Localization = { // failed to load, so we don't continue to try to load it // over and over). // - var load = MathJax.Ajax.Require(file,function () {data.isLoaded = true}); + var load = MathJax.Ajax.Require(file,function () {data.isLoaded = true; return callback()}); // // Return the callback if needed, otherwise null. // @@ -1240,24 +1241,27 @@ MathJax.Localization = { // and return a callback for the loading operation. // Otherwise return null (data are loaded). // - loadDomain: function (domain) { - var load; - var localeData = this.strings[this.locale]; + loadDomain: function (domain,callback) { + var load, localeData = this.strings[this.locale]; if (localeData) { if (!localeData.isLoaded) { load = this.loadFile(this.locale,localeData); - // if the main file must be loaded, call us again to load domain - if (load) {return MathJax.Callback.After(["loadDomain",this,domain],load)} + if (load) { + return MathJax.Callback.Queue( + load,["loadDomain",this,domain] // call again to load domain + ).Push(callback); + } } if (localeData.domains && domain in localeData.domains) { var domainData = localeData.domains[domain]; if (!domainData.isLoaded) { load = this.loadFile(domain,domainData); - if (load) {return load} + if (load) {return MathJax.Callback.Queue(load).Push(callback)} } } } - return null; // localization data are loaded + // localization data are loaded, so just do the callback + return MathJax.Callback(callback)(); }, // diff --git a/unpacked/extensions/FontWarnings.js b/unpacked/extensions/FontWarnings.js index cc4868ee6..d633684f1 100644 --- a/unpacked/extensions/FontWarnings.js +++ b/unpacked/extensions/FontWarnings.js @@ -306,12 +306,8 @@ if (message.match(/- Web-Font/)) {if (localFonts) {MSG = "webFont"}} else if (message.match(/- using image fonts/)) {MSG = "imageFonts"} else if (message.match(/- no valid font/)) {MSG = "noFonts"} - if (MSG && CONFIG.Message[MSG]) { - MathJax.Callback.Queue( - ["loadDomain",MathJax.Localization,"FontWarnings"], // make sure these are available - [CREATEMESSAGE,CONFIG.Message[MSG]] - ); - } + if (MSG && CONFIG.Message[MSG]) + {MathJax.Localization.loadDomain("FontWarnings",[CREATEMESSAGE,CONFIG.Message[MSG]])} } }); } diff --git a/unpacked/extensions/v1.0-warning.js b/unpacked/extensions/v1.0-warning.js index f09e3eab5..b269f24bf 100644 --- a/unpacked/extensions/v1.0-warning.js +++ b/unpacked/extensions/v1.0-warning.js @@ -1,5 +1,6 @@ /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */ /* vim: set ts=2 et sw=2 tw=80: */ + /************************************************************* * * MathJax/extensions/v1.0-warning.js