Acess to global function prototypes for extension
Reported by Thatcher | February 26th, 2009 @ 10:27 AM | in 1.0 Release
Hi Everyone,
I've been using envjs with some success as a unit testing tool. My app makes use of ExtJs, which makes use of the DOM Range object. The I added the Range implementation below. I know the goal is to have a pure JavaScript implementation, and my createRange function is not that. But adding this allowed me to do some simple function testing with ExtJs, and so I figured I'd share.
Jeff
DOMDocument.prototype = {
get nodeType(){
debug('DOMDocument : nodeType');
return 9;
},
createRange : function() {
debug('DOMDocument : createRange');
return new Range(this);
},
[...]
function Range(node) {
this._dom = node;
};
Range.prototype = {
setStart : function(el, offset) {
debug('Range : setStart');
this.startContainer = el;
},
setEnd : function(el, offset) {
debug('Range : setEnd');
this.endContainer = el;
},
setStartBefore : function(el) {
debug('Range : setStartBefore');
this.startContainer = el;
},
setStartAfter : function(el) {
debug('Range : setStartAfter');
this.startOffset = el;
},
setEndBefore : function(el) {
debug('Range : setEndBefore');
this.endContainer = el;
},
setEndAfter : function(el) {
debug('Range : setEndAfter');
this.endOffset = el;
},
selectNode : function() {
print('selectNode function unimplemented');
},
selectNodeContents : function() {
print('selectNodeContents function unimplemented');
},
collapse : function() {
debug('Range : collapse');
this.collapsed = true;
},
cloneContents : function() {
print('cloneContents function unimplemented');
},
deleteContents : function() {
print('deleteContents function unimplemented');
},
extractContents : function() {
print('extractContents function unimplemented');
},
insertNode : function() {
print('insertNode function unimplemented');
},
surroundContents : function() {
print('surroundContents function unimplemented');
},
compareBoundaryPoints : function() {
print('compareBoundaryPoints function unimplemented');
},
cloneRange : function() {
print('cloneRange function unimplemented');
},
detach : function() {
print('detach function unimplemented');
},
toString : function() {
print('toString function unimplemented');
},
comparePoint : function() {
print('comparePoint function unimplemented');
},
createContextualFragment : function(html) {
debug('Range : createContextualFragment : html : ' + html);
var stringFrag = new java.lang.String(html);
var bytes = new java.io.ByteArrayInputStream(stringFrag.getBytes());
var doc = Packages.javax.xml.parsers.
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bytes);
var newDoc = doc.getDocumentElement();
var myNode = {
_dom : newDoc
};
return this._dom.importNode(myNode, true);
},
isPointInRange : function() {}
};
Comments and changes to this ticket
-
Thatcher February 26th, 2009 @ 10:27 AM
- State changed from new to open
Hi Jeff, This sort of thing has recently come up as I try to get Prototype running in Env. Basically the problem is that I made the DOM classes are visible as functions, but I made the prototypes private. Since our goal is to emulate the browser I'm going to create a ticket to make the prototype public so the libraries can modify them as they can in the browser.
I'll post back to this thread with the ticket link if you want to comment or track.
Thatcher
-
Thatcher September 9th, 2009 @ 06:16 PM
- State changed from open to resolved
This has been changed. You can now modify all core DOM and HTML classes
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
a javascript browser environment