diff --git a/lite/index.html b/lite/index.html new file mode 100644 index 0000000..834708b --- /dev/null +++ b/lite/index.html @@ -0,0 +1,120 @@ + + +
++ Progress: +
+ + + + + + diff --git a/lite/muther.js b/lite/muther.js new file mode 100644 index 0000000..672615e --- /dev/null +++ b/lite/muther.js @@ -0,0 +1,49 @@ +/** + * Mini Unit Test Harness + * Copyright(c) 2011, Google Inc. + * + * A really tiny unit test harness. + */ + +var muther = muther || {}; + +muther.assert = function(cond, err) { + if (!cond) { + throw err; + } +}; + +muther.addTest_ = function(testDiv, innerHTML, pass) { + var theTest = document.createElement('div'); + // Convert all angle brackets into displayable text. + innerHTML = innerHTML.replace(/&/g, '&'). + replace(//g, '>'); + theTest.innerHTML = innerHTML; + theTest.setAttribute('style', pass ? 'color:#090' : 'color:#900'); + testDiv.appendChild(theTest); +}; + +// Run through all tests and record the results. +muther.test = function(testsToRun) { + var progress = document.createElement('progress'); + var testDiv = document.createElement('div'); + document.body.insertBefore(testDiv, document.body.firstChild); + document.body.insertBefore(progress, document.body.firstChild); + + var max = testsToRun.length; + progress.max = max; + progress.value = 0; + testDiv.innerHTML = max + ' Tests'; + for (var t = 0; t < max; ++t) { + var test = testsToRun[t]; + try { + test(); + muther.addTest_(testDiv, test.name + ': Pass', true); + } catch(e) { + muther.addTest_(testDiv, test.name + ': Fail. ' + e, false); + } + progress.value += 1; + } +}; + diff --git a/lite/pdom.js b/lite/pdom.js new file mode 100644 index 0000000..c4b9d76 --- /dev/null +++ b/lite/pdom.js @@ -0,0 +1,856 @@ +/** + * Pico DOM + * Copyright(c) 2011, Google Inc. + * + * A really tiny implementation of the DOM for use in Web Workers. + */ + +// TODO: Look into defineProperty instead of getters. + +var pdom = pdom || {}; + +// =========================================================================== +// Stolen from Closure because it's the best way to do Java-like inheritance. +pdom.base = function(me, opt_methodName, var_args) { + var caller = arguments.callee.caller; + if (caller.superClass_) { + // This is a constructor. Call the superclass constructor. + return caller.superClass_.constructor.apply( + me, Array.prototype.slice.call(arguments, 1)); + } + + var args = Array.prototype.slice.call(arguments, 2); + var foundCaller = false; + for (var ctor = me.constructor; + ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) { + if (ctor.prototype[opt_methodName] === caller) { + foundCaller = true; + } else if (foundCaller) { + return ctor.prototype[opt_methodName].apply(me, args); + } + } + + // If we did not find the caller in the prototype chain, + // then one of two things happened: + // 1) The caller is an instance method. + // 2) This method was not called by the right caller. + if (me[opt_methodName] === caller) { + return me.constructor.prototype[opt_methodName].apply(me, args); + } else { + throw Error( + 'goog.base called from a method of one name ' + + 'to a method of a different name'); + } +}; +pdom.inherits = function(childCtor, parentCtor) { + /** @constructor */ + function tempCtor() {}; + tempCtor.prototype = parentCtor.prototype; + childCtor.superClass_ = parentCtor.prototype; + childCtor.prototype = new tempCtor(); + childCtor.prototype.constructor = childCtor; +}; +// =========================================================================== + + +/** + * A DOMException + * + * @param {number} code The DOM exception code. + * @constructor + */ +pdom.DOMException = function(code) { + this.__defineGetter__('code', function() { return code }); +}; +pdom.DOMException.INDEX_SIZE_ERR = 1; +pdom.DOMException.DOMSTRING_SIZE_ERR = 2; +pdom.DOMException.HIERARCHY_REQUEST_ERR = 3; +pdom.DOMException.WRONG_DOCUMENT_ERR = 4; +pdom.DOMException.INVALID_CHARACTER_ERR = 5; +pdom.DOMException.NO_DATA_ALLOWED_ERR = 6; +pdom.DOMException.NO_MODIFICATION_ALLOWED_ERR = 7; +pdom.DOMException.NOT_FOUND_ERR = 8; +pdom.DOMException.NOT_SUPPORTED_ERR = 9; +pdom.DOMException.INUSE_ATTRIBUTE_ERR = 10; +pdom.DOMException.INVALID_STATE_ERR = 11; +pdom.DOMException.SYNTAX_ERR = 12; +pdom.DOMException.INVALID_MODIFICATION_ERR = 13; +pdom.DOMException.NAMESPACE_ERR = 14; +pdom.DOMException.INVALID_ACCESS_ERR = 15; +pdom.DOMException.VALIDATION_ERR = 16; +pdom.DOMException.TYPE_MISMATCH_ERR = 17; + + +/** + * A NodeList. + * + * @param {Array.This table shows the current level of DOM Core support in pdom. At present, this table only shows DOM Core Level 1 and a couple properties/methods from DOM Level 2.
+| Interface | Property/Method | Support? |
|---|---|---|
| Node | +DOMString nodeName | |
| DOMString nodeValue | ||
| unsigned short nodeType | ||
| Node parentNode | ||
| NodeList childNodes | ||
| Node firstChild | ||
| Node lastChild | ||
| Node previousSibling | ||
| Node nextSibling | ||
| NamedNodeMap attributes | ||
| Document ownerDocument | ||
| Node insertBefore(in Node newChild, in Node refChild) | ||
| Node replaceChild(in Node newChild, in Node oldChild) | ||
| Node removeChild(in Node oldChild) | ||
| Node appendChild(in Node newChild) | ||
| boolean hasChildNodes() | ||
| Node cloneNode(in boolean deep) | ||
| DOMString namespaceURI | ||
| Element : Node | +DOMString tagName | |
| DOMString getAttribute(in DOMString name) | ||
| void setAttribute(in DOMString name, in DOMString value) | ||
| void removeAttribute(in DOMString name) | ||
| Attr getAttributeNode(in DOMString name) | ||
| Attr setAttributeNode(in Attr newAttr) | ||
| Attr removeAttributeNode(in Attr oldAttr) | ||
| NodeList getElementsByTagName(in DOMString name) | ||
| boolean hasAttribute(in DOMString name) | ||
| Document : Node | +DocumentType doctype | |
| DOMImplementation implementation | ||
| Element documentElement | ||
| Element createElement(in DOMString tagName) | ||
| DocumentFragment createDocumentFragment() | ||
| createTextNode(in DOMString data) | ||
| createComment(in DOMString data) | ||
| createCDATASection(in DOMString data) | ||
| createProcessingInstruction(in DOMString target, in DOMString data) | ||
| Attr createAttribute(in DOMString name) | ||
| EntityReference createEntityByReference(in DOMString name) | ||
| NodeList getElementsByTagName(in DOMString tagName) | ||
| Element getElementById(in DOMString elementId) | ||
| NodeList | +Node item(in unsigned long index) | |
| unsigned long length | ||
| NamedNodeMap | +Node getNamedItem(in DOMString name) | |
| Node setNamedItem(in Node arg) | ||
| Node removeNamedItem(in DOMString name) | ||
| Node item(in unsigned long index) | ||
| unsigned long length | ||
| CharacterData : Node | +DOMString data | |
| unsigned long length | ||
| DOMString substringData(in unsigned long offset, in unsigned long count) | ||
| void appendData(in DOMString arg) | ||
| void insertData(in unsigned long offset, in DOMString arg) | ||
| void deleteData(in unsigned long offset, in unsigned long count) | ||
| void replaceData(in unsigned long offset, in unsigned long count, in DOMString arg) | ||
| Text : CharacterData | +Text splitText(in unsigned long offset) | |
| Attr : Node | +DOMString name | |
| boolean specified | ||
| DOMString value | ||
| Element ownerElement | ||
| Comment : CharacterData | +(empty) | |
| CDATASection : Text | +(empty) | |
| DOMException | +unsigned short code | |
| DOMImplementation | +boolean hasFeature(in DOMString feature, in DOMString version) | |
| DocumentFragment | +(empty) | |
| DocumentType : Node | +DOMString name | |
| NamedNodeMap entities | ||
| NamedNodeMap notations | ||
| Notation : Node | +DOMString publicId | |
| DOMString systemId | ||
| Entity : Node | +DOMString publicId | |
| DOMString systemId | ||
| DOMString notationName | ||
| EntityReference : Node | +(empty) | |
| ProcessingInstruction : Node | +DOMString target | |
| DOMString data | ||