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"+ 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 Resigparse 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;i"+ 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!'
this is a pig... 'oink! oink!'
this is a pig... 'oink! oink!'