<?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>Gilles Cochez</title>
	<atom:link href="http://gillescochez.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://gillescochez.info</link>
	<description>Developing with passion since 1997</description>
	<lastBuildDate>Fri, 11 May 2012 21:45:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>jQuery.doTemplate</title>
		<link>http://gillescochez.info/2012/05/11/jquery-dotemplate/</link>
		<comments>http://gillescochez.info/2012/05/11/jquery-dotemplate/#comments</comments>
		<pubDate>Fri, 11 May 2012 21:41:48 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Plugins & engines]]></category>

		<guid isPermaLink="false">http://gillescochez.info/?p=223</guid>
		<description><![CDATA[doTemplate is a jQuery template plugin build around the high performance doT template engine, which is where the name come from and, well, it clearly state what it does do too Compilation time is where doTemplate is excel, thanks to &#8230; <a href="http://gillescochez.info/2012/05/11/jquery-dotemplate/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>doTemplate is a jQuery template plugin build around the high performance doT template engine, which is where the name come from and, well, it clearly state what it does do too <img src='http://gillescochez.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Compilation time is where doTemplate is excel, thanks to doT, the compilation results are stored as strings until they are requested to be converted to DOM (using toDOM() method or inserted into the dom (using the rendering methods). This allows for better compilation time and more flexibility as you can access the compiled items through the template items property, convert it into a jQuery object and access it or simply use on of the rendering methods to rendering to the document.</p>
<p>The template function is automatically cached and when items are converted to jQuery a data object is attached containing the source, data, compiler function and compiled string for the item being converted, this allow for creation of template based on existing data accessible in the DOM as well as based on an existing doTemplate instance.</p>
<p>Best thing is to try it and make your own mind, hopefully there is enough at <a href="https://github.com/gillescochez/jQuery.doTemplate">github</a> to help you get started <img src='http://gillescochez.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2012/05/11/jquery-dotemplate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LaboiteV2 now public on github</title>
		<link>http://gillescochez.info/2012/04/24/laboitev2-now-public-on-github/</link>
		<comments>http://gillescochez.info/2012/04/24/laboitev2-now-public-on-github/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 21:17:04 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Plugins & engines]]></category>

		<guid isPermaLink="false">http://gillescochez.info/?p=220</guid>
		<description><![CDATA[Introduction Also it&#8217;s not officially release yet laboite is starting to be at a stage where its functionalities are worth putting into the public eyes. Some of the main goals are already achieved and only few minor functionalities are missing &#8230; <a href="http://gillescochez.info/2012/04/24/laboitev2-now-public-on-github/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Also it&#8217;s not officially release yet laboite is starting to be at a stage where its functionalities are worth putting into the public eyes. Some of the main goals are already achieved and only few minor functionalities are missing even if many tweaks are still to come.</p>
<p>Like the old one the basic usage is as a jquery plugin however this one have effects and layouts objects which can be extended so that the plugin can create libraries of custom user interfaces and transition effects making customization a very easy tasks. See the readme on Github for more information on how to use those objects.</p>
<p>The plugin can also inject a gallery into the page instead of just offering the expected modal view which offers a lot more creative opportunities and also allows the markup to control the interface. Many options have also been added to the extend that the plugin could even be used to even create interface such as dropdown menus or preview windows.</p>
<p>If you want to find out more just go to the <a href="https://github.com/gillescochez/laboite">Github page</a>, read the readme document and checkout the demo folder.</p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2012/04/24/laboitev2-now-public-on-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>req.js</title>
		<link>http://gillescochez.info/2012/04/24/req-js/</link>
		<comments>http://gillescochez.info/2012/04/24/req-js/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 20:48:50 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://gillescochez.info/?p=215</guid>
		<description><![CDATA[Introduction req.js is tiny script / module (sort of) management system which can: Load javascript files and execute callback when the requested files are loaded Execute callbacks in the order they were declared for multiple identical requests Store objects declared &#8230; <a href="http://gillescochez.info/2012/04/24/req-js/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>req.js is tiny script / module (sort of) management system which can:</p>
<ul>
<li>Load javascript files and execute callback when the requested files are loaded</li>
<li>Execute callbacks in the order they were declared for multiple identical requests</li>
<li>Store objects declared using req API and make them available as arguments in the callback function when requested</li>
<li>Return its settings object and its module storage objects</li>
<li>Set and get configuration parameter</li>
<li>Can return a loaded/declared object from its storage</li>
</ul>
<h2>Usage</h2>
<pre class="brush: jscript; title: ; notranslate">
// load modules
req(['user','panel'], function(user, panel) {

});

// load modules in the callback scope and an external file in the global scope
req(['user','http://domain.com/data.js','panel'], function(user, panel) {

});

// set a configuration parameter
req('path','http://resources.domain.com/js/');

// set multiple configuration parameter
req({
    path: './',
    order: false
});

// get a configuration paramete
var p = req('get','path');

// get the settings object
var config = req().settings;

// declare a module
req('dummy', {
    foo: function() {
        console.log('foo');
    }
});

// request a module (the module must be loaded)
var mod = req('dummy');

// get an object containing all the modules
var list = req().objects;

// get an object of both settings and objects setting in one go (as you might have guess by now...)
var obj = req();
</pre>
<h2>Minimalistic chainability</h2>
<pre class="brush: jscript; title: ; notranslate">

// change path
req('path','./')

// declare a module
('core', {
    init:function(){

    }
)

// load the declared module just for irony sake
(['core','module'], function(core, mod) {
    core.init();
    mod.load();
});
</pre>
<h2>Get to the code</h2>
<p><a href="https://github.com/gillescochez/req.js">req.js on Github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2012/04/24/req-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>is.js and isFn.js</title>
		<link>http://gillescochez.info/2012/04/24/is-js-and-isfn-js/</link>
		<comments>http://gillescochez.info/2012/04/24/is-js-and-isfn-js/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 16:33:45 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://gillescochez.info/?p=205</guid>
		<description><![CDATA[Just a couple of small scripts I created for fun that deals with type checking in javascript. is.js is a tiny (~200 bytes) strict type checker/engine which offer a little API to test JavaScript types as well as allows the &#8230; <a href="http://gillescochez.info/2012/04/24/is-js-and-isfn-js/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just a couple of small scripts I created for fun that deals with type checking in javascript.</p>
<h2>is.js</h2>
<p>is a tiny (~200 bytes) strict type checker/engine which offer a little API to test JavaScript types as well as allows the creation of custom type checkers.</p>
<p><a href="https://github.com/gillescochez/is.js">is.js on Github</a></p>
<h2>isFn.js</h2>
<p>is a tiny class that allows the creation of custom type checkers.</p>
<p><a href="https://github.com/gillescochez/isFn.js">isFn.js on Github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2012/04/24/is-js-and-isfn-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>domglue &#8211; lightweight data/DOM binding engine</title>
		<link>http://gillescochez.info/2012/01/03/domglue/</link>
		<comments>http://gillescochez.info/2012/01/03/domglue/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 17:47:29 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Plugins & engines]]></category>

		<guid isPermaLink="false">http://gillescochez.info/?p=187</guid>
		<description><![CDATA[Domglue is a tiny data to dom element binding engine. It provides only basic interpolation, the data keys are bind to elements found on the DOM. Everytime a data key value gets updated the DOM element gets automatically updated. Core &#8230; <a href="http://gillescochez.info/2012/01/03/domglue/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Domglue is a tiny data to dom element binding engine. It provides only basic interpolation, the data keys are bind to elements found on the DOM. Everytime a data key value gets updated the DOM element gets automatically updated.</p>
<h2>Core API</h2>
<p>domglue( String selector | HTML Element | Nodelist, object data, object options);</p>
<p>Grab DOM elements, bind data to elements found and return an object containing methods based on the data keys which allows to update the data object.</p>
<p>The options object is optional and can be used to change the settings for the instance created.</p>
<h3>Usage</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;script src=&quot;domglue.js&quot;&gt;&lt;/script&gt;
&lt;body&gt;
&lt;div id=&quot;content&quot;&gt;
    &lt;h1 data-bind=&quot;title&quot;&gt;Title&lt;/h1&gt;
    &lt;p data-bind=&quot;message&quot;&gt;Message&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;loop&quot;&gt;
    &lt;p data-bind=&quot;foo&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;loop&quot;&gt;
    &lt;p data-bind=&quot;foo&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;script&gt;
</pre>
<pre class="brush: jscript; title: ; notranslate">
var data = {
    title: 'Hellow World',
    message: 'I am filled in by domglue'
    },
    dg = domglue('#content', data); 

    // the content element now contains &lt;h1&gt;Hello World&lt;/h1&gt;&lt;p&gt;I am filled in by domglue&lt;/p&gt;

    // this will update the Message in 3 seconds
    setTimeout(function() {
    dg.message('New message is now in place');
    }, 3000);

var dg2 = domglue('div.loop', {foo:'foo'});

setTimeout(function() {
    dg2.foo('Foo');
}, 5000);
</pre>
<pre class="brush: xml; title: ; notranslate">
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h2>Get it</h2>
<p><a href="https://github.com/gillescochez/domglue">domglue on github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2012/01/03/domglue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mucilage &#8211; lightweight data/template binding</title>
		<link>http://gillescochez.info/2011/12/28/mucilage-lightweight-datatemplate-binding/</link>
		<comments>http://gillescochez.info/2011/12/28/mucilage-lightweight-datatemplate-binding/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 17:04:24 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Plugins & engines]]></category>

		<guid isPermaLink="false">http://gillescochez.info/?p=178</guid>
		<description><![CDATA[Information Mucilage is a lightweight data to template binding engine which allows to bind the updating of the template with the data. Mucilage return an object containing methods matching the data keys which can then be used to update the &#8230; <a href="http://gillescochez.info/2011/12/28/mucilage-lightweight-datatemplate-binding/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Information</h2>
<p>Mucilage is a lightweight data to template binding engine which allows to bind the updating of the template with the data. Mucilage return an object containing methods matching the data keys which can then be used to update the data object or retrieve current values.</p>
<p>Due to the nature of the template engine the template is re-compiled everytime the data object changes.</p>
<p>Mucilage also come in a &#8220;light build&#8221; which is based on a strip down version of the template engine so it allows only interpolation and doesn&#8217;t have any configurable settings.</p>
<h2>Usage</h2>
<h3>Basic</h3>
<p>This can be done with the light version as only interpolations.</p>
<pre class="brush: jscript; title: ; notranslate">
var template = '&lt;h1&gt;{{=$.title}}&lt;/h1&gt;&lt;p&gt;{{=$.message}}&lt;/p&gt;',
    data = {
    title: 'Title',
    message: 'Message'
    },
    muc = mucilage(template, data, document.getElementById('content')); 

    // the content element now contains &lt;h1&gt;Title&lt;/h1&gt;&lt;p&gt;Message&lt;/p&gt;

    // this will update the Message in 3 seconds
    setTimeout(function() {
    console.log(muc.message());
    muc.message('New message');
    console.log(muc.message());
    }, 3000);
</pre>
<h3>Advanced usage</h3>
<p>Requires the full version</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;content&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/mucilage-template&quot; id=&quot;templ&quot;&gt;
&lt;h1&gt;Just static text&lt;/h1&gt;
&lt;p&gt;Interpolation {{=$.f1   +    $.f3}} &lt;/p&gt;
&lt;div&gt; JavaScript block evaluation
{{ for(var i=0; i &lt; $.f2; i++) {
    console.log(&quot;Pass\t&quot; + i);
    }}
    &lt;div&gt;{{=$.f3}}&lt;/div&gt;
    {{ } }}
    &lt;/div&gt;
    &lt;div&gt; Encoding {{!'&lt;a   href=&quot;http://github.com&quot;&gt;&lt;/a&gt;'}}&lt;/div&gt;
&lt;/script&gt;
</pre>
<pre class="brush: jscript; title: ; notranslate">
// original data and template
var data = {
    f1: 10,
    f2: 10,
    f3: 10,
    },
    template = document.getElementById('templ').text;

// convert data into a mucilage object
data = mucilage(template, data, document.getElementById('content'));

// update data object and update the template
setTimeout(function(){
    data.f1(5);
}, 3000);
</pre>
<h2>Get it</h2>
<p>Full feature version is around 4KB and the light version is around 1.2KB.</p>
<p>Available from github at <a href="https://github.com/gillescochez/mucilage">https://github.com/gillescochez/mucilage</a> see test for various usage cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2011/12/28/mucilage-lightweight-datatemplate-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>testRemoteJS</title>
		<link>http://gillescochez.info/2011/12/23/testremotejs/</link>
		<comments>http://gillescochez.info/2011/12/23/testremotejs/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 16:39:26 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Plugins & engines]]></category>

		<guid isPermaLink="false">http://gillescochez.info/?p=172</guid>
		<description><![CDATA[testRemoteJS is a simple helper function that works with Qunit and aim to simplify the testing of files loaded via javascript. Usage In your HTML In javascript Get testRemoteJS @ github]]></description>
			<content:encoded><![CDATA[<p><strong>testRemoteJS</strong> is a  simple helper function that works with Qunit and aim to simplify the testing of files loaded via javascript.</p>
<h2>Usage</h2>
<p>In your HTML</p>
<pre class="brush: xml; title: ; notranslate">
&lt;link href=&quot;qunit.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;script src=&quot;qunit.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;testRemoteJS.js&quot;&gt;&lt;/script&gt;
</pre>
<p>In javascript</p>
<pre class="brush: jscript; title: ; notranslate">
testRemoteJS('script.js', function() {
    expect(1);
    ok(foo, 'foo exists');
});
</pre>
<p>Get <a href="https://github.com/gillescochez/testRemoteJS">testRemoteJS @ github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2011/12/23/testremotejs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>_str, a chainable string manipulation library</title>
		<link>http://gillescochez.info/2011/12/16/_str-a-chainable-string-manipulation-library/</link>
		<comments>http://gillescochez.info/2011/12/16/_str-a-chainable-string-manipulation-library/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 15:37:31 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Plugins & engines]]></category>

		<guid isPermaLink="false">http://gillescochez.info/?p=162</guid>
		<description><![CDATA[_str is a chainable library which aims to simplify string manipulation and handling. _str will also keep an history of all the modifications made so it is easy to rollback or access the all history. It is also possible to &#8230; <a href="http://gillescochez.info/2011/12/16/_str-a-chainable-string-manipulation-library/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>_str is a chainable library which aims to simplify string manipulation and handling. </p>
<p>_str will also keep an history of all the modifications made so it is easy to rollback or access the all history. It is also possible to store manipulation state which can later be retrieve individually or as a all (useful if you can have one chain for all your changes but need multiple formatted version of the original strings)</p>
<p>_str was started only few days ago and is not ready for release yet but you can follow it&#8217;s development and/or use it as it is if you wish (a fair amount of tests are done using Qunit already)</p>
<p>Check it out <a href="https://github.com/gillescochez/_str">_str@github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2011/12/16/_str-a-chainable-string-manipulation-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bye bye windows, hello ubuntu</title>
		<link>http://gillescochez.info/2011/12/15/bye-bye-windows-hello-ubuntu/</link>
		<comments>http://gillescochez.info/2011/12/15/bye-bye-windows-hello-ubuntu/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 11:08:32 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://gillescochez.info/?p=155</guid>
		<description><![CDATA[Few weeks ago I wiped out my development laptop and installed ubuntu on it, it&#8217;s quite old and slow but I like it so I wanted to give it a bit more life and after working on Mac over the &#8230; <a href="http://gillescochez.info/2011/12/15/bye-bye-windows-hello-ubuntu/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Few weeks ago I wiped out my development laptop and installed ubuntu on it, it&#8217;s quite old and slow but I like it so I wanted to give it a bit more life and after working on Mac over the last year, and even if I really hate the all Mac experience, I fell in love with the linux kernel underneath so I decided to make the move and feel the love. </p>
<p>Before on windows I could just get rid of the fancy skin, disable services and others to make some spaces and optimize performance but the control you have over the OS is quite small really. </p>
<p>Here with Ubuntu I can finally make my operating system match the minimalism of my development ways. I tried many flavour from the normal ubuntu, kubuntu, lubuntu and LXDE. LXDE seemed to be the closer to what I was looking for at first but it was still providing more than I needed.</p>
<p>So I had to ask myself, what do I really need from an operating system?</p>
<p>1. Run application I need (of course)<br />
2. Take as little resource as possible</p>
<p>And that&#8217;s pretty much it, I don&#8217;t need a taskbar, a clock, icons and all those fancy application and widget, I just need a platform where I can read my email, browse the web and develop.</p>
<p>So in the end I went for a minimalist installation of ubuntu, text based login and openbox as my window manager, which open automatically at login and then launch a terminal, chrome and my email client respectively in desktop 2, 3 and 4. I keep desktop 1 as my workspace.</p>
<p>Memory usage of my idle system is now 50MB (out of 1GB) and it only passes the 200MB barrier if I have a lot of tabs opened in Chrome (also there is lighter browser Chrome has good standard so that&#8217;s my development browser of choice) And the most important thing it&#8217;s really fast for what was originally a single core Celeron processor running Vista out of the box!</p>
<p>I still use Thunderbird as email client, I try Sylpheed which was lighter but I had few issues with it that sent me back to Thunderbird, also I am quite tempted to try terminal based email client. (UPDATE: Actually going for Claws-mail much lighter than Thunderbird)</p>
<p>As for editor after trying many I settle for vim, it&#8217;s light, simple yet elegant and it just feel like the right editor to use for me.</p>
<p>Now I need to set it up in dual boot on my desktop system too, I&#8217;ll always keep a windows version on that one because once in a while I need to do some gaming and nothing beat a PC for that.</p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2011/12/15/bye-bye-windows-hello-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flexible callback design</title>
		<link>http://gillescochez.info/2011/08/15/flexible-callback-design/</link>
		<comments>http://gillescochez.info/2011/08/15/flexible-callback-design/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 20:30:10 +0000</pubDate>
		<dc:creator>Gilles Cochez</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://www.gillescochez.info/?p=83</guid>
		<description><![CDATA[Overview I&#8217;ll go over a method I use which provide a flexible solution for handling callbacks inside a jQuery plugin. It increase the overhead of a lot of method by one function call but the amount of callbacks it can &#8230; <a href="http://gillescochez.info/2011/08/15/flexible-callback-design/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h1>Overview</h1>
<p>I&#8217;ll go over a method I use which provide a flexible solution for handling callbacks inside a jQuery plugin. It increase the overhead of a lot of method by one function call but the amount of callbacks it can handle for the footprint is quite attractive.</p>
<h2>Basic jQuery plugin structure</h2>
<p>A quickly made up plugin structure with options and a couple of methods.</p>
<pre class="brush: jscript; title: ; notranslate">
(function($) {

    var pg = $.fn.myPlugin = function(options) {
        pg.options = $.extend({}, $.fn.myPlugin.defaults, options);
        pg.alertFoo();
        pg.alertThis('Boo');
    };

    $.extend(pg, {
        alertFoo: function() {
            alert('foo');
        },
        alertThis: function(text) {
            alert(txt);
        }
    });

    $.fn.myPlugin.defaults = {
        callbacks: {}
    };

})(jQuery);
</pre>
<h2>The call method</h2>
<p>By creating a call method inside our plugin we create a mean to run any method of the plugin through this method which give us the freedom to look for callbacks based on the method name which can occurs before or after the method is executed.</p>
<p>The following call method can support any number of arguments and also support returning the value if the method called returns any.</p>
<p>It&#8217;s important to note that methods don&#8217;t have to be call that way so if there is some methods that don&#8217;t require callbacks just call them directly to limit the overhead.</p>
<pre class="brush: jscript; title: ; notranslate">
call: function(method) {

    // any before method callback?
    if (pg.options.callbacks[method+'Before']) pg.options.callbacks[method+'Before']();

    // call method
    var res = pg[method].apply(null, Array.prototype.slice.call(arguments, 1));

    // any after method callback?
    if (pg.options.callbacks[method+'After']) pg.options.callbacks[method+'After']();

    // return the result if any
    return res || null;
}
</pre>
<p>Now we can change our method calls to use the call function as such.</p>
<pre class="brush: jscript; title: ; notranslate">
     var pg = $.fn.myPlugin = function(options) {
        pg.options = $.extend({}, $.fn.myPlugin.defaults, options);
        pg.call('alertFoo');
        pg.call('alertThis', 'Boo');
    };
</pre>
<p>We can now bind callbacks before and after those method by passing them into the callback options object like follow.</p>
<pre class="brush: jscript; title: ; notranslate">
$('#myElement').myPlugin({
    callbacks: {
        alertFooBefore: function() {
            alert('I am called BEFORE alertFoo()');
        },
        alertFooAfter: function() {
            alert('I am called AFTER alertFoo()');
        }
    }
});
</pre>
<p>You could also overwrite the default options if the callbacks apply to multiple instances of the plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://gillescochez.info/2011/08/15/flexible-callback-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

