YUI学习笔记1

阅读更多
用js做了几个项目,感觉水平还是不够,决定重新学习一个js框架,好好研究下js。
框架选择了YUI,先从翻译YUI.JS做起吧,正好也提升下英语水平。

YUI.JS

YUI 3.8.1

/*
YUI模块包含创建YUI种子文件的部件。这里包括脚本加载机制、一个简单的队列、程序库的核心工具包。
*/
if (typeof YUI != 'undefined') {
    YUI._YUI = YUI;
}
/*
YUI全局命名空间对象。这事所有YUI实例的构造函数。

这是一个自我实例化的工厂函数,意味着你不需要在在前面使用“new”操作符。你可以直接这样调用它:
    YUI().use('*', function (Y) {
        // Y is a new YUI instance.
    });
但它总是像这样工作:
    var Y = YUI();
“YUI”构造函数接收可变的配置对象,例如:
    YUI({
        debug: true,
        combine: false
    }).use('node', function (Y) {
        // Y.Node is ready to use.
    });
你可以从API文档中查看YUI构造函数所支持的所有配置属性列表。
如果一个全局的YUI对象已经被定义,已经存在的YUI对象将不会被覆盖,以保证已经定义的命名空间是保密的。

每一个YUI实例包括完整的定制事件支持,但只在事件系统有效时。
*/


上面的翻译有不少错误,有些单词搞不懂,比如preserved是嘛意思?猜了半天,将就翻译成“保密的”,先凑合吧,继续:

/*
@class YUI
@uses EventTarget
@constructor
@global
@param {Object} [config]* 0或更多个可选配置对象. 配置都存储在Y.config的属性中。查看config.html获取支持的属性列表。
**/

    /*global YUI*/
    /*global YUI_config*/
    var YUI = function() {
        var i = 0,
            Y = this,
            args = arguments,
            l = args.length,
            instanceOf = function(o, type) {
                return (o && o.hasOwnProperty && (o instanceof type));
            },
            gconf = (typeof YUI_config !== 'undefined') && YUI_config;

        if (!(instanceOf(Y, YUI))) {
            Y = new YUI();
        } else {
            // 建立核心环境
            Y._init();

            /**
            主配置可包含在一个非浏览环境的持续多行文本。它将首先被应用至所有环境的所有实例。

            @例如:

                YUI.GlobalConfig = {
                    filter: 'debug'
                };

                YUI().use('node', function (Y) {
                    // debug代码                });

                YUI({
                    filter: 'min'
                }).use('node', function (Y) {
                    // min代码
                });

            @property {Object} GlobalConfig
            @global
            @static
            **/
            if (YUI.GlobalConfig) {
                Y.applyConfig(YUI.GlobalConfig);
            }
            /**
            页面级别的配置将应用至现行页面的所有YUI实例。它应用在“YUI.GlobalConfig”之后,实例级别的配置之前。

            @example

                // 在YUI种子文件之前的一个单一全局变量
                YUI_config = {
                    filter: 'debug'
                };

                YUI().use('node', function (Y) {
                    // debug files used here
                });

                YUI({
                    filter: 'min'
                }).use('node', function (Y) {
                    // min files used here
                });

            @property {Object} YUI_config
            @global
            **/
            if (gconf) {
                Y.applyConfig(gconf);
            }

            // 绑定该实例指定的附加模块
            if (!l) {
                Y._setup();
            }
        }

        if (l) {
            // 每个实例可接收一到多个配置对象.
            // 它们将作用在YUI.GlobalConfig 和 YUI_Config之后,
            // 如果存在重复的属性,这里将覆盖之前的配置。.
            for (; i < l; i++) {
                Y.applyConfig(args[i]);
            }

            Y._setup();
        }

        Y.instanceOf = instanceOf;

        return Y;
    };



继续:
(function() {

    var proto, prop,
        VERSION = '3.8.1',
        PERIOD = '.',
        BASE = 'http://yui.yahooapis.com/',
        /*
            这些css样式名称不能被getClassName生成自从被使用时不是有效的。  这句没看明白。
        */
        DOC_LABEL = 'yui3-js-enabled',
        CSS_STAMP_EL = 'yui3-css-stamp',
        NOOP = function() {},
        SLICE = Array.prototype.slice,
        APPLY_TO_AUTH = { 'io.xdrReady': 1,   // 函数适用于可调用。
                          'io.xdrResponse': 1,   // 这应该在构建时完成。
                          'SWF.eventHandler': 1 }, // 
        hasWin = (typeof window != 'undefined'),
        win = (hasWin) ? window : null,
        doc = (hasWin) ? win.document : null,
        docEl = doc && doc.documentElement,
        docClass = docEl && docEl.className,
        instances = {},
        time = new Date().getTime(),
        add = function(el, type, fn, capture) {
            if (el && el.addEventListener) {
                el.addEventListener(type, fn, capture);
            } else if (el && el.attachEvent) {
                el.attachEvent('on' + type, fn);
            }
        },
        remove = function(el, type, fn, capture) {
            if (el && el.removeEventListener) {
                // 在firefox将抛出异常
                try {
                    el.removeEventListener(type, fn, capture);
                } catch (ex) {}
            } else if (el && el.detachEvent) {
                el.detachEvent('on' + type, fn);
            }
        },
        handleLoad = function() {
            YUI.Env.windowLoaded = true;
            YUI.Env.DOMReady = true;
            if (hasWin) {
                remove(window, 'load', handleLoad);
            }
        },

你可能感兴趣的:(yui,js)