Skip to content

Commit

Permalink
Added Dom Level 3 methods to browser augmentation for jQuery support …
Browse files Browse the repository at this point in the history
…as standard. Cleaned up examples to match.
  • Loading branch information
Jos Shepherd committed Jun 16, 2010
1 parent 65be3bd commit bef53ad
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
8 changes: 2 additions & 6 deletions lib/browser/browser.js → example/browser/browser.js
@@ -1,18 +1,15 @@

var sys = require('sys');


var dom = require('../level1/core').dom.level1.core;
var browser = require('./index').windowAugmentation(dom);

var dom = require('../../lib/level1/core').dom.level1.core;
var browser = require('../../lib/browser/index').windowAugmentation(dom);

var document = browser.document;
var window = browser.window;
var self = browser.self;
var navigator = browser.navigator;
var location = browser.location;


document.title = 'Test Title';

//GLOBAL
Expand All @@ -21,7 +18,6 @@ el.id = 'foo';
el.innerHTML = '<em>This is a test</em> This <strong class="odd">is another</strong> test ';
document.body.appendChild(el);


//SCOPED
var el2 = browser.document.createElement('div');
el2.id = 'foo2bar';
Expand Down
12 changes: 4 additions & 8 deletions example/jquery/run.js
@@ -1,16 +1,12 @@
var sys = require("sys"),
dom = require(__dirname +"/../../lib/level1/core").dom.level1.core,
fs = require("fs");
var sys = require("sys"), fs = require("fs");

var window = require(__dirname + "/../../lib/browser").windowAugmentation(dom);
var dom = require("../../lib/level1/core").dom.level1.core;
var window = require("../../lib/browser").windowAugmentation(dom).window;
var document = window.document;
var location = window.location;
var navigator = window.navigator = { userAgent: "node-js" };
global.window = window;
var navigator = window.navigator;

fs.readFile(__dirname + "/jquery.js", function(err, data) {
global.window.document.compareDocumentPosition = function() {};
dom.Node.prototype.addEventListener = window.addEventListener = window.document.addEventListener = function() {};

try {
eval(data.toString());
Expand Down
2 changes: 1 addition & 1 deletion example/pure/run.js
Expand Up @@ -4,7 +4,7 @@ var sax = require("./sax");
var sys = require("sys");



// TODO: change this example to use pluggable parser

/**
setup innerHTML setter
Expand Down
5 changes: 5 additions & 0 deletions lib/browser/index.js
Expand Up @@ -43,6 +43,9 @@ exports.windowAugmentation = function(dom, options) {
Window.addEventListener2 = function(type, fn, capture) {
fn.apply(Window);
};
Window.document.compareDocumentPosition = function() {};
Window.addEventListener = function() {};
Window.document.addEventListener = function() {};

var html = Window.document.createElement('html');
Window.document.appendChild(html);
Expand Down Expand Up @@ -93,6 +96,8 @@ var browserAugmentation = exports.browserAugmentation = function(dom, options) {
* Browser Augmentation *
***************************************/

dom.Node.prototype.addEventListener = function(){};

dom.Element.prototype.getElementsByClassName = function(className) {

var queryFunction = function(child) {
Expand Down

0 comments on commit bef53ad

Please sign in to comment.