<?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>@verekia&#039;s blog</title>
	<atom:link href="http://verekia.com/feed" rel="self" type="application/rss+xml" />
	<link>http://verekia.com</link>
	<description>HTML5, CSS3 and JavaScript tutorials</description>
	<lastBuildDate>Fri, 02 Nov 2012 06:50:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Getting Things Done: TODO Zero</title>
		<link>http://verekia.com/slides/todo-zero?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=todo-zero</link>
		<comments>http://verekia.com/slides/todo-zero#comments</comments>
		<pubDate>Sun, 19 Aug 2012 23:48:07 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Slides]]></category>
		<category><![CDATA[App]]></category>
		<category><![CDATA[Archives]]></category>
		<category><![CDATA[Calendar]]></category>
		<category><![CDATA[Creativity]]></category>
		<category><![CDATA[David Allen]]></category>
		<category><![CDATA[Dropbox]]></category>
		<category><![CDATA[Emails]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[Google Calendar]]></category>
		<category><![CDATA[Google Drive]]></category>
		<category><![CDATA[Google Tasks]]></category>
		<category><![CDATA[GTD]]></category>
		<category><![CDATA[Inbox Zero]]></category>
		<category><![CDATA[Lists]]></category>
		<category><![CDATA[Newsletters]]></category>
		<category><![CDATA[Ordering]]></category>
		<category><![CDATA[Postponing]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Remember The Milk]]></category>
		<category><![CDATA[Reminders]]></category>
		<category><![CDATA[Smartphone]]></category>
		<category><![CDATA[SMS]]></category>
		<category><![CDATA[Stress]]></category>
		<category><![CDATA[Task management]]></category>
		<category><![CDATA[TODO list]]></category>
		<category><![CDATA[TODO Zero]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[Yahoo Calendar]]></category>

		<guid isPermaLink="false">http://verekia.com/?p=253</guid>
		<description><![CDATA[Not a geeky topic this time! On August 17th I gave a talk about productivity at Yelp. Here are the slides:]]></description>
				<content:encoded><![CDATA[<p>Not a geeky topic this time! On August 17th I gave a talk about productivity at Yelp.<br />
Here are the slides:</p>
<p><iframe src="https://docs.google.com/presentation/embed?id=1W5HUPYCATwAS3_74TsG3vn8UiCH91GXHoc6W-RHuaGg&#038;start=false&#038;loop=false&#038;delayms=3000" frameborder="0" width="584" height="467" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://verekia.com/slides/todo-zero/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Deep dive into CSS Preprocessors</title>
		<link>http://verekia.com/slides/css-preprocessors?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=css-preprocessors</link>
		<comments>http://verekia.com/slides/css-preprocessors#comments</comments>
		<pubDate>Wed, 30 May 2012 05:45:57 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Slides]]></category>
		<category><![CDATA[@extend]]></category>
		<category><![CDATA[@include]]></category>
		<category><![CDATA[Alexis Sellier]]></category>
		<category><![CDATA[Andy Clarke]]></category>
		<category><![CDATA[Backend]]></category>
		<category><![CDATA[Chris Eppstein]]></category>
		<category><![CDATA[Client-side]]></category>
		<category><![CDATA[Codekit]]></category>
		<category><![CDATA[colors]]></category>
		<category><![CDATA[Colors functions]]></category>
		<category><![CDATA[Colors operations]]></category>
		<category><![CDATA[Compass]]></category>
		<category><![CDATA[constants]]></category>
		<category><![CDATA[CSS Preprocessors]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[DRY]]></category>
		<category><![CDATA[Express]]></category>
		<category><![CDATA[Front-end]]></category>
		<category><![CDATA[gem install]]></category>
		<category><![CDATA[Haml]]></category>
		<category><![CDATA[Hampton Catlin]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Jade]]></category>
		<category><![CDATA[Less]]></category>
		<category><![CDATA[Less.js]]></category>
		<category><![CDATA[lighten]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[LiveReload]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Media Queries]]></category>
		<category><![CDATA[Minification]]></category>
		<category><![CDATA[Mixins]]></category>
		<category><![CDATA[Mobile-first]]></category>
		<category><![CDATA[Modernizr]]></category>
		<category><![CDATA[Nathan Weizenbaum]]></category>
		<category><![CDATA[Nesting]]></category>
		<category><![CDATA[Nicole Sullivan]]></category>
		<category><![CDATA[Node]]></category>
		<category><![CDATA[OOCSS]]></category>
		<category><![CDATA[Responsive]]></category>
		<category><![CDATA[Rhino]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SASS]]></category>
		<category><![CDATA[Sass 3.2]]></category>
		<category><![CDATA[SFHTML5]]></category>
		<category><![CDATA[Stylus]]></category>
		<category><![CDATA[The Sass Way]]></category>
		<category><![CDATA[TJ Holowaychuk]]></category>
		<category><![CDATA[Twitter Bootstrap]]></category>
		<category><![CDATA[Variables]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://verekia.com/?p=216</guid>
		<description><![CDATA[On May 31st, I gave this talk at SFHTML5 about CSS Preprocessors:]]></description>
				<content:encoded><![CDATA[<p>On May 31st, I gave this talk at SFHTML5 about CSS Preprocessors:</p>
<p><iframe width="584" height="407" src="http://www.youtube.com/embed/FlW2vvl0yvo" frameborder="0" allowfullscreen></iframe></p>
<div style="width:584px" id="__ss_13164993">
<p><iframe src="http://www.slideshare.net/slideshow/embed_code/13164993" width="584" height="488" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen></iframe></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://verekia.com/slides/css-preprocessors/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Initializr: With Great Templates Comes Great Responsivity!</title>
		<link>http://verekia.com/initializr/responsive-template?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=responsive-template</link>
		<comments>http://verekia.com/initializr/responsive-template#comments</comments>
		<pubDate>Wed, 21 Dec 2011 04:31:06 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Initializr]]></category>
		<category><![CDATA[1140px]]></category>
		<category><![CDATA[960px]]></category>
		<category><![CDATA[@media only screen]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Christmas]]></category>
		<category><![CDATA[Column]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Fluid]]></category>
		<category><![CDATA[Generator]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[Golden Ratio]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Laptop]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[Margin]]></category>
		<category><![CDATA[Media Queries]]></category>
		<category><![CDATA[min-width]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile-first]]></category>
		<category><![CDATA[Padding]]></category>
		<category><![CDATA[Percentage]]></category>
		<category><![CDATA[Progressive Enhancement]]></category>
		<category><![CDATA[Proportions]]></category>
		<category><![CDATA[Readability]]></category>
		<category><![CDATA[Resize]]></category>
		<category><![CDATA[Resolution]]></category>
		<category><![CDATA[Responsive]]></category>
		<category><![CDATA[Scale]]></category>
		<category><![CDATA[Screen]]></category>
		<category><![CDATA[Size]]></category>
		<category><![CDATA[Smartphone]]></category>
		<category><![CDATA[Tablet]]></category>
		<category><![CDATA[Template]]></category>
		<category><![CDATA[Width]]></category>
		<category><![CDATA[Window]]></category>

		<guid isPermaLink="false">http://verekia.com/?p=169</guid>
		<description><![CDATA[Today I&#8217;m proud to announce that a &#8220;Responsive template&#8221; is now available on Initializr! It will help you dealing with all the various devices used to display your site. Mobiles, tablets, netbooks, laptops, desktop monitors, HUGE desktop monitors&#8230; Making your &#8230; <a href="http://verekia.com/initializr/responsive-template">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://verekia.com/wp-content/uploads/2011/12/responsive-web-design-template.png"><img src="http://verekia.com/wp-content/uploads/2011/12/responsive-web-design-template.png" alt="Resize Me - Responsive Web Design Template" title="Resize Me - Responsive Web Design Template" width="683" height="202" class="aligncenter size-full wp-image-174" /></a></p>
<p>Today I&#8217;m proud to announce that a &#8220;Responsive template&#8221; is now available on <a href="http://www.initializr.com/" target="_blank">Initializr</a>! It will help you dealing with all the various devices used to display your site. Mobiles, tablets, netbooks, laptops, desktop monitors, HUGE desktop monitors&#8230; Making your site work correctly on all these devices is a real nightmare. Well guess what? This nightmare is&#8230; absolutely not over! But as least, the boilerplate code of a responsive layout is now here to make your life easier.</p>
<p>Let’s see how it works and what best practices are introduced with this new template.</p>
<p><span id="more-169"></span></p>
<h2>Little reminder about responsive web design</h2>
<p>For those who have been living in a cave for the last few months (understand: for those who have a life and don&#8217;t spend days reading tweets and blogs) you probably need a short update about what a &#8220;responsive&#8221; design is.</p>
<p>The concept, introduced by <a href="http://ethanmarcotte.com/" target="_blank">Ethan Marcotte</a>, is pretty simple: the page layout should adapt depending on the screen size so it&#8217;s always convenient and easily readable for the user. On mobile for instance, it’s more comfortable to get a minimalistic one-column vertical view than getting a 2 or 3 columns view &#8211; which is perfect for desktops. What about tablets? Maybe we can also adapt the layout to fit their medium size screen too? Since we can’t know the screen size of our users’ devices, well it should just work everywhere.</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/12/responsive-web-design-ethan-marcotte.jpg"><img src="http://verekia.com/wp-content/uploads/2011/12/responsive-web-design-ethan-marcotte.jpg" alt="Responsive Web Design Ethan Marcotte" title="Responsive Web Design Ethan Marcotte" width="328" height="262" class="aligncenter size-full wp-image-203" /></a></p>
<p>To design a responsive layout, we have to forget about the usual static 960px width layouts and go fluid with percentage widths and media queries.</p>
<h2>A fluid layout with percentage widths</h2>
<p>The first thing our page needs is a &#8220;fluid&#8221; layout. A layout is called fluid when the text adapts its container size and when proportions are preserved when the window is resized. To get this working we can&#8217;t have any hard coded static value for widths, horizontal padding nor horizontal margins. We can basically only use percentages:</p>
<pre class="brush: css; title: ; notranslate"> 
#this-is-a-fluid-container{
	width:50%;
	padding: 20px 10%;
	margin:0 10%;
}
</pre>
<p>If you strictly follow this approach, your layout will scale perfectly from a small mobile screen to a huge desktop monitor. It&#8217;s already pretty cool, but you still have the same layout on every device, which is far from ideal! Don’t worry, now comes the fun part with media-queries to solve this problem.</p>
<h2>Mobile-first approach media queries</h2>
<p>Media queries are a cool way to specify different styles depending on the device used (by aiming particular screen resolutions or orientations for example). The mobile-first approach is the equivalent of progressive enhancement for media-queries. The principle is to start with the lowest resolution devices and then enhance the experience for bigger screens.</p>
<h3>The “mobile” view</h3>
<p>Here is the very simple mobile display of the responsive template. It doesn&#8217;t take into account any media query yet:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/12/responsive-layout-mobile-smartphone-iphone.png"><img src="http://verekia.com/wp-content/uploads/2011/12/responsive-layout-mobile-smartphone-iphone.png" alt="Responsive Layout for Mobile - Smartphone - iPhone" title="Responsive Layout for Mobile - Smartphone - iPhone" class="aligncenter size-full wp-image-175" style="width:200px" /></a></p>
<p>You can see that an <code>aside</code> orange block is located at the bottom of the page:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/12/media-query-mobile-smartphone-iphone-bottom.png"><img src="http://verekia.com/wp-content/uploads/2011/12/media-query-mobile-smartphone-iphone-bottom.png" alt="Bottom of the mobile layout for smartphones" title="Bottom of the mobile layout for smartphones" class="aligncenter size-full wp-image-180" style="width:200px" /></a></p>
<p class="advice"><strong>Note</strong>: Remember that an <code>aside</code> element is absolutely not meant to just be on the right or the left of an other element. Its semantic definition is that its content should be related to the main content, so its perfectly fine to have it under the article.
</p>
<h3>The “intermediate” view</h3>
<p>If we display this page on a larger device (like a tablet or a wide smartphone), the vertical menu gets a little bit annoying and ugly because its buttons are stretched too much. We can use a media query to display them horizontally for screens larger than 480px like this:</p>
<pre class="brush: css; title: ; notranslate">
@media only screen and (min-width: 480px) {
   	
	nav a{
		float:left;
		width:27%;
		margin:0 1.7%;
		padding:25px 2%;
		margin-bottom:0;
	}
}
</pre>
<p>Which has the following result:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/12/media-query-tablets-ipad.png"><img src="http://verekia.com/wp-content/uploads/2011/12/media-query-tablets-ipad.png" alt="Media Queries Tablets iPad" title="Media Queries Tablets iPad" width="617" height="751" class="aligncenter size-full wp-image-184" style="width:400px" /></a></p>
<h3>The “wide” view</h3>
<p>We now have a more convenient menu for tablets. Awesome! But what if we open this page on a laptop now? They have bigger screens so the vertical one column layout might not be the best fit for these devices. We would rather prefer a 2 columns layout, so we can move the &#8220;aside&#8221; block and the menu to the right of the page, and keep the content on the left. Let&#8217;s use a second media query to do that for resolutions higher than 768px:</p>
<pre class="brush: css; title: ; notranslate">
@media only screen and (min-width: 768px) {
	
	#title{
		float:left;
	}

	nav{
		float:right;
		width:38%;
	}
 
	#main article{
		float:left;
		width:57%;
	}

	#main aside{
		float:right;
		width:38%;
	}
}
</pre>
<p>This is what we get on a screen of approximately 900 pixels wide:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/12/media-query-960.png"><img src="http://verekia.com/wp-content/uploads/2011/12/media-query-960.png" alt="960 pixels wide layout" title="960 pixels wide layout" width="947" height="759" class="aligncenter size-full wp-image-185" /></a></p>
<p>We now have a nice 2-columns “desktop view”. You see, it wasn’t that hard to start from the mobile version first! I admit it might not be intuitive at first, but you get used to it pretty fast, and it’s definitely cleaner.</p>
<p class="advice"><strong>Note</strong>: You may have noticed some new shadows on this one. Fancy CSS3 effects, like shadows, are CPU consuming so they’re not very suitable for mobiles and low-CPU devices in general. This layout will probably be displayed on a more powerful device like a laptop or a desktop, so we can suppose they’re good enough to handle these effects.
</p>
<h3>The “maximal width” view</h3>
<p>Last but not least, we want a decent display on wide screens. If we leave it as it is now and open the page on a wide screen, a 5 line paragraph would be turned into an awful huge single line, which is terrible for readability. We need a maximal width limit to avoid this on wide screens. This limit can be anything: 960px, 1140px, 2000px, whatever, just choose one that make sense for your site.</p>
<p>In our case I picked 1140px, which suits well 1280 pixels wide screens, the most common resolution. An old school wrapper with fixed width and auto margins does the job perfectly:</p>
<pre class="brush: css; title: ; notranslate"> 
@media only screen and (min-width: 1140px) {
 
	.wrapper{
		width:1026px; /* 1140px - 10% for margins */
		margin:0 auto;
	}
}
</pre>
<p>I&#8217;ve set the wrapper&#8217;s width to 1026px (1140px &#8211; 10%) because on the previous layouts the margins were set to 10%. Therefore if we resize the browser it will move from one layout to another seamlessly. Here is the widest layout we can get:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/12/media-query-1140-large.png"><img src="http://verekia.com/wp-content/uploads/2011/12/media-query-1140-large.png" alt="Wide screen 1140px static layout" title="Wide screen 1140px static layout" width="1509" height="839" class="aligncenter size-full wp-image-186" /></a></p>
<p>All right! We’re done with media queries!</p>
<h2>Christmas presents for nice web developers</h2>
<p>Since you&#8217;ve been very nice this year, here are some other presents for you!</p>
<h3>1st gift: A Live Demo!</h3>
<p>There is now a live demo of the responsive template to see if it works as expected before downloading anything. This is also particularly convenient to see how it runs on your mobile or tablet.</p>
<p>You can find it on <a href="http://www.initializr.com/try" target="_blank">initializr.com/try</a>.</p>
<h3>2nd gift: The Golden Ratio</h3>
<p>This responsive template comes with some golden ratio black magic. You may have heard of it, it&#8217;s a weird mathematical proportion that our stupid brains are supposed to like. Even if its effects are pretty uncertain, many designers and artists like to use it, hoping people will subconsciously like their work more. I&#8217;ve set the proportions of the left and right sections of the desktop view to 62% and 38% (take margins into account) so it always matches the golden ratio as you resize the browser.</p>
<p>Here is also a <a href="http://goldenratiocalculator.com/?width=100" target="_blank">golden ratio calculator</a> for you to play with, and an <a href="http://net.tutsplus.com/tutorials/other/the-golden-ratio-in-web-design/" target="_blank">interesting tutorial</a> about how to apply it to your layout. Feel free to use this black magic or not, but don&#8217;t go crazy with it, this is more myth than science :)</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/12/golden-ratio.jpg"><img src="http://verekia.com/wp-content/uploads/2011/12/golden-ratio.jpg" alt="Golden Ratio" title="Golden Ratio" width="500" height="331" class="aligncenter size-full wp-image-197" /></a></p>
<h3>3rd gift: Readability For The Win</h3>
<p>This new template comes with pretty decent styles for a good readability. Remember that readability is absolutely crucial for your users. It will make them actually read what you have to say instead of just looking at pictures, and if this reading is pleasant they will be more eager to subscribe, retweet, buy your stuff or whatever you want them to do. This is a pretty big deal!</p>
<p>Here is some advice to improve readability:</p>
<ul>
<li>Use a big font size and an adapted line height (this template uses 16px / 24px).</li>
<li>A line should have approximately 80 characters (you’re all set with the template).</li>
<li>Avoid paragraphs of more than 5 lines.</li>
<li>Avoid sections of more than 5 paragraphs in a row.</li>
<li>Put stuff between paragraphs when you can and when it makes sense so the reader can breath before he starts a new one (charts, pictures, code, decorations&#8230;).</li>
</ul>
<p><a href="http://verekia.com/wp-content/uploads/2011/12/readability.jpg"><img src="http://verekia.com/wp-content/uploads/2011/12/readability.jpg" alt="Readability" title="Readability" width="350" height="263" class="aligncenter size-full wp-image-201" /></a></p>
<h3>4th gift: A Github repository for this responsive template</h3>
<p>Some of you might have noticed that Initializr&#8217;s Github repository is the website’s repository, not the template&#8217;s. So it&#8217;s pretty useless for you except if you want to know how to generate archives in Java! I&#8217;ve created a new Github repo for this responsive template, so you can fork it and suggest modifications and improvements to it. Way more useful, yay!</p>
<p>Here is the new repository: <a href="https://github.com/verekia/initializr-template" target="_blank">github.com/verekia/initializr-template</a> </p>
<p><a href="http://verekia.com/wp-content/uploads/2011/12/github-logo.png"><img src="http://verekia.com/wp-content/uploads/2011/12/github-logo.png" alt="Github Logo" title="Github Logo" width="200" height="200" class="aligncenter size-full wp-image-199" /></a></p>
<h2>Enjoy!</h2>
<p>I hope this new responsive template will make your web developer life easier, so you can focus on your actual business instead of setting up again and again the same boilerplate code. I would love to hear your feedback about this, so feel free to <a href="https://github.com/verekia/initializr-template/issues" target="_blank">open issues on Github</a> or mention <a href="http://twitter.com/#!/initializr" target="_blank">@initializr</a> or <a href="http://twitter.com/#!/verekia" target="_blank">@verekia</a> on Twitter, I usually reply fast :)</p>
<p>Merry Christmas and Happy New Year!</p>
]]></content:encoded>
			<wfw:commentRss>http://verekia.com/initializr/responsive-template/feed</wfw:commentRss>
		<slash:comments>113</slash:comments>
		</item>
		<item>
		<title>Build a simple client-side MVC app with RequireJS</title>
		<link>http://verekia.com/requirejs/build-simple-client-side-mvc-app-require-js?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=build-simple-client-side-mvc-app-require-js</link>
		<comments>http://verekia.com/requirejs/build-simple-client-side-mvc-app-require-js#comments</comments>
		<pubDate>Thu, 03 Nov 2011 04:28:27 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[RequireJS]]></category>
		<category><![CDATA[Addy Osmani]]></category>
		<category><![CDATA[AMD]]></category>
		<category><![CDATA[App]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[Asynchronous Module Definition]]></category>
		<category><![CDATA[Backbone]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Client-side]]></category>
		<category><![CDATA[Controller]]></category>
		<category><![CDATA[data-main]]></category>
		<category><![CDATA[define]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[Front-end]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[hashchange]]></category>
		<category><![CDATA[History]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[HTTP requests]]></category>
		<category><![CDATA[James Burke]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery-tmpl]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Large-scale]]></category>
		<category><![CDATA[local storage]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[Modular]]></category>
		<category><![CDATA[Module Pattern]]></category>
		<category><![CDATA[Mustache]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[organize]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Require]]></category>
		<category><![CDATA[require.js]]></category>
		<category><![CDATA[Revealing Module Pattern]]></category>
		<category><![CDATA[Routes]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[script loading]]></category>
		<category><![CDATA[serialization]]></category>
		<category><![CDATA[stringify]]></category>
		<category><![CDATA[structure]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[Templating]]></category>
		<category><![CDATA[TodoMVC]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[View]]></category>
		<category><![CDATA[Web App]]></category>
		<category><![CDATA[webperf]]></category>

		<guid isPermaLink="false">http://verekia.com/?p=127</guid>
		<description><![CDATA[As a web developer, you certainly often started coding your JavaScript in a single file, and, as the code base gets larger and larger, it became really difficult to maintain. To solve this problem you can split your code in &#8230; <a href="http://verekia.com/requirejs/build-simple-client-side-mvc-app-require-js">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://verekia.com/wp-content/uploads/2011/11/require-js.png"><img src="http://verekia.com/wp-content/uploads/2011/11/require-js.png" alt="Require JS Logo" title="Require JS Logo" width="220" height="138" class="aligncenter size-full wp-image-128" /></a></p>
<p>As a web developer, you certainly often started coding your JavaScript in a single file, and, as the code base gets larger and larger, it became really difficult to maintain. To solve this problem you can split your code in several files, add more <code>script</code> tags and use global variables to reach functions declared in other files. But this pollutes the global namespace and for each file an additional HTTP request consumes bandwidth, which slows down the loading time of the page.</p>
<p>If this happened to you, you certainly understand that there is a strong need to organize our front-end code differently, particularly if we have to build large-scale web apps with thousands of lines of JavaScript. We need a new way to organize all this mess to make it easier to maintain. This new technique consists in using script loaders. Plenty of them are available on the web, but we’ll focus on a very good one called RequireJS.</p>
<p>In this step by step tutorial you will learn how to build a simple MVC (Model &#8211; View &#8211; Controller) app using RequireJS. You don’t need any particular previous knowledge of script loading &#8211; we’ll see the basics together.</p>
<p><span id="more-127"></span></p>
<h2>Introduction</h2>
<h3>What is RequireJS and why it&#8217;s awesome</h3>
<p>RequireJS is an implementation of <a href="https://github.com/amdjs/amdjs-api/wiki/AMD" target="_blank">AMD</a> (Asynchronous Module Definition), an API for declaring modules and loading them asynchronously on the fly when they’re needed. It’s developed by <a href="http://twitter.com/#!/jrburke" target="_blank">James Burke</a>, and it just reach the symbolic 1.0 version after 2 years of development. RequireJS can help you organize your code with modules and will manage for you the asynchronous and parallel downloads of your files. Since scripts are loaded only when needed and in parallel, it reduces the loading time of your page, which is great!</p>
<h3>MVC for front-end?</h3>
<p>MVC is a well known design pattern to organize server-side code and make it modular and sustainable. What about using it for front-end? Can we apply this design pattern to JavaScript? If you’re just using JavaScript for animating, validating few forms or any simple treatment that doesn’t require many lines of code (let’s say less than 100 lines), there is no need to structure your files using MVC, and probably no need to use RequireJS either. However if you’re building a rich web app with many different views, definitely yes!</p>
<h3>The app we’ll create</h3>
<p>To illustrate how to organize your MVC code using RequireJS, we’ll create a very simple app with 2 views:</p>
<ul>
<li>The first view will display a list of users (represented by a <code>name</code> attribute),</li>
<li>The second view will allow you to add a user.</li>
</ul>
<p>This is how it will look like at the end:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/11/requirejs-mvc-app.png"><img src="http://verekia.com/wp-content/uploads/2011/11/requirejs-mvc-app.png" alt="Require JS MVC App" title="Require JS MVC App" width="591" height="263" class="aligncenter size-full wp-image-129" /></a></p>
<p>The business logic is obviously super simple so you can focus on understanding what’s really important here: structuring your code. And since it’s that simple, I <em>strongly</em> recommend that you really try to do it in parallel of reading this tutorial. It won’t take long, and if you have never done modular programming or used RequireJS before, coding this example will really help you become a better programmer. Seriously, it’s worth it, you should do it.</p>
<h3>HTML and CSS files</h3>
<p>Here is the HTML markup we’ll use for this example:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;meta charset=&quot;utf-8&quot;&gt;
	&lt;title&gt;A simple MVC structure&lt;/title&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div id=&quot;container&quot;&gt;
		&lt;h1&gt;My users&lt;/h1&gt;
		&lt;nav&gt;&lt;a href=&quot;#list&quot;&gt;List&lt;/a&gt; - &lt;a href=&quot;#add&quot;&gt;Add&lt;/a&gt;&lt;/nav&gt;
		&lt;div id=&quot;app&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;
	&lt;script data-main=&quot;js/main&quot; src=&quot;js/require.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The navigation in our app will be the links of the <code>nav</code> menu which will remain present on each page of the app, and all the magic of the MVC application will happen in the <code>#app</code> div. We also included RequireJS (which you can grab <a href="http://requirejs.org/docs/download.html" target="_blank">here</a>) at the bottom of the <code>body</code>, and you can notice a special attribute on the <code>script</code> tag: <code>data-main="js/main"</code>. The value passed to this attribute is used by RequireJS as the entry point of the entire application.</p>
<p>Let’s also add just a little bit of basic styling:</p>
<pre class="brush: css; title: ; notranslate">
#container{
	font-family:Calibri, Helvetica, serif;
	color:#444;
	width:200px;
	margin:100px auto 0;
	padding:30px;
	border:1px solid #ddd;
	background:#f6f6f6;
	-webkit-border-radius:4px;
	   -moz-border-radius:4px;
	        border-radius:4px;
}

h1, nav{
	text-align:center;
	margin:0 0 20px;
}
</pre>
<h3>OOP reminder: What is a module?</h3>
<p>In JavaScript Object-Oriented Programming, there is a very common design pattern called Module Pattern. It is used to encapsulate methods and attributes in objects (which are the “modules”) to avoid polluting the global namespace. It is also used to kind of simulate classes from other OOP languages like Java or PHP. This is how you would define a simple <code>MyMath</code> module in our <code>main.js</code> file:</p>
<pre class="brush: jscript; title: ; notranslate">
var MyMath = (function(){

	// Put your private variables and functions here
	
	return { // Here are the public methods
		add:function(a, b){
			return a + b;
		}
	};
})();

console.log(MyMath.add(1, 2));
</pre>
<p>Public methods are declared using the object literal notation, which is not very convenient. You can alternatively use the Revealing Module Pattern, which returns private attributes and methods:</p>
<pre class="brush: jscript; title: ; notranslate">
var MyMath = (function(){

	// With this pattern you can use the usual function notation:
	
	function add(a, b){
		return a + b;
	}
	
	return {
		add:add // But don't forget to declare it in the returned object!
	};
})();

console.log(MyMath.add(1, 2));
</pre>
<p>I will be using the Revealing Module Pattern in the rest of this article.</p>
<h2>RequireJS</h2>
<h3>Defining a module with RequireJS</h3>
<p>In the last section we declared a module in a variable to call it later. This is just one way to declare modules. We’re now going to see a (barely!) different method used by RequireJS. The purpose of RequireJS is to split our JavaScript files for a better maintainability, so let’s create a <code>MyMath.js</code> file to <em>define</em> our <code>MyMath</code> module in the same folder as <code>main.js</code>:</p>
<pre class="brush: jscript; title: ; notranslate">
define(function(){

	function add(a, b){
		return a + b;
	}
	
	return {
		add:add
	};
});
</pre>
<p>Instead of declaring a variable, we just put the module as a parameter of the <code>define</code> function. This function is provided by RequireJS and will make our module accessible from the outside.</p>
<h3>Requiring a module from the main file</h3>
<p>Let’s go back to our <code>main.js</code> file. RequireJS provides a second function called <code>require</code> that we’re going to use to call our <code>MyMath</code> module. Here is what our <code>main.js</code> now looks like:</p>
<pre class="brush: jscript; title: ; notranslate">
require(['MyMath'], function(MyMath){
	
	console.log(MyMath.add(1, 2));	

});
</pre>
<p>The call to <code>MyMath</code> is now wrapped in the <code>require</code> function, which takes 2 parameters:</p>
<ul>
<li>An array of modules we want to load, declared with their path relative to the entry point (remember the <code>data-main</code> attribute in the HTML) and without the <code>.js</code> extension,</li>
<li>A function to call once these dependencies are loaded. The modules will be passed as parameters of this function so you can simply name those parameters with the same modules names.</li>
</ul>
<p>You can now reload the page and&#8230; congratulations! You just called a method from an other file! Yes, that was super easy and you’re now ready for the big scary MVC architecture (which works exactly like the module definition you just did, so be sure you’ll be doing great!).</p>
<h2>The MVC structure</h2>
<p class="advice"><strong>Important note</strong>: In this tutorial, we’ll mimic the server-side MVC in which 1 controller = 1 view. In front-end development, it is very common to have multiple views per controller. In this case views become visual components like buttons or fields. MVC JavaScript frameworks like Backbone use this different approach which is not the purpose of this article. My goal here is not to create a real life entire MVC framework, but simply illustrate how RequireJS works through a structure that many of you already know well.</p>
<p>Let’s start with the part I’m sure you love: creating all the folders and files of our project. We want to use Models to represent data, the business logic will be handled by Controllers, and those controllers will call specific Views to render pages. So guess what? We need 3 folders: Models, Controllers and Views. Considering our simple app case, we’ll have 2 controllers, 2 views and 1 model.</p>
<p>Our JavaScript folder now looks like this:</p>
<ul>
<li>Controllers</li>
<ul>
<li>AddController.js</li>
<li>ListController.js</li>
</ul>
<li>Models</li>
<ul>
<li>User.js</li>
</ul>
<li>Views</li>
<ul>
<li>AddView.js</li>
<li>ListView.js</li>
</ul>
<li>main.js</li>
<li>require.js</li>
</ul>
<p>Got the structure ready? Great! Let’s start implementing the simplest part: the Model.</p>
<h2>The Model: User.js</h2>
<p>In this example, a <code>User</code> will be a simple class with a <code>name</code> attribute:</p>
<pre class="brush: jscript; title: ; notranslate">
define(function(){
	
	function User(name){
		this.name = name || 'Default name';
	}
	
	return User;
});
</pre>
<p>If we now come back to our <code>main.js</code> file, we can declare the dependency to <code>User</code> in the require method, and manually create a set of users for the purpose of this example:</p>
<pre class="brush: jscript; title: ; notranslate">
require(['Models/User'], function(User){
	
	var users = [new User('Barney'),
	             new User('Cartman'),
	             new User('Sheldon')];
	
	for (var i = 0, len = users.length; i &lt; len; i++){
		console.log(users[i].name);
	}
	
	localStorage.users = JSON.stringify(users);
});
</pre>
<p>We then serialize in JSON the users array and store it in the HTML5 local storage to make it accessible just like a database:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/11/users-console.png"><img src="http://verekia.com/wp-content/uploads/2011/11/users-console.png" alt="Chrome Console showing the users" title="Chrome Console showing the users" width="641" height="290" class="aligncenter size-full wp-image-132" /></a></p>
<p class="advice"><strong>Note</strong>: JSON serialization with <code>stringify</code> and deserialization with <code>parse</code> need a polyfill to work in IE7 and inferiors. You should use Douglas Crockford’s <code>json2.js</code> from his <a href="https://github.com/douglascrockford/JSON-js" target="_blank">Github repository</a> for this.</p>
<h2>Displaying the users list</h2>
<p>It’s time to display those users in the app interface!  We’ll have to work with <code>ListController.js</code> and <code>ListView.js</code> to do that. Those 2 components are obviously related, and they’ll be linked someway. There are many ways we can do that, and to keep this example simple, here is what I suggest: The <code>ListView</code> will have a <code>render</code> method and our <code>ListController</code> will simply get the users from the local storage and call <code>ListView</code>’s <code>render</code> method by passing the users as a parameter. So obviously, <code>ListController</code> needs <code>ListView</code> as a dependency.</p>
<p>Just like with <code>require</code>, you can pass an array of dependencies to <code>define</code> if the module relies on other modules. Let’s also create a <code>start</code> method (or any other name that makes sense to you &#8211; like <code>run</code> or <code>main</code>), to put the main behavior of the controller in it:</p>
<pre class="brush: jscript; title: ; notranslate">
define(['Views/ListView'], function(ListView){
	
	function start(){
		var users = JSON.parse(localStorage.users);
		ListView.render({users:users});
	}
	
	return {
		start:start
	};
});
</pre>
<p>Here we deserialize the users from the local storage and pass it to <code>render</code> as an object. Now, all we have to do is implementing a <code>render</code> method in <code>ListView.js</code>:</p>
<pre class="brush: jscript; title: ; notranslate">
define(function(){
	
	function render(parameters){
		var appDiv = document.getElementById('app');

		var users = parameters.users;
		
		var html = '&lt;ul&gt;';
		for (var i = 0, len = users.length; i &lt; len; i++){
			html += '&lt;li&gt;' + users[i].name + '&lt;/li&gt;';
		}
		html += '&lt;/ul&gt;';
		
		appDiv.innerHTML = html;
	}

	return {
		render:render
	};
});
</pre>
<p>This method simply loops on our users to concatenate them in an HTML string we inject in the <code>#app</code> element.</p>
<p class="advice"><strong>Important</strong>: Using plain HTML in a JavaScript file like this is not an ideal solution, because it’s very hard to maintain. You should instead consider templating. Templates are an elegant way to insert data in HTML markup. Many very good templating systems are available on the web. You can for instance use <a href="https://github.com/jquery/jquery-tmpl" target="_blank">jQuery-tmpl</a> or <a href="https://github.com/janl/mustache.js" target="_blank">Mustache.js</a>. But this is beyond the scope of this article and it would add complexity to the current architecture, so I prefer keeping it simple.</p>
<p>Now, all we need to do is to “run” our <code>ListController</code> module. To do that let’s declare it as a dependency of <code>require</code> in our <code>main.js</code> file, and call <code>ListController.start()</code>:</p>
<pre class="brush: jscript; title: ; notranslate">
require(['Models/User', 'Controllers/ListController'], function(User, ListController){
	
	var users = [new User('Barney'),
	             new User('Cartman'),
	             new User('Sheldon')];
	
	localStorage.users = JSON.stringify(users);
	
	ListController.start();	
});
</pre>
<p>You can now refresh your page to get this wonderful list of users:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/11/mvc-users-list.png"><img src="http://verekia.com/wp-content/uploads/2011/11/mvc-users-list.png" alt="MVC users list" title="MVC users list" width="297" height="267" class="aligncenter size-full wp-image-133" /></a></p>
<p>Woooaaaah, it works! Congratulations if you coded this too!</p>
<p class="advice"><strong>Note</strong>: For the moment, we can only manually declare the controller we want to run since we don’t have any routing system yet. But we’ll create a very simple one pretty soon, be patient!</p>
<h2>Adding a user</h2>
<p>We now want to be able to add users to our list. We’ll display a simple text input and a button, with an event handler when the button is clicked to add the user to the local storage. Let’s start with <code>AddController</code>, just like we did in the previous section. This file will be pretty simple since we don’t have any parameter to give to the view. Here is <code>AddController.js</code>:</p>
<pre class="brush: jscript; title: ; notranslate">
define(['Views/AddView'], function(AddView){

	function start(){
		AddView.render();
	}

	return {
		start:start
	};
});
</pre>
<p>And its corresponding view:</p>
<pre class="brush: jscript; title: ; notranslate">
define(function(){
	
	function render(parameters){
		var appDiv = document.getElementById('app');
		appDiv.innerHTML = '&lt;input id=&quot;user-name&quot; /&gt;&lt;button id=&quot;add&quot;&gt;Add this user&lt;/button&gt;';
	}
	
	return {
		render:render
	};
});
</pre>
<p>You can now declare <code>AddController</code> as a dependency in your main file and call its <code>start</code> method to successfully get the expected view:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/11/mvc-add-user.png"><img src="http://verekia.com/wp-content/uploads/2011/11/mvc-add-user.png" alt="MVC Add user" title="MVC Add user" width="290" height="242" class="aligncenter size-full wp-image-134" /></a></p>
<p>But since we don’t have any event bind on the button yet, this view is not very useful&#8230; Let’s work on that. I have a question for you: Where should we put the event logic for this event? In the view? In the controller? If we put it in the view it would be the right place to add the events listeners, but putting the business logic in a view would be a very bad practice. Putting the event logic in the controller seems to be a better idea, even if it’s not perfect because we don’t want to see any div’s ID in there, which belong to the view.</p>
<p class="advice"><strong>Note</strong>: The best way to go would be having event listeners in the view, which would call business logic methods located in the controller or in a new dedicated events module. This is really easy to do but it would make this example more complex and I don’t want you to be lost. Feel free to try doing it for practicing!</p>
<p>As I said, let’s put all the event logic in the controller. We can create a <code>bindEvents</code> function in <code>AddController</code> and call it after the view has finished rendering the HTML:</p>
<pre class="brush: jscript; title: ; notranslate">
define(['Views/AddView', 'Models/User'], function(AddView, User){

	function start(){
		AddView.render();
		bindEvents();		
	}
	
	function bindEvents(){
		document.getElementById('add').addEventListener('click', function(){
			var users = JSON.parse(localStorage.users);
			var userName = document.getElementById('user-name').value;
			users.push(new User(userName));
			localStorage.users = JSON.stringify(users);
			require(['Controllers/ListController'], function(ListController){
				ListController.start();
			});
		}, false);
	}

	return {
		start:start
	};
});
</pre>
<p>In <code>bindEvents</code>, we simply add an event listener for clicks on the <code>#add</code> button (feel free to use your own function to deal with IE’s <code>attachEvent</code> &#8211; or just use jQuery). When the button is clicked, we get the users string from the local storage, deserialize it to get the array, push a new user with the name contained in the <code>#user-name</code> input field, and put the updated users array back to the local storage. After that we finally <code>require</code> the <code>ListController</code> to execute its <code>start</code> method so we can see the result:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/11/mvc-list-added.png"><img src="http://verekia.com/wp-content/uploads/2011/11/mvc-list-added.png" alt="MVC List - User added" title="MVC List - User added" width="296" height="286" class="aligncenter size-full wp-image-138" /></a></p>
<p>Brilliant! It’s time for you to take a break, you’ve done a very good job if you’re still doing this example with me. You deserve a cup of coffee before we continue!</p>
<h2>Navigation between views with routes</h2>
<p>Okay back to work. Our little app is pretty cool but it really sucks that we still cannot navigate between views to add more users. What is missing is a <em>routing</em> system. If you’ve worked with server-side MVC frameworks before, you’re probably familiar with this. Each URL leads to a different view. However here we’re client-side and it’s slightly different. JavaScript single page interfaces like this one use the hash of the URL to navigate between different parts of the app. In our case, we want to be able to reach the 2 different views when hitting those URLs:</p>
<ul>
<li>http://yourlocalhostpath/#list</li>
<li>http://yourlocalhostpath/#add</li>
</ul>
<p>This will make each page of our app bookmarkable and easily reachable.</p>
<p class="advice"><strong>Note</strong>: Firefox, Chrome and Opera also have a pretty good support of HTML5 history management (pushState, popState, replaceState), which saves you from dealing with hashes.</p>
<h3>Browsers compatibility and functioning</h3>
<p>Managing history and hash navigation can be very painful if you need a good compatibility with old browsers. Depending on the browsers you aim to support here are different solution you can consider:</p>
<ul>
<li><a href="http://caniuse.com/#search=history" target="_blank">Only the most advanced browsers</a>: HTML5 history management,</li>
<li><a href="http://caniuse.com/#search=hashchange" target="_blank">Most of the current browsers</a>: HTML5 hashchange event,</li>
<li>Old browsers: Simple manual monitoring of hash changes,</li>
<li>Very old browsers: Manual monitoring + iframe hack.</li>
</ul>
<p>In our case we will do the simple manual monitoring, which is pretty easy to implement. All we need to do is checking if the hash changed every n milliseconds, and fire some function if a change is detected.</p>
<p class="advice"><strong>Note</strong>: A <a href="http://tkyk.github.com/jquery-history-plugin/" target="_blank">jQuery plugin</a> is also available to manage this for you.</p>
<h3>The routes and the main routing loop</h3>
<p>Let’s create a <code>Router.js</code> file next to <code>main.js</code> to manage the routing logic. In this file we need a way to declare our routes and the default one if none is specified in the URL. We can for instance use a simple array of route objects that contain a <code>hash</code> and the corresponding <code>controller</code> we want to load. We also need a <code>defaultRoute</code> if no hash is present in the URL:</p>
<pre class="brush: jscript; title: ; notranslate">
define(function(){

	var routes = [{hash:'#list', controller:'ListController'},
	              {hash:'#add',  controller:'AddController'}];
	var defaultRoute = '#list';
	var currentHash = '';
	
	function startRouting(){
		window.location.hash = window.location.hash || defaultRoute;
		setInterval(hashCheck, 100);
	}
	
	return {
		startRouting:startRouting
	};
});
</pre>
<p>When <code>startRouting</code> will be called, it will set the default hash value in the URL, and will start a repetition of calls to <code>hashCheck</code> that we haven’t implemented yet. The <code>currentHash</code> variable will be used to store the current value of the hash if a change is detected.</p>
<h3>Check for hash changes</h3>
<p>And here is <code>hashCheck</code>, the function called every 100 milliseconds: </p>
<pre class="brush: jscript; title: ; notranslate">
function hashCheck(){
	if (window.location.hash != currentHash){
		for (var i = 0, currentRoute; currentRoute = routes[i++];){
			if (window.location.hash == currentRoute.hash)
				loadController(currentRoute.controller);
		}
		currentHash = window.location.hash;
	}
}
</pre>
<p><code>hashCheck</code> simply checks if the hash has changed compared to the <code>currentHash</code>, and if it matches one of the routes, calls <code>loadController</code> with the corresponding controller name.</p>
<h3>Loading the right controller</h3>
<p>Finally, <code>loadController</code> just performs a call to <code>require</code> to load the controller’s module and execute its <code>start</code> function:</p>
<pre class="brush: jscript; title: ; notranslate">
function loadController(controllerName){
	require(['Controllers/' + controllerName], function(controller){
		controller.start();
	});
}
</pre>
<p>So the final <code>Router.js</code> file looks like this:</p>
<pre class="brush: jscript; title: ; notranslate">
define(function(){
	
	var routes = [{hash:'#list', controller:'ListController'},
	              {hash:'#add',  controller:'AddController'}];
	var defaultRoute = '#list';
	var currentHash = '';
	
	function startRouting(){
		window.location.hash = window.location.hash || defaultRoute;
		setInterval(hashCheck, 100);
	}
	
	function hashCheck(){
		if (window.location.hash != currentHash){
			for (var i = 0, currentRoute; currentRoute = routes[i++];){
				if (window.location.hash == currentRoute.hash)
					loadController(currentRoute.controller);
			}
			currentHash = window.location.hash;
		}
	}
	
	function loadController(controllerName){
		require(['Controllers/' + controllerName], function(controller){
			controller.start();
		});
	}
	
	return {
		startRouting:startRouting
	};
});
</pre>
<h3>Using the new routing system</h3>
<p>Now all we have to do is to <code>require</code> this module from our main file and call <code>startRouting</code>:</p>
<pre class="brush: jscript; title: ; notranslate">
require(['Models/User', 'Router'], function(User, Router){
	
	var users = [new User('Barney'),
	             new User('Cartman'),
	             new User('Sheldon')];
	
	localStorage.users = JSON.stringify(users);

	Router.startRouting();	
});
</pre>
<p>If we want to navigate in our app from a controller to another, we can just replace the current <code>window.hash</code> with the new controller’s hash route. In our case we still manually load the <code>ListController</code> in <code>AddController</code> instead of using our new routing system:</p>
<pre class="brush: jscript; title: ; notranslate">
require(['Controllers/ListController'], function(ListController){
	ListController.start();
});
</pre>
<p>Let’s replace those 3 lines with a simple hash update:</p>
<pre class="brush: jscript; title: ; notranslate">
window.location.hash = '#list';
</pre>
<p>And this is it! Our app has now a functional routing system! You can navigate from a view to another, come back, do whatever you want with the hash in the URL, it will keep loading the right controller if it matches the routes declared in the router. Sweet!</p>
<p>Here is an <a href="http://verekia.com/demo/require-js/" target="_blank">online demo</a> of the app.</p>
<h2>Conclusion</h2>
<p>You can be proud of yourself, you built an entire MVC app without any framework! We just used RequireJS to link our files together, which is really the only mandatory tool to build something modular. So now what are the next steps? Well if you liked the minimalist Do It Yourself approach I had in this tutorial, you can enrich our little framework with new features as your app grows and has new technical needs. Here are some ideas of potential interesting next steps:</p>
<ul>
<li>Integrate a templating system,</li>
<li>Create a small external library to put all what is not purely related to your app (like the routing system) to be able to reuse it on other projects,</li>
<li>Define what a Model, a View and a Controller are with objects in this library,</li>
<li>Create a new abstraction layer to deal with getting the data from various sources (RESTful APIs, localStorage, IndexedDB&#8230;).</li>
</ul>
<p>This DIY approach is excellent to learn, but the current state of our framework is really not sufficient for real life projects at this point. If you’re too lazy to implement the features listed above (and this list is absolutely not exhaustive!), you can also start learning how to use an existing MVC framework. The most popular are:</p>
<ul>
<li><a href="http://documentcloud.github.com/backbone/" target="_blank">Backbone</a></li>
<li><a href="http://javascriptmvc.com/" target="_blank">JavaScriptMVC</a></li>
<li><a href="http://www.sproutcore.com/" target="_blank">Sproutcore</a></li>
<li><a href="http://www.sencha.com/products/extjs/" target="_blank">ExtJS</a></li>
<li><a href="http://knockoutjs.com/" target="_blank">Knockout</a></li>
</ul>
<p>I personally like Backbone because it’s lightweight (less than 5kb minified), so my next tutorial will be about mixing RequireJS and Backbone, which works pretty well! Follow <a href="http://twitter.com/#!/verekia" target="_blank">@verekia</a> for updates about this. You should also follow Addy Osmani and read his tutorials about <a href="http://addyosmani.com/blog/large-scale-jquery/" target="_blank">large scale JavaScript applications</a> and <a href="http://addyosmani.com/writing-modular-js/" target="_blank">modular JavaScript</a>, and <a href="http://twitter.com/#!/jrburke" target="_blank">James Burke</a> the creator of RequireJS. Both are very good sources of information for building modular JavaScript apps. Addy Osmani also started a project called <a href="http://addyosmani.github.com/todomvc/" target="_blank">TodoMVC</a> to compare how different MVC frameworks can be used to build the same simple web app, which is really helpful to choose the right framework for your needs.</p>
<p>That’s all for today folks, thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://verekia.com/requirejs/build-simple-client-side-mvc-app-require-js/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>DON&#8217;T READ this Less CSS tutorial (highly addictive)</title>
		<link>http://verekia.com/less-css/dont-read-less-css-tutorial-highly-addictive?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dont-read-less-css-tutorial-highly-addictive</link>
		<comments>http://verekia.com/less-css/dont-read-less-css-tutorial-highly-addictive#comments</comments>
		<pubDate>Wed, 12 Oct 2011 07:40:09 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Less CSS]]></category>
		<category><![CDATA[-moz-]]></category>
		<category><![CDATA[-webkit-]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Addictive]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Color functions]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS Output]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Dangerous]]></category>
		<category><![CDATA[darken]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[desaturate]]></category>
		<category><![CDATA[Dotless]]></category>
		<category><![CDATA[Dynamic stylesheet language]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[fadein]]></category>
		<category><![CDATA[fadeout]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[Importing]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[LessPHP]]></category>
		<category><![CDATA[lighten]]></category>
		<category><![CDATA[Mixins]]></category>
		<category><![CDATA[Nested rules]]></category>
		<category><![CDATA[Operations]]></category>
		<category><![CDATA[Parametric Mixins]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Round]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SASS]]></category>
		<category><![CDATA[saturate]]></category>
		<category><![CDATA[Shapes]]></category>
		<category><![CDATA[spin]]></category>
		<category><![CDATA[Square]]></category>
		<category><![CDATA[Syntax highlighting]]></category>
		<category><![CDATA[this]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Variables]]></category>

		<guid isPermaLink="false">http://verekia.com/?p=60</guid>
		<description><![CDATA[WARNING: If you like copy-pasting, find-replacing, scrolling in giant messy CSS files, not reusing your code, writing hundreds of times the same thing, you should definitely LEAVE THIS PAGE RIGHT NOW. I’m serious, if you start reading this tutorial, you &#8230; <a href="http://verekia.com/less-css/dont-read-less-css-tutorial-highly-addictive">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-logo.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-logo.png" alt="Less CSS logo" title="Less CSS logo" width="199" height="81" class="aligncenter size-full wp-image-73" /></a></p>
<p class="warning">
<strong>WARNING</strong>: If you like copy-pasting, find-replacing, scrolling in giant messy CSS files, not reusing your code, writing hundreds of times the same thing, you should definitely LEAVE THIS PAGE RIGHT NOW. I’m serious, if you start reading this tutorial, you might like it and could dangerously become way more productive. At the end of this read, you might even think crazy things like <i>“pure CSS sucks”</i> ! You’ve been warned&#8230;
</p>
<p><strong>EDIT:</strong> I strongly recommend reading or watching <a href="http://verekia.com/slides/css-preprocessors" target="_blank">my talk about CSS Preprocessors</a> and consider using <a href="http://sass-lang.com/" target="_blank">Sass</a> instead of Less.</p>
<p>If you’re a web developer or designer you probably faced this kind of situation before:<br />
<i>“I wonder if we should use a different theme on our website, can we try a blue one instead of the current green?”</i></p>
<p>2 possible answers:</p>
<ul>
<li>A pure CSS developer: “Damn&#8230; Can you come back in 15 minutes?”</li>
<li>A Less CSS developer: “Sure! Wait just a second&#8230; Done, look!”</li>
</ul>
<p>If you’re using pure CSS, even when respecting best practices, chances are that your answer will be the first one. Indeed, CSS is really far from being perfect. Hasn’t it come to your mind that some essential features are missing from a such widely used language? For instance, very basic things like <em>variables</em>.</p>
<p>Declaring a simple variable to store a color at the top of your stylesheet and being able to change the entire theme of your site by only changing this single variable would be pretty neat right? And what about all these repetitions each time you use CSS3 properties with vendor prefixes? Wouldn’t it be useful to have to declare that just once?</p>
<p>Well guess what, we’re gonna fix that! This article will demonstrate the power of Less, an enrichment of CSS using JavaScript. It adds tons of awesome features missing from CSS to make your web developer life so much easier. Trust me, once you’ve tried it, it changes the way you code your stylesheets forever and you’ll never come back to pure CSS!</p>
<p><span id="more-60"></span></p>
<h2>What is Less?</h2>
<h3>A “dynamic” CSS</h3>
<p>According to the official website, Less is a “dynamic stylesheet language”. I have a question for you now: How many stylesheet languages do you know?</p>
<p>Well except if you developed your own language and a dedicated browser to interpret it, chances are that you only know CSS. You might even have never thought about “What if there were another stylesheet language?”. Well Less is <em>kind of</em> one. “Kind of” because you develop using the Less language, but in the end, it’s compiled to pure CSS so that browsers can read it.</p>
<p>It’s also called “dynamic” because it enriches CSS with many common features available in most modern dynamic programming languages (like variables for instance). During the development phase, you’ll be able to use all those new cool features we’ll see in this tutorial and it will help you code way more efficiently.</p>
<p>Less compiler, which is written in JavaScript, will convert all your Less code into CSS to be interpretable by the client. When does this conversion happen? Well you have 3 options:</p>
<ul>
<li>On the fly in the browser with <code>less.js</code>,</li>
<li>By using the lessc compiler via the command-line,</li>
<li>With some fancy app like CodeKit or LiveReload.</li>
</ul>
<h3>Compiling in the browser with less.js</h3>
<p><a href="http://lesscss.org/" target="_blank">LessCSS.org</a> has a big tempting button to download <code>less.js</code>. It is not a good idea. At least not for production.</p>
<p><code>Less.js</code> will perform AJAX requests to grab your Less files, will then process those files to convert them into CSS, and finally inject the resulting CSS in the head of your document. It is extremely inefficient in terms of performance and you should never use it in production. Plus, if the user&#8217;s JavaScript is deactivated, well&#8230; it will just not work at all.</p>
<p>But if you just want to do a quick Less prototype or if you don&#8217;t have access to your usual development environment, <code>less.js</code> is perfectly fine!</p>
<h3>Lessc and the command-line</h3>
<p>You can also execute Less in your terminal. In order to do this, you will need to install <a href="http://nodejs.org/" target="_blank">Node.js</a> on your development machine, and then install the Less module by running:</p>
<pre class="brush: css; title: ; notranslate">
npm install less -g
</pre>
<p>You can then simply run the following command to compile a <code>style.less</code> file to <code>style.css</code>:</p>
<pre class="brush: css; title: ; notranslate">
lessc style.less &gt; style.css
</pre>
<p>Simple and efficient, I highly recommend this method. But if you&#8217;re really scared of the command-line, you can also use an application to do it for you.</p>
<h3>Using an application to compile for you</h3>
<p>Here is a list of applications that you can run when you are working that will manage the compilation for you. It is taken from my slides about <a href="http://verekia.com/slides/css-preprocessors" target="_blank">CSS Preprocessors</a>:</p>
<p><img src="http://images.slidesharecdn.com/sfhtml5-csspreprocessorsstatic-120601124545-phpapp01/95/slide-36-728.jpg?1338651430" alt="" /></p>
<p>Some of these apps are free, others are paid. I&#8217;ve personally tried Codekit on Mac, which costs $25 and works really well.</p>
<h2>Okay sounds cool, let’s start!</h2>
<p>In this entire scenario, my goal will be to draw CSS shapes with different colors and decorations (cause it’s visual and I know you like it). Of course you can, and should, imagine how you can apply this to a real project. I highly recommend that you implement this example for real, because it’s the best way to learn. Honestly, you should <strong>really</strong> do it. I know you’re lazy but trust me, it’s worth it. So create an empty HTML file and here we go!</p>
<h3>Our HTML file</h3>
<p>First, here is the HTML we’ll be using:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!doctype html&gt;
&lt;head&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div class=&quot;shape&quot; id=&quot;shape1&quot;&gt;&lt;/div&gt;
	&lt;div class=&quot;shape&quot; id=&quot;shape2&quot;&gt;&lt;/div&gt;
	&lt;div class=&quot;shape&quot; id=&quot;shape3&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>A little bit of basic CSS styling</h3>
<p>Okay, we can finally start! First, create and open a <code>style.less</code> file. Then we add some CSS styles to our shapes in order to see them. We’ll set the default shape to a simple light blue square:</p>
<pre class="brush: css; title: ; notranslate">
.shape{
	display:inline-block;
	width:200px;
	height:200px;
	background:#ddf;
	margin:20px;
}
</pre>
<p>Run <code>lessc style.less > style.css</code> to compile it and this is what your browser should display:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-1.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-1.png" alt=".shape{ 	display:inline-block; 	width:200px; 	height:200px; 	background:#ddf; 	margin:20px; }" title="Less CSS - 3 blue squares" width="738" height="248" class="aligncenter size-full wp-image-72" /></a></p>
<p>Nothing surprising here, just pure and simple CSS for the moment. But what if our example gets mucher bigger and we declared the <code>#ddf</code> light blue color in several different places in the file? Even with very good CSS best practices, we would still have to replace every single declaration of this color in order to try a new theme for example. That’s not convenient at all. Let’s use a Less variable to handle this.</p>
<h2>Variables</h2>
<p>Less variables can be declared and used with the <code>@</code> symbol. You give them a name and a value, and then you can refer to the name of the variable anywhere in your Less file:</p>
<pre class="brush: css; title: ; notranslate">
@lightBlue:#ddf;

.shape{
	display:inline-block;
	width:200px;
	height:200px;
	background:@lightBlue;
	margin:20px;
}
</pre>
<p>Pretty cool right? But it won’t be very helpful if we have to change the references to <code>@lightBlue</code> everywhere in the code. So we can for instance declare an other variable for our “default theme”:</p>
<pre class="brush: css; title: ; notranslate">
@lightRed:   #fdd;
@lightGreen: #dfd;
@lightBlue:  #ddf;

@defaultThemeColor:@lightGreen;

.shape{
	display:inline-block;
	width:200px;
	height:200px;
	background:@defaultThemeColor;
	margin:20px;
}
</pre>
<p>With this example you can see our code becoming more modular and reusable. We just have to change the <code>@defaultThemeColor</code> to <code>@lightGreen</code> to apply the new green theme:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-2.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-2.png" alt="Less CSS - Three green squares" title="Less CSS - Three green squares" width="721" height="230" class="aligncenter size-full wp-image-80" /></a></p>
<p>You can see a Less best practice here as well: declaring all the dumb constants at the top of the file, and then adding some logic.Talking about constants, be aware that Less “variables” are actually just constants, and their value cannot be changed once they’re set. So like Indiana Jones, “choose wisely”!</p>
<div class="advice"><strong>Personal tip</strong>: I like to use the usual camelCase notation (lowercase for the first word, then uppercase for the first letter of the following words) for variables. You could also use the CSS-style naming convention with dashes-between-lowercase-words, it’s up to you. It personally helps me to differentiate Less from pure CSS.
</div>
<h2>Mixins</h2>
<p>Do you know how to draw rounds in CSS? You just have to set a very high CSS3 border-radius value. Let’s apply that to the first shape:</p>
<pre class="brush: css; title: ; notranslate">
#shape1{
	border-radius:9999px;
}
</pre>
<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-3.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-3.png" alt="Less CSS - Round and squares" title="Less CSS - Round and squares" width="720" height="229" class="aligncenter size-full wp-image-83" /></a></p>
<p>Since we used CSS3, if we want it to work for as many browsers as possible, we must provide the alternative <code>-webkit-</code> and <code>-moz-</code> vendor prefixes versions as well. So you would do something like this is regular CSS:</p>
<pre class="brush: css; title: ; notranslate">
#shape1{
	-webkit-border-radius:9999px;
	   -moz-border-radius:9999px;
	        border-radius:9999px;
}
</pre>
<p>We see something interesting here: three properties with the same value. Pretty boring to write right? No problem, Less to the rescue!</p>
<p>With Less we can define “mixins”, which are something comparable to functions in other programming languages. In Less they’re used to group CSS instructions. We’ll use a mixin to handle the boring repetition of border-radius declarations. Just like variables, you have to declare a mixin before calling it, with the <code>.</code> symbol this time:</p>
<pre class="brush: css; title: ; notranslate">
.Round{
	-webkit-border-radius:9999px;
	   -moz-border-radius:9999px;
	        border-radius:9999px;	
}

#shape1{
	.Round;
}
</pre>
<p>You can then apply this <code>.Round</code> mixin wherever you want to make something round without having to declare the <code>border-radius</code> instructions again. That’s already cool, but it gets even cooler with parameters.</p>
<div class="advice"><strong>Personal best practice</strong>: You probably noticed that I used a capitalized letter for the mixin name. Well since CSS class selectors also use the <code>.</code> symbol, there is no way to differentiate it from a Less mixin name. That’s why I always use capitalized letters. That also mimics Object Oriented Programming, which uses capitalized letters for classes.
</div>
<h2>Parametric mixins</h2>
<p>I now want to be able to create rounded squares, not just rounds. Let’s modify our <code>.Round</code> mixin to something more generic: <code>.RoundedShape</code>. Our <code>RoundedShape</code> mixin should be able to handle rounds and rounded squares, depending on the parameters used to call it. To declare parameters, use parentheses after the mixin name:</p>
<pre class="brush: css; title: ; notranslate">
@defaultRadius:30px;

.RoundedShape(@radius:@defaultRadius){
	-webkit-border-radius:@radius;
	   -moz-border-radius:@radius;
	        border-radius:@radius;	
}
</pre>
<p>A parameter can be used similarly to a variable inside the mixin, and you can specify a default value for the parameter if none is given when the mixin is called. I also used a variable for this default value to keep the code reusable and generic.</p>
<p>So now that we have our cool RoundedShape mixin, let’s create 2 other mixins which will call it to create rounds and rounded squares:</p>
<pre class="brush: css; title: ; notranslate">
.Round{
	.RoundedShape(9999px);
}

.RoundedSquare(@radius:@defaultRadius){
	.RoundedShape(@radius);
}
</pre>
<p>And then, all we have to do to is applying those <code>Round</code> and <code>RoundedSquare</code> to our shapes:</p>
<pre class="brush: css; title: ; notranslate">
#shape1{
	.Round;
}

#shape2{
	.RoundedSquare;
}
</pre>
<p>Now refresh your page and&#8230; BOOM!</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-4.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-4.png" alt="Less CSS - Rounded rectangle" title="Less CSS - Rounded rectangle" width="725" height="241" class="aligncenter size-full wp-image-87" /></a></p>
<p>Since we haven’t passed any parameter to <code>RoundedSquare</code>, the 30px <code>@defaultRadius</code> variable is used, but we could also call it with parameters, on <code>#shape3</code> for instance:</p>
<pre class="brush: css; title: ; notranslate">
#shape3{
	.RoundedSquare(60px)
}
</pre>
<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-5.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-5.png" alt="Less CSS : Round and rounded squares" title="Less CSS : Round and rounded squares" width="718" height="237" class="aligncenter size-full wp-image-88" /></a></p>
<p>With just 3 lines to call our mixins, we have a whole logic handling behind the scene that makes our code super reusable and easily maintainable. How cool is that? We can go way further with mixins. In my opinion, variables and mixins are so powerful that it’s a sufficient reason to move to Less! But since Less offers tons of other amazing features, let’s take a look at it.</p>
<h2>Operations</h2>
<p>One other powerful feature of Less is the ability to use mathematical operations in your stylesheets (I agree it sounds boring, but it’s actually very cool). Let’s declare a <code>@defaultShapesWidth</code> variable to set the default shapes widths to <code>200px</code> instead of hard-coding it like we used to:</p>
<pre class="brush: css; title: ; notranslate">
@defaultShapesWidth:200px;
</pre>
<p>Now I want to add some borders to our shapes. Borders, whose size will always be 10% of the shape width. How would you do that in pure CSS? Yeah, exactly, you can’t at all! So thanks to Less, we can now do this kind of operation:</p>
<pre class="brush: css; title: ; notranslate">
@borderSize:@defaultShapesWidth * 0.1;
</pre>
<p>You can add, subtract, multiply and divide values. So you might think <i>“Yeah, but it only works for pixels right?”</i>. Nope sir, it also works for colors!</p>
<pre class="brush: css; title: ; notranslate">
@defaultThemeColor:@lightBlue;
@borderColor:@defaultThemeColor - #222;
</pre>
<p>We darkened the light blue color by subtracting 2 hexadecimal units to each RGB value. It can be confusing the first time. Just keep in mind that adding or subtracting <code>#000</code> has no effect and <code>#fff</code> has a maximal effect.</p>
<p>And this is what we get when applying these new variables to a border rule:</p>
<pre class="brush: css; title: ; notranslate">
border:@borderSize solid @borderColor;
</pre>
<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-6.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-6.png" alt="Less CSS - Shapes with borders" title="Less CSS - Shapes with borders" width="848" height="283" class="aligncenter size-full wp-image-89" /></a></p>
<p>The result is exactly as expected. That’s awesome. But the color operation we used was pretty simple. Adding a little bit of dark is easy, performing saturation operations is way more complicated and unintuitive.  Fortunately, we can use some handy color functions to do that!</p>
<div class="advice"><strong>Side note</strong>: Remember that all this funky Less code will be converted to CSS in the end, so this will be static once generated. If you programmatically resize the width of a shape, the border won’t scale with it on the fly.
</div>
<h2>Color functions</h2>
<p>Less provides the following color functions:</p>
<ul>
<li><code>darken()</code> and <code>lighten()</code>, which add some black or white,</li>
<li><code>saturate()</code> and <code>desaturate()</code>, to make a color more “colorful” or more “grayscale”,</li>
<li><code>fadein()</code> and <code>fadeout()</code>, to increase or reduce transparency,</li>
<li>and <code>spin()</code>, which modifies the hue of the color.</li>
</ul>
<p>If, for instance, we want to make the border completely desaturated to get it’s equivalent on the grayscale, we would use the desaturate function like this:</p>
<pre class="brush: css; title: ; notranslate">
@borderColor:desaturate(@defaultThemeColor, 100%);
</pre>
<p>And we can even use the output of a color function as the input of another:</p>
<pre class="brush: css; title: ; notranslate">
@borderColor:darken(desaturate(@defaultThemeColor, 100%), 20%);
</pre>
<p>Which has the following result:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-7.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-7.png" alt="Less CSS - Color functions on shapes" title="Less CSS - Color functions on shapes" width="842" height="268" class="aligncenter size-full wp-image-90" /></a></p>
<p>All color operations take a color and a percentage as parameters, except spin, which uses integers between 0 and 255 instead of percentages to modify the hue:</p>
<pre class="brush: css; title: ; notranslate">
@defaultThemeColor:spin(@lightBlue, 100);
</pre>
<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-8.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-8.png" alt="Less CSS - Spin colors" title="Less CSS - Spin colors" width="834" height="269" class="aligncenter size-full wp-image-91" /></a></p>
<h2>Nested rules</h2>
<p>When designing a complex page using CSS, you often have to chain selectors to aim a particular element in the DOM, like this:</p>
<pre class="brush: css; title: ; notranslate">
#header h1{
}

#main h1{
}
</pre>
<p>Depending on the container of the <code>h1</code> elements, their style will be different if they’re in the <code>#header</code> or the <code>#main</code> section. This syntax is fine when you have a very simple DOM, but if you have to chain 4 or 5 selectors it gets messy and visually hard to represent the hierarchy of your styles. With Less you can nest rules inside parent rules to mimic the DOM structure:</p>
<pre class="brush: css; title: ; notranslate">
#header{
	/* #header styles */
	h1{
		/* #header h1 styles */
	}
}
</pre>
<p>This can be a little bit confusing at the beginning but when you get used to it, this syntax helps a lot to visualise where is located the element you’re working on.</p>
<p>There is also a super handy way to use pseudo-classes (you know, those special selectors like <code>:hover</code>). Let’s say we want to change our shapes’ color when hovering them with the mouse, we can use nested rules combined with the <code>&#038;</code> selector:</p>
<pre class="brush: css; title: ; notranslate">
.shape{
	&amp;:hover{
		background:@lightRed;
	}
}
</pre>
<p>This <code>&#038;</code> symbol represents the current selected elements. It’s the equivalent of “<code>this</code>” in most programming languages. Very convenient! And here is the result:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/10/less-css-9.png"><img src="http://verekia.com/wp-content/uploads/2011/10/less-css-9.png" alt="Less CSS - Hover on shapes" title="Less CSS - Hover on shapes" width="838" height="269" class="aligncenter size-full wp-image-94" /></a></p>
<p>Nested rules are pretty awesome, but there is a little drawback: since we use CSS syntax highlighting for our <code>*.less</code> files, many editors (including Eclipse) will go crazy and do some very bad syntax coloration with nested rules. If you can deal with broken syntax highlighting it will be fine, but for most of us, it’s really awful. The only thing we can do is wait for a proper plugin to bring a real Less support to our editors.</p>
<p>Personally, I only use nested rules for very simple one level nesting with few properties or for the <code>&#038;:hover</code> thing. But it really depends on you.</p>
<h2>Importing</h2>
<p>Finally, the last thing I wanted to show you is how to import Less files. It’s a very good practice to separate your rules into different files instead of having a 1000 lines giant file.</p>
<p>Importing a file into another in Less is as simple as that:</p>
<pre class="brush: css; title: ; notranslate">
@import “colors.less”;
</pre>
<p>You can even omit the .less extension and just declare:</p>
<pre class="brush: css; title: ; notranslate">
@import “colors”;
</pre>
<p>So depending on your project, you can split your files in a relevant way. Personally, I like having separate files for:</p>
<ul>
<li>CSS Reset or normalization,</li>
<li>Colors,</li>
<li>Fonts and typography,</li>
<li>UI Elements,</li>
<li>The main styles of the page,</li>
<li>&#8230;and any other relevant group of rules depending on your project.</li>
</ul>
<p>You can take a look at the very good Twitter Bootstrap <a href="https://github.com/twitter/bootstrap/tree/master/lib" target="_blank">Github repository</a> to see how those guys splitted up their files for a professional usage.</p>
<p>You may think that imports result in many unnecessary HTTP requests that will slow down the loading time of your page, and that’s true! But remember we’ll use the Less output as a new CSS. If we do so, we really don’t care about using multiple files, since at the end, everything will be concatenated into just one! So don’t be afraid of imports. They will really help you to structure your code.</p>
<h2>Final Less code</h2>
<p>Here is what the final code looks like (no import for such a little example):</p>
<pre class="brush: css; title: ; notranslate">
/**********************
       CONSTANTS
***********************/

@lightRed:   #fdd;
@lightGreen: #dfd;
@lightBlue:  #ddf;
@defaultShapesWidth:200px;
@defaultRadius:30px;

/*********************************
   OPERATIONS &amp; COLOR FUNCTIONS
**********************************/

@darkBlue: @lightBlue - #555;

@defaultThemeColor:@lightBlue;
//@defaultThemeColor:spin(@lightBlue, 100);

@borderSize:@defaultShapesWidth * 0.1;
@borderColor:@defaultThemeColor - #222; 
//@borderColor:darken(desaturate(@defaultThemeColor, 100%), 20%); 


/**********************
        MIXINS
***********************/

.RoundedShape(@radius:@defaultRadius){
	-webkit-border-radius:@radius;
	   -moz-border-radius:@radius;
	        border-radius:@radius;	
}

.Round{
	.RoundedShape(9999px);
}

.RoundedSquare(@radius:@defaultRadius){
	.RoundedShape(@radius);
}

/**********************
         STYLES
***********************/

.shape{
	display:inline-block;
	width:@defaultShapesWidth;
	height:200px;
	background:@defaultThemeColor;
	margin:20px;
	border:@borderSize solid @borderColor;
}

.shape{
	&amp;:hover{ background:@lightRed	}
}

#shape1{ .Round }
#shape2{ .RoundedSquare }
#shape3{ .RoundedSquare(60px) }
</pre>
<p>You will also notice that you can use single line comments, which is a very simple but clever addition to CSS!</p>
<p>And here is the <a href="http://verekia.com/demo/less-css/" target="_blank">demonstration of this Less CSS example</a>.</p>
<h2>Conclusion</h2>
<p>We’ve seen a lot of amazing features in this tutorial, and I hope it made you want to start using Less. I personally think Less is a real game changer for web development, and I cannot even consider going back to pure CSS. Less is like CSS5 in 2011!</p>
<p>There are still very interesting things I haven’t covered in this tutorial so if you’re interested in learning more about Less, you should definitely check the <a href="http://lesscss.org/" target="_blank">official documentation</a>. Oh and by the way, since Less is also open source and hosted on <a href="https://github.com/cloudhead/less.js" target="_blank">Github</a> you can easily get involved, report issues, or fork it. This <a href="http://verekia.com/less-css/dont-read-less-css-tutorial-highly-addictive#comment-275">great comment</a> also gives some very interesting tips you should be aware of.</p>
<p>That’s all folks! Thanks for reading and feel free to share your thoughts and previous experience about Less in the comments section. I’d love to know if you enjoy it as much as I do!</p>
]]></content:encoded>
			<wfw:commentRss>http://verekia.com/less-css/dont-read-less-css-tutorial-highly-addictive/feed</wfw:commentRss>
		<slash:comments>62</slash:comments>
		</item>
		<item>
		<title>An overview of developing Windows 8 apps with HTML, CSS and JavaScript</title>
		<link>http://verekia.com/windows8/overview-developing-windows-8-apps-html-css-javascript?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=overview-developing-windows-8-apps-html-css-javascript</link>
		<comments>http://verekia.com/windows8/overview-developing-windows-8-apps-html-css-javascript#comments</comments>
		<pubDate>Thu, 29 Sep 2011 22:15:02 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Tablet]]></category>
		<category><![CDATA[Visual Studio 11]]></category>
		<category><![CDATA[Web Developers]]></category>
		<category><![CDATA[Windows 8 App Store]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[Windows Developers Preview]]></category>
		<category><![CDATA[WinJS]]></category>
		<category><![CDATA[WinRT]]></category>

		<guid isPermaLink="false">http://verekia.com/?p=37</guid>
		<description><![CDATA[After almost one week spent at BUILD Windows 8 conference in Anaheim, it&#8217;s time to let you know what’s important for you as Web Developers! Windows 8 is the new major release of Windows announced earlier this year, with some &#8230; <a href="http://verekia.com/windows8/overview-developing-windows-8-apps-html-css-javascript">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://verekia.com/wp-content/uploads/2011/09/build-windows-8.png"><img src="http://verekia.com/wp-content/uploads/2011/09/build-windows-8.png" alt="Build Windows 8" title="Build Windows 8" width="584" height="191" class="aligncenter size-full wp-image-38" /></a></p>
<p>After almost one week spent at BUILD Windows 8 conference in Anaheim, it&#8217;s time to let you know what’s important for you as Web Developers!</p>
<p>Windows 8 is the new major release of Windows announced earlier this year, with some big surprising news: Windows 8 apps use HTML5. It wasn&#8217;t easy to imagine how this was made possible since the whole interface looks really native. Now the conference is over, it’s way clearer and I will try to summarize what have been announced and what will interest you as Web Developers.</p>
<p><span id="more-37"></span></p>
<p>Before I start, just a little disclaimer: I&#8217;m not a Microsoft fanboy. I&#8217;m a Web Developer, I love standards and Open Source, I&#8217;m not paid to write what follows and Steve Ballmer is not pointing any gun against my head! That being said, my opinion about Microsoft changed a lot during this conference, and you should really turn your &#8220;MS sucks&#8221; mode off as well while reading this article. Done? Alright let&#8217;s start!</p>
<h2>Let’s take the Metro</h2>
<p>So, few words about those Windows 8 apps: They are called &#8220;Metro-style&#8221; apps, and are actually really pleasant to use. They&#8217;re responsive, fluid, beautiful, they&#8217;re almost always using squares and rectangles, because it&#8217;s Windows 8 theme, which is great for having a nice alignment on the grid. They can access Windows APIs like the file picker, the camera, the accelerometer, etc., have their own native contextual menu and settings (Android style), and they will be available on a Windows 8 app store.</p>
<p>To summarize: they&#8217;re pretty cool, fluid and functional from the end user point of view.</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/09/windows-8-start-home-screen.png"><img src="http://verekia.com/wp-content/uploads/2011/09/windows-8-start-home-screen.png" alt="Windows 8 Start Home Screen" title="Windows 8 Start Home Screen" width="1600" height="900" class="aligncenter size-full wp-image-45" /></a></p>
<h2>From a Web Developer point of view</h2>
<h3>The language is up to you</h3>
<p>Windows 8 is built in a way you can choose to develop apps using 3 possible languages: C#, C++ and JavaScript. So MS fanboys and corporate developers will be able to continue using their stuff and will recycle their Silverlight skills, hardcore game coders can still use C, and us, Web 2.0 hippies can now write software with web standards. The 3 languages rely on the same WinRT (RunTime) layer, and have similar performances, so it&#8217;s really up to you to choose your favorite language. I will only talk about JavaScript on this blog however.</p>
<h3>The IDE is *not* up to you</h3>
<p>At this time, Microsoft&#8217;s Visual Studio is the only IDE to develop Windows 8 apps. Coming from the Open Source world and using mostly Eclipse, Intellij, Cloud9, and even Notepad++, I must admit that I had already enough different IDEs to deal with. But after I saw few folks at MS using it to code and run their Windows 8 apps super quickly I have to say that Visual Studio seems pretty powerful when you know it and I guess starting learning to use it is probably worth it. You (and I) should give it a chance.</p>
<p>Visual Studio 11 Developers Preview has some Windows 8 sample apps to do not start from scratch. Let&#8217;s see what we get when we create one of these sample apps:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/09/visual-studio-new-metro-style-app.png"><img src="http://verekia.com/wp-content/uploads/2011/09/visual-studio-new-metro-style-app.png" alt="New JavaScript Metro Style app for Windows 8 in Visual Studio 11" title="New JavaScript Metro Style app for Windows 8 in Visual Studio 11" width="1600" height="900" class="aligncenter size-full wp-image-42" /></a></p>
<h2>A closer look at the sample app</h2>
<p>Okay, so this is what we get when we run the generated new sample app:</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/09/windows-8-metro-style-app.png"><img src="http://verekia.com/wp-content/uploads/2011/09/windows-8-metro-style-app.png" alt="Windows 8 Metro Style App Sample" title="Windows 8 Metro Style App Sample" width="1600" height="900" class="aligncenter size-full wp-image-46" /></a></p>
<p>This app has navigation, a contextual menu, 2 sliding regions and behaves like a regular cool and touchy Metro-style app, so that’s a pretty good and representative starting point.</p>
<h3>HTML</h3>
<p>So we chose JavaScript. But JavaScript’s role is about behavior right? What about HTML and CSS? Well you will be nicely surprised to see that a Windows 8 JavaScript app is actually really 100% made of HTML/CSS/JavaScript. So, what’s under the hood of this sample app? Well, probably not what you expect. Here is the corresponding HTML page:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;title&gt;splitPage&lt;/title&gt;

    &lt;!-- WinJS references --&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;/winjs/css/ui-dark.css&quot; /&gt;
    &lt;script type=&quot;ms-deferred/javascript&quot; src=&quot;/winjs/js/base.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;ms-deferred/javascript&quot; src=&quot;/winjs/js/ui.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;ms-deferred/javascript&quot; src=&quot;/winjs/js/binding.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;ms-deferred/javascript&quot; src=&quot;/winjs/js/controls.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;ms-deferred/javascript&quot; src=&quot;/winjs/js/animations.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;ms-deferred/javascript&quot; src=&quot;/winjs/js/uicollections.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;ms-deferred/javascript&quot; src=&quot;/winjs/js/wwaapp.js&quot;&gt;&lt;/script&gt;
    
    &lt;link rel=&quot;stylesheet&quot; href=&quot;/css/default.css&quot; /&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;/css/splitPage.css&quot; /&gt;
    &lt;script type=&quot;ms-deferred/javascript&quot; src=&quot;/js/splitPage.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;!-- This template is used to display each item in the ListView declared below. --&gt;
    &lt;div class=&quot;itemTemplate&quot; data-win-control=&quot;WinJS.Binding.Template&quot;&gt;
        &lt;div class=&quot;largeIconTextTemplate&quot;&gt;
            &lt;div class=&quot;largeIconTextTemplateImage&quot; data-win-bind=&quot;style.backgroundColor: backgroundColor&quot;&gt;&lt;/div&gt;
            &lt;div class=&quot;largeIconTextTemplateBackground&quot;&gt;
                &lt;div class=&quot;largeIconTextTemplateLargeText win-itemTextStrong&quot; data-win-bind=&quot;textContent: title&quot;&gt;&lt;/div&gt;
                &lt;div class=&quot;largeIconTextTemplateSmallText win-itemTextTertiary&quot; data-win-bind=&quot;textContent: subtitle&quot;&gt;&lt;/div&gt;
                &lt;div class=&quot;largeIconTextTemplateMediumText win-itemText&quot; data-win-bind=&quot;textContent: description&quot;&gt;&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;!-- The content that will be loaded and displayed. --&gt;
    &lt;div class=&quot;splitPage fragment&quot;&gt;
        &lt;header role=&quot;banner&quot; aria-label=&quot;Header content&quot;&gt;
            &lt;button disabled class=&quot;win-backbutton&quot; aria-label=&quot;Back&quot;&gt;&lt;/button&gt;
            &lt;h1 class=&quot;pageTitle win-title&quot;&gt;&lt;/h1&gt;
        &lt;/header&gt;
        &lt;section class=&quot;itemListSection&quot;&gt;
            &lt;div class=&quot;itemList&quot;
                    data-win-control=&quot;WinJS.UI.ListView&quot; 
                    data-win-options=&quot;{dataSource: splitPage.items, oniteminvoked: splitPage.itemInvoked,  layout: {type: WinJS.UI.ListLayout}, selectionMode: 'none' }&quot;&gt;&lt;/div&gt;
        &lt;/section&gt;
        &lt;section class=&quot;articleSection&quot; aria-live=&quot;assertive&quot; aria-atomic=&quot;true&quot; aria-label=&quot;Item detail&quot;&gt;
            &lt;header class=&quot;header&quot;&gt;
                &lt;div class=&quot;image&quot; data-win-bind=&quot;style.backgroundColor: backgroundColor; style.backgroundImage: backgroundImage; alt: title&quot;&gt;&lt;/div&gt;
                &lt;div class=&quot;text&quot;&gt;
                    &lt;h1 class=&quot;title win-contentTitle&quot; data-win-bind=&quot;textContent: title&quot;&gt;&lt;/h1&gt;
                    &lt;h2 class=&quot;subtitle win-itemText&quot; data-win-bind=&quot;textContent: subtitle&quot;&gt;&lt;/h2&gt;
                    &lt;p class=&quot;description&quot; data-win-bind=&quot;textContent: description&quot;&gt;&lt;/p&gt;
                &lt;/div&gt;
            &lt;/header&gt;
            &lt;article class=&quot;content&quot; data-win-bind=&quot;innerHTML: content&quot;&gt;&lt;/article&gt;
        &lt;/section&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>It uses HTML5 elements, data- attributes, ARIA roles, everything <em>looks</em> pretty standard, but it’s radically different from a regular website. There are tons of proprietary stuff, even if it’s still HTML.</p>
<p>Disappointing right? Well at a first glance yes it is, but when you think about it, there is not many ways to do native apps with web technologies. Have you ever used jQuery Mobile? It’s more or less the same. Even a pure web browser-based experience like jQuery Mobile has those data- roles to declare the behavior of the app :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div data-role=&quot;content&quot;&gt;
  &lt;ul data-role=&quot;listview&quot; data-inset=&quot;true&quot; data-theme=&quot;c&quot; data-dividertheme=&quot;a&quot;&gt;
    &lt;li data-role=&quot;list-divider&quot;&gt;Transition Effects&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot; data-transition=&quot;slide&quot;&gt;Slide&lt;/a&gt;&lt;/li&gt;
</pre>
<p>So yes, it’s not really pure HTML anymore if you have to learn all these things. But it’s still way better than Objective-C right?</p>
<h3>CSS</h3>
<p>This extract of the CSS file is less surprising:</p>
<pre class="brush: css; title: ; notranslate">
.splitPage .itemList .largeIconTextTemplate {
    width: 100%;
    height: 100%;
    display: -ms-grid;
    -ms-grid-columns: 124px 12px 1fr;
    -ms-grid-rows: 1fr;
}

.splitPage .itemList .largeIconTextTemplateBackground {
    -ms-grid-column: 3;
    overflow: hidden;
}

@media screen and (-ms-view-state: snapped) {
.splitPage .win-contentTitle {
    font-size: 11pt;
    line-height: 15pt;
}

.splitPage {
    -ms-grid-columns: 320px 0px;
    -ms-grid-rows: 132px 1fr 0px;
}

.splitPage .itemListSection {
    margin-left: 4px;
}

.splitPage header[role=banner] {
    display: -ms-grid;
    -ms-grid-columns: 44px 1fr;
    -ms-grid-rows: 1fr;
}
</pre>
<p>You can see that Metro-style apps use specific media queries and Microsoft&#8217;s proposal for a CSS3 grid system. The rest is pretty common.</p>
<h3>JavaScript</h3>
<p>Here is the real business:</p>
<pre class="brush: jscript; title: ; notranslate">
(function () {
    'use strict';

    // Custom event raised after the fragment is appended to the DOM.
    WinJS.Application.addEventListener('fragmentappended', function handler(e) {
        if (e.location === '/html/splitPage.html') { fragmentLoad(e.fragment, e.state); }
    });

    function updateForLayout(lv, layout) {
        lv.layout = new WinJS.UI.ListLayout();
        lv.refresh();
    }

    function layoutChanged(e) {
        var list = document.querySelector('.itemList');
        if (list) {
            var lv = WinJS.UI.getControl(list);
            updateForLayout(lv, e.layout);
        }
    }

    function fragmentLoad(elements, options) {
        if (!WinJS.Navigation.canGoBack) {
            WinJS.Navigation.history.backStack[0] = { location: '/html/categoryPage.html' };
            var backButton = document.querySelector('header[role=banner] .win-backbutton');
            if (backButton) {
                backButton.removeAttribute('disabled');
            }
        }

        try {
            var appLayout = Windows.UI.ViewManagement.ApplicationLayout.getForCurrentView();
            if (appLayout) {
                appLayout.addEventListener('layoutchanged', layoutChanged);
            }
        } catch (e) { }

        splitPage.groups = pageData.groups;
        var group = (options &amp;&amp; 'group' in options) ? options.group : pageData.groups[0];
        splitPage.items = pageData.items.filter(function (item) { return item.group.key === group.key }),
        splitPage.selectedItem = splitPage.items[0];

        elements.querySelector('.pageTitle').textContent = group.title;

        WinJS.UI.processAll(elements)
            .then(function () {
                var lv = WinJS.UI.getControl(elements.querySelector('.itemList'));
                lv.itemRenderer = elements.querySelector('.itemTemplate');
                updateForLayout(lv, Windows.UI.ViewManagement.ApplicationLayout.value);

                var details = elements.querySelector('.articleSection');
                return WinJS.Binding.processAll(details, splitPage.selectedItem);
            });
    }

    function itemInvoked(e) {
        var details = document.querySelector('.articleSection');
        splitPage.selectedItem = splitPage.items[e.detail.itemIndex];
        WinJS.Binding.processAll(details, splitPage.selectedItem);
        details.scrollTop = 0;
    }

// [...]

    WinJS.Namespace.define('splitPage', {
        fragmentLoad: fragmentLoad,
        itemInvoked: itemInvoked
    });
})();
</pre>
<p>Honestly I’m too lazy to dive into this code since this article is just supposed to be an overview. However you can see that this file often refers to WinJS library and to the Windows object, which are used to access low-level WinRT calls. If you don’t want to access any Windows APIs like the device, the accelerometer and everything, you can omit using it and do pure JavaScript, or even use another lib like jQuery, it should work fine.</p>
<h2>Copy pasting your web app is a bad idea</h2>
<p>Some of you might think: “So if it’s all HTML, CSS and JavaScript, can I just copy and paste my whole website or web app and run it as a Windows 8 app?” Well, yes you could, but the user experience would really suck because you wouldn’t take any advantage of using the Windows RunTime environment. No native menus, no region scrolling and zooming, no access to the device APIs, no access to the filesystem, and the most important, no Metro-style look and feel.</p>
<h2>New platform = New market</h2>
<p>Consider Windows 8 as a whole new platform like iOS or Android, but this time using web standards (and this is a big deal!). You still have to do specific development for yet another platform, but at least you already know the language, so you won’t start from scratch, and that’s good news. The other good news is obviously that Windows 8 app market is currently absolutely empty. So guess what? You just have to be the first to develop some stupid flying explosive angry rabbits game to get freaking rich. Remember that it’s always way easier to be the first&#8230;</p>
<h2>Conclusion</h2>
<p>Even if developing for Windows 8 has some drawbacks for a typical standard-lover Web Developer like me, I must admit that I’m pretty impressed by Microsoft’s move with Windows 8. They’re Apple-style slogan at this conference was “Windows, reimagined”. Well that’s exactly what they did. They really invested a lot to make Windows 8 development accessible to the web developers community. Good job.</p>
<p>“Metro-style” apps are also actually really pleasant to use and they can honestly compete with Apple and Google in the tablets battle. If Web Developers get charmed by developing on this platform, it could even encourage competitors to embrace the same strategy and it could really be the start of a “native web” revolution. And as usual, if you’re here at the beginning of a revolution, there are tons of potentially profitable opportunities to jump on.</p>
<p>So, how do you feel about developing for Windows 8?</p>
]]></content:encoded>
			<wfw:commentRss>http://verekia.com/windows8/overview-developing-windows-8-apps-html-css-javascript/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Welcome to my new blog!</title>
		<link>http://verekia.com/california/welcome?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=welcome</link>
		<comments>http://verekia.com/california/welcome#comments</comments>
		<pubDate>Tue, 13 Sep 2011 14:33:56 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Californian Adventures]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[BUILD Windows 8]]></category>
		<category><![CDATA[HTML5 Boilerplate]]></category>
		<category><![CDATA[Initializr]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Verekia]]></category>

		<guid isPermaLink="false">http://verekia.com/?p=15</guid>
		<description><![CDATA[Hi there, welcome to my blog! I&#8217;m Jonathan Verrecchia, but good luck to remember how to spell my last name! So let&#8217;s keep it shorter and simpler with &#8220;Verekia&#8221;. I&#8217;m a 23 years old Parisian Front-End Web Developer, completely passionate &#8230; <a href="http://verekia.com/california/welcome">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Hi there, welcome to my blog!<br />
I&#8217;m Jonathan Verrecchia, but good luck to remember how to spell my last name! So let&#8217;s keep it shorter and simpler with &#8220;Verekia&#8221;.</p>
<p>I&#8217;m a 23 years old Parisian Front-End Web Developer, completely passionate about HTML, CSS and JavaScript. And believe it or not, I have a life too! I play music, like to party, travel as much as possible (oh, and by the way, I&#8217;m currently in a plane flying to Los Angeles, California right now, but more on that later).</p>
<p>Few notable things about me: I have a <a href="http://www.html5-css3.fr" title="HTML5-CSS3.fr" target="_blank">French blog about HTML5 and CSS3</a>, which led me to <a href="http://www.amazon.fr/HTML5-page-web-%C3%A0-lapplication/dp/2100565281" title="HTML5 : De la page web à l'application web" target="_blank">write a book</a> about HTML5 this year (it&#8217;s also in French, so good luck with that too!).</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/09/livre-html5.jpg"><img src="http://verekia.com/wp-content/uploads/2011/09/livre-html5.jpg" alt="My book about HTML5" title="My book about HTML5" width="279" height="400" class="aligncenter size-full wp-image-27" /></a></p>
<p>You might know me through another of my projects called <a href="http://initializr.com/" title="Initializr" target="_blank">Initializr</a>. It&#8217;s a tool to generate a new HTML5 project based on HTML5 Boilerplate super quickly, you should take a look! It became the official custom builder of Boilerplate, so you can consider me as a <a href="http://html5boilerplate.com/#footer" title="Contributors of HTML5 Boilerplate" target="_blank">contributor of HTML5 Boilerplate</a>, although I don&#8217;t work on the core content.</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/09/Initializr-Générateur-de-templates-HTML5-basé-sur-Boilerplate.png"><img src="http://verekia.com/wp-content/uploads/2011/09/Initializr-Générateur-de-templates-HTML5-basé-sur-Boilerplate.png" alt="Initializr - HTML5 templates generator" title="Initializr - HTML5 templates generator" width="600" height="285" class="aligncenter size-full wp-image-28" /></a></p>
<p>Anyways, because of some of these facts, Microsoft invited me to California to attend BUILD Windows 8 conference, which will deal with HTML5 in many ways. And that&#8217;s why I&#8217;m now on this plane! This major event is the perfect opportunity for me to start a new blog, in English this time, and keep you informed about what is being said at this 4 days conference.</p>
<p><a href="http://verekia.com/wp-content/uploads/2011/09/plane1.jpg"><img src="http://verekia.com/wp-content/uploads/2011/09/plane1.jpg" alt="A plane" title="A plane" width="584" height="389" class="aligncenter size-full wp-image-26" /></a></p>
<p>I will also post few updates about my Californian adventures since I will move to San Francisco next week, and will stay there for 2 months and a half. So I hope you will like this blog, if so, you can <a href="http://twitter.com/#!/verekia" title="Jonathan Verrecchia's Twitter page" target="_blank">follow me on Twitter</a> as well (no French spam, promise!).</p>
<p>Ciao ciao!</p>
]]></content:encoded>
			<wfw:commentRss>http://verekia.com/california/welcome/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.780 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-05-21 09:42:17 -->
<!-- Compression = gzip -->