<?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>dtsn &#187; JavaScript</title>
	<atom:link href="http://dtsn.co.uk/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://dtsn.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 17 Aug 2010 13:18:57 +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>TweetTabs &amp; @Anywhere</title>
		<link>http://dtsn.co.uk/2010/07/14/tweettabs-anywhere/</link>
		<comments>http://dtsn.co.uk/2010/07/14/tweettabs-anywhere/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 19:52:11 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[TweetTabs]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[dtsn]]></category>
		<category><![CDATA[@Anywhere]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=787</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p><em>This was presented at Devnest 9</em>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2010%2F07%2F14%2Ftweettabs-anywhere%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2010%2F07%2F14%2Ftweettabs-anywhere%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=%40Anywhere,TweetTabs" height="61" width="50" /><br />
			</a>
		</div>
<p><em>This was presented at <a href="http://twitterdevelopernest.com/2010/05/devnest-%E2%80%93-london-twitter-developer-nest-9/">Devnest 9</a></em></p>
<p>Developers of Twitter probably heard of @Anywhere when it was launched at Chirp, it includes componants which will enhanch a web page. Which for twitter increases the engagement for their users. These componants are cool, but hardly anything to get excitited about. @Anywhere contains a fantastic secret underneth it&#8217;s hood and thats a fully JS-API. Thats right a method to interface with the Twitter API entirely in JavaScript. This is because @Anywhere provides the means to authenticate a user via OAuth using their new Twitter Connect window.</p>
<p>Authenticated users can achieve a lot more using the API, therefore the JS-API now lets you practically do anything that the regular API can. This is really exciting because it means that i can finally turn TweetTabs into a fully Twitter client built entirely in JavaScript.</p>
<p>Here&#8217;s a quick example of how easy it is to post a status update using @Anywhere:</p>
<pre name="code" class="js">
twttr.anywhere(function(T) {
if (T.isConnected()) {
T.status.Update(‘hello world’);
}
});
</pre>
<p>You can find a lot more information regarding @Anywhere over on the <a href="http://dev.twitter.com/anywhere">@Anywhere dev page</a>. You can also get a full list of <a href="http://platform.twitter.com/js-api.html">support methods</a>.</p>
<h2>TweetTabs</h2>
<p>So how does this all fit in with TweetTabs? Quite simply TweetTabs was never quite finished, i always intended it to be a fully Twitter Client and not just the search client that it became, this is because Twitter at the time of writing TweetTabs didn&#8217;t support any methods of OAuth through JavaScript. But now it does, so i&#8217;ve implemented it.</p>
<p>You can check out a very alpha version (which is my proof of concept) at <a href="http://beta.tweettabs.com">http://beta.tweettabs.com</a>. Please give feedback, I fully intend on integrating @Anywhere fully into TweetTabs.</p>
<h2>Downsides</h2>
<p>The real big problem with the JS-API part of @Anywhere is that it is not supported (at all), there is very little documentation and most of it has changed since it was released. So it really is down to trial and error!</p>
<h2>Slides</h2>
<p>Here are the slides from the talk.</p>
<p><object id="__sse4716451" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dtsn-devnest9-100709020920-phpapp02&amp;rel=0&amp;stripped_title=dtsn-devnest9" /><param name="name" value="__sse4716451" /><param name="allowfullscreen" value="true" /><embed id="__sse4716451" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dtsn-devnest9-100709020920-phpapp02&amp;rel=0&amp;stripped_title=dtsn-devnest9" name="__sse4716451" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2010/07/14/tweettabs-anywhere/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenting at Twitter Development Nest</title>
		<link>http://dtsn.co.uk/2010/06/30/presenting-at-twitter-development-nest/</link>
		<comments>http://dtsn.co.uk/2010/06/30/presenting-at-twitter-development-nest/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 09:37:28 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[dtsn]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=781</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>Next week I will be presenting&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2010%2F06%2F30%2Fpresenting-at-twitter-development-nest%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2010%2F06%2F30%2Fpresenting-at-twitter-development-nest%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p>Next week I will be presenting the first, of what I hope to be many, presentation on what I do. This one will be focusing on Tweettabs and integrating @Anywhere support. It should be a interesting talk with lots of surprises.</p>
<p><strong>Tuesday 6th July, 6pm-9pm</strong></p>
<p><em>The Guardian<br />
King&#8217;s Place<br />
90 York Way<br />
N1 9AG London<br />
United Kingdom</em></p>
<p>Come along and check it out, you can get tickets <a href="http://devnest.eventbrite.com/">here</a> and find more information about the event on their <a href="http://twitterdevelopernest.com/2010/05/devnest-%E2%80%93-london-twitter-developer-nest-9/">website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2010/06/30/presenting-at-twitter-development-nest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing JavaScript</title>
		<link>http://dtsn.co.uk/2010/01/12/optimizing-javascript/</link>
		<comments>http://dtsn.co.uk/2010/01/12/optimizing-javascript/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 13:23:05 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=628</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>JavaScript is in the middle of&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2010%2F01%2F12%2Foptimizing-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2010%2F01%2F12%2Foptimizing-javascript%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=JavaScript,Optimization,Performance" height="61" width="50" /><br />
			</a>
		</div>
<p>JavaScript is in the middle of a massive comeback and developers are abusing it. JavaScript addons and widgets are becoming are the norm for large sites and are so easy to install, in large numbers and quantities. For example <a href="http://mashable.com">Mashable</a> loads nearly a mega byte in JavaScript files. In this article I will go through some tips to help you optimize your JavaScript and reduce both the load on your servers and make your pages respond faster.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="js" border="0" alt="js" src="http://dtsn.co.uk/wp-uploads/2010/01/js-thumb.png" width="480" height="200" /></p>
<h2>Cut code</h2>
<p>The first and biggest thing you should do in optimizing your JavaScript is to cut down on the size, cut out functions that don’t do a lot and try and reduce the size of your file. This goes along side with the question <strong>do you need a framework</strong>? Think it through, is your site big enough to warrant loading a full framework (typically in excess of 3000 lines), if you just want to do some very simple functions write them in JavaScript without a framework.</p>
<p>If you really need to load a framework use the ones available on the <a href="http://code.google.com/apis/ajaxlibs/documentation/">Google AJAX libraries API</a>, most frameworks are available. These are just the frameworks hosted on Google, they work of the principle that if one website uses these files then the user will still have the files in the browser cache and won’t need load them again.</p>
<h3>Minimize </h3>
<p>Run your code through a JavaScript minimiser, this will shrink all the files to be really small there are a number of popular ones available (this is also applicable for CSS):</p>
<ul>
<li>Bundle Fu &#8211; <a title="http://code.google.com/p/bundle-fu/" href="http://code.google.com/p/bundle-fu/">http://code.google.com/p/bundle-fu/</a> </li>
<li>Pack:tag &#8211; <a title="http://sourceforge.net/projects/packtag/" href="http://sourceforge.net/projects/packtag/">http://sourceforge.net/projects/packtag/</a> </li>
<li>JSMIN &#8211; <a title="http://www.crockford.com/javascript/jsmin.html" href="http://www.crockford.com/javascript/jsmin.html">http://www.crockford.com/javascript/jsmin.html</a> </li>
<li>YUI Compressor &#8211; <a title="http://yuilibrary.com/downloads/#yuicompressor" href="http://yuilibrary.com/downloads/#yuicompressor">http://yuilibrary.com/downloads/#yuicompressor</a> </li>
</ul>
<h2>Expires headers</h2>
<p>Set your expires headers, this should be standard for all your static content like CSS and Images as well. A browser may need to make many requests to your server in order to get all the content, by using an expires header you make those components cacheable for a set period of time, therefore the browser will need to make less HTTP requests. For a more detailed explanation, as well other components which need improving reading the <a href="http://developer.yahoo.com/performance/rules.html#expires">Yahoo Developer Network Guide on optimisation</a>.</p>
<h2>Loading Scripts Asynchronously</h2>
<p>Browsers are only single threaded, this means that it can only really load one thing at a time. However there are ways around this, and ways you can load multiple files without locking up the browser. Give Steve Souders articles on <a href="http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/">Loading Scripts without Blocking</a> if you are interested in implementing this. I am currently working on a prototype based class to do this which will be published on this blog in the coming months.</p>
<h2>Defer JavaScript Loading</h2>
<p>Steve Souders talks about deferring JavaScript loading in his series about <a href="http://www.stevesouders.com/blog/2009/12/07/downloading-javascript-as-strings/">high performance websites</a>. It’s quite a simple idea really, don’t load up the JavaScript until you require it. Therefore if your JavaScript is not needed on page load this should be deferred to be loaded up later.</p>
<h2>Evaluate</h2>
<p>Make sure you evaluate your performance when trying to optimize JavaScript. I personally love the Firefox plugin <a href="http://getfirebug.com">FireBug</a>, and it’s plugin <a href="http://developer.yahoo.com/yslow/">YSlow</a>. However there are lots of other methods and tools you can use to evaluate you performance, the best by far is the firebug profiler. <a href="http://michaelsync.net/2007/09/10/firebug-tutorial-logging-profiling-and-commandline-part-ii">Micheal Sync</a> has a fantastic tutorial on the FireBug profiler which is well worth a read.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2010/01/12/optimizing-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bouncing JavaScript Tutorial</title>
		<link>http://dtsn.co.uk/2010/01/07/bouncing-javascript-tutorial/</link>
		<comments>http://dtsn.co.uk/2010/01/07/bouncing-javascript-tutorial/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 11:00:38 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Scriptaculous]]></category>
		<category><![CDATA[Bounce]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=692</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p><strong>Original Source</strong>: http://giancarlo.dimassa.net</p>
<p>There have been&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2010%2F01%2F07%2Fbouncing-javascript-tutorial%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2010%2F01%2F07%2Fbouncing-javascript-tutorial%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=Bounce,JavaScript,Prototype,Scriptaculous" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>Original Source</strong>: <a href="http://giancarlo.dimassa.net/2007/07/11/elastic-and-bouncing-transitions-in-scriptaculous/">http://giancarlo.dimassa.net</a></p>
<p>There have been many examples of bouncing effects in <a href="http://script.aculo.us/">scriptaculous</a> but this one has to be one of the most realistic. It uses the equations developed by <a href="http://www.robertpenner.com/">Robert Penner</a> to accurately represent a bounce, and it does look cool.</p>
<h2>What you need</h2>
<p>As with most of my tutorials this is based on <a href="http://script.aculo.us/">scriptaculous</a> and <a href="http://www.prototypejs.org/">prototype</a>, but the equations could easily be porter to other animation frameworks.</p>
<h2>The code</h2>
<p>This is really simple, basically what we are going to be doing is to add a new transitional effect to scriptaculous. To do this we just extend the Effect class.</p>
<p><strong>Add this to your own JavaScript file instead of scriptaculous, so you don’t loose it when you update.</strong></p>
<pre class="js" name="code">/*Based on Easing Equations v2.0
(c) 2003 Robert Penner, all rights reserved.
This work is subject to the terms in http://www.robertpenner.com/easing_terms_of_use.html

Adapted for Scriptaculous by Ken Snyder (kendsnyder ~at~ gmail ~dot~ com) June 2006
*/

Effect.Transitions.Bounce = function (pos) {
    if (pos &lt; 0.36363636363636365) {
        return 7.5625 * pos * pos;
    } else if (pos &lt; 0.7272727272727273) {
        return 7.5625 * (pos -= 0.5454545454545454) * pos + 0.75;
    } else if (pos &lt; 0.9090909090909091) {
        return 7.5625 * (pos -= 0.8181818181818182) * pos + 0.9375;
    } else {
        return 7.5625 * (pos -= 0.9545454545454546) * pos + 0.984375;
    }
}</pre>
<h2>Use it</h2>
<p>You can use this effect as a transition type with lots of effects.</p>
<pre>new Effect.BlindDown(div, {
    duration: 0.5,
    transition: Effect.Transitions.Bounce
});</pre>
<p>Check out <a href="http://giancarlo.dimassa.net/2007/07/11/elastic-and-bouncing-transitions-in-scriptaculous/">Ken Snyder’s</a> blog for more transitional effects.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2010/01/07/bouncing-javascript-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Check/Uncheck Checkboxes</title>
		<link>http://dtsn.co.uk/2009/12/10/javascript-checkuncheck-checkboxes/</link>
		<comments>http://dtsn.co.uk/2009/12/10/javascript-checkuncheck-checkboxes/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 12:00:00 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Check All]]></category>
		<category><![CDATA[Checkbox]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Uncheck All]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=685</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>This tutorial is a really simple&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F12%2F10%2Fjavascript-checkuncheck-checkboxes%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F12%2F10%2Fjavascript-checkuncheck-checkboxes%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=Check+All,Checkbox,Form,HTML,JavaScript,Prototype,Uncheck+All" height="61" width="50" /><br />
			</a>
		</div>
<p>This tutorial is a really simple one and is only a one liner in prototype (slight more in regular JavaScript). It will check all the checkboxes on a page, and a function to uncheck all checkboxes quite handy really especially if you are dealing with long lists.</p>
<h2>Check All</h2>
<pre class="js" name="code">$$('input[type=&quot;checkbox&quot;]').invoke('writeAttribute', 'checked', 'checked');</pre>
<p>What we are doing here is selecting all the inputs of type checkbox and enumerating over them writing a check attribute to each one.</p>
<h2>Uncheck All</h2>
<pre class="js" name="code">$$('input[type=&quot;checkbox&quot;]').invoke('removeAttribute', 'checked');</pre>
<p>As you can guess this just the opposite way round.</p>
<h2>JavaScript</h2>
<p>You can do the same basic principle without a framework:</p>
<pre class="js" name="code">// check all
var inputs = document.getElementsByTagName('input');
for (var i = 0; i &lt; inputs.length; i++) {
	if (inputs[i].type == 'checkbox') {
		inputs[i].checked = true;
	}
}

// uncheck all
var inputs = document.getElementsByTagName('input');
for (var i = 0; i &lt; inputs.length; i++) {
	if (inputs[i].type == 'checkbox') {
		inputs[i].checked = false
	}
}</pre>
<p>That&#8217;s it there isn&#8217;t really much to it, but I thought it was worth sharing.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2009/12/10/javascript-checkuncheck-checkboxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSON(P) Stacking</title>
		<link>http://dtsn.co.uk/2009/12/06/jsonp-stacking/</link>
		<comments>http://dtsn.co.uk/2009/12/06/jsonp-stacking/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 13:30:50 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Website Hanging]]></category>
		<category><![CDATA[Widgets]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=677</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>JSONP was proposed as grabbing data&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F12%2F06%2Fjsonp-stacking%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F12%2F06%2Fjsonp-stacking%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=JavaScript,JSON,Website+Hanging,Widgets" height="61" width="50" /><br />
			</a>
		</div>
<p>JSONP was proposed as grabbing data from external domains avoiding the cross script scripting limitations (see this <a href="http://ajaxian.com/archives/jsonp-json-with-padding">Ajaxian article</a> for more information). It requires a call to an external API where you specificy the a callback function, you do this through the use of script tag. For example:</p>
<pre class="html" name="code">&lt;script type=&quot;text/javascript&quot; src=&quot;http://yourdomain.com/api?callback=myfunction&quot;&gt;&lt;/script&gt;</pre>
<p>When the script tag has been loaded your function would be called with the JSON data, like so.</p>
<pre class="js" name="code">myfunction(‘some JSON data’);</pre>
<p>However you become reliant on that external service to always be available, if for any reason that service goes down you wouldn’t get any data and your page would be likely to hang.</p>
<p><strong>Therefore I propose a system of JSONP stacking, quite simply you stack up your JSON requests if you don’t receive a response in a set time it will stop the request.</strong></p>
<p>This can be easily achieved by having the following function:</p>
<pre class="js" name="code">// callback function
var _c = false;
// success flag
var _s = false;

function JSONPStacking(url, callback) {
	// create the element
	var script = document.createElement('script');
	// set the source
	script.src = url + '&amp;callback=callback';
	// render the element
	document.appendChild(script);
	// start the counter, this one last for 5 seconds
	setTimeout(function() {
		if (!_s) {
			// remove the element
			document.body.removeChild(script);
		}
	}, 5000);
}

function callback(data) {
	// say the data has been received
	_s = true;
	// call the callback with the data
	_c(data);
}</pre>
<p>Basically what we are doing here is to create a normal JSONP request by creating a script tag and loading it into the body. However we are overriding the standard callback function with our own one, <em>callback. </em>When the request succeeds this will call that function with the data and in turn we call our success function. If 5 seconds have past the timeout will trigger, see if the success flag has been set if not it will remove the element from the DOM thereby stopping the request.</p>
<p>That&#8217;s it, it is a really simple principle but will hopefully stop your site from hanging on long request, such as for the Twitter widget. It will also make your widgets that you build a lot more stable and won&#8217;t overload your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2009/12/06/jsonp-stacking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better Twitter</title>
		<link>http://dtsn.co.uk/2009/12/01/better_twitter/</link>
		<comments>http://dtsn.co.uk/2009/12/01/better_twitter/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 13:47:04 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Greasemonkey]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=669</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>There are a lot of things&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F12%2F01%2Fbetter_twitter%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F12%2F01%2Fbetter_twitter%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=Greasemonkey,JavaScript,Twitter" height="61" width="50" /><br />
			</a>
		</div>
<p>There are a lot of things wrong with the Twitter homepage, that’s why i created Better Twitter. Which is a <a href="https://addons.mozilla.org/en-US/firefox/addon/748">Greasemonkey</a> script which will fix some the things which really bug me with the Twitter UI. I have converted the Greasemonkey script into a standalone Firefox plugin as well using this <a href="http://arantius.com/misc/greasemonkey/script-compiler">user script complier</a>.</p>
<p><a href="http://dtsn.co.uk/wp-uploads/2009/12/bettertwitter.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="bettertwitter" border="0" alt="bettertwitter" src="http://dtsn.co.uk/wp-uploads/2009/12/bettertwitter-thumb.png" width="201" height="157" /></a> </p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/51791/">Install Plugin</a> or download the <a href="http://dtsn.co.uk/wp-content/themes/dtsn/scripts/bettertwitter.js">Greasemonkey Script</a></p>
<h2>Release 0.1</h2>
<ul>
<li>Fixes the tweet box, allowing you to press enter to submit the tweet </li>
<li>Focuses the tweet box when the page loads </li>
</ul>
<h2>Installation</h2>
<p>There are two options for installing the script.</p>
<ol>
<li>Download the <a href="https://addons.mozilla.org/en-US/firefox/addon/51791/">Firefox Plugin</a>, this requires Greasemonkey to be installed (i think)</li>
<li>Download the <a href="http://dtsn.co.uk/wp-content/themes/dtsn/scripts/bettertwitter.js">Greasemonkey Script</a></li>
</ol>
<h2>Feedback</h2>
<p>If you have any thoughts or feedback on this script, or would like to contribute please leave a comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2009/12/01/better_twitter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Weather</title>
		<link>http://dtsn.co.uk/2009/11/26/javascript-weather/</link>
		<comments>http://dtsn.co.uk/2009/11/26/javascript-weather/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 16:08:33 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Pipes]]></category>
		<category><![CDATA[Weather]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=639</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>Here’s a crazy idea, what would&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F11%2F26%2Fjavascript-weather%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F11%2F26%2Fjavascript-weather%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=JavaScript,JSON,Pipes,Weather,Yahoo" height="61" width="50" /><br />
			</a>
		</div>
<p>Here’s a crazy idea, what would you do if you wanted to change the background picture of your website so it matches the weather. Luckily Its really easy, and I figured out all the hard bits for you.</p>
<p><em>UPDATE &#8211; Chris Heilmann over at the </em><a href="http://developer.yahoo.net/blog/archives/2009/12/extending_the_weather_api_with_yql.html"><em>Yahoo! Developer Network Blog</em></a><em> has made this even simpler through the use of YQL.</em></p>
<h2>The Data</h2>
<p>First of all we need a data source which will provide the weather for a particular location, we can grab this from the <a href="http://developer.yahoo.com/weather/">Yahoo Weather API</a>. Using the code UKXX0117 which is for Reading, UK I can create the an RSS feed which you can see here <a title="http://weather.yahooapis.com/forecastrss?p=UKXX0117&amp;u=c" href="http://weather.yahooapis.com/forecastrss?p=UKXX0117&amp;u=c">http://weather.yahooapis.com/forecastrss?p=UKXX0117&amp;u=c</a>. Great but how can we process this RSS feed? That’s where <a href="http://pipes.yahoo.com">Yahoo Pipes</a> comes in, we can take in the RSS feed extract the data we need (item.yweather.condition) and export it as JSON.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dtsn.co.uk/wp-uploads/2009/11/image3.png" width="480" height="269" /></p>
<p>Now we can access the JSON data for the weather in Reading <a href="http://pipes.yahoo.com/pipes/pipe.run?_id=b13966505cb6b00dd1d18ec4aafc14b4&amp;_render=json">here</a>.</p>
<h2>JavaScript</h2>
<p>The JavaScript cannot directly call the JSON script via AJAX due to cross site scripting limitations imposed by the browser. This is where JSONP comes in, JSONP is a way to retrieve data from external domains through wrapping the JSON in a function, you can read more on JSONP at <a href="http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/">from__future__import</a>. Yahoo Pipes fully supports the JSONP format using the parameter callback, therefore in our webpage we load up the following.</p>
<pre class="html" name="code">&lt;script type=&quot;text/javascript&quot; src=&quot;http://pipes.yahoo.com/pipes/pipe.run?_id=b13966505cb6b00dd1d18ec4aafc14b4&amp;_render=json&amp;_callback=weather&quot;&gt;&lt;/script&gt;</pre>
<p>This will call the function weather passing through a weather status code as the parameter.</p>
<p>That is really it, you can do whatever you want with the data, here’s a quick example of how I would use it.</p>
<pre class="js" name="code">function weather(data) {
        var code = data.value.items[0].content;
	switch(code) {
		case '32': $(document.body).addClassName('sunny');
		break;
	}
}</pre>
<h2>Example</h2>
<p><script type="text/javascript" src="http://pipes.yahoo.com/pipes/pipe.run?_id=b13966505cb6b00dd1d18ec4aafc14b4&amp;_render=json&amp;_callback=weather"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2009/11/26/javascript-weather/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TweetTabs, A Story</title>
		<link>http://dtsn.co.uk/2009/06/17/tweettabs-a-story/</link>
		<comments>http://dtsn.co.uk/2009/06/17/tweettabs-a-story/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 22:09:51 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[TweetTabs]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=574</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>For everyone who follows me on&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F06%2F17%2Ftweettabs-a-story%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F06%2F17%2Ftweettabs-a-story%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p>For everyone who follows me on twitter or knows me personally would know that yesterday I launched something that i have been working on for a very long time. <a href="http://tweettabs.com">TweetTabs</a> is a way of tracking real-time twitter trends and searches, and has been my little project since i first started on it back in Easter. The idea came from the lack on online real-time ways to interface with twitter, the premise is simple, i wanted an easy way to search for things in twitter which constantly updated, so TweetTabs was born. </p>
<p>The initial application was written in about 2 hours entirely in JavaScript, it later went through a number of huge revisions especially over the Easter weekend. It gained quite a lot of features, and then lost them. I wrote an entire OAuth module in JavaScript, then realised that you can’t authenticate headers. The project was basically done apart from one of the most complicated features. Then my life changed, I broke up with my long term girlfriend, of 5 years, and had to move back home with my parents. Even though this didn’t dent my enthusiasm for the project it definitely affected the timescales.</p>
<h2>How it works</h2>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dtsn.co.uk/wp-content/uploads/2009/06/image-thumb.png" width="480" height="310" /></p>
<p>TweetTabs is a very simple idea, but it takes a very long time to solve the problems it presents. The entire application is written in JavaScript, this gets around the notion of having a API limit for your twitter searches, you are now only limited by your I.P. address, which has a much higher (not declared) limit. For every tab TweetTab hits twitter to fetch the data, this is controlled by our adaptive pollrate. Put simply this means that each tab can work out the optimum time to fetch more data from twitter. We try and limit the number of times TweetTabs hits twitter in the hour, mostly so that you don&#8217;t reach your API limit (it is possible, and I did it a lot in testing), and we don&#8217;t overload twitter.</p>
<p> <object width="480" height="360"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5208057&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5208057&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="480" height="360"></embed></object>
<p><a href="http://vimeo.com/5208057">TweetTabs Screencast</a> from <a href="http://vimeo.com/user546294">Daniel Saxil-Nielsen</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<h2>Coverage</h2>
<p>So now TweetTabs has been launched and has had loads of positive feedback and has been covered on loads of huge sites:</p>
<ul>
<li><a title="http://www.techcrunch.com/2009/06/16/tweettabs-is-an-awesome-way-to-search-twitter/" href="http://www.techcrunch.com/2009/06/16/tweettabs-is-an-awesome-way-to-search-twitter/">http://www.techcrunch.com/2009/06/16/tweettabs-is-an-awesome-way-to-search-twitter/</a> </li>
<li><a title="http://mashable.com/2009/06/16/tweettabs/" href="http://mashable.com/2009/06/16/tweettabs/">http://mashable.com/2009/06/16/tweettabs/</a> </li>
</ul>
<h2>Dedications</h2>
<p>I don’t know whether this is normally done for releasing products, but I feel it is appropriate, I would like to mention everyone who helped with the process along the way. Starting firstly with <a href="http://twitter.com/nickhalstead" target="_blank">@nickhalstead</a>, who supported me the whole way (and sorry it took so long). <a href="http://twitter.com/nicktelford" target="_blank">@nicktelford</a> who was there to bounce ideas of and to find lots of bugs just before we were about the launch. <a href="http://twitter.com/alexforrow" target="_blank">@alexforrow</a> for writing a really good deployment script, which merges all the files and obfuscates them. All the great people that tested it along the way: <a href="http://twitter.com/chris_alexander" target="_blank">@chris_alexander</a>, <a href="http://twitter.com/craigyd" target="_blank">@craigyd</a>, <a href="http://twitter.com/amykate" target="_blank">@amykate</a> and <a href="http://twitter.com/girlygeekdom" target="_blank">@girlygeekdom</a> (who is probably the one who answers <a href="http://twitter.com/tweettabs" target="_blank">@tweettabs</a> questions online). </p>
<p>TweetTabs is built using <a href="http://prototypejs.org" target="_blank">Prototype</a> and the JavaScript framework, and is powered by <a href="http://tweetmeme.com">TweetMeme</a>, and <a href="http://twitter.com" target="_blank">Twitter</a>.     </p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2009/06/17/tweettabs-a-story/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building JavaScript Widgets</title>
		<link>http://dtsn.co.uk/2009/03/15/building-javascript-widgets/</link>
		<comments>http://dtsn.co.uk/2009/03/15/building-javascript-widgets/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 12:18:09 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=530</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p></p>
<p>Little pieces of JavaScript you&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F03%2F15%2Fbuilding-javascript-widgets%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F03%2F15%2Fbuilding-javascript-widgets%2F&amp;source=dtsn&amp;style=normal&amp;service=is.gd" height="61" width="50" /><br />
			</a>
		</div>
<p><img src="http://dtsn.co.uk/wp-content/uploads/2009/03/buidling_javascript_widgets1.gif" alt="Building JavaScript Widgets" /></p>
<p>Little pieces of JavaScript you embed onto your website are getting more popular. Every major provider of a service on the web also gives you a little widget that you can put on your blog or webpage to promote what you are doing, for example <a href="http://twitter.com/widgets" target="_blank">Twitter</a>, <a href="http://www.last.fm/widgets" target="_blank">Last FM</a> and <a href="http://digg.com/add-digg" target="_blank">Digg</a> all provide widgets which are great for you and great for the service.</p>
<p>I am going to talk you through the development and pitfalls associated with the design and development of widgets. </p>
<p>First and foremost, you need to decide what you want to show with your widget. Knowing this you can make an educated choice about which method you want to use to create a widget, there are basically two methods associated with widget development.</p>
<h4>iframe’s</h4>
<p>No, iframe’s aren’t dead. They are a major part of widget development. Using a <code>iframe</code> is the easiest way to generate a widget &#8211; you host a small file on your web site which contains the information you want to show, like the <a href="http://digg.com/tools/diggthis.php?u=http%3A//hehe2.net/linux-general/linuxcom-to-bring-social-web-to-linux-geeks/&amp;t=Linux.com%20to%20Bring%20%u201CSocial%20Web%u201D%20To%20Linux%20Geeks%3F" target="_blank">Digg button</a> for example, and get the JavaScript on the client side to build the URL to it. In the case of Digg the client side JavaScript builds a URL based on the current posts URL.</p>
<pre class="javascript" name="code">
document.write('<iframe src="http://yoururl" width="50" height="50"></iframe>');
</pre>
<p>To install the widget all you have to do is to point the user at your bit of JavaScript:</p>
<pre class="html" name="code">
<script src="http://yoururl/script.js" type="text/javascript"></script>
</pre>
<p>You can pass any variables you want through to the user at this point by simply making them JavaScript variables, and using the JavaScript to build up the <code>iframe</code> URL based on these variables.</p>
<pre class="html" name="code">
<script type="text/javascript">
	var greeting = 'hello world';
</script>
<script src="http://yoururl/script.js" type="text/javascript"></script>
</pre>
<p>If you want your widget to be able to appear multiple times on the same webpage, you need to remember to set all the variables to <code>null</code> at the end of your JavaScript file.</p>
<p>That&#8217;s it! <code>iframe</code> based widgets are very easy to build and to use, however they do come with their downsides. The biggest of these is that the user can&#8217;t customise the widget at all &#8211; it lives within an <code>iframe</code> and therefore is untouchable by CSS. That&#8217;s why certain widgets, like the twitter widget, which are made entirely on the client side in JavaScript.</p>
<h4>Client Side</h4>
<p>A widget that is built in JavaScript on the client side is definitely the harder option. For this you have to make the JavaScript file create all the HTML, write out a basic style to apply to the HTML and load in the data. When building this try to avoid using frameworks to build the HTML, this only creates more request for your web servers and make the widget slower to load. Instead resort to using the classical JavaScript methods for creating elements.</p>
<pre class="javascript" name="code">
document.write('
<div id="your_id"></div>

');
var widget = document.getElementById('you_id');
var div = document.createElement('div');
div.innerHTML = 'Hello World';
widget.appendChild(div);
</pre>
<p>You will have to load your data in from another source, and for this I recommend extending your API to give you a JavaScript variable followed by the JSON encoded data. Here&#8217;s an example from <a href="http://api.tweetmeme.com/popular.js?count=5&amp;category=all" target="_blank">tweetmeme</a>.</p>
<h4>Pitfalls</h4>
<p>There are a lot of difficulties involved in creating widgets and here are just a few of them:</p>
<ul>
<li>AJAX won’t work! You cannot post information between domains. </li>
<li>Don’t use a JavaScript framework &#8211; for a simple widget it’s is over kill. </li>
<li>Try to keep the requests down. These widgets are coming from your servers. </li>
<li>Anonymise the JavaScript, you don’t want it conflicting with other JavaScript. </li>
<li>Minimize your JavaScript. This will save on bandwidth for you, and make the widget faster to load.&#160; </li>
</ul>
<h4>Questions</h4>
<p>If you have any questions, or want to show off any widgets you have made please comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2009/03/15/building-javascript-widgets/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
