diff --git a/include/util.js b/include/util.js index 62d48a6..ab2e1c1 100644 --- a/include/util.js +++ b/include/util.js @@ -207,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= 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; diff --git a/include/websock.js b/include/websock.js index 87d6e8c..9d6a306 100644 --- a/include/websock.js +++ b/include/websock.js @@ -35,23 +35,14 @@ if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) { Websock_native = false; (function () { - function get_INCLUDE_URI() { - return (typeof INCLUDE_URI !== "undefined") ? - INCLUDE_URI : "include/"; - } - - var start = "