Skip to content

Instantly share code, notes, and snippets.

@eerne
Created July 13, 2009 23:09
Show Gist options
  • Save eerne/146516 to your computer and use it in GitHub Desktop.
Save eerne/146516 to your computer and use it in GitHub Desktop.
Document.implement({
id: (function(){
var types = {
string: function(id, nocash, doc){
id = doc.getElementById(id);
return (id) ? types.element(id, nocash) : null;
},
element: function(el, nocash){
$uid(el);
if (!nocash && !el.$family && !(/^object|embed$/i).test(el.tagName)){
var proto = Element.Prototype;
for (var p in proto) el[p] = proto[p];
};
return el;
},
object: function(obj, nocash, doc){
if (obj.toElement) return types.element(obj.toElement(doc), nocash);
return null;
}
};
types.textnode = types.whitespace = types.window = types.document = $arguments(0);
return function(el, nocash, doc){
if (el && el.$family && el.uid) return el;
var type = $type(el);
return (types[type]) ? types[type](el, nocash, doc || document) : null;
};
})()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment