Socket
Socket
Sign inDemoInstall

jsdom

Package Overview
Dependencies
Maintainers
1
Versions
264
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdom - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

test/jsdom/index.js

28

example/jquery/run.js

@@ -1,17 +0,17 @@

var sys = require("sys"), fs = require("fs");
var sys = require("sys"),
jsdom = require(__dirname + "/../../lib/jsdom").jsdom,
window = jsdom().makeWindow(),
head = window.document.getElementsByTagName('head')[0],
jQueryTag = window.document.createElement("script");
var dom = require("../../lib/jsdom/level1/core").dom.level1.core;
var window = require("../../lib/jsdom/browser").windowAugmentation(dom).window;
var Script = process.binding('evals').Script;
jQueryTag.src = "http://code.jquery.com/jquery-1.4.2.js";
head.appendChild(jQueryTag);
fs.readFile(__dirname + "/jquery.js", function(err, data) {
try {
Script.runInNewContext(data.toString(), {window: window, location: window.location, navigator: window.navigator});
} catch(e){
sys.puts(sys.inspect(e));
jQueryTag.onload = function() {
if (this.readyState === 'complete') {
// jQuery is ready!
window.jQuery('body').append("<div class='testing'>Hello World, It works!</div>");
sys.puts(window.jQuery(".testing").text());
}
window.jQuery('body').append("<div class='testing'>Hello World, It works!</div>");
sys.puts(window.jQuery(".testing").text());
});
};

@@ -1,25 +0,16 @@

// TODO: add on other levels
exports.dom = require("./jsdom/level1/core").dom;
var dom = exports.dom = require("./jsdom/level1/core").dom;
exports.defaultLevel = dom.level1.core;
exports.browserAugmentation = require("./jsdom/browser").browserAugmentation;
exports.windowAugmentation = require("./jsdom/browser").windowAugmentation;
/*
Proposed API
// builds a dom with level2/core features
var dom = jsdom({features:["level2/core"]});
// builds a window with a dom capable of level2/core
var window = jsdom({
features : ["window", "level2/core"]
});
// builds a window swith a dom capable of level2/core and level2/events and no
// live node lists
var window = jsdom({
features : ["level2/core", "window", "level2/events"]
options : { livelists : false }
});
*/
exports.jsdom = function(level) {
level = level || exports.defaultLevel;
var doc = new (level.Document)();
doc.makeWindow = function() {
var window = exports.windowAugmentation(level, {document: doc});
delete window.document.makeWindow;
return window;
}
return doc;
}

@@ -1,2 +0,4 @@

var sys = require('sys');
var sys = require('sys'),
http = require('http'),
url = require('url');

@@ -16,6 +18,8 @@ var HtmlToDom = require('./htmltodom').HtmlToDom;

if(!options) options = {};
var browser = browserAugmentation(dom, options);
var document = (options.document) ?
options.document :
new (browser.Document)();
var Window = {
document: new browser.Document(),
document: document,
setTimeout: setTimeout,

@@ -67,10 +71,5 @@ setInterval: setInterval,

return {
window: Window,
self: Window,
document: Window.document,
navigator: Window.navigator,
location: Window.location
};
Window.window = Window;
Window.self = Window;
return Window;
};

@@ -189,2 +188,46 @@

dom.Document.prototype._elementBuilders['script'] = function(doc, name) {
var element = new dom.Element(doc, name);
element.__defineSetter__("src", function(value) {
var finish = function(data) {
element._text = data;
process.binding('evals').Script.runInNewContext(
element._text,
doc.parentWindow || { document: document }
);
element.readyState = 'complete';
if (element.onload) {
element.onload();
}
};
this._src = value;
if (value.substring(0,7) === "file://") {
require("fs").readFile(value.replace("file://",""), function(err, data) {
if (err) throw err;
finish(data);
});
} else {
var host = url.parse(value);
server = http.createClient(host.port || 80, host.hostname);
path = (host.search) ? host.pathname + "?" + host.search : host.pathname,
request = server.request('GET', path, {'host': host.hostname });
request.end();
request.on('response', function (response) {
response.setEncoding('utf8');
var data = "";
response.on('data', function (chunk) {
data += chunk;
});
response.on('end', function() {
finish(data);
});
});
}
});
element.__defineGetter__("src", function() { return this._src; });
return element;
};
dom.Element.prototype.__defineGetter__('outerHTML', function() {

@@ -197,3 +240,2 @@ return domToHtml(this);

});
dom.Element.prototype.__defineSetter__('innerHTML', function(html) {

@@ -200,0 +242,0 @@ //Check for lib first

@@ -1011,2 +1011,3 @@ /*

core.Document.prototype = {
_elementBuilders : {},
get contentType() { return this._contentType;},

@@ -1048,3 +1049,3 @@ get doctype() { return this._doctype || null;},

createElement: function(/* string */ tagName) {
var c = [];
var c = [], lower = tagName.toLowerCase(), element;
if (!tagName || !tagName.match || (c = tagName.match(/[^\w:\d_-]+/i))) {

@@ -1054,3 +1055,7 @@ throw new core.DOMException(INVALID_CHARACTER_ERR, 'Invalid character in tag name: ' + c.pop());

var element = new core.Element(this, tagName);
if (this._elementBuilders[lower]) {
element = this._elementBuilders[lower](this, tagName);
} else {
element = new core.Element(this, tagName);
}

@@ -1057,0 +1062,0 @@ // Check for and introduce default elements

{
"name": "jsdom",
"version": "0.1.4",
"version": "0.1.5",
"description": "CommonJS implementation of the DOM intended to be platform independent and as minimal/light as possible while completely adhering to the w3c DOM specifications.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -112,4 +112,10 @@ var sys = require("sys");

}
},
"jsdom" : { cases: require("./jsdom").tests, setUp : function() {
global.jsdom = require(__dirname + "/../lib/jsdom");
global.builder.contentType = "text/html";
global.builder.type = "html";
global.builder.testDirectory = "browser";
}
}
/*

@@ -116,0 +122,0 @@ Ignoring for now..

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc