Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed examples, and a bug in createWindow()

  • Loading branch information...
commit 30575d55da7aa03332b3e0c8d69c326726527652 1 parent 33797d9
@tmpvar authored
Showing with 23 additions and 21 deletions.
  1. +22 −9 README.md
  2. +1 −12 lib/jsdom.js
View
31 README.md
@@ -40,8 +40,8 @@ see: [project site][] for additional information
## Creating a browser-like BOM/DOM/Window
- var jsdom = require("jsdom"),
- window = jsdom.createWindow(
+ var jsdom = require("jsdom").jsdom,
+ window = jsdom().createWindow(
"<html><head></head><body>hello world</body></html>"
);
@@ -54,13 +54,26 @@ see: [project site][] for additional information
console.log(typeof window.document.getElementsByClassName);
// outputs: function
-## jQuery
+## Load arbitrary scripts
+ var jsdom = require("jsdom").jsdom,
+ window = jsdom().createWindow(),
+ script = window.document.createElement("script");
+
+ script.src = 'http://code.jquery.com/jquery-1.4.2.js';
+
+ script.onload = function() {
+ if (this.readyState === 'complete') {
+ console.log(window.jQuery.fn.jquery);
+ // outputs: 1.4.2
+ }
+ };
- var sys = require("sys"),
- jsdom = require(__dirname + "/../../lib/jsdom"),
+## jQueryify
+
+ var jsdom = require("jsdom"),
window = jsdom.jsdom().createWindow();
-
- jsdom.jQueryify(window, __dirname + "/jquery.js", function() {
- window.jQuery('body').append("&lt;div class='testing'&gt;Hello World, It works!&lt;/div&gt;");
- sys.puts(window.jQuery(".testing").text());
+
+ jsdom.jQueryify(window, "http://code.jquery.com/jquery-1.4.2.min.js" , function() {
+ window.jQuery('body').append(<div class='testing'>Hello World, It works</div>");
+ console.log(window.jQuery(".testing").text());
});
View
13 lib/jsdom.js
@@ -4,7 +4,7 @@ exports.defaultLevel = dom.level1.core;
exports.browserAugmentation = require("./jsdom/browser").browserAugmentation;
exports.windowAugmentation = require("./jsdom/browser").windowAugmentation;
-createWindow = require("./jsdom/browser").createWindow;
+var createWindow = exports.createWindow = require("./jsdom/browser").createWindow;
exports.jsdom = function (level) {
level = level || exports.defaultLevel;
@@ -22,17 +22,6 @@ exports.jsdom = function (level) {
return doc;
}
-exports.createWindow = function (html, level) {
- if (html) {
- var window = createWindow();
- window.document = new (level || exports.defaultLevel)();
- window.document.innerHTML = html;
- return window;
- } else {
- return createWindow();
- }
-};
-
exports.jQueryify = function (window /* path [optional], callback */) {
if (!window || !window.document) { return; }
Please sign in to comment.
Something went wrong with that request. Please try again.