]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Remove WebUtil.load_scripts
authorSolly Ross <sross@redhat.com>
Sat, 4 Feb 2017 22:40:18 +0000 (17:40 -0500)
committerSolly Ross <sross@redhat.com>
Tue, 7 Mar 2017 16:11:29 +0000 (11:11 -0500)
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.

app/webutil.js
core/util.js
package.json

index ca1f21bca480995e720052720fc9dc4bdeee46a4..2ce1b2d31bcb4389d1f1d4e4db8d0ae1169b6488 100644 (file)
@@ -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
index 9f048914ddf65e2cafd9e807b2d13caa4c95d7fe..08d7d78eb09f59eebb93ea450b29f6199f91ca05 100644 (file)
@@ -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;
         }
index f69f9cea687db2487a4c93edbe4e3293477fd5e6..d51f07dee6e351f6ee3f9a752e2a2dadb4679222 100644 (file)
     "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",