Mercurial > jsm-in-web
changeset 0:c50d0dd32124
Origination.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 08 Apr 2009 14:47:24 -0700 |
parents | |
children | 2062295ebae2 |
files | blank.html index.html jsm-in-web.js server.py |
diffstat | 4 files changed, 104 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/blank.html Wed Apr 08 14:47:24 2009 -0700 @@ -0,0 +1,10 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> + <title>Blank</title> +</head> +<body> +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/index.html Wed Apr 08 14:47:24 2009 -0700 @@ -0,0 +1,13 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> + <title>JS Modules in the Web</title> +</head> +<body> +</body> +<script src="jquery.js"></script> +<script type="application/javascript;version=1.7" + src="jsm-in-web.js"></script> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jsm-in-web.js Wed Apr 08 14:47:24 2009 -0700 @@ -0,0 +1,69 @@ +var FILES_TO_LOAD = []; + +function loadJs(url, cb) { + jQuery.get( + url, + function(data) { + data = data.replace(/Components/g, "FakeComponents"); + cb(data); + } + ); +} + +function loadIframe(win, cb) { + var doc = win.document; + + var iframe = doc.createElement("iframe"); + iframe.setAttribute("src", "blank.html"); + iframe.style.display = "none"; + iframe.addEventListener( + "load", + function onLoad() { + iframe.removeEventListener("load", + onLoad, + true); + cb(iframe); + }, + true + ); + doc.body.appendChild(iframe); +} + +function onEverythingLoaded(iframes, codeFiles) { + console.log("all done."); + var win = iframes[0].contentWindow; + win.eval(codeFiles["blarg.js"]); + console.log(win.blar); +} + +function onFramesLoaded(iframes) { + var codeFiles = {}; + var filesLeft = FILES_TO_LOAD.length; + + FILES_TO_LOAD.forEach( + function(filename) { + loadJs(filename, + function(data) { + codeFiles[filename] = data; + filesLeft -= 1; + if (!filesLeft) { + onEverythingLoaded(iframes, codeFiles); + } + }); + } + ); +} + +$(window).ready( + function() { + var numFrames = FILES_TO_LOAD.length; + var iframes = []; + for (var i = 0; i < numFrames; i++) + loadIframe( + window, + function(iframe) { + iframes.push(iframe); + if (iframes.length == numFrames) + onFramesLoaded(iframes); + }); + });
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server.py Wed Apr 08 14:47:24 2009 -0700 @@ -0,0 +1,12 @@ +import CGIHTTPServer +import BaseHTTPServer + +PORT = 8000 + +Handler = CGIHTTPServer.CGIHTTPRequestHandler + +httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler) + +print "Serving files at http://localhost:%d" % PORT + +httpd.serve_forever()