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.19 to 0.1.20

lib/jsdom/level2/index.js

9

lib/jsdom.js

@@ -11,5 +11,10 @@

level = level || exports.defaultLevel;
var browser = exports.browserAugmentation(level, (options || {}));
doc = new (browser.Document)();
var browser = exports.browserAugmentation(level, (options || {})),
Document = browser.HTMLDocument || browser.Document;
doc = new Document();
if (options && options.url) {
doc.URL = options.url;
}
// Author: Swizec

@@ -16,0 +21,0 @@ // remove IE's expressions and expose what applies to us

@@ -20,5 +20,13 @@ //Make configurable from docType??

param: 1,
embed: 1
embed: 1
};
var singleTagsRegExp = (function() {
var tags = [];
for (var i in singleTags) {
tags.push(i);
}
return new RegExp('<' + tags.join('|<'), 'i');
})();
var uncanon = function(str, letter) {

@@ -95,12 +103,5 @@ return '-' + letter.toLowerCase();

var formatted = '',
reg = /(>)(<)(\/*)/g,
html = html.replace(reg, '$1\r\n$2$3'),
pad = 0,
tags = [];
pad = 0;
for (i in singleTags) {
tags.push(i);
}
tags = '<' + tags.join('|<');
html = html.replace(/(<(\/?\w+).*?>)(?=<(?!\/\2))/gi, '$1\r\n');
html.split('\r\n').forEach(function(node, index) {

@@ -116,4 +117,3 @@ var indent = 0, padding = '', i;

} else if (node.match( /^<\w[^>]*[^\/]>.*$/ )) {
var re = new RegExp(tags, i);
if (!re.exec(node)) {
if (!singleTagsRegExp.exec(node)) {
indent = 1;

@@ -134,3 +134,3 @@ }

return formatted;
}
};

@@ -189,3 +189,3 @@ var generateHtmlRecursive = function(element, rawText) {

for (var i=0; i<length; i++) {
ret += generateHtmlRecursive(dom.item(i));
ret += generateHtmlRecursive(dom.item(i));
}

@@ -203,2 +203,2 @@

}
};

@@ -131,3 +131,3 @@ var HTMLDecode = require('./htmlencoding').HTMLDecode;

try{
newNode.setAttribute(c, HTMLDecode(node.attribs[c]));
newNode.setAttribute(c.toLowerCase(), HTMLDecode(node.attribs[c]));
}catch(err) {

@@ -134,0 +134,0 @@ //console.log("raw: "+node.raw);

@@ -239,3 +239,3 @@ var sys = require('sys'),

var queryFunction = function(child) {
function filterByClassName(child) {
if (!child) {

@@ -263,31 +263,7 @@ return false;

if (this.ownerDocument &&
var disableLiveLists = this.ownerDocument &&
this.ownerDocument.implementation &&
this.ownerDocument.implementation.hasFeature("DisableLiveLists"))
{
return dom.mapDOMNodes(this, true, queryFunction);
} else {
return new dom.LiveNodeList(this._document, this, queryFunction);
}
};
this.ownerDocument.implementation.hasFeature("DisableLiveLists");
dom.Element.prototype.__defineSetter__("id", function(id) {
this.setAttribute("id", id);
id = this.getAttribute("id"); //Passed validation
if (!this._ownerDocument._ids) {
this._ownerDocument._ids = {};
}
if (id === '') {
delete this._ownerDocument._ids[id];
} else {
this._ownerDocument._ids[id] = this;
}
});
dom.Element.prototype.__defineGetter__("id",function() {
return this.getAttribute("id");
});
dom.Document.prototype.getElementById = function(id) {
return this._ids[id];
return new dom.NodeList(dom.mapper(this, filterByClassName), !disableLiveLists);
};

@@ -331,81 +307,2 @@

dom.Document.prototype._elementBuilders['script'] = function(doc, name) {
var element = new dom.Element(doc, name);
var realvalue;
var finish = function(data) {
element._text = data;
try
{
process.binding('evals').Script.runInNewContext(
element._text,
doc.parentWindow || { document: document },
realvalue
);
}
catch(e)
{
try
{
throw (new Error("trace last jsdom place"));
}
catch(epos)
{
console.log(epos.stack);
}
console.log(e.stack);
console.log(element._text);
}
element.readyState = 'complete';
if (element.onload) {
element.onload();
}
};
element.__defineSetter__("src", function(value) {
if (value.substring(0,7) === "file://") {
realvalue = value.substring(7);
} else {
realvalue = value;
}
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; });
element.__defineGetter__("text", function() { return this._text; });
element.__defineSetter__("text", function(data) {
finish(data);
});
return element;
};
dom.Element.prototype.__defineGetter__('outerHTML', function() {

@@ -546,15 +443,2 @@ return domToHtml(this);

dom.Element.prototype.createCaption = function(str) {
var el = document.createElement('caption');
el.innerHTML = str;
return el;
};
dom.Element.prototype.focus = function() { };
dom.Element.prototype.blur = function() {};
dom.Element.prototype.__defineGetter__('elements', function(val) {
//TODO
return {};
});
dom.Element.prototype.__defineGetter__('nodeName', function(val) {

@@ -576,143 +460,3 @@ return this._nodeName.toUpperCase();

dom.Element.prototype.__defineSetter__("href", function(val) {
this.setAttribute("href", val);
});
dom.Element.prototype.__defineGetter__("href",function() {
return this.getAttribute("href");
});
dom.Element.prototype.__defineSetter__("height", function(val) {
this.setAttribute("height", val);
});
dom.Element.prototype.__defineGetter__("height",function() {
return this.getAttribute("height");
});
dom.Element.prototype.__defineSetter__("width", function(val) {
this.setAttribute("width", val);
});
dom.Element.prototype.__defineGetter__("width",function() {
return this.getAttribute("width");
});
dom.Element.prototype.__defineSetter__("src", function(val) {
this.setAttribute("src", val);
});
dom.Element.prototype.__defineGetter__("src",function() {
return this.getAttribute("src");
});
dom.Element.prototype.__defineSetter__("lang", function(val) {
this.setAttribute("lang", val);
});
dom.Element.prototype.__defineGetter__("lang",function() {
return this.getAttribute("lang");
});
dom.Element.prototype.__defineSetter__("className", function(className) {
this.setAttribute("class", className);
});
dom.Element.prototype.__defineGetter__("className",function() {
return this.getAttribute("class");
});
dom.Element.prototype.__defineGetter__('disabled', function() {
return this.getAttribute('disabled') || false;
});
dom.Element.prototype.__defineSetter__('disabled', function(val) {
return this.setAttribute('disabled', val);
});
dom.Element.prototype.__defineGetter__('selected', function() {
return this.getAttribute('selected') || false;
});
dom.Element.prototype.__defineSetter__('selected', function(val) {
return this.setAttribute('selected', val);
});
dom.Element.prototype.__defineGetter__('checked', function() {
return this.getAttribute('checked') || false;
});
dom.Element.prototype.__defineSetter__('checked', function(val) {
return this.setAttribute('checked', val);
});
dom.Element.prototype.__defineGetter__('name', function() {
return this.getAttribute('name');
});
dom.Element.prototype.__defineSetter__('name', function(val) {
return this.setAttribute('name', val);
});
dom.Element.prototype.__defineGetter__('type', function() {
return this.getAttribute('type');
});
dom.Element.prototype.__defineSetter__('type', function(val) {
return this.setAttribute('type', val);
});
dom.Element.prototype.__defineGetter__('selected', function() {
return this.getAttribute('selected') || false;
});
dom.Element.prototype.__defineSetter__('selected', function(val) {
return this.setAttribute('selected', val);
});
dom.Element.prototype.__defineGetter__('rows', function() {
if (this.tagName.toUpperCase() == 'TBODY') {
return this.getElementsByTagName('tr');
} else {
//Throw Error
}
});
dom.Element.prototype.__defineGetter__('options', function() {
if (this.tagName.toUpperCase() == 'SELECT') {
return this.getElementsByTagName('option');
} else {
//Throw Error
}
});
dom.Element.prototype.__defineGetter__('selectedIndex', function() {
if (this.tagName.toUpperCase() == 'SELECT') {
var options = this.getElementsByTagName('option'),
index = options.length > 0 ? 0 : -1;
for (var i = 0; i < options.length; i++) {
if (options[i].selected) {
index = i;
}
}
return index;
} else {
//Throw Error
}
});
dom.Element.prototype.__defineSetter__('selectedIndex', function(index) {
if (this.tagName.toUpperCase() == 'SELECT') {
var options = this.getElementsByTagName('option');
for (var i = 0; i < options.length; i++) {
if (i === index) {
options[i].selected = true;
} else if (options[i].selected) {
options[i].selected = false;
}
}
return index;
} else {
//Throw Error
}
});
dom.Element.prototype.__defineGetter__('text', function() {

@@ -725,44 +469,3 @@ if (this.attributes.getNamedItem('value')) {

});
dom.Element.prototype.__defineGetter__('value', function() {
if (this.tagName.toUpperCase() === 'TEXTAREA') {
return this.innerHTML;
} else if (this.tagName.toUpperCase() === 'OPTION') {
return this.getAttribute('value');// || this.innerHTML;
} else if (this.tagName.toUpperCase() === 'SELECT') {
if (this.selectedIndex === -1) {
return '';
}
return this.options[this.selectedIndex].value;
}
return this.getAttribute('value') || '';
});
dom.Element.prototype.__defineSetter__('value', function(val) {
if (this.nodeName.toUpperCase() === 'TEXTAREA') {
this.nodeValue = this.innerHTML = val;
} else if (this.nodeName.toUpperCase() === 'SELECT') {
for (var i = 0; i < this.options.length; i++) {
if (this.options[i].value === val) {
this.selectedIndex = i;
}
}
return;
} else {
//this.nodeValue = this.innerHTML = val;
return this.setAttribute('value', val);
}
});
dom.Element.prototype.__defineGetter__('form', function() {
var e = this;
while (e) {
if (e.nodeName.toUpperCase() == 'FORM') {
return e;
}
e = e.parentNode;
}
return undefined;
});
dom.Element.prototype.__defineGetter__('textContent', function() {

@@ -769,0 +472,0 @@ var stripHTML = /<\S[^><]*>/g;

@@ -6,2 +6,8 @@ /*

mapper: function(parent, filter, recursive) {
return function() {
return core.mapDOMNodes(parent, recursive !== false, filter);
};
},
// Returns Array

@@ -17,11 +23,7 @@ mapDOMNodes : function(parent, recursive, callback) {

if (callback(child)) {
results[results.length] = child;
results.push(child);
}
if (recursive) {
result = core.mapDOMNodes(child, true, callback);
for (var a=0;a<result.length;a++) {
results.push(result[a]);
}
//results.push.apply(results, result);
results = results.concat(core.mapDOMNodes(child, true, callback));
}

@@ -102,52 +104,31 @@ }

core.NodeList = function(document, element, tagName) {
this._document = document;
this._element = element;
this._tagName = tagName;
core.NodeList = function(query, live) {
this._query = query;
this.update();
};
core.NodeList.prototype = {
/* returns Node */
item : function(index) {
return this[index] || null;
update: function() {
for (var i = 0; i < this._length; i++) {
this[i] = undefined;
}
var nodes = this._snapshot = this._query();
this._length = nodes.length;
for (var i = 0; i < nodes.length; i++) {
this[i] = nodes[i];
}
return nodes;
},
// Array Remove - By John Resig (MIT Licensed)
remove : function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
toArray: function() {
return this.update();
},
toString: function() {
return '[ jsdom NodeList ]: contains ' + this.length + ' items';
}
};
core.NodeList.prototype.__proto__ = Array.prototype;
core.LiveNodeList = function(document, element, callback) {
this._callback = callback;
this._element = element;
this._document = document || element;
// TODO WARNING: this PROBABLY will cause unexpected behavior if used
var results = core.mapDOMNodes(this._element, true, this._callback);
for (var i = 0;i < results.length;i++) {
this[i] = results[i];
}
};
core.LiveNodeList.prototype = {
/* returns Integer */
get length() {
var results = core.mapDOMNodes(this._element, true, this._callback);
return results.length || 0;
this.update();
return this._length;
},
/* returns Node */
item : function(index) {
var results = core.mapDOMNodes(this._element, true, this._callback);
return results[index] || null;
item: function(index) {
this.update();
return this[index] || null;
},
toString: function() {
return '[ jsdom LiveNodeList ]: contains ' + this.length + ' items';
return '[ jsdom NodeList ]: contains ' + this.length + ' items';
}

@@ -158,6 +139,10 @@ };

this._ownerDocument = document;
this._features = features;
if (features) {
this._features = features;
}
};
core.DOMImplementation.prototype = {
_features : {},
get ownerDocument() { return this._ownerDocument;},

@@ -192,3 +177,4 @@ hasFeature: function(/* string */ feature, /* string */ version) {

core.Node = function (ownerDocument) {
this._children = new core.NodeList();
var childArray = this._childArray = [];
this._children = new core.NodeList(function() { return childArray });
this._nodeValue = null;

@@ -244,5 +230,3 @@ this._parentNode = null;

get firstChild() {
return (this._children && this._children.length && this._children.item(0)) ?
this._children.item(0) :
null;
return this._childArray.length > 0 ? this._childArray[0] : null;
},

@@ -254,9 +238,4 @@ set firstChild() { throw new core.DOMException();},

get lastChild() {
if (this._children &&
this._children.length &&
this._children[this._children.length-1])
{
return this._children.item(this._children.length-1);
}
return null;
var len = this._childArray.length;
return len > 0 ? this._childArray[len -1] : null;
},

@@ -354,4 +333,4 @@ set lastChild() { throw new core.DOMException();},

for (var i=0;i<this._children.length;i++) {
if (this._children[i] === refChild) {
for (var i=0;i<this._childArray.length;i++) {
if (this._childArray[i] === refChild) {
var current = this;

@@ -375,3 +354,3 @@ // search for parents matching the newChild

} else {
this._children.splice(i,0,newChild);
this._childArray.splice(i,0,newChild);
newChild._parentNode = this;

@@ -408,5 +387,5 @@ }

for (var i=0;i<this._children.length;i++)
for (var i=0;i<this._childArray.length;i++)
{
if (this._children[i] === oldChild) {
if (this._childArray[i] === oldChild) {
var current = this;

@@ -420,3 +399,3 @@ // search for parents matching the newChild

this._children.remove(i,i);
this._childArray.splice(i,1);

@@ -433,6 +412,6 @@ if (newChild.parentNode && newChild.parentNode.removeChild) {

child = newChild.children.item(j);
this._children.splice(i+j,0, child);
this._childArray.splice(i+j,0, child);
}
} else {
this._children.splice(i,0, newChild);
this._childArray.splice(i,0, newChild);
}

@@ -455,7 +434,7 @@

var found = false, child;
for (var i=0;i<this._children.length;i++) {
if (this._children[i] === oldChild) {
for (var i=0;i<this._childArray.length;i++) {
if (this._childArray[i] === oldChild) {
found=true;
child = this._children[i];
this._children.remove(i,i);
child = this._childArray[i];
this._childArray.splice(i,1);
oldChild._parentNode = null;

@@ -535,3 +514,5 @@

if (newChild && newChild.parentNode) {
newChild.parentNode.removeChild(newChild);
try {
newChild.parentNode.removeChild(newChild);
} catch (e) {}
}

@@ -541,3 +522,3 @@

newChild._parentNode = this;
this._children.push(newChild);
this._childArray.push(newChild);

@@ -668,5 +649,5 @@ if (newChild.id) {

for (i=0;i<this._children.length;i++)
for (i=0;i<this._childArray.length;i++)
{
child = this._children[i];
child = this._childArray[i];

@@ -678,3 +659,3 @@ if (child.normalize) {

if (i>0) {
prevChild = this._children[i-1];
prevChild = this._childArray[i-1];

@@ -1002,3 +983,3 @@ if (child.nodeType === this.TEXT_NODE &&

getElementsByTagName: function(/* string */ name) {
var queryFunction = function(child) {
function filterByTagName(child) {
if (child.nodeType && child.nodeType ===

@@ -1028,10 +1009,7 @@ core.Node.prototype.ENTITY_REFERENCE_NODE)

if (this.ownerDocument &&
var disableLiveLists = this.ownerDocument &&
this.ownerDocument.implementation &&
this.ownerDocument.implementation.hasFeature("DisableLiveLists"))
{
return core.mapDOMNodes(this, true, queryFunction);
} else {
return new core.LiveNodeList(this._document, this, queryFunction);
}
this.ownerDocument.implementation.hasFeature("DisableLiveLists");
return new core.NodeList(core.mapper(this, filterByTagName), !disableLiveLists);
},

@@ -1092,2 +1070,5 @@ };

_elementBuilders : {},
_defaultElementBuilder: function(document, tagName) {
return new core.Element(document, tagName);
},
_nodes: null,

@@ -1101,3 +1082,3 @@ get contentType() { return this._contentType;},

} else {
var children = this._children, len = this._children.length, i=0;
var children = this._childArray, len = this._childArray.length, i=0;
for (i;i<len;i++) {

@@ -1137,9 +1118,4 @@ if (children[i].nodeType === this.ELEMENT_NODE) {

element = (this._elementBuilders[lower] || this._defaultElementBuilder)(this, tagName);
if (this._elementBuilders[lower]) {
element = this._elementBuilders[lower](this, tagName);
} else {
element = new core.Element(this, tagName);
}
// Check for and introduce default elements

@@ -1294,3 +1270,3 @@ if (this.doctype && this.doctype._attributes && this.doctype.name.toLowerCase() !== "html") {

this._children.push(newChild);
this._childArray.push(newChild);

@@ -1430,21 +1406,12 @@ // Attach the parent node.

get nodeValue() {
var val = "", child, i, j;
if (this._children.length > 0) {
for (i=0;i<this._children.length;i++)
{
child = this._children.item(i);
if (child.nodeType === this.ENTITY_REFERENCE_NODE) {
for (j=0;j<child.childNodes.length;j++) {
val+=(child.childNodes.item(j).nodeValue) ?
child.childNodes.item(j).nodeValue :
child.childNodes.item(j);
}
} else {
val += child.nodeValue;
}
var val = '';
this._childArray.forEach(function(child) {
if (child.nodeType === core.Node.prototype.ENTITY_REFERENCE_NODE) {
val += child.childNodes.toArray().reduce(function(prev, c) {
return prev += (c.nodeValue || c);
}, '');
} else {
val += child.nodeValue;
}
}
});
return val;

@@ -1458,4 +1425,4 @@ },

this._children.length = 0;
this._children.push(this.ownerDocument.createTextNode(value));
this._childArray.length = 0;
this._childArray.push(this.ownerDocument.createTextNode(value));
this._specified = true;

@@ -1462,0 +1429,0 @@ this._nodeValue = value;

@@ -268,3 +268,4 @@ var core = require("../level1/core").dom.level1.core,

var nsPrefixCache = {};
var queryFunction = function(child) {
function filterByTagName(child) {
if (child.nodeType && child.nodeType === this.ENTITY_REFERENCE_NODE) {

@@ -284,10 +285,7 @@ child = child._entity;

if (this.ownerDocument &&
var disableLiveLists = this.ownerDocument &&
this.ownerDocument.implementation &&
this.ownerDocument.implementation.hasFeature("DisableLiveLists"))
{
return core.mapDOMNodes(this, true, queryFunction);
} else {
return new core.LiveNodeList(this._document, this, queryFunction);
}
this.ownerDocument.implementation.hasFeature("DisableLiveLists");
return new core.NodeList(core.mapper(this, filterByTagName), !disableLiveLists);
};

@@ -383,13 +381,24 @@

core.Element.prototype.__defineSetter__("id", function(id) {
this.setAttribute("id", id);
id = this.getAttribute("id"); //Passed validation
if (!this._ownerDocument._ids) {
this._ownerDocument._ids = {};
}
if (id === '') {
delete this._ownerDocument._ids[id];
} else {
this._ownerDocument._ids[id] = this;
}
});
core.Element.prototype.__defineGetter__("id",function() {
return this.getAttribute("id");
});
core.Document.prototype.getElementById = function(id) {
return core.mapDOMNodes(this, true, function(element) {
if (element && element.getAttribute) {
var elementId = element.getAttribute("id");
if (elementId === id) {
return true;
}
}
})[0] || null;
return this._ids[id] || null;
};
exports.dom =

@@ -396,0 +405,0 @@ {

@@ -331,3 +331,3 @@ /* DOM Level2 Events implemented as described here:

ev = target.ownerDocument.createEvent("MutationEvents");
ev.initMutationEvent("DOMAttrModified", true, false, this._parentNode, null, node.value, node.name, ev.ADDITION);

@@ -334,0 +334,0 @@ node = level1.call(this, node);

@@ -1,579 +0,1420 @@

var core = require("./core").dom.level2.core;
var core = require("./core").dom.level2.core,
urlParse = require("url").parse,
request = require("request");
readFile = require("fs").readFile,
http = require('http');
/*
// Setup the javascript language processor
core.languageProcessors = {
javascript : require(__dirname + "/languages/javascript").javascript
};
// File: html2.idl
require("./core").dom.level2.events;
#ifndef _HTML2_IDL_
#define _HTML2_IDL_
function define(elementClass, def) {
var tagName = def.tagName,
tagNames = def.tagNames || (tagName? [tagName] : []),
parentClass = def.parentClass || core.HTMLElement,
attrs = def.attributes || [],
proto = def.proto || {};
var elem = core[elementClass] = function(document, name) {
parentClass.call(this, document, name || tagName.toUpperCase());
};
elem.prototype = proto;
elem.prototype.__proto__ = parentClass.prototype;
#include "dom.idl"
attrs.forEach(function(n) {
var prop = n.prop || n,
attr = n.attr || prop.toLowerCase();
if (!n.prop || n.read !== false) {
elem.prototype.__defineGetter__(prop, function() {
var s = this.getAttribute(attr);
if (n.type && n.type == 'boolean') {
return !!s;
}
if (n.type && n.type == 'long') {
return +s;
}
return s;
});
}
#pragma prefix "dom.w3c.org"
module html2
{
if (!n.prop || n.write !== false) {
elem.prototype.__defineSetter__(prop, function(val) {
if (!val) {
this.removeAttribute(attr);
}
else {
this.setAttribute(attr, val.toString());
}
});
}
});
tagNames.forEach(function(tag) {
core.Document.prototype._elementBuilders[tag.toLowerCase()] = function(doc, s) {
typedef dom::DOMString DOMString;
typedef dom::Node Node;
typedef dom::Document Document;
typedef dom::NodeList NodeList;
typedef dom::Element Element;
if (def && def.init) {
def.init(el);
}
interface HTMLElement;
interface HTMLFormElement;
interface HTMLTableCaptionElement;
interface HTMLTableSectionElement;
var el = new elem(doc, s);
return el;
};
});
}
interface HTMLCollection {
readonly attribute unsigned long length;
Node item(in unsigned long index);
Node namedItem(in DOMString name);
};
core.DOMImplementation.prototype._features = {
core : '2.0',
html : '2.0',
xhtml: '2.0',
xml : '2.0'
};
// Introduced in DOM Level 2:
interface HTMLOptionsCollection {
attribute unsigned long length;
// raises(dom::DOMException) on setting
Node item(in unsigned long index);
Node namedItem(in DOMString name);
};
core.HTMLCollection = function(query) {
core.NodeList.call(this, query);
};
interface HTMLDocument : Document {
attribute DOMString title;
readonly attribute DOMString referrer;
readonly attribute DOMString domain;
readonly attribute DOMString URL;
attribute HTMLElement body;
readonly attribute HTMLCollection images;
readonly attribute HTMLCollection applets;
readonly attribute HTMLCollection links;
readonly attribute HTMLCollection forms;
readonly attribute HTMLCollection anchors;
attribute DOMString cookie;
// raises(dom::DOMException) on setting
core.HTMLCollection.prototype = {
namedItem : function(name) {
var results = this.toArray(),
l = results.length,
node,
matchingName = null;
void open();
void close();
void write(in DOMString text);
void writeln(in DOMString text);
NodeList getElementsByName(in DOMString elementName);
};
for (var i=0; i<l; i++) {
node = results[i];
if (node.getAttribute('id') === name) {
return node;
} else if (node.getAttribute('name') === name) {
matchingName = node;
}
}
return matchingName;
},
toString: function() {
return '[ jsdom HTMLCollection ]: contains ' + this.length + ' items';
}
};
core.HTMLCollection.prototype.__proto__ = core.NodeList.prototype;
interface HTMLElement : Element {
attribute DOMString id;
attribute DOMString title;
attribute DOMString lang;
attribute DOMString dir;
attribute DOMString className;
};
core.HTMLOptionsCollection = core.HTMLCollection;
interface HTMLHtmlElement : HTMLElement {
attribute DOMString version;
};
function closest(e, tagName) {
tagName = tagName.toUpperCase();
while (e) {
if (e.nodeName.toUpperCase() == tagName ||
(e.tagName && e.tagName.toUpperCase() === tagName))
{
return e;
}
e = e.parentNode;
}
return null;
}
interface HTMLHeadElement : HTMLElement {
attribute DOMString profile;
};
function descendants(e, tagName, recursive) {
return new core.HTMLCollection(core.mapper(e, function(n) {
return n.nodeName === tagName;
}, recursive));
}
interface HTMLLinkElement : HTMLElement {
attribute boolean disabled;
attribute DOMString charset;
attribute DOMString href;
attribute DOMString hreflang;
attribute DOMString media;
attribute DOMString rel;
attribute DOMString rev;
attribute DOMString target;
attribute DOMString type;
};
function firstChild(e, tagName) {
var c = descendants(e, tagName, false);
return c.length > 0 ? c[0] : null;
}
interface HTMLTitleElement : HTMLElement {
attribute DOMString text;
};
interface HTMLMetaElement : HTMLElement {
attribute DOMString content;
attribute DOMString httpEquiv;
attribute DOMString name;
attribute DOMString scheme;
};
core.HTMLDocument = function(url) {
this._URL = url;
core.Document.call(this);
};
core.HTMLDocument.prototype = {
get referrer() {
return "";
},
get domain() {
return "";
},
_URL : "",
get URL() {
return this._URL;
},
// TODO TODO TODO TODO
// WARNING: THIS IS NOT COVERED BY THE SPEC!
set URL(val) {
this._URL = val;
},
// TODO TODO TODO TODO
interface HTMLBaseElement : HTMLElement {
attribute DOMString href;
attribute DOMString target;
};
// Handle blocking elements ((i)frame, script, img, etc)
// TODO: implement this in script, img, etc
_onloadHandlers : [],
_blockers : [],
set onload(handler) {
},
addBlocker : function(el) {
this._blockers.push(el);
},
removeBlocker : function(el) {
var idx = this._blockers.indexOf(el);
if (idx !== -1) {
this._blockers = this._blockers.splice(idx);
}
if (this._blockers.length === 0) {
while(_onloadHandlers.length > 0) {
var fn = this._onloadHandlers.pop();
if (typeof fn === "function") {
fn();
}
}
}
},
interface HTMLIsIndexElement : HTMLElement {
readonly attribute HTMLFormElement form;
attribute DOMString prompt;
};
get images() {
return this.getElementsByTagName('IMG');
},
get applets() {
return new core.HTMLCollection(core.mapper(this, function(el) {
if (el && el.tagName) {
var upper = el.tagName.toUpperCase();
if (upper === "APPLET") {
return true;
} else if (upper === "OBJECT" &&
el.getElementsByTagName('APPLET').length > 0)
{
return true;
}
}
}));
},
get links() {
return new core.HTMLCollection(core.mapper(this, function(el) {
if (el && el.tagName) {
var upper = el.tagName.toUpperCase();
if (upper === "AREA" || (upper === "A" && el.href)) {
return true;
}
}
}));
},
get forms() {
return this.getElementsByTagName('FORM');
},
get anchors() {
return this.getElementsByTagName('A');
},
open : function() {
this._children = [];
},
close : function() {
},
write : function(text) {
interface HTMLStyleElement : HTMLElement {
attribute boolean disabled;
attribute DOMString media;
attribute DOMString type;
};
},
interface HTMLBodyElement : HTMLElement {
attribute DOMString aLink;
attribute DOMString background;
attribute DOMString bgColor;
attribute DOMString link;
attribute DOMString text;
attribute DOMString vLink;
};
writeln : function(text) {
interface HTMLFormElement : HTMLElement {
readonly attribute HTMLCollection elements;
readonly attribute long length;
attribute DOMString name;
attribute DOMString acceptCharset;
attribute DOMString action;
attribute DOMString enctype;
attribute DOMString method;
attribute DOMString target;
void submit();
void reset();
};
},
interface HTMLSelectElement : HTMLElement {
readonly attribute DOMString type;
attribute long selectedIndex;
attribute DOMString value;
// Modified in DOM Level 2:
attribute unsigned long length;
// raises(dom::DOMException) on setting
getElementsByName : function(elementName) {
return new core.HTMLCollection(core.mapper(this, function(el) {
return (el.getAttribute && el.getAttribute("name") === elementName);
}));
},
_title : "",
get title() {
var title = this.getElementsByTagName("title").item(0);
if (!title) {
return "";
}
return title.innerHTML;
},
set title(val) {
},
_body : null,
get body() { return this.getElementsByTagName('BODY').item(0); },
set body(el) { this.documentElement = el; },
_cookie : "",
get cookie() { return this._cookie; },
set cookie(val) { this._cookie = val; }
};
core.HTMLDocument.prototype.__proto__ = core.Document.prototype;
readonly attribute HTMLFormElement form;
// Modified in DOM Level 2:
readonly attribute HTMLOptionsCollection options;
attribute boolean disabled;
attribute boolean multiple;
attribute DOMString name;
attribute long size;
attribute long tabIndex;
void add(in HTMLElement element,
in HTMLElement before)
raises(dom::DOMException);
void remove(in long index);
void blur();
void focus();
};
interface HTMLOptGroupElement : HTMLElement {
attribute boolean disabled;
attribute DOMString label;
};
define('HTMLElement', {
parentClass: core.Element,
attributes: [
'id',
'title',
'lang',
'dir',
{prop: 'className', attr: 'class'}
]
});
interface HTMLOptionElement : HTMLElement {
readonly attribute HTMLFormElement form;
// Modified in DOM Level 2:
attribute boolean defaultSelected;
readonly attribute DOMString text;
// Modified in DOM Level 2:
readonly attribute long index;
attribute boolean disabled;
attribute DOMString label;
attribute boolean selected;
attribute DOMString value;
};
core.Document.prototype._defaultElementBuilder = function(document, tagName) {
return new core.HTMLElement(document, tagName);
};
interface HTMLInputElement : HTMLElement {
attribute DOMString defaultValue;
attribute boolean defaultChecked;
readonly attribute HTMLFormElement form;
attribute DOMString accept;
attribute DOMString accessKey;
attribute DOMString align;
attribute DOMString alt;
attribute boolean checked;
attribute boolean disabled;
attribute long maxLength;
attribute DOMString name;
attribute boolean readOnly;
// Modified in DOM Level 2:
attribute unsigned long size;
attribute DOMString src;
attribute long tabIndex;
// Modified in DOM Level 2:
attribute DOMString type;
attribute DOMString useMap;
attribute DOMString value;
void blur();
void focus();
void select();
void click();
};
//http://www.w3.org/TR/html5/forms.html#category-listed
var listedElements = /button|fieldset|input|keygen|object|select|textarea/i;
interface HTMLTextAreaElement : HTMLElement {
// Modified in DOM Level 2:
attribute DOMString defaultValue;
readonly attribute HTMLFormElement form;
attribute DOMString accessKey;
attribute long cols;
attribute boolean disabled;
attribute DOMString name;
attribute boolean readOnly;
attribute long rows;
attribute long tabIndex;
readonly attribute DOMString type;
attribute DOMString value;
void blur();
void focus();
void select();
};
define('HTMLFormElement', {
tagName: 'FORM',
proto: {
get elements() {
return new core.HTMLCollection(core.mapper(this, function(e) {
return listedElements.test(e.nodeName) ; // TODO exclude <input type="image">
}));
},
get length() {
return this.elements.length;
},
submit: function() {
},
reset: function() {
}
},
attributes: [
'name',
{prop: 'acceptCharset', attr: 'accept-charset'},
'action',
'enctype',
'method',
'target'
]
});
interface HTMLButtonElement : HTMLElement {
readonly attribute HTMLFormElement form;
attribute DOMString accessKey;
attribute boolean disabled;
attribute DOMString name;
attribute long tabIndex;
readonly attribute DOMString type;
attribute DOMString value;
};
define('HTMLLinkElement', {
tagName: 'LINK',
attributes: [
{prop: 'disabled', type: 'boolean'},
'charset',
'href',
'hreflang',
'media',
'rel',
'rev',
'target',
'type'
]
});
interface HTMLLabelElement : HTMLElement {
readonly attribute HTMLFormElement form;
attribute DOMString accessKey;
attribute DOMString htmlFor;
};
define('HTMLMetaElement', {
tagName: 'META',
attributes: [
'content',
{prop: 'httpEquiv', attr: 'http-equiv'},
'name',
'scheme'
]
});
interface HTMLFieldSetElement : HTMLElement {
readonly attribute HTMLFormElement form;
};
define('HTMLHtmlElement', {
tagName: 'HTML',
attributes: [
'version'
]
});
interface HTMLLegendElement : HTMLElement {
readonly attribute HTMLFormElement form;
attribute DOMString accessKey;
attribute DOMString align;
};
define('HTMLHeadElement', {
tagName: 'HEAD',
attributes: [
'profile'
]
});
interface HTMLUListElement : HTMLElement {
attribute boolean compact;
attribute DOMString type;
};
define('HTMLTitleElement', {
tagName: 'TITLE',
proto: {
get text() {
return this.innerHTML;
},
set text(s) {
this.innerHTML = s;
}
}
});
interface HTMLOListElement : HTMLElement {
attribute boolean compact;
attribute long start;
attribute DOMString type;
};
define('HTMLBaseElement', {
tagName: 'BASE',
attributes: [
'href',
'target'
]
});
interface HTMLDListElement : HTMLElement {
attribute boolean compact;
};
interface HTMLDirectoryElement : HTMLElement {
attribute boolean compact;
};
//**Deprecated**
define('HTMLIsIndexElement', {
tagName : 'ISINDEX',
parentClass : core.Element,
proto : {
get form() {
return closest(this, 'FORM');
}
},
attributes : [
'prompt'
]
});
interface HTMLMenuElement : HTMLElement {
attribute boolean compact;
};
interface HTMLLIElement : HTMLElement {
attribute DOMString type;
attribute long value;
};
define('HTMLStyleElement', {
tagName: 'STYLE',
attributes: [
{prop: 'disabled', type: 'boolean'},
'media',
'type',
]
});
interface HTMLDivElement : HTMLElement {
attribute DOMString align;
};
define('HTMLBodyElement', {
tagName: 'BODY',
attributes: [
'aLink',
'background',
'bgColor',
'link',
'text',
'vLink'
]
});
interface HTMLParagraphElement : HTMLElement {
attribute DOMString align;
};
define('HTMLSelectElement', {
tagName: 'SELECT',
proto: {
get options() {
return new core.HTMLOptionsCollection(core.mapper(this, function(n) {
return n.nodeName == 'OPTION';
}));
},
get length() {
return this.options.length;
},
get selectedIndex() {
return this.options.toArray().reduceRight(function(prev, option, i) {
return option.selected ? i : prev;
}, -1);
},
set selectedIndex(index) {
this.options.toArray().forEach(function(option, i) {
option.selected = i === index;
});
},
get value() {
var i = this.selectedIndex;
if (this.options.length && (i === -1)) {
i = 0;
}
if (i === -1) {
return '';
}
return this.options[i].value;
},
set value(val) {
this.options.toArray().forEach(function(option) {
if (option.value === val) {
option.selected = true;
}
});
},
get form() {
return closest(this, 'FORM');
},
get type() {
return this.multiple ? 'select-multiple' : 'select';
},
add: function(opt, before) {
if (before) {
this.insertBefore(opt, before);
}
else {
this.appendChild(opt);
}
},
remove: function(index) {
var opts = this.options.toArray();
if (index >= 0 && index < opts.length) {
var el = opts[index];
el.parentNode.removeChild(el);
}
},
blur: function() {
//TODO
},
focus: function() {
//TODO
}
},
attributes: [
{prop: 'disabled', type: 'boolean'},
{prop: 'multiple', type: 'boolean'},
'name',
{prop: 'size', type: 'long'},
{prop: 'tabIndex', type: 'long'},
]
});
interface HTMLHeadingElement : HTMLElement {
attribute DOMString align;
};
define('HTMLOptGroupElement', {
tagName: 'OPTGROUP',
attributes: [
{prop: 'disabled', type: 'boolean'},
'label'
]
});
interface HTMLQuoteElement : HTMLElement {
attribute DOMString cite;
};
define('HTMLOptionElement', {
tagName: 'OPTION',
proto: {
_initDefaultSelected: function() {
if (this._defaultSelected === undefined) {
this._defaultSelected = !!this.getAttribute('selected');
}
return this._defaultSelected;
},
get form() {
return closest(this, 'FORM');
},
get defaultSelected() {
return this._initDefaultSelected();
},
get text() {
return (this.hasAttribute('value')) ? this.getAttribute('value') : this.innerHTML;
},
get value() {
return (this.hasAttribute('value')) ? this.getAttribute('value') : this.innerHTML;
},
set value(val) {
this.setAttribute('value', val);
},
get index() {
return closest(this, 'SELECT').options.toArray().indexOf(this);
},
get selected() {
return !!this.getAttribute('selected');
},
set selected(s) {
this._initDefaultSelected();
if (s) {
this.setAttribute('selected', 'selected');
}
else {
this.removeAttribute('selected');
}
}
},
attributes: [
{prop: 'disabled', type: 'boolean'},
'label'
]
});
interface HTMLPreElement : HTMLElement {
attribute long width;
};
define('HTMLInputElement', {
tagName: 'INPUT',
proto: {
_initDefaultValue: function() {
if (this._defaultValue === undefined) {
this._defaultValue = this.getAttribute('value');
}
return this._defaultValue;
},
_initDefaultChecked: function() {
if (this._defaultChecked === undefined) {
this._defaultChecked = !!this.getAttribute('checked');
}
return this._defaultChecked;
},
get form() {
return closest(this, 'FORM');
},
get defaultValue() {
return this._initDefaultValue();
},
get defaultChecked() {
return this._initDefaultChecked();
},
get checked() {
return !!this.getAttribute('checked');
},
set checked(checked) {
this._initDefaultChecked();
this.setAttribute('checked', checked);
},
get value() {
return this.getAttribute('value');
},
set value(val) {
this._initDefaultValue();
this.setAttribute('value', value);
},
blur: function() {
},
focus: function() {
},
select: function() {
},
click: function() {
this.checked = !this.checked;
}
},
attributes: [
'accept',
'accessKey',
'align',
'alt',
{prop: 'disabled', type: 'boolean'},
{prop: 'maxLength', type: 'long'},
'name',
{prop: 'readOnly', type: 'boolean'},
{prop: 'size', type: 'long'},
'src',
{prop: 'tabIndex', type: 'long'},
'type',
'useMap',
'value'
]
});
interface HTMLBRElement : HTMLElement {
attribute DOMString clear;
};
define('HTMLTextAreaElement', {
tagName: 'TEXTAREA',
proto: {
_initDefaultValue: function() {
if (this._defaultValue === undefined) {
this._defaultValue = this.innerHTML;
}
return this._defaultValue;
},
get form() {
return closest(this, 'FORM');
},
get defaultValue() {
return this._initDefaultValue();
},
get value() {
return this.innerHTML;
},
set value(val) {
this._initDefaultValue();
this.innerHTML = val;
},
get type() {
return 'textarea';
},
blur: function() {
},
focus: function() {
},
select: function() {
}
},
attributes: [
'accessKey',
{prop: 'cols', type: 'long'},
{prop: 'disabled', type: 'boolean'},
{prop: 'maxLength', type: 'long'},
'name',
{prop: 'readOnly', type: 'boolean'},
{prop: 'rows', type: 'long'},
{prop: 'tabIndex', type: 'long'}
]
});
interface HTMLBaseFontElement : HTMLElement {
attribute DOMString color;
attribute DOMString face;
// Modified in DOM Level 2:
attribute long size;
};
define('HTMLButtonElement', {
tagName: 'BUTTON',
proto: {
get form() {
return closest(this, 'FORM');
}
},
attributes: [
'accessKey',
{prop: 'disabled', type: 'boolean'},
'name',
{prop: 'tabIndex', type: 'long'},
'type',
'value'
]
});
interface HTMLFontElement : HTMLElement {
attribute DOMString color;
attribute DOMString face;
attribute DOMString size;
};
define('HTMLLabelElement', {
tagName: 'LABEL',
proto: {
get form() {
return closest(this, 'FORM');
}
},
attributes: [
'accessKey',
{prop: 'htmlFor', attr: 'for'}
]
});
interface HTMLHRElement : HTMLElement {
attribute DOMString align;
attribute boolean noShade;
attribute DOMString size;
attribute DOMString width;
};
define('HTMLFieldSetElement', {
tagName: 'FIELDSET',
proto: {
get form() {
return closest(this, 'FORM');
}
}
});
interface HTMLModElement : HTMLElement {
attribute DOMString cite;
attribute DOMString dateTime;
};
define('HTMLLegendElement', {
tagName: 'LEGEND',
proto: {
get form() {
return closest(this, 'FORM');
}
},
attributes: [
'accessKey',
'align'
]
});
interface HTMLAnchorElement : HTMLElement {
attribute DOMString accessKey;
attribute DOMString charset;
attribute DOMString coords;
attribute DOMString href;
attribute DOMString hreflang;
attribute DOMString name;
attribute DOMString rel;
attribute DOMString rev;
attribute DOMString shape;
attribute long tabIndex;
attribute DOMString target;
attribute DOMString type;
void blur();
void focus();
};
define('HTMLUListElement', {
tagName: 'UL',
attributes: [
{prop: 'compact', type: 'boolean'},
'type'
]
});
interface HTMLImageElement : HTMLElement {
attribute DOMString name;
attribute DOMString align;
attribute DOMString alt;
attribute DOMString border;
// Modified in DOM Level 2:
attribute long height;
// Modified in DOM Level 2:
attribute long hspace;
attribute boolean isMap;
attribute DOMString longDesc;
attribute DOMString src;
attribute DOMString useMap;
// Modified in DOM Level 2:
attribute long vspace;
// Modified in DOM Level 2:
attribute long width;
};
define('HTMLOListElement', {
tagName: 'OL',
attributes: [
{prop: 'compact', type: 'boolean'},
{prop: 'start', type: 'long'},
'type'
]
});
interface HTMLObjectElement : HTMLElement {
readonly attribute HTMLFormElement form;
attribute DOMString code;
attribute DOMString align;
attribute DOMString archive;
attribute DOMString border;
attribute DOMString codeBase;
attribute DOMString codeType;
attribute DOMString data;
attribute boolean declare;
attribute DOMString height;
attribute long hspace;
attribute DOMString name;
attribute DOMString standby;
attribute long tabIndex;
attribute DOMString type;
attribute DOMString useMap;
attribute long vspace;
attribute DOMString width;
// Introduced in DOM Level 2:
readonly attribute Document contentDocument;
};
define('HTMLDListElement', {
tagName: 'DL',
attributes: [
{prop: 'compact', type: 'boolean'}
]
});
interface HTMLParamElement : HTMLElement {
attribute DOMString name;
attribute DOMString type;
attribute DOMString value;
attribute DOMString valueType;
};
define('HTMLDirectoryElement', {
tagName: 'DIR',
attributes: [
{prop: 'compact', type: 'boolean'}
]
});
interface HTMLAppletElement : HTMLElement {
attribute DOMString align;
attribute DOMString alt;
attribute DOMString archive;
attribute DOMString code;
attribute DOMString codeBase;
attribute DOMString height;
// Modified in DOM Level 2:
attribute long hspace;
attribute DOMString name;
// Modified in DOM Level 2:
attribute DOMString object;
// Modified in DOM Level 2:
attribute long vspace;
attribute DOMString width;
};
define('HTMLMenuElement', {
tagName: 'MENU',
attributes: [
{prop: 'compact', type: 'boolean'}
]
});
interface HTMLMapElement : HTMLElement {
readonly attribute HTMLCollection areas;
attribute DOMString name;
};
define('HTMLLIElement', {
tagName: 'LI',
attributes: [
'type',
{prop: 'value', type: 'long'}
]
});
interface HTMLAreaElement : HTMLElement {
attribute DOMString accessKey;
attribute DOMString alt;
attribute DOMString coords;
attribute DOMString href;
attribute boolean noHref;
attribute DOMString shape;
attribute long tabIndex;
attribute DOMString target;
};
define('HTMLDivElement', {
tagName: 'DIV',
attributes: [
'align'
]
});
interface HTMLScriptElement : HTMLElement {
attribute DOMString text;
attribute DOMString htmlFor;
attribute DOMString event;
attribute DOMString charset;
attribute boolean defer;
attribute DOMString src;
attribute DOMString type;
};
define('HTMLParagraphElement', {
tagName: 'P',
attributes: [
'align'
]
});
interface HTMLTableElement : HTMLElement {
// Modified in DOM Level 2:
attribute HTMLTableCaptionElement caption;
// raises(dom::DOMException) on setting
define('HTMLHeadingElement', {
tagNames: ['H1','H2','H3','H4','H5','H6'],
attributes: [
'align'
]
});
// Modified in DOM Level 2:
attribute HTMLTableSectionElement tHead;
// raises(dom::DOMException) on setting
define('HTMLQuoteElement', {
tagNames: ['Q','BLOCKQUOTE'],
attributes: [
'cite'
]
});
// Modified in DOM Level 2:
attribute HTMLTableSectionElement tFoot;
// raises(dom::DOMException) on setting
define('HTMLPreElement', {
tagName: 'PRE',
attributes: [
{prop: 'width', type: 'long'}
]
});
readonly attribute HTMLCollection rows;
readonly attribute HTMLCollection tBodies;
attribute DOMString align;
attribute DOMString bgColor;
attribute DOMString border;
attribute DOMString cellPadding;
attribute DOMString cellSpacing;
attribute DOMString frame;
attribute DOMString rules;
attribute DOMString summary;
attribute DOMString width;
HTMLElement createTHead();
void deleteTHead();
HTMLElement createTFoot();
void deleteTFoot();
HTMLElement createCaption();
void deleteCaption();
// Modified in DOM Level 2:
HTMLElement insertRow(in long index)
raises(dom::DOMException);
// Modified in DOM Level 2:
void deleteRow(in long index)
raises(dom::DOMException);
};
define('HTMLBRElement', {
tagName: 'BR',
attributes: [
'clear'
]
});
interface HTMLTableCaptionElement : HTMLElement {
attribute DOMString align;
};
define('HTMLBaseFontElement', {
tagName: 'BASEFONT',
attributes: [
'color',
'face',
{prop: 'size', type: 'long'}
]
});
interface HTMLTableColElement : HTMLElement {
attribute DOMString align;
attribute DOMString ch;
attribute DOMString chOff;
attribute long span;
attribute DOMString vAlign;
attribute DOMString width;
};
define('HTMLFontElement', {
tagName: 'FONT',
attributes: [
'color',
'face',
'size'
]
});
interface HTMLTableSectionElement : HTMLElement {
attribute DOMString align;
attribute DOMString ch;
attribute DOMString chOff;
attribute DOMString vAlign;
readonly attribute HTMLCollection rows;
// Modified in DOM Level 2:
HTMLElement insertRow(in long index)
raises(dom::DOMException);
// Modified in DOM Level 2:
void deleteRow(in long index)
raises(dom::DOMException);
};
define('HTMLHRElement', {
tagName: 'HR',
attributes: [
'align',
{prop: 'noShade', type: 'boolean'},
'size',
'width'
]
});
interface HTMLTableRowElement : HTMLElement {
// Modified in DOM Level 2:
readonly attribute long rowIndex;
// Modified in DOM Level 2:
readonly attribute long sectionRowIndex;
// Modified in DOM Level 2:
readonly attribute HTMLCollection cells;
attribute DOMString align;
attribute DOMString bgColor;
attribute DOMString ch;
attribute DOMString chOff;
attribute DOMString vAlign;
// Modified in DOM Level 2:
HTMLElement insertCell(in long index)
raises(dom::DOMException);
// Modified in DOM Level 2:
void deleteCell(in long index)
raises(dom::DOMException);
};
define('HTMLModElement', {
tagNames: ['INS', 'DEL'],
attributes: [
'cite',
'dateTime'
]
});
interface HTMLTableCellElement : HTMLElement {
readonly attribute long cellIndex;
attribute DOMString abbr;
attribute DOMString align;
attribute DOMString axis;
attribute DOMString bgColor;
attribute DOMString ch;
attribute DOMString chOff;
attribute long colSpan;
attribute DOMString headers;
attribute DOMString height;
attribute boolean noWrap;
attribute long rowSpan;
attribute DOMString scope;
attribute DOMString vAlign;
attribute DOMString width;
};
define('HTMLAnchorElement', {
tagName: 'A',
interface HTMLFrameSetElement : HTMLElement {
attribute DOMString cols;
attribute DOMString rows;
};
proto: {
blur: function() {
},
focus: function() {
},
get href() {
return this.getAttribute('href').replace(/^\.\//,'/');
}
},
attributes: [
'accessKey',
'charset',
'coords',
{prop: 'href', type: 'string', read: false},
'hreflang',
'name',
'rel',
'rev',
'shape',
{prop: 'tabIndex', type: 'long'},
'target',
'type'
]
});
interface HTMLFrameElement : HTMLElement {
attribute DOMString frameBorder;
attribute DOMString longDesc;
attribute DOMString marginHeight;
attribute DOMString marginWidth;
attribute DOMString name;
attribute boolean noResize;
attribute DOMString scrolling;
attribute DOMString src;
// Introduced in DOM Level 2:
readonly attribute Document contentDocument;
};
define('HTMLImageElement', {
tagName: 'IMG',
attributes: [
'name',
'align',
'alt',
'border',
{prop: 'height', type: 'long'},
{prop: 'hspace', type: 'long'},
{prop: 'isMap', type: 'boolean'},
'longDesc',
'src',
'useMap',
{prop: 'vspace', type: 'long'},
{prop: 'width', type: 'long'}
]
});
interface HTMLIFrameElement : HTMLElement {
attribute DOMString align;
attribute DOMString frameBorder;
attribute DOMString height;
attribute DOMString longDesc;
attribute DOMString marginHeight;
attribute DOMString marginWidth;
attribute DOMString name;
attribute DOMString scrolling;
attribute DOMString src;
attribute DOMString width;
// Introduced in DOM Level 2:
readonly attribute Document contentDocument;
};
};
define('HTMLObjectElement', {
tagName: 'OBJECT',
proto: {
get form() {
return closest(this, 'FORM');
},
get contentDocument() {
return null;
}
},
attributes: [
'code',
'align',
'archive',
'border',
'codeBase',
'codeType',
'data',
{prop: 'declare', type: 'boolean'},
{prop: 'height', type: 'long'},
{prop: 'hspace', type: 'long'},
'name',
'standby',
{prop: 'tabIndex', type: 'long'},
'type',
'useMap',
{prop: 'vspace', type: 'long'},
{prop: 'width', type: 'long'}
]
});
#endif // _HTML2_IDL_
*/
define('HTMLParamElement', {
tagName: 'PARAM',
attributes: [
'name',
'type',
'value',
'valueType'
]
});
define('HTMLAppletElement', {
tagName: 'APPLET',
attributes: [
'align',
'alt',
'archive',
'code',
'codeBase',
'height',
{prop: 'hspace', type: 'long'},
'name',
'object',
{prop: 'vspace', type: 'long'},
'width'
]
});
define('HTMLMapElement', {
tagName: 'MAP',
proto: {
get areas() {
return this.getElementsByTagName("AREA");
}
},
attributes: [
'name'
]
});
define('HTMLAreaElement', {
tagName: 'AREA',
attributes: [
'accessKey',
'alt',
'coords',
'href',
{prop: 'noHref', type: 'boolean'},
'shape',
{prop: 'tabIndex', type: 'long'},
'target'
]
});
define('HTMLScriptElement', {
tagName: 'SCRIPT',
proto : {
get src() {},
set src(value) {
this.setAttribute('src', value);
var self = this;
if (value.substring(0,7) === "file://") {
realvalue = value.substring(7);
} else {
realvalue = value;
}
if (value.substring(0,7) === "file://") {
require("fs").readFile(value.replace("file://",""), function(err, data)
{
if (err) throw err;
core.languageProcessors.javascript(self, data);
});
} else {
var host = urlParse(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.toString();
});
response.on('end', function() {
core.languageProcessors.javascript(self, data);
});
});
}
},
get text() {
return this.children.item(0).value;
},
set text(text) {
if (!this.children.item(0)) {
this.appendChild(this.ownerDocument.createTextNode(text));
}
// Execute the javascript
var type = this.type || "text/javascript",
lang = type.split("/").pop();
if (!core.languageProcessors[lang]) {
core.languageProcessors[lang](this.ownerDocument, text);
}
}
},
attributes : [
{prop: 'defer', 'type': 'boolean'},
'htmlFor',
'event',
'charset',
'type',
{prop: 'src', write: false, type:'string'},
]
})
define('HTMLTableElement', {
tagName: 'TABLE',
proto: {
get caption() {
return firstChild(this, 'CAPTION');
},
get tHead() {
return firstChild(this, 'THEAD');
},
get tFoot() {
return firstChild(this, 'TFOOT');
},
get rows() {
if (!this._rows) {
var table = this;
this._rows = new core.HTMLCollection(function() {
var sections = [table.tHead].concat(table.tBodies.toArray(), table.tFoot).filter(function(s) { return !!s });
if (sections.length == 0) {
return core.mapDOMNodes(table, false, function(el) {
return el.tagName == 'TR';
});
}
return sections.reduce(function(prev, s) {
return prev.concat(s.rows.toArray());
}, []);
});
}
return this._rows;
},
get tBodies() {
if (!this._tBodies) {
this._tBodies = descendants(this, 'TBODY', false);
}
return this._tBodies;
},
createTHead: function() {
var el = this.tHead;
if (!el) {
el = this.ownerDocument.createElement('THEAD');
this.appendChild(el);
}
return el;
},
deleteTHead: function() {
var el = this.tHead;
if (el) {
debugger;
el.parentNode.removeChild(el);
}
},
createTFoot: function() {
var el = this.tFoot;
if (!el) {
el = this.ownerDocument.createElement('TFOOT');
this.appendChild(el);
}
return el;
},
deleteTFoot: function() {
var el = this.tFoot;
if (el) {
el.parentNode.removeChild(el);
}
},
createCaption: function() {
var el = this.caption;
if (!el) {
el = this.ownerDocument.createElement('CAPTION');
this.appendChild(el);
}
return el;
},
deleteCaption: function() {
var c = this.caption;
if (c) {
c.parentNode.removeChild(c);
}
},
insertRow: function(index) {
var tr = this.ownerDocument.createElement('TR');
if (this.childNodes.length === 0) {
this.appendChild(this.ownerDocument.createElement('TBODY'));
}
var rows = this.rows.toArray();
if (index < -1 || index > rows.length) {
throw new core.DOMException(core.INDEX_SIZE_ERR);
}
if (index == -1 || (index === 0 && rows.length === 0)) {
this.tBodies.item(0).appendChild(tr);
}
else if (index == rows.length) {
var ref = rows[index-1];
ref.parentNode.appendChild(tr);
}
else {
var ref = rows[index];
ref.parentNode.insertBefore(tr, ref);
}
return tr;
},
deleteRow: function(index) {
var rows = this.rows.toArray();
if (index == -1) {
index = rows.length-1;
}
if (index < 0 || index >= rows.length) {
throw new core.DOMException(core.INDEX_SIZE_ERR);
}
var tr = this.rows[index];
tr.parentNode.removeChild(tr);
}
},
attributes: [
'align',
'bgColor',
'border',
'cellPadding',
'cellSpacing',
'frame',
'rules',
'summary',
'width'
]
});
define('HTMLTableCaptionElement', {
tagName: 'CAPTION',
attributes: [
'align'
]
});
define('HTMLTableColElement', {
tagNames: ['COL','COLGROUP'],
attributes: [
'align',
{prop: 'ch', attr: 'char'},
{prop: 'chOff', attr: 'charoff'},
{prop: 'span', type: 'long'},
'vAlign',
'width',
]
});
define('HTMLTableSectionElement', {
tagNames: ['THEAD','TBODY','TFOOT'],
proto: {
get rows() {
if (!this._rows) {
this._rows = descendants(this, 'TR', false);
}
return this._rows;
},
insertRow: function(index) {
var tr = this.ownerDocument.createElement('TR');
var rows = this.rows.toArray();
if (index < -1 || index > rows.length) {
throw new core.DOMException(core.INDEX_SIZE_ERR);
}
if (index == -1 || index == rows.length) {
this.appendChild(tr);
}
else {
var ref = rows[index];
this.insertBefore(tr, ref);
}
return tr;
},
deleteRow: function(index) {
var rows = this.rows.toArray();
if (index == -1) {
index = rows.length-1;
}
if (index < 0 || index >= rows.length) {
throw new core.DOMException(core.INDEX_SIZE_ERR);
}
var tr = this.rows[index];
this.removeChild(tr);
}
},
attributes: [
'align',
{prop: 'ch', attr: 'char'},
{prop: 'chOff', attr: 'charoff'},
{prop: 'span', type: 'long'},
'vAlign',
'width',
]
});
define('HTMLTableRowElement', {
tagName: 'TR',
proto: {
get cells() {
if (!this._cells) {
this._cells = new core.HTMLCollection(core.mapper(this, function(n) {
return n.nodeName == 'TD' || n.nodeName == 'TH';
}, false));
}
return this._cells;
},
get rowIndex() {
return closest(this, 'TABLE').rows.toArray().indexOf(this);
},
get sectionRowIndex() {
return this.parentNode.rows.toArray().indexOf(this);
},
insertCell: function(index) {
var td = this.ownerDocument.createElement('TD');
var cells = this.cells.toArray();
if (index < -1 || index > cells.length) {
throw new core.DOMException(core.INDEX_SIZE_ERR);
}
if (index == -1 || index == cells.length) {
this.appendChild(td);
}
else {
var ref = cells[index];
this.insertBefore(td, ref);
}
return td;
},
deleteCell: function(index) {
var cells = this.cells.toArray();
if (index == -1) {
index = cells.length-1;
}
if (index < 0 || index >= cells.length) {
throw new core.DOMException(core.INDEX_SIZE_ERR);
}
var td = this.cells[index];
this.removeChild(td);
}
},
attributes: [
'align',
'bgColor',
{prop: 'ch', attr: 'char'},
{prop: 'chOff', attr: 'charoff'},
'vAlign'
]
});
define('HTMLTableCellElement', {
tagNames: ['TH','TD'],
proto: {
get headers() {
var cellIndex = this.cellIndex,
headings = [],
siblings = this.parentNode.getElementsByTagName(this.tagName);
for (var i=0; i<siblings.length; i++) {
if (siblings.item(i).cellIndex >= cellIndex) {
break;
}
headings.push(siblings.item(i).id);
}
return headings.join(' ');
},
get cellIndex() {
return closest(this, 'TR').cells.toArray().indexOf(this);
}
},
attributes: [
'abbr',
'align',
'axis',
'bgColor',
{prop: 'ch', attr: 'char'},
{prop: 'chOff', attr: 'charoff'},
{prop: 'colSpan', type: 'long'},
'height',
{prop: 'noWrap', type: 'boolean'},
{prop: 'rowSpan', type: 'long'},
'scope',
'vAlign',
'width'
]
});
define('HTMLFrameSetElement', {
tagName: 'FRAMESET',
attributes: [
'cols',
'rows'
]
});
define('HTMLFrameElement', {
tagName: 'FRAME',
init : function() {
/*
This is my shoddy attempt at frames. There are two problems here:
+ keeping the DOM free of BOM stuff (innerHTML, etc)
+ asynchronously loading the contents of the frame which should be fixable
using the test suite's 'checkInitialization' method
*/
var _setAttribute = core.HTMLFrameElement.prototype.setAttribute
core.HTMLFrameElement.prototype.setAttribute = function(name, value) {
_setAttribute.call(this, name, value);
if (name === "src") {
if (this._contentDocument) {
delete this._contentDocument; // TODO: better cleanup
}
this._contentDocument = new (core.HTMLDocument)();
this._contentDocument.URL = value;
var self = this;
this.ownerDocument.addBlocker(this);
if (this.ownerDocument.URL.indexOf("file://") !== -1) {
var pathToFile = this.ownerDocument.URL.replace("file://","");
// handle relative links
if (value.indexOf("://") === -1) {
// Prepare for hack sauce
var split = pathToFile.split('/');
split.pop(); // clean off the filename
split.push(value);
pathToFile = split.join("/");
}
readFile(function(err, data) {
if (err) {
console.log(err);
this.ownerDocument.removeBlocker(this);
return;
}
parser = require('htmlparser'),
HtmlToDom = require(__dirname + '/../../../lib/jsdom/' +
'browser/htmltodom').HtmlToDom,
html2dom = new HtmlToDom(parser);
html2dom.appendHtmlToElement(data.toString(), self._contentDocument);
this.ownerDocument.removeBlocker(this);
});
// Handle Urls
} else {
}
}
};
},
proto: {
_contentDocument : null,
get contentDocument() {
return this._contentDocument;
},
set src() {
console.log("OH MAH GAWDDD");
}
},
attributes: [
'frameBorder',
'longDesc',
'marginHeight',
'marginWidth',
'name',
{prop: 'noResize', type: 'boolean'},
'scrolling',
{prop: 'src', type: 'string', write: false}
]
});
define('HTMLIFrameElement', {
tagName: 'IFRAME',
proto: {
_contentDocument : null,
get contentDocument() {
if (this._contentDocument === null) {
this._contentDocument = new HTMLDocument();
}
return this._contentDocument;
}
},
attributes: [
'align',
'frameBorder',
'height',
'longDesc',
'marginHeight',
'marginWidth',
'name',
'scrolling',
'src',
'width'
]
});
exports.define = define;
exports.dom = {

@@ -580,0 +1421,0 @@ level2 : {

{
"name": "jsdom",
"version": "0.1.19",
"version": "0.1.20",
"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.",

@@ -26,2 +26,6 @@ "keywords": [

{
"name": "Felix Gnass",
"email": "fgnass@gmail.com"
},
{
"name" : "Charlie Robins",

@@ -59,3 +63,4 @@ "email": "charlie.robbins@gmail.com"

"dependencies": {
"mjsunit.runner": ">= 0.1.0"
"mjsunit.runner": ">=0.1.0",
"request" : ">=0.10.0"
},

@@ -62,0 +67,0 @@ "engines" : { "node" : ">=0.1.9" },

@@ -177,5 +177,5 @@ exports.tests = {

assertEquals('',
'<html style="color: black; background-color: white">\r\n</html>\r\n',
'<html style="color: black; background-color: white"></html>\r\n',
require('../../lib/jsdom/browser/domtohtml').domToHtml(doc));
}
};

@@ -132,3 +132,3 @@ var dom = require("../../../../lib/jsdom/level1/core").dom.level1.core;

var ent1Ref = doc.createEntityReference("ent1");
addresses[3].attributes.getNamedItem("street").childNodes.push(ent1Ref);
addresses[3].attributes.getNamedItem("street").appendChild(ent1Ref);
addresses[3].appendChild(doc.createTextNode("27 South Road. Dallas, Texas 98556"));

@@ -135,0 +135,0 @@ names[3].appendChild(doc.createTextNode("Jeny Oconnor"));

@@ -171,3 +171,3 @@ var dom = require("../../../../lib/jsdom/level1/core").dom.level1.core;

var ent1Ref = doc.createEntityReference("ent1");
addresses[3].attributes.getNamedItem("street").childNodes.push(ent1Ref);
addresses[3].attributes.getNamedItem("street").appendChild(ent1Ref);
addresses[3].appendChild(doc.createTextNode("27 South Road. Dallas, Texas 98556"));

@@ -174,0 +174,0 @@ names[3].appendChild(doc.createTextNode("Jeny Oconnor"));

@@ -1,2 +0,3 @@

var sys = require("sys");
var sys = require("sys"),
fs = require("fs");

@@ -106,4 +107,2 @@ var mixin = function(target) {

},
/*
Ignoring for now..
"level2/html" : { cases: require("./level2/html").tests, setUp : function() {

@@ -113,4 +112,21 @@ global.builder.contentType = "text/html";

global.builder.testDirectory = "level2/html";
global.load = function(docRef, doc, name) {
var file = __dirname + "/" + global.builder.testDirectory +
"/files/" + name + "." + global.builder.type,
contents = fs.readFileSync(file, 'utf8'),
doc = require("../lib/jsdom").jsdom(contents, null, {
url : "file://" + file // fake out the tests
});
return doc;
};
var core = require("../lib/jsdom/level2/html").dom.level2.html;
global.getImplementation = function() {
var doc = new (core.HTMLDocument)();
return doc.implementation;
};
}
},*/
},
"level3/core" : { cases: require("./level3/core").tests, setUp : function() {

@@ -155,5 +171,5 @@ global.builder.contentType = "text/xml";

"browser" : { cases: require("./browser/index").tests, setUp : function() {
global.dom = require("../lib/jsdom/level1/core").dom.level1.core;
global.dom = require("../lib/jsdom/level2/core").dom.level2.core;
global.html = require("../lib/jsdom/level2/html").dom.level2.html;
global.browser = require("../lib/jsdom/browser/index").browserAugmentation(dom);
global.builder.contentType = "text/html";

@@ -160,0 +176,0 @@ global.builder.type = "html";

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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