CustomTagReader.js

/**
 * @class Ext.CustomTagReader
 * Utility class to normalize reading of custom tags across browsers. This class is entirely experimental, use at own risk!
 */
Ext.CustomTagReader = function(namespace){
    this.namespace = namespace;
};
Ext.CustomTagReader.prototype = {
    getAttribute : function(el, name, defaultValue){
        return (this.useNS ?
            v = el.getAttributeNS(this.namespace, name) : null) ||
            el.getAttribute(this.namespace+':'+name) ||
            el.getAttribute(name);
    },
    
    getElements : function(tagName, targetEl){
        targetEl = targetEl || document.body;
        var els;
        if(this.useNS){ // no namespaces in IE
           els = targetEl.getElementsByTagNameNS(this.namespace, tagName);
        }
        if(!els || els.length < 1){ // ie6, firefox 1.5, firefox 2 depending on doc type
           els = targetEl.getElementsByTagName(this.namespace+':'+tagName);
        }
        if(!els || els.length < 1){ // everyone else
           els = targetEl.getElementsByTagName(tagName);
        }
        return els;
    },
    
    eachElement : function(tagName, targetEl, fn, scope){
        var els = this.getElements(tagName, targetEl);
        for(var i = 0, len = els.length; i < len; i++) {
        	var el = els[i];
        	fn.call(scope || el, el);
        }  
    },
    
    useNS : (!Ext.isIE && document.getElementsByTagNameNS) ? true : false
};

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.