diff --git a/bin/jquery-1.3.2-test.js b/bin/jquery-1.3.2-test.js index 80a2b342..69706814 100644 --- a/bin/jquery-1.3.2-test.js +++ b/bin/jquery-1.3.2-test.js @@ -3,6 +3,8 @@ load("build/runtest/env.js"); (function($env){ + //$env.fixHTML = false; + $env("test/index.html", { //let it load the script from the html scriptTypes: { @@ -24,9 +26,57 @@ load("build/runtest/env.js"); }); $env.writeToFile( document.documentElement.xml, - $env.location('jqenv.html') + $env.location('jqenv-'+Date.now()+'.html') ); }; + //allow jquery to run ajax + isLocal = false; + + + var unsafeStop = stop, + unsafeStart = start, + isStopped = null; + + stop = function(){ + if(isStopped === null || !isStopped === false){ + $env.log('PAUSING QUNIT'); + isStopped = true; + unsafeStop(arguments); + } + }; + start = function(){ + if(isStopped === null || isStopped === true ){ + $env.log('RESTARTING QUNIT'); + isStopped = false; + unsafeStart(arguments); + } + }; + //we know some ajax calls will fail becuase + //we are not running against a running server + //for php files + var handleError = jQuery.handleError; + jQuery.handleError = function(){ + ok(false, 'Ajax may have failed while running locally'); + try{ + handleError(arguments); + }catch(e){} + //allow tests to gracefully continue + start(); + }; + //allow unanticipated xhr error with no ajax.handleError + //callback (eg jQuery.getScript) to exit gracefully + $env.onInterrupt = function(){ + ok(false, 'gracefully continuing test'); + start(); + }; + + + $env.onScriptLoadError = function(script){ + Envjs.error("failed to load script \n"+script.text); + ok(false, 'Ajax may have failed to load correct script while running locally'); + //allow tests to gracefully continue + start(); + }; } } }); diff --git a/bin/test-jquery.sh b/bin/test-jquery.sh index 0fa3978f..10fc4582 100755 --- a/bin/test-jquery.sh +++ b/bin/test-jquery.sh @@ -27,7 +27,7 @@ if [ ! -d "$JQUERY_DIR" ]; then fi cp dist/env.rhino.js $JQUERY_DIR/build/runtest/env.js -cp rhino/js.jar $JQUERY_DIR/build/js.jar +cp dist/env-js.jar $JQUERY_DIR/build/js.jar cp bin/jquery-$VERSION-test.js $JQUERY_DIR/build/runtest/test.js if [ $DEBUG -eq 1 ]; then @@ -35,7 +35,7 @@ if [ $DEBUG -eq 1 ]; then perl -pi~ -e "s/^JAR(.*)(-jar.*|-cp.*)/JAR\1 -cp \\$\{BUILD_DIR}\/js.jar org.mozilla.javascript.tools.debugger.Main/" $JQUERY_DIR/Makefile; else echo 'running with rhino' - perl -pi~ -e "s/^JAR(.*)(-jar.*|-cp.*)/JAR\1 -jar \\$\{BUILD_DIR}\/js.jar -w -debug/" $JQUERY_DIR/Makefile; + perl -pi~ -e "s/^JAR(.*)(-jar.*|-cp.*)/JAR\1 -cp \\$\{BUILD_DIR}\/js.jar org.mozilla.javascript.tools.envjs.Main/" $JQUERY_DIR/Makefile; fi cd $JQUERY_DIR diff --git a/build.properties b/build.properties index 3e69c527..51ad5408 100644 --- a/build.properties +++ b/build.properties @@ -2,7 +2,7 @@ PROJECT: env-js BUILD_MAJOR: 1 BUILD_MINOR: 0 -BUILD_ID: rc1 +BUILD_ID: rc2 BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} VERSION: ${BUILD} ${DSTAMP} diff --git a/dist/env-js.jar b/dist/env-js.jar index 54920281..29779a89 100644 Binary files a/dist/env-js.jar and b/dist/env-js.jar differ diff --git a/dist/env.js b/dist/env.js index 752cca12..59b148ba 100644 --- a/dist/env.js +++ b/dist/env.js @@ -1,5 +1,5 @@ /* - * Envjs env-js.1.0.rc1 + * Envjs env-js.1.0.rc2 * Pure JavaScript Browser Environment * By John Resig * Copyright 2008-2009 John Resig, under the MIT License @@ -499,12 +499,12 @@ __extend__(DOMNamedNodeMap.prototype, { throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)); } else { this[itemIndex] = arg; // over-write existing NamedNode - this[arg.name] = arg; + this[arg.name.toLowerCase()] = arg; } } else { // add new NamedNode Array.prototype.push.apply(this, [arg]); - this[arg.name] = arg; + this[arg.name.toLowerCase()] = arg; } arg.ownerElement = this.parentNode; // update ownerElement @@ -652,12 +652,13 @@ var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) { for (var i=0; i 0); + return (this!==null&&this!=undefined); }, get nodeType(){ return DOMNode.ATTRIBUTE_NODE; }, get xml(){ - return this.nodeName + '="' + __escapeXML__(this.nodeValue) + '" '; + if(this.nodeValue) + return this.nodeName + '="' + __escapeXML__(this.nodeValue) + '" '; + else + return ''; }, toString : function(){ return "Attr #" + this._id + " " + this.name; @@ -1769,7 +1775,7 @@ $debug("Defining Element"); var DOMElement = function(ownerDocument) { this.DOMNode = DOMNode; this.DOMNode(ownerDocument); - this.id = ""; // the ID of the element + //this.id = null; // the ID of the element }; DOMElement.prototype = new DOMNode; __extend__(DOMElement.prototype, { @@ -1790,17 +1796,17 @@ __extend__(DOMElement.prototype, { if (attr) { ret = attr.value; } - return ret; // if Attribute exists, return its value, otherwise, return "" + return ret; // if Attribute exists, return its value, otherwise, return null }, setAttribute : function (name, value) { // if attribute exists, use it var attr = this.attributes.getNamedItem(name); - var value = value+''; + //I had to add this check becuase as the script initializes //the id may be set in the constructor, and the html element //overrides the id property with a getter/setter. if(__ownerDocument__(this)){ - if (!attr) { + if (attr===null||attr===undefined) { attr = __ownerDocument__(this).createAttribute(name); // otherwise create it } @@ -1818,15 +1824,17 @@ __extend__(DOMElement.prototype, { } } - if (__isIdDeclaration__(name)) { - // this.id = value; // cache ID for getElementById() - } + /*if (__isIdDeclaration__(name)) { + this.id = value; // cache ID for getElementById() + }*/ // assign values to properties (and aliases) attr.value = value; // add/replace Attribute in NamedNodeMap this.attributes.setNamedItem(attr); + }else{ + $warn('Element has no owner document '+this.tagName+'\n\t cant set attribute ' + name + ' = '+value ); } }, removeAttribute : function removeAttribute(name) { @@ -3206,7 +3214,7 @@ function isEmpty(str) { * @param str : string - The string to be escaped * @return : string - The escaped string */ -var escAmpRegEx = /&/g; +var escAmpRegEx = /&(?!(amp;|lt;|gt;|quot|apos;))/g; var escLtRegEx = //g; var quotRegEx = /"/g; @@ -3529,7 +3537,7 @@ var DOMImplementation = function() { this.errorChecking = true; // by default, test for exceptions }; -var $handleEndOfNormalOrEmptyElement = function(node, doc, p){ +var __endHTMLElement__ = function(node, doc, p){ if(node.nodeName.toLowerCase() == 'script'){ p.replaceEntities = true; $env.loadLocalScript(node, p); @@ -3798,7 +3806,7 @@ function __parseLoop__(impl, doc, p) { } else if(iEvt == XMLP._ELM_E) { // End-Element Event - $handleEndOfNormalOrEmptyElement(iNodeParent, doc, p); + __endHTMLElement__(iNodeParent, doc, p); iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree } @@ -3886,7 +3894,7 @@ function __parseLoop__(impl, doc, p) { } - $handleEndOfNormalOrEmptyElement(iNode, doc, p); + __endHTMLElement__(iNode, doc, p); iNodeParent.appendChild(iNode); // attach Element to parentNode } else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) { // TextNode and entity Events @@ -4178,9 +4186,15 @@ __extend__(DOMDocument.prototype, { get parentWindow(){ return this._parentWindow; }, - loadXML : function(xmlStr) { + loadXML : function(xmlString) { // create SAX Parser - var parser = new XMLP(xmlStr+''); + var htmlString; + if($env.fixHTML){ + htmlString = $env.cleanHTML(xmlString); + }else{ + htmlString = xmlString + } + var parser = new XMLP(htmlString+''); // create DOM Document if(this === $document){ @@ -4470,11 +4484,7 @@ __extend__(DOMDocument.prototype, { }, get defaultView(){ //TODO: why isnt this just 'return $w;'? return { getComputedStyle: function(elem){ - return { getPropertyValue: function(prop){ - prop = prop.replace(/\-(\w)/g,function(m,c){ return c.toUpperCase(); }); - var val = elem.style[prop]; - if ( prop == "opacity" && val == "" ){ val = "1"; }return val; - }}; + return $w.getComputedStyle(elem); }}; }, _genId : function() { @@ -4939,7 +4949,7 @@ __extend__(HTMLDocument.prototype, { else if(tagName.match(/SELECT/)) {node = new HTMLSelectElement(this);} else if(tagName.match(/STYLE/)) {node = new HTMLStyleElement(this);} else if(tagName.match(/TABLE/)) {node = new HTMLTableElement(this);} - else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLSectionElement(this);} + else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLTableSectionElement(this);} else if(tagName.match(/TD|TH/)) {node = new HTMLTableCellElement(this);} else if(tagName.match(/TEXTAREA/)) {node = new HTMLTextAreaElement(this);} else if(tagName.match(/TITLE/)) {node = new HTMLTitleElement(this);} @@ -5089,11 +5099,10 @@ var HTMLElement = function(ownerDocument) { HTMLElement.prototype = new DOMElement; __extend__(HTMLElement.prototype, { get className() { - return this.getAttribute("class")||""; - + return this.getAttribute("class")||''; }, - set className(val) { - return this.setAttribute("class",trim(val)); + set className(value) { + return this.setAttribute("class",trim(value)); }, get dir() { @@ -5105,7 +5114,7 @@ __extend__(HTMLElement.prototype, { }, get id(){ - return this.getAttribute('id')||''; + return this.getAttribute('id'); }, set id(id){ @@ -5135,7 +5144,7 @@ __extend__(HTMLElement.prototype, { doc = null; }, get lang() { - return this.getAttribute("lang")||""; + return this.getAttribute("lang"); }, set lang(val) { @@ -5164,33 +5173,36 @@ __extend__(HTMLElement.prototype, { scrollRight: 0, get style(){ if(this.$css2props === null){ - this.updateCss2Props(); + __updateCss2Props__(this); } return this.$css2props }, - updateCss2Props: function() { - this.$css2props = new CSS2Properties({ - onSet: (function(that) { - return function() { that.__setAttribute("style", this.cssText); } - })(this), - cssText:this.getAttribute("style") - }); - }, - __setAttribute: HTMLElement.prototype.setAttribute, setAttribute: function (name, value) { - this.__setAttribute(name, value); + DOMElement.prototype.setAttribute.apply(this,[name, value]); if (name === "style") { - this.updateCss2Props(); + __updateCss2Props__(this); } }, get title() { - return this.getAttribute("title")||""; + return this.getAttribute("title"); }, - set title(val) { - return this.setAttribute("title",val); + set title(value) { + return this.setAttribute("title", value); }, + get tabIndex(){ + var ti = this.getAttribute('tabindex'); + if(ti!==null) + return Number(ti); + else + return 0; + }, + set tabIndex(value){ + if(value===undefined||value===null) + value = 0; + this.setAttribute('tabindex',Number(value)); + }, //Not in the specs but I'll leave it here for now. get outerHTML(){ return this.xml; @@ -5203,17 +5215,9 @@ __extend__(HTMLElement.prototype, { }, onclick: function(event){ - __eval__(this.getAttribute('onclick')||'', this) + __eval__(this.getAttribute('onclick')||'', this); }, - // non-ECMA function, but no other way for click events to enter env.js - __click__: function(element){ - var event = new Event({ - target:element, - currentTarget:element - }); - event.initEvent("click"); - element.dispatchEvent(event); - }, + ondblclick: function(event){ __eval__(this.getAttribute('ondblclick')||'', this); @@ -5272,6 +5276,10 @@ var __eval__ = function(script, startingNode){ } }; +var __updateCss2Props__ = function(elem){ + elem.$css2props = new CSS2Properties(elem); +}; + var __registerEventAttrs__ = function(elm){ if(elm.hasAttribute('onclick')){ elm.addEventListener('click', elm.onclick ); @@ -5306,6 +5314,15 @@ var __registerEventAttrs__ = function(elm){ return elm; }; +// non-ECMA function, but no other way for click events to enter env.js +var __click__ = function(element){ + var event = new Event({ + target:element, + currentTarget:element + }); + event.initEvent("click"); + element.dispatchEvent(event); +}; var __submit__ = function(element){ var event = new Event({ target:element, @@ -5415,7 +5432,7 @@ var HTMLAnchorElement = function(ownerDocument) { HTMLAnchorElement.prototype = new HTMLElement; __extend__(HTMLAnchorElement.prototype, { get accessKey() { - return this.getAttribute("accesskey") || ""; + return this.getAttribute("accesskey"); }, set accessKey(val) { @@ -5423,7 +5440,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get charset() { - return this.getAttribute("charset") || ""; + return this.getAttribute("charset"); }, set charset(val) { @@ -5431,7 +5448,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get coords() { - return this.getAttribute("coords") || ""; + return this.getAttribute("coords"); }, set coords(val) { @@ -5439,7 +5456,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get href() { - return this.getAttribute("href") || ""; + return this.getAttribute("href"); }, set href(val) { @@ -5447,7 +5464,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get hreflang() { - return this.getAttribute("hreflang") || ""; + return this.getAttribute("hreflang"); }, set hreflang(val) { @@ -5455,7 +5472,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get name() { - return this.getAttribute("name") || ""; + return this.getAttribute("name"); }, set name(val) { @@ -5463,7 +5480,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get rel() { - return this.getAttribute("rel") || ""; + return this.getAttribute("rel"); }, set rel(val) { @@ -5471,7 +5488,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get rev() { - return this.getAttribute("rev") || ""; + return this.getAttribute("rev"); }, set rev(val) { @@ -5479,23 +5496,15 @@ __extend__(HTMLAnchorElement.prototype, { }, get shape() { - return this.getAttribute("shape") || ""; + return this.getAttribute("shape"); }, set shape(val) { return this.setAttribute("shape",val); - }, - get tabIndex() { - return this.getAttribute("tabindex") || ""; - - }, - set tabIndex(val) { - return this.setAttribute("tabindex",val); - }, get target() { - return this.getAttribute("target") || ""; + return this.getAttribute("target"); }, set target(val) { @@ -5503,7 +5512,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get type() { - return this.getAttribute("type") || ""; + return this.getAttribute("type"); }, set type(val) { @@ -5641,12 +5650,12 @@ __extend__(HTMLAreaElement.prototype, { //TODO return 0; }, - get tabIndex(){ + /*get tabIndex(){ return this.getAttribute('tabindex'); }, set tabIndex(value){ this.setAttribute('tabindex',value); - }, + },*/ get target(){ return this.getAttribute('target'); }, @@ -5738,12 +5747,12 @@ __extend__(HTMLButtonElement.prototype, { set accessKey(value){ this.setAttribute('accesskey',value); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',Number(value)); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -5929,7 +5938,7 @@ __extend__(HTMLFormElement.prototype,{ }, get name() { - return this.getAttribute("name") || ""; + return this.getAttribute("name"); }, set name(val) { @@ -5937,7 +5946,7 @@ __extend__(HTMLFormElement.prototype,{ }, get target() { - return this.getAttribute("target") || ""; + return this.getAttribute("target"); }, set target(val) { @@ -6276,12 +6285,12 @@ __extend__(HTMLInputElement.prototype, { set src(value){ this.setAttribute('src', value); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',Number(value)); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -6295,6 +6304,8 @@ __extend__(HTMLInputElement.prototype, { return this.getAttribute('value'); }, set value(value){ + if(this.defaultValue===null&&this.value!==null) + this.defaultValue = this.value; this.setAttribute('value',value); }, blur:function(){ @@ -6575,12 +6586,12 @@ __extend__(HTMLObjectElement.prototype, { set standby(value){ this.setAttribute('standby',value); }, - get tabIndex(){ + /*get tabIndex(){ return this.getAttribute('tabindex'); }, set tabIndex(value){ this.setAttribute('tabindex',value); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -6681,6 +6692,8 @@ __extend__(HTMLOptionElement.prototype, { return (this.getAttribute('selected')=='selected'); }, set selected(value){ + if(this.defaultSelected===null&&this.selected!==null) + this.defaultSelected = this.selected; this.setAttribute('selected', (value ? 'selected' :'')); }, get value(){ @@ -6756,6 +6769,10 @@ __extend__(HTMLScriptElement.prototype, { return this.nodeValue; }, + set text(value){ + this.nodeValue = value; + $env.loadInlineScript(this); + }, get htmlFor(){ return this.getAttribute('for'); }, @@ -6884,12 +6901,12 @@ __extend__(HTMLSelectElement.prototype, { set size(value){ this.setAttribute('size',value); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',value); - }, + },*/ add : function(){ __add__(this); }, @@ -7005,24 +7022,29 @@ __extend__(HTMLTableElement.prototype, { }, appendChild : function (child) { - - var tagName = child.tagName.toLowerCase(); - if (tagName === "tr") { - // need an implcit to contain this... - if (!this.currentBody) { - this.currentBody = document.createElement("tbody"); - - DOMNode.prototype.appendChild.apply(this, [this.currentBody]); + + var tagName; + if(child.tagName){ + tagName = child.tagName.toLowerCase(); + if (tagName === "tr") { + // need an implcit to contain this... + if (!this.currentBody) { + this.currentBody = document.createElement("tbody"); + + DOMNode.prototype.appendChild.apply(this, [this.currentBody]); + } + + return this.currentBody.appendChild(child); + + } else if (tagName === "tbody" || tagName === "tfoot" && this.currentBody) { + this.currentBody = child; + return DOMNode.prototype.appendChild.apply(this, arguments); + + } else { + return DOMNode.prototype.appendChild.apply(this, arguments); } - - return this.currentBody.appendChild(child); - - } else if (tagName === "tbody" || tagName === "tfoot" && this.currentBody) { - this.currentBody = child; - return DOMNode.prototype.appendChild.apply(this, arguments); - - } else { - return DOMNode.prototype.appendChild.apply(this, arguments); + }else{ + $error('HTMLTableElement.appendChild => child.tagName should not be undefined here... Fix ME!'); } }, @@ -7299,6 +7321,12 @@ __extend__(HTMLTextAreaElement.prototype, { set disabled(value){ this.setAttribute('disabled', (value ? 'disabled' :'')); }, + get maxLength(){ + return Number(this.getAttribute('maxlength')||'0'); + }, + set maxLength(value){ + this.setAttribute('maxlength', value); + }, get name(){ return this.getAttribute('name')||''; }, @@ -7311,12 +7339,12 @@ __extend__(HTMLTextAreaElement.prototype, { set readOnly(value){ this.setAttribute('readonly', (value ? 'readonly' :'')); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',Number(value)); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -7324,10 +7352,12 @@ __extend__(HTMLTextAreaElement.prototype, { this.setAttribute('type',value); }, get value(){ - return this.getAttribute('value'); + return this.text; }, set value(value){ - this.setAttribute('value',value); + if(this.defaultValue===null&&this.text!==null) + this.defaultValue = this.text; + return this.text = value; }, blur:function(){ __blur__(this); @@ -7672,45 +7702,53 @@ var $onblur, $onresize;/* * CSS2Properties - DOM Level 2 CSS */ -var CSS2Properties = function(options){ - __extend__(this, __supportedStyles__); - this.onSetCallback = options.onSet?options.onSet:(function(){}); - this.styleIndices = {}; - __cssTextToStyles__(this, options.cssText?options.cssText:""); +var CSS2Properties = function(element){ + //this.onSetCallback = options.onSet?options.onSet:(function(){}); + this.styleIndex = __supportedStyles__(); + this.nameMap = {}; + this.__previous__ = {}; + this.__element__ = element + __cssTextToStyles__(this, element.getAttribute('style')||''); }; __extend__(CSS2Properties.prototype, { get cssText(){ - return Array.prototype.join.apply(this,[';\n']); + var css = ''; + for(var i=0;i0){ @@ -7718,1067 +7756,218 @@ __extend__(CSS2Properties.prototype, { }else{ return ''; } - }, - onSet:function(camelCaseName, value){ - var dashedName = __toDashed__(camelCaseName); - var definition = dashedName + ": " + value; - if (this.styleIndices[camelCaseName] !== undefined) - this[this.styleIndices[camelCaseName]] = definition; - else { - Array.prototype.push.apply(this, [definition]); - this.styleIndices[camelCaseName] = this.length - 1; - } - this.onSetCallback(); - }, + } }); +var __parseStyle__ = function(css2prop, name, value){ + css2prop.styleIndex[name] = value; + var definition = __toDashed__(name); + if(css2prop.length===undefined){ + Array.prototype.push.apply(css2prop, [definition]); + css2prop.nameMap[definition] = 0; + }else{ + if(definition in css2prop.nameMap){ + css2prop[css2prop.nameMap[definition]] = definition; + }else{ + Array.prototype.push.apply(css2prop, [definition]); + css2prop.nameMap[definition] = css2prop.length; + } + } +}; + + var __cssTextToStyles__ = function(css2props, cssText){ - var styleArray=[]; + //var styleArray=[]; var style, name, value, camelCaseName, w3cName, styles = cssText.split(';'); - css2props.styleIndices = {}; for ( var i = 0; i < styles.length; i++ ) { //$log("Adding style property " + styles[i]); style = styles[i].split(':'); + //$log(" style " + style[0]); if ( style.length == 2 ){ - //keep a reference to the original name of the style which was set - //this is the w3c style setting method. - var idx = styleArray.length; - styleArray[idx] = w3cName = styles[i]; - //camel case for dash case - value = trim(style[1]); - camelCaseName = trim(__toCamelCase__(style[0])); - css2props.styleIndices[camelCaseName] = idx; - $debug('CSS Style Name: ' + camelCaseName); - if(css2props["_" + camelCaseName]!==undefined){ - //set the value internally with camelcase name - $debug('Setting css ' + camelCaseName + ' to ' + value); - css2props["_" + camelCaseName] = value; - }; + //$log(" value " + style[1]); + __parseStyle__(css2props, style[0].replace(" ",'','g'), style[1].replace(" ",'','g')); } } - __setArray__(css2props, styleArray); }; var __toCamelCase__ = function(name) { - return name.replace(/\-(\w)/g, function(all, letter){ - return letter.toUpperCase(); - }); + //$info('__toCamelCase__'+name); + if(name){ + return name.replace(/\-(\w)/g, function(all, letter){ + return letter.toUpperCase(); + }); + } + return name; }; var __toDashed__ = function(camelCaseName) { - return camelCaseName.replace(/[A-Z]/g, function(all) { - return "-" + all.toLowerCase(); - }); + //$info("__toDashed__"+camelCaseName); + if(camelCaseName){ + return camelCaseName.replace(/[A-Z]/g, function(all) { + return "-" + all.toLowerCase(); + }); + } + return camelCaseName; }; //Obviously these arent all supported but by commenting out various sections //this provides a single location to configure what is exposed as supported. -//These getters/setters will need to get fine-tuned in the future to deal with -//the variation on input formulations -var __supportedStyles__ = (function(){ - return{ - _azimuth: "", - get azimuth() { - return this._azimuth; - }, - set azimuth(val) { - this._azimuth = val; - this.onSet("azimuth", val); - }, - _background: "", - get background() { - return this._background; - }, - set background(val) { - this._background = val; - this.onSet("background", val); - }, - _backgroundAttachment: "", - get backgroundAttachment() { - return this._backgroundAttachment; - }, - set backgroundAttachment(val) { - this._backgroundAttachment = val; - this.onSet("backgroundAttachment", val); - }, - _backgroundColor: "", - get backgroundColor() { - return this._backgroundColor; - }, - set backgroundColor(val) { - this._backgroundColor = val; - this.onSet("backgroundColor", val); - }, - _backgroundImage: "", - get backgroundImage() { - return this._backgroundImage; - }, - set backgroundImage(val) { - this._backgroundImage = val; - this.onSet("backgroundImage", val); - }, - _backgroundPosition: "", - get backgroundPosition() { - return this._backgroundPosition; - }, - set backgroundPosition(val) { - this._backgroundPosition = val; - this.onSet("backgroundPosition", val); - }, - _backgroundRepeat: "", - get backgroundRepeat() { - return this._backgroundRepeat; - }, - set backgroundRepeat(val) { - this._backgroundRepeat = val; - this.onSet("backgroundRepeat", val); - }, - _border: "", - get border() { - return this._border; - }, - set border(val) { - this._border = val; - this.onSet("border", val); - }, - _borderBottom: "", - get borderBottom() { - return this._borderBottom; - }, - set borderBottom(val) { - this._borderBottom = val; - this.onSet("borderBottom", val); - }, - _borderBottomColor: "", - get borderBottomColor() { - return this._borderBottomColor; - }, - set borderBottomColor(val) { - this._borderBottomColor = val; - this.onSet("borderBottomColor", val); - }, - _borderBottomStyle: "", - get borderBottomStyle() { - return this._borderBottomStyle; - }, - set borderBottomStyle(val) { - this._borderBottomStyle = val; - this.onSet("borderBottomStyle", val); - }, - _borderBottomWidth: "", - get borderBottomWidth() { - return this._borderBottomWidth; - }, - set borderBottomWidth(val) { - this._borderBottomWidth = val; - this.onSet("borderBottomWidth", val); - }, - _borderCollapse: "", - get borderCollapse() { - return this._borderCollapse; - }, - set borderCollapse(val) { - this._borderCollapse = val; - this.onSet("borderCollapse", val); - }, - _borderColor: "", - get borderColor() { - return this._borderColor; - }, - set borderColor(val) { - this._borderColor = val; - this.onSet("borderColor", val); - }, - _borderLeft: "", - get borderLeft() { - return this._borderLeft; - }, - set borderLeft(val) { - this._borderLeft = val; - this.onSet("borderLeft", val); - }, - _borderLeftColor: "", - get borderLeftColor() { - return this._borderLeftColor; - }, - set borderLeftColor(val) { - this._borderLeftColor = val; - this.onSet("borderLeftColor", val); - }, - _borderLeftStyle: "", - get borderLeftStyle() { - return this._borderLeftStyle; - }, - set borderLeftStyle(val) { - this._borderLeftStyle = val; - this.onSet("borderLeftStyle", val); - }, - _borderLeftWidth: "", - get borderLeftWidth() { - return this._borderLeftWidth; - }, - set borderLeftWidth(val) { - this._borderLeftWidth = val; - this.onSet("borderLeftWidth", val); - }, - _borderRight: "", - get borderRight() { - return this._borderRight; - }, - set borderRight(val) { - this._borderRight = val; - this.onSet("borderRight", val); - }, - _borderRightColor: "", - get borderRightColor() { - return this._borderRightColor; - }, - set borderRightColor(val) { - this._borderRightColor = val; - this.onSet("borderRightColor", val); - }, - _borderRightStyle: "", - get borderRightStyle() { - return this._borderRightStyle; - }, - set borderRightStyle(val) { - this._borderRightStyle = val; - this.onSet("borderRightStyle", val); - }, - _borderRightWidth: "", - get borderRightWidth() { - return this._borderRightWidth; - }, - set borderRightWidth(val) { - this._borderRightWidth = val; - this.onSet("borderRightWidth", val); - }, - _borderSpacing: "", - get borderSpacing() { - return this._borderSpacing; - }, - set borderSpacing(val) { - this._borderSpacing = val; - this.onSet("borderSpacing", val); - }, - _borderStyle: "", - get borderStyle() { - return this._borderStyle; - }, - set borderStyle(val) { - this._borderStyle = val; - this.onSet("borderStyle", val); - }, - _borderTop: "", - get borderTop() { - return this._borderTop; - }, - set borderTop(val) { - this._borderTop = val; - this.onSet("borderTop", val); - }, - _borderTopColor: "", - get borderTopColor() { - return this._borderTopColor; - }, - set borderTopColor(val) { - this._borderTopColor = val; - this.onSet("borderTopColor", val); - }, - _borderTopStyle: "", - get borderTopStyle() { - return this._borderTopStyle; - }, - set borderTopStyle(val) { - this._borderTopStyle = val; - this.onSet("borderTopStyle", val); - }, - _borderTopWidth: "", - get borderTopWidth() { - return this._borderTopWidth; - }, - set borderTopWidth(val) { - this._borderTopWidth = val; - this.onSet("borderTopWidth", val); - }, - _borderWidth: "", - get borderWidth() { - return this._borderWidth; - }, - set borderWidth(val) { - this._borderWidth = val; - this.onSet("borderWidth", val); - }, - _bottom: "", - get bottom() { - return this._bottom; - }, - set bottom(val) { - this._bottom = val; - this.onSet("bottom", val); - }, - _captionSide: "", - get captionSide() { - return this._captionSide; - }, - set captionSide(val) { - this._captionSide = val; - this.onSet("captionSide", val); - }, - _clear: "", - get clear() { - return this._clear; - }, - set clear(val) { - this._clear = val; - this.onSet("clear", val); - }, - _clip: "", - get clip() { - return this._clip; - }, - set clip(val) { - this._clip = val; - this.onSet("clip", val); - }, - _color: "", - get color() { - return this._color; - }, - set color(val) { - this._color = val; - this.onSet("color", val); - }, - _content: "", - get content() { - return this._content; - }, - set content(val) { - this._content = val; - this.onSet("content", val); - }, - _counterIncrement: "", - get counterIncrement() { - return this._counterIncrement; - }, - set counterIncrement(val) { - this._counterIncrement = val; - this.onSet("counterIncrement", val); - }, - _counterReset: "", - get counterReset() { - return this._counterReset; - }, - set counterReset(val) { - this._counterReset = val; - this.onSet("counterReset", val); - }, - _cssFloat: "", - get cssFloat() { - return this._cssFloat; - }, - set cssFloat(val) { - this._cssFloat = val; - this.onSet("cssFloat", val); - }, - _cue: "", - get cue() { - return this._cue; - }, - set cue(val) { - this._cue = val; - this.onSet("cue", val); - }, - _cueAfter: "", - get cueAfter() { - return this._cueAfter; - }, - set cueAfter(val) { - this._cueAfter = val; - this.onSet("cueAfter", val); - }, - _cueBefore: "", - get cueBefore() { - return this._cueBefore; - }, - set cueBefore(val) { - this._cueBefore = val; - this.onSet("cueBefore", val); - }, - _cursor: "", - get cursor() { - return this._cursor; - }, - set cursor(val) { - this._cursor = val; - this.onSet("cursor", val); - }, - _direction: "", - get direction() { - return this._direction; - }, - set direction(val) { - this._direction = val; - this.onSet("direction", val); - }, - _display: "", - get display() { - return this._display; - }, - set display(val) { - this._display = val; - this.onSet("display", val); - }, - _elevation: "", - get elevation() { - return this._elevation; - }, - set elevation(val) { - this._elevation = val; - this.onSet("elevation", val); - }, - _emptyCells: "", - get emptyCells() { - return this._emptyCells; - }, - set emptyCells(val) { - this._emptyCells = val; - this.onSet("emptyCells", val); - }, - _font: "", - get font() { - return this._font; - }, - set font(val) { - this._font = val; - this.onSet("font", val); - }, - _fontFamily: "", - get fontFamily() { - return this._fontFamily; - }, - set fontFamily(val) { - this._fontFamily = val; - this.onSet("fontFamily", val); - }, - _fontSize: "", - get fontSize() { - return this._fontSize; - }, - set fontSize(val) { - this._fontSize = val; - this.onSet("fontSize", val); - }, - _fontSizeAdjust: "", - get fontSizeAdjust() { - return this._fontSizeAdjust; - }, - set fontSizeAdjust(val) { - this._fontSizeAdjust = val; - this.onSet("fontSizeAdjust", val); - }, - _fontStretch: "", - get fontStretch() { - return this._fontStretch; - }, - set fontStretch(val) { - this._fontStretch = val; - this.onSet("fontStretch", val); - }, - _fontStyle: "", - get fontStyle() { - return this._fontStyle; - }, - set fontStyle(val) { - this._fontStyle = val; - this.onSet("fontStyle", val); - }, - _fontVariant: "", - get fontVariant() { - return this._fontVariant; - }, - set fontVariant(val) { - this._fontVariant = val; - this.onSet("fontVariant", val); - }, - _fontWeight: "", - get fontWeight() { - return this._fontWeight; - }, - set fontWeight(val) { - this._fontWeight = val; - this.onSet("fontWeight", val); - }, - _height: "", - get height() { - return this._height; - }, - set height(val) { - this._height = val; - this.onSet("height", val); - }, - _left: "", - get left() { - return this._left; - }, - set left(val) { - this._left = val; - this.onSet("left", val); - }, - _letterSpacing: "", - get letterSpacing() { - return this._letterSpacing; - }, - set letterSpacing(val) { - this._letterSpacing = val; - this.onSet("letterSpacing", val); - }, - _lineHeight: "", - get lineHeight() { - return this._lineHeight; - }, - set lineHeight(val) { - this._lineHeight = val; - this.onSet("lineHeight", val); - }, - _listStyle: "", - get listStyle() { - return this._listStyle; - }, - set listStyle(val) { - this._listStyle = val; - this.onSet("listStyle", val); - }, - _listStyleImage: "", - get listStyleImage() { - return this._listStyleImage; - }, - set listStyleImage(val) { - this._listStyleImage = val; - this.onSet("listStyleImage", val); - }, - _listStylePosition: "", - get listStylePosition() { - return this._listStylePosition; - }, - set listStylePosition(val) { - this._listStylePosition = val; - this.onSet("listStylePosition", val); - }, - _listStyleType: "", - get listStyleType() { - return this._listStyleType; - }, - set listStyleType(val) { - this._listStyleType = val; - this.onSet("listStyleType", val); - }, - _margin: "", - get margin() { - return this._margin; - }, - set margin(val) { - this._margin = val; - this.onSet("margin", val); - }, - _marginBottom: "", - get marginBottom() { - return this._marginBottom; - }, - set marginBottom(val) { - this._marginBottom = val; - this.onSet("marginBottom", val); - }, - _marginLeft: "", - get marginLeft() { - return this._marginLeft; - }, - set marginLeft(val) { - this._marginLeft = val; - this.onSet("marginLeft", val); - }, - _marginRight: "", - get marginRight() { - return this._marginRight; - }, - set marginRight(val) { - this._marginRight = val; - this.onSet("marginRight", val); - }, - _marginTop: "", - get marginTop() { - return this._marginTop; - }, - set marginTop(val) { - this._marginTop = val; - this.onSet("marginTop", val); - }, - _markerOffset: "", - get markerOffset() { - return this._markerOffset; - }, - set markerOffset(val) { - this._markerOffset = val; - this.onSet("markerOffset", val); - }, - _marks: "", - get marks() { - return this._marks; - }, - set marks(val) { - this._marks = val; - this.onSet("marks", val); - }, - _maxHeight: "", - get maxHeight() { - return this._maxHeight; - }, - set maxHeight(val) { - this._maxHeight = val; - this.onSet("maxHeight", val); - }, - _maxWidth: "", - get maxWidth() { - return this._maxWidth; - }, - set maxWidth(val) { - this._maxWidth = val; - this.onSet("maxWidth", val); - }, - _minHeight: "", - get minHeight() { - return this._minHeight; - }, - set minHeight(val) { - this._minHeight = val; - this.onSet("minHeight", val); - }, - _minWidth: "", - get minWidth() { - return this._minWidth; - }, - set minWidth(val) { - this._minWidth = val; - this.onSet("minWidth", val); - }, - _opacity: 1, - get opacity() { - return this._opacity; - }, - set opacity(val) { - this._opacity = val; - this.onSet("opacity", val); - }, - _orphans: "", - get orphans() { - return this._orphans; - }, - set orphans(val) { - this._orphans = val; - this.onSet("orphans", val); - }, - _outline: "", - get outline() { - return this._outline; - }, - set outline(val) { - this._outline = val; - this.onSet("outline", val); - }, - _outlineColor: "", - get outlineColor() { - return this._outlineColor; - }, - set outlineColor(val) { - this._outlineColor = val; - this.onSet("outlineColor", val); - }, - _outlineOffset: "", - get outlineOffset() { - return this._outlineOffset; - }, - set outlineOffset(val) { - this._outlineOffset = val; - this.onSet("outlineOffset", val); - }, - _outlineStyle: "", - get outlineStyle() { - return this._outlineStyle; - }, - set outlineStyle(val) { - this._outlineStyle = val; - this.onSet("outlineStyle", val); - }, - _outlineWidth: "", - get outlineWidth() { - return this._outlineWidth; - }, - set outlineWidth(val) { - this._outlineWidth = val; - this.onSet("outlineWidth", val); - }, - _overflow: "", - get overflow() { - return this._overflow; - }, - set overflow(val) { - this._overflow = val; - this.onSet("overflow", val); - }, - _overflowX: "", - get overflowX() { - return this._overflowX; - }, - set overflowX(val) { - this._overflowX = val; - this.onSet("overflowX", val); - }, - _overflowY: "", - get overflowY() { - return this._overflowY; - }, - set overflowY(val) { - this._overflowY = val; - this.onSet("overflowY", val); - }, - _padding: "", - get padding() { - return this._padding; - }, - set padding(val) { - this._padding = val; - this.onSet("padding", val); - }, - _paddingBottom: "", - get paddingBottom() { - return this._paddingBottom; - }, - set paddingBottom(val) { - this._paddingBottom = val; - this.onSet("paddingBottom", val); - }, - _paddingLeft: "", - get paddingLeft() { - return this._paddingLeft; - }, - set paddingLeft(val) { - this._paddingLeft = val; - this.onSet("paddingLeft", val); - }, - _paddingRight: "", - get paddingRight() { - return this._paddingRight; - }, - set paddingRight(val) { - this._paddingRight = val; - this.onSet("paddingRight", val); - }, - _paddingTop: "", - get paddingTop() { - return this._paddingTop; - }, - set paddingTop(val) { - this._paddingTop = val; - this.onSet("paddingTop", val); - }, - _page: "", - get page() { - return this._page; - }, - set page(val) { - this._page = val; - this.onSet("page", val); - }, - _pageBreakAfter: "", - get pageBreakAfter() { - return this._pageBreakAfter; - }, - set pageBreakAfter(val) { - this._pageBreakAfter = val; - this.onSet("pageBreakAfter", val); - }, - _pageBreakBefore: "", - get pageBreakBefore() { - return this._pageBreakBefore; - }, - set pageBreakBefore(val) { - this._pageBreakBefore = val; - this.onSet("pageBreakBefore", val); - }, - _pageBreakInside: "", - get pageBreakInside() { - return this._pageBreakInside; - }, - set pageBreakInside(val) { - this._pageBreakInside = val; - this.onSet("pageBreakInside", val); - }, - _pause: "", - get pause() { - return this._pause; - }, - set pause(val) { - this._pause = val; - this.onSet("pause", val); - }, - _pauseAfter: "", - get pauseAfter() { - return this._pauseAfter; - }, - set pauseAfter(val) { - this._pauseAfter = val; - this.onSet("pauseAfter", val); - }, - _pauseBefore: "", - get pauseBefore() { - return this._pauseBefore; - }, - set pauseBefore(val) { - this._pauseBefore = val; - this.onSet("pauseBefore", val); - }, - _pitch: "", - get pitch() { - return this._pitch; - }, - set pitch(val) { - this._pitch = val; - this.onSet("pitch", val); - }, - _pitchRange: "", - get pitchRange() { - return this._pitchRange; - }, - set pitchRange(val) { - this._pitchRange = val; - this.onSet("pitchRange", val); - }, - _position: "", - get position() { - return this._position; - }, - set position(val) { - this._position = val; - this.onSet("position", val); - }, - _quotes: "", - get quotes() { - return this._quotes; - }, - set quotes(val) { - this._quotes = val; - this.onSet("quotes", val); - }, - _richness: "", - get richness() { - return this._richness; - }, - set richness(val) { - this._richness = val; - this.onSet("richness", val); - }, - _right: "", - get right() { - return this._right; - }, - set right(val) { - this._right = val; - this.onSet("right", val); - }, - _size: "", - get size() { - return this._size; - }, - set size(val) { - this._size = val; - this.onSet("size", val); - }, - _speak: "", - get speak() { - return this._speak; - }, - set speak(val) { - this._speak = val; - this.onSet("speak", val); - }, - _speakHeader: "", - get speakHeader() { - return this._speakHeader; - }, - set speakHeader(val) { - this._speakHeader = val; - this.onSet("speakHeader", val); - }, - _speakNumeral: "", - get speakNumeral() { - return this._speakNumeral; - }, - set speakNumeral(val) { - this._speakNumeral = val; - this.onSet("speakNumeral", val); - }, - _speakPunctuation: "", - get speakPunctuation() { - return this._speakPunctuation; - }, - set speakPunctuation(val) { - this._speakPunctuation = val; - this.onSet("speakPunctuation", val); - }, - _speechRate: "", - get speechRate() { - return this._speechRate; - }, - set speechRate(val) { - this._speechRate = val; - this.onSet("speechRate", val); - }, - _stress: "", - get stress() { - return this._stress; - }, - set stress(val) { - this._stress = val; - this.onSet("stress", val); - }, - _tableLayout: "", - get tableLayout() { - return this._tableLayout; - }, - set tableLayout(val) { - this._tableLayout = val; - this.onSet("tableLayout", val); - }, - _textAlign: "", - get textAlign() { - return this._textAlign; - }, - set textAlign(val) { - this._textAlign = val; - this.onSet("textAlign", val); - }, - _textDecoration: "", - get textDecoration() { - return this._textDecoration; - }, - set textDecoration(val) { - this._textDecoration = val; - this.onSet("textDecoration", val); - }, - _textIndent: "", - get textIndent() { - return this._textIndent; - }, - set textIndent(val) { - this._textIndent = val; - this.onSet("textIndent", val); - }, - _textShadow: "", - get textShadow() { - return this._textShadow; - }, - set textShadow(val) { - this._textShadow = val; - this.onSet("textShadow", val); - }, - _textTransform: "", - get textTransform() { - return this._textTransform; - }, - set textTransform(val) { - this._textTransform = val; - this.onSet("textTransform", val); - }, - _top: "", - get top() { - return this._top; - }, - set top(val) { - this._top = val; - this.onSet("top", val); - }, - _unicodeBidi: "", - get unicodeBidi() { - return this._unicodeBidi; - }, - set unicodeBidi(val) { - this._unicodeBidi = val; - this.onSet("unicodeBidi", val); - }, - _verticalAlign: "", - get verticalAlign() { - return this._verticalAlign; - }, - set verticalAlign(val) { - this._verticalAlign = val; - this.onSet("verticalAlign", val); - }, - _visibility: "", - get visibility() { - return this._visibility; - }, - set visibility(val) { - this._visibility = val; - this.onSet("visibility", val); - }, - _voiceFamily: "", - get voiceFamily() { - return this._voiceFamily; - }, - set voiceFamily(val) { - this._voiceFamily = val; - this.onSet("voiceFamily", val); - }, - _volume: "", - get volume() { - return this._volume; - }, - set volume(val) { - this._volume = val; - this.onSet("volume", val); - }, - _whiteSpace: "", - get whiteSpace() { - return this._whiteSpace; - }, - set whiteSpace(val) { - this._whiteSpace = val; - this.onSet("whiteSpace", val); - }, - _widows: "", - get widows() { - return this._widows; - }, - set widows(val) { - this._widows = val; - this.onSet("widows", val); - }, - _width: "", - get width() { - return this._width; - }, - set width(val) { - this._width = val; - this.onSet("width", val); - }, - _wordSpacing: "", - get wordSpacing() { - return this._wordSpacing; - }, - set wordSpacing(val) { - this._wordSpacing = val; - this.onSet("wordSpacing", val); - }, - _zIndex: "", - get zIndex() { - return this._zIndex; - }, - set zIndex(val) { - this._zIndex = val; - this.onSet("zIndex", val); - } - }; -})() +var __supportedStyles__ = function(){ + return { + azimuth: null, + background: null, + backgroundAttachment: null, + backgroundColor: null, + backgroundImage: null, + backgroundPosition: null, + backgroundRepeat: null, + border: null, + borderBottom: null, + borderBottomColor: null, + borderBottomStyle: null, + borderBottomWidth: null, + borderCollapse: null, + borderColor: null, + borderLeft: null, + borderLeftColor: null, + borderLeftStyle: null, + borderLeftWidth: null, + borderRight: null, + borderRightColor: null, + borderRightStyle: null, + borderRightWidth: null, + borderSpacing: null, + borderStyle: null, + borderTop: null, + borderTopColor: null, + borderTopStyle: null, + borderTopWidth: null, + borderWidth: null, + bottom: null, + captionSide: null, + clear: null, + clip: null, + color: null, + content: null, + counterIncrement: null, + counterReset: null, + cssFloat: null, + cue: null, + cueAfter: null, + cueBefore: null, + cursor: null, + direction: 'ltr', + display: 'block', + elevation: null, + emptyCells: null, + font: null, + fontFamily: null, + fontSize: "1em", + fontSizeAdjust: null, + fontStretch: null, + fontStyle: null, + fontVariant: null, + fontWeight: null, + height: '1px', + left: null, + letterSpacing: null, + lineHeight: null, + listStyle: null, + listStyleImage: null, + listStylePosition: null, + listStyleType: null, + margin: null, + marginBottom: "0px", + marginLeft: "0px", + marginRight: "0px", + marginTop: "0px", + markerOffset: null, + marks: null, + maxHeight: null, + maxWidth: null, + minHeight: null, + minWidth: null, + opacity: 1, + orphans: null, + outline: null, + outlineColor: null, + outlineOffset: null, + outlineStyle: null, + outlineWidth: null, + overflow: null, + overflowX: null, + overflowY: null, + padding: null, + paddingBottom: "0px", + paddingLeft: "0px", + paddingRight: "0px", + paddingTop: "0px", + page: null, + pageBreakAfter: null, + pageBreakBefore: null, + pageBreakInside: null, + pause: null, + pauseAfter: null, + pauseBefore: null, + pitch: null, + pitchRange: null, + position: null, + quotes: null, + richness: null, + right: null, + size: null, + speak: null, + speakHeader: null, + speakNumeral: null, + speakPunctuation: null, + speechRate: null, + stress: null, + tableLayout: null, + textAlign: null, + textDecoration: null, + textIndent: null, + textShadow: null, + textTransform: null, + top: null, + unicodeBidi: null, + verticalAlign: null, + visibility: null, + voiceFamily: null, + volume: null, + whiteSpace: null, + widows: null, + width: '1px', + wordSpacing: null, + zIndex: 1 + }; +}; + + +for(var style in __supportedStyles__()){ + (function(name){ + if(name === 'width' || name === 'height'){ + CSS2Properties.prototype.__defineGetter__(name, function(){ + if(this.getPropertyValue('display')==='none'){ + return '0px'; + } + //$info(name+' = '+this.getPropertyValue(name)); + return this.getPropertyValue(name); + }); + CSS2Properties.prototype.__defineSetter__(name, function(value){ + this.setProperty(name, value); + }); + }else{ + CSS2Properties.prototype.__defineGetter__(name, function(){ + //$log(" css2properties.get " + name); + return this.getPropertyValue(name); + }); + CSS2Properties.prototype.__defineSetter__(name, function(value){ + this.setProperty(name, value); + }); + } + })(style); +}; + $w.CSS2Properties = CSS2Properties;/* * CSSRule - DOM Level 2 @@ -9069,33 +8258,11 @@ $debug("Initializing Window Timer."); var $timers = []; window.setTimeout = function(fn, time){ - var num = $timers.length; - var tfn; - - if (typeof fn == 'string') { - tfn = function() { - eval(fn); - window.clearInterval(num); - }; - } else { - tfn = function() { - fn(); - window.clearInterval(num); - }; - } - - if (time === 0){ - if (typeof fn == 'string') - eval(fn); - else - fn(); - } - else { - $debug("Creating timer number "+num); - $timers[num] = new $env.timer(tfn, time); - $timers[num].start(); - return num; - } + var num; + return num = window.setInterval(function(){ + fn(); + window.clearInterval(num); + }, time); }; window.setInterval = function(fn, time){ @@ -9110,7 +8277,7 @@ window.setInterval = function(fn, time){ if(time===0){ fn(); }else{ - $debug("Creating timer number "+num); + //$debug("Creating timer number "+num); $timers[num] = new $env.timer(fn, time); $timers[num].start(); } @@ -9118,15 +8285,14 @@ window.setInterval = function(fn, time){ }; window.clearInterval = window.clearTimeout = function(num){ + //$log("clearing interval "+num); if ( $timers[num] ) { - $debug("Deleting timer number "+num); $timers[num].stop(); delete $timers[num]; } }; - -window.$wait = function(wait){ $env.wait(wait); }/* + /* * event.js */ // Window Events @@ -9137,7 +8303,7 @@ var $events = [], $onunload; $w.addEventListener = function(type, fn){ - //$log("adding event listener " + type); + $debug("adding event listener \n\t" + type +" \n\tfor "+this+" with callback \n\t"+fn); if ( !this.uuid ) { this.uuid = $events.length; $events[this.uuid] = {}; @@ -9174,25 +8340,29 @@ $w.dispatchEvent = function(event, bubbles){ bubbles = true; if (!event.target) { + $debug("no event target : "+event.target); event.target = this; } $debug("event target: " + event.target); - if ( event.type ) { + if ( event.type && this.nodeType || this===window) { + $debug("nodeType: " + this.nodeType); if ( this.uuid && $events[this.uuid][event.type] ) { var _this = this; $events[this.uuid][event.type].forEach(function(fn){ $debug('calling event handler '+fn+' on target '+_this); - fn.call( _this, event ); + fn( event ); }); } if (this["on" + event.type]) { - $debug('calling event handler '+event.type+' on target '+this); - this["on" + event.type].call(this, event); + $debug('calling event handler on'+event.type+' on target '+this); + this["on" + event.type](event); } + }else{ + $debug("non target: " + event.target + " \n this->"+this); } if (bubbles && this.parentNode){ - this.parentNode.dispatchEvent.call(this.parentNode,event); + this.parentNode.dispatchEvent(event); } }; @@ -9268,10 +8438,21 @@ XMLHttpRequest.prototype = { $debug("parsing response text into xml document"); responseXML = $domparser.parseFromString(_this.responseText+""); return responseXML; - } catch(e) { return null;/*TODO: need to flag an error here*/} + } catch(e) { + $error('response XML does not apear to be well formed xml', e); + responseXML = $domparser.parseFromString(""+ + "

parse error

"); + return responseXML; + } } - }else{return null;} + }else{ + $env.warn('response XML does not apear to be xml'); + return null; + } }); + _this.__defineSetter__("responseXML",function(xml){ + responseXML = xml; + }); }, data); _this.onreadystatechange(); } @@ -9324,6 +8505,7 @@ $debug("Initializing Window CSS"); // attributes and values used to render the specified element in this // window. Any length values are always expressed in pixel, or // absolute values. + $w.getComputedStyle = function(elt, pseudo_elt){ //TODO //this is a naive implementation diff --git a/dist/env.rhino.js b/dist/env.rhino.js index eebd340b..1e6f6485 100644 --- a/dist/env.rhino.js +++ b/dist/env.rhino.js @@ -1,5 +1,5 @@ /* - * Envjs env-js.1.0.rc1 + * Envjs env-js.1.0.rc2 * Pure JavaScript Browser Environment * By John Resig * Copyright 2008-2009 John Resig, under the MIT License @@ -109,6 +109,7 @@ var Envjs = function(){ "text/envjs" :true }; + $env.onScriptLoadError = function(){}; $env.loadLocalScript = function(script, parser){ $env.debug("loading script "); var types, type, src, i, base, @@ -156,6 +157,7 @@ var Envjs = function(){ } }catch(e){ $env.error("Error loading script.", e); + $env.onScriptLoadError(script); }finally{ if(parser){ parser.appendFragment(docWrites.join('')); @@ -279,63 +281,39 @@ var Envjs = function(){ var timers = []; - $env.timer = function(fn, interval){ - this.fn = fn; - this.interval = interval; - this.at = Date.now() + interval; - this.index = timers.length; - timers[this.index] = this; - }; - - $env.timer.prototype.start = function(){}; - $env.timer.prototype.stop = function(){ - delete timers[this.index]; - }; - - // wait === null: execute any immediately runnable timers and return - // wait(n) (n > 0): execute any timers as they fire but no longer than n ms - // wait(0): execute any timers as they fire, waiting until there are none left - $env.wait = function(wait) { - var i; - var empty; - var after; - var now; - var timer; - var sleep; - if (wait !== 0 && wait !== null && wait !== undefined){ - wait += Date.now(); - } - for (;;) { - for (i in timers){ - timer = timers[i]; - now = Date.now(); - if (timer.at <= now){ - f = timer.fn; - f(); - timer.at += timer.interval; - } - } - empty = true; - sleep = null; - now = Date.now(); - for (i in timers){ - empty = false; - timer = timers[i]; - after = timer.at - now - sleep = (sleep === null || after < sleep) ? after : sleep; - } - sleep = sleep < 0 ? 0 : sleep; - if (empty || - ( wait !== 0 ) && - ( ( sleep > 0 && !wait ) || ( Date.now() + sleep > wait ) ) ) { - break; - } - if (sleep) { - java.lang.Thread.currentThread().sleep(sleep); - } - } + //For Java the window.timer is created using the java.lang.Thread in combination + //with the java.lang.Runnable + $env.timer = function(fn, time){ + var running = true; + + var run = sync(function(){ //while happening only thing in this timer + //$env.debug("running timed function"); + fn(); + }); + var _this = this; + var thread = new java.lang.Thread(new java.lang.Runnable({ + run: function(){ + try { + while (running){ + java.lang.Thread.currentThread().sleep(time); + run.apply(_this); + } + }catch(e){ + $env.error("erro running timed function", e); + _this.stop(); + $env.onInterrupt(); + }; + } + })); + this.start = function(){ + thread.start(); + }; + this.stop = sync(function(num){ + running = false; + thread.interrupt(); + }) }; - + //Since we're running in rhino I guess we can safely assume //java is 'enabled'. I'm sure this requires more thought //than I've given it here @@ -344,11 +322,27 @@ var Envjs = function(){ //Used in the XMLHttpRquest implementation to run a // request in a seperate thread + $env.onInterrupt = function(){}; $env.runAsync = function(fn){ $env.debug("running async"); - (new java.lang.Thread(new java.lang.Runnable({ - run: fn - }))).start(); + var running = true; + + var run = sync(function(){ //while happening only thing in this timer + //$env.debug("running timed function"); + fn(); + }); + + var async = (new java.lang.Thread(new java.lang.Runnable({ + run: run + }))); + + try{ + async.start(); + }catch(e){ + $env.error("error while running async", e); + async.interrupt(); + $env.onInterrupt(); + } }; //Used to write to a local file @@ -388,14 +382,22 @@ var Envjs = function(){ var url = java.net.URL(xhr.url);//, $w.location); var connection; if ( /^file\:/.test(url) ) { - if ( xhr.method == "PUT" ) { - var text = data || "" ; - $env.writeToFile(text, url); - } else if ( xhr.method == "DELETE" ) { - $env.deleteFile(url); - } else { - connection = url.openConnection(); - connection.connect(); + try{ + if ( xhr.method == "PUT" ) { + var text = data || "" ; + $env.writeToFile(text, url); + } else if ( xhr.method == "DELETE" ) { + $env.deleteFile(url); + } else { + connection = url.openConnection(); + connection.connect(); + } + }catch(e){ + $env.error('failed to open file '+ url, e); + connection = null; + xhr.readyState = 4; + xhr.statusText = "Local File Protocol Error"; + xhr.responseText = "

"+ e+ "

"; } } else { connection = url.openConnection(); @@ -463,6 +465,7 @@ var Envjs = function(){ } if(responseHandler){ + $env.debug('calling ajax response handler'); responseHandler(); } }; @@ -472,21 +475,45 @@ var Envjs = function(){ htmlDocBuilder.setValidating(false); var htmlCleaner, - cleanDomSerializer, - cleanProperties; - $env.parseHTML = function(htmlstring){ - var domdoc;//what's up dom doc? - if($env.cleanHTML){ - htmlCleaner = htmlCleaner||new org.htmlcleaner.HtmlCleaner(); - cleanDomSerializer = cleanDomSerializer||new org.htmlcleaner.DomSerializer(); - cleanProperties = cleanProperties||new org.htmlcleaner.CleanerProperties(); - domdoc = org.htmlcleaner.DomSerializer.createDOM(htmlCleaner.clean(htmlstring)); - }else{ - domdoc = htmlDocBuilder.newDocumentBuilder().parse( - new java.io.ByteArrayInputStream( - (new java.lang.String(htmlstring)).getBytes("UTF8"))); - } - return domdoc; + cleanXMLSerializer, + cleanerProperties, + htmlTransformer, + htmlOutputProps; + $env.fixHTML = false; + $env.cleanHTML = function(xmlString){ + var htmlString; + $env.debug('Cleaning html :\n'+xmlString); + if(!htmlCleaner){ + cleanerProperties = new org.htmlcleaner.CleanerProperties(); + cleanerProperties.setOmitHtmlEnvelope(true); + cleanerProperties.setTranslateSpecialEntities(true); + cleanerProperties.setAdvancedXmlEscape(true); + cleanerProperties.setUseCdataForScriptAndStyle(false); + cleanerProperties.setOmitXmlDeclaration(true); + htmlCleaner = new org.htmlcleaner.HtmlCleaner(cleanerProperties); + cleanXMLSerializer = new org.htmlcleaner.SimpleXmlSerializer(cleanerProperties); + //may have been initialized in $env.xslt + /*transformerFactory = transformerFactory|| + Packages.javax.xml.transform.TransformerFactory.newInstance(); + htmlTransformer = transformerFactory.newTransformer(); + htmlOutputProps = new java.util.Properties(); + htmlOutputProps.put(javax.xml.transform.OutputKeys.METHOD, "xml"); + htmlOutputProps.put(javax.xml.transform.OutputKeys.INDENT , "no"); + htmlOutputProps.put(javax.xml.transform.OutputKeys.ENCODING , "UTF-8"); + htmlOutputProps.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION , "yes"); + htmlTransformer.setOutputProperties(htmlOutputProps)*/ + } + + /*var node = cleanXMLSerializer.createDOM(htmlCleaner.clean(xmlString)), + outText = new java.io.StringWriter(); + htmlTransformer.transform( + new javax.xml.transform.dom.DOMSource(node), + new javax.xml.transform.stream.StreamResult(outText)); + + htmlString = outText.toString()+'';*/ + htmlString = cleanXMLSerializer.getXmlAsString(htmlCleaner.clean(xmlString)); + //$env.info('Cleaned html :\n'+htmlString); + return htmlString; }; var xmlDocBuilder = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance(); @@ -554,10 +581,18 @@ var Envjs = function(){ $env.loadInlineScript = function(script){ - $env.debug("loading inline script :" + script.text); + //$env.info("loading inline script :" + script.text+''); + //var rand = Date.now()+'-'+Math.floor(Math.random()*10000000); + //window[rand]=false; var tmpFile = $env.writeToTempFile(script.text, 'js') ; $env.debug("loading " + tmpFile); $env.load(tmpFile); + /*if(window[rand]===false){ + $env.error('Error loading script:\n\n'+script.text+'\n\n'); + delete window[rand]; + throw new Error('ScriptLoadingError'); + } + delete window[rand];*/ }; //injected by org.mozilla.javascript.tools.envjs. @@ -568,7 +603,7 @@ var Envjs = function(){ $env.restoreScope = restoreScope; })(Envjs);/* - * Envjs env-js.1.0.rc1 + * Envjs env-js.1.0.rc2 * Pure JavaScript Browser Environment * By John Resig * Copyright 2008-2009 John Resig, under the MIT License @@ -1068,12 +1103,12 @@ __extend__(DOMNamedNodeMap.prototype, { throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)); } else { this[itemIndex] = arg; // over-write existing NamedNode - this[arg.name] = arg; + this[arg.name.toLowerCase()] = arg; } } else { // add new NamedNode Array.prototype.push.apply(this, [arg]); - this[arg.name] = arg; + this[arg.name.toLowerCase()] = arg; } arg.ownerElement = this.parentNode; // update ownerElement @@ -1221,12 +1256,13 @@ var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) { for (var i=0; i 0); + return (this!==null&&this!=undefined); }, get nodeType(){ return DOMNode.ATTRIBUTE_NODE; }, get xml(){ - return this.nodeName + '="' + __escapeXML__(this.nodeValue) + '" '; + if(this.nodeValue) + return this.nodeName + '="' + __escapeXML__(this.nodeValue) + '" '; + else + return ''; }, toString : function(){ return "Attr #" + this._id + " " + this.name; @@ -2338,7 +2379,7 @@ $debug("Defining Element"); var DOMElement = function(ownerDocument) { this.DOMNode = DOMNode; this.DOMNode(ownerDocument); - this.id = ""; // the ID of the element + //this.id = null; // the ID of the element }; DOMElement.prototype = new DOMNode; __extend__(DOMElement.prototype, { @@ -2359,17 +2400,17 @@ __extend__(DOMElement.prototype, { if (attr) { ret = attr.value; } - return ret; // if Attribute exists, return its value, otherwise, return "" + return ret; // if Attribute exists, return its value, otherwise, return null }, setAttribute : function (name, value) { // if attribute exists, use it var attr = this.attributes.getNamedItem(name); - var value = value+''; + //I had to add this check becuase as the script initializes //the id may be set in the constructor, and the html element //overrides the id property with a getter/setter. if(__ownerDocument__(this)){ - if (!attr) { + if (attr===null||attr===undefined) { attr = __ownerDocument__(this).createAttribute(name); // otherwise create it } @@ -2387,15 +2428,17 @@ __extend__(DOMElement.prototype, { } } - if (__isIdDeclaration__(name)) { - // this.id = value; // cache ID for getElementById() - } + /*if (__isIdDeclaration__(name)) { + this.id = value; // cache ID for getElementById() + }*/ // assign values to properties (and aliases) attr.value = value; // add/replace Attribute in NamedNodeMap this.attributes.setNamedItem(attr); + }else{ + $warn('Element has no owner document '+this.tagName+'\n\t cant set attribute ' + name + ' = '+value ); } }, removeAttribute : function removeAttribute(name) { @@ -3775,7 +3818,7 @@ function isEmpty(str) { * @param str : string - The string to be escaped * @return : string - The escaped string */ -var escAmpRegEx = /&/g; +var escAmpRegEx = /&(?!(amp;|lt;|gt;|quot|apos;))/g; var escLtRegEx = //g; var quotRegEx = /"/g; @@ -4098,7 +4141,7 @@ var DOMImplementation = function() { this.errorChecking = true; // by default, test for exceptions }; -var $handleEndOfNormalOrEmptyElement = function(node, doc, p){ +var __endHTMLElement__ = function(node, doc, p){ if(node.nodeName.toLowerCase() == 'script'){ p.replaceEntities = true; $env.loadLocalScript(node, p); @@ -4367,7 +4410,7 @@ function __parseLoop__(impl, doc, p) { } else if(iEvt == XMLP._ELM_E) { // End-Element Event - $handleEndOfNormalOrEmptyElement(iNodeParent, doc, p); + __endHTMLElement__(iNodeParent, doc, p); iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree } @@ -4455,7 +4498,7 @@ function __parseLoop__(impl, doc, p) { } - $handleEndOfNormalOrEmptyElement(iNode, doc, p); + __endHTMLElement__(iNode, doc, p); iNodeParent.appendChild(iNode); // attach Element to parentNode } else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) { // TextNode and entity Events @@ -4747,9 +4790,15 @@ __extend__(DOMDocument.prototype, { get parentWindow(){ return this._parentWindow; }, - loadXML : function(xmlStr) { + loadXML : function(xmlString) { // create SAX Parser - var parser = new XMLP(xmlStr+''); + var htmlString; + if($env.fixHTML){ + htmlString = $env.cleanHTML(xmlString); + }else{ + htmlString = xmlString + } + var parser = new XMLP(htmlString+''); // create DOM Document if(this === $document){ @@ -5039,11 +5088,7 @@ __extend__(DOMDocument.prototype, { }, get defaultView(){ //TODO: why isnt this just 'return $w;'? return { getComputedStyle: function(elem){ - return { getPropertyValue: function(prop){ - prop = prop.replace(/\-(\w)/g,function(m,c){ return c.toUpperCase(); }); - var val = elem.style[prop]; - if ( prop == "opacity" && val == "" ){ val = "1"; }return val; - }}; + return $w.getComputedStyle(elem); }}; }, _genId : function() { @@ -5508,7 +5553,7 @@ __extend__(HTMLDocument.prototype, { else if(tagName.match(/SELECT/)) {node = new HTMLSelectElement(this);} else if(tagName.match(/STYLE/)) {node = new HTMLStyleElement(this);} else if(tagName.match(/TABLE/)) {node = new HTMLTableElement(this);} - else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLSectionElement(this);} + else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLTableSectionElement(this);} else if(tagName.match(/TD|TH/)) {node = new HTMLTableCellElement(this);} else if(tagName.match(/TEXTAREA/)) {node = new HTMLTextAreaElement(this);} else if(tagName.match(/TITLE/)) {node = new HTMLTitleElement(this);} @@ -5658,11 +5703,10 @@ var HTMLElement = function(ownerDocument) { HTMLElement.prototype = new DOMElement; __extend__(HTMLElement.prototype, { get className() { - return this.getAttribute("class")||""; - + return this.getAttribute("class")||''; }, - set className(val) { - return this.setAttribute("class",trim(val)); + set className(value) { + return this.setAttribute("class",trim(value)); }, get dir() { @@ -5674,7 +5718,7 @@ __extend__(HTMLElement.prototype, { }, get id(){ - return this.getAttribute('id')||''; + return this.getAttribute('id'); }, set id(id){ @@ -5704,7 +5748,7 @@ __extend__(HTMLElement.prototype, { doc = null; }, get lang() { - return this.getAttribute("lang")||""; + return this.getAttribute("lang"); }, set lang(val) { @@ -5733,33 +5777,36 @@ __extend__(HTMLElement.prototype, { scrollRight: 0, get style(){ if(this.$css2props === null){ - this.updateCss2Props(); + __updateCss2Props__(this); } return this.$css2props }, - updateCss2Props: function() { - this.$css2props = new CSS2Properties({ - onSet: (function(that) { - return function() { that.__setAttribute("style", this.cssText); } - })(this), - cssText:this.getAttribute("style") - }); - }, - __setAttribute: HTMLElement.prototype.setAttribute, setAttribute: function (name, value) { - this.__setAttribute(name, value); + DOMElement.prototype.setAttribute.apply(this,[name, value]); if (name === "style") { - this.updateCss2Props(); + __updateCss2Props__(this); } }, get title() { - return this.getAttribute("title")||""; + return this.getAttribute("title"); }, - set title(val) { - return this.setAttribute("title",val); + set title(value) { + return this.setAttribute("title", value); }, + get tabIndex(){ + var ti = this.getAttribute('tabindex'); + if(ti!==null) + return Number(ti); + else + return 0; + }, + set tabIndex(value){ + if(value===undefined||value===null) + value = 0; + this.setAttribute('tabindex',Number(value)); + }, //Not in the specs but I'll leave it here for now. get outerHTML(){ return this.xml; @@ -5772,17 +5819,9 @@ __extend__(HTMLElement.prototype, { }, onclick: function(event){ - __eval__(this.getAttribute('onclick')||'', this) + __eval__(this.getAttribute('onclick')||'', this); }, - // non-ECMA function, but no other way for click events to enter env.js - __click__: function(element){ - var event = new Event({ - target:element, - currentTarget:element - }); - event.initEvent("click"); - element.dispatchEvent(event); - }, + ondblclick: function(event){ __eval__(this.getAttribute('ondblclick')||'', this); @@ -5841,6 +5880,10 @@ var __eval__ = function(script, startingNode){ } }; +var __updateCss2Props__ = function(elem){ + elem.$css2props = new CSS2Properties(elem); +}; + var __registerEventAttrs__ = function(elm){ if(elm.hasAttribute('onclick')){ elm.addEventListener('click', elm.onclick ); @@ -5875,6 +5918,15 @@ var __registerEventAttrs__ = function(elm){ return elm; }; +// non-ECMA function, but no other way for click events to enter env.js +var __click__ = function(element){ + var event = new Event({ + target:element, + currentTarget:element + }); + event.initEvent("click"); + element.dispatchEvent(event); +}; var __submit__ = function(element){ var event = new Event({ target:element, @@ -5984,7 +6036,7 @@ var HTMLAnchorElement = function(ownerDocument) { HTMLAnchorElement.prototype = new HTMLElement; __extend__(HTMLAnchorElement.prototype, { get accessKey() { - return this.getAttribute("accesskey") || ""; + return this.getAttribute("accesskey"); }, set accessKey(val) { @@ -5992,7 +6044,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get charset() { - return this.getAttribute("charset") || ""; + return this.getAttribute("charset"); }, set charset(val) { @@ -6000,7 +6052,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get coords() { - return this.getAttribute("coords") || ""; + return this.getAttribute("coords"); }, set coords(val) { @@ -6008,7 +6060,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get href() { - return this.getAttribute("href") || ""; + return this.getAttribute("href"); }, set href(val) { @@ -6016,7 +6068,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get hreflang() { - return this.getAttribute("hreflang") || ""; + return this.getAttribute("hreflang"); }, set hreflang(val) { @@ -6024,7 +6076,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get name() { - return this.getAttribute("name") || ""; + return this.getAttribute("name"); }, set name(val) { @@ -6032,7 +6084,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get rel() { - return this.getAttribute("rel") || ""; + return this.getAttribute("rel"); }, set rel(val) { @@ -6040,7 +6092,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get rev() { - return this.getAttribute("rev") || ""; + return this.getAttribute("rev"); }, set rev(val) { @@ -6048,23 +6100,15 @@ __extend__(HTMLAnchorElement.prototype, { }, get shape() { - return this.getAttribute("shape") || ""; + return this.getAttribute("shape"); }, set shape(val) { return this.setAttribute("shape",val); - }, - get tabIndex() { - return this.getAttribute("tabindex") || ""; - - }, - set tabIndex(val) { - return this.setAttribute("tabindex",val); - }, get target() { - return this.getAttribute("target") || ""; + return this.getAttribute("target"); }, set target(val) { @@ -6072,7 +6116,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get type() { - return this.getAttribute("type") || ""; + return this.getAttribute("type"); }, set type(val) { @@ -6210,12 +6254,12 @@ __extend__(HTMLAreaElement.prototype, { //TODO return 0; }, - get tabIndex(){ + /*get tabIndex(){ return this.getAttribute('tabindex'); }, set tabIndex(value){ this.setAttribute('tabindex',value); - }, + },*/ get target(){ return this.getAttribute('target'); }, @@ -6307,12 +6351,12 @@ __extend__(HTMLButtonElement.prototype, { set accessKey(value){ this.setAttribute('accesskey',value); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',Number(value)); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -6498,7 +6542,7 @@ __extend__(HTMLFormElement.prototype,{ }, get name() { - return this.getAttribute("name") || ""; + return this.getAttribute("name"); }, set name(val) { @@ -6506,7 +6550,7 @@ __extend__(HTMLFormElement.prototype,{ }, get target() { - return this.getAttribute("target") || ""; + return this.getAttribute("target"); }, set target(val) { @@ -6845,12 +6889,12 @@ __extend__(HTMLInputElement.prototype, { set src(value){ this.setAttribute('src', value); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',Number(value)); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -6864,6 +6908,8 @@ __extend__(HTMLInputElement.prototype, { return this.getAttribute('value'); }, set value(value){ + if(this.defaultValue===null&&this.value!==null) + this.defaultValue = this.value; this.setAttribute('value',value); }, blur:function(){ @@ -7144,12 +7190,12 @@ __extend__(HTMLObjectElement.prototype, { set standby(value){ this.setAttribute('standby',value); }, - get tabIndex(){ + /*get tabIndex(){ return this.getAttribute('tabindex'); }, set tabIndex(value){ this.setAttribute('tabindex',value); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -7250,6 +7296,8 @@ __extend__(HTMLOptionElement.prototype, { return (this.getAttribute('selected')=='selected'); }, set selected(value){ + if(this.defaultSelected===null&&this.selected!==null) + this.defaultSelected = this.selected; this.setAttribute('selected', (value ? 'selected' :'')); }, get value(){ @@ -7325,6 +7373,10 @@ __extend__(HTMLScriptElement.prototype, { return this.nodeValue; }, + set text(value){ + this.nodeValue = value; + $env.loadInlineScript(this); + }, get htmlFor(){ return this.getAttribute('for'); }, @@ -7453,12 +7505,12 @@ __extend__(HTMLSelectElement.prototype, { set size(value){ this.setAttribute('size',value); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',value); - }, + },*/ add : function(){ __add__(this); }, @@ -7574,24 +7626,29 @@ __extend__(HTMLTableElement.prototype, { }, appendChild : function (child) { - - var tagName = child.tagName.toLowerCase(); - if (tagName === "tr") { - // need an implcit to contain this... - if (!this.currentBody) { - this.currentBody = document.createElement("tbody"); - - DOMNode.prototype.appendChild.apply(this, [this.currentBody]); + + var tagName; + if(child.tagName){ + tagName = child.tagName.toLowerCase(); + if (tagName === "tr") { + // need an implcit to contain this... + if (!this.currentBody) { + this.currentBody = document.createElement("tbody"); + + DOMNode.prototype.appendChild.apply(this, [this.currentBody]); + } + + return this.currentBody.appendChild(child); + + } else if (tagName === "tbody" || tagName === "tfoot" && this.currentBody) { + this.currentBody = child; + return DOMNode.prototype.appendChild.apply(this, arguments); + + } else { + return DOMNode.prototype.appendChild.apply(this, arguments); } - - return this.currentBody.appendChild(child); - - } else if (tagName === "tbody" || tagName === "tfoot" && this.currentBody) { - this.currentBody = child; - return DOMNode.prototype.appendChild.apply(this, arguments); - - } else { - return DOMNode.prototype.appendChild.apply(this, arguments); + }else{ + $error('HTMLTableElement.appendChild => child.tagName should not be undefined here... Fix ME!'); } }, @@ -7868,6 +7925,12 @@ __extend__(HTMLTextAreaElement.prototype, { set disabled(value){ this.setAttribute('disabled', (value ? 'disabled' :'')); }, + get maxLength(){ + return Number(this.getAttribute('maxlength')||'0'); + }, + set maxLength(value){ + this.setAttribute('maxlength', value); + }, get name(){ return this.getAttribute('name')||''; }, @@ -7880,12 +7943,12 @@ __extend__(HTMLTextAreaElement.prototype, { set readOnly(value){ this.setAttribute('readonly', (value ? 'readonly' :'')); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',Number(value)); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -7893,10 +7956,12 @@ __extend__(HTMLTextAreaElement.prototype, { this.setAttribute('type',value); }, get value(){ - return this.getAttribute('value'); + return this.text; }, set value(value){ - this.setAttribute('value',value); + if(this.defaultValue===null&&this.text!==null) + this.defaultValue = this.text; + return this.text = value; }, blur:function(){ __blur__(this); @@ -8241,45 +8306,53 @@ var $onblur, $onresize;/* * CSS2Properties - DOM Level 2 CSS */ -var CSS2Properties = function(options){ - __extend__(this, __supportedStyles__); - this.onSetCallback = options.onSet?options.onSet:(function(){}); - this.styleIndices = {}; - __cssTextToStyles__(this, options.cssText?options.cssText:""); +var CSS2Properties = function(element){ + //this.onSetCallback = options.onSet?options.onSet:(function(){}); + this.styleIndex = __supportedStyles__(); + this.nameMap = {}; + this.__previous__ = {}; + this.__element__ = element + __cssTextToStyles__(this, element.getAttribute('style')||''); }; __extend__(CSS2Properties.prototype, { get cssText(){ - return Array.prototype.join.apply(this,[';\n']); + var css = ''; + for(var i=0;i0){ @@ -8287,1067 +8360,218 @@ __extend__(CSS2Properties.prototype, { }else{ return ''; } - }, - onSet:function(camelCaseName, value){ - var dashedName = __toDashed__(camelCaseName); - var definition = dashedName + ": " + value; - if (this.styleIndices[camelCaseName] !== undefined) - this[this.styleIndices[camelCaseName]] = definition; - else { - Array.prototype.push.apply(this, [definition]); - this.styleIndices[camelCaseName] = this.length - 1; - } - this.onSetCallback(); - }, + } }); +var __parseStyle__ = function(css2prop, name, value){ + css2prop.styleIndex[name] = value; + var definition = __toDashed__(name); + if(css2prop.length===undefined){ + Array.prototype.push.apply(css2prop, [definition]); + css2prop.nameMap[definition] = 0; + }else{ + if(definition in css2prop.nameMap){ + css2prop[css2prop.nameMap[definition]] = definition; + }else{ + Array.prototype.push.apply(css2prop, [definition]); + css2prop.nameMap[definition] = css2prop.length; + } + } +}; + + var __cssTextToStyles__ = function(css2props, cssText){ - var styleArray=[]; + //var styleArray=[]; var style, name, value, camelCaseName, w3cName, styles = cssText.split(';'); - css2props.styleIndices = {}; for ( var i = 0; i < styles.length; i++ ) { //$log("Adding style property " + styles[i]); style = styles[i].split(':'); + //$log(" style " + style[0]); if ( style.length == 2 ){ - //keep a reference to the original name of the style which was set - //this is the w3c style setting method. - var idx = styleArray.length; - styleArray[idx] = w3cName = styles[i]; - //camel case for dash case - value = trim(style[1]); - camelCaseName = trim(__toCamelCase__(style[0])); - css2props.styleIndices[camelCaseName] = idx; - $debug('CSS Style Name: ' + camelCaseName); - if(css2props["_" + camelCaseName]!==undefined){ - //set the value internally with camelcase name - $debug('Setting css ' + camelCaseName + ' to ' + value); - css2props["_" + camelCaseName] = value; - }; + //$log(" value " + style[1]); + __parseStyle__(css2props, style[0].replace(" ",'','g'), style[1].replace(" ",'','g')); } } - __setArray__(css2props, styleArray); }; var __toCamelCase__ = function(name) { - return name.replace(/\-(\w)/g, function(all, letter){ - return letter.toUpperCase(); - }); + //$info('__toCamelCase__'+name); + if(name){ + return name.replace(/\-(\w)/g, function(all, letter){ + return letter.toUpperCase(); + }); + } + return name; }; var __toDashed__ = function(camelCaseName) { - return camelCaseName.replace(/[A-Z]/g, function(all) { - return "-" + all.toLowerCase(); - }); + //$info("__toDashed__"+camelCaseName); + if(camelCaseName){ + return camelCaseName.replace(/[A-Z]/g, function(all) { + return "-" + all.toLowerCase(); + }); + } + return camelCaseName; }; //Obviously these arent all supported but by commenting out various sections //this provides a single location to configure what is exposed as supported. -//These getters/setters will need to get fine-tuned in the future to deal with -//the variation on input formulations -var __supportedStyles__ = (function(){ - return{ - _azimuth: "", - get azimuth() { - return this._azimuth; - }, - set azimuth(val) { - this._azimuth = val; - this.onSet("azimuth", val); - }, - _background: "", - get background() { - return this._background; - }, - set background(val) { - this._background = val; - this.onSet("background", val); - }, - _backgroundAttachment: "", - get backgroundAttachment() { - return this._backgroundAttachment; - }, - set backgroundAttachment(val) { - this._backgroundAttachment = val; - this.onSet("backgroundAttachment", val); - }, - _backgroundColor: "", - get backgroundColor() { - return this._backgroundColor; - }, - set backgroundColor(val) { - this._backgroundColor = val; - this.onSet("backgroundColor", val); - }, - _backgroundImage: "", - get backgroundImage() { - return this._backgroundImage; - }, - set backgroundImage(val) { - this._backgroundImage = val; - this.onSet("backgroundImage", val); - }, - _backgroundPosition: "", - get backgroundPosition() { - return this._backgroundPosition; - }, - set backgroundPosition(val) { - this._backgroundPosition = val; - this.onSet("backgroundPosition", val); - }, - _backgroundRepeat: "", - get backgroundRepeat() { - return this._backgroundRepeat; - }, - set backgroundRepeat(val) { - this._backgroundRepeat = val; - this.onSet("backgroundRepeat", val); - }, - _border: "", - get border() { - return this._border; - }, - set border(val) { - this._border = val; - this.onSet("border", val); - }, - _borderBottom: "", - get borderBottom() { - return this._borderBottom; - }, - set borderBottom(val) { - this._borderBottom = val; - this.onSet("borderBottom", val); - }, - _borderBottomColor: "", - get borderBottomColor() { - return this._borderBottomColor; - }, - set borderBottomColor(val) { - this._borderBottomColor = val; - this.onSet("borderBottomColor", val); - }, - _borderBottomStyle: "", - get borderBottomStyle() { - return this._borderBottomStyle; - }, - set borderBottomStyle(val) { - this._borderBottomStyle = val; - this.onSet("borderBottomStyle", val); - }, - _borderBottomWidth: "", - get borderBottomWidth() { - return this._borderBottomWidth; - }, - set borderBottomWidth(val) { - this._borderBottomWidth = val; - this.onSet("borderBottomWidth", val); - }, - _borderCollapse: "", - get borderCollapse() { - return this._borderCollapse; - }, - set borderCollapse(val) { - this._borderCollapse = val; - this.onSet("borderCollapse", val); - }, - _borderColor: "", - get borderColor() { - return this._borderColor; - }, - set borderColor(val) { - this._borderColor = val; - this.onSet("borderColor", val); - }, - _borderLeft: "", - get borderLeft() { - return this._borderLeft; - }, - set borderLeft(val) { - this._borderLeft = val; - this.onSet("borderLeft", val); - }, - _borderLeftColor: "", - get borderLeftColor() { - return this._borderLeftColor; - }, - set borderLeftColor(val) { - this._borderLeftColor = val; - this.onSet("borderLeftColor", val); - }, - _borderLeftStyle: "", - get borderLeftStyle() { - return this._borderLeftStyle; - }, - set borderLeftStyle(val) { - this._borderLeftStyle = val; - this.onSet("borderLeftStyle", val); - }, - _borderLeftWidth: "", - get borderLeftWidth() { - return this._borderLeftWidth; - }, - set borderLeftWidth(val) { - this._borderLeftWidth = val; - this.onSet("borderLeftWidth", val); - }, - _borderRight: "", - get borderRight() { - return this._borderRight; - }, - set borderRight(val) { - this._borderRight = val; - this.onSet("borderRight", val); - }, - _borderRightColor: "", - get borderRightColor() { - return this._borderRightColor; - }, - set borderRightColor(val) { - this._borderRightColor = val; - this.onSet("borderRightColor", val); - }, - _borderRightStyle: "", - get borderRightStyle() { - return this._borderRightStyle; - }, - set borderRightStyle(val) { - this._borderRightStyle = val; - this.onSet("borderRightStyle", val); - }, - _borderRightWidth: "", - get borderRightWidth() { - return this._borderRightWidth; - }, - set borderRightWidth(val) { - this._borderRightWidth = val; - this.onSet("borderRightWidth", val); - }, - _borderSpacing: "", - get borderSpacing() { - return this._borderSpacing; - }, - set borderSpacing(val) { - this._borderSpacing = val; - this.onSet("borderSpacing", val); - }, - _borderStyle: "", - get borderStyle() { - return this._borderStyle; - }, - set borderStyle(val) { - this._borderStyle = val; - this.onSet("borderStyle", val); - }, - _borderTop: "", - get borderTop() { - return this._borderTop; - }, - set borderTop(val) { - this._borderTop = val; - this.onSet("borderTop", val); - }, - _borderTopColor: "", - get borderTopColor() { - return this._borderTopColor; - }, - set borderTopColor(val) { - this._borderTopColor = val; - this.onSet("borderTopColor", val); - }, - _borderTopStyle: "", - get borderTopStyle() { - return this._borderTopStyle; - }, - set borderTopStyle(val) { - this._borderTopStyle = val; - this.onSet("borderTopStyle", val); - }, - _borderTopWidth: "", - get borderTopWidth() { - return this._borderTopWidth; - }, - set borderTopWidth(val) { - this._borderTopWidth = val; - this.onSet("borderTopWidth", val); - }, - _borderWidth: "", - get borderWidth() { - return this._borderWidth; - }, - set borderWidth(val) { - this._borderWidth = val; - this.onSet("borderWidth", val); - }, - _bottom: "", - get bottom() { - return this._bottom; - }, - set bottom(val) { - this._bottom = val; - this.onSet("bottom", val); - }, - _captionSide: "", - get captionSide() { - return this._captionSide; - }, - set captionSide(val) { - this._captionSide = val; - this.onSet("captionSide", val); - }, - _clear: "", - get clear() { - return this._clear; - }, - set clear(val) { - this._clear = val; - this.onSet("clear", val); - }, - _clip: "", - get clip() { - return this._clip; - }, - set clip(val) { - this._clip = val; - this.onSet("clip", val); - }, - _color: "", - get color() { - return this._color; - }, - set color(val) { - this._color = val; - this.onSet("color", val); - }, - _content: "", - get content() { - return this._content; - }, - set content(val) { - this._content = val; - this.onSet("content", val); - }, - _counterIncrement: "", - get counterIncrement() { - return this._counterIncrement; - }, - set counterIncrement(val) { - this._counterIncrement = val; - this.onSet("counterIncrement", val); - }, - _counterReset: "", - get counterReset() { - return this._counterReset; - }, - set counterReset(val) { - this._counterReset = val; - this.onSet("counterReset", val); - }, - _cssFloat: "", - get cssFloat() { - return this._cssFloat; - }, - set cssFloat(val) { - this._cssFloat = val; - this.onSet("cssFloat", val); - }, - _cue: "", - get cue() { - return this._cue; - }, - set cue(val) { - this._cue = val; - this.onSet("cue", val); - }, - _cueAfter: "", - get cueAfter() { - return this._cueAfter; - }, - set cueAfter(val) { - this._cueAfter = val; - this.onSet("cueAfter", val); - }, - _cueBefore: "", - get cueBefore() { - return this._cueBefore; - }, - set cueBefore(val) { - this._cueBefore = val; - this.onSet("cueBefore", val); - }, - _cursor: "", - get cursor() { - return this._cursor; - }, - set cursor(val) { - this._cursor = val; - this.onSet("cursor", val); - }, - _direction: "", - get direction() { - return this._direction; - }, - set direction(val) { - this._direction = val; - this.onSet("direction", val); - }, - _display: "", - get display() { - return this._display; - }, - set display(val) { - this._display = val; - this.onSet("display", val); - }, - _elevation: "", - get elevation() { - return this._elevation; - }, - set elevation(val) { - this._elevation = val; - this.onSet("elevation", val); - }, - _emptyCells: "", - get emptyCells() { - return this._emptyCells; - }, - set emptyCells(val) { - this._emptyCells = val; - this.onSet("emptyCells", val); - }, - _font: "", - get font() { - return this._font; - }, - set font(val) { - this._font = val; - this.onSet("font", val); - }, - _fontFamily: "", - get fontFamily() { - return this._fontFamily; - }, - set fontFamily(val) { - this._fontFamily = val; - this.onSet("fontFamily", val); - }, - _fontSize: "", - get fontSize() { - return this._fontSize; - }, - set fontSize(val) { - this._fontSize = val; - this.onSet("fontSize", val); - }, - _fontSizeAdjust: "", - get fontSizeAdjust() { - return this._fontSizeAdjust; - }, - set fontSizeAdjust(val) { - this._fontSizeAdjust = val; - this.onSet("fontSizeAdjust", val); - }, - _fontStretch: "", - get fontStretch() { - return this._fontStretch; - }, - set fontStretch(val) { - this._fontStretch = val; - this.onSet("fontStretch", val); - }, - _fontStyle: "", - get fontStyle() { - return this._fontStyle; - }, - set fontStyle(val) { - this._fontStyle = val; - this.onSet("fontStyle", val); - }, - _fontVariant: "", - get fontVariant() { - return this._fontVariant; - }, - set fontVariant(val) { - this._fontVariant = val; - this.onSet("fontVariant", val); - }, - _fontWeight: "", - get fontWeight() { - return this._fontWeight; - }, - set fontWeight(val) { - this._fontWeight = val; - this.onSet("fontWeight", val); - }, - _height: "", - get height() { - return this._height; - }, - set height(val) { - this._height = val; - this.onSet("height", val); - }, - _left: "", - get left() { - return this._left; - }, - set left(val) { - this._left = val; - this.onSet("left", val); - }, - _letterSpacing: "", - get letterSpacing() { - return this._letterSpacing; - }, - set letterSpacing(val) { - this._letterSpacing = val; - this.onSet("letterSpacing", val); - }, - _lineHeight: "", - get lineHeight() { - return this._lineHeight; - }, - set lineHeight(val) { - this._lineHeight = val; - this.onSet("lineHeight", val); - }, - _listStyle: "", - get listStyle() { - return this._listStyle; - }, - set listStyle(val) { - this._listStyle = val; - this.onSet("listStyle", val); - }, - _listStyleImage: "", - get listStyleImage() { - return this._listStyleImage; - }, - set listStyleImage(val) { - this._listStyleImage = val; - this.onSet("listStyleImage", val); - }, - _listStylePosition: "", - get listStylePosition() { - return this._listStylePosition; - }, - set listStylePosition(val) { - this._listStylePosition = val; - this.onSet("listStylePosition", val); - }, - _listStyleType: "", - get listStyleType() { - return this._listStyleType; - }, - set listStyleType(val) { - this._listStyleType = val; - this.onSet("listStyleType", val); - }, - _margin: "", - get margin() { - return this._margin; - }, - set margin(val) { - this._margin = val; - this.onSet("margin", val); - }, - _marginBottom: "", - get marginBottom() { - return this._marginBottom; - }, - set marginBottom(val) { - this._marginBottom = val; - this.onSet("marginBottom", val); - }, - _marginLeft: "", - get marginLeft() { - return this._marginLeft; - }, - set marginLeft(val) { - this._marginLeft = val; - this.onSet("marginLeft", val); - }, - _marginRight: "", - get marginRight() { - return this._marginRight; - }, - set marginRight(val) { - this._marginRight = val; - this.onSet("marginRight", val); - }, - _marginTop: "", - get marginTop() { - return this._marginTop; - }, - set marginTop(val) { - this._marginTop = val; - this.onSet("marginTop", val); - }, - _markerOffset: "", - get markerOffset() { - return this._markerOffset; - }, - set markerOffset(val) { - this._markerOffset = val; - this.onSet("markerOffset", val); - }, - _marks: "", - get marks() { - return this._marks; - }, - set marks(val) { - this._marks = val; - this.onSet("marks", val); - }, - _maxHeight: "", - get maxHeight() { - return this._maxHeight; - }, - set maxHeight(val) { - this._maxHeight = val; - this.onSet("maxHeight", val); - }, - _maxWidth: "", - get maxWidth() { - return this._maxWidth; - }, - set maxWidth(val) { - this._maxWidth = val; - this.onSet("maxWidth", val); - }, - _minHeight: "", - get minHeight() { - return this._minHeight; - }, - set minHeight(val) { - this._minHeight = val; - this.onSet("minHeight", val); - }, - _minWidth: "", - get minWidth() { - return this._minWidth; - }, - set minWidth(val) { - this._minWidth = val; - this.onSet("minWidth", val); - }, - _opacity: 1, - get opacity() { - return this._opacity; - }, - set opacity(val) { - this._opacity = val; - this.onSet("opacity", val); - }, - _orphans: "", - get orphans() { - return this._orphans; - }, - set orphans(val) { - this._orphans = val; - this.onSet("orphans", val); - }, - _outline: "", - get outline() { - return this._outline; - }, - set outline(val) { - this._outline = val; - this.onSet("outline", val); - }, - _outlineColor: "", - get outlineColor() { - return this._outlineColor; - }, - set outlineColor(val) { - this._outlineColor = val; - this.onSet("outlineColor", val); - }, - _outlineOffset: "", - get outlineOffset() { - return this._outlineOffset; - }, - set outlineOffset(val) { - this._outlineOffset = val; - this.onSet("outlineOffset", val); - }, - _outlineStyle: "", - get outlineStyle() { - return this._outlineStyle; - }, - set outlineStyle(val) { - this._outlineStyle = val; - this.onSet("outlineStyle", val); - }, - _outlineWidth: "", - get outlineWidth() { - return this._outlineWidth; - }, - set outlineWidth(val) { - this._outlineWidth = val; - this.onSet("outlineWidth", val); - }, - _overflow: "", - get overflow() { - return this._overflow; - }, - set overflow(val) { - this._overflow = val; - this.onSet("overflow", val); - }, - _overflowX: "", - get overflowX() { - return this._overflowX; - }, - set overflowX(val) { - this._overflowX = val; - this.onSet("overflowX", val); - }, - _overflowY: "", - get overflowY() { - return this._overflowY; - }, - set overflowY(val) { - this._overflowY = val; - this.onSet("overflowY", val); - }, - _padding: "", - get padding() { - return this._padding; - }, - set padding(val) { - this._padding = val; - this.onSet("padding", val); - }, - _paddingBottom: "", - get paddingBottom() { - return this._paddingBottom; - }, - set paddingBottom(val) { - this._paddingBottom = val; - this.onSet("paddingBottom", val); - }, - _paddingLeft: "", - get paddingLeft() { - return this._paddingLeft; - }, - set paddingLeft(val) { - this._paddingLeft = val; - this.onSet("paddingLeft", val); - }, - _paddingRight: "", - get paddingRight() { - return this._paddingRight; - }, - set paddingRight(val) { - this._paddingRight = val; - this.onSet("paddingRight", val); - }, - _paddingTop: "", - get paddingTop() { - return this._paddingTop; - }, - set paddingTop(val) { - this._paddingTop = val; - this.onSet("paddingTop", val); - }, - _page: "", - get page() { - return this._page; - }, - set page(val) { - this._page = val; - this.onSet("page", val); - }, - _pageBreakAfter: "", - get pageBreakAfter() { - return this._pageBreakAfter; - }, - set pageBreakAfter(val) { - this._pageBreakAfter = val; - this.onSet("pageBreakAfter", val); - }, - _pageBreakBefore: "", - get pageBreakBefore() { - return this._pageBreakBefore; - }, - set pageBreakBefore(val) { - this._pageBreakBefore = val; - this.onSet("pageBreakBefore", val); - }, - _pageBreakInside: "", - get pageBreakInside() { - return this._pageBreakInside; - }, - set pageBreakInside(val) { - this._pageBreakInside = val; - this.onSet("pageBreakInside", val); - }, - _pause: "", - get pause() { - return this._pause; - }, - set pause(val) { - this._pause = val; - this.onSet("pause", val); - }, - _pauseAfter: "", - get pauseAfter() { - return this._pauseAfter; - }, - set pauseAfter(val) { - this._pauseAfter = val; - this.onSet("pauseAfter", val); - }, - _pauseBefore: "", - get pauseBefore() { - return this._pauseBefore; - }, - set pauseBefore(val) { - this._pauseBefore = val; - this.onSet("pauseBefore", val); - }, - _pitch: "", - get pitch() { - return this._pitch; - }, - set pitch(val) { - this._pitch = val; - this.onSet("pitch", val); - }, - _pitchRange: "", - get pitchRange() { - return this._pitchRange; - }, - set pitchRange(val) { - this._pitchRange = val; - this.onSet("pitchRange", val); - }, - _position: "", - get position() { - return this._position; - }, - set position(val) { - this._position = val; - this.onSet("position", val); - }, - _quotes: "", - get quotes() { - return this._quotes; - }, - set quotes(val) { - this._quotes = val; - this.onSet("quotes", val); - }, - _richness: "", - get richness() { - return this._richness; - }, - set richness(val) { - this._richness = val; - this.onSet("richness", val); - }, - _right: "", - get right() { - return this._right; - }, - set right(val) { - this._right = val; - this.onSet("right", val); - }, - _size: "", - get size() { - return this._size; - }, - set size(val) { - this._size = val; - this.onSet("size", val); - }, - _speak: "", - get speak() { - return this._speak; - }, - set speak(val) { - this._speak = val; - this.onSet("speak", val); - }, - _speakHeader: "", - get speakHeader() { - return this._speakHeader; - }, - set speakHeader(val) { - this._speakHeader = val; - this.onSet("speakHeader", val); - }, - _speakNumeral: "", - get speakNumeral() { - return this._speakNumeral; - }, - set speakNumeral(val) { - this._speakNumeral = val; - this.onSet("speakNumeral", val); - }, - _speakPunctuation: "", - get speakPunctuation() { - return this._speakPunctuation; - }, - set speakPunctuation(val) { - this._speakPunctuation = val; - this.onSet("speakPunctuation", val); - }, - _speechRate: "", - get speechRate() { - return this._speechRate; - }, - set speechRate(val) { - this._speechRate = val; - this.onSet("speechRate", val); - }, - _stress: "", - get stress() { - return this._stress; - }, - set stress(val) { - this._stress = val; - this.onSet("stress", val); - }, - _tableLayout: "", - get tableLayout() { - return this._tableLayout; - }, - set tableLayout(val) { - this._tableLayout = val; - this.onSet("tableLayout", val); - }, - _textAlign: "", - get textAlign() { - return this._textAlign; - }, - set textAlign(val) { - this._textAlign = val; - this.onSet("textAlign", val); - }, - _textDecoration: "", - get textDecoration() { - return this._textDecoration; - }, - set textDecoration(val) { - this._textDecoration = val; - this.onSet("textDecoration", val); - }, - _textIndent: "", - get textIndent() { - return this._textIndent; - }, - set textIndent(val) { - this._textIndent = val; - this.onSet("textIndent", val); - }, - _textShadow: "", - get textShadow() { - return this._textShadow; - }, - set textShadow(val) { - this._textShadow = val; - this.onSet("textShadow", val); - }, - _textTransform: "", - get textTransform() { - return this._textTransform; - }, - set textTransform(val) { - this._textTransform = val; - this.onSet("textTransform", val); - }, - _top: "", - get top() { - return this._top; - }, - set top(val) { - this._top = val; - this.onSet("top", val); - }, - _unicodeBidi: "", - get unicodeBidi() { - return this._unicodeBidi; - }, - set unicodeBidi(val) { - this._unicodeBidi = val; - this.onSet("unicodeBidi", val); - }, - _verticalAlign: "", - get verticalAlign() { - return this._verticalAlign; - }, - set verticalAlign(val) { - this._verticalAlign = val; - this.onSet("verticalAlign", val); - }, - _visibility: "", - get visibility() { - return this._visibility; - }, - set visibility(val) { - this._visibility = val; - this.onSet("visibility", val); - }, - _voiceFamily: "", - get voiceFamily() { - return this._voiceFamily; - }, - set voiceFamily(val) { - this._voiceFamily = val; - this.onSet("voiceFamily", val); - }, - _volume: "", - get volume() { - return this._volume; - }, - set volume(val) { - this._volume = val; - this.onSet("volume", val); - }, - _whiteSpace: "", - get whiteSpace() { - return this._whiteSpace; - }, - set whiteSpace(val) { - this._whiteSpace = val; - this.onSet("whiteSpace", val); - }, - _widows: "", - get widows() { - return this._widows; - }, - set widows(val) { - this._widows = val; - this.onSet("widows", val); - }, - _width: "", - get width() { - return this._width; - }, - set width(val) { - this._width = val; - this.onSet("width", val); - }, - _wordSpacing: "", - get wordSpacing() { - return this._wordSpacing; - }, - set wordSpacing(val) { - this._wordSpacing = val; - this.onSet("wordSpacing", val); - }, - _zIndex: "", - get zIndex() { - return this._zIndex; - }, - set zIndex(val) { - this._zIndex = val; - this.onSet("zIndex", val); - } - }; -})() +var __supportedStyles__ = function(){ + return { + azimuth: null, + background: null, + backgroundAttachment: null, + backgroundColor: null, + backgroundImage: null, + backgroundPosition: null, + backgroundRepeat: null, + border: null, + borderBottom: null, + borderBottomColor: null, + borderBottomStyle: null, + borderBottomWidth: null, + borderCollapse: null, + borderColor: null, + borderLeft: null, + borderLeftColor: null, + borderLeftStyle: null, + borderLeftWidth: null, + borderRight: null, + borderRightColor: null, + borderRightStyle: null, + borderRightWidth: null, + borderSpacing: null, + borderStyle: null, + borderTop: null, + borderTopColor: null, + borderTopStyle: null, + borderTopWidth: null, + borderWidth: null, + bottom: null, + captionSide: null, + clear: null, + clip: null, + color: null, + content: null, + counterIncrement: null, + counterReset: null, + cssFloat: null, + cue: null, + cueAfter: null, + cueBefore: null, + cursor: null, + direction: 'ltr', + display: 'block', + elevation: null, + emptyCells: null, + font: null, + fontFamily: null, + fontSize: "1em", + fontSizeAdjust: null, + fontStretch: null, + fontStyle: null, + fontVariant: null, + fontWeight: null, + height: '1px', + left: null, + letterSpacing: null, + lineHeight: null, + listStyle: null, + listStyleImage: null, + listStylePosition: null, + listStyleType: null, + margin: null, + marginBottom: "0px", + marginLeft: "0px", + marginRight: "0px", + marginTop: "0px", + markerOffset: null, + marks: null, + maxHeight: null, + maxWidth: null, + minHeight: null, + minWidth: null, + opacity: 1, + orphans: null, + outline: null, + outlineColor: null, + outlineOffset: null, + outlineStyle: null, + outlineWidth: null, + overflow: null, + overflowX: null, + overflowY: null, + padding: null, + paddingBottom: "0px", + paddingLeft: "0px", + paddingRight: "0px", + paddingTop: "0px", + page: null, + pageBreakAfter: null, + pageBreakBefore: null, + pageBreakInside: null, + pause: null, + pauseAfter: null, + pauseBefore: null, + pitch: null, + pitchRange: null, + position: null, + quotes: null, + richness: null, + right: null, + size: null, + speak: null, + speakHeader: null, + speakNumeral: null, + speakPunctuation: null, + speechRate: null, + stress: null, + tableLayout: null, + textAlign: null, + textDecoration: null, + textIndent: null, + textShadow: null, + textTransform: null, + top: null, + unicodeBidi: null, + verticalAlign: null, + visibility: null, + voiceFamily: null, + volume: null, + whiteSpace: null, + widows: null, + width: '1px', + wordSpacing: null, + zIndex: 1 + }; +}; + + +for(var style in __supportedStyles__()){ + (function(name){ + if(name === 'width' || name === 'height'){ + CSS2Properties.prototype.__defineGetter__(name, function(){ + if(this.getPropertyValue('display')==='none'){ + return '0px'; + } + //$info(name+' = '+this.getPropertyValue(name)); + return this.getPropertyValue(name); + }); + CSS2Properties.prototype.__defineSetter__(name, function(value){ + this.setProperty(name, value); + }); + }else{ + CSS2Properties.prototype.__defineGetter__(name, function(){ + //$log(" css2properties.get " + name); + return this.getPropertyValue(name); + }); + CSS2Properties.prototype.__defineSetter__(name, function(value){ + this.setProperty(name, value); + }); + } + })(style); +}; + $w.CSS2Properties = CSS2Properties;/* * CSSRule - DOM Level 2 @@ -9638,33 +8862,11 @@ $debug("Initializing Window Timer."); var $timers = []; window.setTimeout = function(fn, time){ - var num = $timers.length; - var tfn; - - if (typeof fn == 'string') { - tfn = function() { - eval(fn); - window.clearInterval(num); - }; - } else { - tfn = function() { - fn(); - window.clearInterval(num); - }; - } - - if (time === 0){ - if (typeof fn == 'string') - eval(fn); - else - fn(); - } - else { - $debug("Creating timer number "+num); - $timers[num] = new $env.timer(tfn, time); - $timers[num].start(); - return num; - } + var num; + return num = window.setInterval(function(){ + fn(); + window.clearInterval(num); + }, time); }; window.setInterval = function(fn, time){ @@ -9679,7 +8881,7 @@ window.setInterval = function(fn, time){ if(time===0){ fn(); }else{ - $debug("Creating timer number "+num); + //$debug("Creating timer number "+num); $timers[num] = new $env.timer(fn, time); $timers[num].start(); } @@ -9687,15 +8889,14 @@ window.setInterval = function(fn, time){ }; window.clearInterval = window.clearTimeout = function(num){ + //$log("clearing interval "+num); if ( $timers[num] ) { - $debug("Deleting timer number "+num); $timers[num].stop(); delete $timers[num]; } }; - -window.$wait = function(wait){ $env.wait(wait); }/* + /* * event.js */ // Window Events @@ -9706,7 +8907,7 @@ var $events = [], $onunload; $w.addEventListener = function(type, fn){ - //$log("adding event listener " + type); + $debug("adding event listener \n\t" + type +" \n\tfor "+this+" with callback \n\t"+fn); if ( !this.uuid ) { this.uuid = $events.length; $events[this.uuid] = {}; @@ -9743,25 +8944,29 @@ $w.dispatchEvent = function(event, bubbles){ bubbles = true; if (!event.target) { + $debug("no event target : "+event.target); event.target = this; } $debug("event target: " + event.target); - if ( event.type ) { + if ( event.type && this.nodeType || this===window) { + $debug("nodeType: " + this.nodeType); if ( this.uuid && $events[this.uuid][event.type] ) { var _this = this; $events[this.uuid][event.type].forEach(function(fn){ $debug('calling event handler '+fn+' on target '+_this); - fn.call( _this, event ); + fn( event ); }); } if (this["on" + event.type]) { - $debug('calling event handler '+event.type+' on target '+this); - this["on" + event.type].call(this, event); + $debug('calling event handler on'+event.type+' on target '+this); + this["on" + event.type](event); } + }else{ + $debug("non target: " + event.target + " \n this->"+this); } if (bubbles && this.parentNode){ - this.parentNode.dispatchEvent.call(this.parentNode,event); + this.parentNode.dispatchEvent(event); } }; @@ -9837,10 +9042,21 @@ XMLHttpRequest.prototype = { $debug("parsing response text into xml document"); responseXML = $domparser.parseFromString(_this.responseText+""); return responseXML; - } catch(e) { return null;/*TODO: need to flag an error here*/} + } catch(e) { + $error('response XML does not apear to be well formed xml', e); + responseXML = $domparser.parseFromString(""+ + "

parse error

"); + return responseXML; + } } - }else{return null;} + }else{ + $env.warn('response XML does not apear to be xml'); + return null; + } }); + _this.__defineSetter__("responseXML",function(xml){ + responseXML = xml; + }); }, data); _this.onreadystatechange(); } @@ -9893,6 +9109,7 @@ $debug("Initializing Window CSS"); // attributes and values used to render the specified element in this // window. Any length values are always expressed in pixel, or // absolute values. + $w.getComputedStyle = function(elt, pseudo_elt){ //TODO //this is a naive implementation diff --git a/doc/jquery-compatibility.txt b/doc/jquery-compatibility.txt index 5a75317c..71ffd703 100644 --- a/doc/jquery-compatibility.txt +++ b/doc/jquery-compatibility.txt @@ -17,6 +17,11 @@ 5) Note the date and your email here. +== 2009-08-18: thatcher.christopher@gmail.com == +(ran against github.com/thatcher/env-js) + +jQuery 1.3.2: +* 1308 tests of 1472 passed, 164 failed. == 2009-05-08: larry.karnowski@gmail.com == (ran against github.com/thatcher/env-js) diff --git a/src/css/properties.js b/src/css/properties.js index 96355bab..3db0a4eb 100644 --- a/src/css/properties.js +++ b/src/css/properties.js @@ -1,45 +1,53 @@ /* * CSS2Properties - DOM Level 2 CSS */ -var CSS2Properties = function(options){ - __extend__(this, __supportedStyles__); - this.onSetCallback = options.onSet?options.onSet:(function(){}); - this.styleIndices = {}; - __cssTextToStyles__(this, options.cssText?options.cssText:""); +var CSS2Properties = function(element){ + //this.onSetCallback = options.onSet?options.onSet:(function(){}); + this.styleIndex = __supportedStyles__(); + this.nameMap = {}; + this.__previous__ = {}; + this.__element__ = element + __cssTextToStyles__(this, element.getAttribute('style')||''); }; __extend__(CSS2Properties.prototype, { get cssText(){ - return Array.prototype.join.apply(this,[';\n']); + var css = ''; + for(var i=0;i0){ @@ -47,1066 +55,217 @@ __extend__(CSS2Properties.prototype, { }else{ return ''; } - }, - onSet:function(camelCaseName, value){ - var dashedName = __toDashed__(camelCaseName); - var definition = dashedName + ": " + value; - if (this.styleIndices[camelCaseName] !== undefined) - this[this.styleIndices[camelCaseName]] = definition; - else { - Array.prototype.push.apply(this, [definition]); - this.styleIndices[camelCaseName] = this.length - 1; - } - this.onSetCallback(); - }, + } }); +var __parseStyle__ = function(css2prop, name, value){ + css2prop.styleIndex[name] = value; + var definition = __toDashed__(name); + if(css2prop.length===undefined){ + Array.prototype.push.apply(css2prop, [definition]); + css2prop.nameMap[definition] = 0; + }else{ + if(definition in css2prop.nameMap){ + css2prop[css2prop.nameMap[definition]] = definition; + }else{ + Array.prototype.push.apply(css2prop, [definition]); + css2prop.nameMap[definition] = css2prop.length; + } + } +}; + + var __cssTextToStyles__ = function(css2props, cssText){ - var styleArray=[]; + //var styleArray=[]; var style, name, value, camelCaseName, w3cName, styles = cssText.split(';'); - css2props.styleIndices = {}; for ( var i = 0; i < styles.length; i++ ) { //$log("Adding style property " + styles[i]); style = styles[i].split(':'); + //$log(" style " + style[0]); if ( style.length == 2 ){ - //keep a reference to the original name of the style which was set - //this is the w3c style setting method. - var idx = styleArray.length; - styleArray[idx] = w3cName = styles[i]; - //camel case for dash case - value = trim(style[1]); - camelCaseName = trim(__toCamelCase__(style[0])); - css2props.styleIndices[camelCaseName] = idx; - $debug('CSS Style Name: ' + camelCaseName); - if(css2props["_" + camelCaseName]!==undefined){ - //set the value internally with camelcase name - $debug('Setting css ' + camelCaseName + ' to ' + value); - css2props["_" + camelCaseName] = value; - }; + //$log(" value " + style[1]); + __parseStyle__(css2props, style[0].replace(" ",'','g'), style[1].replace(" ",'','g')); } } - __setArray__(css2props, styleArray); }; var __toCamelCase__ = function(name) { - return name.replace(/\-(\w)/g, function(all, letter){ - return letter.toUpperCase(); - }); + //$info('__toCamelCase__'+name); + if(name){ + return name.replace(/\-(\w)/g, function(all, letter){ + return letter.toUpperCase(); + }); + } + return name; }; var __toDashed__ = function(camelCaseName) { - return camelCaseName.replace(/[A-Z]/g, function(all) { - return "-" + all.toLowerCase(); - }); + //$info("__toDashed__"+camelCaseName); + if(camelCaseName){ + return camelCaseName.replace(/[A-Z]/g, function(all) { + return "-" + all.toLowerCase(); + }); + } + return camelCaseName; }; //Obviously these arent all supported but by commenting out various sections //this provides a single location to configure what is exposed as supported. -//These getters/setters will need to get fine-tuned in the future to deal with -//the variation on input formulations -var __supportedStyles__ = (function(){ - return{ - _azimuth: "", - get azimuth() { - return this._azimuth; - }, - set azimuth(val) { - this._azimuth = val; - this.onSet("azimuth", val); - }, - _background: "", - get background() { - return this._background; - }, - set background(val) { - this._background = val; - this.onSet("background", val); - }, - _backgroundAttachment: "", - get backgroundAttachment() { - return this._backgroundAttachment; - }, - set backgroundAttachment(val) { - this._backgroundAttachment = val; - this.onSet("backgroundAttachment", val); - }, - _backgroundColor: "", - get backgroundColor() { - return this._backgroundColor; - }, - set backgroundColor(val) { - this._backgroundColor = val; - this.onSet("backgroundColor", val); - }, - _backgroundImage: "", - get backgroundImage() { - return this._backgroundImage; - }, - set backgroundImage(val) { - this._backgroundImage = val; - this.onSet("backgroundImage", val); - }, - _backgroundPosition: "", - get backgroundPosition() { - return this._backgroundPosition; - }, - set backgroundPosition(val) { - this._backgroundPosition = val; - this.onSet("backgroundPosition", val); - }, - _backgroundRepeat: "", - get backgroundRepeat() { - return this._backgroundRepeat; - }, - set backgroundRepeat(val) { - this._backgroundRepeat = val; - this.onSet("backgroundRepeat", val); - }, - _border: "", - get border() { - return this._border; - }, - set border(val) { - this._border = val; - this.onSet("border", val); - }, - _borderBottom: "", - get borderBottom() { - return this._borderBottom; - }, - set borderBottom(val) { - this._borderBottom = val; - this.onSet("borderBottom", val); - }, - _borderBottomColor: "", - get borderBottomColor() { - return this._borderBottomColor; - }, - set borderBottomColor(val) { - this._borderBottomColor = val; - this.onSet("borderBottomColor", val); - }, - _borderBottomStyle: "", - get borderBottomStyle() { - return this._borderBottomStyle; - }, - set borderBottomStyle(val) { - this._borderBottomStyle = val; - this.onSet("borderBottomStyle", val); - }, - _borderBottomWidth: "", - get borderBottomWidth() { - return this._borderBottomWidth; - }, - set borderBottomWidth(val) { - this._borderBottomWidth = val; - this.onSet("borderBottomWidth", val); - }, - _borderCollapse: "", - get borderCollapse() { - return this._borderCollapse; - }, - set borderCollapse(val) { - this._borderCollapse = val; - this.onSet("borderCollapse", val); - }, - _borderColor: "", - get borderColor() { - return this._borderColor; - }, - set borderColor(val) { - this._borderColor = val; - this.onSet("borderColor", val); - }, - _borderLeft: "", - get borderLeft() { - return this._borderLeft; - }, - set borderLeft(val) { - this._borderLeft = val; - this.onSet("borderLeft", val); - }, - _borderLeftColor: "", - get borderLeftColor() { - return this._borderLeftColor; - }, - set borderLeftColor(val) { - this._borderLeftColor = val; - this.onSet("borderLeftColor", val); - }, - _borderLeftStyle: "", - get borderLeftStyle() { - return this._borderLeftStyle; - }, - set borderLeftStyle(val) { - this._borderLeftStyle = val; - this.onSet("borderLeftStyle", val); - }, - _borderLeftWidth: "", - get borderLeftWidth() { - return this._borderLeftWidth; - }, - set borderLeftWidth(val) { - this._borderLeftWidth = val; - this.onSet("borderLeftWidth", val); - }, - _borderRight: "", - get borderRight() { - return this._borderRight; - }, - set borderRight(val) { - this._borderRight = val; - this.onSet("borderRight", val); - }, - _borderRightColor: "", - get borderRightColor() { - return this._borderRightColor; - }, - set borderRightColor(val) { - this._borderRightColor = val; - this.onSet("borderRightColor", val); - }, - _borderRightStyle: "", - get borderRightStyle() { - return this._borderRightStyle; - }, - set borderRightStyle(val) { - this._borderRightStyle = val; - this.onSet("borderRightStyle", val); - }, - _borderRightWidth: "", - get borderRightWidth() { - return this._borderRightWidth; - }, - set borderRightWidth(val) { - this._borderRightWidth = val; - this.onSet("borderRightWidth", val); - }, - _borderSpacing: "", - get borderSpacing() { - return this._borderSpacing; - }, - set borderSpacing(val) { - this._borderSpacing = val; - this.onSet("borderSpacing", val); - }, - _borderStyle: "", - get borderStyle() { - return this._borderStyle; - }, - set borderStyle(val) { - this._borderStyle = val; - this.onSet("borderStyle", val); - }, - _borderTop: "", - get borderTop() { - return this._borderTop; - }, - set borderTop(val) { - this._borderTop = val; - this.onSet("borderTop", val); - }, - _borderTopColor: "", - get borderTopColor() { - return this._borderTopColor; - }, - set borderTopColor(val) { - this._borderTopColor = val; - this.onSet("borderTopColor", val); - }, - _borderTopStyle: "", - get borderTopStyle() { - return this._borderTopStyle; - }, - set borderTopStyle(val) { - this._borderTopStyle = val; - this.onSet("borderTopStyle", val); - }, - _borderTopWidth: "", - get borderTopWidth() { - return this._borderTopWidth; - }, - set borderTopWidth(val) { - this._borderTopWidth = val; - this.onSet("borderTopWidth", val); - }, - _borderWidth: "", - get borderWidth() { - return this._borderWidth; - }, - set borderWidth(val) { - this._borderWidth = val; - this.onSet("borderWidth", val); - }, - _bottom: "", - get bottom() { - return this._bottom; - }, - set bottom(val) { - this._bottom = val; - this.onSet("bottom", val); - }, - _captionSide: "", - get captionSide() { - return this._captionSide; - }, - set captionSide(val) { - this._captionSide = val; - this.onSet("captionSide", val); - }, - _clear: "", - get clear() { - return this._clear; - }, - set clear(val) { - this._clear = val; - this.onSet("clear", val); - }, - _clip: "", - get clip() { - return this._clip; - }, - set clip(val) { - this._clip = val; - this.onSet("clip", val); - }, - _color: "", - get color() { - return this._color; - }, - set color(val) { - this._color = val; - this.onSet("color", val); - }, - _content: "", - get content() { - return this._content; - }, - set content(val) { - this._content = val; - this.onSet("content", val); - }, - _counterIncrement: "", - get counterIncrement() { - return this._counterIncrement; - }, - set counterIncrement(val) { - this._counterIncrement = val; - this.onSet("counterIncrement", val); - }, - _counterReset: "", - get counterReset() { - return this._counterReset; - }, - set counterReset(val) { - this._counterReset = val; - this.onSet("counterReset", val); - }, - _cssFloat: "", - get cssFloat() { - return this._cssFloat; - }, - set cssFloat(val) { - this._cssFloat = val; - this.onSet("cssFloat", val); - }, - _cue: "", - get cue() { - return this._cue; - }, - set cue(val) { - this._cue = val; - this.onSet("cue", val); - }, - _cueAfter: "", - get cueAfter() { - return this._cueAfter; - }, - set cueAfter(val) { - this._cueAfter = val; - this.onSet("cueAfter", val); - }, - _cueBefore: "", - get cueBefore() { - return this._cueBefore; - }, - set cueBefore(val) { - this._cueBefore = val; - this.onSet("cueBefore", val); - }, - _cursor: "", - get cursor() { - return this._cursor; - }, - set cursor(val) { - this._cursor = val; - this.onSet("cursor", val); - }, - _direction: "", - get direction() { - return this._direction; - }, - set direction(val) { - this._direction = val; - this.onSet("direction", val); - }, - _display: "", - get display() { - return this._display; - }, - set display(val) { - this._display = val; - this.onSet("display", val); - }, - _elevation: "", - get elevation() { - return this._elevation; - }, - set elevation(val) { - this._elevation = val; - this.onSet("elevation", val); - }, - _emptyCells: "", - get emptyCells() { - return this._emptyCells; - }, - set emptyCells(val) { - this._emptyCells = val; - this.onSet("emptyCells", val); - }, - _font: "", - get font() { - return this._font; - }, - set font(val) { - this._font = val; - this.onSet("font", val); - }, - _fontFamily: "", - get fontFamily() { - return this._fontFamily; - }, - set fontFamily(val) { - this._fontFamily = val; - this.onSet("fontFamily", val); - }, - _fontSize: "", - get fontSize() { - return this._fontSize; - }, - set fontSize(val) { - this._fontSize = val; - this.onSet("fontSize", val); - }, - _fontSizeAdjust: "", - get fontSizeAdjust() { - return this._fontSizeAdjust; - }, - set fontSizeAdjust(val) { - this._fontSizeAdjust = val; - this.onSet("fontSizeAdjust", val); - }, - _fontStretch: "", - get fontStretch() { - return this._fontStretch; - }, - set fontStretch(val) { - this._fontStretch = val; - this.onSet("fontStretch", val); - }, - _fontStyle: "", - get fontStyle() { - return this._fontStyle; - }, - set fontStyle(val) { - this._fontStyle = val; - this.onSet("fontStyle", val); - }, - _fontVariant: "", - get fontVariant() { - return this._fontVariant; - }, - set fontVariant(val) { - this._fontVariant = val; - this.onSet("fontVariant", val); - }, - _fontWeight: "", - get fontWeight() { - return this._fontWeight; - }, - set fontWeight(val) { - this._fontWeight = val; - this.onSet("fontWeight", val); - }, - _height: "", - get height() { - return this._height; - }, - set height(val) { - this._height = val; - this.onSet("height", val); - }, - _left: "", - get left() { - return this._left; - }, - set left(val) { - this._left = val; - this.onSet("left", val); - }, - _letterSpacing: "", - get letterSpacing() { - return this._letterSpacing; - }, - set letterSpacing(val) { - this._letterSpacing = val; - this.onSet("letterSpacing", val); - }, - _lineHeight: "", - get lineHeight() { - return this._lineHeight; - }, - set lineHeight(val) { - this._lineHeight = val; - this.onSet("lineHeight", val); - }, - _listStyle: "", - get listStyle() { - return this._listStyle; - }, - set listStyle(val) { - this._listStyle = val; - this.onSet("listStyle", val); - }, - _listStyleImage: "", - get listStyleImage() { - return this._listStyleImage; - }, - set listStyleImage(val) { - this._listStyleImage = val; - this.onSet("listStyleImage", val); - }, - _listStylePosition: "", - get listStylePosition() { - return this._listStylePosition; - }, - set listStylePosition(val) { - this._listStylePosition = val; - this.onSet("listStylePosition", val); - }, - _listStyleType: "", - get listStyleType() { - return this._listStyleType; - }, - set listStyleType(val) { - this._listStyleType = val; - this.onSet("listStyleType", val); - }, - _margin: "", - get margin() { - return this._margin; - }, - set margin(val) { - this._margin = val; - this.onSet("margin", val); - }, - _marginBottom: "", - get marginBottom() { - return this._marginBottom; - }, - set marginBottom(val) { - this._marginBottom = val; - this.onSet("marginBottom", val); - }, - _marginLeft: "", - get marginLeft() { - return this._marginLeft; - }, - set marginLeft(val) { - this._marginLeft = val; - this.onSet("marginLeft", val); - }, - _marginRight: "", - get marginRight() { - return this._marginRight; - }, - set marginRight(val) { - this._marginRight = val; - this.onSet("marginRight", val); - }, - _marginTop: "", - get marginTop() { - return this._marginTop; - }, - set marginTop(val) { - this._marginTop = val; - this.onSet("marginTop", val); - }, - _markerOffset: "", - get markerOffset() { - return this._markerOffset; - }, - set markerOffset(val) { - this._markerOffset = val; - this.onSet("markerOffset", val); - }, - _marks: "", - get marks() { - return this._marks; - }, - set marks(val) { - this._marks = val; - this.onSet("marks", val); - }, - _maxHeight: "", - get maxHeight() { - return this._maxHeight; - }, - set maxHeight(val) { - this._maxHeight = val; - this.onSet("maxHeight", val); - }, - _maxWidth: "", - get maxWidth() { - return this._maxWidth; - }, - set maxWidth(val) { - this._maxWidth = val; - this.onSet("maxWidth", val); - }, - _minHeight: "", - get minHeight() { - return this._minHeight; - }, - set minHeight(val) { - this._minHeight = val; - this.onSet("minHeight", val); - }, - _minWidth: "", - get minWidth() { - return this._minWidth; - }, - set minWidth(val) { - this._minWidth = val; - this.onSet("minWidth", val); - }, - _opacity: 1, - get opacity() { - return this._opacity; - }, - set opacity(val) { - this._opacity = val; - this.onSet("opacity", val); - }, - _orphans: "", - get orphans() { - return this._orphans; - }, - set orphans(val) { - this._orphans = val; - this.onSet("orphans", val); - }, - _outline: "", - get outline() { - return this._outline; - }, - set outline(val) { - this._outline = val; - this.onSet("outline", val); - }, - _outlineColor: "", - get outlineColor() { - return this._outlineColor; - }, - set outlineColor(val) { - this._outlineColor = val; - this.onSet("outlineColor", val); - }, - _outlineOffset: "", - get outlineOffset() { - return this._outlineOffset; - }, - set outlineOffset(val) { - this._outlineOffset = val; - this.onSet("outlineOffset", val); - }, - _outlineStyle: "", - get outlineStyle() { - return this._outlineStyle; - }, - set outlineStyle(val) { - this._outlineStyle = val; - this.onSet("outlineStyle", val); - }, - _outlineWidth: "", - get outlineWidth() { - return this._outlineWidth; - }, - set outlineWidth(val) { - this._outlineWidth = val; - this.onSet("outlineWidth", val); - }, - _overflow: "", - get overflow() { - return this._overflow; - }, - set overflow(val) { - this._overflow = val; - this.onSet("overflow", val); - }, - _overflowX: "", - get overflowX() { - return this._overflowX; - }, - set overflowX(val) { - this._overflowX = val; - this.onSet("overflowX", val); - }, - _overflowY: "", - get overflowY() { - return this._overflowY; - }, - set overflowY(val) { - this._overflowY = val; - this.onSet("overflowY", val); - }, - _padding: "", - get padding() { - return this._padding; - }, - set padding(val) { - this._padding = val; - this.onSet("padding", val); - }, - _paddingBottom: "", - get paddingBottom() { - return this._paddingBottom; - }, - set paddingBottom(val) { - this._paddingBottom = val; - this.onSet("paddingBottom", val); - }, - _paddingLeft: "", - get paddingLeft() { - return this._paddingLeft; - }, - set paddingLeft(val) { - this._paddingLeft = val; - this.onSet("paddingLeft", val); - }, - _paddingRight: "", - get paddingRight() { - return this._paddingRight; - }, - set paddingRight(val) { - this._paddingRight = val; - this.onSet("paddingRight", val); - }, - _paddingTop: "", - get paddingTop() { - return this._paddingTop; - }, - set paddingTop(val) { - this._paddingTop = val; - this.onSet("paddingTop", val); - }, - _page: "", - get page() { - return this._page; - }, - set page(val) { - this._page = val; - this.onSet("page", val); - }, - _pageBreakAfter: "", - get pageBreakAfter() { - return this._pageBreakAfter; - }, - set pageBreakAfter(val) { - this._pageBreakAfter = val; - this.onSet("pageBreakAfter", val); - }, - _pageBreakBefore: "", - get pageBreakBefore() { - return this._pageBreakBefore; - }, - set pageBreakBefore(val) { - this._pageBreakBefore = val; - this.onSet("pageBreakBefore", val); - }, - _pageBreakInside: "", - get pageBreakInside() { - return this._pageBreakInside; - }, - set pageBreakInside(val) { - this._pageBreakInside = val; - this.onSet("pageBreakInside", val); - }, - _pause: "", - get pause() { - return this._pause; - }, - set pause(val) { - this._pause = val; - this.onSet("pause", val); - }, - _pauseAfter: "", - get pauseAfter() { - return this._pauseAfter; - }, - set pauseAfter(val) { - this._pauseAfter = val; - this.onSet("pauseAfter", val); - }, - _pauseBefore: "", - get pauseBefore() { - return this._pauseBefore; - }, - set pauseBefore(val) { - this._pauseBefore = val; - this.onSet("pauseBefore", val); - }, - _pitch: "", - get pitch() { - return this._pitch; - }, - set pitch(val) { - this._pitch = val; - this.onSet("pitch", val); - }, - _pitchRange: "", - get pitchRange() { - return this._pitchRange; - }, - set pitchRange(val) { - this._pitchRange = val; - this.onSet("pitchRange", val); - }, - _position: "", - get position() { - return this._position; - }, - set position(val) { - this._position = val; - this.onSet("position", val); - }, - _quotes: "", - get quotes() { - return this._quotes; - }, - set quotes(val) { - this._quotes = val; - this.onSet("quotes", val); - }, - _richness: "", - get richness() { - return this._richness; - }, - set richness(val) { - this._richness = val; - this.onSet("richness", val); - }, - _right: "", - get right() { - return this._right; - }, - set right(val) { - this._right = val; - this.onSet("right", val); - }, - _size: "", - get size() { - return this._size; - }, - set size(val) { - this._size = val; - this.onSet("size", val); - }, - _speak: "", - get speak() { - return this._speak; - }, - set speak(val) { - this._speak = val; - this.onSet("speak", val); - }, - _speakHeader: "", - get speakHeader() { - return this._speakHeader; - }, - set speakHeader(val) { - this._speakHeader = val; - this.onSet("speakHeader", val); - }, - _speakNumeral: "", - get speakNumeral() { - return this._speakNumeral; - }, - set speakNumeral(val) { - this._speakNumeral = val; - this.onSet("speakNumeral", val); - }, - _speakPunctuation: "", - get speakPunctuation() { - return this._speakPunctuation; - }, - set speakPunctuation(val) { - this._speakPunctuation = val; - this.onSet("speakPunctuation", val); - }, - _speechRate: "", - get speechRate() { - return this._speechRate; - }, - set speechRate(val) { - this._speechRate = val; - this.onSet("speechRate", val); - }, - _stress: "", - get stress() { - return this._stress; - }, - set stress(val) { - this._stress = val; - this.onSet("stress", val); - }, - _tableLayout: "", - get tableLayout() { - return this._tableLayout; - }, - set tableLayout(val) { - this._tableLayout = val; - this.onSet("tableLayout", val); - }, - _textAlign: "", - get textAlign() { - return this._textAlign; - }, - set textAlign(val) { - this._textAlign = val; - this.onSet("textAlign", val); - }, - _textDecoration: "", - get textDecoration() { - return this._textDecoration; - }, - set textDecoration(val) { - this._textDecoration = val; - this.onSet("textDecoration", val); - }, - _textIndent: "", - get textIndent() { - return this._textIndent; - }, - set textIndent(val) { - this._textIndent = val; - this.onSet("textIndent", val); - }, - _textShadow: "", - get textShadow() { - return this._textShadow; - }, - set textShadow(val) { - this._textShadow = val; - this.onSet("textShadow", val); - }, - _textTransform: "", - get textTransform() { - return this._textTransform; - }, - set textTransform(val) { - this._textTransform = val; - this.onSet("textTransform", val); - }, - _top: "", - get top() { - return this._top; - }, - set top(val) { - this._top = val; - this.onSet("top", val); - }, - _unicodeBidi: "", - get unicodeBidi() { - return this._unicodeBidi; - }, - set unicodeBidi(val) { - this._unicodeBidi = val; - this.onSet("unicodeBidi", val); - }, - _verticalAlign: "", - get verticalAlign() { - return this._verticalAlign; - }, - set verticalAlign(val) { - this._verticalAlign = val; - this.onSet("verticalAlign", val); - }, - _visibility: "", - get visibility() { - return this._visibility; - }, - set visibility(val) { - this._visibility = val; - this.onSet("visibility", val); - }, - _voiceFamily: "", - get voiceFamily() { - return this._voiceFamily; - }, - set voiceFamily(val) { - this._voiceFamily = val; - this.onSet("voiceFamily", val); - }, - _volume: "", - get volume() { - return this._volume; - }, - set volume(val) { - this._volume = val; - this.onSet("volume", val); - }, - _whiteSpace: "", - get whiteSpace() { - return this._whiteSpace; - }, - set whiteSpace(val) { - this._whiteSpace = val; - this.onSet("whiteSpace", val); - }, - _widows: "", - get widows() { - return this._widows; - }, - set widows(val) { - this._widows = val; - this.onSet("widows", val); - }, - _width: "", - get width() { - return this._width; - }, - set width(val) { - this._width = val; - this.onSet("width", val); - }, - _wordSpacing: "", - get wordSpacing() { - return this._wordSpacing; - }, - set wordSpacing(val) { - this._wordSpacing = val; - this.onSet("wordSpacing", val); - }, - _zIndex: "", - get zIndex() { - return this._zIndex; - }, - set zIndex(val) { - this._zIndex = val; - this.onSet("zIndex", val); - } - }; -})() +var __supportedStyles__ = function(){ + return { + azimuth: null, + background: null, + backgroundAttachment: null, + backgroundColor: null, + backgroundImage: null, + backgroundPosition: null, + backgroundRepeat: null, + border: null, + borderBottom: null, + borderBottomColor: null, + borderBottomStyle: null, + borderBottomWidth: null, + borderCollapse: null, + borderColor: null, + borderLeft: null, + borderLeftColor: null, + borderLeftStyle: null, + borderLeftWidth: null, + borderRight: null, + borderRightColor: null, + borderRightStyle: null, + borderRightWidth: null, + borderSpacing: null, + borderStyle: null, + borderTop: null, + borderTopColor: null, + borderTopStyle: null, + borderTopWidth: null, + borderWidth: null, + bottom: null, + captionSide: null, + clear: null, + clip: null, + color: null, + content: null, + counterIncrement: null, + counterReset: null, + cssFloat: null, + cue: null, + cueAfter: null, + cueBefore: null, + cursor: null, + direction: 'ltr', + display: 'block', + elevation: null, + emptyCells: null, + font: null, + fontFamily: null, + fontSize: "1em", + fontSizeAdjust: null, + fontStretch: null, + fontStyle: null, + fontVariant: null, + fontWeight: null, + height: '1px', + left: null, + letterSpacing: null, + lineHeight: null, + listStyle: null, + listStyleImage: null, + listStylePosition: null, + listStyleType: null, + margin: null, + marginBottom: "0px", + marginLeft: "0px", + marginRight: "0px", + marginTop: "0px", + markerOffset: null, + marks: null, + maxHeight: null, + maxWidth: null, + minHeight: null, + minWidth: null, + opacity: 1, + orphans: null, + outline: null, + outlineColor: null, + outlineOffset: null, + outlineStyle: null, + outlineWidth: null, + overflow: null, + overflowX: null, + overflowY: null, + padding: null, + paddingBottom: "0px", + paddingLeft: "0px", + paddingRight: "0px", + paddingTop: "0px", + page: null, + pageBreakAfter: null, + pageBreakBefore: null, + pageBreakInside: null, + pause: null, + pauseAfter: null, + pauseBefore: null, + pitch: null, + pitchRange: null, + position: null, + quotes: null, + richness: null, + right: null, + size: null, + speak: null, + speakHeader: null, + speakNumeral: null, + speakPunctuation: null, + speechRate: null, + stress: null, + tableLayout: null, + textAlign: null, + textDecoration: null, + textIndent: null, + textShadow: null, + textTransform: null, + top: null, + unicodeBidi: null, + verticalAlign: null, + visibility: null, + voiceFamily: null, + volume: null, + whiteSpace: null, + widows: null, + width: '1px', + wordSpacing: null, + zIndex: 1 + }; +}; + + +for(var style in __supportedStyles__()){ + (function(name){ + if(name === 'width' || name === 'height'){ + CSS2Properties.prototype.__defineGetter__(name, function(){ + if(this.getPropertyValue('display')==='none'){ + return '0px'; + } + //$info(name+' = '+this.getPropertyValue(name)); + return this.getPropertyValue(name); + }); + CSS2Properties.prototype.__defineSetter__(name, function(value){ + this.setProperty(name, value); + }); + }else{ + CSS2Properties.prototype.__defineGetter__(name, function(){ + //$log(" css2properties.get " + name); + return this.getPropertyValue(name); + }); + CSS2Properties.prototype.__defineSetter__(name, function(value){ + this.setProperty(name, value); + }); + } + })(style); +}; + $w.CSS2Properties = CSS2Properties; \ No newline at end of file diff --git a/src/dom/attr.js b/src/dom/attr.js index 1a0477c4..6dfe0d16 100644 --- a/src/dom/attr.js +++ b/src/dom/attr.js @@ -36,13 +36,16 @@ __extend__(DOMAttr.prototype, { this.nodeValue = value; }, get specified(){ - return (this.value.length > 0); + return (this!==null&&this!=undefined); }, get nodeType(){ return DOMNode.ATTRIBUTE_NODE; }, get xml(){ - return this.nodeName + '="' + __escapeXML__(this.nodeValue) + '" '; + if(this.nodeValue) + return this.nodeName + '="' + __escapeXML__(this.nodeValue) + '" '; + else + return ''; }, toString : function(){ return "Attr #" + this._id + " " + this.name; diff --git a/src/dom/document.js b/src/dom/document.js index 240cffce..24be9220 100644 --- a/src/dom/document.js +++ b/src/dom/document.js @@ -48,9 +48,15 @@ __extend__(DOMDocument.prototype, { get parentWindow(){ return this._parentWindow; }, - loadXML : function(xmlStr) { + loadXML : function(xmlString) { // create SAX Parser - var parser = new XMLP(xmlStr+''); + var htmlString; + if($env.fixHTML){ + htmlString = $env.cleanHTML(xmlString); + }else{ + htmlString = xmlString + } + var parser = new XMLP(htmlString+''); // create DOM Document if(this === $document){ @@ -340,11 +346,7 @@ __extend__(DOMDocument.prototype, { }, get defaultView(){ //TODO: why isnt this just 'return $w;'? return { getComputedStyle: function(elem){ - return { getPropertyValue: function(prop){ - prop = prop.replace(/\-(\w)/g,function(m,c){ return c.toUpperCase(); }); - var val = elem.style[prop]; - if ( prop == "opacity" && val == "" ){ val = "1"; }return val; - }}; + return $w.getComputedStyle(elem); }}; }, _genId : function() { diff --git a/src/dom/element.js b/src/dom/element.js index 4f88b2df..e6cd6b5e 100644 --- a/src/dom/element.js +++ b/src/dom/element.js @@ -9,7 +9,7 @@ $debug("Defining Element"); var DOMElement = function(ownerDocument) { this.DOMNode = DOMNode; this.DOMNode(ownerDocument); - this.id = ""; // the ID of the element + //this.id = null; // the ID of the element }; DOMElement.prototype = new DOMNode; __extend__(DOMElement.prototype, { @@ -30,17 +30,17 @@ __extend__(DOMElement.prototype, { if (attr) { ret = attr.value; } - return ret; // if Attribute exists, return its value, otherwise, return "" + return ret; // if Attribute exists, return its value, otherwise, return null }, setAttribute : function (name, value) { // if attribute exists, use it var attr = this.attributes.getNamedItem(name); - var value = value+''; + //I had to add this check becuase as the script initializes //the id may be set in the constructor, and the html element //overrides the id property with a getter/setter. if(__ownerDocument__(this)){ - if (!attr) { + if (attr===null||attr===undefined) { attr = __ownerDocument__(this).createAttribute(name); // otherwise create it } @@ -58,15 +58,17 @@ __extend__(DOMElement.prototype, { } } - if (__isIdDeclaration__(name)) { - // this.id = value; // cache ID for getElementById() - } + /*if (__isIdDeclaration__(name)) { + this.id = value; // cache ID for getElementById() + }*/ // assign values to properties (and aliases) attr.value = value; // add/replace Attribute in NamedNodeMap this.attributes.setNamedItem(attr); + }else{ + $warn('Element has no owner document '+this.tagName+'\n\t cant set attribute ' + name + ' = '+value ); } }, removeAttribute : function removeAttribute(name) { diff --git a/src/dom/implementation.js b/src/dom/implementation.js index f25920cf..9b3b4f0f 100644 --- a/src/dom/implementation.js +++ b/src/dom/implementation.js @@ -12,7 +12,7 @@ var DOMImplementation = function() { this.errorChecking = true; // by default, test for exceptions }; -var $handleEndOfNormalOrEmptyElement = function(node, doc, p){ +var __endHTMLElement__ = function(node, doc, p){ if(node.nodeName.toLowerCase() == 'script'){ p.replaceEntities = true; $env.loadLocalScript(node, p); @@ -281,7 +281,7 @@ function __parseLoop__(impl, doc, p) { } else if(iEvt == XMLP._ELM_E) { // End-Element Event - $handleEndOfNormalOrEmptyElement(iNodeParent, doc, p); + __endHTMLElement__(iNodeParent, doc, p); iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree } @@ -369,7 +369,7 @@ function __parseLoop__(impl, doc, p) { } - $handleEndOfNormalOrEmptyElement(iNode, doc, p); + __endHTMLElement__(iNode, doc, p); iNodeParent.appendChild(iNode); // attach Element to parentNode } else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) { // TextNode and entity Events diff --git a/src/dom/namednodemap.js b/src/dom/namednodemap.js index 06a84901..59f0a7a4 100644 --- a/src/dom/namednodemap.js +++ b/src/dom/namednodemap.js @@ -60,12 +60,12 @@ __extend__(DOMNamedNodeMap.prototype, { throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)); } else { this[itemIndex] = arg; // over-write existing NamedNode - this[arg.name] = arg; + this[arg.name.toLowerCase()] = arg; } } else { // add new NamedNode Array.prototype.push.apply(this, [arg]); - this[arg.name] = arg; + this[arg.name.toLowerCase()] = arg; } arg.ownerElement = this.parentNode; // update ownerElement @@ -213,12 +213,13 @@ var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) { for (var i=0; i/g; var quotRegEx = /"/g; diff --git a/src/dom/text.js b/src/dom/text.js index 6d09d436..0bafa007 100644 --- a/src/dom/text.js +++ b/src/dom/text.js @@ -64,6 +64,7 @@ __extend__(DOMText.prototype,{ }, get xml(){ return __escapeXML__(""+ this.nodeValue); + //return ""+ this.nodeValue; }, toString: function(){ return "Text #" + this._id; diff --git a/src/html/a.js b/src/html/a.js index ff88694a..62082826 100644 --- a/src/html/a.js +++ b/src/html/a.js @@ -10,7 +10,7 @@ var HTMLAnchorElement = function(ownerDocument) { HTMLAnchorElement.prototype = new HTMLElement; __extend__(HTMLAnchorElement.prototype, { get accessKey() { - return this.getAttribute("accesskey") || ""; + return this.getAttribute("accesskey"); }, set accessKey(val) { @@ -18,7 +18,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get charset() { - return this.getAttribute("charset") || ""; + return this.getAttribute("charset"); }, set charset(val) { @@ -26,7 +26,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get coords() { - return this.getAttribute("coords") || ""; + return this.getAttribute("coords"); }, set coords(val) { @@ -34,7 +34,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get href() { - return this.getAttribute("href") || ""; + return this.getAttribute("href"); }, set href(val) { @@ -42,7 +42,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get hreflang() { - return this.getAttribute("hreflang") || ""; + return this.getAttribute("hreflang"); }, set hreflang(val) { @@ -50,7 +50,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get name() { - return this.getAttribute("name") || ""; + return this.getAttribute("name"); }, set name(val) { @@ -58,7 +58,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get rel() { - return this.getAttribute("rel") || ""; + return this.getAttribute("rel"); }, set rel(val) { @@ -66,7 +66,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get rev() { - return this.getAttribute("rev") || ""; + return this.getAttribute("rev"); }, set rev(val) { @@ -74,23 +74,15 @@ __extend__(HTMLAnchorElement.prototype, { }, get shape() { - return this.getAttribute("shape") || ""; + return this.getAttribute("shape"); }, set shape(val) { return this.setAttribute("shape",val); - }, - get tabIndex() { - return this.getAttribute("tabindex") || ""; - - }, - set tabIndex(val) { - return this.setAttribute("tabindex",val); - }, get target() { - return this.getAttribute("target") || ""; + return this.getAttribute("target"); }, set target(val) { @@ -98,7 +90,7 @@ __extend__(HTMLAnchorElement.prototype, { }, get type() { - return this.getAttribute("type") || ""; + return this.getAttribute("type"); }, set type(val) { diff --git a/src/html/area.js b/src/html/area.js index d216339a..0752060d 100644 --- a/src/html/area.js +++ b/src/html/area.js @@ -39,12 +39,12 @@ __extend__(HTMLAreaElement.prototype, { //TODO return 0; }, - get tabIndex(){ + /*get tabIndex(){ return this.getAttribute('tabindex'); }, set tabIndex(value){ this.setAttribute('tabindex',value); - }, + },*/ get target(){ return this.getAttribute('target'); }, diff --git a/src/html/button.js b/src/html/button.js index 5e679f77..c33bf67a 100644 --- a/src/html/button.js +++ b/src/html/button.js @@ -21,12 +21,12 @@ __extend__(HTMLButtonElement.prototype, { set accessKey(value){ this.setAttribute('accesskey',value); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',Number(value)); - }, + },*/ get type(){ return this.getAttribute('type'); }, diff --git a/src/html/document.js b/src/html/document.js index 6187261c..0fc1aa6b 100644 --- a/src/html/document.js +++ b/src/html/document.js @@ -67,7 +67,7 @@ __extend__(HTMLDocument.prototype, { else if(tagName.match(/SELECT/)) {node = new HTMLSelectElement(this);} else if(tagName.match(/STYLE/)) {node = new HTMLStyleElement(this);} else if(tagName.match(/TABLE/)) {node = new HTMLTableElement(this);} - else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLSectionElement(this);} + else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLTableSectionElement(this);} else if(tagName.match(/TD|TH/)) {node = new HTMLTableCellElement(this);} else if(tagName.match(/TEXTAREA/)) {node = new HTMLTextAreaElement(this);} else if(tagName.match(/TITLE/)) {node = new HTMLTitleElement(this);} diff --git a/src/html/element.js b/src/html/element.js index 285c450b..586c4d18 100644 --- a/src/html/element.js +++ b/src/html/element.js @@ -11,11 +11,10 @@ var HTMLElement = function(ownerDocument) { HTMLElement.prototype = new DOMElement; __extend__(HTMLElement.prototype, { get className() { - return this.getAttribute("class")||""; - + return this.getAttribute("class")||''; }, - set className(val) { - return this.setAttribute("class",trim(val)); + set className(value) { + return this.setAttribute("class",trim(value)); }, get dir() { @@ -27,7 +26,7 @@ __extend__(HTMLElement.prototype, { }, get id(){ - return this.getAttribute('id')||''; + return this.getAttribute('id'); }, set id(id){ @@ -57,7 +56,7 @@ __extend__(HTMLElement.prototype, { doc = null; }, get lang() { - return this.getAttribute("lang")||""; + return this.getAttribute("lang"); }, set lang(val) { @@ -86,33 +85,36 @@ __extend__(HTMLElement.prototype, { scrollRight: 0, get style(){ if(this.$css2props === null){ - this.updateCss2Props(); + __updateCss2Props__(this); } return this.$css2props }, - updateCss2Props: function() { - this.$css2props = new CSS2Properties({ - onSet: (function(that) { - return function() { that.__setAttribute("style", this.cssText); } - })(this), - cssText:this.getAttribute("style") - }); - }, - __setAttribute: HTMLElement.prototype.setAttribute, setAttribute: function (name, value) { - this.__setAttribute(name, value); + DOMElement.prototype.setAttribute.apply(this,[name, value]); if (name === "style") { - this.updateCss2Props(); + __updateCss2Props__(this); } }, get title() { - return this.getAttribute("title")||""; + return this.getAttribute("title"); }, - set title(val) { - return this.setAttribute("title",val); + set title(value) { + return this.setAttribute("title", value); }, + get tabIndex(){ + var ti = this.getAttribute('tabindex'); + if(ti!==null) + return Number(ti); + else + return 0; + }, + set tabIndex(value){ + if(value===undefined||value===null) + value = 0; + this.setAttribute('tabindex',Number(value)); + }, //Not in the specs but I'll leave it here for now. get outerHTML(){ return this.xml; @@ -125,17 +127,9 @@ __extend__(HTMLElement.prototype, { }, onclick: function(event){ - __eval__(this.getAttribute('onclick')||'', this) + __eval__(this.getAttribute('onclick')||'', this); }, - // non-ECMA function, but no other way for click events to enter env.js - __click__: function(element){ - var event = new Event({ - target:element, - currentTarget:element - }); - event.initEvent("click"); - element.dispatchEvent(event); - }, + ondblclick: function(event){ __eval__(this.getAttribute('ondblclick')||'', this); @@ -194,6 +188,10 @@ var __eval__ = function(script, startingNode){ } }; +var __updateCss2Props__ = function(elem){ + elem.$css2props = new CSS2Properties(elem); +}; + var __registerEventAttrs__ = function(elm){ if(elm.hasAttribute('onclick')){ elm.addEventListener('click', elm.onclick ); @@ -228,6 +226,15 @@ var __registerEventAttrs__ = function(elm){ return elm; }; +// non-ECMA function, but no other way for click events to enter env.js +var __click__ = function(element){ + var event = new Event({ + target:element, + currentTarget:element + }); + event.initEvent("click"); + element.dispatchEvent(event); +}; var __submit__ = function(element){ var event = new Event({ target:element, diff --git a/src/html/form.js b/src/html/form.js index 52fa094c..dd29f37f 100644 --- a/src/html/form.js +++ b/src/html/form.js @@ -49,7 +49,7 @@ __extend__(HTMLFormElement.prototype,{ }, get name() { - return this.getAttribute("name") || ""; + return this.getAttribute("name"); }, set name(val) { @@ -57,7 +57,7 @@ __extend__(HTMLFormElement.prototype,{ }, get target() { - return this.getAttribute("target") || ""; + return this.getAttribute("target"); }, set target(val) { diff --git a/src/html/input.js b/src/html/input.js index aabdcbab..9ad871f6 100644 --- a/src/html/input.js +++ b/src/html/input.js @@ -86,12 +86,12 @@ __extend__(HTMLInputElement.prototype, { set src(value){ this.setAttribute('src', value); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',Number(value)); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -105,6 +105,8 @@ __extend__(HTMLInputElement.prototype, { return this.getAttribute('value'); }, set value(value){ + if(this.defaultValue===null&&this.value!==null) + this.defaultValue = this.value; this.setAttribute('value',value); }, blur:function(){ diff --git a/src/html/object.js b/src/html/object.js index dc51c959..699e5b20 100644 --- a/src/html/object.js +++ b/src/html/object.js @@ -56,12 +56,12 @@ __extend__(HTMLObjectElement.prototype, { set standby(value){ this.setAttribute('standby',value); }, - get tabIndex(){ + /*get tabIndex(){ return this.getAttribute('tabindex'); }, set tabIndex(value){ this.setAttribute('tabindex',value); - }, + },*/ get type(){ return this.getAttribute('type'); }, diff --git a/src/html/option.js b/src/html/option.js index b662a8c1..21a9dfae 100644 --- a/src/html/option.js +++ b/src/html/option.js @@ -50,6 +50,8 @@ __extend__(HTMLOptionElement.prototype, { return (this.getAttribute('selected')=='selected'); }, set selected(value){ + if(this.defaultSelected===null&&this.selected!==null) + this.defaultSelected = this.selected; this.setAttribute('selected', (value ? 'selected' :'')); }, get value(){ diff --git a/src/html/script.js b/src/html/script.js index 5efe0bb5..f3b6eb44 100644 --- a/src/html/script.js +++ b/src/html/script.js @@ -23,6 +23,10 @@ __extend__(HTMLScriptElement.prototype, { return this.nodeValue; }, + set text(value){ + this.nodeValue = value; + $env.loadInlineScript(this); + }, get htmlFor(){ return this.getAttribute('for'); }, diff --git a/src/html/select.js b/src/html/select.js index 7cc45f44..9f5b8419 100644 --- a/src/html/select.js +++ b/src/html/select.js @@ -85,12 +85,12 @@ __extend__(HTMLSelectElement.prototype, { set size(value){ this.setAttribute('size',value); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',value); - }, + },*/ add : function(){ __add__(this); }, diff --git a/src/html/table.js b/src/html/table.js index c3ee3e33..8a13efca 100644 --- a/src/html/table.js +++ b/src/html/table.js @@ -59,24 +59,29 @@ __extend__(HTMLTableElement.prototype, { }, appendChild : function (child) { - - var tagName = child.tagName.toLowerCase(); - if (tagName === "tr") { - // need an implcit to contain this... - if (!this.currentBody) { - this.currentBody = document.createElement("tbody"); - - DOMNode.prototype.appendChild.apply(this, [this.currentBody]); + + var tagName; + if(child.tagName){ + tagName = child.tagName.toLowerCase(); + if (tagName === "tr") { + // need an implcit to contain this... + if (!this.currentBody) { + this.currentBody = document.createElement("tbody"); + + DOMNode.prototype.appendChild.apply(this, [this.currentBody]); + } + + return this.currentBody.appendChild(child); + + } else if (tagName === "tbody" || tagName === "tfoot" && this.currentBody) { + this.currentBody = child; + return DOMNode.prototype.appendChild.apply(this, arguments); + + } else { + return DOMNode.prototype.appendChild.apply(this, arguments); } - - return this.currentBody.appendChild(child); - - } else if (tagName === "tbody" || tagName === "tfoot" && this.currentBody) { - this.currentBody = child; - return DOMNode.prototype.appendChild.apply(this, arguments); - - } else { - return DOMNode.prototype.appendChild.apply(this, arguments); + }else{ + $error('HTMLTableElement.appendChild => child.tagName should not be undefined here... Fix ME!'); } }, diff --git a/src/html/textarea.js b/src/html/textarea.js index 8ffe0e53..b58fcab7 100644 --- a/src/html/textarea.js +++ b/src/html/textarea.js @@ -52,6 +52,12 @@ __extend__(HTMLTextAreaElement.prototype, { set disabled(value){ this.setAttribute('disabled', (value ? 'disabled' :'')); }, + get maxLength(){ + return Number(this.getAttribute('maxlength')||'0'); + }, + set maxLength(value){ + this.setAttribute('maxlength', value); + }, get name(){ return this.getAttribute('name')||''; }, @@ -64,12 +70,12 @@ __extend__(HTMLTextAreaElement.prototype, { set readOnly(value){ this.setAttribute('readonly', (value ? 'readonly' :'')); }, - get tabIndex(){ + /*get tabIndex(){ return Number(this.getAttribute('tabindex')); }, set tabIndex(value){ this.setAttribute('tabindex',Number(value)); - }, + },*/ get type(){ return this.getAttribute('type'); }, @@ -77,10 +83,12 @@ __extend__(HTMLTextAreaElement.prototype, { this.setAttribute('type',value); }, get value(){ - return this.getAttribute('value'); + return this.text; }, set value(value){ - this.setAttribute('value',value); + if(this.defaultValue===null&&this.text!==null) + this.defaultValue = this.text; + return this.text = value; }, blur:function(){ __blur__(this); diff --git a/src/platform/core.js b/src/platform/core.js index e02f1ff1..38380427 100644 --- a/src/platform/core.js +++ b/src/platform/core.js @@ -104,6 +104,7 @@ var Envjs = function(){ "text/envjs" :true }; + $env.onScriptLoadError = function(){}; $env.loadLocalScript = function(script, parser){ $env.debug("loading script "); var types, type, src, i, base, @@ -151,6 +152,7 @@ var Envjs = function(){ } }catch(e){ $env.error("Error loading script.", e); + $env.onScriptLoadError(script); }finally{ if(parser){ parser.appendFragment(docWrites.join('')); diff --git a/src/platform/rhino.js b/src/platform/rhino.js index 17e06312..d463d71d 100644 --- a/src/platform/rhino.js +++ b/src/platform/rhino.js @@ -36,63 +36,39 @@ var timers = []; - $env.timer = function(fn, interval){ - this.fn = fn; - this.interval = interval; - this.at = Date.now() + interval; - this.index = timers.length; - timers[this.index] = this; - }; - - $env.timer.prototype.start = function(){}; - $env.timer.prototype.stop = function(){ - delete timers[this.index]; - }; - - // wait === null: execute any immediately runnable timers and return - // wait(n) (n > 0): execute any timers as they fire but no longer than n ms - // wait(0): execute any timers as they fire, waiting until there are none left - $env.wait = function(wait) { - var i; - var empty; - var after; - var now; - var timer; - var sleep; - if (wait !== 0 && wait !== null && wait !== undefined){ - wait += Date.now(); - } - for (;;) { - for (i in timers){ - timer = timers[i]; - now = Date.now(); - if (timer.at <= now){ - f = timer.fn; - f(); - timer.at += timer.interval; - } - } - empty = true; - sleep = null; - now = Date.now(); - for (i in timers){ - empty = false; - timer = timers[i]; - after = timer.at - now - sleep = (sleep === null || after < sleep) ? after : sleep; - } - sleep = sleep < 0 ? 0 : sleep; - if (empty || - ( wait !== 0 ) && - ( ( sleep > 0 && !wait ) || ( Date.now() + sleep > wait ) ) ) { - break; - } - if (sleep) { - java.lang.Thread.currentThread().sleep(sleep); - } - } + //For Java the window.timer is created using the java.lang.Thread in combination + //with the java.lang.Runnable + $env.timer = function(fn, time){ + var running = true; + + var run = sync(function(){ //while happening only thing in this timer + //$env.debug("running timed function"); + fn(); + }); + var _this = this; + var thread = new java.lang.Thread(new java.lang.Runnable({ + run: function(){ + try { + while (running){ + java.lang.Thread.currentThread().sleep(time); + run.apply(_this); + } + }catch(e){ + $env.error("erro running timed function", e); + _this.stop(); + $env.onInterrupt(); + }; + } + })); + this.start = function(){ + thread.start(); + }; + this.stop = sync(function(num){ + running = false; + thread.interrupt(); + }) }; - + //Since we're running in rhino I guess we can safely assume //java is 'enabled'. I'm sure this requires more thought //than I've given it here @@ -101,11 +77,27 @@ //Used in the XMLHttpRquest implementation to run a // request in a seperate thread + $env.onInterrupt = function(){}; $env.runAsync = function(fn){ $env.debug("running async"); - (new java.lang.Thread(new java.lang.Runnable({ - run: fn - }))).start(); + var running = true; + + var run = sync(function(){ //while happening only thing in this timer + //$env.debug("running timed function"); + fn(); + }); + + var async = (new java.lang.Thread(new java.lang.Runnable({ + run: run + }))); + + try{ + async.start(); + }catch(e){ + $env.error("error while running async", e); + async.interrupt(); + $env.onInterrupt(); + } }; //Used to write to a local file @@ -145,14 +137,22 @@ var url = java.net.URL(xhr.url);//, $w.location); var connection; if ( /^file\:/.test(url) ) { - if ( xhr.method == "PUT" ) { - var text = data || "" ; - $env.writeToFile(text, url); - } else if ( xhr.method == "DELETE" ) { - $env.deleteFile(url); - } else { - connection = url.openConnection(); - connection.connect(); + try{ + if ( xhr.method == "PUT" ) { + var text = data || "" ; + $env.writeToFile(text, url); + } else if ( xhr.method == "DELETE" ) { + $env.deleteFile(url); + } else { + connection = url.openConnection(); + connection.connect(); + } + }catch(e){ + $env.error('failed to open file '+ url, e); + connection = null; + xhr.readyState = 4; + xhr.statusText = "Local File Protocol Error"; + xhr.responseText = "

"+ e+ "

"; } } else { connection = url.openConnection(); @@ -220,6 +220,7 @@ } if(responseHandler){ + $env.debug('calling ajax response handler'); responseHandler(); } }; @@ -229,21 +230,45 @@ htmlDocBuilder.setValidating(false); var htmlCleaner, - cleanDomSerializer, - cleanProperties; - $env.parseHTML = function(htmlstring){ - var domdoc;//what's up dom doc? - if($env.cleanHTML){ - htmlCleaner = htmlCleaner||new org.htmlcleaner.HtmlCleaner(); - cleanDomSerializer = cleanDomSerializer||new org.htmlcleaner.DomSerializer(); - cleanProperties = cleanProperties||new org.htmlcleaner.CleanerProperties(); - domdoc = org.htmlcleaner.DomSerializer.createDOM(htmlCleaner.clean(htmlstring)); - }else{ - domdoc = htmlDocBuilder.newDocumentBuilder().parse( - new java.io.ByteArrayInputStream( - (new java.lang.String(htmlstring)).getBytes("UTF8"))); + cleanXMLSerializer, + cleanerProperties, + htmlTransformer, + htmlOutputProps; + $env.fixHTML = false; + $env.cleanHTML = function(xmlString){ + var htmlString; + $env.debug('Cleaning html :\n'+xmlString); + if(!htmlCleaner){ + cleanerProperties = new org.htmlcleaner.CleanerProperties(); + cleanerProperties.setOmitHtmlEnvelope(true); + cleanerProperties.setTranslateSpecialEntities(true); + cleanerProperties.setAdvancedXmlEscape(true); + cleanerProperties.setUseCdataForScriptAndStyle(false); + cleanerProperties.setOmitXmlDeclaration(true); + htmlCleaner = new org.htmlcleaner.HtmlCleaner(cleanerProperties); + cleanXMLSerializer = new org.htmlcleaner.SimpleXmlSerializer(cleanerProperties); + //may have been initialized in $env.xslt + /*transformerFactory = transformerFactory|| + Packages.javax.xml.transform.TransformerFactory.newInstance(); + htmlTransformer = transformerFactory.newTransformer(); + htmlOutputProps = new java.util.Properties(); + htmlOutputProps.put(javax.xml.transform.OutputKeys.METHOD, "xml"); + htmlOutputProps.put(javax.xml.transform.OutputKeys.INDENT , "no"); + htmlOutputProps.put(javax.xml.transform.OutputKeys.ENCODING , "UTF-8"); + htmlOutputProps.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION , "yes"); + htmlTransformer.setOutputProperties(htmlOutputProps)*/ } - return domdoc; + + /*var node = cleanXMLSerializer.createDOM(htmlCleaner.clean(xmlString)), + outText = new java.io.StringWriter(); + htmlTransformer.transform( + new javax.xml.transform.dom.DOMSource(node), + new javax.xml.transform.stream.StreamResult(outText)); + + htmlString = outText.toString()+'';*/ + htmlString = cleanXMLSerializer.getXmlAsString(htmlCleaner.clean(xmlString)); + //$env.info('Cleaned html :\n'+htmlString); + return htmlString; }; var xmlDocBuilder = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance(); @@ -311,7 +336,6 @@ $env.loadInlineScript = function(script){ - $env.debug("loading inline script :" + script.text); var tmpFile = $env.writeToTempFile(script.text, 'js') ; $env.debug("loading " + tmpFile); $env.load(tmpFile); diff --git a/src/window/css.js b/src/window/css.js index c9c15c1e..266546af 100644 --- a/src/window/css.js +++ b/src/window/css.js @@ -6,6 +6,7 @@ $debug("Initializing Window CSS"); // attributes and values used to render the specified element in this // window. Any length values are always expressed in pixel, or // absolute values. + $w.getComputedStyle = function(elt, pseudo_elt){ //TODO //this is a naive implementation diff --git a/src/window/event.js b/src/window/event.js index 2223ae2f..c37697c8 100644 --- a/src/window/event.js +++ b/src/window/event.js @@ -9,7 +9,7 @@ var $events = [], $onunload; $w.addEventListener = function(type, fn){ - //$log("adding event listener " + type); + $debug("adding event listener \n\t" + type +" \n\tfor "+this+" with callback \n\t"+fn); if ( !this.uuid ) { this.uuid = $events.length; $events[this.uuid] = {}; @@ -46,25 +46,29 @@ $w.dispatchEvent = function(event, bubbles){ bubbles = true; if (!event.target) { + $debug("no event target : "+event.target); event.target = this; } $debug("event target: " + event.target); - if ( event.type ) { + if ( event.type && this.nodeType || this===window) { + $debug("nodeType: " + this.nodeType); if ( this.uuid && $events[this.uuid][event.type] ) { var _this = this; $events[this.uuid][event.type].forEach(function(fn){ $debug('calling event handler '+fn+' on target '+_this); - fn.call( _this, event ); + fn( event ); }); } if (this["on" + event.type]) { - $debug('calling event handler '+event.type+' on target '+this); - this["on" + event.type].call(this, event); + $debug('calling event handler on'+event.type+' on target '+this); + this["on" + event.type](event); } + }else{ + $debug("non target: " + event.target + " \n this->"+this); } if (bubbles && this.parentNode){ - this.parentNode.dispatchEvent.call(this.parentNode,event); + this.parentNode.dispatchEvent(event); } }; diff --git a/src/window/timer.js b/src/window/timer.js index 31234cee..0096bf10 100644 --- a/src/window/timer.js +++ b/src/window/timer.js @@ -9,33 +9,11 @@ $debug("Initializing Window Timer."); var $timers = []; window.setTimeout = function(fn, time){ - var num = $timers.length; - var tfn; - - if (typeof fn == 'string') { - tfn = function() { - eval(fn); - window.clearInterval(num); - }; - } else { - tfn = function() { - fn(); - window.clearInterval(num); - }; - } - - if (time === 0){ - if (typeof fn == 'string') - eval(fn); - else - fn(); - } - else { - $debug("Creating timer number "+num); - $timers[num] = new $env.timer(tfn, time); - $timers[num].start(); - return num; - } + var num; + return num = window.setInterval(function(){ + fn(); + window.clearInterval(num); + }, time); }; window.setInterval = function(fn, time){ @@ -50,7 +28,7 @@ window.setInterval = function(fn, time){ if(time===0){ fn(); }else{ - $debug("Creating timer number "+num); + //$debug("Creating timer number "+num); $timers[num] = new $env.timer(fn, time); $timers[num].start(); } @@ -58,12 +36,11 @@ window.setInterval = function(fn, time){ }; window.clearInterval = window.clearTimeout = function(num){ + //$log("clearing interval "+num); if ( $timers[num] ) { - $debug("Deleting timer number "+num); $timers[num].stop(); delete $timers[num]; } }; - -window.$wait = function(wait){ $env.wait(wait); } \ No newline at end of file + \ No newline at end of file diff --git a/src/window/xhr.js b/src/window/xhr.js index 538442ad..0f297160 100644 --- a/src/window/xhr.js +++ b/src/window/xhr.js @@ -40,10 +40,21 @@ XMLHttpRequest.prototype = { $debug("parsing response text into xml document"); responseXML = $domparser.parseFromString(_this.responseText+""); return responseXML; - } catch(e) { return null;/*TODO: need to flag an error here*/} + } catch(e) { + $error('response XML does not apear to be well formed xml', e); + responseXML = $domparser.parseFromString(""+ + "

parse error

"); + return responseXML; + } } - }else{return null;} + }else{ + $env.warn('response XML does not apear to be xml'); + return null; + } }); + _this.__defineSetter__("responseXML",function(xml){ + responseXML = xml; + }); }, data); _this.onreadystatechange(); } diff --git a/test/test.js b/test/test.js index c9146293..c7f260b7 100644 --- a/test/test.js +++ b/test/test.js @@ -31,7 +31,7 @@ window.onload = function(){ "test/unit/frame.js", "test/unit/events.js", "test/unit/parser.js", - "test/unit/timer.js", + /*"test/unit/timer.js",*/ //NOTE: keep this test last because Prototype pollutes //the namespace and several DOM objects "test/unit/prototypecompat.js" diff --git a/test/unit/events.js b/test/unit/events.js index 15f6d5e1..ec517f8d 100644 --- a/test/unit/events.js +++ b/test/unit/events.js @@ -23,6 +23,15 @@ module("events"); // to the *Checks convenience functions). +var __click__ = function(element){ + var event = new Event({ + target:element, + currentTarget:element + }); + event.initEvent("click"); + element.dispatchEvent(event); +} + function loadChecks(tag, imgCount, count){ expect(4); @@ -134,7 +143,7 @@ test("Check that an event which should bubble actually does", function() { // simulate a "click" user action var img = document.getElementById('eventsFrame').contentDocument. getElementById('theIMG'); - img.__click__(img); + __click__(img); clickChecks("Click img", 1, 1); }); @@ -143,7 +152,7 @@ test("Bubbling event ONLY bubbles 'up'", function() { // simulate a "click" user action var td = document.getElementById('eventsFrame').contentDocument. getElementById('theTD'); - td.__click__(td); + __click__(td); clickChecks("Click td", 2, 1); }); diff --git a/test/unit/frame.js b/test/unit/frame.js index 26a5b683..d90f8742 100644 --- a/test/unit/frame.js +++ b/test/unit/frame.js @@ -149,12 +149,13 @@ test("IFRAMEs can be nested, created dynamically", function() { newIframe.setAttribute("onload", "iframeOnloadHandler();"); var bottomBody = bottomIframe.contentDocument. getElementsByTagName('body')[0]; + bottomBody.appendChild(newIframe); newIframe.src = "html/iframeN.html"; bottomIframe = newIframe; - + //////////////////////////////////////// // verify contents of just-loaded iframe mtch = bottomIframe.contentDocument.getElementById('nestingLevel'). diff --git a/test/unit/parser.js b/test/unit/parser.js index c60e2857..4a95b3ab 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -89,4 +89,24 @@ test("Toggle entity replacement", function() { equals(XMLP._ELM_E, p.next(), "Closing body tag"); // _ELM_E equals(XMLP._ELM_E, p.next(), "Closing html tag"); // _ELM_E -}); \ No newline at end of file +}); + +/*test("Clean HTML", function() { + expect(3); + var domParser = new DOMParser(), + htmlstr = "

this is a pig... 'oink! oink!'

"; + + Envjs.fixHTML = true; + equals(Envjs.cleanHTML(htmlstr), + "

this is a pig... 'oink! oink!'

", + 'got expected xmlstring'); + + + var domnode = domParser.parseFromString(htmlstr); + ok(domnode, 'Malformed p was parsed without error'); + equals(domnode.xml, + "

this is a pig... 'oink! oink!'

", + 'got expected value for .xml'); + Envjs.fixHTML = false; + +});*/ diff --git a/test/unit/scope.js b/test/unit/scope.js index cc909ccc..d3dfa8de 100644 --- a/test/unit/scope.js +++ b/test/unit/scope.js @@ -18,6 +18,14 @@ module("scope"); // event handlers (page-global and attribute-assigned), as well as // confirming the independence of scoping in frames. +var __click__ = function(element){ + var event = new Event({ + target:element, + currentTarget:element + }); + event.initEvent("click"); + element.dispatchEvent(event); +}; // this test depends on 'iframe1.html' having been loaded into 'index.html's // 'loadediframe' element (and not modified prior to this test's execution) @@ -58,7 +66,7 @@ test("Event handler attribute has access to (correct) 'document'", function() { }catch(e){print(e);} var img1 = idoc.getElementById('img1'); - img1.__click__(img1); + __click__(img1); mtch = idoc.getElementById('p1').innerHTML.match(/img1 click/); try{ ok(mtch && mtch.length > 0, "img1 event handler executed correctly"); @@ -77,7 +85,7 @@ test("Event handler attribute has access to (correct) 'this'", function() { }catch(e){print(e);} var div1 = idoc.getElementById('div1'); - div1.__click__(div1); + __click__(div1); mtch = idoc.getElementById('p2').innerHTML.match(/div1 click/); try{ ok(mtch && mtch.length > 0, "div1 event handler executed correctly"); @@ -122,7 +130,7 @@ test("Handler defined in frame lexically scopes to frame", function() { }catch(e){print(e);} var div2 = idoc.getElementById('div2'); - div2.__click__(div2); + __click__(div2); lex = idoc.getElementById('lex'); mtch = lex.innerHTML.match(/Lexical scoping is Overridden/); try{ ok(mtch && mtch.length > 0, @@ -147,7 +155,7 @@ test("In-frame object-assigned handler scopes to frame", function() { }catch(e){print(e);} bVar = 13; // handler shouldn't pick up this version of 'bVar'; - p4.__click__(p4); // should bubble to div3 and handler + __click__(p4); // should bubble to div3 and handler mtch = p4.innerHTML.match(/number 42/); try{ ok(mtch && mtch.length > 0, "div3 event handler executed correctly"); @@ -174,7 +182,7 @@ test("Handler defined in root lexically scopes to root", function() { }catch(e){print(e);} var div3 = idoc.getElementById('div3'); - div3.__click__(div3); + __click__(div3); mtch = p4.innerHTML.match(/contains good text/); try{ ok(mtch && mtch.length > 0, "new div3 event handler executed correctly"); diff --git a/test/unit/timer.js b/test/unit/timer.js index 452dc952..787a1831 100644 --- a/test/unit/timer.js +++ b/test/unit/timer.js @@ -8,7 +8,6 @@ test("runnable callbacks are run until wait", function() { // so that setTimeout/Interval functions with time=0 *are* executed prior // within the call to setTimeout/Interval // ok( occurred === 0, "Timeout should not have been executed" ); - $wait(); ok( occurred !== 0, "Timeout was not executed" ); }); @@ -16,7 +15,6 @@ test("wait() executes runnable callbacks", function() { expect(1); var occurred = 0; setTimeout(function(){ occurred = Date.now(); }, 0); - $wait(); ok( occurred !== 0, "Timeout was not executed" ); }); @@ -24,7 +22,6 @@ test("wait() does not execute nonrunnable callbacks", function() { expect(1); var occurred = 0; setTimeout(function(){ occurred = Date.now(); }, 100); - $wait(); ok( occurred === 0, "Timeout should not have been executed" ); }); @@ -32,7 +29,6 @@ test("wait(0) executes nonrunnable callbacks", function() { expect(1); var occurred = 0; setTimeout(function(){ occurred = Date.now(); }, 100); - $wait(0); ok( occurred !== 0, "Timeout should have been executed" ); }); @@ -40,9 +36,7 @@ test("wait(n) does not execute nonrunnable callbacks", function() { expect(2); var occurred = 0; setTimeout(function(){ occurred = Date.now(); }, 1000); - $wait(500); ok( occurred === 0, "Timeout should not have been executed" ); - $wait(0); ok( occurred !== 0, "Timeout should have been executed" ); });