X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=build%2Fruntest%2Fenv.js;h=febc08a693aa684282c6c94a06a82c170daa119f;hb=0bb035a1abc37fbf033a18ac53dd62ec85599a49;hp=564b02207754035687ca19f2bb0caa5332a21cd5;hpb=b5bf00a37368baf69595434c0329f869b9ca18e9;p=jquery.git
diff --git a/build/runtest/env.js b/build/runtest/env.js
index 564b022..febc08a 100644
--- a/build/runtest/env.js
+++ b/build/runtest/env.js
@@ -17,16 +17,32 @@ var window = this;
}
};
+ var curLocation = (new java.io.File("./")).toURL();
+
window.__defineSetter__("location", function(url){
- window.document = new DOMDocument(
- new Packages.org.xml.sax.InputSource(
new java.io.InputStreamReader(
- new java.io.FileInputStream(url))));
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", url);
+ xhr.onreadystatechange = function(){
+ curLocation = new java.net.URL( curLocation, url );
+ window.document = xhr.responseXML;
+
+ var event = document.createEvent();
+ event.initEvent("load");
+ window.dispatchEvent( event );
+ };
+ xhr.send();
});
window.__defineGetter__("location", function(url){
return {
get protocol(){
- return "file:";
+ return curLocation.getProtocol() + ":";
+ },
+ get href(){
+ return curLocation.toString();
+ },
+ toString: function(){
+ return this.href;
}
};
});
@@ -68,9 +84,51 @@ var window = this;
};
// Window Events
+
+ var events = [{}];
- window.addEventListener = function(){};
- window.removeEventListener = function(){};
+ window.addEventListener = function(type, fn){
+ if ( !this.uuid || this == window ) {
+ this.uuid = events.length;
+ events[this.uuid] = {};
+ }
+
+ if ( !events[this.uuid][type] )
+ events[this.uuid][type] = [];
+
+ if ( events[this.uuid][type].indexOf( fn ) < 0 )
+ events[this.uuid][type].push( fn );
+ };
+
+ window.removeEventListener = function(type, fn){
+ if ( !this.uuid || this == window ) {
+ this.uuid = events.length;
+ events[this.uuid] = {};
+ }
+
+ if ( !events[this.uuid][type] )
+ events[this.uuid][type] = [];
+
+ events[this.uuid][type] =
+ events[this.uuid][type].filter(function(f){
+ return f != fn;
+ });
+ };
+
+ window.dispatchEvent = function(event){
+ if ( event.type ) {
+ if ( this.uuid && events[this.uuid][event.type] ) {
+ var self = this;
+
+ events[this.uuid][event.type].forEach(function(fn){
+ fn.call( self, event );
+ });
+ }
+
+ if ( this["on" + event.type] )
+ this["on" + event.type].call( self, event );
+ }
+ };
// DOM Document
@@ -79,17 +137,22 @@ var window = this;
this._dom = Packages.javax.xml.parsers.
DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(file);
+
+ if ( !obj_nodes.containsKey( this._dom ) )
+ obj_nodes.put( this._dom, this );
};
DOMDocument.prototype = {
createTextNode: function(text){
- return makeNode( this._dom.createTextNode(text) );
+ return makeNode( this._dom.createTextNode(
+ text.replace(/&/g, "&").replace(//g, ">")) );
},
createElement: function(name){
- return makeNode( this._dom.createElement(name) );
+ return makeNode( this._dom.createElement(name.toLowerCase()) );
},
getElementsByTagName: function(name){
- return new DOMNodeList( this._dom.getElementsByTagName(name) );
+ return new DOMNodeList( this._dom.getElementsByTagName(
+ name.toLowerCase()) );
},
getElementById: function(id){
var elems = this._dom.getElementsByTagName("*");
@@ -111,8 +174,9 @@ var window = this;
get ownerDocument(){
return null;
},
- addEventListener: function(){},
- removeEventListener: function(){},
+ addEventListener: window.addEventListener,
+ removeEventListener: window.removeEventListener,
+ dispatchEvent: window.dispatchEvent,
get nodeName() {
return "#document";
},
@@ -142,9 +206,22 @@ var window = this;
};
}
};
+ },
+
+ createEvent: function(){
+ return {
+ type: "",
+ initEvent: function(type){
+ this.type = type;
+ }
+ };
}
};
+ function getDocument(node){
+ return obj_nodes.get(node);
+ }
+
// DOM NodeList
window.DOMNodeList = function(list){
@@ -188,10 +265,10 @@ var window = this;
return makeNode( this._dom.cloneNode(deep) );
},
get ownerDocument(){
- return document;
+ return getDocument( this._dom.ownerDocument );
},
get documentElement(){
- return document.documentElement;
+ return makeNode( this._dom.documentElement );
},
get parentNode() {
return makeNode( this._dom.getParentNode() );
@@ -214,7 +291,10 @@ var window = this;
window.DOMElement = function(elem){
this._dom = elem;
- this.style = {};
+ this.style = {
+ get opacity(){ return this._opacity; },
+ set opacity(val){ this._opacity = val + ""; }
+ };
// Load CSS info
var styles = (this.getAttribute("style") || "").split(/\s*;\s*/);
@@ -264,6 +344,10 @@ var window = this;
return this.childNodes.valueOf();
},
set innerHTML(html){
+ html = html.replace(/<\/?([A-Z]+)/g, function(m){
+ return m.toLowerCase();
+ });
+
var nodes = this.ownerDocument.importNode(
new DOMDocument( new java.io.ByteArrayInputStream(
(new java.lang.String("