X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;ds=inline;f=build%2Fruntest%2Fenv.js;h=e15a2263184475b42f0f6d3b3d4ee23807a6d938;hb=9ac9aaeec3dd036f805bc607ea4fd9afcab92047;hp=564b02207754035687ca19f2bb0caa5332a21cd5;hpb=b5bf00a37368baf69595434c0329f869b9ca18e9;p=jquery.git
diff --git a/build/runtest/env.js b/build/runtest/env.js
index 564b022..e15a226 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";
},
@@ -123,6 +187,9 @@ var window = this;
return "Document" + (typeof this._file == "string" ?
": " + this._file : "");
},
+ get innerHTML(){
+ return this.documentElement.outerHTML;
+ },
get defaultView(){
return {
@@ -142,9 +209,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){
@@ -162,9 +242,9 @@ var window = this;
return "[ " +
Array.prototype.join.call( this, ", " ) + " ]";
},
- valueOf: function(){
+ get outerHTML(){
return Array.prototype.map.call(
- this, function(node){return node.valueOf();}).join('');
+ this, function(node){return node.outerHTML;}).join('');
}
};
@@ -188,10 +268,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() );
@@ -205,7 +285,7 @@ var window = this;
toString: function(){
return '"' + this.nodeValue + '"';
},
- valueOf: function(){
+ get outerHTML(){
return this.nodeValue;
}
};
@@ -214,7 +294,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*/);
@@ -236,14 +319,14 @@ var window = this;
toString: function(){
return "<" + this.tagName + (this.id ? "#" + this.id : "" ) + ">";
},
- valueOf: function(){
+ get outerHTML(){
var ret = "<" + this.tagName, attr = this.attributes;
for ( var i in attr )
ret += " " + i + "='" + attr[i] + "'";
if ( this.childNodes.length || this.nodeName == "SCRIPT" )
- ret += ">" + this.childNodes.valueOf() +
+ ret += ">" + this.childNodes.outerHTML +
"" + this.tagName + ">";
else
ret += "/>";
@@ -261,9 +344,13 @@ var window = this;
},
get innerHTML(){
- return this.childNodes.valueOf();
+ return this.childNodes.outerHTML;
},
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("