]> git.proxmox.com Git - mirror_novnc.git/commitdiff
include/vnc.js: dynamic load without document.write.
authorJoel Martin <github@martintribe.org>
Fri, 14 Sep 2012 21:29:35 +0000 (16:29 -0500)
committerJoel Martin <github@martintribe.org>
Mon, 17 Sep 2012 22:15:49 +0000 (17:15 -0500)
Instead of using document.write to load scripts, use createElement to
create and append script tags. document.write is problematic in a lot
of situation and in particular is not allowed in a Chrome
extension/packaged app.

Also, in webutil.js, instead of calling init_logging during parsing of
include/webutil.js, rely on the caller to do this. The problem is that
calling init_logging on parse tries to call Util logging functions and
the new model of dynamic load may not having Util loaded by the time
webutil is parsed.

include/vnc.js
include/webutil.js
vnc_auto.html

index 7679d845c0f95aae4dcbdb2f52120264f96ae874..435fdc47e58fa72afd8cc8c593a0533a03cbd0ef 100644 (file)
 function get_INCLUDE_URI() {
     return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI : "include/";
 }
+/*
+ * Dynamically load a script without using document.write()
+ * Reference: http://unixpapa.com/js/dyna.html
+ */
+function load_scripts(base, files) {
+    var head = document.getElementsByTagName('head')[0];
+    for (var i=0; i<files.length; i++) {
+        var script = document.createElement('script');
+        script.type = 'text/javascript';
+        script.src = base + files[i];
+        head.appendChild(script);
+    }
+}
 
-(function () {
-    "use strict";
-
-    var extra = "", start, end;
-
-    start = "<script src='" + get_INCLUDE_URI();
-    end = "'><\/script>";
-
-    // Uncomment to activate firebug lite
-    //extra += "<script src='http://getfirebug.com/releases/lite/1.2/" + 
-    //         "firebug-lite-compressed.js'><\/script>";
-
-    extra += start + "util.js" + end;
-    extra += start + "webutil.js" + end;
-    extra += start + "base64.js" + end;
-    extra += start + "websock.js" + end;
-    extra += start + "des.js" + end;
-    extra += start + "input.js" + end;
-    extra += start + "display.js" + end;
-    extra += start + "rfb.js" + end;
-    extra += start + "jsunzip.js" + end;
-
-    document.write(extra);
-}());
+load_scripts(get_INCLUDE_URI(),
+    ["util.js", "webutil.js", "base64.js", "websock.js", "des.js",
+     "input.js", "display.js", "rfb.js", "jsunzip.js"]);
 
index 70a0e8ffc82756dc9e531ffdb769ca12d2b0dec4..c12805f1a9928acdbbfbead644b8b2d1acaf7543 100644 (file)
@@ -37,14 +37,16 @@ if (!window.$D) {
  */
 
 // init log level reading the logging HTTP param
-WebUtil.init_logging = function() {
-    Util._log_level = (document.location.href.match(
-         /logging=([A-Za-z0-9\._\-]*)/) ||
-         ['', Util._log_level])[1];
-    
+WebUtil.init_logging = function(level) {
+    if (typeof level !== "undefined") {
+        Util._log_level = level;
+    } else {
+        Util._log_level = (document.location.href.match(
+            /logging=([A-Za-z0-9\._\-]*)/) ||
+            ['', Util._log_level])[1];
+    }
     Util.init_logging();
 };
-WebUtil.init_logging();
 
 
 WebUtil.dirObj = function (obj, depth, parent) {
index 2b60d779d642d224fadc543c594f1ce444da2d22..f5d28257f17633908e92cc5167666161362beb82 100644 (file)
@@ -90,6 +90,7 @@
             $D('sendCtrlAltDelButton').style.display = "inline";
             $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
 
+            WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
             document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
             // By default, use the host and port of server that served this file
             host = WebUtil.getQueryVar('host', window.location.hostname);