Permalink
Browse files

(re new) And voilà! It works!

  • Loading branch information...
1 parent 2f35e33 commit 3b1ce66fc64cb4beb271a5bdd7c06a81b5a068b3 @ELLIOTTCABLE committed Jun 22, 2011
Showing with 44 additions and 7 deletions.
  1. +27 −5 server.js
  2. +3 −2 template/ANAL.html
  3. +14 −0 template/ANAL.js
View
@@ -1,11 +1,33 @@
var util = require('util')
, fs = require('fs')
+, url = require('url')
+, http = require('http')
, jsdom = require('jsdom').jsdom
-, ANAL = {page: require('./Source/page')}
+, ANAL = {page: require('./Source/page')}
-fs.readFile('./template/ANAL.html', function(err, data) { if (err) throw err; var window
- window = jsdom(data).createWindow();
+
+,go = function(to, neverGoAlone) {
+ to.writeHead(200, "I LOVE YOU", {
+ 'Content-Type': "text/html; charset=utf-8"
+ , 'Content-Length': Buffer.byteLength(neverGoAlone, 'utf8') })
+ to.write(neverGoAlone, 'utf8')
+ to.end() }
+
+fs.readFile('./template/ANAL.html', function(err, data) { if (err) throw err; var server,
+ route = function(coming, going) { route[url.parse(coming.url).pathname](coming, going) }
+ route['/'] = function(coming, going) { var // »
+ window = jsdom(data).createWindow()
+ go(going, window.document.outerHTML)
+ }
+ route['/modified'] = function(coming, going) {
+ window = jsdom(data).createWindow()
+
+ ANAL.page.constructify(window)
+
+ go(going, window.document.outerHTML)
+ }
- ANAL.page.constructify(window);
- util.log(window.document.outerHTML);
+ server = new(http.Server)()
+ server.addListener('request', route)
+ server.listen(7441)
})
View
@@ -1,13 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang='en' xml:lang="en">
<head>
- <meta charset="UTF-8"/>
+ <meta charset="utf-8"/>
<title>ANAL</title>
<link rel="stylesheet" href="../template/ANAL.css"/>
- <script src="../Source/page.js"></script>
</head>
<body>
+ <a href="/modified" id="the.modifier">modify!</a>
<a href="http://google.com/search?q=elliottcable" id="the.link">elliottcable</a>
+ <script src="../template/ANAL.js"></script>
</body>
</html>
View
@@ -0,0 +1,14 @@
+(function(){ var body, script
+ body = document.getElementsByTagName('body')[0]
+ script = document.createElement('script')
+ script.type = 'text/javascript'
+ script.src = "../Source/page.js"
+ script.onload = function(){
+ document.getElementById('the.modifier').onclick = function(){
+ ANAL.page.constructify(window);
+ window.history.pushState({}, "", "/modified");
+ return false; }
+ }
+
+ body.appendChild(script)
+})()

0 comments on commit 3b1ce66

Please sign in to comment.