<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>随网之舞YAHOO_config</title>
	<atom:link href="http://dancewithnet.com/tag/yahoo_config/feed/" rel="self" type="application/rss+xml" />
	<link>http://dancewithnet.com</link>
	<description>WEB Design{HTML:CSS:Javascript:DOM:AJAX:PHP:Usability}/Viewpoint/Photo/Food/Mood</description>
	<lastBuildDate>Mon, 18 Jul 2011 02:45:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>扩展YUI Loader</title>
		<link>http://dancewithnet.com/2008/03/26/extend-yuiloader/</link>
		<comments>http://dancewithnet.com/2008/03/26/extend-yuiloader/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 15:45:24 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[Javascript & DOM & AJAX]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[YAHOO_config]]></category>
		<category><![CDATA[YUI]]></category>
		<category><![CDATA[YUILoader]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/2008/03/26/extend-yuiloader/</guid>
		<description><![CDATA[YUI Loader是YUI的动态载入外部Javascript和CSS文件的整体解决方案。它的可靠、安全、高效，优化了页面的呈现速度，实现了外部Js和CSS的按需加载。
在YUI 2.4.0到2.5.1版本中，YUI Loader通过其addModule()... ]]></description>
			<content:encoded><![CDATA[<p><a href="http://developer.yahoo.com/yui/yuiloader/">YUI Loader</a>是YUI的动态载入外部Javascript和CSS文件的整体解决方案。它的可靠、安全、高效，优化了页面的呈现速度，实现了外部Js和CSS的按需加载。</p>
<p>在YUI 2.4.0到2.5.1版本中，<a href="http://developer.yahoo.com/yui/yuiloader/">YUI Loader</a>通过其<a href="http://developer.yahoo.com/yui/yuiloader/#addmodule"><code>addModule()</code></a>方法只能配置一个YUI Loader实例的加载模块信息，无法配置全局的加载模块信息。实际中，能够全局的配置加载文件的模块信息对于统一维护非常的重要，特别是在静态文件服务器设置了上传文件不可以修改和删除情况下。下面是解决这个问题的两个方法：<span id="more-1273"></span></p>
<h3>方法1：修改YUI Loader源文件，引入YAHOO_config.load来配置全局信息</h3>
<p>在YUI两个全局变量之一的<a href="http://developer.yahoo.com/yui/docs/YAHOO_config.html">    <code>YAHOO_config</code></a>中,有一个<code>load</code>属性是用来配置YUI Loader的全局信息的，但是遗憾的是仅仅是2.4.0之前的版本支持。</p>
<h4>1、修改YUI Loader源文件</h4>
<pre><code>var Y=YAHOO, util=Y.util, lang=Y.lang, env=Y.env;
<span>/*
 *在上面一行代码的位置下面加上下面的代码：
 *判断当YAHOO_config存在且有load属性时，把YAHOO_config.load赋值给变量Y_load
 */</span>
if('undefined'!== typeof YAHOO_config){
	if(lang.hasOwnProperty(YAHOO_config,'load')){
		var Y_load = YAHOO_config.load;
	}
}
<span>...</span>
this.base = YUI.info.base;
<span>/*把上面一行修改为下面一行，这样可以用过YAHOO_config.load.base来指定YUI组件的路径*/</span>
this.base  = (lang.hasOwnProperty(Y_load,'base'))?Y_load.base:YUI.info.base;
<span>...</span>
this.moduleInfo = lang.merge(YUI.info.moduleInfo);
<span>/*把上面一行修改为下面一行，这样可以用过YAHOO_config.load.moduleInfo来指定YUI组件的路径*/</span>
this.moduleInfo = (lang.hasOwnProperty(Y_load,'moduleInfo'))?
lang.merge(YUI.info.moduleInfo,Y_load.moduleInfo):lang.merge(YUI.info.moduleInfo);
</code></pre>
<h4>2、在YUI Loader文件前写下如下配置文件：</h4>
<pre><code>YAHOO_config = {
load : {
 base : 'http://cn.yui.yahooapis.com/2.5.1/build/',
 <span>/*
 *  通用的非YUI组件和不自动加载皮肤的YUI组件
 *  @name   string
 *  @type   string
 *  @fullpath   string
 *  @requires   array
 *  @optinal    array
 *  @skinnable  boolean
 */</span>
 moduleInfo : {
<span>/*
 *YUI的组件中，有皮肤的组件使用时都会自动加载皮肤
 *比如require(['container'])时，会加载container.js，也会加载container.css
 *但是实际应用中，往往不会直接使用YUI的默认皮肤
 *<a href="http://developer.yahoo.com/yui/yuiloader/#usingskins">利用YUI Loader本身的skins属性设置</a>，只能在具体的YUI实例中使用，且需要满足YUI的文件结构
 *利用insert({},'js')方法虽然只能加载Js，但如何require()方法中的CSS也会被过滤掉
 *所以最好的方法是全局性的把其skinnable属性值修改为false
 */</span>
  'container': {
   'type': 'js',
   'path': 'container/container-min.js',
   'requires': ['dom', 'event'],
   'optional': ['dragdrop', 'animation', 'connection'],
   'supersedes': ['containercore'],
   'skinnable': false
  },
  'dwncontainercss' : {
   'type' : 'css',
   'fullpath' : '/lab/2008/extend-yuiloader/container.css'
  },
  'dwncarouselcss':{
   'name' : 'dwncarouselcss',
   'type' : 'css',
   'fullpath' : '/lab/2008/extend-yuiloader/carousel.css'
  },
  'dwncarousel':{
   'type' : 'js',
   'fullpath' : '/lab/2008/extend-yuiloader/carousel-min.js',
   'requires':['dwncarouselcss','yahoo','event','dom',
                'containercore','animation']
  }
 }
}
}</code></pre>
<p>请看<a href="/lab/2008/extend-yuiloader/" class="link-btn">演示实例1</a></p>
<h3>方法2：利用YAHOO.lang.extend方法封装一个新的Loader</h3>
<pre><code>YAHOO.namespace('CN.util');
<span>/* start:YAHOO.CN.util.YUILoader */</span>
YAHOO.CN.util.YUILoader = function(o){
 YAHOO.CN.util.YUILoader.superclass.constructor.call(this,o);
  this.base = 'http://cn.yui.yahooapis.com/2.5.1/build/';
  this.addModule({
   'name': 'container',
   'type': 'js',
   'path': 'container/container-min.js',
   'requires': ['dom', 'event'],
   'optional': ['dragdrop', 'animation', 'connection'],
   'supersedes': ['containercore'],
   'skinnable': false
  });
  this.addModule({
   'name' : 'dwncontainercss',
   'type' : 'css',
   'fullpath' : '/lab/2008/extend-yuiloader/container.css'
  });
  this.addModule({
   'name' : 'dwncarouselcss',
   'type' : 'css',
   'fullpath' : '/lab/2008/extend-yuiloader/carousel.css'
  });
  this.addModule({
   'name' : 'dwncarousel',
   'type' : 'js',
   'fullpath' : '/lab/2008/extend-yuiloader/carousel-min.js',
   'requires':['dwncarouselcss','yahoo','event','dom',
                'containercore','animation']
  });
}
YAHOO.lang.extend(YAHOO.CN.util.YUILoader,YAHOO.util.YUILoader);
<span>/* end: YAHOO.CN.util.YUILoader */</span></code></pre>
<p>YAHOO.CN.util.YUILoader的使用和<a href="http://developer.yahoo.com/yui/yuiloader/#using">YAHOO.util.YUILoader的使用</a>没有任何区别。请看<a href="/lab/2008/extend-yuiloader/index1.html" class="link-btn">演示实例2</a></p>
<h3><ins datetime="2008-03-28T09:46:41+08:00">两种方法的优劣比较</ins></h3>
<p>方法1的缺点是需要修改YUI Loader的源文件，而方法二2只是外层增加一个壳，比较友好和保险，但方法1直接修改配置文件的方法比方法2每次实例化都需要通过特定方法修改配置文件要高效，特别是当添加或者修改的配置模块间也有依赖关系的时候，方法2很可能会因为过度运算而死掉。例如把实例中的模块<code>container</code>依赖于<!--more-->dwncontainercss的时候，方法1没有问题（请看<a href="/lab/2008/extend-yuiloader/index2.html" class="link-btn">演示实例3</a>），但方法2下浏览器会提示脚本忙（请看<a href="/lab/2008/extend-yuiloader/index3.html" class="link-btn">演示实例4</a>）。</p>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2008/03/26/extend-yuiloader/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

