<?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>theChrisWalker.net &#187; Javascript</title>
	<atom:link href="http://thechriswalker.net/tag/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://thechriswalker.net</link>
	<description>I like Web Development</description>
	<lastBuildDate>Tue, 31 Aug 2010 07:42:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>HTML5 WebSockets: the demo (part 2)</title>
		<link>http://thechriswalker.net/2010-08/html5-websockets-the-demo-part-2.html</link>
		<comments>http://thechriswalker.net/2010-08/html5-websockets-the-demo-part-2.html#comments</comments>
		<pubDate>Mon, 16 Aug 2010 20:40:43 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Not Code]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[WebSockets]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=219</guid>
		<description><![CDATA[For my next trick, here&#8217;s the code of the websockets demo. I&#8217;m afraid you&#8217;ll have to run it on your own machine, and you&#8217;ll need PHP5.3 but that&#8217;s all. I reckon an up to date XAMPP should probably do the trick. WebSocket Demo Code To use it, read the README file, it shows how to [...]]]></description>
			<content:encoded><![CDATA[<p>For my next trick, here&#8217;s the code of the websockets demo. I&#8217;m afraid you&#8217;ll have to run it on your own machine, and you&#8217;ll need PHP5.3 but that&#8217;s all. I reckon an up to date XAMPP should probably do the trick.</p>
<p><a href="/websocket-demo.tgz" title="WebSockets Demo Code">WebSocket Demo Code</a></p>
<p>To use it, read the README file, it shows how to run the server, and then you can open clients in your modern browser and see them intercommunicate. </p>
<p>Note: The code is very basic, so treat it kindly&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2010-08/html5-websockets-the-demo-part-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 WebSockets, very cool. (part 1)</title>
		<link>http://thechriswalker.net/2010-05/html5-websockets-very-cool-part-1.html</link>
		<comments>http://thechriswalker.net/2010-05/html5-websockets-very-cool-part-1.html#comments</comments>
		<pubDate>Fri, 28 May 2010 14:45:32 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Not Code]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=215</guid>
		<description><![CDATA[I only found out about these at the Future of Web Design on Tuesday. I knew they existed in the spec but had never really investigated what they were or how they worked. Now I know I am excited. It seems they are to web apps what the XMLHTTPRequest was when it started to get [...]]]></description>
			<content:encoded><![CDATA[<p>I only found out about these at the Future of Web Design on Tuesday. I knew they existed in the spec but had never really investigated what they were or how they worked. Now I know I am excited. It seems they are to web apps what the XMLHTTPRequest was when it started to get used for AJAX. So let&#8217;s look at what they are, and then why they can be so beneficial to web development. It&#8217;s also worth pointing out at this stage that only Chrome 4+ (I think that version, I&#8217;m writing from memory) supports WebSockets natively although apparently Mozilla want to implement them in the next iteration of Firefox (they are already available with an add-on), so don&#8217;t expect to be using them in any non-specialist projects just yet.</p>
<p><span id="more-215"></span></p>
<h2>What are WebSockets?</h2>
<p>WebSockets are a connection that the browser makes to a server. Unlike a normal HTTP request, this is not a simple &#8220;send request&#8221;, &#8220;receive response&#8221; connection. This is a persistent and full-duplex connection. They can run over port 80 (or 443 for a WebSocket over TLS/SSL) and so have little difficulty with firewalls. There are some concerns over their interaction with proxies, particularly transparent ones. Once the browser sets up the WebSocket, you can send UTF8 text over it, and receive text data from the server. All this sending and receiving over data requires no more headers and only a 2 byte overhead per message.</p>
<h2>Why are they going to be so useful?</h2>
<p>It&#8217;s really the last sentence of that last paragraph that is important. The problem is trying to get data from the server when it&#8217;s available. Web apps using AJAX (or similar techniques), have to ask for data and then get a response, i.e. polling for updates or using Comet-like long polling techniques &#8211; where the request is made and the connection opened but the response is delayed until the server decides it has something useful to say. The Comet technique allows much better real-time updates from the server, but there&#8217;s still the overhead of the HTTP request headers and then the response headers/content.</p>
<p>WebSockets aim to alleviate both issues. Once the socket is open, data can flow from the server to the client whenever the server decides it wants to. Also the client can send information to the server without have to send any extra headers, any info it receives from the server is also header free and therefore the process is very efficient. HTTP headers tend to bulk up with Cookies and remain the same size irrespective of the payload sent.</p>
<h2>Do you have an example I can actually use?</h2>
<p>I do, but it&#8217;s not exactly ready for distribution yet. I built a very basic chat client that uses WebSockets as a demo for myself. The hardest bit was writing a socket server in PHP that could handle multiple clients and manage the broadcasting of data to them. I will post all the code in part 2 &#8212; watch this space! (in the mean time a search for &#8220;websocket&#8221; on Google Code will find you some examples (it&#8217;s what I based my code on&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2010-05/html5-websockets-very-cool-part-1.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Xbox Live Gamercard API</title>
		<link>http://thechriswalker.net/2009-12/xbox-live-gamercard-api.html</link>
		<comments>http://thechriswalker.net/2009-12/xbox-live-gamercard-api.html#comments</comments>
		<pubDate>Thu, 31 Dec 2009 11:34:25 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[xbox]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=155</guid>
		<description><![CDATA[So, got decided to join most of my friends and I got an Xbox 360. Me being me though, I got interested in the way that all the information about your &#8220;Gamertag&#8221; is stored an accessible on the xbox.com website. Wouldn&#8217;t it be fun to do something with this data! As it turns out, I [...]]]></description>
			<content:encoded><![CDATA[<p>So, got decided to join most of my friends and I got an Xbox 360. Me being me though, I got interested in the way that all the information about your &#8220;Gamertag&#8221; is stored an accessible on the xbox.com website. Wouldn&#8217;t it be fun to do something with this data!</p>
<p>As it turns out, I was beaten to the post by Duncan MacKensie (<a href="http://duncanmackenzie.net/Blog/put-up-a-rest-api-for-xbox-gamertag-data">http://duncanmackenzie.net/Blog/put-up-a-rest-api-for-xbox-gamertag-data</a>) who hosts a webservice to retrieve gamer data from Microsoft. <del datetime="2009-12-31T11:41:44+00:00"> I could find <strong>no</strong> details about how this service works, where the data comes from or anything! Either he has a relationship with Microsoft, or he scrapes xbox.com but either way, the data seems pretty consistent and reliable.</del> <em>Actually it turns out this information was right there on his website&#8230; <a href="http://www.duncanmackenzie.net/Blog/if-you-are-wondering-where-i-get-my-xbox-live-info">http://www.duncanmackenzie.net/Blog/if-you-are-wondering-where-i-get-my-xbox-live-info</a> So he gets it as part of his membership to the Xbox Community Developer Program.</em></p>
<p>However, the webservice is great, and returns XML which is fine, but I thought it would be more useful to me to have a PHP API for this data. So I wrote one which retrieves data from Duncans webservice.</p>
<p> <span id="more-155"></span></p>
<p>Then I thought wouldn&#8217;t it be great to be able to use this dynamically in a webpage, so I wrote a service frontend which will return JSON formatted data. Then I thought wouldn&#8217;t it be useful to let other people use this as well, so I modified it and it can now cope with JSONP requests with a &#8220;_callback&#8221; parameter.</p>
<p>OK, so what does this all mean.</p>
<p><strong>The PHP</strong></p>
<p>The class is called gamertag and the usage is very simple:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// include the class file</span><br />
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">&quot;gamertag.php&quot;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//instantiate</span><br />
<span style="color: #000088;">$G</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Gamertag<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thechriswalker'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//get data</span><br />
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$G</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$G</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>which outputs something like this:</p>
<pre class='code'>Array
(
    [Gamertag] => thechriswalker
    [AccountStatus] => Silver
    [State] => Valid
    [ProfileUrl] => http://live.xbox.com/member/thechriswalker
    [TileUrl] => http://avatar.xboxlive.com/avatar/thechriswalker/avatarpic-l.png
    [AvatarFullUrl] => http://avatar.xboxlive.com/avatar/thechriswalker/avatar-body.png
    [Country] => United Kingdom
    [Location] => Bradninch
    [Bio] =>
    [Reputation] => 58.72229
    [ReputationImageUrl] => http://live.xbox.com/xweb/lib/images/gc_repstars_external_12.gif
    [Zone] => Recreation
    [GamerScore] => 230
    [PresenceInfo] => Array
        (
            [Valid] => true
            [Info] => Last seen 12/29/09   playing Modern Warfare® 2
            [Info2] =>
            [LastSeen] => Tue, 29 Dec 2009 21:35:22 +0000
            [Online] => false
            [StatusText] => Offline
            [Title] => Modern Warfare® 2
        )

    [RecentGames] => Array
        (
            [0] => Array
                (
                    [Name] => Modern Warfare® 2
                    [TotalAchievements] => 50
                    [TotalGamerScore] => 1000
                    [Image32Url] => http://tiles.xbox.com/tiles/Z+/tF/12dsb2JgbA9ECgQJGgYfVl5UL2ljb24vMC84MDAwIAABAAAAAPhq63g=.jpg
                    [Image64Url] => http://tiles.xbox.com/tiles/CE/Vx/0Gdsb2JhbC9ECgQJGgYfVl5UL2ljb24vMC84MDAwAAAAAAAAAP9eRRc=.jpg
                    [LastPlayed] => Tue, 29 Dec 2009 21:32:52 +0000
                    [Achievements] => 9
                    [GamerScore] => 115
                    [DetailsURL] => http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3a%60m%2fl%3b%7cw&amp;compareTo=thechriswalker
                )

            [1] => Array
                (
                    [Name] => PGR 4
                    [TotalAchievements] => 60
                    [TotalGamerScore] => 1250
                    [Image32Url] => http://tiles.xbox.com/tiles/Y1/qn/0Gdsb2JgbA9ECgR8GgMfWSlaL2ljb24vMC84MDAwIAABAAAAAP+IWnw=.jpg
                    [Image64Url] => http://tiles.xbox.com/tiles/DP/ST/12dsb2JhbC9ECgR8GgMfWSlaL2ljb24vMC84MDAwAAAAAAAAAPi89BM=.jpg
                    [LastPlayed] => Mon, 28 Dec 2009 16:59:25 +0000
                    [Achievements] => 5
                    [GamerScore] => 115
                    [DetailsURL] => http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3a%15%18*iAq%0b&amp;compareTo=thechriswalker
                )

        )

)</pre>
<p>So now we can easily get at the data. The source code for the class (which is not fully tested, but the basics work!) is at <a href="http://thechriswalker.net/xbox360/gamertag.source.php">http://thechriswalker.net/xbox360/gamertag.source.php</a> (NB it requires either PHP5 (for json_encode) or the PEAR Services_JSON class if you want to use the &#8220;getJSON()&#8221; method).</p>
<p><strong>The JSON</strong></p>
<p>PHP is well and good but what if I want to use a JSON/JSONP (JSONP is for cross-domain information requesting and is very useful for public information services, see http://en.wikipedia.org/wiki/JSON#JSONP) request, well, that can be done at <a href="http://thechriswalker.net/xbox360/?gamertag=YOUR_GAMERTAG">http://thechriswalker.net/xbox360/?gamertag=YOUR_GAMERTAG</a> for the straight JSON or <a href="http://thechriswalker.net/xbox360/?gamertag=YOUR_GAMERTAG&#038;_callback=YOUR_CALLBACK_FUNCTION_NAME"> http://thechriswalker.net/xbox360/?gamertag=YOUR_GAMERTAG&#038;_callback=YOUR_CALLBACK_FUNCTION_NAME</a> for JSONP.</p>
<p>The first returns just JSON with a content type &#8220;application/json&#8221; and the second returns a javascript function call to your callback function with the JSON object as the only parameter and a content type of &#8220;text/javascript&#8221;.</p>
<p>These enabled me to build a simple Google Gadget to display a Gamercard:</p>
<p><center><br />
<script src="http://www.gmodules.com/ig/ifr?url=http://thechriswalker.net/xbox360/xblgamercard.xml&amp;up_gamertag=thechriswalker&amp;synd=open&amp;w=600&amp;h=200&amp;title=Xbox+Live+Gamertag+Info+for+%22chriswalker%22&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script></center></p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2009-12/xbox-live-gamercard-api.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Multiple Drag and Drop between two lists with jQuery</title>
		<link>http://thechriswalker.net/2009-02/multiple-drag-and-drop-between-two-lists-with-jquery.html</link>
		<comments>http://thechriswalker.net/2009-02/multiple-drag-and-drop-between-two-lists-with-jquery.html#comments</comments>
		<pubDate>Tue, 10 Feb 2009 12:26:58 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=64</guid>
		<description><![CDATA[I wanted this functionality for a project a while ago. I google&#8217;d and found that lots of others did too, but no one had done it. Or at least not in a way that I could understand. In fact, I&#8217;m not sure I completely understand it anymore. It works very well, but also it could [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted this functionality for a project a while ago. I google&#8217;d and found that lots of others did too, but no one had done it. Or at least not in a way that I could understand. In fact, I&#8217;m not sure I completely understand it anymore. It works very well, but also it could have some improvement. I would like to be able to drag the mouse to create a selection, but this in itself poses the difficultly of how to distinguish a &#8220;drag-to-move&#8221; from a &#8220;drag-to-select&#8221;. </p>
<p>Still I found it an interesting proof-of-concept and maybe you will too. The test can be found here: <a href='/select-drag/' title='Select and Drag Demo'>Select and Drag Demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2009-02/multiple-drag-and-drop-between-two-lists-with-jquery.html/feed</wfw:commentRss>
		<slash:comments>101</slash:comments>
		</item>
		<item>
		<title>jQuery SuperSelect</title>
		<link>http://thechriswalker.net/2009-01/jquery-superselect.html</link>
		<comments>http://thechriswalker.net/2009-01/jquery-superselect.html#comments</comments>
		<pubDate>Thu, 29 Jan 2009 13:44:43 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=53</guid>
		<description><![CDATA[A little while back I was working on a project and wanted a selectbox to look a bit more pretty, but with complete backwards compatibility with regular select boxs. I.E. If I already had a select box on the page, and it had various JavaScript events hanging off it already, I wanted that to function [...]]]></description>
			<content:encoded><![CDATA[<p>A little while back I was working on a project and wanted a selectbox to look a bit more pretty, but with complete backwards compatibility with regular select boxs. </p>
<p>I.E. If I already had a select box on the page, and it had various JavaScript events hanging off it already, I wanted that to function still but I wanted the box to be prettier.</p>
<p>The first idea was to use CSS to just style the box. But then I realised that each browser and OS has it&#8217;s own different way of rendering the controls. So I turned to JavaScript, and the always useful <a href='http://jquery.com/' title='the jQuery Homepage'>jQuery</a> library. I wrote a plugin that will immediately transform any selectboxes into prettier ones, allows icons for the options, all with valid xhtml and works completely fine with JavaScript (or the plugin) disabled. Pretty cool, eh?</p>
<p>Well, I put the original demo page I designed for it back online, so <a href='/superselect/' title='the jQuery superselect plugin'>check out the plugin!</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2009-01/jquery-superselect.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
