Created
January 12, 2011 01:25
-
-
Save ekashida/775513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require.paths.push('/usr/local/lib/node/'); | |
var sys = require('sys'), | |
http = require('http'), | |
express = require('express'), | |
jsdom = require('jsdom'); | |
var app = express.createServer(); | |
var responseLogic = function(req, res, callback) { | |
var window = jsdom.jsdom().createWindow(); | |
jsdom.jQueryify(window, '/Users/ekashida/jquery-1.4.4.min.js', function (window, jquery) { | |
window.jQuery('script').remove(); | |
callback(req, res, window); | |
res.send(window.document.innerHTML); | |
}); | |
} | |
app.jQueryGet = function(path, callback) { | |
app.get(path, function(req, res) { | |
responseLogic(req, res, callback); | |
}); | |
}; | |
// begin: app logic | |
app.jQueryGet('/', function(req, res, window) { | |
window.jQuery('body').append('<p>foo</p>'); | |
}); | |
app.jQueryGet('/foo/:id', function(req, res, window) { | |
var $ = window.jQuery; | |
$('body').append('<p>one</p>'); | |
$('body').append('<p>two</p>'); | |
$('body').append('<p>three</p>'); | |
$('p:nth-child(' + req.params.id + ')').addClass('big'); | |
}); | |
// end: app logic | |
app.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment