<?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>Position Absolute, resources for the web developer &#187; Articles</title>
	<atom:link href="http://www.position-absolute.com/category/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.position-absolute.com</link>
	<description>Get your web worker news fix</description>
	<lastBuildDate>Mon, 23 Jan 2012 20:53:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using the jQuery Validation Engine with modal &amp; dialog plugins</title>
		<link>http://www.position-absolute.com/articles/using-the-jquery-validation-engine-with-modal-plugins/</link>
		<comments>http://www.position-absolute.com/articles/using-the-jquery-validation-engine-with-modal-plugins/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 20:49:27 +0000</pubDate>
		<dc:creator>Cedric Dugas</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Javascript / jQuery]]></category>
		<category><![CDATA[featured]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3936</guid>
		<description><![CDATA[<p>This is a question I often get asked by email, and I think there is enough requests to warrant a small blog post.</p>
<h2>All about the DOM </h2>
<p>The validationEngine expect your form to be present on the page when you initialize&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>This is a question I often get asked by email, and I think there is enough requests to warrant a small blog post.</p>
<h2>All about the DOM </h2>
<p>The validationEngine expect your form to be present on the page when you initialize the plugin, and this is where modal plugins fall short. If your using those plugins you generally want to load a new piece of html into your document using AJAX.</p>
<p>In that case you need to initialize the validationEngine <strong>after</strong> you loaded your modal content. Generally modal plugins have an api that let you do this. Let&#8217;s take 2 example, Colorbox and jQuey ui.</p>
<p><strong>Colorbox :</strong></p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">bind</span><span class="br0">&#40;</span><span class="st0">&#39;cbox_complete&#39;</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#formID&quot;</span><span class="br0">&#41;</span>.<span class="me1">validationEngine</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><strong>jQuery UI :</strong></p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span> <span class="st0">&quot;.selector&quot;</span> <span class="br0">&#41;</span>.<span class="me1">bind</span><span class="br0">&#40;</span> <span class="st0">&quot;dialogopen&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>event, ui<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;$<span class="br0">&#40;</span><span class="st0">&quot;#formID&quot;</span><span class="br0">&#41;</span>.<span class="me1">validationEngine</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>That should give you a pretty good idea of what you need to do whatever the plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/articles/using-the-jquery-validation-engine-with-modal-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s never been about the open web</title>
		<link>http://www.position-absolute.com/articles/its-never-been-about-the-open-web/</link>
		<comments>http://www.position-absolute.com/articles/its-never-been-about-the-open-web/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 18:47:19 +0000</pubDate>
		<dc:creator>Cedric Dugas</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3832</guid>
		<description><![CDATA[<p><strong>Warning! warning! rant ahead! I wrote this a week or two weeks ago, not being sure if I should publish it, finally decided to go for it.</strong></p>
<p>The open web grinds my gear, there I said it! It seems a lot&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><strong>Warning! warning! rant ahead! I wrote this a week or two weeks ago, not being sure if I should publish it, finally decided to go for it.</strong></p>
<p>The open web grinds my gear, there I said it! It seems a lot of developers wave their flags at every technology that are not open like the open web was the only solution viable. There is some sort of movement about the power of the open web and more specifically HTML5, and these days HTML5 is about pretty much anything that was added to the web stack for 2 years.</p>
<p>Even non developers heard of HTML5. Hell, even the web agency secretary knows the buzz word.</p>
<h2>People supporting the Occupy Flash movement don&#8217;t get it</h2>
<p>It seems the Occupy movement even got into web technologies. Even if &#8220;occupying flash&#8221; doesn&#8217;t make any sense if you want people to uninstall it. If I had to guess, I would say that the people supporting Occupy flash never really delved into that technology and just are kind of pissed that most of the publicity on the web is in flash (which makes a pretty poor audience to go to war with anyway). Because knowing the technology, you would know that Adobe API&#8217;s for creating interactive experiences is specially awesome, and that AS3 is a really beautiful language.</p>
<h3>It&#8217;s so slow</h3>
<p>So why do you want to remove Flash from the web again? Oh yeah, slow, buggy software&#8230; Guess what, there are as much javascript developers than AS3 developers that don&#8217;t care about performance, and the consequences are as much important: crashing and slowing your computer. </p>
<p>So don&#8217;t tell me it slows the web. A more accurate saying would be that videos and animations slow the web. The more we have javascript, animations, canvas, videos, the more your page is going to crash, whatever the technology. If Flash never existed another technology would have slowed down your computer with videos and animations.</p>
<p>Adobe is iterating a zillion times faster than the W3C body. Adding cooler API&#8217;s to Flash every year. Forget it guys it&#8217;s not going away. And this bring us to the next subject.</p>
<h2>Flash cannot be replaced by HTML5 (* not currently, not in the near future)</h2>
<p>Now you could certainly use HTML5 and jQuery to do what Flash does? <strong>Bullshit</strong>. That&#8217;s a statement that I often see. What does jQuery has to do with HTML5 anyway? You are going to query canvas with jQuery?</p>
<p>What you can currently replace, is the same thing that you could replace 3 years ago when jQuery 1.0 came out: basic animations. So why all the fuss? </p>
<p>CSS3 is a <strong>mess</strong> cross browser, it&#8217;s non-existent on IE8 and less, and canvas API&#8217;s are so low level we currently have no idea if you will be able to achieve all the great stuff that you do with Flash with a decent framerate soon.</p>
<h2>No, Occupy Flash is about supporting the open web</h2>
<p>The what web? Who&#8217;s behind the open web? Google, Apple, Sun, etc. The same companies that love proprietary technologies. They love it so much that they could not decide one default video format for HTML5 pushing for their own. They love so much javascript that they created a competitor much like Actionscript, Dart. They love it so much that they put their companies&#8217; needs before the needs of the many.</p>
<p>They also bring us absurd things like &#8220;aside&#8221; , aside what? How does it help semantic if I can&#8217;t understand from the get go what it does. Is that going to be remove? No, that would mean tons of back and forth with tons of people that are moving a ship bigger than the largest boat on earth and consequently can never turn on a dime. Once a direction is taken, going to the other side is slow and costly.</p>
<p>The open web is a great smoke screen if you ask me. It&#8217;s nice that we move forward, it&#8217;s nice that we got new tools (thanks god for border-radius and box-shadow) but it does not mean it&#8217;s the better tool for all situations.</p>
<h2>It&#8217;s about using the technology that make sense for your client or product.</h2>
<p>You want to create an interactive experience, bring emotions, nothing will beat Flash with great designers. You want to create a web application, well there is a ton of opened and closed framework to that end. You must choose technology depending what is better for your team.</p>
<h2>About mobile..</h2>
<p>In fact it seems we are steering more and more away from open technologies. Mobile is all about closed frameworks that are faster than the open web. Try an app with jQuery mobile, then try an native application, which is faster? Maybe we should kill all apps created with Phonegap, or maybe, it&#8217;s all about using the right technology at the right time. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/articles/its-never-been-about-the-open-web/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Another year is ending..</title>
		<link>http://www.position-absolute.com/articles/another-year-ending/</link>
		<comments>http://www.position-absolute.com/articles/another-year-ending/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 18:13:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3863</guid>
		<description><![CDATA[<p><em>Each year I highlight what has been happening in my small dev life and another year is coming to an end, so here we go.</em></p>
<h2>1. Github (and git) changed everything</h2>
<p>At the beginning of the year I moved the jQuery validationEngine&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><em>Each year I highlight what has been happening in my small dev life and another year is coming to an end, so here we go.</em></p>
<h2>1. Github (and git) changed everything</h2>
<p>At the beginning of the year I moved the jQuery validationEngine plugin to github and started to learn git. First thing first, I <strong>love</strong> git. It is so refreshing to use it after 2 years of wanting to kill svn. Thanks to Github I also learned more commands than i knew with svn.</p>
<p>Github also supercharged the validationEngine plugin development. I have got a lot of contributions and can&#8217;t thank you enough guys for submitting pull requests. Special mention to @orefalo that really took the early development of 2.0 in his hand and made the code more professionnal.</p>
<p>I unfortunately have less and less time for developing the plugin, after 3 years of maintaining it, my resteless captivation for form validation have greatly diminish, but don&#8217;t worry, I don&#8217;t plan to stop supporting it.</p>
<h2>The validationEngine plugin still got strong support</h2>
<p>Obviously the official plugin take much of the market. But there is something really satisfying of not having to play around to place the error prompts, and I know for a fact that&#8217;s why so much people are turning to my plugin.</p>
<p>This year approximately 50 000 peoples downloaded the plugin, overall it got downloaded  200 000 times since it was launched. Not bad!</p>
<h2>Did my biggest Javascript project yet</h2>
<p>This year we launched a new email editor at Cakemail, much like the one that campaign monitor and mailchimp got. We do not have the man power that those 2 companies got but I am really proud of what we did. For my part, it&#8217;s 2 months of javascript development + debugging with iframes and IE.</p>
<p><img src="http://ww1.prweb.com/prfiles/2011/11/23/8989813/gI_79077_general%20templates.png"></p>
<p>My last big JS project was for Workopolis. Unfortunately the time constraint was a bitch, I don&#8217;t think I can speak of this project yet, but in 1 year or 2 it will probably go offline and I will, I learned a lot from this.. <img src='http://www.position-absolute.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> . It was a 7 months project nightmare and I will probably be going to hell for the code in there.</p>
<h2>Launching a project part time is more than hard, it&#8217;s near impossible for some people</h2>
<p>I don&#8217;t want to say for people that got a life, because that&#8217;s an idiotic statement and people saying that probably just got no career ambitions (or do not take the steps to achieve those) and would not understand anyway why we do this.</p>
<p>But when you got a house (that needs renovating), a girlfriend, still got 1 or 2 friends, you need to chose between trying to start a company and doing other things. Fortunately I got a very understanding girlfriend and I am really near of launching something, but obviously I had to cut some stuff out.</p>
<p>Kind of funny how 4 years ago I was really not into coding and was just waiting 5 o&#8217;clock to go cardio training. </p>
<h2>Don&#8217;t scale a project before it need to (specially if you are doing it part time)</h2>
<p>I&#8217;m not in Y Combinator, and would probably never be accepted in there, and I also don&#8217;t push 60 hours of code each day. This mean that I need to cut corners somewhere. I cut unit tests, procedures, validation (to some extends), frameworks complexity and more..</p>
<p>In my first personal project I used Symfony 1.4. I wanted a framework that can scale team wise. That was probably the stupidest decision I did. For once Symfony 1.x is dead now, that does not help&#8230;.but, you pay a price when you use code generators, big orms, big caching systems and etc. You don&#8217;t really understand <em>the fuck</em> is going on, and when you hit a framework bug, you just want to throw your computer on the wall, and since you don&#8217;t have much time, it is really slowing you down.</p>
<p>Now I stay near stuff I know best, the front-end stuff. I also use a really small footprint framework on the back-end that does not change often its api, CodeIgniter. I try to get frameworks out of my way as much as possible. </p>
<p>This way I got as much chances as possible to launch something the faster I can.</p>
<h2>People don&#8217;t want to get involved in other people stuff</h2>
<p>This year I started backbonefu.com. I have come to love backbone.js and was feeling that the web was missing helping guides for it. In my <em>ideas of grander</em> I thought this could be a big community website, but I hitted a wall, the same wall I got with this blog in the past. 2 years ago I redesigned this website to become more news oriented and tried to get people involved in it. </p>
<p>Thing is, people don&#8217;t want to be involved in others shit. They want to do their own shit (which is understandable). And so I am still the sole author on backbonefu <img src='http://www.position-absolute.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> . Still, I like the site and will continue to post about my trials and errors with the framework.</p>
<h2>The conclusion</h2>
<p>After more than 5 years as a professional, I am still a front-end developer. I do not lead a team and I am really not sure if I would be good at that. I still have fun at what I do but wonders what will happen to me and my &#8220;career&#8221; in 10-15 years (like every year <img src='http://www.position-absolute.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/articles/another-year-ending/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working with jQuery load() function on images in Internet Explorer 8 and below</title>
		<link>http://www.position-absolute.com/articles/working-with-jquery-load-function-in-internet-explorer-8-and-below/</link>
		<comments>http://www.position-absolute.com/articles/working-with-jquery-load-function-in-internet-explorer-8-and-below/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 20:11:39 +0000</pubDate>
		<dc:creator>Cedric Dugas</dc:creator>
				<category><![CDATA[Article small archives]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Javascript / jQuery]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3819</guid>
		<description><![CDATA[<p>One big problem with using load() on images is that it just does not work at all on ie. Now there is a lot of solutions proposed to counter this problem, however most of them are irritating.</p>
<h2>Why IE handle load()&#8230;</h2>]]></description>
			<content:encoded><![CDATA[<p>One big problem with using load() on images is that it just does not work at all on ie. Now there is a lot of solutions proposed to counter this problem, however most of them are irritating.</p>
<h2>Why IE handle load() this way</h2>
<p>Simple, IE already cached your image, so it does not need to load it back The 2 most know solution to this are one, adding a random string at the end of the image url, like this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">myImge = $<span class="br0">&#40;</span><span class="st0">&quot;&lt;img /&gt;&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;src&quot;</span>,anyDynamicSource+ <span class="st0">&quot;?&quot;</span> + <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getTime</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>The other solution is to check the height property since if it&#8217;s not zero, the image is already loaded:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span><span class="st0">&#39;img&#39;</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">height</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;our callback</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;$<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">load</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;our callback</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Well these 2 solutions work, but they are not really nice. In fact this problem can be solved a lot easier.</p>
<h2>Use load() first</h2>
<p>Yup. That&#8217;s it, when you create your image in javascript, before doing anything else use your load function and IE will behave like all the other browsers.</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span><span class="st0">&quot;&lt;img&gt;&quot;</span><span class="br0">&#41;</span>.<span class="me1">load</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="co1">// do stuff</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&quot;id&quot;</span>:<span class="st0">&quot;imgInsert&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&quot;src&quot;</span>:response.<span class="me1">url</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&quot;alt&quot;</span>:response.<span class="me1">alt</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/articles/working-with-jquery-load-function-in-internet-explorer-8-and-below/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Text editors again</title>
		<link>http://www.position-absolute.com/news/text-editors-again/</link>
		<comments>http://www.position-absolute.com/news/text-editors-again/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 03:41:27 +0000</pubDate>
		<dc:creator>Cedric Dugas</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Opinions]]></category>
		<category><![CDATA[Random news]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3798</guid>
		<description><![CDATA[<p>I found my new house, really. I have been using e-text-editor on windows and Textmate on OSX for nearly 3 years and never really saw any contender to them. I tried aptana 3, too slow, no textmate bundle, buggy jquery&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>I found my new house, really. I have been using e-text-editor on windows and Textmate on OSX for nearly 3 years and never really saw any contender to them. I tried aptana 3, too slow, no textmate bundle, buggy jquery snippets, in the end I still went back. My 2 favorites both support tm bundles, there fast, E had split view and some nice features like command lines via cygwin.. But where is my textmate 2? Nobody knows, I heard the author went to work on the Espresso editor, it did not impress me, but fortunately now Sublime 2 is here to take the place of Textmate 2.</p>
<h2>Sublime text 2, the new holy grail of editing</h2>
<p>Okay, I know VIM is powerful (hello sys admins <img src='http://www.position-absolute.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) and Emacs got a weird following but here we got a game changer. It got the snippets power of textmate (all tm bundle works, mostly), the extensibility of VIM and the split view of E, all in a nice package, available on Windows, OSX and Linus. Meaning you will never have to fear coding on any platform.<em> A part maybe from your web server.</em></p>
<p>Obviously I am excited, I moved my tm bundles and started playing around with it but it is too soon to tell if the relation will last. If you want some tips and tricks on using Sublime 2 I recommend having a look at <a href="http://net.tutsplus.com/tutorials/tools-and-tips/sublime-text-2-tips-and-tricks/">this article on nettuts</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/news/text-editors-again/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Organizing events with jQuery</title>
		<link>http://www.position-absolute.com/articles/organizing-events-with-jquery/</link>
		<comments>http://www.position-absolute.com/articles/organizing-events-with-jquery/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 12:07:47 +0000</pubDate>
		<dc:creator>Cedric Dugas</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Javascript / jQuery]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3773</guid>
		<description><![CDATA[<p><br />
Following the launch of <a href="http://www.backbonefu.com">BackboneFU</a> I wanted to take the time to talk about my current setup when I am not using an MVC framework on the front-end. This will be also part of my presentation at Confoo 2011 (if I&#8217;m&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><!-- {EAV_BLOG_VER:d174f150c64c385e} --><br />
Following the launch of <a href="http://www.backbonefu.com">BackboneFU</a> I wanted to take the time to talk about my current setup when I am not using an MVC framework on the front-end. This will be also part of my presentation at Confoo 2011 (if I&#8217;m chosen).</p>
<p>The problem with handling events with jQuery is probably that jQuery itself makes it really easy to make spaghetti code, so only reading the jQuery documentation you are bound to hit a wall at some point. I&#8217;m always amazed at junior javascript developers&#8217; code and how they always mess things up if they use jQuery.</p>
<h2>Prob #1 Anonymous functions</h2>
<p>When you look at the jQuery documentation for events, you would see something like this explaining bind:</p>
<div class="geshi no javascript">
<div class="head">$(&#8220;#myButton&#8221;).bind(&#8220;click&#8221;, function(){</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;$<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">&quot;selected&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>It&#8217;s not because you can use anonymous function to do everything that you should, use simple objects for that.</p>
<div class="geshi no javascript">
<div class="head">var myapp.dashboard = {</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;loadEvents: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> _this = <span class="kw1">this</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#myButton&quot;</span><span class="br0">&#41;</span>.<span class="me1">bind</span><span class="br0">&#40;</span><span class="st0">&quot;click&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> &nbsp;_this.<span class="me1">selectedOption</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;#myButton2&quot;</span><span class="br0">&#41;</span>.<span class="me1">bind</span><span class="br0">&#40;</span><span class="st0">&quot;click&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> _this.<span class="me1">doSomething</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;selectedOption : <span class="kw2">function</span><span class="br0">&#40;</span>el<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; $<span class="br0">&#40;</span>el<span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">&quot;selected&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;doSomething : <span class="kw2">function</span><span class="br0">&#40;</span>el<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h3>What is the deal with &#8220;this&#8221;</h3>
<p>jQuery always assigns the <em>this</em> value on the DOM element when you bind events, pretty useful, but not really good if we use objects and want to call other methods, that is why I pass the <em>this</em> value as a parameter in loadEvents().</p>
<p>Also since the anonymous function changes our scope we need to save the <em>this</em> value doing var _this = this; at the beginning of the method to use it later.</p>
<p>Using an object you will give you a much better code organization, as a bonus you see every events binded in the js file easily.</p>
<h2>Give a context</h2>
<p>If you are the kind that dump every js files at the beginning of each page, giving a context to your events can be a very good idea.</p>
<p>Personally I really like to use a parent element for that, for example, I know that everything that happens on the dashboard has a parent with the css class <em>dashboard</em>. So I would do something like this:</p>
<div class="geshi no javascript">
<div class="head">var myapp.dashboard = {</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;loadEvents: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//Check if we are in the right section</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> $dashboard = $<span class="br0">&#40;</span><span class="st0">&quot;.dashboard&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span>$dashboard<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Save the this value for later</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> _this = <span class="kw1">this</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Delegate give a context to our events</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; $dashboard.<span class="me1">delegate</span><span class="br0">&#40;</span><span class="st0">&quot;#myButton&quot;</span>,<span class="st0">&quot;click&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> &nbsp;_this.<span class="me1">selectedOption</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; $dashboard.<span class="me1">delegate</span><span class="br0">&#40;</span><span class="st0">&quot;#myButton2&quot;</span>,<span class="st0">&quot;click&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> _this.<span class="me1">doSomething</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;selectedOption : <span class="kw2">function</span><span class="br0">&#40;</span>el<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; $<span class="br0">&#40;</span>el<span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">&quot;selected&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;doSomething : <span class="kw2">function</span><span class="br0">&#40;</span>el<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span> myapp.<span class="me1">dashboard</span>.<span class="me1">loadEvents</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>On this line: <em>if(!$(&#8220;.dashboard&#8221;)[0]) return false;</em> we check if the dashboard element exist, and if it does not, we do not load the events, It can save you a lot of overhead at practically no cost. Then we use delegate instead of bind, so if we want to convert this app to an ajaxy app, events would be automatically destroyed if we removed the dashboard element.</p>
<h2>That&#8217;s it!</h2>
<p>I just wanted to share my current code organization, hope it can give you ideas for your organization too!</p>
<h2>Update</h2>
<p>Following some commenters ideas, there is a couple of things we could do to improve this.</p>
<p>First, we can use <em>!$dashboard.length </em>instead of <em>!$dashboard[0],</em> little bit clearer.</p>
<p>Lets chain the delegate! Since we always use the same parent this is something we can do. Also, wrapping into an anonymous function is not the best idea in the world, 2 things have been proposed here.</p>
<p>We could use jQuery proxy like this <em>$.proxy(this.selectedOption, this),</em> or we could do something like <em>$dashboard.delegate(“#myButton”,”click”, { dashboard: this }, this.selectedOption);</em>.</p>
<p>So lets check our new formula:</p>
<div class="geshi no javascript">
<div class="head">var myapp.dashboard = {</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;loadEvents: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//Check if we are in the right section</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> $dashboard = $<span class="br0">&#40;</span><span class="st0">&quot;.dashboard&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span>$dashboard.<span class="me1">length</span><span class="br0">&#41;</span> <span class="kw1">return</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Save the this value for later</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> _this = <span class="kw1">this</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Delegate give a context to our events</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; $dashboard</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;.<span class="me1">delegate</span><span class="br0">&#40;</span><span class="st0">&quot;#myButton&quot;</span>,<span class="st0">&quot;click&quot;</span>, &nbsp;$.<span class="me1">proxy</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">selectedOption</span>, <span class="kw1">this</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;.<span class="me1">delegate</span><span class="br0">&#40;</span><span class="st0">&quot;#myButton2&quot;</span>,<span class="st0">&quot;click&quot;</span>, &nbsp;$.<span class="me1">proxy</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">doSomething</span>, <span class="kw1">this</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;selectedOption : <span class="kw2">function</span><span class="br0">&#40;</span>el<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; $<span class="br0">&#40;</span>el<span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">&quot;selected&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;doSomething : <span class="kw2">function</span><span class="br0">&#40;</span>el<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span> myapp.<span class="me1">dashboard</span>.<span class="me1">loadEvents</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/articles/organizing-events-with-jquery/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Two headaches explained when you&#8217;re getting started with backbone.js</title>
		<link>http://www.position-absolute.com/articles/two-headaches-explained-when-youre-getting-started-with-backbone-js/</link>
		<comments>http://www.position-absolute.com/articles/two-headaches-explained-when-youre-getting-started-with-backbone-js/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 02:26:10 +0000</pubDate>
		<dc:creator>Cedric Dugas</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Javascript / jQuery]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3739</guid>
		<description><![CDATA[<p>Recently I decided to dive into backbone.js. I tried to write a small project with it but I found it was hard to get into and abandoned. After seeing a presentation of it at<a href="http://www.js-montreal.org"> JS-Montreal</a>, I finally decided to give it&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Recently I decided to dive into backbone.js. I tried to write a small project with it but I found it was hard to get into and abandoned. After seeing a presentation of it at<a href="http://www.js-montreal.org"> JS-Montreal</a>, I finally decided to give it another try and started porting a project I was working on to it.</p>
<p>Personally I find that <a href="http://documentcloud.github.com/backbone/">backbone.js</a> is a weird beast. It&#8217;s called an MVC framework, but there is no controller, the events system is completely different from your default PHP/Ruby MVC style and there is a notion of collections. Basically Backbone is a MRVT(Model Route Views Template), scratch that, it&#8217;s in fact a MCRVT(Model Collection Route View Template)</p>
<p>So if you are a front-end developer with some MVC knowledge because you are sometimes dealing with a back-end framework you will probably be completely lost. Then you start reading the doc, it seems good and gets you 80% there, but trying to start only with the doc will probably end in pain. Then you go to the todo app example, you understand a little bit more the concepts but there is still lot of WTF.</p>
<p>Then, you <a href="http://backbonetutorials.com/">search</a> for <a href="http://thomasdavis.github.com/tutorial/backbone-introduction.html">tutorials</a>, the <a href="http://net.tutsplus.com/tutorials/javascript-ajax/getting-started-with-backbone-js/">nettuts</a> tutorial is particularly good. But personally I had problems with what is not really explained in those tutorials, I guess you could call that &#8220;edges cases&#8221;. Only the videos at <a href="http://peepcode.com/products/backbone-js">peepscode</a> (Did not want to do promotion, but credits where it is due) where successful at really showing me all the power of backbone and really helped me understand all the underlying concepts that come with that.</p>
<p>So anyway, what was the 2 problems I have been struggling with? Well for one when I was binding a collection to a method within my view, I would lose the <strong>this</strong> reference to my view in that method, and also, my events would not bind to my views and would just never fire.</p>
<h2>Events Binding In The Views</h2>
<p>In backbone, the views control all the events that are happening &#8220;in this part of html code&#8221; (in other words, your associated template). Which is really good for decoupling your code, and makes for a very good code structure. Events are handled automatically with jQuery delegates, thing is, the dom element that delegates all the events need to be outside the view, something I did not understand at first. It makes also no sense to me that I can&#8217;t delegate my events from within my view, what happen if the view is a popup? I don&#8217;t want to delegate to the document.</p>
<p>Fortunately something  you can do after your view content is rendered is changing the <em>this.el</em> element to the view container and call <em>this.delegateEvents(this.events)</em> . That took care of the event binding problem.</p>
<p><strong>Update from Josh comment:</strong><br />
If you assign ‘el’ directly to the view and remove it from render, the dom element that delegates all the events will be part of your view. Based on your example, do:</p>
<p>wedapp.view.TasksForm = Backbone.View.extend({<br />
el: $(“.dialogForm”),<br />
…You can then remove this.delegateEvents from render as well.</p>
<p>Example:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">wedapp.view.TasksForm = Backbone.View.extend({
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;events: {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &quot;click #completedbtn&quot; : &nbsp;&quot;complete&quot;,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &quot;click #updatebtn&quot; : &nbsp; &quot;update&quot;,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &quot;click #savebtn&quot; : &nbsp; &nbsp;&quot;save&quot;,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &quot;click #closebtn&quot; : &nbsp; &quot;close&quot;,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;},
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;render: function() {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; var data = (this.model.has(&quot;name&quot;) ) ? this.model.toJSON() : this.model.default;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; var formString = this.template(data);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; $(formString).dialog({
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;autoOpen: true,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;height: 460,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;width: 350,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;title:&quot;Tasks&quot;,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;modal: true
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; })
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; this.el = $(&quot;.dialogForm&quot;);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; this.delegateEvents(this.events)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; return this;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;},
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;initialize : function(){
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; _.bindAll(this,&quot;render&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; this.template = _.template($(&quot;#task_form_tpl&quot;).html());
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; this.render().el;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;},
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;complete: function(){
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; console.log(&quot;crap&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;},
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;update: function(){
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;},
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;save: function(){
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;},
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;close: function(){
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;},
</div>
</li>
<li class="li1">
<div class="de1">});</div>
</li>
</ol>
</div>
<h2>Weird Custom Events Behaviors</h2>
<p>Backbone has a custom events system baked-in which makes it really simple to handle model states. This is really powerful since when you update a row in your database, for example, the html for that row would be automatically rendered back when you change the data. No DOM data tags non-sense.</p>
<p>Problems is, doing <em>this.collection(&#8216;reset&#8217;, handleCollection)</em> changes the <strong>this</strong> handle to the collection! I was wondering why in <em>handleCollection()</em> I could not call any other method from my current view. Of course I logged <strong>this</strong> to see what was happening, but since backbone is very particular of what it returns I did not see that handleCollection was returning the collection instead of the view object.</p>
<p>What you need to do for retaking control of <strong>this</strong>, is to bind it to the view in the initialize method like this: <em>_.bindAll(this,&#8221;handleCollection&#8221;)</em> . Personally I don&#8217;t think it makes sense to handle it that way and it pains me to add this code, but here is no other way that I know of.</p>
<p><strong>Update from Josh comment:</strong><br />
If you want to bind your collection to a callback event, do: this.collection.bind(‘reset’, this.handleCollection, this)</p>
<p>If you pass “this” as the third parameter, you won’t need to do your _.bindAll() in initialize for that method. I’m assuming here that handleCollection is a method in the view.</p>
<h2>Hope it helps!</h2>
<p>I am a bit disappointed that backbone.js is so hard to get started with. It introduces a lot of concept to front-end developers and do not have enough tools to guide you around. </p>
<p>I think tutorial videos through each sections would really help a lot the beginners understanding all the underlying concepts of backbone, I even thought about doing some myself but I&#8217;m too much inexperience with it to do that. In fact I think that a getting started guide like rails for zombies would be perfect, but hey, I know it is a lot of work <img src='http://www.position-absolute.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/articles/two-headaches-explained-when-youre-getting-started-with-backbone-js/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Do you use script loaders?</title>
		<link>http://www.position-absolute.com/articles/do-you-use-script-loaders/</link>
		<comments>http://www.position-absolute.com/articles/do-you-use-script-loaders/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 16:21:05 +0000</pubDate>
		<dc:creator>Cedric Dugas</dc:creator>
				<category><![CDATA[Article small archives]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Javascript / jQuery]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3711</guid>
		<description><![CDATA[<p>It&#8217;s funny I have the impression that script loaders keep coming back in the news, if we go back one year and a half ago  we mostly only had <a href="http://labjs.com">labJS</a> and <a href="http://requirejs.com">requireJS</a>, these guys want to load all your scripts asynch,&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s funny I have the impression that script loaders keep coming back in the news, if we go back one year and a half ago  we mostly only had <a href="http://labjs.com">labJS</a> and <a href="http://requirejs.com">requireJS</a>, these guys want to load all your scripts asynch, but now we got new kids, notably <a href="http://yepnopejs.com/">yepnope</a>, that allows you to load scripts based on feature detection and others.. <a href="http://headjs.com/">headJS</a>, <a href="http://stevesouders.com/controljs/">controlJS</a>, <a href="http://filamentgroup.com/lab/introducing_enhancejs_smarter_safer_apply_progressive_enhancement/">enhanceJS</a>, <a href="https://github.com/BorisMoore/jsdefer">jsDefer</a> ouch&#8230; </p>
<p>Script loaders are responding to a weird problem, you would think that browsers do a good job at loading script since its been doing just that for more than 10 years, but in fact not really, it could be a lot better and this is where those technologies come in.</p>
<p>What they do is super charge the loading speed of your scripts by using various tricks, and when I say tricks, sometimes it really means hacks, specially in older browsers like ie6. In my <a href="http://www.position-absolute.com/articles/optimizing-javascriptjquery-loading-time-a-beginners-guide/">article about script loaders 1 year ago</a> I gave them praised, and I definitely meant it, but currently I unfortunately just stopped using loaders.</p>
<h2>What went wrong?</h2>
<p>When I first tested labJS I was flabbergasted, it was loading my scripts 3 times faster on a average website. I was looking at optimizing the front-end speed of our framework at my last job (w.illi.am/ a web consulting/agency), and this was a strong contender at being implemented. And we did just that, we implemented labJS at the core of our CMS. It definitely took some fine tuning and we had some weird bugs at first with execution order and dom ready statements, but within a week or 2 everything was back to normal.</p>
<p>Then a new project came with an IE phase testing, to our horror IE8 was giving us wrong error lines, it did not understand what labJS was doing and could not find any script file loaded by labjs. Still we continued to use it. Then Firefox4 came along, our older labjs version was not compatible with it, this was a big problem for us, since w.illi.am/ does something like 50 websites a year, not centralized. We just could not afford to update labJS for each project. This was the end of script loading for us, we had to revert back to our old way, we could not take the chance that older version would not be compatible with future browsers.<br />
<em><br />
** I also heard that some of them had problems with newer webkit releases, prompting another library update.</em></p>
<h2>Is it really worth it to use a script loader?</h2>
<p>Personally my response would be no, you introduce in your stack a <strong>very big point of failure</strong>, if this script fails, your entire app fails, furthermore you *generally* need to follow convention dictated by the library. RequireJS works best if you follow their module convention, and labJS has an api to make it easier to keep the execution order, but it really changes the way you would normally work. </p>
<p>I&#8217;m no more at w.illi.am/, but at Cakemail we are currently minifying everything we can into one big js file, like what javascriptMVC does, and loading it normally. It seems to me as the best approach, *some* scripts minifier have been stable for ages, so I know that my production application will not break because of it (it can happen of course, but it is really rare), and in development we just keep the gazillions of script tags for debugging. </p>
<p>That being said, I still think script loaders are a brilliant technology, and I have a lot of respect for their authors. I mean, if your looking for optimizing your page loading time to the maximum, script loaders are a no brainer, its probably your single best optimization beside doing the <a href="http://developer.yahoo.com/performance/rules.html">normal stuff</a>, but it&#8217;s not a task to be taken lightly and you must be aware that there will be maintenance and setup cost.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/articles/do-you-use-script-loaders/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating a CSS3D hovering state with fallback for older browsers</title>
		<link>http://www.position-absolute.com/articles/creating-a-css3d-hovering-state-with-fallback-for-older-browsers/</link>
		<comments>http://www.position-absolute.com/articles/creating-a-css3d-hovering-state-with-fallback-for-older-browsers/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 01:42:49 +0000</pubDate>
		<dc:creator>Cedric Dugas</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CSS / HTML]]></category>
		<category><![CDATA[Small Projects & plugins]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3673</guid>
		<description><![CDATA[<p>HTML5 &#038; CSS3 are a big sugar rush in the front-end community currently, you can see those nice CSS3 buttons popping everywhere around the web. For one project I am working on I  wanted to use a nice 3d flip&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>HTML5 &#038; CSS3 are a big sugar rush in the front-end community currently, you can see those nice CSS3 buttons popping everywhere around the web. For one project I am working on I  wanted to use a nice 3d flip effect like <a href="http://desandro.github.com/3dtransforms/examples/card-01.html">this one</a>. </p>
<p>Unfortunately that kind of effect is currently only achievable with Safari and Chrome, so to make this thing work I needed a normal hover behavior for other browsers, and that is what I wanted to show you how to do here.</p>
<style>
.containerCard {
	height:194px;
	position:relative;
	background:#fff;
	width:144px;
}
	.containerCard .element{
		height:194px;
		position:absolute;
		top:0; left:0;
		background:#fff;
		width:144px;
	} .containerCard .elementB{
		display:none;
	} .containerCard:hover .elementA {
			display:none;
		} .containerCard:hover .elementB{
			display:block;
		} @media screen and (-webkit-min-device-pixel-ratio:0) {
.containerCard .elementB{
				-webkit-transform: rotateY(-180deg);
				-webkit-transform-style: preserve-3d;
				-webkit-backface-visibility: hidden;</p>
<p>				/* -- transition is the magic sauce for animation -- */
				transition: all .4s ease-in-out;
				-moz-transition: all .4s ease-in-out;
				-webkit-transition: all .4s ease-in-out;
			}	
.containerCard .elementA{
				-webkit-transform: rotateY(0deg);
				-webkit-transform-style: preserve-3d;
				-webkit-backface-visibility: hidden;
				/* -- transition is the magic sauce for animation -- */
				transition: all .4s ease-in-out;
				-moz-transition: all .4s ease-in-out;
				-webkit-transition: all .4s ease-in-out;
			}
.containerCard:hover .elementA{
					-webkit-transform: rotateY(180deg);
				}
.containerCard:hover .elementB{
					-webkit-transform: rotateY(0deg);
				}
.containerCard{
					-webkit-perspective: 600;
				}
.containerCard:hover .elementA{
					display:block;
				}
.containerCard .elementB{display:block;}		
		}		
</style>
<div class="containerCard">
<div class="elementA element"><img src="/back.jpg" width="144" height="194" alt="Back"></div>
<div class="elementB element"><img src="/king.jpg" width="144" height="194" alt="Back"></div>
</div>
<h2>Setup</h2>
<p>I&#8217;m not going to be talking about how to do the flip effect, there is already <a href="http://desandro.github.com/3dtransforms/">several</a> <a href="http://24ways.org/2010/intro-to-css-3d-transforms">posts</a> about <a href="http://css3wizardry.com/2010/07/13/css3-page-flips/">that</a>. What I will show you is how to use it intelligently and make it fallback. </p>
<p>So, why this effect is not working on Firefox you might ask? Firefox had css3d since version 3.5 after all, well webkit implemented a new property, *currently a w3c draft* called <a href="http://www.w3.org/TR/css3-3d-transforms/">backface-visibility</a>. This nifty property allow you to hide the back face of an element. I guess you can imagine and this can come handy in a flip effect. This is something that IE9 and Firefox does not currently support.</p>
<h2>Creating a version compatible with other browsers</h2>
<p>For achieving this, we will need to use 2 absolute positioned elements, and show and hide them with display:none on the hover state, pretty easy in fact. The tricky part is that we also need to override this behavior on webkit based browsers(and maybe other browsers one day). For this, we will need to use a nice css feature called media queries.</p>
<h2>Media queries </h2>
<p>Yup, you can do conditionals statement in CSS. This is really handy if you want to implement edgy stuff on browser that supports it, and still give a nice level of support for older browsers (it&#8217;s, of course, useful for <a href="http://www.w3.org/TR/css3-mediaqueries/">other very important things</a>). For our little project we will use this media query.</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">@media screen and (-webkit-min-device-pixel-ratio:0) { }</div>
</li>
</ol>
</div>
<p>So why use <em>-webkit-min-device-pixel-ratio</em>? Well because this property has been added at the same time that backface-visibility. So yes, this is a <strong>hack</strong>! But it works, I would like to have something cleaner but this will do for now, we will also need use something similar when firefox will implement backface-visibility.</p>
<p>So what our CSS code looks like?</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">.containerCard {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;height:194px;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;position:relative;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;background:#fff;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;width:144px;
</div>
</li>
<li class="li1">
<div class="de1">}
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;.containerCard .element{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; height:194px;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; position:absolute;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; top:0; left:0;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; background:#fff;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; width:144px;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;}
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;.containerCard .elementB{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; display:none;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;}
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; .containerCard:hover .elementA {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;display:none;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; .containerCard:hover .elementB{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;display:block;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; @media screen and (-webkit-min-device-pixel-ratio:0) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;.containerCard .elementB{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -webkit-transform: rotateY(-180deg);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -webkit-transform-style: preserve-3d;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -webkit-backface-visibility: hidden;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; /* &#8212; transition is the magic sauce for animation &#8212; */
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; transition: all .4s ease-in-out;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -moz-transition: all .4s ease-in-out;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -webkit-transition: all .4s ease-in-out;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;}
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;.containerCard .elementA{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -webkit-transform: rotateY(0deg);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -webkit-transform-style: preserve-3d;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -webkit-backface-visibility: hidden;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; /* &#8212; transition is the magic sauce for animation &#8212; */
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; transition: all .4s ease-in-out;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -moz-transition: all .4s ease-in-out;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; -webkit-transition: all .4s ease-in-out;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;}
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; .containerCard:hover .elementA{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;-webkit-transform: rotateY(180deg);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; .containerCard:hover .elementB{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;-webkit-transform: rotateY(0deg);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; .containerCard{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;-webkit-perspective: 600;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; .containerCard:hover .elementA{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;display:block;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; .containerCard .elementB{display:block;} &nbsp;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; }</div>
</li>
</ol>
</div>
<h2>Download</h2>
<p>There we have it! As usual the code can be found on github.</p>
<p class="clearfix"><a class="download" href="https://github.com/posabsolute/css3d-hover-effect-with-fallback">Download the source code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/articles/creating-a-css3d-hovering-state-with-fallback-for-older-browsers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Handling javascript errors on production websites</title>
		<link>http://www.position-absolute.com/articles/handling-javascript-errors-on-production-websites/</link>
		<comments>http://www.position-absolute.com/articles/handling-javascript-errors-on-production-websites/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 21:41:51 +0000</pubDate>
		<dc:creator>Cedric Dugas</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Javascript / jQuery]]></category>
		<category><![CDATA[Small Projects & plugins]]></category>

		<guid isPermaLink="false">http://www.position-absolute.com/?p=3636</guid>
		<description><![CDATA[<p>Handling javascript errors as always been sort of a problem for me. Testing every combination possible in a big application is hard, and there is always a chance you will miss something.</p>
<p>Of course, we should always strive to make an&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Handling javascript errors as always been sort of a problem for me. Testing every combination possible in a big application is hard, and there is always a chance you will miss something.</p>
<p>Of course, we should always strive to make an application as bug free as possible, but users seems to always find a way to break it. You can always expect them to do something you never have think of, and this is one of the reason I created this plugin.</p>
<p>When a javascript error is detected, this plugin will do an ajax request to your server and then sends an email, of course you could also log it in a database. It&#8217;s certainly not a revolutionary idea, but still, I was finding the idea cool enough to add it to my list of online plugin.</p>
<p>It&#8217;s also very useful for debugging big live applications that you have not written. In which case you want to know if some users hit javascript errors already.</p>
<p class="clearfix"><a class="download" href="https://github.com/posabsolute/jQuery-Error-Handler-Plugin">Download the source code</a></p>
<h2>Integration</h2>
<p>Load the plugin just after the jQuery library</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; $(document).jsErrorHandler();</div>
</li>
</ol>
</div>
<p>Your done.</p>
<h2>Options</h2>
<p>By default the plugin automatically fetch the domain and add it to the email subject, but you can overwrite it.<br />
You can also define a from attribute, I would highly recommend that you change the from setting in the plugin file (jquery.onerror.js)  if your going to use this plugin on multiple websites.</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;$(document).jsErrorHandler({
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; from: &quot;support@youremail.com&quot;,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; website: document.domain
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;});</div>
</li>
</ol>
</div>
<h2>The Email</h2>
<p>The email received will look like this:</p>
<p>A javascript error has been detected on www.position-absolute.com</p>
<p>Error: variable is not defined<br />
Url: http://www.position-absolute.com/creation/onerror/<br />
Line: 21<br />
UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0</p>
<h2>Limitation</h2>
<p>The plugin works on:<br />
Firefox 3.6+<br />
Chrome Latest<br />
IE 7+</p>
<p>It does not work on Safari (but it will not break your application)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.position-absolute.com/articles/handling-javascript-errors-on-production-websites/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.264 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-03 23:58:54 -->
<!-- Compression = gzip -->
