建立组件库

REPOS = {
            jQuery:{
                        /**
                         *
资源文件
                         *
逗号、空格分隔,或者是数组
                         */

                        assets:'jquery.js',
                        /**
                         *
文件编码
                         *
如果js 或者 css文件中包含中文等非assii码值,且不与页面编码一置,
                         *
可以考虑设置该项
                         */

                        charset:'',
                        /**
                         *
特征函数,用来验证再用fet之前是否已经载入,防止冲突
                         *
函数表达式或者字符串的函数体
                         *
                         * @return bool
                         */

                        test:function(){
                                   try {
                                               return /1\.3\.\d/.test(jQuery.fn.jquery);
                                   }catch(e){
                                               return false;
                                   }
                        },
                        /**
                         *
依赖的组件
                         *
逗号、空格分隔,或者是数组
                         */

                        depends:''
            },
 
            config:{
                        assets:'config.js'
            },
 
            cmstop:{
                        assets:'cmstop.js style.css',
                        test:'window.cmstop',
                        depends:'config jQuery'
            },
 
            cmstop:{
                        assets:['cmstop.js','style.css'],
                        test:'window.cmstop',
                        depends:['config', 'jQuery']
            },
 
            cmstop:{
                        assets:'cmstop.js, style.css',
                        test:function(){return window.cmstop ? true : false;},
                        depends:'config, jQuery'
            }
}

组件库建立的时候,键值最好使用带目录以点号分隔,如:

'admin.apps.special.js.diy':{
            assets:'diy.js style.css',
            depends:'jQuery cmstop config'
}

或者可以短一点:

'admin.special.diy':{
            assets:'diy.js style.css',
            depends:'jQuery cmstop config'
}

尽量做到让别人一看便知该组件的定位,且又能防止键值冲突,一旦冲突就会报错,并且终止脚本的运行。



Copyright ©2009 - 2014 CmsTop.Com.All rights reserved.
思拓合众