sub
Version:
A subset of the DOM environment for running Rule.js on the server
1,559 lines (1,407 loc) • 346 kB
JavaScript
;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";
var Node = require('./Node').Node;
var initializeNode = require('./Node').initializeNode;
/*
* CharacterData
*/
var CharacterData, initializeCharacterData;
CharacterData = (function () {
// Extension
(function (child, parent) {
function CharacterData() {
this.constructor = child;
}
CharacterData.prototype = parent.prototype;
child.prototype = new CharacterData();
}(CharacterData, Node));
// Prototype
(function () {
// These properties within defineProperties should not be in the element
// prototype, this is a speed optimization, as the call to defineProperties
// is expensive when called on every element initialization.
// On the actual DOM, these properties belong to the object itself,
// not the prototype.
Object.defineProperty(CharacterData.prototype, 'length', {
configurable: true,
get: (function(){
return this.data.length;
}).bind(this)
});
CharacterData.prototype.appendData = function (data) {
this.data += data;
};
}());
// Constructor
function CharacterData() {
throw new TypeError('Illegal constructor');
}
return CharacterData;
}());
initializeCharacterData = function (string) {
initializeNode.apply(this, arguments);
this.data = String(string);
};
exports.CharacterData = CharacterData;
exports.initializeCharacterData = initializeCharacterData;
},{"./Node":9}],2:[function(require,module,exports){
"use strict";
/*
* DOMException
*/
var DOMException, initializeDOMException, createDOMException;
DOMException = (function () {
// Extension
(function (child, parent) {
function DOMException() {
this.constructor = child;
}
DOMException.prototype = parent.prototype;
child.prototype = new DOMException();
}(DOMException, Error));
//Constants
DOMException.ABORT_ERR = 20;
DOMException.DATA_CLONE_ERR = 25;
DOMException.DOMSTRING_SIZE_ERR = 2;
DOMException.HIERARCHY_REQUEST_ERR = 3;
DOMException.INDEX_SIZE_ERR = 1;
DOMException.INUSE_ATTRIBUTE_ERR = 10;
DOMException.INVALID_ACCESS_ERR = 15;
DOMException.INVALID_CHARACTER_ERR = 5;
DOMException.INVALID_MODIFICATION_ERR = 13;
DOMException.INVALID_NODE_TYPE_ERR = 24;
DOMException.INVALID_STATE_ERR = 11;
DOMException.NAMESPACE_ERR = 14;
DOMException.NETWORK_ERR = 19;
DOMException.NOT_FOUND_ERR = 8;
DOMException.NOT_SUPPORTED_ERR = 9;
DOMException.NO_DATA_ALLOWED_ERR = 6;
DOMException.NO_MODIFICATION_ALLOWED_ERR = 7;
DOMException.QUOTA_EXCEEDED_ERR = 22;
DOMException.SECURITY_ERR = 18;
DOMException.SYNTAX_ERR = 12;
DOMException.TIMEOUT_ERR = 23;
DOMException.TYPE_MISMATCH_ERR = 17;
DOMException.URL_MISMATCH_ERR = 21;
DOMException.VALIDATION_ERR = 16;
DOMException.WRONG_DOCUMENT_ERR = 4;
//Constructor
function DOMException() {
throw new TypeError('Illegal constructor');
}
return DOMException;
}());
initializeDOMException = function (code) {
var key;
this.code = code;
for (key in DOMException) {
if (DOMException[key] === code) {
this.name = key;
this.message = 'DOM Exception ' + code;
}
}
};
createDOMException = (function (constructor) {
DOMException.prototype = constructor.prototype;
function DOMException(code) {
initializeDOMException.apply(this, arguments);
}
return function (code) {
var exception = new DOMException(code);
Error.captureStackTrace(exception, createDOMException);
return exception;
};
}(DOMException));
exports.DOMException = DOMException;
exports.initializeDOMException = initializeDOMException;
exports.createDOMException = createDOMException;
},{}],3:[function(require,module,exports){
"use strict";
var Node = require('./Node').Node;
var createText = require('./Text').createText;
var createHTMLElement = require('./HTMLElement').createHTMLElement;
/*
* Document
*/
var Document;
Document = (function () {
// Extension
(function (child, parent) {
function Document() {
this.constructor = child;
}
Document.prototype = parent.prototype;
child.prototype = new Document();
}(Document, Node));
// Prototype
Document.prototype.createTextNode = createText;
Document.prototype.createElement = createHTMLElement;
// Constructor
function Document() {
throw new TypeError('Illegal constructor');
}
return Document;
}());
exports.Document = Document;
},{"./HTMLElement":7,"./Node":9,"./Text":10}],4:[function(require,module,exports){
"use strict";
var Node = require('./Node').Node;
var initializeNode = require('./Node').initializeNode;
/*
* DocumentType
*/
var DocumentType, initializeDocumentType, createDocumentType;
DocumentType = (function () {
// Extension
(function (child, parent) {
function DocumentType() {
this.constructor = child;
}
DocumentType.prototype = parent.prototype;
child.prototype = new DocumentType();
}(DocumentType, Node));
// Constructor
function DocumentType() {
throw new TypeError('Illegal constructor');
}
return DocumentType;
}());
initializeDocumentType = function (name, publicId, systemId) {
initializeNode.apply(this, arguments);
this.name = name || '';
this.publicId = publicId || '';
this.systemId = systemId || '';
};
createDocumentType = (function (constructor) {
DocumentType.prototype = constructor.prototype;
function DocumentType() {
initializeDocumentType.apply(this, arguments);
}
return function (name, publicId, systemId) {return new DocumentType(name, publicId, systemId); };
}(DocumentType));
exports.DocumentType = DocumentType;
exports.initializeDocumentType = initializeDocumentType;
exports.createDocumentType = createDocumentType;
},{"./Node":9}],5:[function(require,module,exports){
"use strict";
var Node = require('./Node').Node;
var initializeNode = require('./Node').initializeNode;
var DOMException = require('./DOMException').DOMException;
var createDOMException = require('./DOMException').createDOMException;
var Text = require('./Text').Text;
// Helpers
/* As specified at:
* http://www.w3.org/TR/2008/REC-xml-20081126/#d0e804
*/
var attributeNameStartChar, attributeNameChar, attributeNameRegExp, attributeString;
attributeNameStartChar = "([:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD])";
attributeNameChar = "(" + attributeNameStartChar + "|[\\-\\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040])";
attributeNameRegExp = new RegExp("^" + attributeNameStartChar + attributeNameChar + "*$");
attributeString = function (string) {
string = String(string);
if (!attributeNameRegExp.test(string)) {throw createDOMException(DOMException.INVALID_CHARACTER_ERR); }
return string.toLowerCase();
};
var tagNameStartChar, tagNameChar, tagNameRegExp, tagString;
tagNameStartChar = "([:A-Z_a-z])";
tagNameChar = "(" + tagNameStartChar + "|[-.0-9])";
tagNameRegExp = new RegExp("^" + tagNameStartChar + tagNameChar + "*$");
tagString = function (string) {
string = String(string);
if (!tagNameRegExp.test(string)) {throw createDOMException(DOMException.INVALID_CHARACTER_ERR); }
return string.toUpperCase();
};
var asHTML, voidElements, escape, escapeAttr, escapeScript;
escape = function (text) {
return text
.replace(/</g, '<')
.replace(/>/g, '>');
};
escapeAttr = function (text) {
return text
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
};
escapeScript = function (text) {
return text
.replace(/<\//g, '\\u003C/');
};
// List of elements that are not allowed to have children
voidElements = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
asHTML = function (node) {
var key;
if (node instanceof Text) {
if (node.parentElement && node.parentElement.tagName === 'SCRIPT') {
return escapeScript(node.data);
} else {
return escape(node.data);
}
}
if (node instanceof Element) {
var tag, attributes, attribute, index;
tag = node.tagName.toLowerCase();
attributes = '';
for (index = 0; index < node.attributes.length; index++) {
attribute = node.attributes[index];
attributes += ' '+attribute.name+'="'+escapeAttr(attribute.value)+'"';
}
if (voidElements.indexOf(tag) !== -1 && node.childNodes.length === 0) {
return '<'+tag+attributes+'/>';
} else {
return '<'+tag+attributes+'>'+node.innerHTML+'</'+tag+'>';
}
}
};
/*
* Element
*/
var Element, initializeElement, createElement;
Element = (function () {
// Extension
(function (child, parent) {
function Element() {
this.constructor = child;
}
Element.prototype = parent.prototype;
child.prototype = new Element();
}(Element, Node));
// Prototype
(function () {
// These properties within defineProperties should not be in the element
// prototype, this is a speed optimization, as the call to defineProperties
// is expensive when called on every element initialization.
// On the actual DOM, these properties belong to the object itself,
// not the prototype.
Object.defineProperties(Element.prototype, {
'firstElementChild': {
configurable: true,
get: function () {
var index, child;
for (index = 0; index < this.childNodes.length; index++) {
child = this.childNodes[index];
if (child instanceof Element) {
return child;
}
}
return null;
}
},
'nextElementSibling': {
configurable: true,
get: function () {
var index, sibling, siblings;
if (this.parentNode) {
siblings = this.parentNode.childNodes;
for (index = siblings.indexOf(this) + 1; index < siblings.length; index++) {
sibling = siblings[index];
if (sibling instanceof Element) {
return sibling;
}
}
}
return null;
}
},
'innerHTML': {
configurable: true,
get: function () {
var index, html;
html = '';
for (index = 0; index < this.childNodes.length; index++) {
html += asHTML(this.childNodes[index]);
}
return html;
},
set: function (string) {
while (this.firstChild) {
this.removeChild(this.firstChild);
}
parser(string).forEach(
function (element) {
this.insertBefore(element);
}, this);
return string;
}
},
'outerHTML': {
configurable: true,
get: function () {
return asHTML(this);
},
set: function (string) {
parser(string).forEach(
function (element) {
this.parentElement.insertBefore(element, this);
}, this);
this.parentElement.removeChild(this);
return string;
}
},
'className': {
configurable: true,
get: function () {
return this.getAttribute('class') || '';
},
set: function (string) {
return this.setAttribute('class', string);
}
},
'id': {
configurable: true,
get: function () {
return this.getAttribute('id') || '';
},
set: function (string) {
return this.setAttribute('id', string);
}
}
});
Element.prototype.hasAttributes = function () {
return this.attributes.length > 0;
};
Element.prototype.getAttribute = function (key) {
var attribute, index;
if (key === null || key === undefined) { return null; }
for (index = 0; index < this.attributes.length; index++) {
attribute = this.attributes[index];
if (attribute.name === key){
return attribute.value;
}
}
return null;
};
Element.prototype.setAttribute = function (key, value) {
var attribute, index;
value = String(value);
key = attributeString(key);
for (index = 0; index < this.attributes.length; index++) {
attribute = this.attributes[index];
if (attribute.name === key){
attribute.value = value;
return;
}
}
this.attributes.push({
name: key,
value: value
});
};
Element.prototype.removeAttribute = function (key) {
var attribute, index;
key = attributeString(key);
for (index = 0; index < this.attributes.length; index++) {
attribute = this.attributes[index];
if (attribute.name === key){
this.attributes.splice(index, 1);
return;
}
}
};
Element.prototype.getElementsByClassName = function (string) {
var child, index, childClassName, classes, hasClasses, tree, matches;
hasClasses = function (childClasses, matchClasses) {
var index;
for (index = 0; index < matchClasses.length; index++) {
if (childClasses.indexOf(matchClasses[index]) === -1) {
return false;
}
}
return true;
};
// Initialization
classes = string.split(' ');
matches = [];
tree = [];
// Flatten node tree before filtering
Array.prototype.push.apply(tree, this.childNodes);
for (index = 0; index < tree.length; index++) {
child = tree[index];
if (!(child instanceof Element)) {
continue;
}
Array.prototype.push.apply(tree, child.childNodes);
childClassName = child.getAttribute('class');
if (childClassName && hasClasses(childClassName.split(' '), classes)) {
matches.push(child);
}
}
return matches;
};
Element.prototype.getElementsByTagName = function (string) {
var child, index, tag, tree, matches;
// Initialization
tag = string.toUpperCase();
matches = [];
tree = [];
// Flatten node tree before filtering
Array.prototype.push.apply(tree, this.childNodes);
for (index = 0; index < tree.length; index++) {
child = tree[index];
if (!(child instanceof Element)) {
continue;
}
Array.prototype.push.apply(tree, child.childNodes);
if (child instanceof Element && child.tagName === tag) {
matches.push(child);
}
}
return matches;
};
Element.prototype.querySelector = function (string) {
return this.querySelectorAll(string)[0];
};
Element.prototype.querySelectorAll = function (string) {
var elements, queries, trim,
parseSelector, parseSelectors, parseQuery, parseQueries,
checkTag, checkIDs, checkClasses, checkAttributes, check,
selectChildren, select;
trim = function (string) {
return string.trim();
};
parseSelector = function (string) {
var nameMatch, selector, nextMatch, match;
nameMatch = "([-]?[_a-zA-Z]+[_a-zA-Z0-9-]*)";
selector = {
combinator: '',
tag: '',
ids: [],
classes: [],
attributes: []
};
// This is a side-effecty helper function to reduce duplicate code.
nextMatch = function (regExp) {
var match;
if (regExp.test(string)) {
match = regExp.exec(string).slice(1);
string = string.replace(regExp, '');
}
return match;
};
// Combinator and tag must come first so they are checked before the loop
if (match = nextMatch(new RegExp("^([+~> ])\\s*"))) {
selector.combinator = match[0];
}
if (match = nextMatch(new RegExp("^"+nameMatch))) {
selector.tag = match[0];
}
// Within each selector, parse out classes, ids, and attributes
while (string !== '') {
if (match = nextMatch(new RegExp("^#"+nameMatch)))
{ selector.ids.push(match[0]); } else
if (match = nextMatch(new RegExp("^\\."+nameMatch)))
{ selector.classes.push(match[0]); } else
if (match = nextMatch(new RegExp("^\\["+nameMatch+"(?:([~|^$*]?[=])['\"]?"+nameMatch+"['\"]?)?\\]")))
{ selector.attributes.push({key: match[0], comparator: match[1], value: match[2]}); } else
{ throw createDOMException(DOMException.SYNTAX_ERR); }
}
return selector;
};
parseSelectors = function (strings) {
return strings.reduce(function (selectors, string) {
selectors.push(parseSelector(string));
return selectors;
}, []);
};
parseQuery = function (string) {
// Split selectors so there is a combinator, then selector
return parseSelectors(
string
.match(/\s*([+~> ]?\s*[^+~> ]+)/g)
.map(trim)
);
};
parseQueries = function (strings) {
return strings.reduce(function (queries, string) {
queries.push(parseQuery(string));
return queries;
}, []);
};
checkTag = function(selector, element) {
return !(selector.tag && selector.tag.toUpperCase() !== element.tagName);
};
checkIDs = function(selector, element) {
return !(selector.ids.length > 1 || (selector.ids.length === 1 && selector.ids[0] !== element.getAttribute('id')));
};
checkClasses = function(selector, element) {
var classes, index;
classes = (element.getAttribute('class') || '').split(' ').filter(function(string){return string;});
for (index = 0; index < selector.classes.length; index++) {
if (classes.indexOf(selector.classes[index]) === -1) { return false; }
}
return true;
};
checkAttributes = function(selector, element) {
var attribute, value, index;
for (index = 0; index < selector.attributes.length; index++) {
attribute = selector.attributes[index];
value = element.getAttribute(attribute.key);
if (value === null) { return false; }
switch (attribute.comparator) {
// Exactly equal to query value
case '=':
if (attribute.value !== value) { return false; }
break;
// One of space seperated words is equal to query value
case '~=':
if (value.split(' ').indexOf(attribute.value) === -1) { return false; }
break;
// One of hyphen seperated words is equal to query value
case '|=':
if (value.split('-').indexOf(attribute.value) === -1) { return false; }
break;
// Starts with query value
case '^=':
if (value.indexOf(attribute.value) !== 0) { return false; }
break;
// Ends with query value
case '$=':
if (value.indexOf(attribute.value)+attribute.value.length-value.length !== 0) { return false; }
break;
// Has query value somewhere
case '*=':
if (value.indexOf(attribute.value) === -1) { return false; }
break;
}
}
return true;
};
check = function (selector, element) {
if (element instanceof Element) {
return (checkTag(selector, element) && checkIDs(selector, element) && checkClasses(selector, element) && checkAttributes(selector, element));
}
};
// Given a selector and an element, find new elements that match the selector from the current element
selectChildren = function (selector, element) {
var selected, childIndex, child;
selected = [];
if (selector.combinator === '' || selector.combinator === '>') {
for (childIndex = 0; childIndex < element.childNodes.length; childIndex++) {
child = element.childNodes[childIndex];
if (check(selector, child)) {
selected.push(child);
}
if (selector.combinator === '' && child.childNodes.length) {
selected.push.apply(selected, selectChildren(selector, child));
}
}
} else if (element.nextSibling && (selector.combinator === '+' || selector.combinator === '~')) {
child = element.nextSibling;
if (check(selector, child)) {
selected.push(child);
}
if (selector.combinator === '~' || child.nodeType === Node.TEXT_NODE) {
selected.push.apply(selected, selectChildren(selector, child));
}
}
return selected;
};
// Given a query of selectors, apply selectors against elements and find matching children
select = function (query, elements) {
var selector, selected;
selector = query[0];
selected = elements.reduce(function (selected, element) {
return selected.concat(selectChildren(selector, element));
}, []);
if (query.length > 1) {
selected = select(query.slice(1), selected);
}
return selected;
};
string = String(string);
if (!string) { throw createDOMException(DOMException.SYNTAX_ERR); }
queries = parseQueries(
string
.split(',')
.map(trim)
);
elements = [this];
// Iterate through each query and return unique results
return queries.reduce(function (selected, query) {
return selected.concat(select(query, elements).filter(
function (element) { return selected.indexOf(element) === -1; }
));
}, []);
};
}());
//Constructor
function Element() {
throw new TypeError('Illegal constructor');
}
return Element;
}());
var parser;
initializeElement = function(tagName) {
// Required here because it would cause infinite loop if required above
if (!parser) {
parser = require('../utils/parser');
}
initializeNode.apply(this, arguments);
this.attributes = [];
this.nodeType = Node.ELEMENT_NODE;
this.tagName = tagString(tagName);
};
exports.Element = Element;
exports.initializeElement = initializeElement;
},{"../utils/parser":13,"./DOMException":2,"./Node":9,"./Text":10}],6:[function(require,module,exports){
"use strict";
var Document = require('./Document').Document;
/*
* HTMLDocument
*/
var HTMLDocument, createHTMLDocument;
HTMLDocument = (function () {
// Extension
(function (child, parent) {
function HTMLDocument() {
this.constructor = child;
}
HTMLDocument.prototype = parent.prototype;
child.prototype = new HTMLDocument();
}(HTMLDocument, Document));
// Constructor
function HTMLDocument() {
throw new TypeError('Illegal constructor');
}
return HTMLDocument;
}());
createHTMLDocument = (function (constructor) {
HTMLDocument.prototype = constructor.prototype;
function HTMLDocument() {
}
return function () {return new HTMLDocument(); };
}(HTMLDocument));
exports.HTMLDocument = HTMLDocument;
exports.createHTMLDocument = createHTMLDocument;
},{"./Document":3}],7:[function(require,module,exports){
"use strict";
var Element = require('./Element').Element;
var initializeElement = require('./Element').initializeElement;
/*
* HTMLElement
*/
var HTMLElement, initializeHTMLElement, createHTMLElement;
HTMLElement = (function () {
// Extension
(function (child, parent) {
function HTMLElement() {
this.constructor = child;
}
HTMLElement.prototype = parent.prototype;
child.prototype = new HTMLElement();
}(HTMLElement, Element));
// Constructor
function HTMLElement() {
throw new TypeError('Illegal constructor');
}
return HTMLElement;
}());
initializeHTMLElement = function(){
initializeElement.apply(this, arguments);
};
var createHTMLUnknownElement;
createHTMLElement = (function (constructor) {
HTMLElement.prototype = constructor.prototype;
function HTMLElement() {
initializeHTMLElement.apply(this, arguments);
}
return function (tagName) {
// Require it here instead of at the top because these classes extend this class
if (!createHTMLUnknownElement) {
createHTMLUnknownElement = require('./HTMLUnknownElement').createHTMLUnknownElement;
}
var factory;
tagName = String(tagName);
tagName = tagName.toUpperCase();
if (factories.hasOwnProperty(tagName)) {
factory = factories[tagName];
if (factory === createHTMLElement) {
return new HTMLElement(tagName);
}
return factory(tagName);
}
return createHTMLUnknownElement(tagName);
};
}(HTMLElement));
// These are all recognized html tags, and the factory to create them
// Unless they are implemented they will point to createHTMLElement
// The actual element they should point to are in comments after the tag
var factories = {
'A': createHTMLElement, // HTMLAnchorElement
'ABBR': createHTMLElement,
'ACRONYM': createHTMLElement,
'ADDRESS': createHTMLElement,
'APPLET': createHTMLElement, // HTMLAppletElement
'AREA': createHTMLElement, // HTMLAreaElement
'ARTICLE': createHTMLElement,
'ASIDE': createHTMLElement,
'AUDIO': createHTMLElement, // HTMLAudioElement extends HTMLMediaElement
'B': createHTMLElement,
'BASE': createHTMLElement, // HTMLBaseElement
'BASEFONT': createHTMLElement, // HTMLBaseFontElement
'BDI': createHTMLElement,
'BDO': createHTMLElement,
'BGSOUND': createHTMLElement,
'BIG': createHTMLElement,
'BLINK': createHTMLElement,
'BLOCKQUOTE': createHTMLElement, // HTMLQuoteElement
'BODY': createHTMLElement, // HTMLBodyElement
'BR': createHTMLElement, // HTMLBRElement
'BUTTON': createHTMLElement, // HTMLButtonElement
'CANVAS': createHTMLElement, // HTMLCanvasElement
'CAPTION': createHTMLElement, // HTMLTableCaptionElement
'CENTER': createHTMLElement,
'CITE': createHTMLElement,
'CODE': createHTMLElement,
'COL': createHTMLElement, // HTMLTableColElement
'COLGROUP': createHTMLElement, // HTMLTableColElement
'COMMAND': createHTMLElement,
'DATA': createHTMLElement,
'DATALIST': createHTMLElement, // HTMLDataListElement
'DD': createHTMLElement,
'DEL': createHTMLElement, // HTMLModElement
'DETAILS': createHTMLElement, // HTMLDetailsElement
'DFN': createHTMLElement,
'DIR': createHTMLElement, // HTMLDirectoryElement
'DIV': createHTMLElement, // HTMLDivElement
'DL': createHTMLElement, // HTMLDListElement
'DT': createHTMLElement,
'EM': createHTMLElement,
'EMBED': createHTMLElement, // HTMLEmbedElement
'FIELDSET': createHTMLElement, // HTMLFieldSetElement
'FIGCAPTION': createHTMLElement,
'FIGURE': createHTMLElement,
'FONT': createHTMLElement, // HTMLFontElement
'FOOTER': createHTMLElement,
'FORM': createHTMLElement, // HTMLFormElement
'FRAME': createHTMLElement, // HTMLFrameElement
'FRAMESET': createHTMLElement, // HTMLFrameSetElement
'H1': createHTMLElement, // HTMLHeadingElement
'H2': createHTMLElement, // HTMLHeadingElement
'H3': createHTMLElement, // HTMLHeadingElement
'H4': createHTMLElement, // HTMLHeadingElement
'H5': createHTMLElement, // HTMLHeadingElement
'H6': createHTMLElement, // HTMLHeadingElement
'HEAD': createHTMLElement, // HTMLHeadElement
'HEADER': createHTMLElement,
'HGROUP': createHTMLElement,
'HR': createHTMLElement, // HTMLHRElement
'HTML': createHTMLElement, // HTMLHtmlElement
'I': createHTMLElement,
'IFRAME': createHTMLElement, // HTMLIFrameElement
'IMG': createHTMLElement, // HTMLImageElement
'INPUT': createHTMLElement, // HTMLInputElement
'INS': createHTMLElement, // HTMLModElement
'ISINDEX': createHTMLElement,
'KBD': createHTMLElement,
'KEYGEN': createHTMLElement, // HTMLKeygenElement
'LABEL': createHTMLElement, // HTMLLabelElement
'LEGEND': createHTMLElement, // HTMLLegendElement
'LI': createHTMLElement, // HTMLLIElement
'LINK': createHTMLElement, // HTMLLinkElement
'LISTING': createHTMLElement, // HTMLPreElement
'MAIN': createHTMLElement,
'MAP': createHTMLElement, // HTMLMapElement
'MARK': createHTMLElement,
'MARQUEE': createHTMLElement, // HTMLMarqueeElement
'MENU': createHTMLElement, // HTMLMenuElement
'META': createHTMLElement, // HTMLMetaElement
'METER': createHTMLElement, // HTMLMeterElement
'NAV': createHTMLElement,
'NOBR': createHTMLElement,
'NOFRAMES': createHTMLElement,
'NOSCRIPT': createHTMLElement,
'OBJECT': createHTMLElement, // HTMLObjectElement
'OL': createHTMLElement, // HTMLOListElement
'OPTGROUP': createHTMLElement, // HTMLOptGroupElement
'OPTION': createHTMLElement, // HTMLOptionElement
'OUTPUT': createHTMLElement, // HTMLOutputElement
'P': createHTMLElement, // HTMLParagraphElement
'PARAM': createHTMLElement, // HTMLParamElement
'PLAINTEXT': createHTMLElement,
'PRE': createHTMLElement, // HTMLPreElement
'PROGRESS': createHTMLElement, // HTMLProgressElement
'Q': createHTMLElement, // HTMLQuoteElement
'RP': createHTMLElement,
'RT': createHTMLElement,
'RUBY': createHTMLElement,
'S': createHTMLElement,
'SAMP': createHTMLElement,
'SCRIPT': createHTMLElement, // HTMLScriptElement
'SECTION': createHTMLElement,
'SELECT': createHTMLElement, // HTMLSelectElement
'SMALL': createHTMLElement,
'SOURCE': createHTMLElement, // HTMLSourceElement
'SPACER': createHTMLElement,
'SPAN': createHTMLElement, // HTMLSpanElement
'STRIKE': createHTMLElement,
'STRONG': createHTMLElement,
'STYLE': createHTMLElement, // HTMLStyleElement
'SUB': createHTMLElement,
'SUMMARY': createHTMLElement,
'SUP': createHTMLElement,
'TABLE': createHTMLElement, // HTMLTableElement
'TBODY': createHTMLElement, // HTMLTableSectionElement
'TD': createHTMLElement, // HTMLTableCellElement
'TEXTAREA': createHTMLElement, // HTMLTextAreaElement
'TFOOT': createHTMLElement, // HTMLTableSectionElement
'TH': createHTMLElement, // HTMLTableCellElement
'THEAD': createHTMLElement, // HTMLTableSectionElement
'TIME': createHTMLElement,
'TITLE': createHTMLElement, // HTMLTitleElement
'TR': createHTMLElement, // HTMLTableRowElement
'TRACK': createHTMLElement, // HTMLTrackElement
'TT': createHTMLElement,
'U': createHTMLElement,
'UL': createHTMLElement, // HTMLUListElement
'VAR': createHTMLElement,
'VIDEO': createHTMLElement, // HTMLVideoElement extends HTMLMediaElement
'WBR': createHTMLElement,
'XMP': createHTMLElement // HTMLPreElement
};
exports.HTMLElement = HTMLElement;
exports.initializeHTMLElement = initializeHTMLElement;
exports.createHTMLElement = createHTMLElement;
},{"./Element":5,"./HTMLUnknownElement":8}],8:[function(require,module,exports){
"use strict";
var HTMLElement = require('./HTMLElement').HTMLElement;
var initializeHTMLElement = require('./HTMLElement').initializeHTMLElement;
/*
* HTMLUnknownElement
*/
var HTMLUnknownElement, createHTMLUnknownElement;
HTMLUnknownElement = (function () {
// Extension
(function (child, parent) {
function HTMLUnknownElement() {
this.constructor = child;
}
HTMLUnknownElement.prototype = parent.prototype;
child.prototype = new HTMLUnknownElement();
}(HTMLUnknownElement, HTMLElement));
//Constructor
function HTMLUnknownElement() {
throw new TypeError('Illegal constructor');
}
return HTMLUnknownElement;
}());
createHTMLUnknownElement = (function (constructor) {
HTMLUnknownElement.prototype = constructor.prototype;
function HTMLUnknownElement() {
initializeHTMLElement.apply(this, arguments);
}
return function (tagName) {return new HTMLUnknownElement(tagName); };
}(HTMLUnknownElement));
exports.HTMLUnknownElement = HTMLUnknownElement;
exports.createHTMLUnknownElement = createHTMLUnknownElement;
},{"./HTMLElement":7}],9:[function(require,module,exports){
"use strict";
var DOMException = require('./DOMException').DOMException;
var createDOMException = require('./DOMException').createDOMException;
/*
* Node
*/
var Node, initializeNode;
Node = (function () {
// Contants
Node.ELEMENT_NODE = 1;
Node.ATTRIBUTE_NODE = 2;
Node.TEXT_NODE = 3;
Node.CDATA_SECTION_NODE = 4;
Node.ENTITY_REFERENCE_NODE = 5;
Node.ENTITY_NODE = 6;
Node.PROCESSING_INSTRUCTION_NODE = 7;
Node.DOCUMENT_NODE = 9;
Node.COMMENT_NODE = 8;
Node.DOCUMENT_TYPE_NODE = 10;
Node.DOCUMENT_FRAGMENT_NODE = 11;
Node.NOTATION_NODE = 12;
Node.DOCUMENT_POSITION_DISCONNECTED = 1;
Node.DOCUMENT_POSITION_PRECEDING = 2;
Node.DOCUMENT_POSITION_FOLLOWING = 4;
Node.DOCUMENT_POSITION_CONTAINS = 8;
Node.DOCUMENT_POSITION_CONTAINED_BY = 16;
Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32;
//Prototype
// These properties within defineProperties should not be in the element
// prototype, this is a speed optimization, as the call to defineProperties
// is expensive when called on every element initialization.
// On the actual DOM, these properties belong to the object itself,
// not the prototype.
Object.defineProperties(Node.prototype, {
'parentElement': {
configurable: true,
get: function () {
return this.parentNode;
}
},
'firstChild': {
configurable: true,
get: function () {
return this.childNodes[0] || null;
}
},
'lastChild': {
configurable: true,
get: function () {
return this.childNodes[this.childNodes.length - 1] || null;
}
},
'nextSibling': {
configurable: true,
get: function () {
var index, sibling;
if (this.parentNode) {
index = this.parentNode.childNodes.indexOf(this);
sibling = this.parentNode.childNodes[index + 1];
}
return sibling || null;
}
},
'previousSibling': {
configurable: true,
get: function () {
var index, sibling;
if (this.parentNode) {
index = this.parentNode.childNodes.indexOf(this);
sibling = this.parentNode.childNodes[index - 1];
}
return sibling || null;
}
}
});
// cloneNode is set up to load in dependencies once, and then replace itself
// with the closure function. This is so the dependencies do not need to be
// loaded repeatedly, they cannot be taken out of the function, or it will
// cause a dependency loop.
Node.prototype.cloneNode = function () {
var createHTMLElement = require('./HTMLElement').createHTMLElement;
var createText = require('./Text').createText;
Node.prototype.cloneNode = function (deep) {
var newNode;
var index;
if (deep === null || deep === undefined) { deep = true; }
if (this.nodeType === 1 || this.nodeType === 10 || this.nodeType === 11) {
newNode = createHTMLElement(this.tagName);
for (index = 0; index < this.attributes.length; index++) {
newNode.attributes[index] = {
name: this.attributes[index].name,
value: this.attributes[index].value
};
}
}
if (this.nodeType === 3) {
newNode = createText(this.data);
}
if (deep === true) {
for (index = 0; index < this.childNodes.length; index++) {
newNode.insertBefore(this.childNodes[index].cloneNode(true));
}
}
return newNode;
};
return Node.prototype.cloneNode.apply(this, arguments);
};
Node.prototype.contains = function (element) {
var index, child;
for (index = 0; index < this.childNodes.length; index++) {
child = this.childNodes[index];
if (child === element || child.contains(element)) {
return true;
}
}
return false;
};
Node.prototype.hasChildNodes = function () {
return this.childNodes.length > 0;
};
Node.prototype.normalize = function () {
var index, child;
for (index = 0; index < this.childNodes.length; index++) {
child = this.childNodes[index];
child.normalize();
if (child.nodeType === Node.TEXT_NODE) {
if (child.data === '') {
child.parentNode.removeChild(child);
} else if (child.nextSibling.nodeType === Node.TEXT_NODE) {
child.appendData(child.nextSibling.data);
this.removeChild(child.nextSibling);
}
}
}
};
Node.prototype.insertBefore = function (newElement, referenceElement) {
var index;
if (!(newElement instanceof Node)) {
throw createDOMException(DOMException.NOT_FOUND_ERR);
}
if (referenceElement instanceof Node) {
index = this.childNodes.indexOf(referenceElement);
if (index === -1) {
throw createDOMException(DOMException.NOT_FOUND_ERR);
}
}
// If already inserted, remove from where it was
if (newElement.parentNode) {
newElement.parentNode.removeChild(newElement);
}
newElement.parentNode = this;
// We need to reindex in case the parent element was this element
// Index is by default the last node.
index = this.childNodes.length;
if (referenceElement !== null && referenceElement !== undefined) {
index = this.childNodes.indexOf(referenceElement);
}
this.childNodes.splice(index, 0, newElement);
return newElement;
};
Node.prototype.appendChild = function (newElement) {
return this.insertBefore(newElement);
};
Node.prototype.removeChild = function (childElement) {
var index = this.childNodes.indexOf(childElement);
if (index === -1) {
throw createDOMException(DOMException.NOT_FOUND_ERR);
}
this.childNodes.splice(index, 1);
// We still have to set parent to null in case it's reused.
childElement.parentNode = null;
return childElement;
};
Node.prototype.replaceChild = function (newElement, oldElement) {
if (newElement instanceof Node || oldElement instanceof Node) {
this.insertBefore(newElement, oldElement);
this.removeChild(oldElement);
}
return oldElement;
};
//Constructor
function Node() {
throw new TypeError('Illegal constructor');
}
return Node;
}());
initializeNode = function () {
this.parentNode = null;
this.childNodes = [];
};
exports.Node = Node;
exports.initializeNode = initializeNode;
},{"./DOMException":2,"./HTMLElement":7,"./Text":10}],10:[function(require,module,exports){
"use strict";
var CharacterData = require('./CharacterData').CharacterData;
var initializeCharacterData = require('./CharacterData').initializeCharacterData;
var Node = require('./Node').Node;
/*
* Text
*/
var Text, initializeText, createText;
Text = (function () {
// Extension
(function (child, parent) {
function Text() {
this.constructor = child;
}
Text.prototype = parent.prototype;
child.prototype = new Text();
}(Text, CharacterData));
// Constructor
function Text() {
if (!(this instanceof Text)) {
throw new TypeError("Failed to construct 'Text': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
} else {
return createText.apply(this, arguments);
}
};
return Text;
}());
initializeText = function (string) {
initializeCharacterData.apply(this, arguments);
this.nodeType = Node.TEXT_NODE;
};
createText = (function (constructor) {
Text.prototype = constructor.prototype;
function Text() {
initializeText.apply(this, arguments);
}
return function (string) {return new Text(string); };
}(Text));
exports.Text = Text;
exports.initializeText = initializeText;
exports.createText = createText;
},{"./CharacterData":1,"./Node":9}],11:[function(require,module,exports){
"use strict";
var CharacterData = require('./CharacterData').CharacterData;
var Document = require('./Document').Document;
var DOMException = require('./DOMException').DOMException;
var Element = require('./Element').Element;
var HTMLDocument = require('./HTMLDocument').HTMLDocument;
var HTMLElement = require('./HTMLElement').HTMLElement;
var Node = require('./Node').Node;
var Text = require('./Text').Text;
var Window = require('./Window').Window;
var createHTMLDocument = require('./HTMLDocument').createHTMLDocument;
/*
* Window
*/
var Window, createWindow;
Window = (function () {
// Constructor
function Window() {
throw new TypeError('Illegal constructor');
}
return Window;
}());
createWindow = (function (constructor) {
Window.prototype = constructor.prototype;
// Constructor Override
function Window() {
// References to constructors
this.CharacterData = CharacterData;
this.Document = Document;
this.DOMException = DOMException;
this.Element = Element;
this.HTMLDocument = HTMLDocument;
this.HTMLElement = HTMLElement;
this.Node = Node;
this.Text = Text;
this.Window = Window;
// Properties
this.document = createHTMLDocument();
}
return function () {return new Window(); };
}(Window));
exports.Window = Window;
exports.createWindow = createWindow;
},{"./CharacterData":1,"./DOMException":2,"./Document":3,"./Element":5,"./HTMLDocument":6,"./HTMLElement":7,"./Node":9,"./Text":10,"./Window":11}],12:[function(require,module,exports){
var process=require("__browserify_process");"use strict";
exports.window = require('./DOM/Window').createWindow();
exports.parser = require('./utils/parser');
if (process.browser)
window.sub = exports;
},{"./DOM/Window":11,"./utils/parser":13,"__browserify_process":66}],13:[function(require,module,exports){
"use strict";
var createDocumentType = require('../DOM/DocumentType').createDocumentType;
var createHTMLElement = require('../DOM/HTMLElement').createHTMLElement;
var createText = require('../DOM/Text').createText;
var htmlparser = require('htmlparser2');
var handler = new htmlparser.DefaultHandler(function (error, dom) {
if (error) {
throw error;
}
else {
}
}, { verbose: true, ignoreWhitespace: false, enforceEmptyTags: true });
var parser = new htmlparser.Parser(handler);
var converter = function (raw) {
return raw.map(function(node){
var element, children, key, match;
switch (node.type) {
case 'directive':
/* doctype regex explanation
* // All doctypes start with !doctype then one or more spaces
* ^!doctype\s+
* // The name is a consecutive group of characters
* (\S+)
* // This next segment is optional
* (?:\s+
* // The optional segment begins with PUBLIC or SYSTEM
* (?:SYSTEM
* // If the optional segment begins with SYSTEM there must be a string after it
* (?!\s*$)
* |PUBLIC\s+
* // If it begins with PUBLIC the next segment is a quoted publicID string
* // Check for an opening " or '
* // Then do a lookahead for the matching quote to prevent quote mixing
* (?:"(?=[^']+")|'(?=[^"]+'))
* // The string block (This means you cannot have a differing quote within your quote block but this regex is complex enough)
* ([^'"]+)
* // Match the ending quote
* ["']
* )
* // Begin the systemID string which may come after SYSTEM or after the publicID string
* // The systemID is optional after the publicID
* (?:\s+
* // The quote check same as above
* (?:"(?=[^']+")|'(?=[^"]+'))
* // The string block
* ([^'"]+)
* // Match the ending quote
* ["']
* )?
*)?$
*/
match = node.data.match(/^!doctype\s+(\S+)(?:\s+(?:SYSTEM(?!$)|PUBLIC\s+(?:"(?=[^']+")|'(?=[^"]+'))([^'"]+)["'])(?:\s+(?:"(?=[^']+")|'(?=[^"]+'))([^'"]+)["'])?)?$/i) || [];
element = createDocumentType(match[1], match[2], match[3]);
break;
case 'tag':
case 'script':
case 'style':
element = createHTMLElement(node.name);
for (key in node.attribs) {
element.setAttribute(key, node.attribs[key]);
}
if (node.children) {
children = converter(node.children);
children.forEach(function(child){
element.insertBefore(child);
});
}
break;
case 'text':
element = createText(node.data);
break;
}
return element;
}).filter(function(element){
return element;
});
};
module.exports = function (string) {
parser.parseComplete(string);
return converter(handler.dom);
};
},{"../DOM/DocumentType":4,"../DOM/HTMLElement":7,"../DOM/Text":10,"htmlparser2":64}],14:[function(require,module,exports){
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
;(function (exports) {
'use strict';
var Arr = (typeof Uint8Array !== 'undefined')
? Uint8Array
: Array
var PLUS = '+'.charCodeAt(0)
var SLASH = '/'.charCodeAt(0)
var NUMBER = '0'.charCodeAt(0)
var LOWER = 'a'.charCodeAt(0)
var UPPER = 'A'.charCodeAt(0)
var PLUS_URL_SAFE = '-'.charCodeAt(0)
var SLASH_URL_SAFE = '_'.charCodeAt(0)
function decode (elt) {
var code = elt.charCodeAt(0)
if (code === PLUS ||
code === PLUS_URL_SAFE)
return 62 // '+'
if (code === SLASH ||
code === SLASH_URL_SAFE)
return 63 // '/'
if (code < NUMBER)
return -1 //no match
if (code < NUMBER + 10)
return code - NUMBER + 26 + 26
if (code < UPPER + 26)
return code - UPPER
if (code < LOWER + 26)
return code - LOWER + 26
}
function b64ToByteArray (b64) {
var i, j, l, tmp, placeHolders, arr
if (b64.length % 4 > 0) {
throw new Error('Invalid string. Length must be a multiple of 4')
}
// the number of equal signs (place holders)
// if there are two placeholders, than the two characters before it
// represent one byte
// if there is only one, then the three characters before it represent 2 bytes
// this is just a cheap hack to not do indexOf twice
var len = b64.length
placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
// base64 is 4/3 + up to two characters of the original data
arr = new Arr(b64.length * 3 / 4 - placeHolders)
// if there are placeholders, only get up to the last complete 4 chars
l = placeHolders > 0 ? b64.length - 4 : b64.length
var L = 0
function push (v) {
arr[L++] = v
}
for (i = 0, j = 0; i < l; i += 4, j += 3) {
tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
push((tmp & 0xFF0000) >> 16)
push((tmp & 0xFF00) >> 8)
push(tmp & 0xFF)
}
if (placeHolders === 2) {
tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
push(tmp & 0xFF)
} else if (placeHolders === 1) {
tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
push((tmp >> 8) & 0xFF)
push(tmp & 0xFF)
}
return arr
}
function uint8ToBase64 (uint8) {
var i,
extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
output = "",
temp, length
function encode (num) {
return lookup.charAt(num)
}
function tripletToBase64 (num) {
return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
}
// go through the array every three bytes, we'll deal with trailing stuff later
for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
output += tripletToBase64(temp)
}
// pad the end with zeros, but make sure to not forget the extra bytes
switch (extraBytes) {
case 1:
temp = uint8[uint8.length - 1]
output += encode(temp >> 2)
output += encode((temp << 4) & 0x3F)
output += '=='
break
case 2:
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
output += encode(temp >> 10)
output += encode((temp >> 4) & 0x3F)
output += encode((temp << 2) & 0x3F)
output += '='
break
}
return output
}
exports.toByteArray = b64ToByteArray
exports.fromByteArray = uint8ToBase64
}(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
},{}],15:[function(require,module,exports){
//
// The shims in this file are not fully implemented shims for the ES5
// features, but do work for the particular usecases there is in
// the other modules.
//
var toString = Object.prototype.toString;
var hasOwnProperty = Object.prototype.hasOwnProperty;
// Array.isArray is supported in IE9
function isArray(xs) {
return toString.call(xs) === '[object Array]';
}
exports.isArray = typeof Array.isArray === 'function' ? Array.isArray : isArray;
// Array.prototype.indexOf is supported in IE9
exports.indexOf = function indexOf(xs, x) {
if (xs.indexOf) return xs.indexOf(x);
for (var i = 0; i < xs.length; i++) {
if (x === xs[i]) return i;
}
return -1;
};
// Array.prototype.filter is supported in IE9
exports.filter = function filter(xs, fn) {
if (xs.filter) return xs.filter(fn);
var res = [];
for (var i = 0; i < xs.length; i++) {
if (fn(xs[i], i, xs)) res.push(xs[i]);
}
return res;
};
// Array.prototype.forEach is supported in IE9
exports.forEach = function forEach(xs, fn, self) {
if (xs.forEach) return xs.forEach(fn, self);
for (var i = 0; i < xs.length; i++) {
fn.call(self, xs[i], i, xs);
}
};
// Array.prototype.map is supported in IE9
expor