<?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>delusionworld blog &#187; MooTools</title>
	<atom:link href="http://www.delusionworld.com/tag/mootools/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.delusionworld.com</link>
	<description>my MooTools, TYPO3 and FLOW3 experiences</description>
	<lastBuildDate>Sun, 01 Nov 2009 11:57:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MooTools Plugin CanvasOverlay</title>
		<link>http://www.delusionworld.com/mootools/mootools-plugin-canvasoverlay/</link>
		<comments>http://www.delusionworld.com/mootools/mootools-plugin-canvasoverlay/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 11:18:59 +0000</pubDate>
		<dc:creator>daKmoR</dc:creator>
				<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Imagemap]]></category>
		<category><![CDATA[MPR]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Repository]]></category>

		<guid isPermaLink="false">http://www.delusionworld.com/?p=107</guid>
		<description><![CDATA[Uses canvas to dynamically create overlays (with fill, border, glow) for Images with imagemaps
MPR Demo
MPR Docu
it&#8217;s basically a jQuery port from:
http://davidlynch.org/js/maphilight/docs/
it doesn&#8217;t support IE as it doesn&#8217;t have canvas and I didn&#8217;t wanted to hack around with VML&#8230; :p
]]></description>
			<content:encoded><![CDATA[<p>Uses canvas to dynamically create overlays (with fill, border, glow) for Images with imagemaps</p>
<p><a href="http://mpr.mooforum.net/MprAdmin.php?mode=demo&#038;file=./Visual/CanvasOverlays/Demos/CanvasOverlays.html">MPR Demo</a><br />
<a href="http://mpr.mooforum.net/MprAdmin.php?mode=docu&#038;file=./Visual/CanvasOverlays/Docu/CanvasOverlays.md">MPR Docu</a></p>
<p>it&#8217;s basically a jQuery port from:<br />
<a href="http://davidlynch.org/js/maphilight/docs/">http://davidlynch.org/js/maphilight/docs/</a></p>
<p>it doesn&#8217;t support IE as it doesn&#8217;t have canvas and I didn&#8217;t wanted to hack around with VML&#8230; :p</p>
]]></content:encoded>
			<wfw:commentRss>http://www.delusionworld.com/mootools/mootools-plugin-canvasoverlay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MPR Best Practice &#8211; Plugin MultiOverlays</title>
		<link>http://www.delusionworld.com/mootools/mpr-best-practice-plugin-multioverlays/</link>
		<comments>http://www.delusionworld.com/mootools/mpr-best-practice-plugin-multioverlays/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 13:04:44 +0000</pubDate>
		<dc:creator>daKmoR</dc:creator>
				<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Milkbox]]></category>
		<category><![CDATA[MultiOverlays]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Repository]]></category>

		<guid isPermaLink="false">http://www.delusionworld.com/?p=93</guid>
		<description><![CDATA[So now we have this local part of MPR to help us using MooTools Plugins. But howto create such Plugins and what should you use&#8230;
(bad) Examples
At first let me show you some examples why it&#8217;s not so easy currently to work with MooTools. I think the main reason is that it&#8217;s pretty hard to use [...]]]></description>
			<content:encoded><![CDATA[<p>So now we have this local part of MPR to help us using MooTools Plugins. But <strong>howto create</strong> such Plugins and what should you use&#8230;</p>
<h2>(bad) Examples</h2>
<p>At first let me show you some examples why it&#8217;s not so easy currently to work with MooTools. I think the main reason is that <strong>it&#8217;s pretty hard to use multiple files</strong> (js, css, img&#8230;) so people <strong>try to do everything in ONE file</strong>.</p>
<h3>Example <a href="http://mpr.mooforum.net/MprAdmin.php?mode=demo&#038;file=./Galleries/Milkbox/Demos/Milkbox.html">Milkbox</a>:</h3>
<p>Whenever you add it you will <strong>automatically add an Event to domready</strong> to create a milkbox with the default params&#8230; But what if I don&#8217;t want to use it on a page, I <strong>can&#8217;t easily disable it</strong> as I would <strong>need to edit the file</strong>.<br />
[don't get me wrong - milkbox is cool, I'm just saying it might be even better this way...]<br />
It would be nicer if separate in more files:</p>
<ul>
<li>Milkbox.js // class Milkbox &#8211; with the milkbox effect</li>
<li>Milkboxes.js // class Milkboxes &#8211; create multiple Milkboxes and has the logic for &#8220;galleries&#8221;</li>
<li>AutoMilkboxes.js // will require Milkboxes and will add it&#8217;s creation to the domready event</li>
</ul>
<p>With that now we can decide what we want to include. For the <strong>&#8220;basic&#8221; user</strong> its just $require( AutoMilkbox ); and people who know can decide if they either want one or multiple milkboxes. However as I said above <strong>using 3 files for one plugin</strong> without MPR is pretty inconvenient so people don&#8217;t do it. [and by inconvenient I mean <strong>it's freaking crazy</strong> to use 3 script tags for one little plugin - no no no; and yeah we all don't want to build our own script.json for each plugin... (little side kick to the devs..) :p]<br />
<strong>Now you can, just use MPR <img src='http://www.delusionworld.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong></p>
<h3>Example <a href="http://www.clientcide.com/wiki/cnet-libraries/07-ui/11-waiter">clientcide Waiter</a>:</h3>
<p>[again, the waiter is cool, but it might be better this way]<br />
As you can see in it&#8217;s docs there if you have this &#8221; baseHref: &#8216;&#8230;&#8217; &#8221; which means that if you use the class the <strong>image will be by default loaded</strong> from this location: <a href="http://www.cnet.com/html/rb/assets/global/waiter/waiter.gif">http://www.cnet.com/html/rb/assets/global/waiter/waiter.gif</a> I think this is another &#8220;hack&#8221; around the <strong>MooTools policy</strong> &#8220;<em>don&#8217;t use more than one file in your Plugin</em>&#8221; *<em>hehe</em> offending people here&#8230;*.<br />
I mean what happens if this file gets forgotten? server upgrade &#8211; do we still need this waiter.gif? no, just delete it&#8230; :p ok that might be not the actual process but there is surely the<strong> possibility</strong> that <strong>this file will just vanish</strong> without a notice&#8230; why not deliver the file with the Plugin?<br />
It would gives me again a few benefits</p>
<ul>
<li>I can easily replace the image to my own (no need to change any js/css; just replace the file)</li>
<li>I can define/override the url in my css (if uses as background image) so again no need to change any javascript</li>
<li>What if I have multiple image files? I mean if I have a Plugin that uses some images from the cnet server; some from the plugin server; and some from my own server.. pretty hard to maintain right?</li>
</ul>
<h2>use of MPR within the Plugin <a href="http://mpr.mooforum.net/MprAdmin.php?mode=demo&#038;file=./Visual/MultiOverlays/Demos/MultiOverlays.html">MultiOverlays</a></h2>
<p>So now let&#8217;s take a closer look at a Plugin and a way I think it should be done. </p>
<h3>File MultiOverlay.js</h3>
<pre class="brush: javascript;">
$require(MPR.path + 'Core/Fx.Tween/Fx.Tween.js');
$require(MPR.path + 'More/Class.Occlude/Class.Occlude.js');
var MultiOverlay = new Class({
  ...
});
</pre>
<p>ok, here we define the <strong>requirements and the logic</strong> for one MultiOverlay. now if you want to use it I need to use it with an id and create the Class instance myself. If you know how it&#8217;s easy&#8230;</p>
<pre class="brush: javascript;">var myMultiOverlay = new MultiOverlay( $('imageWithId') );</pre>
<h3>File MultiOverlays.js</h3>
<p>this file is so short I will post it&#8217;s full code here&#8230;</p>
<pre class="brush: javascript;">
$require(MPR.path + 'Visual/MultiOverlays/MultiOverlay.js');
var MultiOverlays = new Class({
	multiOverlays: [],
	initialize: function(elements, options) {
		$$(elements).each( function(el) {
			this.multiOverlays.include( new MultiOverlay(el, options) );
		}, this);
	},
	getMultiOverlays: function() {
		return this.multiOverlays;
	}
});
</pre>
<p>So what do we get here, it just gives you the possibility to create <strong>Multiple MultiOverlay(s)</strong>&#8230; So now you can give the image(s) a class and for each image it will create a MultiOverlay instance which get&#8217;s saved in an array (if you may need it any time later&#8230;)</p>
<h3>File AutoMultiOverlays.js</h3>
<p>again such a short file&#8230; here is it&#8217;s code&#8230;</p>
<pre class="brush: javascript;">
$require(MPR.path + 'Visual/MultiOverlays/MultiOverlays.js');
var Auto = Auto || {};
window.addEvent('domready', function() {
	Auto.MultiOverlays = new MultiOverlays( '.MultiOverlay' );
});
</pre>
<p>basically it just creates a <strong>new MultiOverlays</strong> with a <strong>hard coded &#8220;default&#8221; value</strong>&#8230; so if you require this file you don&#8217;t need to write any javascript code at all, just give the CSS-class to your images and your done! <strong>It&#8217;s the easiest way you can do it&#8230; </strong>[here the value get's saved in the Auto variable as I might still want to use it later... the Auto variable is globally here]</p>
<h3>So why all this files?</h3>
<p>As I said above I think it&#8217;s vital to <strong>separate logic</strong> to where it belongs. And for me that means if I want to have a single MultiOverlay I should be able to. So the logic for Multiple MultiOverlays shouldn&#8217;t be in it, as it&#8217;s just more stuff I don&#8217;t need&#8230; :p<br />
And while we are at it, now that we need a Folder for it let&#8217;s add the <a href="http://mpr.mooforum.net/MprAdmin.php?mode=docu&#038;file=./Visual/MultiOverlays/Docu/MultiOverlays.md">Docu</a>. So now we got <strong>demos, docu, Resources</strong>(css, images) all in a single <a href="http://mpr.mooforum.net/MprAdmin.php?mode=zip&#038;file=Visual/MultiOverlays">Plugin Zip file</a>.<br />
It&#8217;s just <strong>easy to send</strong> it to someone and <strong>he get&#8217;s everything</strong> &#8211; I don&#8217;t need to explain what css image files he has to manually include&#8230; If you have a local MPR you can just <strong>install it in the admin area</strong>&#8230;.  (talking about easy&#8230; <img src='http://www.delusionworld.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<p>What do you want to hear next? more MPR best Pratice?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.delusionworld.com/mootools/mpr-best-practice-plugin-multioverlays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>General MooTools UI</title>
		<link>http://www.delusionworld.com/mootools/general-mootools-ui/</link>
		<comments>http://www.delusionworld.com/mootools/general-mootools-ui/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 13:41:46 +0000</pubDate>
		<dc:creator>daKmoR</dc:creator>
				<category><![CDATA[MooTools]]></category>
		<category><![CDATA[progressive Enhancement]]></category>
		<category><![CDATA[Repository]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.delusionworld.com/?p=65</guid>
		<description><![CDATA[While I was trying to fully utilize progressive Enhancement I had another idea. Why not separate functionality and layout even while writing javascript/MooTools. That way it would be far easier to create different layouts for the same functionality without the need to reproduce code. Again let&#8217;s just look at an example:
simple tabs (my favorite example&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>While I was trying to fully utilize progressive Enhancement I had another idea. Why not <strong>separate functionality and layout</strong> even while writing javascript/MooTools. That way it would be far easier to <strong>create different layouts for the same functionality</strong> without the need to reproduce code. Again let&#8217;s just look at an example:<br />
<a href="http://www.delusionworld.com/files/general-mootools-ui/mootools-tabs.html">simple tabs</a> (my favorite example&#8230; :p)</p>
<pre class="brush: js;">
var myTabs = new FlowTabs.inline( $$('.FlowTabs &gt; h4'), $$('.FlowTabs &gt; div') );
</pre>
<p><em>If you look at the source you will find an &#8220;$require(&#8230;);&#8221; it&#8217;s just the same as including the file directly with script or link tag.</em> You can find more info about that in my previous posts about MPR. So what do we get with this code &#8211; <strong>It just gives us the functionality</strong> and looks pretty shitty, as only the necessary things are defined. Now let&#8217;s take at an example where we use the UI. <a href="http://www.delusionworld.com/files/general-mootools-ui/mootools-ui-tabs.html">simple ui tabs</a></p>
<pre class="brush: js;">
UI.render('Plain');
</pre>
<p>So it looks now a little bit nicer, but that can all be done with CSS &#8211; and you are right as if we look at the source of the UI.Plain.Tabs it does nothing &#8211; it <strong>just includes 2 css files</strong>&#8230;.</p>
<pre class="brush: js;">
$require(MPR.path + 'Ui/Plain/Plain.js');

$require(MPR.path + 'Snippets/Css/Resources/clearfix.css');
$require(MPR.path + 'Ui/Plain/Resources/Plain.Tabs.css');

Ui.Plain.Tabs = new Class({
	Implements: [Options],
	options: {
	},

	initialize: function(options) {
		this.setOptions(options);
	}
});
</pre>
<p>How boring is that?!?! Seems like we <strong>need a little more complicated example</strong>. I guess most of you know the MochaUI &#8211; how about adopting some style from it&#8230;</p>
<h2>MochaUI Tabs</h2>
<p><a href="http://www.delusionworld.com/files/general-mootools-ui/mootools-ui-tabs-mocha.html">mocha ui tabs</a></p>
<pre class="brush: js;">
$require(MPR.path + 'Ui/Mocha/Mocha.Tabs.js');
UI.render('Mocha');
</pre>
<p>only those 2 lines changed &#8211; we now load a different UI class and render a different theme called &#8216;Mocha&#8217;&#8230; so let&#8217;s look at it&#8217;s functions</p>
<pre class="brush: js;">
initialize: function(tabs, options) {
	this.setOptions(options);
	this.attach(tabs);
},

attach: function(tabs) {
	if ( $type(tabs) == 'string' ) tabs = $$(tabs);
	if ( $type(tabs) == 'element' ) tabs = [tabs];

	tabs.each( function(el) {
		var inside = new Element('span', { html: el.get('html') } );
		el.empty();
		el.grab(inside);
	}, this);
}
</pre>
<p>It&#8217;s again not really funny as it <strong>just creates an span inside every tab</strong> &#8211; we could have easily put this inside the &#8220;original&#8221; Tab Class. However what if the<strong> problem is a little bit more complex</strong> and the <strong>layout is also quite heavy on it&#8217;s own</strong>. Wouldn&#8217;t it be nice to separate these problems&#8230; Yeah I guess with just words you won&#8217;t believe me. So I will show you something more complex afterward.<br />
But for now <strong>let&#8217;s find out how the UI knows what theme to render and with which parameters</strong>. For that we need to look at the FlowTabs.inline.js file&#8230; at the bottom you will find:</p>
<pre class="brush: js;">
if ( typeof(UI) !== 'undefined' ) UI.registerClass({ 'Tabs': { 'param': '.ui-tab', 'name': 'FlowTabs.inline' } });
</pre>
<p>So what this does is basically it <strong>registers the FlowTabs Class as a Tabs Class</strong> with it&#8217;s default parameter and it&#8217;s name&#8230; Now when the UI is rendered it calls UI.<em>theme</em>.Tabs(<em>param</em>) and that&#8217;s exactly what we created earlier: &#8220;Ui.Mocha.Tabs = new Class({&#8221;</p>
<p>So let&#8217;s <strong>summaries this a little</strong>&#8230; until now it works like:</p>
<ul>
<li>create all Tabs + Content</li>
<li>call the UI Class that will look for predefined classes and it will modify the layout accordingly</li>
</ul>
<p>That&#8217;s pretty straight forward and in many situations this will work pretty well. <strong>However what about dynamically created tabs</strong> after the initial creation. I don&#8217;t know maybe loading with ajax or as a user populates some fields&#8230; So my FlowTabs class my support creating these Tabs on the fly but I somehow need to tell the UI that new Tabs are created and they need to be styled.</p>
<p>So now how do we do that:<br />
FlowTabs.inline.js in the attach function (creating of the tabs) we just fire an Event and give it some things to work with:</p>
<pre class="brush: js;">
this.fireEvent('onUiAttach', [el, j-1, content[i], this.tabsContainer]);
</pre>
<p>now what we need to do is use this onUiAttach Event. For that we just define this.options.refactor</p>
<pre class="brush: js;">
Ui.Mocha.Tabs = new Class({
	Implements: [Options],
	options: {
		refactor: {
			options: {
				onUiAttach: function(el, i) {
					if ( (typeof(UI) !== 'undefined') &amp;&amp; ( typeof(UI.Uis.Tabs) !== 'undefined' ) ) {
						UI.Uis.Tabs.attach( $(el) );
					}
				}
			}
		}
	},
</pre>
<p>If this is provided the <strong>UI will either refactor the class</strong> (if it hasn&#8217;t been instantiated) or it <strong>will set it options</strong> if the class has already been instantiated. [This doesn't seem to work currently - so note at the end]  To detect that we have another function in FlowTabs.inline that will be called on initialize:</p>
<pre class="brush: js;">
registerUi: function() {
	if ( typeof(UI) !== 'undefined' )
		UI.registerClass({ 'Tabs': { 'param': '.' + this.options.ui.tab['class'], 'name': 'FlowTabs.inline', 'class': this } });
}
</pre>
<p>it&#8217;s <strong>basically the same as the registration above</strong>, only that we now get the param from the option &#8211; this will help for example if we want to change the classes of the tabs; with that we don&#8217;t need to change them on the Tab creation script and on the Tab UI script&#8230; it will be automatically updated on the UI script. <strong>And we give the ui as &#8216;class&#8217; this</strong> (that&#8217;s pretty important!).</p>
<p>So now with all that it doesn&#8217;t matter when the UI [UI.render('Mocha');] is called as:</p>
<ul>
<li>If you call it at the beginning before all the tabs are created it basically does nothing except that it refactors every Class that it might need. So these classes then automatically do the right thing when the Event onUiAttach is fired.</li>
<li>If you call it at the end it will create all the necessary layout and set the options for every Class that&#8217;s registered so further elements that get attached get the layout automatically.</li>
</ul>
<p>I still prefer to call the UI at the and as it might need a little bit less performance. [so also note at the end]</p>
<h2>FlowWindows</h2>
<p>So now <strong>let&#8217;s go for an more complex example</strong>. Let&#8217;s talk about windows&#8230; I think there are quite a few implementations out there&#8230; MochaUI for example &#8211; it&#8217;s Window Class is really cool. However it&#8217;s also really really big. So what if I just want a little div to resize and drag around. <strong>I think functionality and UI should be separated</strong>. I mean now I needed to write my own class as I didn&#8217;t &#8220;wanted&#8221; to use a complex layout as MochaUI&#8230;. the functionality would be great but <strong>you can&#8217;t get MochaUI Window without the Layout</strong>&#8230;<br />
So basically that&#8217;s what I came up: <a href="http://www.delusionworld.com/files/general-mootools-ui/mootools-windows.html">simple windows</a>. (I looked up some things at MochaUI window so it wasn&#8217;t that hard&#8230; :p)</p>
<p>If you look at it you see:</p>
<pre class="brush: js;">
$require(MPR.path + 'Windows/FlowWindows/FlowWindows.js');
[...]
var myWindows = new FlowWindows( $$('.FlowWindow &gt; h3')[0], $$('.FlowWindow &gt; div')[0] );
myWindows.attach( $$('.FlowWindow &gt; h3')[0], $$('.FlowWindow &gt; div')[0] );
</pre>
<p>So this just creates all the divs needed for all the handlers to resize, the header, the controlls&#8230; <strong>all you need for a nice window</strong>&#8230; but it&#8217;s ugly. yeah sure it&#8217;s<strong> just for functionality</strong> no UI at all. Now let&#8217;s get some UI &#8211; <a href="http://www.delusionworld.com/files/general-mootools-ui/mootools-ui-windows.html">the plain UI</a> is not really something special (again no change with js &#8211; just css). To use it &#8211; there are just some small differences&#8230;</p>
<pre class="brush: js;">
$require(MPR.path + 'Ui/Plain/Plain.Full.js');
[...]
UI.render('Plain');
</pre>
<p>we include <strong>Plain.Full which will give me all available UI elements of Plain</strong> &#8211; currently Tabs and Windows. In the end we just need to start UI.render &#8230;</p>
<p>So now comes the nice stuff, if I want to just change the style of the Tabs and the Windows I <strong>don&#8217;t need to change any of the Functionality Classes</strong>. I just need to change the UI with:</p>
<pre class="brush: js;">
$require(MPR.path + 'Ui/Mocha/Mocha.Full.js');
[...]
UI.render('Mocha');
</pre>
<p>and we get <a href="http://www.delusionworld.com/files/general-mootools-ui/mootools-ui-windows-mocha.html">Mocha Layout</a> for Tabs and Windows.</p>
<p>The<strong> Mocha.Windows is a little bit more complicated</strong> as it needed a Canvas which gets updated on every size change. But in the end it&#8217;s really flexible and the best thing is if you want to change the functionality you don&#8217;t have to think (to much) about they layout. Moreover this also works the other way around. It&#8217;s far easiere to create just the layout for a specific structure than to create all the functionality&#8230;</p>
<p>one other thing that might come in handy is that you can start the UI without any functionality classes&#8230;.<a href="http://www.delusionworld.com/files/general-mootools-ui/mootools-ui-only-mocha.html">Mocha UI only</a>. The html markup has to be created accordingly by a server scripting language or so&#8230; Starting the UI is again pretty simple</p>
<pre class="brush: js;">
$require(MPR.path + 'Ui/Mocha/Mocha.Full.js');
window.addEvent('domready', function() {

	//say we want to use the WindowsUI and the TabsUI
	UI.render('Mocha', {
		'Windows': {
			'param': '.ui-window'
		},
		'Tabs': {
			'param': '.ui-tab'
		}
	});

});
</pre>
<p>I currently can only think of one rule you need to follow (maybe I get some more ofer time&#8230;):</p>
<ul>
<li>include the UI classes always after the functionality classes</li>
</ul>
<p>Limitation:</p>
<ul>
<li>the setOptions method (if the UI is called at the end) only support options while with refactor you can override and define new functions.
</ul>
<h2>Note at the end:</h2>
<p>The setOptions doesn&#8217;t seem to work for subclasses if&#8230; yeah right if I knew that I would fix it, but for now the UI should be called at the top if you need some complex update functions like for MochaUI Window (for all the other stuff it also works at the end) [I guess the problem lies somewhere in between <a href="http://www.delusionworld.com/files/MPR/Ui/Ui.js">the UI - fireEvent('onUiInit');</a> and <a href="http://www.delusionworld.com/files/MPR/Ui/Mocha/Mocha.Windows.js">the UI.Mocha - this.options.refactor.options.onUiInit</a>. If you catch any error - I'm open for suggestions...]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.delusionworld.com/mootools/general-mootools-ui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>progressive vs non-progressive development</title>
		<link>http://www.delusionworld.com/webdev/progressive-vs-non-progressive-development/</link>
		<comments>http://www.delusionworld.com/webdev/progressive-vs-non-progressive-development/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 00:25:03 +0000</pubDate>
		<dc:creator>daKmoR</dc:creator>
				<category><![CDATA[WebDev]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[progressive Enhancement]]></category>
		<category><![CDATA[Tabs]]></category>

		<guid isPermaLink="false">http://www.delusionworld.com/?p=54</guid>
		<description><![CDATA[Progressive Enhancement will not only help you to support different levels of context &#8211; it can also help you during development. So let&#8217;s look at an example again (here is an overview).
What we see here is just a simple way of displaying content that might be transformed to tabs.

&#60;div class=&#34;FlowTabs&#34;&#62;
	&#60;h4 class=&#34;Tab&#34;&#62;Short Text&#60;/h4&#62;
	&#60;div class=&#34;TabContent&#34;&#62;Lorem ipsum dolor [...]]]></description>
			<content:encoded><![CDATA[<p>Progressive Enhancement will not only help you to support different levels of context &#8211; it can also help you during development. So let&#8217;s look at an <a href="http://www.delusionworld.com/files/progressive-vs-non-progressive-development/progressive.Basic.html">example</a> again (here is an <a href="http://www.delusionworld.com/files/progressive-vs-non-progressive-development/">overview</a>).</p>
<p>What we see here is just a <strong>simple way</strong> of displaying content <strong>that might be transformed to tabs.</strong></p>
<pre class="brush: html;">
&lt;div class=&quot;FlowTabs&quot;&gt;
	&lt;h4 class=&quot;Tab&quot;&gt;Short Text&lt;/h4&gt;
	&lt;div class=&quot;TabContent&quot;&gt;Lorem ipsum dolor [...]&lt;/div&gt;
	&lt;h4 class=&quot;Tab&quot;&gt;Long Text&lt;/h4&gt;
	&lt;div class=&quot;TabContent&quot;&gt;Sed ut perspiciatis [...]&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The h4 could be the title and the div could be the content. So without any js magic it&#8217;s just a header and some content below. It&#8217;s clear that the h4 is the header for the following text. It&#8217;s just simple.</p>
<h2>MooTools Tabs</h2>
<p>Now let&#8217;s look at the <a href="http://www.delusionworld.com/files/progressive-vs-non-progressive-development/progressive.MooTools.html">MooTools version</a>. The <strong>HTML just remains the same</strong>. Some modifications to the css so it&#8217;s look a little bit more like tabs. <em>[this is just an example, no style contest.. :p]</em><br />
The actual javascript is really boring:</p>
<pre class="brush: js;">
window.addEvent('domready', function() {
	$require(MPR.path + 'Tabs/FlowTabs/FlowTabs.inline.js');
	var myTabs = new FlowTabs.inline( $$('.FlowTabs .Tab'), $$('.FlowTabs .TabContent')  );
});
</pre>
<p>Just include the class and say we should <strong>get the tabs from &#8220;.Tab&#8221;</strong> and the <strong>content from &#8220;.TabContent&#8221;</strong>. If we wanted you could <strong>easily change this</strong>. Say we want to use the first h6 as title and the first div as content (without the classes) we only need to change the class call to &#8220;new FlowTabs.inline( $$(&#8217;.FlowTabs h6&#8242;), $$(&#8217;.FlowTabs > div&#8217;)  );&#8221;. So we are <strong>pretty flexible</strong> and can use this in different situation with the same progressive Enhancement functionality. <em>[ok, class creation takes some time - but once you have it it's so nice <img src='http://www.delusionworld.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  - I wrote this class just as an example for this, but I might release it at some point...]</em></p>
<h2>jQuery Tabs</h2>
<p>This was pretty easy right? Let&#8217;s assume we we want to <strong>change the javascript Framework</strong> (for whatever reason). Now this is usually a pretty bad day for us developers &#8211; means a lot of work and recreate all that stuff (if we wanna do it right and don&#8217;t use 2 Frameworks at the same time). However with <em>progressive Enhancement</em> <strong>half the work is already done</strong>. The style, the content, multi-language support&#8230; &#8211; all that is already working. We <strong>just</strong> need to <strong>recreate the behavior</strong>. I had no &#8220;real&#8221; glue about jQuery but I had it done within less than half an hour. Just take a look at the <a href="http://www.delusionworld.com/files/progressive-vs-non-progressive-development/progressive.jQuery.html">progressive Enhancement version with jQuery</a>. </p>
<pre class="brush: js;">
$('.FlowTabs').prepend('&lt;div class=&quot;inlineTabTabs clearfix&quot;&gt;&lt;/div&gt;');
var tabContainers = $('.FlowTabs .TabContent');
$('.FlowTabs .Tab').each( function(index) {
	$('.inlineTabTabs').append(this);
	$(this).click( function() {
		tabContainers.hide();
		tabContainers.filter(':eq(' + index + ')').show();

		$('.FlowTabs .Tab').removeClass('act');
		$(this).addClass('act');

		return false;
	})
}).filter(':eq(0)').click();
</pre>
<p>The code may not be the nicest and there a certainly some ways to make it more flexible like we can do this with MooTool classes, but I <strong>got it to work within a short time</strong> and it looks and feels exactly the same. I would say <strong>progressive Enhancement at it best</strong> <img src='http://www.delusionworld.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Now you may wonder why I didn&#8217;t used the <a href="http://stilbuero.de/jquery/tabs_3/">jQuery UI Tabs</a>. It&#8217;s for a simple reason &#8211; it&#8217;s no real progressive Enhancement (in the way I think of it). First the tabs are in a separate ul, li list at the top of all the content. So if you have no javascript all the tab titles will be disconnected from their content. Furthermore the the &#8220;headers&#8221; (tabs-title) are links and connected with their content through anchors. So this link href=&#8221;#myTabContent&#8221; will open the tab with the id=&#8221;myTabContent&#8221;. There are 2 reasons why I don&#8217;t like this: First I don&#8217;t want to create all this id&#8217;s and second why use links? there is no page to go to&#8230; ok, it makes partly sense because the &#8220;headers&#8221; are disconnected with there content, but that&#8217;s just an excuse for the first mistake so we certainly can do better right?</p>
<h2>ExtJS Tabs</h2>
<p>Now I tried to create the same effect with ExtJS, I was quite motivated as MooTools and jQuery went so smoothly. However <strong>the closest to progressive Enhancement I could come up </strong>with is more or less progressive Enhancement. <a href="http://www.delusionworld.com/files/progressive-vs-non-progressive-development/progressive.ExtJS.html">Let&#8217;s take a closer look</a>.</p>
<pre class="brush: js;">
Ext.onReady(function(){
	var tabs = new Ext.TabPanel({
		applyTo: 'FlowTabs',
		activeTab: 0,
		deferredRender: false,
		autoTabs: true
	});
});
</pre>
<p>Now with this &#8220;autoTabs: true&#8221; the TabPanel actually looks for &#8216;&lt;div class=&quot;x-tab&quot; title=&quot;myTabTitle&quot;&gt;&#8217; and create Tabs from it. It&#8217;s easy and again I don&#8217;t need to write many javascript. However I <strong>had to change my HTML so it&#8217;s not progressive Enhancement</strong>. Furthermore the title for the tab is not well displayed without javascript. Also I included the the 532KB ext-all.js and a 81KB ext-all.css, both minified. This quite some stuff and it doesn&#8217;t even let me choose which tabs and content is taken. Wow and yeah it looks different. I didn&#8217;t tried to style it accordingly as I had to change my original 4 lines (from the top &#8211; [basic]) to those 2 lines:</p>
<pre class="brush: js;">
&lt;div class=&quot;x-tab&quot; title=&quot;Short Text&quot;&gt;Lorem ipsum dolor [...]&lt;/div&gt;
&lt;div class=&quot;x-tab&quot; title=&quot;Long Text&quot;&gt;Sed ut perspiciatis [...]&lt;/div&gt;
</pre>
<p>and after the Ext.TabPanel has <strong>transformed it to 49(!!) HTML lines</strong>. You can either look at the code in firebug or look at this page where you can see the <a href="http://www.delusionworld.com/files/progressive-vs-non-progressive-development/ExtJS.generatedCode.txt">output code</a>. ok, this was a little bit to much for me, so I guess <strong>maybe I would need to create my own Ext widget</strong> to make it work, but if I need to write my own code I (me personally) wouldn&#8217;t choose ExtJS. <em>[I might be completely wrong here, as I don't know Ext well enough. However it seems like it works quite different than MooTools or jQuery]</em><strong><br />
Update: you can of course create your own script &#8211; Thomas Fritz was nice enough to provide an <a href="http://fritzthomas.com/files/extjs-progressive-enhancement-example/">example</a>. So it really just depends on your personal preference what Framework you wanna choose.</strong></p>
<h2>non-progressive ExtJS</h2>
<p>Now let&#8217;s take the other way around. We just start with a <a href="http://www.delusionworld.com/files/progressive-vs-non-progressive-development/non-progressive.ExtJS.html">Javascript Version by ExtJS</a>.</p>
<pre class="brush: js;">
Ext.onReady(function(){
	var tabs = new Ext.TabPanel({
		renderTo: 'FlowTabs',
		activeTab: 0,
		plain:true,
		defaults:{autoHeight: true},
		items:[
			{title:'Short Text', html: 'Lorem ipsum dolor [...]'},
			{title:'Long Text', html: 'Sed ut perspiciatis [...]'}
		]
	});
});
</pre>
<p>All the <strong>content is in the javascript</strong> so we don&#8217;t have any html-content that&#8217;s sent by the server. All the transformation from the content (JSON to HTML) is done by javascript. If you don&#8217;t have javascript you see a white page. It&#8217;s so not progressive Enhancement :p. Whenever I want to change content I need to change the javascript (but hey, I don&#8217;t need to change the html&#8230; :p). I don&#8217;t like this way but whatever. </p>
<h2>non-progressive MooTools</h2>
<p>Here we go, so now we have this start from a non-progressive page. I want to port it to another Javascript Framework. So now where do I start. hmmm yeah right &#8211; at the beginning? I don&#8217;t have any html I could take as a base. So I need to recreate everything from scratch again. So let&#8217;s just do it:</p>
<pre class="brush: js;">
var items = [
	{title:'Short Text', html: 'Lorem ipsum dolor [...]'},
	{title:'Long Text', html: 'Sed ut perspiciatis [...]'}
];

var container = new Element('div', { 'class' : 'FlowTabs' });
$each( items, function(el) {
	container.grab( new Element('h4', { 'class': 'Tab', html: el.title }) );
	container.grab( new Element('div', { 'class': 'TabContent', html: el.html }) );
});

$require(MPR.path + 'Tabs/FlowTabs/FlowTabs.inline.js');
var myTabs = new FlowTabs.inline( container.getElements('.Tab'), container.getElements('.TabContent') );

container.inject( $('FlowTabs') );
</pre>
<p>ok, I cheated a little. I just <strong>create the basic html</strong> from above &#8211; <strong>this time simply with javascript</strong>. Strange right? So now I have all this virtual dom element and here comes again a little MooTools magic (sorry for being biased :p). Even though nothing is in the dom, we can still create the object and hand the class the &#8220;virtual&#8221; items. Afterward we inject only the already modified html.</p>
<p>I didn&#8217;t tried to create it again with jQuery as I think it&#8217;s just not worth my time. It&#8217;s worthless time as progressive Enhancement is just way better. <img src='http://www.delusionworld.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Conclusion</h2>
<p>I&#8217;m <strong>more than ever confident </strong>that <strong>progressive Enhancement</strong> is the way <strong>to use javascript</strong>. And I just need to quote <a href="http://adactio.com/articles/1349/">Jeremy Keith</a> with: &#8220;Think about Ajax from the start but don’t implement it until the very end.&#8221; I can really recommend the first part of <a href="http://adactio.com/articles/1349/">this speak</a> (about the first 20 minutes).<br />
I also believe that there are currently only a few javascript &#8220;plugins&#8221; around that make use of &#8220;real&#8221; progressive Enhancement and that&#8217;s really sad as it saves time and give your content some sort of universality. Even if all the design all the behavior changes, your true content will always stay the same.</p>
<p>If there where a package based javascript library that would follow true progressive Enhancement with the same amount of features as the current ExtJS framework than I might not need to write this article <em>(if anyone knows something just let me know)</em>. I doubt it so I will just try to create such a library (just step by step) and I think the perfect base for something like this is MooTools.</p>
<p><em>Update: so here we are again &#8211; thx to an <a href="http://fritzthomas.com/files/extjs-progressive-enhancement-example/">example</a> from Peter Fritz every Framework just masters all the requirements. So yet again it&#8217;s just your personal preference what Framework you choose.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.delusionworld.com/webdev/progressive-vs-non-progressive-development/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>progressive Enhancement</title>
		<link>http://www.delusionworld.com/webdev/progressive-enhancement/</link>
		<comments>http://www.delusionworld.com/webdev/progressive-enhancement/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 16:56:42 +0000</pubDate>
		<dc:creator>daKmoR</dc:creator>
				<category><![CDATA[WebDev]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[progressive Enhancement]]></category>

		<guid isPermaLink="false">http://www.delusionworld.com/?p=24</guid>
		<description><![CDATA[What is progressive Enhancement? (from wikipedia)
Progressive enhancement is a strategy for web design that emphasizes accessibility, semantic markup, and external stylesheet and scripting technologies. Progressive enhancement uses web technologies in a layered fashion that allows everyone to access the basic content and functionality of a web page, using any browser or Internet connection, while also [...]]]></description>
			<content:encoded><![CDATA[<p>What is progressive Enhancement? (from wikipedia)</p>
<blockquote><p><strong>Progressive enhancement</strong> is a strategy for <a title="Web design" href="http://en.wikipedia.org/wiki/Web_design">web design</a> that emphasizes accessibility, semantic markup, and external stylesheet and scripting technologies. Progressive enhancement uses web technologies in a layered fashion that allows everyone to access the basic content and functionality of a web page, using any browser or Internet connection, while also providing those with better bandwidth or more advanced browser software an enhanced version of the page.</p></blockquote>
<p>So in other words you start with the most basic concept and evolve it with every step (but the <strong>basic concept always stays the same</strong>). So let&#8217;s do an <a href="http://www.delusionworld.com/files/progressive-enhancement/">example</a> (there you can see the actual code) [please don't use IE :p]:</p>
<h2>Basic</h2>
<p>Here we have the basic setup &#8211; simple html so even without css and everything the user will still be able to know what&#8217;s going on.<br />
As you can see it&#8217;s just about providing a Headline + some Help for a bunch of Input fields.</p>
<pre class="brush: html;">
&lt;h4&gt;Server Configuration&lt;/h4&gt;
&lt;a href=&quot;help.php?id=Server&quot;&gt;&lt;span&gt;(Help)&lt;/span&gt;&lt;/a&gt;
&lt;div&gt; Here are a lot of Inputs &lt;/div&gt;
&lt;h4&gt;General Configuration&lt;/h4&gt;
&lt;a href=&quot;help.php?id=General&quot;&gt;&lt;span&gt;(Help)&lt;/span&gt;&lt;/a&gt;
&lt;div&gt; Here are a lot of Inputs &lt;/div&gt;
</pre>
<h2>CSS Enhanced</h2>
<p>So now the HTML is completely the same we just add some CSS. With this it just looks nicer, but if at any time we remove the CSS it still makes sense. However I&#8217;m sure most of you know how to handle CSS.</p>
<pre class="brush: css;">
.cssEnhanced h4 { display: inline-block; margin: 10px 0 5px; }
.cssEnhanced a { background: url('img/help.png'); width: 16px; height: 16px; display: inline-block; margin-left: 5px; }
.cssEnhanced a span { display: none; }
</pre>
<h2>JS Enhanced</h2>
<p>With a little javascript we can do even more.</p>
<pre class="brush: js;">
$require('jsEnhanced.css'); //load a css with js, so it will only be included if js is enabled

window.addEvent('domready', function() {
	$require(MPR.path + 'Tools/Roar/Roar.js');
	var roar = new Roar();

	$$('.jsEnhanced a').each( function(el) {
		// load all message on startup - could also be done on mouseenter or click (would require a cache check)
		new Request.JSON({
			'url' : el.get('href') + '&amp;ajax=1',
			'method' : 'get',
			onComplete : function(tree, elements, html) {
				el.store('content', tree);
			}
		}).send();

		el.addEvents({
			'mouseenter': function() {
				roar.alert(el.retrieve('content').header, el.retrieve('content').msg );
			},
			'click': function(e) {
				e.stop(); // or return false; as we don't want to go to the page as the info is provided with js
			}
		});
	});  // $$('.jsEnhanced a').each(

});
</pre>
<p>First at line 1 we load an additional css with javascript to modify the image to show it doesn&#8217;t require a click. If javascript is disabled the icon will just stay as it was.</p>
<p>Then we wait for the dom to be ready(3), as afterward we just loop through all jsEnhanced links(7) and request all the messages we will need for this page(9-15). For the Request Url we just <strong>us the href from the link</strong> and add an <em>ajax=1</em>. By doing this the <a href="http://www.delusionworld.com/files/progressive-enhancement/help.txt">script</a> that provides the messages will know that we don&#8217;t need all the usual html stuff &#8211; just the data encoded in json.<br />
After the Request is Complete(12) we just <strong>save the output to the link</strong>(13). Finally we just add 2 Events to the links. One to display the message on hover(18) and one to stop the default click as we don&#8217;t want to see the standalone info page. [Note: we could also reshow the message on click or do something else]</p>
<h2>Javascript multi-language support for free</h2>
<p>So if you stick to the progressive enhancement you don&#8217;t even need to create a multi-language support for javascript on your own. Just create <strong>proper html</strong> code with your <strong>favorite server side programming language</strong>. And with proper I mean make the whole page with html first and <strong>enhance it afterward</strong>. So what do I mean by &#8220;get it for free&#8221;. Until now the html code has always been the same, just enhanced with css and javascript. So if I just create a <strong>multi-language support for html</strong> (and you will always need that) I don&#8217;t even need to touch my css or javascript as it will then just enhance my different language. So let&#8217;s change the html a little:</p>
<pre class="brush: html;">
&lt;h4&gt;Konfiguration des Servers&lt;/h4&gt;
&lt;a href=&quot;help.php?id=Server&amp;lang=de&quot;&gt;&lt;span&gt;(Hilfe)&lt;/span&gt;&lt;/a&gt;
&lt;div&gt;Hier gibt es eine Menge Inputs&lt;/div&gt;
&lt;h4&gt;Allgemein Konfiguration&lt;/h4&gt;
&lt;a href=&quot;help.php?id=General&amp;lang=de&quot;&gt;&lt;span&gt;(Hilfe)&lt;/span&gt;&lt;/a&gt;
&lt;div&gt;Hier gibt es eine Menge Inputs&lt;/div&gt;
</pre>
<p>Now it&#8217;s some German HTML with links to German help files (or in this case just a config for the script). <strong>I didn&#8217;t changed any css or js and it still works</strong>. So the only reason you need multi-language support in javascript is when you are lazy and don&#8217;t want to create proper html/css. I mean even if you have some messages that only make sense if you have javascript &#8211; just include them hidden?.</p>
<p>There are only TWO thing I can think of where you might want to have multi-language support in javascript. <em>ONE</em> is validation of inputs on the client and you don&#8217;t want to submit the form every time a user changes something so you can provide error messages. However it&#8217;s not even a real good exception, as</p>
<ol>
<li>with ajax request you could submit a form without disturbing the user</li>
<li>you still need a server side validation</li>
<li>you could include the messages as hidden content</li>
</ol>
<p><em>TWO</em> would be <strong>real javascript applications</strong> like a RichTextEditors or drawing canvas/svg &#8211; things that won&#8217;t display in any way as html.</p>
<p>So I would forgive you if you use multi-language support for javascript in these special cases.</p>
<p><em>What you can expect next &#8211; development comparison progressive enhancement vs non-progressive.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.delusionworld.com/webdev/progressive-enhancement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
