In our code (formerly based on prototype), we do a lot of dynamic DOM creation. Many times we do not attach the created elements to the document until later in the code. This presents a problem when working with your library as your functions depend on YAHOO.ext.Element.get which requires the element to be appended to the document. I cannot think of any reason why you require this. I have created a patch that will allow the passing of an element that is not appended to the document. From my testing, it breaks nothing. I tried to maintain backwards compatibility. My changes are marked with comments.
I would appreciate it if you would test it, and if it meets your expectations, commit it to subversion. Thanks!
Code:
YAHOO.ext.Element.get = function(){
var doc = document;
var docEl;
var E = YAHOO.ext.Element;
var D = YAHOO.util.Dom;
return function(el){
if(!el){ return null; }
if(el instanceof E){
if(el != docEl){
/*
* if getElementById is ull, use el.dom
*/
var domElem = doc.getElementById(el.id);
el.dom = (domElem)?domElem:el.dom;
E.cache[el.id] = el;
}
return el;
}else if(el.isComposite){
return el;
}else if(el instanceof Array){
return E.select(el);
}else if(el == doc){
if(!docEl){
var f = function(){};
f.prototype = E.prototype;
docEl = new f();
docEl.dom = doc;
}
return docEl;
}
var key = el;
if(typeof el != 'string'){
D.generateId(el, 'elgen-');
key = el.id;
}
var element = E.cache[key];
if(!element){
/*
* pass el instead of key. YAHOO.ext.Element will handle it. You don't need to pass it key.
*/
element = new E(el);
if(!element.dom) return null;
E.cache[key] = element;
}else{
element.dom = doc.getElementById(key);
}
return element;
};
}();