[go: nahoru, domu]

Skip to content

Commit

Permalink
Remove WebUtil.load_scripts
Browse files Browse the repository at this point in the history
The only remaining user of WebUtil.load_scripts was for loading
localisation.  Instead, we now load the localization information
over XHR as a JSON blob.
  • Loading branch information
DirectXMan12 committed Mar 7, 2017
1 parent 2a7c6d2 commit 6e74411
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 72 deletions.
69 changes: 0 additions & 69 deletions app/webutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,75 +208,6 @@ WebUtil.injectParamIfMissing = function (path, param, value) {
}
};

// Dynamically load scripts without using document.write()
// Reference: http://unixpapa.com/js/dyna.html
//
// Handles the case where load_scripts is invoked from a script that
// itself is loaded via load_scripts. Once all scripts are loaded the
// window.onscriptsloaded handler is called (if set).
WebUtil.get_include_uri = function (root_dir) {
return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI + root_dir + '/' : root_dir + '/';
};
WebUtil._loading_scripts = [];
WebUtil._pending_scripts = [];
WebUtil.load_scripts = function (files_by_dir) {
"use strict";
var head = document.getElementsByTagName('head')[0], script,
ls = WebUtil._loading_scripts, ps = WebUtil._pending_scripts;

var loadFunc = function (e) {
while (ls.length > 0 && (ls[0].readyState === 'loaded' ||
ls[0].readyState === 'complete')) {
// For IE, append the script to trigger execution
var s = ls.shift();
//console.log("loaded script: " + s.src);
head.appendChild(s);
}
if (!this.readyState ||
(Util.Engine.presto && this.readyState === 'loaded') ||
this.readyState === 'complete') {
if (ps.indexOf(this) >= 0) {
this.onload = this.onreadystatechange = null;
//console.log("completed script: " + this.src);
ps.splice(ps.indexOf(this), 1);

// Call window.onscriptsload after last script loads
if (ps.length === 0 && window.onscriptsload) {
window.onscriptsload();
}
}
}
};

var root_dirs = Object.keys(files_by_dir);

for (var d = 0; d < root_dirs.length; d++) {
var root_dir = root_dirs[d];
var files = files_by_dir[root_dir];

for (var f = 0; f < files.length; f++) {
script = document.createElement('script');
script.type = 'text/javascript';
script.src = WebUtil.get_include_uri(root_dir) + files[f];
//console.log("loading script: " + script.src);
script.onload = script.onreadystatechange = loadFunc;
// In-order script execution tricks
if (Util.Engine.trident) {
// For IE wait until readyState is 'loaded' before
// appending it which will trigger execution
// http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
ls.push(script);
} else {
// For webkit and firefox set async=false and append now
// https://developer.mozilla.org/en-US/docs/HTML/Element/script
script.async = false;
head.appendChild(script);
}
ps.push(script);
}
}
};

// sadly, we can't use the Fetch API until we decide to drop
// IE11 support or polyfill promises and fetch in IE11.
// resolve will receive an object on success, while reject
Expand Down
7 changes: 5 additions & 2 deletions core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ Util.Localisation = {
// Currently configured language
language: 'en',

// Current dictionary of translations
dictionary: undefined,

// Configure suitable language based on user preferences
setup: function (supportedLanguages) {
var userLanguages;
Expand Down Expand Up @@ -397,8 +400,8 @@ Util.Localisation = {

// Retrieve localised text
get: function (id) {
if (typeof Language !== 'undefined' && Language[id]) {
return Language[id];
if (typeof Util.Localisation.dictionary !== 'undefined' && Util.Localisation.dictionary[id]) {
return Util.Localisation.dictionary[id];
} else {
return id;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
"ansi": "^0.3.1",
"babel-core": "^6.22.1",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-es2015-modules-amd": "^6.22.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
"babel-plugin-transform-es2015-modules-systemjs": "^6.22.0",
"babel-plugin-transform-es2015-modules-umd": "^6.22.0",
"browser-es-module-loader": "^0.4.1",
"babelify": "^7.3.0",
"browser-es-module-loader": "^0.4.1",
"browserify": "^13.1.0",
"casperjs": "^1.1.3",
"chai": "^3.5.0",
Expand Down

0 comments on commit 6e74411

Please sign in to comment.