I\'m working with some legacy code where the original developers made heavy use of generating HTML DOM nodes with a non-standard attribute named translate
The best I've been able to come up with so far is going through every DOM element in the page defining a getter that checks for the existence of an attribute. (the Object.__defineGetter__
guard clause ensures no errors in browsers that don't support modern Javascript)
if(Object.__defineGetter__)
{
var hasTranslateAttribute = function(){
return $(this).hasAttribute("translate");
};
document.observe("dom:loaded", function() {
$$('*').each(function(theElement){
theElement.__defineGetter__("translate", hasTranslateAttribute);
});
});
}
I tried defining a getting on Object.prototype
and Element.prototype
, but it seems like the browser's native translate
is defined higher up the chain, so you need to redefine things on a per element basis.