Comparing version 0.2.19 to 0.3.0
@@ -34,6 +34,9 @@ var dom = exports.dom = require("./jsdom/level3/index").dom, | ||
exports.level = function (level, feature) { | ||
if(!feature) feature = 'core' | ||
return require('./jsdom/level' + level + '/' + feature).dom['level' + level][feature] | ||
} | ||
if(!feature) { | ||
feature = 'core'; | ||
} | ||
return require('./jsdom/level' + level + '/' + feature).dom['level' + level][feature]; | ||
}; | ||
exports.jsdom = function (html, level, options) { | ||
@@ -43,3 +46,3 @@ | ||
if(typeof level == "string") { | ||
level = exports.level(level, 'html') | ||
level = exports.level(level, 'html'); | ||
} else { | ||
@@ -65,5 +68,3 @@ level = level || exports.defaultLevel; | ||
if (options.features && options.features.QuerySelector) { | ||
require("./jsdom/selectors/index").applyQuerySelector(doc, level); | ||
} | ||
require("./jsdom/selectors/index").applyQuerySelector(doc, level); | ||
@@ -132,3 +133,3 @@ features.applyDocumentFeatures(doc, options.features); | ||
window.document.implementation.addFeature('ProcessExternalResources', ['script']); | ||
window.document.implementation.addFeature('MutationEvents', ["1.0"]); | ||
window.document.implementation.addFeature('MutationEvents', ["2.0"]); | ||
jQueryTag.src = path || 'http://code.jquery.com/jquery-latest.js'; | ||
@@ -198,3 +199,3 @@ window.document.body.appendChild(jQueryTag); | ||
window.document.implementation.addFeature('ProcessExternalResources', ['script']); | ||
window.document.implementation.addFeature('MutationEvents', ['1.0']); | ||
window.document.implementation.addFeature('MutationEvents', ['2.0']); | ||
@@ -201,0 +202,0 @@ var scriptComplete = function() { |
@@ -5,3 +5,2 @@ exports.availableDocumentFeatures = [ | ||
'MutationEvents', | ||
'QuerySelector', | ||
'SkipExternalResources' | ||
@@ -11,6 +10,5 @@ ]; | ||
exports.defaultDocumentFeatures = { | ||
"FetchExternalResources": ['script'/*, 'img', 'css', 'frame', 'link'*/], | ||
"FetchExternalResources": ['script', 'link'/*, 'img', 'css', 'frame'*/], | ||
"ProcessExternalResources": ['script'/*, 'frame', 'iframe'*/], | ||
"MutationEvents": '2.0', | ||
"QuerySelector": false, | ||
"SkipExternalResources": false | ||
@@ -17,0 +15,0 @@ }; |
@@ -9,2 +9,3 @@ var http = require('http'), | ||
jsdom = require('../../jsdom'), | ||
CSSStyleDeclaration = require('cssstyle').CSSStyleDeclaration, | ||
Contextify = null; | ||
@@ -70,6 +71,2 @@ | ||
if (options.features && options.features.QuerySelector) { | ||
require(__dirname + "/../selectors/index").applyQuerySelectorPrototype(browser); | ||
} | ||
options.document = (browser.HTMLDocument) ? | ||
@@ -90,3 +87,5 @@ new browser.HTMLDocument(options) : | ||
ev.initEvent('load', false, false); | ||
window.dispatchEvent(ev); | ||
process.nextTick(function () { | ||
window.dispatchEvent(ev); | ||
}); | ||
} | ||
@@ -242,12 +241,19 @@ else { | ||
var s = node.style, | ||
cs = {}; | ||
cs = new CSSStyleDeclaration(), | ||
forEach = Array.prototype.forEach; | ||
for (var n in s) { | ||
cs[n] = s[n]; | ||
} | ||
cs.__proto__ = { | ||
getPropertyValue: function(name) { | ||
return node.style[name]; | ||
} | ||
}; | ||
forEach.call(node.ownerDocument.styleSheets, function (sheet) { | ||
forEach.call(sheet.cssRules, function (ruleSet) { | ||
if (node.matchesSelector(ruleSet.selectorText)) { | ||
forEach.call(ruleSet.style, function (property) { | ||
cs.setProperty(property, ruleSet.style.getPropertyValue(property), ruleSet.style.getPropertyPriority(property)); | ||
}); | ||
} | ||
}); | ||
}); | ||
forEach.call(s, function (property) { | ||
cs.setProperty(property, s.getPropertyValue(property), s.getPropertyPriority(property)); | ||
}); | ||
return cs; | ||
@@ -254,0 +260,0 @@ }, |
@@ -1149,3 +1149,3 @@ /* | ||
this._documentElement = null; | ||
this._ids = {}; | ||
this._ids = Object.create(null); | ||
this._attached = true; | ||
@@ -1152,0 +1152,0 @@ this._ownerDocument = this; |
@@ -146,3 +146,3 @@ var core = require("./core").dom.level2.core, | ||
readFile: function(url, callback) { | ||
fs.readFile(url.replace(/^file:\/\//, "").replace(/^\/([a-z]):\//i, '$1:/'), 'utf8', callback); | ||
fs.readFile(url.replace(/^file:\/\//, "").replace(/^\/([a-z]):\//i, '$1:/').replace(/%20/g, ' '), 'utf8', callback); | ||
} | ||
@@ -737,9 +737,9 @@ }; | ||
blur: function() { | ||
//TODO | ||
blur : function() { | ||
this._ownerDocument.activeElement = this._ownerDocument.body; | ||
}, | ||
focus : function() { | ||
this._ownerDocument.activeElement = this; | ||
} | ||
focus: function() { | ||
//TODO | ||
} | ||
}, | ||
@@ -878,5 +878,7 @@ attributes: [ | ||
}, | ||
blur: function() { | ||
blur : function() { | ||
this._ownerDocument.activeElement = this._ownerDocument.body; | ||
}, | ||
focus: function() { | ||
focus : function() { | ||
this._ownerDocument.activeElement = this; | ||
}, | ||
@@ -941,5 +943,7 @@ select: function() { | ||
}, | ||
blur: function() { | ||
blur : function() { | ||
this._ownerDocument.activeElement = this._ownerDocument.body; | ||
}, | ||
focus: function() { | ||
focus : function() { | ||
this._ownerDocument.activeElement = this; | ||
}, | ||
@@ -966,2 +970,8 @@ select: function() { | ||
return closest(this, 'FORM'); | ||
}, | ||
focus : function() { | ||
this._ownerDocument.activeElement = this; | ||
}, | ||
blur : function() { | ||
this._ownerDocument.activeElement = this._ownerDocument.body; | ||
} | ||
@@ -1142,5 +1152,7 @@ }, | ||
proto: { | ||
blur: function() { | ||
blur : function() { | ||
this._ownerDocument.activeElement = this._ownerDocument.body; | ||
}, | ||
focus: function() { | ||
focus : function() { | ||
this._ownerDocument.activeElement = this; | ||
}, | ||
@@ -1147,0 +1159,0 @@ get href() { |
@@ -60,5 +60,20 @@ var core = require("./core").dom.level2.core, | ||
// StyleSheetList has the same interface as NodeList, so we'll use the same | ||
// object. | ||
core.StyleSheetList = core.NodeList; | ||
// StyleSheetList - | ||
// http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html#StyleSheets-StyleSheetList | ||
// added a push method to help manage the length | ||
core.StyleSheetList = function() { | ||
this._length = 0; | ||
}; | ||
core.StyleSheetList.prototype = { | ||
item: function (i) { | ||
return this[i]; | ||
}, | ||
push: function (sheet) { | ||
this[this._length] = sheet; | ||
this._length++; | ||
}, | ||
get length() { | ||
return this._length; | ||
} | ||
}; | ||
@@ -101,2 +116,3 @@ core.Document.prototype.__defineGetter__('styleSheets', function() { | ||
scanForImportRules.call(this, sheet.cssRules, baseUrl); | ||
this.ownerDocument.styleSheets.push(sheet); | ||
} | ||
@@ -103,0 +119,0 @@ /** |
@@ -1,17 +0,17 @@ | ||
var createSizzle = require("./sizzle"); | ||
exports.applyQuerySelector = function(doc, dom) { | ||
var addSizzle = function(document) { | ||
var nwmatcher = require("nwmatcher"); | ||
if (!document._sizzle) { | ||
document._sizzle = createSizzle(document); | ||
} | ||
return document._sizzle; | ||
}; | ||
function addNwmatcher(document) { | ||
if (!document._nwmatcher) { | ||
document._nwmatcher = nwmatcher({ document: document }); | ||
} | ||
return document._nwmatcher; | ||
} | ||
exports.applyQuerySelector = function(doc, dom) { | ||
doc.querySelector = function(selector) { | ||
return addSizzle(this)(selector, this)[0]; | ||
return addNwmatcher(this).first(selector, this); | ||
}; | ||
doc.querySelectorAll = function(selector) { | ||
return new dom.NodeList(addSizzle(this)(selector, this)); | ||
return new dom.NodeList(addNwmatcher(this).select(selector, this)); | ||
}; | ||
@@ -24,17 +24,15 @@ | ||
element.querySelector = function(selector) { | ||
return addSizzle(this.ownerDocument)(selector, this)[0]; | ||
return addNwmatcher(this.ownerDocument).first(selector, this); | ||
}; | ||
element.querySelectorAll = function(selector) { | ||
var el = this; | ||
if (!this.parentNode) { | ||
el = this.ownerDocument.createElement("div"); | ||
el.appendChild(this); | ||
} | ||
return new dom.NodeList(addSizzle(this.ownerDocument)(selector, el.parentNode || el)); | ||
return new dom.NodeList(addNwmatcher(this.ownerDocument).select(selector, this)); | ||
}; | ||
element.matchesSelector = function(selector) { | ||
return addNwmatcher(this.ownerDocument).match(this, selector); | ||
}; | ||
return element; | ||
}; | ||
}; |
{ | ||
"name": "jsdom", | ||
"version": "0.2.19", | ||
"version": "0.3.0", | ||
"description": "A JavaScript implementation of the W3C DOM", | ||
@@ -187,2 +187,3 @@ "keywords": [ | ||
"htmlparser" : "1.x", | ||
"nwmatcher" : ">=1.3.0", | ||
"request" : "2.x", | ||
@@ -189,0 +190,0 @@ "cssom" : "0.2.x", |
@@ -157,5 +157,5 @@ # jsdom | ||
var doc = jsdom("<html><body></body></html>", null, { | ||
features: { | ||
FetchExternalResources : ["img"] | ||
} | ||
features: { | ||
FetchExternalResources : ["img"] | ||
} | ||
}); | ||
@@ -170,6 +170,4 @@ ``` | ||
require("jsdom").defaultDocumentFeatures = { | ||
FetchExternalResources: ["script"], | ||
ProcessExternalResources: false, | ||
MutationEvents: false, | ||
QuerySelector: false | ||
FetchExternalResources: ["script"], | ||
ProcessExternalResources: false | ||
}; | ||
@@ -205,20 +203,2 @@ ``` | ||
`MutationEvents` | ||
- _Default_: `"2.0"` | ||
- _Allowed_ : `"2.0"` or `false` | ||
Initially enabled to be up to spec. Disable this if you do not need mutation events and want jsdom to be a bit more efficient. | ||
**Note**: `ProcessExternalResources` requires this to be enabled. | ||
`QuerySelector` | ||
- _Default_ : `false` | ||
- _Allowed_ : `true` | ||
This feature is backed by [sizzle][] but currently causes problems with some libraries. Enable this 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. | ||
[sizzle]: http://sizzlejs.com/ | ||
## Canvas | ||
@@ -301,4 +281,4 @@ | ||
level2/core 283/283 100% | ||
level2/html 694/694 100% | ||
level2/style 5/5 100% | ||
level2/html 695/695 100% | ||
level2/style 7/7 100% | ||
level2/extra 4/4 100% | ||
@@ -310,4 +290,4 @@ level2/events 24/24 100% | ||
window/frame 14/14 100% | ||
sizzle/index 12/15 80% | ||
jsdom/index 83/83 100% | ||
sizzle/index 8/14 57% | ||
jsdom/index 85/85 100% | ||
jsonp/jsonp 1/1 100% | ||
@@ -317,3 +297,3 @@ browser/contextifyReplacement 4/4 100% | ||
------------------------------------------------------ | ||
TOTALS: 3/2554 failed; 99% success | ||
TOTALS: 6/2558 failed; 99% success | ||
``` | ||
@@ -320,0 +300,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
5
3
341390
7
24
9931
311
+ Addednwmatcher@>=1.3.0
+ Addednwmatcher@1.4.4(transitive)