PDA

View Full Version : DomHelper's new feature



alltouch
15 Nov 2008, 11:00 AM
I have modified DomHelper's source code. Now it can get HTMLElement's object as argument to it functions.

Earlier:


ExtDomHelper.insertAfter( el , {'tag':'div' , 'html':'lol x2 :)'} ); - worked
ExtDomHelper.insertAfter( el , Ext.get('my') ); - didn't worked


Now:


ExtDomHelper.insertAfter( el , {'tag':'div' , 'html':'lol x2 :)'} ); - works
ExtDomHelper.insertAfter( el , Ext.get('my') ); - works


Modified function:


doInsert : function(el, o, returnElement, pos, sibling){
el = Ext.getDom(el);
var newNode;
if(this.useDom){
if(o.toString().substr(0,12) != '[object HTML')
newNode = createDom(o, null);
else
newNode = o;
(sibling === "firstChild" ? el : el.parentNode).insertBefore(newNode, sibling ? el[sibling] : el);
}else{
var html = createHtml(o);
newNode = this.insertHtml(pos, el, html);
}
return returnElement ? Ext.get(newNode, true) : newNode;
}


Guys, what can you say about it?
How can i ask Extjs developers to include it in next release? :)

Animal
15 Nov 2008, 11:15 AM
Testing the toString() probably is not the best way. I'd probably use



if (el.nodeType)


because nodeType is a standard property of HTML nodes.

http://www.w3.org/TR/DOM-Level-2-Core/ecma-script-binding.html

see "Object Node"

Animal
15 Nov 2008, 11:18 AM
But Ext.get does not return an HTML node, it returns an Ext.Element, and the toString of that is likely to be "[object Object]"

alltouch
15 Nov 2008, 1:04 PM
have updated code:


doInsert : function(el, o, returnElement, pos, sibling){
el = Ext.getDom(el);
var newNode;
if(this.useDom){
if(o.nodeType && o.nodeType == 1){
newNode = o;
} else if(o.dom && o.dom.nodeType && o.dom.nodeType == 1){
newNode = o.dom;
} else {
newNode = createDom(o, null);
}
(sibling === "firstChild" ? el : el.parentNode).insertBefore(newNode, sibling ? el[sibling] : el);
}else{
var html = createHtml(o);
newNode = this.insertHtml(pos, el, html);
}
return returnElement ? Ext.get(newNode, true) : newNode;
}

thanks for comments...

Where can i ask to add this to next release?