Permalink
Browse files

added callback to jQueryify

  • Loading branch information...
tmpvar committed Aug 12, 2010
1 parent 824a2f3 commit 77275a869c0034e2799d7a497a8fe8493265a8b8
Showing with 21 additions and 7 deletions.
  1. +9 −5 lib/jsdom.js
  2. +12 −2 test/jsdom/index.js
View
@@ -18,20 +18,24 @@ exports.jsdom = function (level) {
exports.createWindow = function (html, level) {
var window = exports.jsdom(level).createWindow();
window.document.innerHTML = html;
-
return window;
};
-exports.jQueryify = function (html, level, path) {
+exports.jQueryify = function (html, level, path, fn) {
var window = exports.createWindow(html, level);
var head = window.document.getElementsByTagName('head')[0],
jQueryTag = window.document.createElement("script");
path = path ? "file://" + path : 'http://code.jquery.com/jquery-1.4.2.js';
+
jQueryTag.src = path;
-
- head.appendChild(jQueryTag);
- return window;
+ jQueryTag.onload = function() {
+ if (this.readyState === 'complete') {
+ if (typeof fn === "function") {
+ fn();
+ }
+ }
+ };
};
View
@@ -2,8 +2,18 @@ var sys = require("sys");
exports.tests = {
build_window : function() {
- sys.debug(sys.inspect(jsdom));
var window = jsdom.jsdom().createWindow();
assertNotNull("window must be a new object!", window);
- }
+ },
+
+ /*
+ Async tests and mjsunit dont play well..
+ jquerify : function() {
+ var window = jsdom.jQueryify("<html><head></head><body><p>it works</p></body></html>", false, false,
+ function() {
+ console.dir(window);
+ assertEqual("jquery selectors should work at this point", window.jQuery("p").text(), "it works");
+ });
+ }*/
+
};

0 comments on commit 77275a8

Please sign in to comment.