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() {}
};