<?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>Inspire Labs &#187; Javascript</title>
	<atom:link href="http://www.inspirelabs.co.uk/category/development/frontend/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.inspirelabs.co.uk</link>
	<description>Updates from Inspire Digital at IPC Media</description>
	<lastBuildDate>Wed, 05 Oct 2011 14:03:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>YUI3: My First Experience</title>
		<link>http://www.inspirelabs.co.uk/16/02/2010/yui3-my-first-experience/</link>
		<comments>http://www.inspirelabs.co.uk/16/02/2010/yui3-my-first-experience/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 09:29:55 +0000</pubDate>
		<dc:creator>Adam Pancutt</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=176</guid>
		<description><![CDATA[With the Yahoo! User Interface (YUI) javascript library now the library of choice at IPC I thought it was about time to start playing with it. Background to Javascript Frameworks My first experience of a javascript library was to build a debug console for my framework. Version one of the console was built in jQuery [...]]]></description>
			<content:encoded><![CDATA[<p>With the Yahoo! User Interface (YUI) javascript library now the library of choice at IPC I thought it was about time to start playing with it.</p>
<h2>Background to Javascript Frameworks</h2>
<p>My first experience of a javascript <em>library </em>was to build a debug console for <a href="http://framework.pixelinx.co.uk" target="_blank">my framework</a>. Version one of the console was built in jQuery (v1.2, I think). I liked it. I liked how you no longer needed to repeat the same cross-browser checks every time you built something new; how effects were easy to acheive without having to create your own; chaining. Most importantly, though, I liked how the library made the development experience a little more unified.</p>
<h2>First Taste of YUI</h2>
<p>A few months later I decided to migrate the jQuery console to <a href="http://developer.yahoo.com/yui/2/" target="_blank">YUI2</a>. I quickly found that the <a href="http://developer.yahoo.com/yui/docs/" target="_blank">documentation</a> was not brilliant for new-comers (and still isn&#8217;t). My migration, although worked, was not how YUI2 intended a widget to be built. Overall, it took me a lot longer to learn YUI2 than jQuery and I put this mostly down to the documentation (<a href="http://api.jquery.com/" target="_blank">jQuery API docs</a> are brilliant) though also because jQuery tutorials are abundant as are community plugins which you can rip apart to assist your learning.</p>
<h2>Upgrading to YUI3</h2>
<p>Last week I decided to have a go at upgrading the console to <a href="http://developer.yahoo.com/yui/3/" target="_blank">YUI3</a>. Once again, the <a href="http://developer.yahoo.com/yui/3/api/" target="_blank">documentation</a> was pretty poor for new-comers but at least this time at least I had a foundation to work with. This time I wanted to do things right. I wanted to extend the YUI Widget class and do things how YUI wanted me to do things. Just a week later, it&#8217;s done.</p>
<h2>Benefits of YUI3</h2>
<p>I couldn&#8217;t give you a fair comparison between jQuery and YUI, or advise you on which is the best for your project, as I&#8217;ve not kept up with the progress of jQuery. However, I&#8217;m happy YUI is the IPC standard as it&#8217;s something I&#8217;ve had a lot of fun learning and playing with.</p>
<p>Key components of YUI3 that I&#8217;ve come to love are:</p>
<ul>
<li><a href="http://developer.yahoo.com/yui/3/yui/#loader" target="_blank">Loader</a></li>
<li><a href="http://developer.yahoo.com/yui/3/widget/" target="_blank">Widget</a></li>
<li><a href="http://developer.yahoo.com/yui/3/attribute/" target="_blank">Attribute</a></li>
<li><a href="http://developer.yahoo.com/yui/3/event/" target="_blank">Event</a></li>
<li><a href="http://developer.yahoo.com/yui/3/node/">Node</a>, specifically their consideration for <a href="http://developer.yahoo.com/yui/3/node/#node-aria">WAI-ARIA</a> support and <a href="http://developer.yahoo.com/yui/3/node/#node-query">Node Queries/CSS3 Selectors</a></li>
</ul>
<p>Next, to get the most out of YUI3, I need to look into:</p>
<ol>
<li><a href="http://developer.yahoo.com/yui/3/profiler/" target="_blank">Profiler</a></li>
<li><a href="http://developer.yahoo.com/yui/3/test/" target="_blank">Test</a></li>
<li>&#8230;and the other many utilities available</li>
</ol>
<h2>Summary</h2>
<p>In summary, once you&#8217;ve grasped YUI and put together your first widget you&#8217;ll feel like you&#8217;ve acheived something a lot more pure, legible and stable than you do with jQuery. Or at least I do.</p>
<h2>More to Come</h2>
<p>Over the next few days I hope to put together some tutorials to assist people with their first YUI widget. It&#8217;s been a struggle for me to find the help I needed so, hopefully, I can help a few of you out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/16/02/2010/yui3-my-first-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YUI errorLogging</title>
		<link>http://www.inspirelabs.co.uk/23/07/2009/yui-errorlogging/</link>
		<comments>http://www.inspirelabs.co.uk/23/07/2009/yui-errorlogging/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 11:04:17 +0000</pubDate>
		<dc:creator>John Wright</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=122</guid>
		<description><![CDATA[As we have decided to start using the YUI javascript framework, I rewrote the logging tool I did for jQuery. I understand there&#8217;s already a logging tool for YUI, but if you don&#8217;t want to initiate the logger, here&#8217;s a quick fix: YAHOO.namespace&#40;'IPC'&#41;; &#160; &#40;function&#40;Y&#41; &#123; &#160; var Log = &#123; debug : function&#40;message&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>As we have decided to start using the YUI javascript framework, I rewrote the <a href="http://inspirelabs.co.uk/14/05/2009/jquery-error-logging/">logging tool I did for jQuery</a>.</p>
<p>I understand there&#8217;s already a logging tool for YUI, but if you don&#8217;t want to initiate the logger, here&#8217;s a quick fix:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'IPC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>Y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> Log <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		debug <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				console.<span style="color: #660066;">debug</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Debug Message: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		info <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				console.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Info: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		warn <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				console.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;WARNING: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		error <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;boolean&quot;</span><span style="color: #339933;">:</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">:</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;string&quot;</span><span style="color: #339933;">:</span>
						console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">:</span>
						console.<span style="color: #660066;">group</span><span style="color: #009900;">&#40;</span>e.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							console.<span style="color: #660066;">dir</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
						<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							console.<span style="color: #660066;">dirxml</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
						console.<span style="color: #660066;">trace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						console.<span style="color: #660066;">groupEnd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
						Y.<span style="color: #660066;">IPC</span>.<span style="color: #660066;">Log</span>.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Problem logging error. Unknown error type: '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span> e <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> message <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;FATAL ERROR!: &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;boolean&quot;</span><span style="color: #339933;">:</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">:</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;string&quot;</span><span style="color: #339933;">:</span>
						<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">:</span>
						<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
						Y.<span style="color: #660066;">IPC</span>.<span style="color: #660066;">Log</span>.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Problem logging error. Unknown error type: '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span> e <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		throwError <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		    <span style="color: #003366; font-weight: bold;">var</span> error <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				error.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> info.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				error.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Error'</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span>
&nbsp;
		    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				error.<span style="color: #660066;">object</span> <span style="color: #339933;">=</span> info.<span style="color: #660066;">object</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span>
&nbsp;
		    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				error.<span style="color: #660066;">xml</span> <span style="color: #339933;">=</span> info.<span style="color: #660066;">xml</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span>
&nbsp;
		    <span style="color: #000066; font-weight: bold;">throw</span> error<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	Y.<span style="color: #660066;">IPC</span>.<span style="color: #660066;">Log</span> <span style="color: #339933;">=</span> Log<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>YAHOO<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You&#8217;d use it in the same way as before, either a separate method in your object, use one of the logging methods directly, or use the throw method directly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/23/07/2009/yui-errorlogging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript frameworks</title>
		<link>http://www.inspirelabs.co.uk/14/05/2009/javascript-frameworks/</link>
		<comments>http://www.inspirelabs.co.uk/14/05/2009/javascript-frameworks/#comments</comments>
		<pubDate>Thu, 14 May 2009 21:55:43 +0000</pubDate>
		<dc:creator>John Wright</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=69</guid>
		<description><![CDATA[We've been looking around at what's available and what we think could possibly suit exemplar best.]]></description>
			<content:encoded><![CDATA[<p>So&#8230;. exemplar (our beloved &#8216;master&#8217; site) is built on symfony (take it or leave it) which has inbuilt helpers and functions using the prototype/scriptaculous framework. It&#8217;s not necessary to use this, however at the time it was probably considered the best javascript solution and therefore was used in development. A couple of years down the line, and we realise that there&#8217;s better stuff around, and our current library is a little on the messy side. Time for a re-vamp <img src='http://www.inspirelabs.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>We&#8217;ve been looking around at what&#8217;s available and what we think could possibly suit exemplar best. We&#8217;re looking for:</p>
<ul>
<li>simplicity</li>
<li>extensibility</li>
<li>good performance</li>
</ul>
<p>I can&#8217;t see any of us wanting to build our own framework when there are so many good ones around, so that&#8217;s out of the question. So I guess the real competitors are:</p>
<ul>
<li><a href="http://script.aculo.us/" target="_blank">Scriptaculous</a></li>
<li><a href="http://jquery.com/" target="_blank">jQuery</a></li>
<li><a href="http://mootools.net/" target="_blank">Mootools</a></li>
<li><a href="http://developer.yahoo.com/yui/" target="_blank">YUI</a></li>
<li><a href="http://www.dojotoolkit.org/" target="_blank">Dojo</a></li>
</ul>
<p>I&#8217;ve personally looked at the 1st 3 in depth and wish to look at the last 2 aswell before making any proposal. So far I feel that once you&#8217;ve got to grips with any of them, they become very natural and easy to use.<span id="more-69"></span></p>
<p>The <span style="color: #000000;">prototype framework</span> was the first JavaScript framework I had ever used and was immediately impressed. The syntax is lovely and especially coming from a OO background, being able to create patterns and separate your code into classes and objects was a real relief and most of our work is already using this framework, we could simply revisit it. However, it is slow&#8230; real slow. When creating a mass of libraries the page load gets very heavy. I also found that some things didn&#8217;t seem consistent, and doing small tasks could take quite a while.</p>
<p>Next, I moved onto Mootools. It&#8217;s a very, very sweet framework. It felt like someone got hold of prototype, pulled it apart, tore out all the unnecessary bits and put it together again. It&#8217;s solid, really quick and the syntax is very familiar to prototype. I was originally introduced to it by our favourite French man Fabien about a year ago, but it&#8217;s lame website didn&#8217;t sell it to me. Now that I&#8217;ve actually used it I can&#8217;t see why this wouldn&#8217;t be a good one to choose, other than there isn&#8217;t a much of a community yet. This also means, less developers are going to know it. If we were to get another developer on board, there&#8217;s a small chance they will know how to use it.</p>
<p>Next, the mother, jQuery. Syntactically, totally different to the other 2, but it can live up to it&#8217;s name. It feels a bit strange to use after coming from the OO style frameworks, but it&#8217;s very, very simple. It&#8217;s so simple in fact, I felt like I was cheating. There&#8217;s no way that it would ever get confusing bouncing code from one developer to another and it&#8217;s real simple to pick up. The community is pretty large and a lot of people swear by it. Although the other two are good competitors and I wouldn&#8217;t mind using any, for IPC, I feel jQuery is the right move.</p>
<p>(So far anyway. To be continued&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/14/05/2009/javascript-frameworks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery error logging</title>
		<link>http://www.inspirelabs.co.uk/14/05/2009/jquery-error-logging/</link>
		<comments>http://www.inspirelabs.co.uk/14/05/2009/jquery-error-logging/#comments</comments>
		<pubDate>Thu, 14 May 2009 17:29:07 +0000</pubDate>
		<dc:creator>John Wright</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://inspirelabs.co.uk/?p=64</guid>
		<description><![CDATA[As I may very well be doing alot of development in jQuery in the up and coming future, I decided to start by writing an exception throwing and logging plugin.]]></description>
			<content:encoded><![CDATA[<p>As I may be doing alot of development in jQuery in the up and coming future, I decided to start by writing an exception throwing and logging plugin.</p>
<p>Here&#8217;s where I am so far, I&#8217;ve created an error throwing plugin which will take several parameters; <em>an exception name, a message and a number of debugging objects</em> (like a XML object or a JavaScript object).</p>
<p>You would use it like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">throwError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">name</span>    <span style="color: #339933;">:</span> <span style="color: #3366CC;">'MyException'</span><span style="color: #339933;">,</span>
  message <span style="color: #339933;">:</span> <span style="color: #3366CC;">'You simply can<span style="color: #000099; font-weight: bold;">\'</span>t do that!'</span><span style="color: #339933;">,</span>
  object  <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  xml     <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mungElement'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&#8230;or&#8230; it would be better to have a method for each plugin to create the above:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> handleError <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #339933;">,</span> debugInfo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> error <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">name</span>    <span style="color: #339933;">:</span> <span style="color: #3366CC;">'MyPluginError'</span><span style="color: #339933;">,</span>
    message <span style="color: #339933;">:</span> message
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  error <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>error<span style="color: #339933;">,</span> debugInfo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $.<span style="color: #660066;">throwError</span><span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>thisWillWork<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  handleError<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'You simply can<span style="color: #000099; font-weight: bold;">\'</span>t do that!'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>xml<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, I have a logging plugin which can be used for catching these errors:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ticker'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ticker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The &#8216;$.log.error&#8217; method checks if a &#8216;console&#8217; is available and then records the error as a traced exception with the given debug objects displayed. If the console is not available, it will then use the alert function.</p>
<p><em>I intend on extending this functionality so that the error will be displayed in a nicely formatted popup (if the console isn&#8217;t available). </em></p>
<p>Obviously we don&#8217;t want this to be displayed on production so another feature will be to separate environments. Does anyone have any suggestions on how to do this? I was thinking putting another query string on the URL, for instance: http://mysite.com/mung.html?_js_dev=1</p>
<p><em>Source code for the plugins:</em><br />
<span id="more-64"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">log</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">debug</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">debug</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Debug Message: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">info</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Info: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">warn</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;WARNING: &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">log</span>.<span style="color: #660066;">error</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;boolean&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;string&quot;</span><span style="color: #339933;">:</span>
          console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">:</span>
          console.<span style="color: #660066;">group</span><span style="color: #009900;">&#40;</span>e.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            console.<span style="color: #660066;">dir</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            console.<span style="color: #660066;">dirxml</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          console.<span style="color: #660066;">trace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          console.<span style="color: #660066;">groupEnd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
          $.<span style="color: #660066;">log</span>.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Problem logging error. Unknown error type: '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span> e <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> message <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;FATAL ERROR!: &quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;boolean&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;string&quot;</span><span style="color: #339933;">:</span>
          <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">:</span>
          <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
          $.<span style="color: #660066;">log</span>.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Problem logging error. Unknown error type: '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span> e <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message <span style="color: #339933;">+</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">throwError</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> error <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      error.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> info.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      error.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Error'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      error.<span style="color: #660066;">object</span> <span style="color: #339933;">=</span> info.<span style="color: #660066;">object</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      error.<span style="color: #660066;">xml</span> <span style="color: #339933;">=</span> info.<span style="color: #660066;">xml</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">throw</span> error<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.inspirelabs.co.uk/14/05/2009/jquery-error-logging/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

