diff options
author | Hiroshi Ichikawa <gimite@gmail.com> | 2011-12-14 22:48:02 +0900 |
---|---|---|
committer | Hiroshi Ichikawa <gimite@gmail.com> | 2011-12-14 22:48:02 +0900 |
commit | 841b01d9f1f8620af349642d5a7f9ab7f0769c17 (patch) | |
tree | 084cb4e714aaf3640ef7374463cdabc5d7a0c99b | |
parent | 4f7b9f870eb69f7eb626260d8b972f573b447af4 (diff) | |
download | web-socket-js-841b01d9f1f8620af349642d5a7f9ab7f0769c17.tar.gz |
Using swfobject.addDomLoadEvent() to simplify the initialization.
-rw-r--r-- | web_socket.js | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/web_socket.js b/web_socket.js index aa7c5ea..0037d68 100644 --- a/web_socket.js +++ b/web_socket.js @@ -370,20 +370,12 @@ }; if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) { - var init = function(){ + // NOTE: + // This fires immediately if web_socket.js is dynamically loaded after + // the document is loaded. + swfobject.addDomLoadEvent(function() { WebSocket.__initialize(); - }; - if (document.readyState == "complete") { - // Document is already loaded. - init(); - } else if (window.addEventListener) { - // This fires earlier but is not supported by all browsers. - document.addEventListener("DOMContentLoaded", init, false); - // This is supported by all browsers. - window.addEventListener("load", init, false); - } else { - window.attachEvent("onload", init); - } + }); } })(); |