<?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>James Padolsey&#187; Usability category &#8211; James Padolsey</title>
	<atom:link href="http://james.padolsey.com/category/usability/feed/" rel="self" type="application/rss+xml" />
	<link>http://james.padolsey.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 21 Aug 2010 04:38:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript is the icing!</title>
		<link>http://james.padolsey.com/javascript/javascript-is-the-icing/</link>
		<comments>http://james.padolsey.com/javascript/javascript-is-the-icing/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:56:40 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=1226</guid>
		<description><![CDATA[I am a strong proponent of layered cakes. I don&#8217;t know how to handle a cake that is just mashed together with many ingredients and shoved in the oven &#8212; I just end up staring at it, wondering how the hell I&#8217;m meant to consume&#8230;]]></description>
			<content:encoded><![CDATA[<p>I am a strong proponent of layered cakes. I don&#8217;t know how to handle a cake that is just mashed together with many ingredients and shoved in the oven &#8212; I just end up staring at it, wondering how the hell I&#8217;m meant to consume this thing! I prefer to have clearly defined layers, each with a unique palette that, when combined with the other layers adds to the overall symphony of taste.</p>

<p>Of course, I&#8217;m not actually talking about bakery; I&#8217;m talking about the web, and the many layers that it&#8217;s made of. I believe that maintaining separate layers is the best way to move forward whilst offering a usable, functional and accessible web. </p>

<p>I think JavaScript is an afterthought, and I think it&#8217;s best for everyone if it&#8217;s treated that way. Once you try mixing it into your application you&#8217;ll eventually encounter a conflict of layers! <em>A.K.A pissed off users.</em></p>

<p>I&#8217;m not just talking about being unobtrusive; I&#8217;m talking about <em>true</em> progressive enhancement, and <em>true</em> separation of concerns, on the server side <em>and</em> on the client side. I appreciate and try to develop by this ideal, because I honestly feel that it is the best way to develop any website or any application.</p>

<p>It&#8217;s not just about the end-user experience though; it&#8217;s about developing in a way that makes sense. For me, this makes sense.</p>

<p>For me, until I change my mind, JavaScript will always be the icing on the cake!</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/javascript-is-the-icing/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Table rows as clickable anchors</title>
		<link>http://james.padolsey.com/javascript/table-rows-as-clickable-anchors/</link>
		<comments>http://james.padolsey.com/javascript/table-rows-as-clickable-anchors/#comments</comments>
		<pubDate>Mon, 25 May 2009 18:24:57 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=853</guid>
		<description><![CDATA[Recently a question was posed on StackOverflow.com that sparked my interest. You can <a href="http://stackoverflow.com/questions/890743/click-entire-row-preserving-middle-click-and-ctrlclick">head over there</a> to read it yourself. The original poster wanted to know how to make an entire table row (<code>&#60;tr&#62;</code>) clickable, like a link. This is fairly easy if you&#8217;re only after&#8230;]]></description>
			<content:encoded><![CDATA[<p>Recently a question was posed on StackOverflow.com that sparked my interest. You can <a href="http://stackoverflow.com/questions/890743/click-entire-row-preserving-middle-click-and-ctrlclick">head over there</a> to read it yourself. The original poster wanted to know how to make an entire table row (<code>&lt;tr&gt;</code>) clickable, like a link. This is fairly easy if you&#8217;re only after the very redimentary link functionality: it only requires you to register a click handler which will change the location to anything you desire.</p>

<p>An example of this:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="st0">'tr'</span><span class="br0">&#41;</span>.<span class="me1">bind</span><span class="br0">&#40;</span><span class="st0">'click'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
    window.<span class="me1">location</span> <span class="sy0">=</span> <span class="st0">'http://somelocation.com'</span><span class="sy0">;</span>
    <span class="co1">// Or, we can grab the HREF from the first anchor:</span>
    <span class="co1">// window.location = $('a:first', this).attr('href');</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>




<p>This might be deemed suitable by most but, truth be told, it&#8217;s an almost pointless enhancement. The same is true for any attempted link simulations. For example, having a DIV element and making it re-locate the page upon a click. Doing this is pointless because it&#8217;s not a real link! Browsers offer a bunch of behavioural enhancements to anchors, for example:</p>

<ul>
    <li>Middle-click: Page opens in new tab.</li>
    <li>CTRL/SHIFT click: Page opens in new window/tab.</li>
    <li>Right-click options: &#8220;open in new window&#8221;, &#8220;copy link location&#8221; etc.</li>
    <li>Status message is changed to the HREF of the anchor.</li>
    <li>etc&#8230;</li>
</ul>

<p>It&#8217;s impossible to simulate all of the above. Users are left confused and sometimes annoyed when an element doesn&#8217;t act like it&#8217;s supposed to&#8230;</p>

<p>There are no <em>rules</em> that state that table rows or DIV elements cannot be clickable but if you&#8217;re going to do so then it&#8217;s important to preserve what functionality is expected from anchors. Of course, most users don&#8217;t think of them as &#8220;anchors&#8221;; they&#8217;re just links to other pages, but even so, users have a set of unwritten expectations which dictate how websites should behave.</p>

<p>In other words, if you&#8217;re going to make an element function like an anchor then it <em>must</em> be an entirely accurate emulation.</p>

<span id="more-853"></span>

<p>So I thought, instead of trying to simulate the expected functionality I could instead simply create an absolutely positioned anchor that moved with the cursor; this anchor would only be activated when the corresponding table row was being hovered. And since it&#8217;s a real anchor, all expected functionality is present, including those behavioural enhancement offers by the browser. This is the answer I originally posted on the thread at Stack Overflow.</p>

<p>Then I had another thought; instead of having to update the anchor&#8217;s position whenever the document&#8217;s <code>mousemove</code> event triggered, I could just keep it statically hovering over the table row; like a blanket.</p>

<p>I decided to create a jQuery plugin utilizing the above technique:</p>

<ul>
    <li><strong><a href="http://james.padolsey.com/demos/plugins/jQuery/superLink/superlink.jquery.js/view">See the code!</a></strong></li>
    <li><strong><a href="http://james.padolsey.com/demos/plugins/jQuery/superLink">See the demo!</a></strong></li>
</ul>

<p>It works on any element that contains a link. The plugin takes one argument; the selector to target the link within the container, which, by default, is &#8216;a:first&#8217;.</p>

<p>Note: If you plan on binding <code>mouseover</code>/<code>mouseout</code> events on the same element that the plugin is running on then make sure to bind both events BEFORE calling the plugin. Also, <strong>don&#8217;t use <code>mouseenter</code>/<code>mouseleave</code> events</strong> &#8211; the <code>mouseleave</code> event won&#8217;t occur as expected because of the anchor overlay.</p>

<p>Using the plugin is dead simple; say, for example, you have a table with multiple rows; each row has an anchor within the last cell <code>&lt;td&gt;</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="st0">'table#mytable tr'</span><span class="br0">&#41;</span>.<span class="me1">superLink</span><span class="br0">&#40;</span><span class="st0">'a:last'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>




<p>Now every row will seem like one giant anchor to the user!</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/table-rows-as-clickable-anchors/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Readability, a noble cause</title>
		<link>http://james.padolsey.com/javascript/readability-a-noble-cause/</link>
		<comments>http://james.padolsey.com/javascript/readability-a-noble-cause/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 01:46:36 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Readability]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=728</guid>
		<description><![CDATA[According to a <a href="#">recently completed report</a> commissioned by the Web Standards Authority, the majority of popular websites do not reach the desired readability standards. Contrast, colour, sizing, positioning and other various aspects all have an effect on the readability of your site. Readability itself is of&#8230;]]></description>
			<content:encoded><![CDATA[<p>According to a <a href="#">recently completed report</a> commissioned by the Web Standards Authority, the majority of popular websites do not reach the desired readability standards. Contrast, colour, sizing, positioning and other various aspects all have an effect on the readability of your site. Readability itself is of central importance; without it your message is lost!</p>

<p>As per the details digressed in the mentioned report I have created a jQuery plugin which deals with this issue. By implementing the following enhancements, the plugin ensures your users a visit worth remembering!</p>

<ul>
    <li>Continuously varying textual colour makes words easier to focus on while progressing through any particular sentence.</li>
    <li>In addition, constantly changing background colours ensure the necessary inconsistency when reading text. As mentioned in the report, contrast is of central importance, &#8211; this is integrated into the plugin.</li>
    <li>Whenever a word is hovered over, the report states that the user must be looking for a deeper meaning &#8211; to fulfill this need the word in question is subtly re-sized.</li>
</ul>

<p>You can experience a fully working demo over here. If you are epileptic please don&#8217;t visit this link: <strong><a href="/demos/plugins/jQuery/readability/">THE DEMONSTRATION</a></strong></p>

<p>This plugin is very easy to integrate. Just call the &#8220;readability&#8221; plugin like so:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span class="me1">rEaDaBiLiTy</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>




<p>Once initiated the plugin will automatically enhance the page in the ways mentioned.</p>

<p>Readability isn&#8217;t something to be taken lightly, it&#8217;s a serious issue and has been known to have widespread lethal affects across the globe. Web designers and developers have advanced recently in this area but the job isn&#8217;t yet done; we have to push for absolute readability. This plugin is only a tool, a tool to enable the world to get that one step closer to an entirely readable internet!</p>

<p>Please consider donating as I had to scour the entire WSA&#8217;s report just to uncover the key to readability. The plugin took a considerable amount of time to develop; throughout its creation I continually became parched and/or hungry so please consider buying me whatever you can afford (i.e. <a href="http://www.amazon.com/Apple-Cinema-30-inch-Flat-Panel-Display/dp/B0002ILKWM">this</a>). Thank you for supporting me!</p>

<p><strong>UPDATE: APRIL FOOLS!!!</strong></p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/readability-a-noble-cause/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t use &#8220;!important&#8221;</title>
		<link>http://james.padolsey.com/usability/dont-use-important/</link>
		<comments>http://james.padolsey.com/usability/dont-use-important/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 08:37:47 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Specificity]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=676</guid>
		<description><![CDATA[In CSS, the &#8220;!important&#8221; suffix was originally intended to provide a method of overriding author stylesheets. Users could define their own &#8220;user stylesheets&#8221; and could use this suffix to give their rules precedence over the author&#8217;s (website creator&#8217;s) styles.

Unfortunately, and quite predictably, its usage&#8230;]]></description>
			<content:encoded><![CDATA[<p>In CSS, the &#8220;!important&#8221; suffix was originally intended to provide a method of overriding author stylesheets. Users could define their own &#8220;user stylesheets&#8221; and could use this suffix to give their rules precedence over the author&#8217;s (website creator&#8217;s) styles.</p>

<p>Unfortunately, and quite predictably, its usage has spread massively, but not in the right direction. Nowadays, it&#8217;s used to counteract the pain of having to deal with CSS specificity, otherwise known as the set of rules which dictate that &#8220;div h1 a&#8221; is more specific selector than &#8220;div a&#8221;. Most people that use CSS on a daily basis don&#8217;t know enough about CSS specificity to solve their problems without using the &#8220;!important&#8221; suffix.</p>

<p>For reference, &#8220;specificity&#8221; is the name given to signify the precedence of a particular CSS selector. Here&#8217;s a quick rundown:</p>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span class="sy0">*</span>             <span class="br0">&#123;</span><span class="br0">&#125;</span>  <span class="coMULTI">/* a=0 b=0 c=0 -&gt; specificity =   0 */</span>
LI            <span class="br0">&#123;</span><span class="br0">&#125;</span>  <span class="coMULTI">/* a=0 b=0 c=1 -&gt; specificity =   1 */</span>
UL LI         <span class="br0">&#123;</span><span class="br0">&#125;</span>  <span class="coMULTI">/* a=0 b=0 c=2 -&gt; specificity =   2 */</span>
UL OL<span class="sy0">+</span>LI      <span class="br0">&#123;</span><span class="br0">&#125;</span>  <span class="coMULTI">/* a=0 b=0 c=3 -&gt; specificity =   3 */</span>
H1 <span class="sy0">+</span> <span class="sy0">*</span><span class="br0">&#91;</span>REL<span class="sy0">=</span>up<span class="br0">&#93;</span><span class="br0">&#123;</span><span class="br0">&#125;</span>  <span class="coMULTI">/* a=0 b=1 c=1 -&gt; specificity =  11 */</span>
UL OL LI<span class="re1">.red</span>  <span class="br0">&#123;</span><span class="br0">&#125;</span>  <span class="coMULTI">/* a=0 b=1 c=3 -&gt; specificity =  13 */</span> 
LI<span class="re1">.red</span><span class="re1">.level</span>  <span class="br0">&#123;</span><span class="br0">&#125;</span>  <span class="coMULTI">/* a=0 b=2 c=1 -&gt; specificity =  21 */</span>
<span class="re0">#x34y</span>         <span class="br0">&#123;</span><span class="br0">&#125;</span>  <span class="coMULTI">/* a=1 b=0 c=0 -&gt; specificity = 100 */</span>
&nbsp;
<span class="coMULTI">/* Source: http://www.w3.org/TR/CSS2/cascade.html */</span></pre></div></div>




<p>The specificity is calculated as follows:</p>

<ul>
    <li>count the number of ID attributes in the selector (= a)</li>
    <li>count the number of other attributes and pseudo-classes in the selector (= b)</li>
    <li>count the number of element names in the selector (= c)</li>
    <li>ignore pseudo-elements. </li>
</ul>

<p>(read more about it: <a href="http://www.w3.org/TR/CSS2/cascade.html#important-rules">http://www.w3.org/TR/CSS2/cascade.html#important-rules</a>)</p>
    


<p>The power of CSS and its cascading nature, in my opinion, is only fully appreciated when one understands specificity. A lack of understanding only leads to bad practices, such as using the &#8220;!important&#8221; suffix. Of course, it&#8217;s not always a bad idea, sometimes it&#8217;s necessary; for example, the Google toolbar in browsers always insists on colouring certain input fields yellow to signify that an &#8216;autocomplete&#8217; feature is available. To be blunt, this can make your design look crap! The only way to counteract this is to define an &#8220;!important&#8221; style, i.e. the only thing more specific than inline styles.</p>

<p>Apart from a few edge cases its use is, in my opinion, unfounded and mostly unnecessary. Not to mention the fact of how annoying it is for a user when they want to apply their own styles or enhancements; you better have a damn good reason for relinquishing such a rudimentary level of control!</p>

<p>The only thing that can override an &#8220;!important&#8221; rule is <em>another</em> one, which must be specified lower down and its selector must have the same (or a higher) level of specificity. You can also specify &#8220;!important&#8221; styles inline. Another method would be to remove the rule entirely, this can be achieved with JavaScript, by accessing and manually removing the rule in question: <a href="http://dev.opera.com/articles/view/dynamic-style-css-javascript/#addingandremovingrules">http://dev.opera.com/articles/view/dynamic-style-css-javascript/#addingandremovingrules</a>.</p>

<p>Even though there are solutions, it is still a massive pain for users, so please, don&#8217;t use &#8220;!important&#8221; unless you have no other option!</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/usability/dont-use-important/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Usability &amp; Animation</title>
		<link>http://james.padolsey.com/javascript/usability-animation/</link>
		<comments>http://james.padolsey.com/javascript/usability-animation/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 18:09:15 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=597</guid>
		<description><![CDATA[Animation is normally seen as a very good quality, whether it be on a screen or in real life; all it&#8217;s connotations are positive. The days of wonderment and delight will soon be history though, that is, if people don&#8217;t start to realise that, like&#8230;]]></description>
			<content:encoded><![CDATA[<p>Animation is normally seen as a very good quality, whether it be on a screen or in real life; all it&#8217;s connotations are positive. The days of wonderment and delight will soon be history though, that is, if people don&#8217;t start to realise that, like everything, you can have too much of a good thing.</p>

<p>When is too much? &#8230;</p>

<h2>Story time&#8230;</h2>

<p>I recently was revising for an upcoming driving theory examination. To revise I was issued with a piece of software containing various mock tests and the Highway Code. The only thing wrong with the entire application was the damn navigation. Every time I returned to the top-most level of a topic area it took about 5 seconds (yes, that is a long time) for the menu to animate on to the screen. The most useful menu-item happened to be at the bottom of the menu and so every single time I wanted to click it I had to wait 5 whole seconds after arriving on the page! </p>

<p>A couple of years ago I would&#8217;ve really appreciated a slowly cascading menu but nowadays it&#8217;s just incredibly annoying because I have to wait until the very end of an entire animation until I have full access.</p>

<p>You know what the real problem is? It&#8217;s some over-zealous programmer or designer who thought it would be cool to have something whizzing or popping on to the page. If it&#8217;s not them then it&#8217;s their managers or perhaps it was the bloody client!</p>

<p>And that&#8217;s not the only time the obvious over-zealousness of a &#8220;professional&#8221; has pissed me off: To aid me further in my driving theory preparation I decided to purchase (and not cheaply, I might add) an application for my iPod Touch which also contained mock tests and the Highway Code. After testing it out for the first time I was quite satisfied. But again, because of some crappy developer, the software frequently screwed up on itself because of an intentional feature. The hotshot app developer thought it would be cool to add a &#8217;shake&#8217; feature so when a user reaches a question in one of the mock tests they have the option to skip it by shaking the device.</p>

<p>I had previously read about this feature in the iTunes store; I thought nothing of it at the time. It was only when sitting in the back of a car, being driven at a regular speed, trying out a mock test that the app suddenly skipped three questions in a row. The app offers no way to go back a question so that really sucked! I mean come on! What the **** is the point in adding a &#8217;shake&#8217; feature? It&#8217;s one of those, &#8220;I&#8217;ll add this feature to show how cool a developer I am&#8221; &#8211; normally I&#8217;m actually okay when people show off, but when it effects the usability or usefulness of a product it&#8217;s simply not acceptable!</p>

<p>Now, what does that last story have to do with animation? Well, that idiot developer thought it would be cool and obviously didn&#8217;t think much past that. It would be nice if people would consider coolness as a lesser priority than something like usability. </p>

<h2>So&#8230;</h2>

<p>When you&#8217;re thinking of adding any animation to anything on a website, even if you&#8217;ve been ordered to do so by a boss or client, always think about usability&#8230;. always, always, always think about the user! Nobody is going to be impressed if your steaming animation impedes process! Don&#8217;t impede or delay the process of an application or website, ever!</p>

<p>By &#8220;process&#8221;, I mean the normal and anticipated manner through which a user may interact with your application or website.</p> 

<p>Oh, also, I really <strong>really</strong> hate Flash! If you&#8217;re still using flash to develop websites then the only acceptable excuse is that you&#8217;ve been in a coma for about three years! FLASH SUCKS! I don&#8217;t give a damn about &#8220;immersive experiences&#8221; when I&#8217;m surfing the web, all I want is my damn information!</p>

<h2>JavaScript; jQuery, MooTools etc.</h2>

<p>Evident from my above ramblings, the line between &#8216;quite pleasant&#8217; and &#8216;inconceivably annoying&#8217; is very thin! Don’t go crossing it with a JavaScript framework! &#8211; That’s not what they were made for!</p>

<p>I am also at fault; I have also succumbed to the idiocy of the collective. But I have learnt my lesson and have vowed to myself that I will never [consciously] do it again.</p>

<p>Lesson learnt: <strong>Don&#8217;t jump on the bandwagon just cos&#8217; it&#8217;s shiny and faster than the other ones!</strong></p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/usability-animation/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Getting the real time in JavaScript</title>
		<link>http://james.padolsey.com/uncategorized/getting-the-real-time-in-javascript/</link>
		<comments>http://james.padolsey.com/uncategorized/getting-the-real-time-in-javascript/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 00:03:51 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[Time]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=477</guid>
		<description><![CDATA[Getting the time in JavaScript is pretty simple. Using the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date">Date</a> constructor will give us the time as set on the user's computer, but what if we want the accurate time, or the time in a different timezone?]]></description>
			<content:encoded><![CDATA[<p>Getting the time in JavaScript is pretty simple. Using the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date">Date</a> constructor will give us the time as set on the user&#8217;s computer, but what if we want the accurate time, or the time in a different timezone?</p>

<p>Even with <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date/getTimezoneOffset"><code>getTimezoneOffset()</code></a> you&#8217;re still relying on the client!</p>

<p>It turns out that the only way of getting a complete and accurate time from any timezone requires a little bit of server interaction. Luckily there are a few APIs out there that offer this service (actually, there&#8217;s only one; well I couldn&#8217;t find any others)! </p>

<p>Here we&#8217;re using the <a href="http://simonwillison.net/2008/Jun/21/jsontime/">&#8216;json-time&#8217; API developed by Simon Willson</a>:</p>


<h2>JSON-time</h2>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">function</span> getTime<span class="br0">&#40;</span>zone<span class="sy0">,</span> success<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw2">var</span> url <span class="sy0">=</span> <span class="st0">'http://json-time.appspot.com/time.json?tz='</span> <span class="sy0">+</span> zone<span class="sy0">,</span>
        ud <span class="sy0">=</span> <span class="st0">'json'</span> <span class="sy0">+</span> <span class="br0">&#40;</span><span class="sy0">+</span><span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    window<span class="br0">&#91;</span>ud<span class="br0">&#93;</span><span class="sy0">=</span> <span class="kw2">function</span><span class="br0">&#40;</span>o<span class="br0">&#41;</span><span class="br0">&#123;</span>
        success <span class="sy0">&amp;&amp;</span> success<span class="br0">&#40;</span><span class="kw2">new</span> Date<span class="br0">&#40;</span>o.<span class="me1">datetime</span><span class="br0">&#41;</span><span class="sy0">,</span> o<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">;</span>
    document.<span class="me1">getElementsByTagName</span><span class="br0">&#40;</span><span class="st0">'head'</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">appendChild</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
        <span class="kw2">var</span> s <span class="sy0">=</span> document.<span class="me1">createElement</span><span class="br0">&#40;</span><span class="st0">'script'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        s.<span class="me1">type</span> <span class="sy0">=</span> <span class="st0">'text/javascript'</span><span class="sy0">;</span>
        s.<span class="me1">src</span> <span class="sy0">=</span> url <span class="sy0">+</span> <span class="st0">'&amp;callback='</span> <span class="sy0">+</span> ud<span class="sy0">;</span>
        <span class="kw1">return</span> s<span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>




<h2>Usage</h2>

<p>The first parameter of the callback function is the time (having been passed through the Date constructor), so you can use <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date#Methods_2">Date methods</a> such as <code>getSeconds()</code> etc. The second parameter is the entire object returned from the JSON request.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="co1">// Alert GMT:</span>
getTime<span class="br0">&#40;</span><span class="st0">'GMT'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>time<span class="br0">&#41;</span><span class="br0">&#123;</span>
    <span class="kw3">alert</span><span class="br0">&#40;</span>time<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// Get London time, and format it:</span>
getTime<span class="br0">&#40;</span><span class="st0">'Europe/London'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>time<span class="br0">&#41;</span><span class="br0">&#123;</span>
    <span class="kw2">var</span> formatted <span class="sy0">=</span> time.<span class="me1">getHours</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">':'</span> 
                  <span class="sy0">+</span> time.<span class="me1">getMinutes</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">':'</span>
                  <span class="sy0">+</span> time.<span class="me1">getSeconds</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw3">alert</span><span class="br0">&#40;</span> <span class="st0">'The time in London is '</span> <span class="sy0">+</span> formatted <span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>




<p>For reference, here&#8217;s <a href="http://json-time.appspot.com/timezones.json">a list of all the available timezones</a> (to use one, remove the backslash).</p>

<h2>jQuery version</h2>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span class="me1">getTime</span> <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">&#40;</span>zone<span class="sy0">,</span> success<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw2">var</span> url <span class="sy0">=</span> <span class="st0">'http://json-time.appspot.com/time.json?tz='</span>
            <span class="sy0">+</span> zone <span class="sy0">+</span> <span class="st0">'&amp;callback=?'</span><span class="sy0">;</span>
    $.<span class="me1">getJSON</span><span class="br0">&#40;</span>url<span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>o<span class="br0">&#41;</span><span class="br0">&#123;</span>
        success <span class="sy0">&amp;&amp;</span> success<span class="br0">&#40;</span><span class="kw2">new</span> Date<span class="br0">&#40;</span>o.<span class="me1">datetime</span><span class="br0">&#41;</span><span class="sy0">,</span> o<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// Usage:</span>
$.<span class="me1">getTime</span><span class="br0">&#40;</span><span class="st0">'GMT'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>time<span class="br0">&#41;</span><span class="br0">&#123;</span>
    <span class="kw3">alert</span><span class="br0">&#40;</span>time<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>




<h2>MooTools version</h2>

<p>You&#8217;ll need to download the <a href="http://www.clientcide.com/docs/Request/JsonP">JsonP class</a>.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">function</span> getTime<span class="br0">&#40;</span>zone<span class="sy0">,</span> success<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw2">var</span> url <span class="sy0">=</span> <span class="st0">'http://json-time.appspot.com/time.json'</span><span class="sy0">;</span>
    <span class="kw2">new</span> JsonP<span class="br0">&#40;</span>url<span class="sy0">,</span> <span class="br0">&#123;</span>
        data<span class="sy0">:</span> <span class="br0">&#123;</span> tz<span class="sy0">:</span> zone <span class="br0">&#125;</span><span class="sy0">,</span>
        onComplete<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>o<span class="br0">&#41;</span><span class="br0">&#123;</span>
            success <span class="sy0">&amp;&amp;</span> success<span class="br0">&#40;</span><span class="kw2">new</span> Date<span class="br0">&#40;</span>o.<span class="me1">datetime</span><span class="br0">&#41;</span><span class="sy0">,</span> o<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">request</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="co1">// Usage:</span>
getTime<span class="br0">&#40;</span><span class="st0">'GMT'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>time<span class="br0">&#41;</span><span class="br0">&#123;</span>
    <span class="kw3">alert</span><span class="br0">&#40;</span>time<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>




<p>Thank you <a href="http://simonwillison.net/">Simon Willison</a> for making this API; seriously, I searched around the entire internets just for one damn API and I almost lost hope!</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/uncategorized/getting-the-real-time-in-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Graceful degradation still matters!</title>
		<link>http://james.padolsey.com/javascript/graceful-degradation-still-matters/</link>
		<comments>http://james.padolsey.com/javascript/graceful-degradation-still-matters/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 10:39:07 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Graceful Degradation]]></category>
		<category><![CDATA[Progressive Enhancement]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=380</guid>
		<description><![CDATA[If you know about the timeless importance of <a href="http://accessites.org/site/2007/02/graceful-degradation-progressive-enhancement/">graceful degradation</a> then you need not read this, but for those of you who think it&#8217;s an old-fashioned methodology or even an optional technicality then let me be the first to tell you that you&#8217;re wrong! I know&#8230;]]></description>
			<content:encoded><![CDATA[<p>If you know about the timeless importance of <a href="http://accessites.org/site/2007/02/graceful-degradation-progressive-enhancement/">graceful degradation</a> then you need not read this, but for those of you who think it&#8217;s an old-fashioned methodology or even an optional technicality then let me be the first to tell you that you&#8217;re wrong! I know this may put me, a mere 18-year-old web developer in the awkward position of having to tell some ignorant 50-year-old that they&#8217;re wrong but I&#8217;m perfectly comfortable with that if it ensures a better internet! </p>
<p>I&#8217;ve never surfed the web in a browser less capable than IE5, this should say quite a lot about my <strong>lack</strong> of understanding of less capable pieces of software and devices, yet, I still appreciate and understand that graceful degradation is of upmost important when creating any website.</p>
<p>Let&#8217;s look at your average out-of-college web designer&#8217;s perspective on graceful degradation, assuming they know what it means:</p>
<p><strong>Note</strong>: When reading the below passage out in your head do it with an &quot;<a href="http://en.wikipedia.org/wiki/The_Arctful_Dodger">Artful Dodger</a>&quot; (from <a href="http://en.wikipedia.org/wiki/Oliver_Twist">Oliver Twist</a>) accent; it&#8217;ll come across as more believable!</p>
<h2>Some idiot:</h2>
<blockquote>
    <p>&quot;Look, mate, I&#8217;m NOT gonna build an entire website which validates, is table-less and has degrading JavaScript for any amount of money &#8211; that&#8217;s just stupid! Even if that 5% stat were true (I doubt it) I wouldn&#8217;t feel any different. Graceful degradation is an added feature; something which clients should have to pay more for! I make clients pay more for validation, table-less layouts, optimized images, IE6 support, IE7 support, Opera support, actually anything which isn&#8217;t Firefox (FF FTW!) I charge extra for! My approach is way more forward-thinking and innovative than those &quot;standardistas&quot;!! Who the hell gives a damn about some paranoid geek running Lynx to browse the web, and nobody even uses NoScript! If a user disables JavaScript then that user shouldn&#8217;t expect functionality, period! And as far as I&#8217;m concerned, if a user doesn&#8217;t have the very latest nightly build of FF3 then I&#8217;m not gonna cater to them!&quot;</p>
</blockquote>
<h2>Why the idiot is wrong:</h2>
<p>The above passage represents the complete and utter idiocy of some people, real people! You might think it&#8217;s a little over the top, what with the &quot;<em>if a user doesn&#8217;t have the very latest nightly build</em>&quot; comment but overall it is a pretty accurate depiction of what I fear a few web designers around the world actually think.</p>
<span id="more-380"></span>
<h3>&quot;Graceful degradation is an added feature&quot;</h3>
<p>This is an all-too-common misconception; if you think this is true then you&#8217;ve got it all backwards. In all this mess the only thing which is really an &quot;added feature&quot; is the JavaScript itself. The methodology which ensures degradability may be part and parcel <em>with</em> the JavaScript (as it should be!) but it certainly is <strong>not</strong> an added feature itself.</p>
<h3>&quot;If a user disables JavaScript then that user shouldn&#8217;t expect functionality, period!&quot;</h3>
<p>What you have to understand is that JavaScript and the extent to which it is supported is not always controlled by the user, there may be other reasons why your JavaScript enhancements cannot be experienced by them (look below), so don&#8217;t assume that your user&#8217;s have <em>knowingly</em> disabled JavaScript or that they even <em>know</em> what JavaScript is.</p>
<h3>&quot;Who the hell gives a damn about some paranoid geek running Lynx&quot;</h3>
<p>It&#8217;s not only the &quot;paranoid geeks&quot; who will have JavaScript disabled, there are many other valid reasons for JavaScript not working. Ignoring these  users is selfish, against standards and is definitely a bad business decision!</p>
<h2>Reasons for JavaScript being disabled:</h2>
<ul>
    <li>Security reasons. (to protect from XSS attacks and Internet Explorer&#8217;s multiple security flaws etc.)</li>
    <li>JavaScript slows down a user&#8217;s already slow dialup connection.</li>
    <li>Browser sometimes crashes because of excessive JS, user disables it.</li>
    <li>Popups, onBeforeUnload alerts, disabled right-click etc. &#8211; User get&#8217;s pissed off and disables JavaScript!</li>
    <li>User is disabled in some way and uses a screen reader such as JAWS, Windows-eyes, SpeakThis etc. (Each having no or limited JavaScript support)</li>
    <li>User is surfing from behind a corporate firewall &#8211; the firewall blocks client-side-scripting. .</li>
    <li>Very old browsers don&#8217;t support JavaScript.</li>
    <li>Mobile web browsers only have limited support of JavaScript. (&#8216;Opera 4 mobile&#8217; uses a proxy which strips out most JavaScript)</li>
</ul>
<p>As you can see, it&#8217;s not just some people who disable JavaScript from within their browsers, there are a</p>
<h2>Ensuring a degradable experience</h2>
<p>In order to ensure a degradable experience for your users it&#8217;s important to have the right mindset from day one. Graceful degradation itself is really just an end to which the means is usually something called &#8216;progressive enhancement&#8217;, a well-known methodology used in building fualt-tolerant systems.</p>
<p>Progressive enhancement, when applied to the internet, is essentially the process of a website or web application functioning perfectly on modern software  while still being able to work correctly on older software. When applying this concept to websites it&#8217;s easy to see it&#8217;s relation to the three layers of the web; <strong>content</strong>, <strong>presentation</strong> and <strong>behaviour</strong>.</p>
<p><strong>Content</strong> is the fundamental backbone of any website; all your content should be visible whatever device or software platform a user is running. The content of your website will typically be found within the HTML, neither of the other two layers should be found within your HTML! Equally, your content should not come from either of the other layers. With the rise of multimedia (video/audio websites) this is becoming an ever unrealistic expectation but it&#8217;s good to have principles, right!?</p>
<p><strong>Presentation</strong> (usually CSS) is the second layer and, for those browsers that support it, offers a lot of control over the layout and decoration of your content.</p>
<p><strong>Behaviour</strong> (usually JavaScript) is the third layer of the web and should be the last thing to build within a project cycle. Only use JavaScript to enhance the user&#8217;s experience. By making a site&#8217;s functionality dependent on JavaScript you&#8217;re immediately cutting out a percentage of users.</p>
<p>Once you have your content in place you can work on the presentation of that content, and then after that you can start adding JavaScript enhancements.</p>
<p><strong>Please note</strong>: I am talking about <strong>websites</strong> in this post, not web applications. Web Applications (many of which require JavaScript to operate) and the principles by which they&#8217;re built really have more in common with desktop applications than real websites. That said, it would be great if web application developers took a couple of the above points seriously!</p>
<h2>Not only JavaScript&#8230;</h2>
<p>The topic of this post does not <em>only</em> apply to JavaScript. Your content (HTML) and presentation (CSS) layers must also degrade in the same way. Nowadays most of the focus is on JavaScript because that happens to be the layer which most people screw up so frequently!</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/graceful-degradation-still-matters/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Some jQuery Shortcuts</title>
		<link>http://james.padolsey.com/javascript/some-jquery-shortcuts/</link>
		<comments>http://james.padolsey.com/javascript/some-jquery-shortcuts/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 15:55:48 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Shortcuts]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=163</guid>
		<description><![CDATA[Having used jQuery on a number of projects I&#8217;ve picked up a few handy shortcuts that are definitely worth sharing. There are no secrets here, just basic jQuery techniques discovered with the aid of the <a href="http://docs.jquery.com">jQuery documentation</a>. If you have any which you think are&#8230;]]></description>
			<content:encoded><![CDATA[<p>Having used jQuery on a number of projects I&#8217;ve picked up a few handy shortcuts that are definitely worth sharing. There are no secrets here, just basic jQuery techniques discovered with the aid of the <a href="http://docs.jquery.com">jQuery documentation</a>. If you have any which you think are worth mentioning then please feel free to leave a comment.</p> 
<h3>Checking if the DOM is ready</h3>
<p>Running code when the DOM is loaded and ready for manipulation is a popular requirement. The ideal solution is to place all initiating code at the bottom of your document (as per Yahoo&#8217;s &quot;<a href="http://developer.yahoo.com/performance/rules.html">Best Practices for Speeding Up Your Web Site</a>&quot;) but sometimes this is not possible. The next best alternative is to use a solid &#8216;DOM ready&#8217; function such as the one jQuery offers. You normally access it like this:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>...<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>



<p>There&#8217;s a quicker way of accessing the same functionality:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>...<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>



<h3>Creating elements</h3>
<p>There are a few different ways of creating elements, this is my favorite:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="st0">'&lt;div/&gt;'</span><span class="br0">&#41;</span>.<span class="me1">appendTo</span><span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>



<p>Alternatively you could take this route:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span>.<span class="me1">append</span><span class="br0">&#40;</span><span class="st0">'&lt;div/&gt;'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>



<p>Notice that you don&#8217;t have to write out the entire element. Even though DIV elements cannot have self-closing tags it&#8217;s still fine to specify it like above &#8211; JQuery will know what you mean.</p>
<span id="more-163"></span>
<h3>Adding or changing attributes in bulk</h3>
<p>Not so good:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="st0">'a'</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="sy0">,</span><span class="st0">'mydiv'</span><span class="br0">&#41;</span><span class="sy0">;</span>
$<span class="br0">&#40;</span><span class="st0">'a'</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">'class'</span><span class="sy0">,</span><span class="st0">'important'</span><span class="br0">&#41;</span><span class="sy0">;</span>
$<span class="br0">&#40;</span><span class="st0">'a'</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">'href'</span><span class="sy0">,</span><span class="st0">'http://www.google.com'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>



<p>Better:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="co1">// i.e. Chaining</span>
$<span class="br0">&#40;</span><span class="st0">'a'</span><span class="br0">&#41;</span>
	.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="sy0">,</span><span class="st0">'mydiv'</span><span class="br0">&#41;</span>
	.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">'class'</span><span class="sy0">,</span><span class="st0">'important'</span><span class="br0">&#41;</span>
	.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">'href'</span><span class="sy0">,</span><span class="st0">'http://www.google.com'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>



<p>Best:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="st0">'a'</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
	id<span class="sy0">:</span> <span class="st0">'mydiv'</span><span class="sy0">,</span>
	<span class="kw2">class</span><span class="sy0">:</span> <span class="st0">'important'</span><span class="sy0">,</span>
	href<span class="sy0">:</span> <span class="st0">'http://www.google.com'</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>



<h3>Have full control over your animations</h3>
<p>jQuery&#8217;s stock animation functions such as <code>fadeOut()</code> and <code>slideDown()</code> can be useful but may sometimes do more than you intended (like setting the element to <code>display:none;</code> instead of JUST reducing the opacity). So if you want to have full control over your animations then use <code>animate()</code>.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="st0">'#elem'</span><span class="br0">&#41;</span>.<span class="me1">animate</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
	<span class="co1">// Reduce opacity by 0.2:</span>
	opacity<span class="sy0">:</span> <span class="st0">'-=.2'</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>



<h3>Three ways to test wheter an element exists</h3>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="co1">// 1:</span>
<span class="kw1">if</span> <span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="st0">'#elem'</span><span class="br0">&#41;</span>.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">'It exists!'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="br0">&#125;</span>
<span class="co1">// 2:</span>
<span class="kw1">if</span> <span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="st0">'#elem'</span><span class="br0">&#41;</span>.<span class="me1">length</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">'It exists!'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="br0">&#125;</span>
<span class="co1">// 3:</span>
<span class="kw1">if</span> <span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="st0">'#elem'</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">'It exists!'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="br0">&#125;</span></pre></div></div>



<h3>Chain Everything!</h3>
<p>jQuery gives you the power of chainability, this means you can perform multiple actions on a single element or set of elements without having to &#8216;re-select&#8217;:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span><span class="st0">'&lt;div/&gt;'</span><span class="br0">&#41;</span>
	.<span class="me1">css</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
		cursor<span class="sy0">:</span> pointer<span class="sy0">,</span>
		height<span class="sy0">:</span> <span class="st0">'200px'</span><span class="sy0">,</span>
		width<span class="sy0">:</span> <span class="st0">'200px'</span>
	<span class="br0">&#125;</span><span class="br0">&#41;</span>
	.<span class="me1">attr</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
		id<span class="sy0">:</span> <span class="st0">'mydiv'</span><span class="sy0">,</span>
		<span class="kw2">class</span><span class="sy0">:</span> <span class="st0">'box'</span>
	<span class="br0">&#125;</span><span class="br0">&#41;</span>
	.<span class="me1">append</span><span class="br0">&#40;</span><span class="st0">'&lt;a href=&quot;#&quot;&gt;link&lt;/a&gt;'</span><span class="br0">&#41;</span>
	.<span class="me1">appendTo</span><span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>


]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/some-jquery-shortcuts/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JavaScript libraries vs. Usability</title>
		<link>http://james.padolsey.com/javascript/javascript-libraries-vs-usability/</link>
		<comments>http://james.padolsey.com/javascript/javascript-libraries-vs-usability/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 14:43:33 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Graceful Degradation]]></category>
		<category><![CDATA[JavaScript libraries]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[Progressive Enhancement]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://james.padolsey.com/?p=132</guid>
		<description><![CDATA[JavaScript libraries like <a href="http://mootools.net/">MooTools</a>, <a href="http://jquery.com/">jQuery</a>, <a href="http://dojotoolkit.org/">Dojo</a> and <a href="http://www.prototypejs.org/">Prototype</a> have proven very popular with developers recently, perhaps too popular!?
Over the last year there&#8217;s been a major recognition boost for these libraries, especially those featuring animations/effects and Ajax capabilities. Blinking/fading/sliding text was in fashion back in the nineties&#8230;]]></description>
			<content:encoded><![CDATA[<p>JavaScript libraries like <a href="http://mootools.net/">MooTools</a>, <a href="http://jquery.com/">jQuery</a>, <a href="http://dojotoolkit.org/">Dojo</a> and <a href="http://www.prototypejs.org/">Prototype</a> have proven very popular with developers recently, perhaps too popular!?</p>
<p>Over the last year there&#8217;s been a major recognition boost for these libraries, especially those featuring animations/effects and Ajax capabilities. Blinking/fading/sliding text was in fashion back in the nineties but it seems, following the hype of Web 2.0, these effects have made a massive comeback! </p>
<p>To be honest I think it&#8217;s great; what better way to expand the imagination of the average developer than to give him/her some brand new toy to play with? Web developers are now thinking of innovative ways to utilise these new-found JavaScript enhancements and designers are pushing boundaries with their designs, integrating these enhancements into their mockups!</p>
<p>This is all wonderful, but unfortunately I fear the overuse of JavaScript libraries such as jQuery has had a detrimental   effect on usability. Obviously we had issues before these libraries and we will surely continue to rave about it afterwards but I cannot help but notice what is happening right now; people are turning a blind eye to usability and focusing all their attention on making their websites as smooth and swish as possible!</p>
<span id="more-132"></span>
<p>If you&#8217;re in the template trading industry then you will have heard of the recent successful launch of <a href="http://themeforest.net">ThemeForest</a>, yet another powerhouse off the <a href="http://envato.com/">Envato</a> production line. At the moment it has upwards of 300 templates for sale, ranging from <a href="http://wordpress.org">Wordpress</a> magazine-style themes to one-page portfolio sites. </p>
<p>Flicking through the templates on offer you&#8217;ll probably notice nothing wrong with what&#8217;s offered, even if you look at the previews of some of them you&#8217;ll notice nothing strange. But, if you continue you&#8217;ll eventually find a number of templates offering &quot;jQuery effects&quot; and featuring &quot;Ajax pagination&quot;! Both of these terms spark a lack-of-usability chord within me. Looking at the preview of these particular templates proves just how lacking the author&#8217;s knowledge of usability is. Even basic concepts like code validation and degradable JavaScript have been massively overlooked!</p>
<p>Yes, these templates look great when you&#8217;re using a modern browser like Firefox 3 and have JavaScript enabled. But what happens if you&#8217;re using IE6 without JavaScript? In fact, even using a modern browser, but with JS disabled is disappointing &#8211; for a couple of the themes nothing even comes up&#8230; not even a warning to say &quot;you must have JavaScript enabled to view this site&quot;. </p>
<p>Why should these authors be allowed to make any money from their laziness? Template buyers are as clueless about the issues as the authors and so ignorantly give over the odd $15 for their new &quot;premium&quot; template, completely ignoring the fact that a large proportion of their users may be utterly disappointed! </p>
<p>One of the core values of jQuery is that it lends itself to unobtrusive JavaScript, thus  promoting the ideals of progressive enhancement and graceful degradation, two terms that seem totally lost on some developers!</p>
<p>Contrary to the title of this post, the JavaScript libraries are not to blame; they&#8217;re merely making it easier to access JavaScript functionality so that people don&#8217;t have to spend hours developing it themselves. The problem lies in the ignorance and laziness of web developers! </p>
<p>Just to be clear, there is nothing wrong with ThemeForest itself, in fact it&#8217;s one of the best and probably the cheapest template-selling website out there. I only take issue with a couple of the authors &#8211; it seems they insist on making &quot;cool&quot; sites which totally lack many of the core and fundamental practices of the web!</p>]]></content:encoded>
			<wfw:commentRss>http://james.padolsey.com/javascript/javascript-libraries-vs-usability/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
