 <?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>Broken Links &#187; Scripting</title>
	<atom:link href="http://www.broken-links.com/category/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.broken-links.com</link>
	<description>Thoughts on web development and technologies by Peter Gasston</description>
	<lastBuildDate>Fri, 30 Jul 2010 00:10:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://www.broken-links.com/?pushpress=hub'/>
		<item>
		<title>My Name In Print</title>
		<link>http://www.broken-links.com/2010/05/26/my-name-in-print/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=my-name-in-print</link>
		<comments>http://www.broken-links.com/2010/05/26/my-name-in-print/#comments</comments>
		<pubDate>Wed, 26 May 2010 13:06:31 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Miscellanea]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[glow]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[magazine]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[selfpromotion]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/?p=814</guid>
		<description><![CDATA[I hope you’ll forgive a little self-promotion, as I’d just like to play a few quick notes on my own trumpet. The latest issue of Net magazine is now on sale, and features a tutorial article, Create A Dynamic Content Panel, written by me. In the article I explain how to build a dynamic Contact [...]]]></description>
			<content:encoded><![CDATA[<p>I hope you’ll forgive a little self-promotion, as I’d just like to play a few quick notes on my own trumpet. <a href="http://www.netmag.co.uk/zine/latest-issue/issue-203">The latest issue of Net magazine</a> is now on sale, and features a tutorial article, <em>Create A Dynamic Content Panel</em>, written by me.</p>
<p>In the article I explain how to build a dynamic Contact area, as we did on our recent redesign of <a href="http://preloaded.com/">Preloaded.com</a>, using the <a href="http://www.w3.org/TR/webstorage/">Web Storage API</a> and <a href="http://www.bbc.co.uk/glow/">the BBC’s Glow Javascript library</a>.</p>
<p>I’m not sure what the rights situation is with this article, but I hope that at some point in the future I’ll be able to post it here on my blog. But in the meantime, you can buy a copy of Net magazine in the UK at all good newsagents, as the saying goes (I don’t know if it will be in overseas editions also).</p>
<p><img src="/wp-content/uploads/2010/05/tut_js-1.jpg" alt="Printed Tutorial" title="Tutorial Page 1" width="190" height="250" class="aligncenter size-full wp-image-833" /><img src="/wp-content/uploads/2010/05/tut_js-2.jpg" alt="Printed Tutorial" title="Tutorial Page 2" width="190" height="250" class="aligncenter size-full wp-image-834" /><img src="/wp-content/uploads/2010/05/tut_js-3.jpg" alt="Printed Tutorial" title="Tutorial Page 3" width="190" height="250" class="aligncenter size-full wp-image-835" /></p>
<p>On the subject of print, I’m also currently writing a book about CSS3 which should be published later this year. I’ll have more information on that nearer the time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2010/05/26/my-name-in-print/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building a better HTML5 video player with Glow</title>
		<link>http://www.broken-links.com/2010/04/14/building-a-better-html5-video-player-with-glow/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=building-a-better-html5-video-player-with-glow</link>
		<comments>http://www.broken-links.com/2010/04/14/building-a-better-html5-video-player-with-glow/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 12:52:33 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[glow]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/?p=767</guid>
		<description><![CDATA[Last year I wrote a post (Building HTML5 video controls with JavaScript) introducing the HTML5 Media Elements API and demonstrating a simple set of controls for playing video. In this (somewhat belated) follow-up I’m going to explore building a more interactive set of controls using a JavaScript UI library; I’m going to use Glow, but [...]]]></description>
			<content:encoded><![CDATA[<p>Last year I wrote a post (<a href="http://www.broken-links.com/2009/10/06/building-html5-video-controls-with-javascript/">Building HTML5 video controls with JavaScript</a>) introducing the HTML5 Media Elements API and demonstrating a simple set of controls for playing video.</p>
<p>In this (somewhat belated) follow-up I’m going to explore building a more interactive set of controls using a JavaScript UI library; I’m going to use <a href="http://www.bbc.co.uk/glow/">Glow</a>, but it could easily be adapted to <a href="http://jqueryui.com/">jQuery UI</a> or similar.</p>
<p><span id="more-767"></span></p>
<p>You can see the player I’ll be using as an example here — although it must be stressed that it’s not a final version, for reasons I’ll cover at the end:</p>
<p><a href="http://www.broken-links.com/tests/videoglow/">HTML5 &amp; Glow Video Player</a></p>
<h2>The markup</h2>
<p>The video player itself is pretty straightforward:</p>
<pre>&lt;video autobuffer controls height="180" poster="BBB_poster.jpg" width="320"&gt;
  &lt;source src="bbb.mp4" type="video/mp4"&gt;
  &lt;source src="bbb.webm" type="video/ogg"&gt;
  &lt;source src="bbb.theora.ogg" type="video/ogg"&gt;
  &lt;img alt="Film Poster" height="180" src="BBB_poster.jpg" width="320"&gt;
&lt;/video&gt;</pre>
<p>The <code>video</code> element has the <code>controls</code> attribute set, which we’ll remove with JavaScript later. Note also the <code>poster</code> attribute, which displays a still image until the video is ready to be played, at which point it displays the first frame instead.</p>
<p>Next there are two <code>source</code> elements, which serve the video to Firefox, Opera and Chrome (ogg) and Safari (mp4). Finally there’s an <code>img</code> element, which displays if the browser doesn’t have video support. <strong>Update:</strong> Added <a href="http://www.webmproject.org/">WebM</a> support.</p>
<p>As for the controls, rather than list them here I’ll ask you to view the source to see what I’ve done. Basically I’ve added a bunch of form elements; two <code>input</code> <code>image</code> types for the play and volume icons, and two <code>input</code> <code>text</code> types for the duration and volume sliders. The latter two aren’t necessary, but I wanted them there for accessibility reasons.</p>
<h2>The style</h2>
<p>How I’ve styled the player doesn’t matter too much; I’ve been influenced by the Quicktime player for the layout of the controls, but really the CSS isn’t too important here. The only thing to note is that I’ve added some rules here for screen overlays, which I’ll explain in due course:</p>
<pre>.overlay { background-repeat: no-repeat; height: 180px; position: absolute; width: 320px; }
.paused { background-color: rgba(0,0,0,0.2); background-image: url('pause.png'); background-position: left bottom; }
.play { background-image: url('play.png'); background-position: center center; }</pre>
<h2>The JavaScript</h2>
<p>You can see all the script I’ve used in the file <a href="http://www.broken-links.com/tests/videoglow/video.js">video.js</a>. I’ll go through some of the more important functions in turn.</p>
<h3>Setting up</h3>
<p>The first thing I’ve done is removed the native controls from the player for people who have JS enabled, so as not to provide two conflicting sets of controls:</p>
<pre>video[0].controls = false;</pre>
<p>Next I’ve defined some of the key variables which I’ll be using throughout the script. One of those variables, <em>volumeSlide</em>, is assigned to one of Glow’s native widgets, a <a href="http://www.bbc.co.uk/glow/docs/1.7/api/glow.widgets.slider.shtml">Slider</a>; this will be used to control the volume:</p>
<pre>volumeSlide = new glow.widgets.Slider('#volume',{bindTo:'#vol_count', buttons:false, step:0.1, min:0, max:1, size:70, val:1});</pre>
<p>You can see what all the options do in the Glow documentation, but the key ones I’ve set are for it to appear in &lt;div id=“volume”&gt;, to have a minimum value of 0 and a max of 1, and to increment in steps of 0.1. This matches the volume setting for the <code>video</code> element.</p>
<h3>Waiting for the metadata</h3>
<p>For the next step I’m going to create another slider, but this time for the duration/seek bar. In order to do this, however, I need to query the video’s metadata to know what the duration of the video is, and in Safari (which uses mp4 video) that doesn’t load before the rest of my JS has run.</p>
<p>To get around this I’ll poll the <code>readyState</code> attribute every half a second — with the <code>setInterval</code> function — until it’s value is at least 1, which means the metadata has loaded; once that’s done, I’ll load the slider:</p>
<pre>t = window.setInterval(function() {
  if (video[0].readyState >= 1) {
    window.clearInterval(t);
    durationSlide = new glow.widgets.Slider('#vid_duration',{bindTo:'#duration_count', buttons:false, step:1, min:1, max:Math.round(video[0].duration-1), size:260, val:0});
    playVid();
  }
},500);</pre>
<p>So you can see there that I’ve created the slider with a minimum value of 1 and a maximum of the duration of the video (in seconds), to increment in steps of 1. After that the setup is complete so I can begin the actual playback functions.</p>
<h3>Playback controls</h3>
<p>There are too many functions to go into in detail, so I’ll quickly go through what happens. First an overlay is placed over the top of the video, which begins playback when clicked. Next, event listeners are added to the play button, the volume icon, and the volume and duration sliders.</p>
<p>The listener on the play button runs the function <em>playControl</em>, which determines the state of playback (<em>ended</em>, <em>paused</em> or playing) and either plays or pauses the video accordingly. It also updates the icon to reflect its action (if it is paused, the icon changes to a play icon, and <span lang="la">vice versa</span>), and adds the pause overlay onto the video screen when relevant:</p>
<pre>function playControl() {
  if (video[0].paused === true) {
    video[0].play();
    /* Further functions here */
  };
} else if (video[0].ended === true) {
    video[0].play();
     /* Further functions here */
} else {
    video[0].pause();
     /* Further functions here */
}</pre>
<p>There’s a function called <em>startCount</em> which uses <code>setInterval</code> to move the duration slider along by one second while the video is playing, and a function called <em>pauseCount</em> which uses <code>clearInterval</code> to pause.</p>
<p>The <em>muteToggle</em> function does what you expect, and mutes the video; it also changes the volume icon to show that state, and disables the volume slider while it is active.</p>
<p>A further function, <em>volumeIcons</em>, sets the state of the volume icon; there are four possible icon states, which are used depending on the value of the volume.</p>
<p>And the last function, <em>secondsToTime</em>, converts second values into hour/minute/second values, allowing for the timer to be updated. This is done every second by the <em>startCount</em> function, and also used for the function which is called from the event listener on the duration slider.</p>
<p>That event is probably worth looking at in detail:</p>
<pre>glow.events.addListener(durationSlide,'slideStop',function(event){
  video[0].currentTime = event.currentVal;
  var currentSecs = secondsToTime(event.currentVal);
  vidTimer.text(currentSecs.h + ':' + currentSecs.m + ':' + currentSecs.s);
});</pre>
<p>Using the <code>slideStop</code> event I can check when the slider has been moved, and first set the video to begin playback from that point, then update the timer with the same values. The volume slider has a similar event set on it.</p>
<h2>Next steps</h2>
<p>So as a reminder, here’s what I have so far:</p>
<p><a href="http://www.broken-links.com/tests/videoglow/">HTML5 &amp; Glow Video Player</a></p>
<p>Please bear in mind that this is very much a work in progress; I started writing the controls without Glow and introduced it at a later stage, so some of the JavaScript could do with being optimised.</p>
<p>The markup for the controls could also do with some extra work to make them fully accessible, which they probably aren’t right now. Also, all of the dimensions are built around this video size, and won’t scale if different sized videos are used.</p>
<p>I hope to return to this topic when I have more time, and create a robust set of video player controls which can be used in any site without extra work.</p>
<p>Please feel free to let me know if you encounter any bugs or oddities as you use this; it will help with the next stage of development.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2010/04/14/building-a-better-html5-video-player-with-glow/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building Preloaded.com: The Front-end</title>
		<link>http://www.broken-links.com/2010/01/21/building-preloaded-com-the-front-end/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=building-preloaded-com-the-front-end</link>
		<comments>http://www.broken-links.com/2010/01/21/building-preloaded-com-the-front-end/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 15:53:37 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[glow]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/?p=686</guid>
		<description><![CDATA[This post discusses the redesign project of my employer’s own website, Preloaded.com, and is cross-posted from there with permission.

At the beginning of the redesign project we agreed some design tenets: the new site should be a best-practice showcase and an opportunity to learn and use some of the latest web technologies; and it should employ existing services where practical.]]></description>
			<content:encoded><![CDATA[<p><em>This subject of this post is the redesign of my employer’s website, <a href="http://preloaded.com/">Preloaded.com</a>, and is cross-posted from the Preloaded blog with permission.</em></p>
<p>At the beginning of the redesign project we agreed some design tenets: the new site should be a best-practice showcase and an opportunity to  learn and use some of the latest web technologies; and it should employ existing services where practical.</p>
<p><span id="more-686"></span></p>
<p>To achieve the former we targeted users with the most modern web browsers, using the <a href="http://en.wikipedia.org/wiki/Progressive_enhancement">graceful (or progressive) enhancement</a> method to ensure that even with older technology, no-one would be left unable to read all of the site content.</p>
<p>The most obvious example of this is in the design of the buttons; users with a decent browser (e.g. Firefox or Safari) would see these with rounded corners — because these browsers are capable of producing them natively with the CSS3 <em>border-radius </em>declaration — while users of other browsers (e.g. Internet Explorer) would see them square:</p>
<p><img src="http://preloaded.com/site_media/uploads/blog/preloaded_frontend/comparison.jpg" alt="" width="475" height="243" /></p>
<p><em>Browser comparison. Top: Safari 4; Bottom: Internet Explorer 8</em></p>
<p>While all users see the same content, those with a modern browser are rewarded with a slightly improved experience. We used other variations of this method elsewhere throughout the site.</p>
<h2>Technology</h2>
<h3>Web Fonts</h3>
<p>In order to achieve brand consistency we had a font in mind which we were going to implement using the <a href="http://cufon.shoqolate.com/">Cufón</a> Javascript technique. During the process of adding this the font foundry clarified their licensing, excluding this font from online use in this way, so we had to scrap it and look for a different angle.</p>
<p>While we were trying out various alternatives using Flash and Javascript (we now know more about font licensing and implementation than we ever wanted to), a new solution presented itself. Using <a href="http://www.fontsquirrel.com/fontface/generator">Font Squirrel’s web font generator</a> and <a href="http://paulirish.com/2009/bulletproof-font-face-implementation-syntax/">Paul Irish’s bulletproof syntax</a> we were able to use the browsers’ own built-in font support (with <em>@font-face</em>) and achieve our desired result for 95% of our users; the other 5% will see a standard system font, as per the graceful en­hance­ment method.</p>
<h3>Glow</h3>
<p><a href="http://www.bbc.co.uk/glow/">Glow</a> is a BBC-developed Javascript library, with a jQuery-like syntax but a focus on interface widgets, which makes it easy to create animations and UI elements for websites. Having already used it briefly on a project earlier in the year, we decided it would be a good fit for what we wanted — and something new to learn.</p>
<p>The image carousel on the homepage was made with Glow, as was the slide-down contact details on each page, and the lightbox overlay effect for screenshots on the case study pages.</p>
<p>The only drawback we found with Glow was a bug in their carousel rendering in IE8; this meant that we had to force <a href="http://blogs.msdn.com/ie/archive/2008/08/27/introducing-compatibility-view.aspx">compatibility view</a> for IE8 to display as IE7, but it’s something we’re hoping to change after the next Glow release.</p>
<h3>HTML5</h3>
<p>Under the bonnet we used some cutting-edge code to mark up our content. HTML5 is a very new specification and still somewhat in a state of flux, but we used it in two different ways:</p>
<p>First was to provide semantic structure to the pages with the new structural elements (the definitions of which are still being discussed, so may not be completely correct — <a href="http://html5doctor.com/">HTML5 Doctor</a> was an invaluable resource for this).</p>
<p>Second, and of more impact to the user, was using <em>sessionStorage</em> to take advantage of the opportunities for storing data in the user’s browser. We used this in conjunction with Glow to create the carousel and slide-down effects; if you have a modern browser these are created only once and held in the browser’s storage, whereas older browsers create them anew each time you visit the page — this leads to the site being somewhat snappier in modern browsers.</p>
<h2>Conclusion</h2>
<p>Working with brand new and cutting edge features meant spending time chasing down false leads and up blind alleys, but was a great way of learning and gave us invaluable experience to take into the sites we make for our clients in future.</p>
<p>There are still one or two changes which we’ll be rolling into the site in the coming months, but if you spot any problems — or just want to talk more in-depth about the methods and techniques we’ve used — don’t hesitate to leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2010/01/21/building-preloaded-com-the-front-end/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mozilla release Bespin Embedded preview</title>
		<link>http://www.broken-links.com/2009/11/18/mozilla-release-bespin-embedded-preview/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mozilla-release-bespin-embedded-preview</link>
		<comments>http://www.broken-links.com/2009/11/18/mozilla-release-bespin-embedded-preview/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 10:27:07 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bespin]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[mozilla]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/?p=622</guid>
		<description><![CDATA[Mozilla’s Bespin is a code editor built using web technologies. It’s still in its infancy, but shows promise. A new release, Bespin Embedded, lets you use the basic editor functionality on your own websites, using just a couple of lines of Javascript. If you don’t want to download it yourself, I’ve got a working demo. [...]]]></description>
			<content:encoded><![CDATA[<p>Mozilla’s <a href="https://bespin.mozilla.com/">Bespin</a> is a code editor built using web technologies. It’s still in its infancy, but shows promise. A new release, <a href="http://mozillalabs.com/bespin/2009/11/13/bespin-embedded-first-preview-release/">Bespin Embedded</a>, lets you use the basic editor functionality on your own websites, using just a couple of lines of Javascript. If you don’t want to download it yourself, <a href="http://www.broken-links.com/tests/bespin-embedded/">I’ve got a working demo</a>. The editor doesn’t really do much at the moment, so this is really only a proof of concept.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2009/11/18/mozilla-release-bespin-embedded-preview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the GeoLocation API</title>
		<link>http://www.broken-links.com/2009/11/11/using-the-geolocation-api/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-the-geolocation-api</link>
		<comments>http://www.broken-links.com/2009/11/11/using-the-geolocation-api/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 00:32:42 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/?p=613</guid>
		<description><![CDATA[With the <a href="http://www.brandon-hall.com/workplacelearningtoday/?p=7870">rapid growth of the mobile web</a>, location-aware services are very much in-demand; the <a href="http://dev.w3.org/geo/api/spec-source.html">GeoLocation API</a> was proposed to cater to this need.

Implementation is spotty at the moment; Firefox 3.5 supports it, as does Safari for iPhone (although not on the desktop, <abbr title="as far as I can see">AFAICS</abbr>). But it's so <a href="https://developer.mozilla.org/en/using_geolocation">simple to use</a>, I've no doubt it will be adopted rapidly.]]></description>
			<content:encoded><![CDATA[<p>With the <a href="http://www.brandon-hall.com/workplacelearningtoday/?p=7870">rapid growth of the mobile web</a>, location-aware services are very much in-demand; the <a href="http://dev.w3.org/geo/api/spec-source.html">GeoLocation API</a> was proposed to cater to this need.</p>
<p>Implementation is spotty at the moment; Firefox 3.5 supports it, as does Safari for iPhone (although not on the desktop, <abbr title="as far as I can see">AFAICS</abbr>). But it’s so <a href="https://developer.mozilla.org/en/using_geolocation">simple to use</a>, I’ve no doubt it will be adopted rapidly.</p>
<p><span id="more-613"></span></p>
<p>I’ve put together <a href="http://www.broken-links.com/tests/geolocation/">a small demo of the GeoLocation API</a> in action; it uses data from the Arts Council England website, so visitors from outside of England won’t get any meaningful results from this, I’m afraid. Visitors from England will probably get best results using a mobile device (such as an iPhone).</p>
<p>First, the JavaScript function tests that the browser supports the API:</p>
<pre>var hasGeoLocation = navigator.geolocation ? true : false;
if (hasGeoLocation === true) { ... }</pre>
<p>If so, it requests the current position from the browser using the <code>getCurrentPosition</code> method (the user will have to give permission for this) and passes the result into a function:</p>
<pre>navigator.geolocation.getCurrentPosition(function(position) {
    getJSON(position.coords.latitude,position.coords.longitude);
});</pre>
<p>This result is used in the latitude and longitude attributes of the coords object, which I then use for the rest of my function (using <a href="http://docs.jquery.com/Ajax/jQuery.getJSON">jQuery’s getJSON function</a> to mine microformatted data from <a href="http://www.artscouncil.org.uk/map/">the map page</a> of the Arts Council England website, transforming it using <a href="http://microformatique.com/optimus/">Optimus</a>, then parsing it back into HTML for my demo).</p>
<p>There’s a lot more to this, of course; the API is quite extensive, covering altitude and heading as well as lat/long, and there’s a massive amount of <a href="http://en.wikipedia.org/wiki/Geotagging">geotagged</a> data available (<a href="http://flickr.com/">Flickr</a> photos, for example). Hopefully my demo serves as an example of how easy it is to make the move into the mobile space.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2009/11/11/using-the-geolocation-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building HTML5 video controls with JavaScript</title>
		<link>http://www.broken-links.com/2009/10/06/building-html5-video-controls-with-javascript/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=building-html5-video-controls-with-javascript</link>
		<comments>http://www.broken-links.com/2009/10/06/building-html5-video-controls-with-javascript/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 16:04:06 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/?p=582</guid>
		<description><![CDATA[The HTML5 video element is now included in Firefox, Safari &#38; Chrome, and on its way in Opera. By using JavaScript to access the media elements API it’s easy to build your own custom controls for it; in this article I’m going to show how I built a (very) basic control interface. A quick disclaimer: [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#video">HTML5 video element</a> is now included in Firefox, Safari &amp; Chrome, and on its way in Opera. By using JavaScript to access the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/media-elements.html#media-elements">media elements API</a> it’s easy to build your own custom controls for it; in this article I’m going to show how I built a (very) basic control interface.</p>
<p><span id="more-582"></span></p>
<p>A quick disclaimer: my JavaScript is a little rusty, so may not use best practice throughout; if you can see a way my code could be better, don’t hesitate to let me know.</p>
<p>Anyway, <a href="http://www.broken-links.com/tests/video/">here’s the finished demo</a>.</p>
<h2>Getting started</h2>
<p>First you must include the <code>video</code> element. <del datetime="2010-04-01T16:39:46+00:00">There are a number of attributes available, but for our purposes we need define only the <code>src</code>, which is the URI of our video file</del> <strong>Update</strong>: changed the markup to use the more correct <code>source</code> elements inside <code>video</code>.</p>
<pre>&lt;video&gt;
  &lt;source src="filename.mp4"&gt;
  &lt;source src="filename.webm"&gt;
  &lt;source src="filename.ogg"&gt;
&lt;/video&gt;</pre>
<p>The video has been encoded twice, once in Theora and once in H264, to cater for different browsers; <a href="http://camendesign.com/code/video_for_everybody">Kroc Camen’s Video for Everybody</a> explains the reasons behind this (and how to make a bulletproof player). <strong>Update:</strong> added <a href="http://www.webmproject.org/">WebM</a> support.</p>
<p>Having marked up a few controls with HTML (I’ve used <code>id</code> attributes on all of them to make this demo easier), the next step is to write the JavaScript to access the API (<a href="https://developer.mozilla.org/En/NsIDOMHTMLMediaElement">which is well explained in this article at the Mozilla Developer Center</a>) for the controls.</p>
<p>The first and most important control is the play/pause button; for this I’ve written a function which checks so see if the <code>paused</code> attribute is true or false, and triggers the <code>play()</code> or <code>pause()</code> methods accordingly:</p>
<pre>play.addEventListener('click',playControl,false);
function playControl() {
    if (video.paused == false) {
        video.pause();
        this.firstChild.nodeValue = 'Play';
        pauseCount();
    } else {
        video.play();
        this.firstChild.nodeValue = 'Pause';
        startCount();
    }
}</pre>
<p>You’ll notice that it also updates the control text to indicate the action that the control will perform. There are also two function calls — <code>pauseCount()</code> and <code>startCount()</code> — which control the timer shown next to the play button.</p>
<p>The timer uses the <code>currentTime</code> and <code>duration</code> attributes (although the latter doesn’t seem to be currently supported by Chrome). To get the current time I’ve used <code>setInterval</code> to create a loop:</p>
<pre>function startCount() {
    t = window.setInterval(function() {
        if (video.ended != true) {
            timer.firstChild.nodeValue = Math.round(video.currentTime + 1);
        } else {
            play.firstChild.nodeValue = 'Play';
            window.clearInterval(t);
        }
    },1000);
}</pre>
<p>First it uses an <code>if…else</code> statement on the <code>ended</code> attribute to check that the video has not finished playing; if it hasn’t, it updates the timer with <code>currentTime</code> (plus a little maths). If the video HAS finished, it uses <code>clearInterval</code> to stop the loop; this is also used in a function to pause the timer if the pause control is used:</p>
<pre>function pauseCount() {
    window.clearInterval(t);
}</pre>
<p>To complete the controls we have functions to increase and decrease the volume. Both are very similar:</p>
<pre>vUp.addEventListener('click',volUp,false);
function volUp() {
    if (video.volume < 1) {
        video.volume = Math.round((video.volume + 0.1)*10)/10;
        volume.firstChild.nodeValue = Math.round(video.volume*10);
    }
}</pre>
<p>First they check that the minimum/maximum limits have not been reached, and increase/decrease the <code>volume</code> attribute if not. Volume is on a scale of 0 to 1, and this function changes that value in increments of 0.1. The on-screen volume counter is also changed accordingly.</p>
<p>There are a number of small details elsewhere in the script, so feel free to have a dig through to see what else I’ve done; <a href="http://www.broken-links.com/tests/video/">here’s another link to the finished demo</a>.</p>
<h2>Further steps</h2>
<p>I’ve obviously used a little CSS to tidy the controls up, but a lot more could be done; using images instead of text, for example, or perhaps using something like <a href="http://jqueryui.com/">jQuery’s user interface library</a> to make more dynamic controls.</p>
<p>This article was intended only to show how easy it is to get started; what will be exciting is to see how these techniques can be expanded upon.</p>
<p><strong>Update:</strong> If you found this article useful, you may be interested to know that I returned to this subject in a later post, <a href="http://www.broken-links.com/2010/04/14/building-a-better-html5-video-player-with-glow/">Building a better HTML5 video player with Glow</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2009/10/06/building-html5-video-controls-with-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Quick testing for console.log</title>
		<link>http://www.broken-links.com/2009/02/04/quick-testing-for-consolelog/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=quick-testing-for-consolelog</link>
		<comments>http://www.broken-links.com/2009/02/04/quick-testing-for-consolelog/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 23:50:28 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/?p=332</guid>
		<description><![CDATA[I'm happy to see that <a href="http://blogs.msdn.com/ie/archive/2008/09/09/what-s-new-for-jscript-for-ie8-beta-2.aspx">IE8 includes native support for console.log</a>, the JavaScript command which writes information to your preferred debugging tool (mine is <a href="http://getfirebug.com/">Firebug</a>). If you leave it in your code &#8211; as I did on my latest project &#8211; it throws an error in IE7 &#038; below.]]></description>
			<content:encoded><![CDATA[<p>I’m happy to see that <a href="http://blogs.msdn.com/ie/archive/2008/09/09/what-s-new-for-jscript-for-ie8-beta-2.aspx">IE8 includes native support for console.log</a>, the JavaScript command which writes information to your preferred debugging tool (mine is <a href="http://getfirebug.com/">Firebug</a>). If you leave it in your code – as I did on my latest project – it throws an error in IE7 &amp; below.</p>
<p>The way around it is to quickly check that the command is supported by your browser, and to provide an alternative (I use that old standby, <code>alert</code>) if not; and the quickest way to do that is with the <a href="http://javascriptant.com/articles/28/the-conditional-operator-ternary-operactor"><code>if…else</code> shorthand</a>:</p>
<pre>window.console ? console.log(foo) : alert(foo);</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2009/02/04/quick-testing-for-consolelog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Very quick equal-height columns in jQuery</title>
		<link>http://www.broken-links.com/2009/01/20/very-quick-equal-height-columns-in-jquery/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=very-quick-equal-height-columns-in-jquery</link>
		<comments>http://www.broken-links.com/2009/01/20/very-quick-equal-height-columns-in-jquery/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 11:19:02 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[DOM]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/?p=320</guid>
		<description><![CDATA[I'm having a bit of a love affair with <a href="http://jquery.com/">jQuery</a>, the Javascript library, at the moment. I know my way around JS but am far from an expert, so jQuery's simple syntax is a godsend for me, and provides huge savings in my development time.]]></description>
			<content:encoded><![CDATA[<p>I’m having a bit of a love affair with <a href="http://jquery.com/">jQuery</a>, the Javascript library, at the moment. I know my way around JS but am far from an expert, so jQuery’s simple syntax is a godsend for me, and provides huge savings in my development time.</p>
<p>One quick technique I used yesterday was to make three elements of equal height; it’s very simple and won’t cope with dynamic content, but is perfectly suitable for simple page layouts.</p>
<p><span id="more-320"></span></p>
<p>The code simply takes the elements involved (I’m using two in this example), calculates the height of the tallest, and sets the heights of the others to match:</p>
<pre>var highestCol = Math.max($('#element1').height(),$('#element2').height());
$('.elements').height(highestCol);</pre>
<p>There’s nothing groundbreaking about this, and I’m certainly not claiming to have invented the technique (there’s <a href="http://www.cssnewbie.com/equal-height-columns-with-jquery/">another version here</a>, for example); I provide it here only as an example of how jQuery makes layout problems easy to resolve.</p>
<p>I’ve since discovered that there’s <a href="http://www.cssnewbie.com/equalheights-jquery-plugin/">a plugin</a> which will do this for you, which is much more useful if you want to work with multiple elements, but mine has the advantage of being only two lines!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2009/01/20/very-quick-equal-height-columns-in-jquery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>What I saw at @media 2008</title>
		<link>http://www.broken-links.com/2008/06/04/what-i-saw-at-media-2008/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=what-i-saw-at-media-2008</link>
		<comments>http://www.broken-links.com/2008/06/04/what-i-saw-at-media-2008/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 23:32:26 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[atmedia]]></category>
		<category><![CDATA[atmedia2008]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[presentations]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/?p=171</guid>
		<description><![CDATA[As is customary (or as customary as ‘twice’ can be), here is a quick round-up of the sessions I attended at @media this year, with links to slides where available (which, as I type this, is pretty much unavailable). Sessions which I found particularly interesting should be covered in more detail later, and I’ll update [...]]]></description>
			<content:encoded><![CDATA[<p>As is customary (or as customary as ‘twice’ can be), here is a quick round-up of the sessions I attended at <a href="http://www.vivabit.com/atmedia2008/london/">@media</a> this year, with links to slides where available (which, as I type this, is pretty much unavailable).</p>
<p>Sessions which I found particularly interesting should be covered in more detail later, and I’ll update here as I find more presentations.</p>
<p><span id="more-171"></span></p>
<h3><a href="http://veen.com/data-design.pdf" title="PDF: Designing our way through data" type="application/pdf">Designing our way through data</a> (<a href="http://www.veen.com/jeff/">Jeff Veen</a>)</h3>
<p>How good design can make sense of data (and how bad design can complicate it too much), and using user feedback to make data findable.</p>
<h3>For example: BBC and Edenbee (Tom Cartwright &amp; Clare Roberts, and <a href="http://www.jeckecko.net/blog/">James Box</a>)</h3>
<p>On the challenges posed by redesigning on of the <a href="http://bbc.co.uk/home/beta">most visible homepages</a> in the world, and on how to build a <a href="http://www.edenbee.com/">social community</a>.</p>
<h3><a href="http://lachy.id.au/dev/presentation/hands-on-html5/">Getting your hands dirty with HTML5</a> (James Graham &amp; <a href="http://lachy.id.au/">Lachlan Hunt</a>)</h3>
<p>Introducing the new structural elements (which I will definitely write more about later), and what HTML5 you can use right now.</p>
<h3>Underpants over my trousers (<a href="http://malarkey.co.uk/">Andy Clarke</a>)</h3>
<p>What inspiration we can take from the narrative devices of comics? Andy Clarke is always an entertaining speaker, and this was no exception — although I’d seen some of it before.</p>
<h3><a href="http://superfluousbanter.org/presentations/2008/">Details make the difference</a> (<a href="http://superfluousbanter.org/">Dan Rubin</a>)</h3>
<p>One of the best and most practical of the sessions I saw; tips on how to make compelling designs and details.</p>
<h3><a href="http://nate.koechley.com/blog/2008/06/11/slides-professional-frontend-engineering/">Professional front end engineering</a> (<a href="http://nate.koechley.com/blog/">Nate Koechley</a>)</h3>
<p>A call for professionalism in the web development community. Very interesting, although recapped some of the points from <a href="http://nate.koechley.com/blog/2007/06/12/high-performance-web-sites/">last year’s talk</a>.</p>
<h3>Building on the shoulders of giants (<a href="http://snook.ca/jonathan/">Jonathan Snook</a>)</h3>
<p>How to make practical use of frameworks, libraries and APIs in your work. Revealed some new tools which I will check out.</p>
<h3>For example: The Guardian and Dopplr (<a href="http://marc.baffl.co.uk/">Marc Pacheco</a> and <a href="http://www.hackdiary.com/">Matt Biddulph</a>)</h3>
<p>Similar to the earlier ‘For example’ session; a look at the practicalities of building a <a href="http://www.guardian.co.uk/">large content portal</a> and a <a href="http://www.dopplr.com/">social community</a>. The latter displayed how to take advantage of the many APIs that exist.</p>
<h3><a href="http://www.paciellogroup.com/blog/misc/ARIA/atmedia2008/">WAI-ARIA – it’s easy</a> (<a href="http://www.paciellogroup.com/blog/">Steve Faulkner</a>)</h3>
<p>I didn’t know what <a href="http://www.w3.org/WAI/intro/aria">WAI-ARIA</a> was before this session, but this was a comprehensive and practical introduction.</p>
<h3><a href="http://www.w3.org/2008/Talks/05-atmedia-ishida/slides.pdf" title="PDF: Global design: characters, language, and more" type="application/pdf">Global design: characters, language, and more</a> (<a href="http://rishida.net/">Richard Ishida</a>)</h3>
<p>Another very practical session, which I really wish I’d taken more notes on. Why character encoding matters and how you can use it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2008/06/04/what-i-saw-at-media-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bloglines moves backwards with Ajax</title>
		<link>http://www.broken-links.com/2007/06/29/bloglines-moves-backwards-with-ajax/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=bloglines-moves-backwards-with-ajax</link>
		<comments>http://www.broken-links.com/2007/06/29/bloglines-moves-backwards-with-ajax/#comments</comments>
		<pubDate>Fri, 29 Jun 2007 14:18:45 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.broken-links.com/2007/06/29/bloglines-moves-backwards-with-ajax/</guid>
		<description><![CDATA[I’ve used Bloglines for a long time to organise the many (too many?) feeds I read daily. I’ve always been happy with it, resisting the charms of new kids on the block such as Google Reader, but recently there’ve been some changes I find have taken the service a few steps backwards. The first I [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve used <a href="http://www.bloglines.com/public/cheeks">Bloglines</a> for a long time to organise the many (too many?) feeds I read daily. I’ve always been happy with it, resisting the charms of new kids on the block such as <a href="http://reader.google.com/">Google Reader</a>, but recently there’ve been some changes I find have taken the service a few steps backwards.</p>
<p><span id="more-73"></span></p>
<p>The first I noticed was the move to a newer, more <a href="http://en.wikipedia.org/wiki/Ajax_(programming)">Ajax</a>–y interface a few months ago. The problems with Ajax are well-documented, and one of the major problems is what’s happened to Bloglines: <a href="http://www.isolani.co.uk/blog/javascript/FixingTheBackButtonThatAjaxBroke">they’ve broken the ‘back’ button</a>. Previously, if I wanted to go back to a link I’d seen before, I could just hit ‘back’ and it would return me to what I was looking at; not any more, unfortunately.</p>
<p>Which brings me to the next problem: the ‘Display items in the last session’ option has been removed. In the event that I did want to go back and look at a link I’d seen before, I could have chosen that option and brought back all the category links I’d just looked at; now I only get the option to view by time (last hour, last 6 hours, etc). It’s not the same thing; if I’m looking at my links on a Monday morning and I hadn’t checked them over the weekend, I’d have to choose ‘last 48 hours’ and wade through potentially hundreds of posts looking for the one I wanted.</p>
<p>I wonder if they did any usability testing before making these changes? They may not be enormous, insurmountable problems, but they’ve certainly changed my opinion towards the service; for the first time, I’m seriously thinking of choosing a new provider. The question is: to what? Google Reader seems to be the most popular, but both the problems I’ve identified above are even worse with that; the ‘back’ button takes you out of the application entirely, and the archive feature only allows you to see all previous items.</p>
<p>I  need a web-based feed reader so I can check my feeds anywhere, and one that doesn’t break the fundamental navigation principles of the web. I don’t need loads of bells &amp; whistles, but I would like there to be a notifier extenstion for Firefox. Is there such a service out there?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.broken-links.com/2007/06/29/bloglines-moves-backwards-with-ajax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
