summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolly Ross <sross@redhat.com>2017-02-04 17:40:18 -0500
committerSolly Ross <sross@redhat.com>2017-03-07 11:11:29 -0500
commit6e744119f81d8dcef496fc8de539481870321819 (patch)
treeb6506ac7648786a87ede99627a436c49065dcd3a
parent2a7c6d20ab7bb3684e6450249348337b34933df6 (diff)
downloadnovnc-6e744119f81d8dcef496fc8de539481870321819.tar.gz
Remove WebUtil.load_scripts
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.
-rw-r--r--app/webutil.js69
-rw-r--r--core/util.js7
-rw-r--r--package.json3
3 files changed, 7 insertions, 72 deletions
diff --git a/app/webutil.js b/app/webutil.js
index ca1f21b..2ce1b2d 100644
--- a/app/webutil.js
+++ b/app/webutil.js
@@ -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
diff --git a/core/util.js b/core/util.js
index 9f04891..08d7d78 100644
--- a/core/util.js
+++ b/core/util.js
@@ -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;
@@ -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;
}
diff --git a/package.json b/package.json
index f69f9ce..d51f07d 100644
--- a/package.json
+++ b/package.json
@@ -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",