Permalink
Browse files

updated readme

  • Loading branch information...
1 parent 16dfe29 commit 4faadca9a79ed3596002e382e9814538a6f2a4d7 @tmpvar committed Feb 16, 2011
Showing with 76 additions and 40 deletions.
  1. +0 −7 PLAN.md
  2. +76 −33 README.md
View
@@ -1,7 +0,0 @@
-# JSDOM Plan
-
- - comment level1
- - consider implementing HTML based elements in level1 (no tests currently.. boo)
- - consolidate/clean TODOs
- - consider a cleaner way to do "private" variables (as apposed to x._imPrivateISwear)
- - consider implementing dom level2, dom level2 events, and dom level3
View
@@ -1,6 +1,6 @@
# jsdom
-CommonJS implementation of the DOM intended to be platform independent and as minimal/light as
+CommonJS implementation of the DOM intended to be platform independent and as minimal/light as
possible while completely adhering to the w3c DOM specifications.
Currently Implemented and w3c Compliant:
@@ -9,27 +9,63 @@ Currently Implemented and w3c Compliant:
- DOM Level 2 (html/events) with partial level2/core support
- Browser (BOM) Augmentation (getElementsByClassName, getElementById, etc..)
-**Note**: Running the tests now requires [mjsunit.runner][]
+# Installation
-see: [mailing list][]
+ npm install jsdom
-see: [testlog][] for w3/jsdom test compliance
+or
-see: [plan][] for roadmap and thoughts about this project
+ git clone http://github.com/tmpvar/jsdom.git
+ cd jsdom
+ npm link .
-see: [project site][] for additional information
+# Easymode
+
+Bootstrapping a DOM is never easy, that is why a new method, jsdom.env(), has been
+added in jsdom 0.2.0 which should make everyone's lives easier.
+
+ // Count all of the links from the nodejs build page
+ var jsdom = require("jsdom");
+
+ jsdom.env("http://nodejs.org/dist/", [
+ 'http://code.jquery.com/jquery-1.5.min.js'
+ ], function(errors, window) {
+ console.log("there have been", window.$("a").length, "nodejs releases!");
+ });
+
+or with raw html
+
+ // Run some jQuery on a html fragment
+ var jsdom = require('jsdom');
+
+ jsdom.env('<p><a class="the-link" href="http://jsdom.org>JSDOM\'s Homepage</a></p>', [
+ 'http://code.jquery.com/jquery-1.5.min.js'
+ ], function(errors, window) {
+ console.log("contents of a.the-link:", window.$("a.the-link").text());
+ });
+
+or with a configuration object
+
+ // Fetch the first page of hackernews links
+ var jsdom = require('jsdom');
+
+ jsdom.env({
+ html : "http://news.ycombinator.com/",
+ scripts : ['http://code.jquery.com/jquery-1.5.min.js'],
+ done : function(errors, window) {
+ console.log("HN Links");
+ window.$("td.title a").each(function() {
+ console.log(" - " + window.$(this).text());
+ });
+ }
+ });
- [mailing list]: http://groups.google.com/group/jsdom
- [project site]: http://www.jsdom.org
- [mjsunit.runner]: http://github.com/tmpvar/mjsunit.runner
- [testlog]: http://github.com/tmpvar/jsdom/blob/master/test/testlog.txt
- [plan]: http://github.com/tmpvar/jsdom/blob/master/PLAN.md
# Flexibility
One of the stated goals of jsdom is to be as minimal and light as possible. This section details how
someone can change the behavior of `Document`s on the fly. These features are baked into
-the `DOMImplementation` that every `Document` has. These features can be tweaked in two ways:
+the `DOMImplementation` that every `Document` has, and may be tweaked in two ways:
1. When you create a new `Document` using the jsdom builder (`require('jsdom').jsdom()`)
@@ -45,12 +81,12 @@ will use the defaults specified below (see: Default Features)
2. Previous to creating any documents you can modify the defaults for all future documents
- require('jsdom').defaultDocumentFeatures = {
- FetchExternalResources : ['script'],
- ProcessExternalResources : false,
- MutationEvents : false,
- QuerySelector : false
- }
+ require('jsdom').defaultDocumentFeatures = {
+ FetchExternalResources : ['script'],
+ ProcessExternalResources : false,
+ MutationEvents : false,
+ QuerySelector : false
+ }
@@ -92,7 +128,7 @@ This feature is backed by [sizzle][]
[sizzle]: http://sizzlejs.com/ but currently causes problems with some libraries. Enable if you want `document.querySelector` and friends, but be aware that many libraries feature detect for this, and it may cause you a bit of trouble.
-# Examples
+# More Examples
## Creating a document-less window
@@ -110,9 +146,9 @@ This feature is backed by [sizzle][]
## Creating a browser-like BOM/DOM/Window
- var jsdom = require("./lib/jsdom").jsdom,
- document = jsdom("<html><head></head><body>hello world</body></html>"),
- window = document.createWindow();
+ var jsdom = require("./lib/jsdom").jsdom,
+ document = jsdom("<html><head></head><body>hello world</body></html>"),
+ window = document.createWindow();
console.log(window.document.innerHTML);
// output: '<html><head></head><body>hello world</body></html>'
@@ -123,17 +159,6 @@ This feature is backed by [sizzle][]
console.log(typeof window.document.getElementsByClassName);
// outputs: function
-## Load arbitrary scripts
- var document = require("jsdom").jsdom(),
- window = document.createWindow(),
- script = document.createElement("script");
-
- script.src = 'http://code.jquery.com/jquery-1.4.2.js';
- script.onload = function() {
- console.log(window.jQuery.fn.jquery);
- // outputs: 1.4.2
- };
- document.head.appendChild(script);
## jQueryify
@@ -144,3 +169,21 @@ This feature is backed by [sizzle][]
window.$('body').append('<div class="testing">Hello World, It works</div>');
console.log(window.$('.testing').text());
});
+
+# More
+
+see: [mailing list][]
+
+see: [testlog][] for w3/jsdom test compliance
+
+see: [plan][] for roadmap and thoughts about this project
+
+see: [project site][] for additional information
+
+ [mailing list]: http://groups.google.com/group/jsdom
+ [project site]: http://www.jsdom.org
+ [mjsunit.runner]: http://github.com/tmpvar/mjsunit.runner
+ [testlog]: http://github.com/tmpvar/jsdom/blob/master/test/testlog.txt
+ [plan]: http://github.com/tmpvar/jsdom/blob/master/PLAN.json
+
+[mjsunit.runner]: http://github.com/tmpvar/mjsunit.runner

0 comments on commit 4faadca

Please sign in to comment.