日期:2014-05-16  浏览次数:20385 次

一款类似Ext的轻量级实现UI的JS框架
/*!
 * UC JS Library 1.0.0
 */

// 兼容旧浏览器,早期的浏览器实现中,undefined并不是全局变量。就是说,你要判断一个变量是否是没定义,  
// 你需要这样写if (typeof  a == 'undefined'),不可以写成if (a == undefined)。所以,上面的代码就可以理解了。  
// 右面的window["undefined"],因为window对象没有undefined属性,所以其值为undefined,  
// 把undefined赋值给window的undefined属性上,就相当于把undefined设置成了全局变量,  
// 这样以后你再判断一个变量是否是未定义的时候,就不需要使用typeof,直接判断就可以了。  
//window.undefined = window.undefined;

/**
 * @class webuc
 * UC core utilities and functions.
 * @singleton
 */

UC = {
    /**
     * The version of the framework
     * @type String
     */
    version : '1.0'
};

/**
 * 把对象c中的属性复制到对象o中,支持默认属性defaults设置。
 * 这个方法属于对象属性的一个浅拷贝函数。  
 * 
 * @param {Object} obj The receiver of the properties
 * @param {Object} config The source of the properties
 * @param {Object} defaults A different object that will also be applied for default values
 * @return {Object} returns obj
 * @member UC apply
 */
UC.apply = function(o, c, defaults){
	// 如果默认值defaults存在,那么先把defaults上得属性复制给对象o 
    if(defaults){
        UC.apply(o, defaults);
    }
    if(o && c && typeof c == 'object'){
        for(var p in c){
            o[p] = c[p];
        }
    }
    return o;
};


(function(window, undefined){
	
	// idSeed,用来生成自增长的id值。
    var idSeed = 0,
        toString = Object.prototype.toString,
        
        // ua,浏览器的用户代理,主要用来识别浏览器的型号、版本、内核和操作系统等。  
        ua = navigator.userAgent.toLowerCase(),
        check = function(r){
            return r.test(ua);
        },
        
        /**
         * Iterates an array calling the supplied function.
         * @param {Array/NodeList/Mixed} array The array to be iterated. If this
         * argument is not really an array, the supplied function is called once.
         * @param {Function} fn The function to be called with each item. If the
         * supplied function returns false, iteration stops and this method returns
         * the current index. This function is called with
         * the following arguments:
         */
        isIterable = function(v){
            //check for array or arguments
            if(UC.isArray(v) || v.callee){
                return true;
            }
            //check for node list type
            if(/NodeList|HTMLCollection/.test(toString.call(v))){
                return true;
            }
            //NodeList has an item and length property
            //IXMLDOMNodeList has nextNode method, needs to be checked first.
            return ((v.nextNode || v.item) && UC.isNumber(v.length));
        },
        
        DOC = document,
        
        // isStrict,表示当前浏览器是否是标准模式。  
        // 如果正确的设置了网页的doctype,则compatMode为CSS1Compat,否则为BackCompat 
        isStrict = DOC.compatMode == "CSS1Compat",
        
        // isOpera,表示是否是opera浏览器。
        isOpera = check(/opera/),
        
        // isChrome,表示是否是谷歌浏览器。 
        isChrome = check(/chrome/),
        
        // isWebKit,表示当前浏览器是否使用WebKit引擎。  
        // WebKit是浏览器内核,Safari和Chrome使用WebKit引擎。  
        isWebKit = check(/webkit/),  
        
        // isSafari,表示是否是苹果浏览器,下面代码是对其版本识别。 
        isSafari = !isChrome && check(/safari/),
        isSafari3 = isSafari && check(/version\/3/),
        isSafari4 = isSafari && check(/version\/4/),
        isSafari5 = isSafari && check(/version\/5/),
        
        // isIE,表示是否是IE浏览器,下面代码是对其版本识别。 
        isIE = !isOpera && check(/msie/),
        isIE7 = isIE && check(/msie 7/),
        isIE8 = isIE && check(/msie 8/),
        
        // isGecko,表示当前浏览器是否使用Gecko引擎。  
        // Gecko是浏览器内核,Firefox使用Gecko引擎。  
        isGecko = !isWebKit && check(/gecko/),  
        isGecko2 = isGecko && check(/rv:1\.8/),  
        isGecko3 = isGecko && check(/rv:1\.9/), 
        
        // isBorderBox,表示浏览器是否是IE的盒模式。  
        // 众所周知,IE的盒模式和W3C的盒模式不一致。当IE浏览器在怪异模式下,就会导致错误的盒模式。  
        isBorderBox = isIE && !isStrict,