<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: MPR Preparation Part 2</title>
	<atom:link href="http://www.delusionworld.com/mootools/mpr-preparation-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.delusionworld.com/mootools/mpr-preparation-part-2/</link>
	<description>my MooTools, TYPO3 and FLOW3 experiences</description>
	<lastBuildDate>Sat, 10 Apr 2010 08:26:52 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Greg Houston</title>
		<link>http://www.delusionworld.com/mootools/mpr-preparation-part-2/comment-page-1/#comment-37</link>
		<dc:creator>Greg Houston</dc:creator>
		<pubDate>Wed, 11 Mar 2009 20:25:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.delusionworld.com/?p=16#comment-37</guid>
		<description>Things become a bit more complicated however if the plugin being loaded on the fly also uses $require to load another plugin that it extends, and even more complicated if that plugin in turn needs to first load yet another plugin that it extends.

Generally it is fine if the CSS loads after the plugin is ran, but in some cases the CSS needs to be loaded first such as when the plugin uses getStyle() or custom functions like getCSSRule(). So this would be yet another situation where a more complicated callback system would be required than the code above by itself.

So in some cases it would be nice if there was an onload callback telling us ALL the required assets have been loaded.

This lazy loader has a feature something along those lines, though I don&#039;t think it checks for nested dependencies:
http://ajaxian.com/index.php?s=lazy+load&amp;searchbutton=Go</description>
		<content:encoded><![CDATA[<p>Things become a bit more complicated however if the plugin being loaded on the fly also uses $require to load another plugin that it extends, and even more complicated if that plugin in turn needs to first load yet another plugin that it extends.</p>
<p>Generally it is fine if the CSS loads after the plugin is ran, but in some cases the CSS needs to be loaded first such as when the plugin uses getStyle() or custom functions like getCSSRule(). So this would be yet another situation where a more complicated callback system would be required than the code above by itself.</p>
<p>So in some cases it would be nice if there was an onload callback telling us ALL the required assets have been loaded.</p>
<p>This lazy loader has a feature something along those lines, though I don&#8217;t think it checks for nested dependencies:<br />
<a href="http://ajaxian.com/index.php?s=lazy+load&amp;searchbutton=Go" rel="nofollow">http://ajaxian.com/index.php?s=lazy+load&amp;searchbutton=Go</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Houston</title>
		<link>http://www.delusionworld.com/mootools/mpr-preparation-part-2/comment-page-1/#comment-36</link>
		<dc:creator>Greg Houston</dc:creator>
		<pubDate>Wed, 11 Mar 2009 18:45:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.delusionworld.com/?p=16#comment-36</guid>
		<description>I just started playing with MPR. A fun thing I discovered is if you add the onload argument to $require then you can set it up so that trying to run certain plugin methods will first load the plugin and then retry running the method along with whatever arguments were initially passed.

The following goes in the core JavaScript file of &quot;MyLibrary&quot;. If someone tries to use the tab plugin by running MyLibrary.initializeTabs(el) and the plugin has not been loaded yet, then the plugin is loaded. The plugin overwrites MyLibrary.initializeTabs, and then the function the user tried to run is ran again, passing their arguments right along.

&lt;code&gt;
var MyLibrary = new Hash({

	// ...
		
	initializeTabs: function(arg){
		$require(MyLibrary.options.path.source + &#039;Components/Tabs.js&#039;, function(){MyLibrary.initializeTabs(arg)});
	},
	
	// ...
		
});	
&lt;/code&gt;

The modified MPR code:
&lt;code&gt;
function $require(source, onload) {
	if ( MyLibrary.files[source] ) return true;
	// console.log(&#039;require &#039;, source);
	MyLibrary.files[source] = 1;
	
	switch ( source.match(/\.\w+$/)[0] ) {
		case &#039;.js&#039;: return Asset.js(source, {&#039;onload&#039;: onload ? onload : $empty});
		case &#039;.css&#039;: return Asset.css(source);
		case &#039;.jpg&#039;:
		case &#039;.png&#039;:
		case &#039;.gif&#039;: return Asset.image(source);
	}
	
	alert(&#039;The required file &quot;&#039; + source + &#039;&quot; could not be loaded&#039;);
}

Asset.extend({
	js: function(source, properties) {
		var a = new Request({ url: source, async: false, evalResponse: true, method: &#039;get&#039; }).send();
		return Asset.javascript(source, properties);
	}
});
&lt;/code&gt;

Crosses fingers that code tags work.</description>
		<content:encoded><![CDATA[<p>I just started playing with MPR. A fun thing I discovered is if you add the onload argument to $require then you can set it up so that trying to run certain plugin methods will first load the plugin and then retry running the method along with whatever arguments were initially passed.</p>
<p>The following goes in the core JavaScript file of &#8220;MyLibrary&#8221;. If someone tries to use the tab plugin by running MyLibrary.initializeTabs(el) and the plugin has not been loaded yet, then the plugin is loaded. The plugin overwrites MyLibrary.initializeTabs, and then the function the user tried to run is ran again, passing their arguments right along.</p>
<p><code><br />
var MyLibrary = new Hash({</p>
<p>	// ...</p>
<p>	initializeTabs: function(arg){<br />
		$require(MyLibrary.options.path.source + 'Components/Tabs.js', function(){MyLibrary.initializeTabs(arg)});<br />
	},</p>
<p>	// ...</p>
<p>});<br />
</code></p>
<p>The modified MPR code:<br />
<code><br />
function $require(source, onload) {<br />
	if ( MyLibrary.files[source] ) return true;<br />
	// console.log('require ', source);<br />
	MyLibrary.files[source] = 1;</p>
<p>	switch ( source.match(/\.\w+$/)[0] ) {<br />
		case '.js': return Asset.js(source, {'onload': onload ? onload : $empty});<br />
		case '.css': return Asset.css(source);<br />
		case '.jpg':<br />
		case '.png':<br />
		case '.gif': return Asset.image(source);<br />
	}</p>
<p>	alert('The required file "' + source + '" could not be loaded');<br />
}</p>
<p>Asset.extend({<br />
	js: function(source, properties) {<br />
		var a = new Request({ url: source, async: false, evalResponse: true, method: 'get' }).send();<br />
		return Asset.javascript(source, properties);<br />
	}<br />
});<br />
</code></p>
<p>Crosses fingers that code tags work.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
