aboutsummaryrefslogtreecommitdiff
path: root/third_party/websockify/include/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/websockify/include/util.js')
-rw-r--r--third_party/websockify/include/util.js62
1 files changed, 59 insertions, 3 deletions
diff --git a/third_party/websockify/include/util.js b/third_party/websockify/include/util.js
index ddc1914c..ab2e1c1e 100644
--- a/third_party/websockify/include/util.js
+++ b/third_party/websockify/include/util.js
@@ -1,7 +1,7 @@
/*
- * noVNC: HTML5 VNC client
- * Copyright (C) 2011 Joel Martin
- * Licensed under LGPL-3 (see LICENSE.txt)
+ * from noVNC: HTML5 VNC client
+ * Copyright (C) 2012 Joel Martin
+ * Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
@@ -57,6 +57,21 @@ if (!Array.prototype.map)
};
}
+//
+// requestAnimationFrame shim with setTimeout fallback
+//
+
+window.requestAnimFrame = (function(){
+ return window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ function(callback){
+ window.setTimeout(callback, 1000 / 60);
+ };
+})();
+
/*
* ------------------------------------------------------
* Namespaced in Util
@@ -131,6 +146,8 @@ Util.conf_default = function(cfg, api, defaults, v, mode, type, defval, desc) {
}
} else if (type in {'integer':1, 'int':1}) {
val = parseInt(val, 10);
+ } else if (type === 'str') {
+ val = String(val);
} else if (type === 'func') {
if (!val) {
val = function () {};
@@ -190,6 +207,45 @@ Util.conf_defaults = function(cfg, api, defaults, arr) {
* Cross-browser routines
*/
+
+// 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).
+Util.get_include_uri = function() {
+ return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI : "include/";
+}
+Util._pending_scripts = [];
+Util.load_scripts = function(files) {
+ var head = document.getElementsByTagName('head')[0],
+ ps = Util._pending_scripts;
+ for (var f=0; f<files.length; f++) {
+ var script = document.createElement('script');
+ script.type = 'text/javascript';
+ script.src = Util.get_include_uri() + files[f];
+ //console.log("loading script: " + Util.get_include_uri() + files[f]);
+ head.appendChild(script);
+ ps.push(script);
+ script.onload = script.onreadystatechange = function (e) {
+ if (!this.readyState ||
+ this.readyState == 'complete' ||
+ this.readyState == 'loaded') {
+ this.onload = this.onreadystatechange = null;
+ if (ps.indexOf(this) >= 0) {
+ //console.log("loaded script: " + this.src);
+ ps.splice(ps.indexOf(this), 1);
+ }
+ // Call window.onscriptsload after last script loads
+ if (ps.length === 0 && window.onscriptsload) {
+ window.onscriptsload();
+ }
+ }
+ }
+ }
+}
+
// Get DOM element position on page
Util.getPosition = function (obj) {
var x = 0, y = 0;