<?xml version="1.0" encoding="utf-8"?>
<!-- Atom RSS Feed, index template, v1 -->
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Web Developer</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/" />
    <link rel="self" type="application/atom+xml" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/atom.xml" />
   <id>tag:www.bbc.co.uk,2013:/blogs/webdeveloper//311</id>
    <link rel="service.post" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311" title="Web Developer" />
    <updated>2010-05-25T14:52:29Z</updated>
    <subtitle>A blog about the web and the BBC, from the people who build the BBC website. Follow us on Twitter</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.33-en</generator>
 

<entry>
    <title>Goodbye world</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/05/goodbye-world.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=217886" title="Goodbye world" />
    <id>tag:www.bbc.co.uk,2010:/blogs/webdeveloper//311.217886</id>
    
    <published>2010-05-24T11:12:39Z</published>
    <updated>2010-05-25T14:52:29Z</updated>
    
    <summary>Don&apos;t panic! Nothing&apos;s ending... this blog is just going to be merged with the BBC Internet blog. Or they&apos;re merging with us. All this means is that any time a web developer wants to explain what they&apos;ve been working on,...</summary>
    <author>
        <name>Richard Northover</name>
        <uri>http://richard.northover.info</uri>
    </author>
    
        <category term="Interesting Things" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p><em>Don't panic!</em> Nothing's ending... this blog is just going to be merged with the BBC Internet blog. Or they're merging with <em>us</em>.</p>

<p>All this means is that any time a web developer wants to explain what they've been working on, they'll do it at <a href="https://bbcstreaming.pages.dev/blogs/bbcinternet">https://bbcstreaming.pages.dev/blogs/bbcinternet</a>, rather than here.</p>

<p>And suddenly, the Internet blog will start to be <em>extra</em>-interesting.</p>

<p>Thanks for your comments... see you on the other side.</p>

<pre><code>exit();</code></pre>]]>
        
    </content>
</entry>

<entry>
    <title>Setting your location on the new BBC Homepage</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/05/setting-your-location-on-the-n.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=216722" title="Setting your location on the new BBC Homepage" />
    <id>tag:www.bbc.co.uk,2010:/blogs/webdeveloper//311.216722</id>
    
    <published>2010-05-21T10:58:00Z</published>
    <updated>2010-05-21T12:52:34Z</updated>
    
    <summary>Before I joined the BBC Homepage team, the only thing I&apos;d ever really done on the page was to set my location so that I could see my local weather. It turns out that I&apos;m not alone - about 2.5...</summary>
    <author>
        <name>Neil Crosby</name>
        
    </author>
    
        <category term="HTML" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Before I joined the <a href="https://bbcstreaming.pages.dev/">BBC Homepage</a> team, the only thing I'd ever really done on the page was to set my location so that I could see my local weather.  It turns out that I'm not alone - about 2.5 million of the visitors to the homepage each week will have set their location at some point - quite a few people.</p>

<p>So, when it came to the new version of the homepage, we knew that getting this right was important.  But we also wanted to make it better than it was before.  But how to do this?  In the end we decided on two things - let users set their location to anywhere in the world (good for international users, or people who want to see what the weather's like where they're going on holiday), and stop requiring a full page reload every time a user's location is set.</p>

<h3>Going global</h3>

<p>The first problem was letting users set a location anywhere in the world.  Unfortunately, Postcoder (the data set used by the previous version of the homepage) only knew about places in the UK.  Granted, it knew about a huge number of places in the UK, but it was still limited to the UK.  So, we had to look at a second data set that knew about the rest of the world - the BBC Weather Search API.  This API knew about places all over the world but unfortunately it knew a lot less about the UK than Postcoder did.</p>

<p>This turned out to be a problem.  Whilst  the Weather Search API knew about the UK's postcodes, it didn't know about a lot of the smaller places within the country. So, for example, whilst it knew about Leicester, it didn't know about Belgrave (the home of Leicester's "Golden Mile" and the largest Diwali celebrations outside of India).  This was obviously a problem.  Understandably, people would expect the new homepage to know about at least as many places as the old one did, so just using the Weather Search API was not going to be possible.</p>

<p>After a bit of head scratching, I did the obvious thing: I took the best bits of each data set and used them to generate a cohesive whole.  Now, whenever a user tries to set their location we send queries to both Postcoder and to the Weather search API.  We then throw away anything the Weather Search API tells us about the UK, and just use its worldwide data along with all the data that we previously had for the UK from Postcoder.</p>

<p>Of course, things weren't actually quite that easy.  Let's walk through the actual process we have to go through to determine a user's location:</p>

<ol>
<li>The user searches for a location.  We send requests to Postcoder and the Weather Search API.</li>
<li>We get data back from the APIs (and remove any UK results from the Weather data set). If there was more than one result then we let the user choose between them.</li>
<li>Now that we have a single location, we have a decision to make.
<ul>
    <li>If the location came from the Weather API then it's not in the UK.  We reset the localisation for news, TV and Radio (since we don't have any non-UK localised data for them), and set the weather localisation.  At this point we have nothing left to do.  Hooray.</li>
    <li>If, however, the location came from Postcoder then we continue along the branches of our tree.</li>
</ul>
</li><li>Since we now know that the place the user has chosen is definitely in the UK, we can localise news, TV and Radio. We do this.</li>
<li>Unfortunately, Postcoder doesn't provide us with a weather ID that can be plugged directly into the weather system, so we need to find one from somewhere.</li>
<li>Using the first half of the postcode we got from Postcoder we once again query the Weather Search API.
<ul>
	<li>Weather returns us a single place matching this postcode, and as part of its data an ID that can be plugged into the weather system.</li>
	<li>If, for whatever reason, Weather doesn't know about the postcode we give it (it's happened a couple of times), then we perform yet another search on the Weather Search API, this time with the name of the place that Postcoder returned us data for and really get some data.</li>
</ul>
</li>
<li>Finally, at this point we've gathered all the data that we need for the localisations that can be applied to the page. So, we return the data we've assembled to the user's browser, and they get to see lots of lovely localised data.</li>
</ol>

<p>Phew.  That's basically what we have to step through every time a user sets their location.  Essentially, every time a user tries to set their location to a place in the UK we have to make at least three calls to extrnal APIs (and sometimes more) to gather all the data we need to localise the page.  And this is before we even get to pulling in the data for the localised modules!</p>

<p>And, with this change in place, the localisation popup on the homepage suddenly became aware of places all over the world.  Users can now keep track of the weather in Istanbul just as easily as they can in Dunstable.</p>

<h3>Updating modules in-page</h3>

<p>The other big thing we did to the user localisation on the homepage was to no longer require a full page refresh whenever a location was set.  Previously, whenever a location was set by a user on the page, a full page regeneration was triggered.</p>

<p>Now, this obviously wasn't pleasant.  Having to wait for a full page refresh can be tiresome, and the flash of no content as a new page loads just doesn't look very nice.  So, one of the aims we had with the homepage refresh was to stop that, and instead just update the portions of the page that needed updating.</p>

<p>When the user sets their location on the new homepage we make several AJAX requests back and forth to the server.  These requests allow us to update the model we store that determines how the page is to be laid out for individual users.  In the  Old World, we would then have forced a full page refresh to enable the user to see this new layout.  In the new homepage, we instead return a blob of JSON data to the user's browser.</p>

<p>That JSON data contains everything we need to update the page.  Here's a simplified view of the data we return:</p>

<pre><code>{
    "content":{
        "news_local":{
            "html":"...some html...",
            ...
        },
        "forecast":{
            "html":"...some html...",
            ...
        }
    },
    ...
}</code></pre>

<p>Here, you can see that each module that we're going to update on the page is defined within its own section of the returned JSON.  Each section is named after the ID of the HTML block that needs updating, and contains (amongst other things) a big block of pre-rendered HTML.  This allows us to do the simplest thing possible in the JavaScript of just replacing one bit of HTML with another, and gives the added benefit of being able to reuse the same logic that was used to generate the module's HTML when JavaScript isn't available.</p>

<h3>Refreshing the look</h3>

<p>The other obviously different thing about setting your location in the refreshed homepage is the overlaid panel that you now see when you enter your location.  The nice thing about this panel is that it's provided for us by the <a href="https://bbcstreaming.pages.dev/glow/">BBC Glow</a> team, and it allowed us to take a form that already worked on the page without JavaScript and inject it with a new look and feel.</p>

<p><img alt="location-popup.png" src="https://bbcstreaming.pages.dev/blogs/webdeveloper/location-popup.png" class="mt-image-center" style="text-align: center; display: block; margin: 0pt auto 20px;" height="259" width="492" /></p>

<p>The fact that this sort of functionality (and a whole lot more) is provided for us by the fantastic Glow team makes our job a whole lot easier.</p>

<h3>Other Complications</h3>

<p>Of course, not everything was fun and games in the land of location setting.  One issue that had managed to slip by me until fairly late in the day was that some places have the option of taking their news from one of two different areas.  A good example of this is Chepstow on the Welsh border.</p>

<p>For good reason, there are many people who live in Chepstow who identify as wanting to be provided with Welsh local news.  Likewise, there are others who would prefer to receive local news from Gloucestershire.  The way we now deal with this on the homepage is by giving users the option to choose between these places within the same popup that they had previously chosen their main location in.</p>

<h3>Finally</h3>

<p>So, that's what went into the new Homepage's localisation options.  Frankly, it's a bigger thing than I expected when I was first given the work to complete.  As the developer who worked on this I'd like to thank each and every person who took the time to leave feedback during the Beta process - you really helped to make the homepage what it is now.</p>
]]>
        <![CDATA[<p><br /></p>]]>
    </content>
</entry>

<entry>
    <title>BBC Homepage: Clock</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/04/good-news-the-clock-has.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=210194" title="BBC Homepage: Clock" />
    <id>tag:www.bbc.co.uk,2010:/blogs/webdeveloper//311.210194</id>
    
    <published>2010-04-29T14:40:57Z</published>
    <updated>2010-04-29T14:42:50Z</updated>
    
    <summary>Good news! The clock has returned to the BBC Homepage. When we launched the Beta Homepage we received feedback from a number of you who missed the clock, so we&apos;ve turned it into a module allowing you to position the...</summary>
    <author>
        <name>Claire Roberts</name>
        
    </author>
    
        <category term="HTML" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Good news! The <a href="http://news.bbc.co.uk/1/hi/magazine/7271036.stm">clock</a> has returned to the BBC Homepage.</p>

<p>When we launched the <a href="http://beta.bbc.co.uk">Beta Homepage</a> we received feedback from a number of you who missed the clock, so we've turned it into a module allowing you to position the clock where you want it on the page (or shrink it or remove it altogether). It continues as before to show your computer's local time and date.</p>

<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="clock.png" src="https://bbcstreaming.pages.dev/blogs/webdeveloper/clock.png" width="316" height="110" class="mt-image-center" style="text-align: center; display: block; margin: 0 auto 20px;" /></span>

<p>As part of moving the clock to its own module, it now makes use of upcoming HTML standards. Flash is no longer a necessity as the module uses <a href="http://diveintohtml5.org/canvas.html">HTML5 Canvas</a> to draw and animate the clock face. This means users of newer browsers (and iPhones) will see the clock ticking on the page even if they don't have Flash. Of course, if you're using an older browser the Flash version will continue to load as usual.</p>

<p>If you're interested in how our Canvas code works, here's a snippet showing how to draw the clock face:</p>
<pre>drawDisplay: function(pos){
    this.context.clearRect(0,0,49,49); // clear canvas
    this.context.save(); // save state before translation
    this.context.translate(24.5, 24.5); // move 0,0 to center
    this.context.strokeStyle = "#fff";
    for (var i = 0; i&lt;12 ; i++){ // draw numerals
        var lineWidth = 1.2+(i*0.1), rotation = 30*(i+1),
            startX1 = -0.5 - lineWidth/2,
            startX2 = 0.5 + lineWidth/2,
            startY = -26, endY = -18;
        this.drawLine(lineWidth, rotation, startX1, startY, startX1, endY);
        this.drawLine(lineWidth, rotation, startX2, startY, startX2, endY);
    }
    this.drawCircle(2, 0, 0, 5, 0, Math.PI*2, true); // draw centre circle
    this.drawLine(3, pos.hrsPos, 0, -6, 0, -17); // draw hour hand
    this.drawLine(2, pos.minPos, 0, -6, 0, -24); //draw minute hand
    this.drawLine(1, pos.secPos, 0, -6, 0, -26); //draw second hand
    this.drawLine(1, pos.secPos, 0, 5, 0, 10);	
    this.context.restore(); // go back to the state before translation
    this.drawnPos = pos;
}
</pre>
<p>The display is then redrawn every second to move the hands to the current time using <a href="https://bbcstreaming.pages.dev/glow/">Glow</a> Animations.</p>

<p>The clock has come a long way since it first appeared in our <a href="http://625.uk.com/tv_logos/bbc.htm">idents</a> and continues to live on in new technologies.</p>]]>
        
    </content>
</entry>

<entry>
    <title>CSS for Widgets: friends don&apos;t break friends&apos; styles</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/02/css-for-widgets-friends-dont-break-friends-styles.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=167154" title="CSS for Widgets: friends don't break friends' styles" />
    <id>tag:www.bbc.co.uk,2010:/blogs/webdeveloper//311.167154</id>
    
    <published>2010-02-01T14:15:18Z</published>
    <updated>2010-02-01T14:24:37Z</updated>
    
    <summary>Hello. My name&apos;s Mark (as it says up at the top of the post) and I&apos;m on the team developing BBC iD, the new membership system that&apos;s being gradually rolled out across the BBC site. One of the important features...</summary>
    <author>
        <name>Mark Stickley</name>
        <uri>http://www.norestfortheweekend.com</uri>
    </author>
    
        <category term="BBC iD" />
    
        <category term="CSS" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Hello. My name's Mark (as it says up at the top of the post) and I'm on the team developing <a href="https://id.bbc.co.uk/users/help/#id-help-bbcid">BBC iD</a>, the new membership system that's being gradually rolled out across the BBC site.</p>

<p>One of the important features of BBC iD is the status bar, which sits in the top right of every page. The idea is that if you click the sign in link, or a relevant link anywhere else, we bring up a JavaScript overlay which allows you to sign in without leaving the page. It's designed to be a seamless experience, and we think it comes pretty close.</p>

<p>While building the <abbr title="HyperText Markup Language">HTML</abbr>, <abbr title="Cascading Style Sheets">CSS</abbr> and <abbr title="JavaScript">JS</abbr> for the project, a key part of my job has been to ensure that our code doesn't break any of the pages into which it's included. What's more, I have to be confident that the CSS defined for the <em>page</em> doesn't break any of the BBC iD components. Actually this is pretty tricky, but I'll explain how I approach this problem.</p>

<h3>A word on w*dgets</h3>

<p>First, I have to apologise to my colleagues and anyone else who puts the term 'widget' on the same level as a filthy curse word. When I talk about 'widgets' I'm just trying to find a short way of saying something like "chunks of HTML of any size supported by CSS (and possibly JavaScript) strategically inserted into a web page, the source of which you may not necessarily influence or control". It doesn't exactly trip off the tongue which is why I'm tempted to use the 'W' word, despite it's ambiguity.</p>

<p>The term 'widget' - and therefore this post - has a massive scope which covers much more than the BBC iD status bar and overlay. It will affect most developers, if not now certainly in the near future.</p>

<p>Before I continue, however, I need to cover some of the basics of CSS. For anyone who is already <a href="http://en.wiktionary.org/wiki/au_fait">au fait</a> with things like specificity, feel free to <a href="#beconsiderate">skip this section</a>, if you want to.</p>

<h3>Inheritance & Specificity</h3>

<p>CSS selectors are based on inheritance and specificity. Let me just take a moment to explain that for those who don't know already, because knowing this has saved me countless hours of headaches and frustration.</p>

<h4>Inheritance</h4>

<p>Some styles are inheritable. When you give an element an inheritable style, the children of that element will have the same style unless another selector says otherwise. Examples are: <code>font-family</code>, <code>color</code>, <code>font-style</code>, <code>font-size</code>.</p>

<p>Other styles like <code>border</code>, <code>background</code> and <code>width</code> are not inherited.</p>

<h4>Specificity</h4>

<p>This is a concept that is less well-known, or at least less well-understood.</p>

<p>Specificity is calculated on a per-selector points system. The higher the number of points accrued, the more important the styles within that selector are considered.</p>

<p>A simple tag is worth 1 point:</p>

<pre>
a{}
p{}
label{}
</pre>

<p>A <code>class</code> comes in at 10 points:</p>

<pre>
.post{}
.error{}
.section{}
</pre>

<p>Mix them up for higher scoring combinations:</p>

<pre>
a.external span{}
</pre>

<p>That one is worth 12 (1 + 10 + 1) points.</p>

<p><code>id</code>s are worth a massive 100 points.</p>

<p>Other things worth noting are:</p>

<ul>
    <li>Pseudo-classes (E.g. <cdoe>:hover</code>) are worth 10 points.</li>
    <li>Pseudo-elements (E.g. <code>:first-line</code>) are worth just one point each.</li>
    <li>The <code>*</code> selector is worth nothing at all.</li>
    <li>If a selector has more <code>id</code>s than another, it will always win no matter how many <code>class</code>es and elements the other has.</li>
    <li>If a selector has more <code>class</code>es than another, it will always win no matter how many elements the other has (assuming neither has any <code>id</code>s).</li>
    <li>Selectors with an equal number of points will use the order they are defined to decide which is more important. The most recently defined (further down the CSS file) is the most important.</li>
    <li>Inline styles using the <code>style=""</code> attribute do not hold a points value - they simply take precedence over any conflicting rules.</li>
</ul>

<h4>Overriding styles</h4>

<p>Just because one selector is deemed more important than another, it doesn't mean that the styles defined in the less important selector are void. Only the individual styles that the more important selector specifically defines are overridden, if they have already been defined by a less important selector.</p>

<p>Think of it like this: all selectors are used and applied in the order lowest scoring to highest scoring, identical or similar styles overriding what's already there.</p>

<div class="snippet-highlight">
    <p>I have adapted this information from multiple sources. It's the way I find it easiest to think about, but if you feel you are still a bit in the dark have a look at some other people's explanations:</p>

    <ul>
        <li><a href="http://www.molly.com/2005/10/06/css2-and-css21-specificity-clarified/">CSS2 and CSS2.1 Specificity Clarified</a> by <a href="http://www.molly.com">Molly Holzschlag</a></li>
        <li><a href="http://meyerweb.com/eric/css/link-specificity.html">Link Specificity</a> by <a href="http://meyerweb.com/eric">Eric Meyer</a></li>
        <li><a href="http://www.htmldog.com/guides/cssadvanced/specificity/">Specificity</a> by <a href="http://www.htmldog.com">Patrick Griffiths</a></li>
        <li><a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#specificity">W3C CSS Specification (Calculating a selector's specificity)</a></li>
        <li><a href="http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/">CSS Specificity: Things you should know</a> by <a href="http://www.smashingmagazine.com/author/vitaly-friedman/">Vitaly Friedman</a></li>
    </ul>
</div>


<h3 id="beconsiderate">Be considerate, but don't expect it back</h3>

<p>This specificity model is what we have to work with, whether we like it or not.</p>

<p>Any CSS file loaded by a document could affect any part of that document; conversely, any part of the document can be affected by any CSS file it includes. When you're working in an environment where your HTML and CSS share a space with someone else's you have to be considerate and defensive in equal parts.</p>

<p>Let's assume that the people writing CSS for any one page fall into two basic categories: Page author and Inclusion author. (We could call them 'Widget authors', but I've spent enough in the swear-box already.)</p>

<h3>Being considerate</h3>

<p>Coding considerately means doing your absolute best to make sure your styles don't mess about with parts of the page that you have no business messing about with. Let's start with includes.</p>

<h4>The considerate Inclusion developer</h4>

<p>It's so easy to get this right, there's really no excuse not to.</p>

<p>Because the inclusion is only a small part of the page, it's fair to say that it will have it's own container element, probably a <code>div</code>. You aren't interested in styling anything on the page except what is directly inside that container, so make that clear in your CSS.</p>

<p>Wrong:</p>

<pre>
h4{}
p{}
.entry span{}
</pre>

<p>Right:</p>

<pre>
#inclusionname h4{}
#inclusionname p{}
#inclusionname .entry span{}
</pre>

<p>By namespacing your CSS in this way, you are ensuring that your styles will not interfere with the styles on the page, as you might imagine those selectors in the 'wrong' example could.</p>

<p>It's worth mentioning that if your inclusion is called something that might well be used as an <code>id</code> elsewhere on the page, you should probably go a step further and use a more specific <code>id</code> to define the namespace. Here are some ideas:</p>

<pre>
#inclusionname-inclusion h4{}
#inclusionname-pageinclude p{}
#inclusionname-originatingurl-co-uk .entry span{}
</pre>

<h4>The considerate page developer</h4>

<p>It's a little harder as a page developer to avoid writing styles that will affect inclusions in your page. By the nature of CSS, it will cascade styles to elements further down the tree making namespacing harder. This doesn't mean that there's nothing you can do, however. Far from it, in fact.</p>

<p>Here are a few guidelines that will help avoid breaking inclusions:</p>

<h5>Don't put styles on bare tags</h5>

<p>By 'bare tags' I mean selectors like this:</p>

<pre>
p{}
li{}
span{}
</pre>

<p>It might seem reasonable to place a <code>line-height</code> of <code>8em</code> on all the <code>li</code>s in your page, but it's probably not what any inclusion developer will be expecting.</p>

<p>The more specific you can be in your selectors, the less likely they will be to leak into areas where they shouldn't be. A lot of developers give their pages a container <code>div</code> directly inside the <code>body</code>. At the very least you can namespace to that:</p>

<pre>
.container p{}
</pre>

<p>This might not seem too useful at first, because everything on the page is within the container. But if you use <a href="https://bbcstreaming.pages.dev/glow">Glow</a> (other JavaScript frameworks are available) to add an overlay, this is generated and placed at the very end of the <code>body</code> element. Styles namespaced to the container will not affect the overlay. So simple, so effective.</p>

<p>Going one better: if your style is only used in the header, footer or the main content area, specify it that way.</p>

<pre>
.header p{}
.main li{}
.footer span{}
</pre>

<p>Not only does it prevent unexpected style leakage (whether you have any inclusions in your page or not) but it makes the file easier to maintain, as you can tell at a glance that changing a particular declaration will only affect that specific part of the page.</p>

<p>There are limits to the depths of namespacing you can go to before you end up having to repeat your styles (defeating the point of the 'cascading' part of cascading style sheets). Just be as specific as you can be within reason. You'll know you've done your best, and as a result you'll get a nice warm fuzzy feeling inside.</p>

<h3>Being defensive</h3>

<p>Of course, you can't presume that all other developers value this nice warm fuzzy feeling. They won't necessarily have done their bit to protect your interests, especially as an inclusion developer, since namespacing pages can only work so far.</p>

<p>This is where defensive styling comes in. This is a bit of an exercise for the ol' grey matter, so grab a nice hot cup of tea, rich in <a href="http://en.wikipedia.org/wiki/Brownian_motion#Popular_culture">Brownian Motion</a> - the ultimate thinking aid - before you continue.</p>

<h4>The defensive inclusion developer</h4>

<p>The bad news here is that any styles defined for the main page with a higher specificity than your styles will interfere with your inclusion. And you have no way of telling how specific the page styles are, because this will vary from page to page.</p>

<p>Also, because of the cascading nature of CSS, you can have the most specific styles ever but unless you set every possible style on each selector then there is still a chance that some undesirable rogue styles that you didn't override might creep in.</p>

<p>This leaves us with two options:</p>

<ol>
    <li>CSS Resetters</li>
    <li>Applying the styles directly in a <code>style</code> attribute</li>
</ol>

<p>Despite being the only sure-fire way of getting the styles you want, applying every possible style to each element within a <code>style</code> attribute goes against the principle of separated style and content; it's nasty, messy, hard to maintain and generally not clever. So essentially we only have one option.</p>

<p>The thing about CSS resetters is that they're designed for the whole page; they're there to provide a common base line across all browsers, overriding the browsers' default styles and setting sensible defaults - <a href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2009/10/css-resets.shtml">something that Mat went into in some detail last year</a>. Because of this, they are all extremely overridable, usually basing their styles on a single element selector.</p>

<p>If we were to apply a reset to an inclusion, we would want it to be overridable so we can style it properly. We also need to namespace our resets so they don't affect the rest of the page. This requires at least a class to base the reset upon.</p>

<pre>
.reset{}
</pre>

<p>Of course, any style from the page that contains an <code>id</code> will obliterate any reset styles which leads to the logical conclusion of reset <code>id</code>s.</p>

<pre>
#inclusionname-reset{}
</pre>

<p>This has the limitation of only being able to be used once, as <code>id</code>s are unique. Also, any page style that uses more than one <code>id</code> will override that.</p>

<p>I could go on, but suffice it to say the more specific you make your reset the less likely it is that the page styles will affect your inclusion. But in turn, however specific your reset styles are, the styles for your inclusion will have to be <em>even more</em> specific.</p>

<p>You need to pick a level that suits you and the needs of your inclusion. You can never be 100% sure that your styles are safe, but if you take these precautions you stand a far better chance.</p>

<p>Barlesque, the inclusion that provides the header, footer and various pan-site modules on the BBC website comes with a re-useable class-based resetter (<code>.blq-rst</code>) which we apply to the BBC iD inclusions; I feel this is an appropriate level of protection.</p>

<h4>The defensive page author</h4>

<p>As a page author, if you come across an inclusion that breaks styles in your page I would simply recommend not using it. If the author of that inclusion has not thought carefully enough to namespace their styles, I wouldn't want their HTML or JavaScript on my page either.</p>

<p>If you have no choice in the matter, you need to get in touch with the author and point them in the direction of this post!</p>


<h3>Food for thought</h3>

<p>I haven't come across anything so far, but it might be possible to solve the <em>Defensive inclusion author</em> problem with some JavaScript. All it would need to do is to read in the styles from a <strong>specific</strong> stylesheet, parse them, and apply the computed styles to each element in a <code>style</code> attribute. Maybe that's a subject for a future blog post...</p>]]>
        
    </content>
</entry>

<entry>
    <title>Interesting Things 29/1/10</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/01/interesting-things-29110.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=189938" title="Interesting Things 29/1/10" />
    <id>tag:www.bbc.co.uk,2010:/blogs/webdeveloper//311.189938</id>
    
    <published>2010-01-29T17:15:00Z</published>
    <updated>2010-01-29T17:16:56Z</updated>
    
    <summary>Here&apos;s another crop of links that caught our eye recently. We&apos;re changing focus a little this time, pulling out some more technical posts. In praise of Git&apos;s index Aristotle Pagaltzis has a good writeup of the benefits of Git&apos;s index...</summary>
    <author>
        <name>Tom Yandell</name>
        
    </author>
    
        <category term="Interesting Things" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Here's another crop of links that caught our eye recently. We're changing focus a little this time, pulling out some more technical posts.</p>

<h3>In praise of Git's index</h3>

<p>Aristotle Pagaltzis has a good <a href="http://plasmasturm.org/log/gitidxpraise/">writeup of the benefits of Git's index</a> (via <a href="http://tomayko.com/linkings/1f2b86bd8d744e82737498f04604aeae">Ryan Tomayko</a>). This is one of those things that isn't immediately obvious, but quickly becomes invaluable.</p>

<h3>Alternatives to inheritance</h3>

<p>Curtis "Ovid" Poe has written quite a lot about <a href="http://blogs.perl.org/users/ovid/2009/11/alternatives-to-inheritance.html">alternatives to inheritance</a> for code reuse in Perl. His latest post examines the options for using <a href="http://blogs.perl.org/users/ovid/2010/01/roles-without-moose.html">Roles without Moose</a> for his new project at the BBC.</p>

<h3>Live SPARQL end-point for BBC Programmes</h3>

<p>Yves Raimond announced an experimental <a href="http://blog.dbtune.org/post/2010/01/13/Live-SPARQL-end-point-for-BBC-Programmes">SPARQL end-point for BBC programme data</a>, including a description of how the service was created. It's a great addition to the variety of <a href="https://bbcstreaming.pages.dev/programmes/developers">linked data provided by BBC Programmes</a>. See also this case study on the use of <a href="http://www.w3.org/2001/sw/sweo/public/UseCases/BBC/">semantic web technologies at the BBC</a>.</p>

<h3>New Browser Security Features</h3>

<p>The <a href="http://blog.chromium.org/">Chromium Blog</a> had a good post about <a href="http://blog.chromium.org/2010/01/security-in-depth-new-security-features.html">new security features in Chromium</a>, but also in Internet Explorer, Firefox, Safari and Opera. It's nice to see browser vendors centering around standards to solve these problems.</p>
]]>
        
    </content>
</entry>

<entry>
    <title>Interesting Things 22/1/10</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/01/interesting-things-22110.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=188243" title="Interesting Things 22/1/10" />
    <id>tag:www.bbc.co.uk,2010:/blogs/webdeveloper//311.188243</id>
    
    <published>2010-01-22T13:38:18Z</published>
    <updated>2010-01-22T13:52:29Z</updated>
    
    <summary> Here&apos;s another set of articles that have caught our attention during the week... Semantic Versioning Tom Preston-Werner, one of the co-founders of GitHub, has written a specification for a standard software versioning scheme. Many of our teams already use...</summary>
    <author>
        <name>Tom Cartwright</name>
        <uri>https://bbcstreaming.pages.dev</uri>
    </author>
    
        <category term="Interesting Things" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[ <p>Here's another set of articles that have caught our attention during the week...</p>

<h3>Semantic Versioning</h3>

<p>Tom Preston-Werner, one of the co-founders of <a href="http://www.github.com/">GitHub</a>, has written a specification for a standard <a href="http://semver.org/" rel="nofollow">software versioning scheme</a>. Many of our teams already use approximations of this (in fact the <a href="https://bbcstreaming.pages.dev/glow/docs/articles/versioning_scheme.shtml">Glow team document theirs</a>) and find it works well, but as the article says:</p>

<blockquote>The problem is that "close" isn't good enough. Without compliance to some sort of formal specification, version numbers are essentially useless for dependency management.</blockquote>

<p>It's a great piece of common sense and we'll be looking at how we can follow this spec more widely around these parts.</p>


<h3>Building the Mobile Homepage</h3>

<p>Some of the key issues tackled in <a href="https://bbcstreaming.pages.dev/blogs/bbcinternet/2010/01/a_brief_technical_overview_of.html">creating the the personalised mobile BBC homepage</a> are discussed on the Internet Blog. While modern devices are looking to blur the lines between the mobile and desktop web, it's clear that building a compelling mobile experience still poses its own unique challenges.</p>

<h3>The Digital Revolution</h3>

<p>An upcoming documentary on the history of the internet, <a href="https://bbcstreaming.pages.dev/digitalrevolution/">Digital Revolution</a> has already made some great interviews available with key internet people available on the site, with more permissive licensing than usual. Gizmodo has published an <a href="http://gizmodo.com/5453788/sneak-peek-of-new-bbc-documentary-the-virtual-revolution">early trailer for the series</a> and it looks like it's going to be a must-see for anyone interested in the web.</p>

<h3>52 Weeks of <abbr title="User Experience">UX</abbr></h3>

<p>Something else that has caught our eye this week is the early output of <a href="http://52weeksofux.com/">52 Weeks of UX</a>. The project is aiming to stimulate discussion around User Experience design through a year-long series of short posts on various aspects of the subject. To software engineers the visual design process can often seem a vague thing, lacking definitive answers, so we're hoping this will help improve understanding of just how important this part of our job really is.</p>

<h3>By the way...</h3>

<p>...we're trying to pick things from the week that might have missed your inbox, so please feel free to let us know if there are any interesting things that seem to have missed ours.</p>
]]>
        
    </content>
</entry>

<entry>
    <title>Interesting Things 15/1/10</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/01/interesting-things-15110.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=185928" title="Interesting Things 15/1/10" />
    <id>tag:www.bbc.co.uk,2010:/blogs/webdeveloper//311.185928</id>
    
    <published>2010-01-15T16:07:47Z</published>
    <updated>2010-01-15T16:37:15Z</updated>
    
    <summary>Like at any other company, the email accounts and feedreaders of our developers are always overflowing with new articles from around the web. Here&apos;s a quick set of some of the links creating discussion among bbc.co.uk development teams this week....</summary>
    <author>
        <name>Tom Cartwright</name>
        <uri>https://bbcstreaming.pages.dev</uri>
    </author>
    
        <category term="Interesting Things" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Like at any other company, the email accounts and feedreaders of our developers are always overflowing with new articles from around the web. Here's a quick set of some of the links creating discussion among bbc.co.uk development teams this week.</p>

<h3>Asynchronous Servers in Python</h3>

<p>There has been a lot of hype around the <a href="http://www.nodejs.org/" rel="nofollow">Node.js</a>
project over the last couple of months. Whilst not a brand new concept,
JavaScript does seem particularly well suited as a language to the
event based model of I/O. Nicholas Piël has written a detailed
comparison of <a href="http://nichol.as/asynchronous-servers-in-python/" rel="nofollow">Python frameworks which use this model</a> and it will be good to see this expanded to cover frameworks in other languages such as Node.</p>

<h3>Alt and Title Display in Browsers</h3>

<p>Steve Faulkner from the <a href="http://www.paciellogroup.com/">Paciello Group</a> has done a thorough
examination of the <a href="http://www.paciellogroup.com/blog/?p=498">behaviour of Alt and Title attributes on images</a> in
the major browsers. We really liked the methodology here, taking a
discrete problem and covering it completely, rather than trying to boil
the ocean.</p>

<h3>iPlayer Stats</h3>

<p>Over on the <a href="https://bbcstreaming.pages.dev/blogs/bbcinternet/">internet blog</a> Paul Murphy gives an overview of the
<a href="https://bbcstreaming.pages.dev/blogs/bbcinternet/2010/01/bbc_iplayer_november_and_decem.html">latest iPlayer usage stats</a>. Particularly noteworthy is the uptake of
iPlayer on new platforms such as Wii and Playstation 3, which now makes
up 6% of requests for TV programmes.</p>
<h3>Woosh - JavaScript Performance Testing</h3>

<p>The <a href="https://bbcstreaming.pages.dev/glow/">Glow</a> guys are hard at work on Glow 2 and to make sure it's as fast as it can be, they've developed a speed testing framework. Frances from the team has written an <a href="http://fberriman.com/2010/01/12/javascript-speed-testing-with-woosh/">overview and getting started guide</a>.</p>]]>
        
    </content>
</entry>

<entry>
    <title>A/B Testing</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/01/ab-testing.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=155693" title="A/B Testing" />
    <id>tag:www.bbc.co.uk,2009:/blogs/webdeveloper//311.155693</id>
    
    <published>2010-01-12T14:34:07Z</published>
    <updated>2010-01-15T10:54:48Z</updated>
    
    <summary>A look at an small experimental system written to allow AB testing on bbc.co.uk.</summary>
    <author>
        <name>Mat Hampson</name>
        
    </author>
    
        <category term="experiments" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[ <p>A little while ago I was talking to our interaction designer Pekka about a link we had in the masthead that was under-performing. We suspected it was the wording that wasn't working, and after thinking up a few possible options Pekka said it would be great to be able to "A-B test" some of them. This led to some blank gawping from me, and so in turn to an explanation from him.</p>

<p>It turns out '<a href="http://www.webcredible.co.uk/user-friendly-resources/web-usability/ab-testing.shtml">A-B testing</a>' is a way to show different options for part of the UI to two (or more) groups of users, and then monitor what they do as a result. This can be done in normal <a href="http://en.wikipedia.org/wiki/Usability_testing">user testing</a> of course, but more interestingly it can also be done on a live site with large numbers of users - getting real world results on a statistically valid scale. In our very simple case we could show the different wording options to different groups and see which one generated the most clickthroughs.</p>

<p>This sounded like a great idea, but not something I could fit onto the project backlog at the time. Luckily, some teams here set aside a little time within their project planning specifically to let developers 'scratch that itch'. No, not like that. I mean work on something that's bothering them rather than whatever's needed next in the project. Our team uses a <a href="http://www.tomhume.org/2009/05/gold-cards.html">gold card</a> system within our normal project planning process, <a href="http://en.wikipedia.org/wiki/Scrum_(development)">Scrum</a>, to give us up to a day a fortnight for this.</p>

<p>Thus I decided to spend a day writing <strong><a href="https://bbcstreaming.pages.dev/includes/abtest/">this mechanism for doing A-B testing on bbc.co.uk</a></strong>.</p>

<h3>The code</h3>

<p><a href="https://bbcstreaming.pages.dev/includes/abtest/script/main.js">The JavaScript</a> is split into two parts. The first is used for new visitors, and, aside from checking the function's configuration is valid, simply uses the probability value to decide whether the user is going to be part of the test, and cookie them accordingly.</p>

<p>The second is used for those who already have a cookie, and have been randomly selected for testing. It cycles through all the links on the page, checking for any that have a class starting 'abtest_'. When it finds one it adds an onclick which, when activated, makes a call to a tracked image so that the click is counted.</p>

<p>This tracking is done using the BBC's <a href="http://www.google.co.uk/search?q=define:click+tracking">click tracking</a> stats system, known internally as 'go-tracking', which allows us to easily get reports from the server logs showing how many times particular URLs are visited.</p>

<p>To make these calls I used <code>img.src="..."</code> to make an asynchronous call from JavaScript. Note however, if the link in question goes to a new page about 1/3 of browsers won't complete the request before the page unloads. If this was an issue for a particular test the links' hrefs could be changed, so they go via a tracked URL instead.</p>

<p>Finally, in the page itself we place some small snippets of SSI (though we could easily use more Javascript or PHP) that check for the cookie, and change what the user gets shown according to its value.</p>

<h3>Example use</h3>

<p>For 5 in 100 people to get a two-option test running for 24 hours the function is initialised like this:</p>

<code><pre>abtest.init(
    'mydemo', {
        probability:5, 
        numOfOptions:2, 
        path:'/includes', 
        duration:24
    }
);</pre></code>

<p>Within the markup, content is changed according to the cookie value:</p>

<code><pre>&lt;!--#if expr="$HTTP_COOKIE=/abtest_mydemo=a/" --&gt;
	Text a
&lt;!--#elif expr="$HTTP_COOKIE=/abtest_mydemo=b/" --&gt;
	Text b
&lt;!--#else --&gt;
	Default text
&lt;!--#endif --&gt;</pre></code>

<p>And classes like this are added to links that are to be counted:</p>

<code><pre>class="abtest_mydemo"</pre></code>

<p>Any clicks on that link will result in an asynchronous call to an image with a path that includes "mydemo" from the class and the option value (e.g. "b") from the cookie:</p>

<code><pre>/go/abtest/int/abtest_mydemo_b/</pre></code>

<p>Thus after the test we can count the totals for each option, and use those figures to help decide which solution  to go with.</p>

<h3>And the winner is...</h3>

<p>Well, whaddya know: the design changed, removing the button in question, so I'm still waiting for my first excuse to use it. However, my friend Manjit over in <a href="https://bbcstreaming.pages.dev/worldservice/">World Service</a> has just run a test of the wording for the main link to their <a href="https://bbcstreaming.pages.dev/worldservice/programmes/000000_widget_terms.shtml">syndication widget</a>, and immediately proven a small tweak would be three times as effective at getting users' attention. Not a bad first outing.</p>

<p>As a method it's not without its dangers of course. Your presented options must be realistic, and not just chasing clickthroughs for example - but with an experienced information architect at the helm I think this little snippet may come in quite handy.</p>

<p>What do you think? Have any of you used this kind of testing?</p>]]>
        
    </content>
</entry>

<entry>
    <title><![CDATA[Always read the &lt;label&gt;]]></title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/01/always-read-the-label.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=181787" title="Always read the &amp;lt;label&amp;gt;" />
    <id>tag:www.bbc.co.uk,2010:/blogs/webdeveloper//311.181787</id>
    
    <published>2010-01-05T15:42:05Z</published>
    <updated>2010-03-22T15:37:02Z</updated>
    
    <summary> Text fields in forms need to have labels, so that people know what they&apos;re meant to enter into them. Next to a username field, for example, it&apos;ll say something like &quot;Enter your username&quot;. The HTML you&apos;d use for this...</summary>
    <author>
        <name>Richard Northover</name>
        <uri>http://richard.northover.info</uri>
    </author>
    
        <category term="CSS" />
    
        <category term="HTML" />
    
        <category term="accessibility" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[


<p>Text fields in forms need to have labels, so that people know what they're meant to enter into them. Next to a username field, for example, it'll say something like "Enter your username". The HTML you'd use for this would involve a <code>&lt;label&gt;</code> tag, with <code>id</code> and <code>for</code> attributes tying everything together. The association between <code>&lt;label&gt;</code> and <code>&lt;input&gt;</code> lets the browser know which hint applies to which field.</p>

<p>
	<label for="username">Username</label>
	<input id="username" type="text" />
</p>

<code><pre>&lt;label for=&quot;username&quot;&gt;Username&lt;/label&gt;
&lt;input id=&quot;username&quot; type=&quot;text&quot; /&gt;
</pre></code>

<p>When properly associated like this, the label becomes a handy way for users of visual browsers to send focus to the field. Users of non-visual browsers, however, <em>need</em> the label to be there so that when the field is reached, there is any information about it at all.</p>

<h3>Multi-labels</h3>

<p>The pairing of <em>one</em> input tag with <em>one</em> label tag only allows space for <em>one chunk of text</em> for each field. It's not unusual for a design to call for <em>more than one</em> chunk to be associated with a field, often with the second one appearing elsewhere on the page.</p>

<img alt="A form field with two label elements" src="https://bbcstreaming.pages.dev/blogs/webdeveloper/2010/01/05/doublelabel.jpg" width="293" height="95" class="mt-image-left" />

<p>This design pattern often appears when we need to explain more than one thing about a field: the fact that the username can't contain spaces, or that it needs to be more than a certain number of characters, for example. It's also a common way to show feedback after form validation.</p>

<h3>Can't we just add more labels?</h3>

<p>Sadly, no. You might think that if you need two labels, you could just use two label tags. But as Roger Johansson pointed out in <a href="http://www.456bereastreet.com/archive/200809/multiple_form_labels_and_screen_readers/
">an article over at 456 Berea St</a> a while back, this appears not to work. Generally, only one or other of the labels is noticed by screenreaders.</p>

<p>As a result, out in the wild, extra bits of hint text usually end up <em>separated</em> from the label, inside another tag, with CSS then positioning them according to the design. The HTML generally looks something like this:</p>
	
<code><pre>&lt;label for=&quot;username&quot;&gt;Username&lt;/label&gt;
&lt;input id=&quot;username&quot; type=&quot;text&quot; /&gt;
&lt;span id=&quot;username_info&quot;&gt;Pick a name to use on this site.&lt;/span&gt;
</pre></code>

<p>The problem with this approach is that the second hint chunk won't always be read out by screenreaders, as only the main label tag, "Username", is explicitly associated with the input. To use a common but sometimes hard-to-pin-down phrase, this way of doing things is <em>inaccessible</em>.</p>

<h3>A quick aside about forms mode</h3>

<p>When interacting with forms, some screenreaders enter 'forms mode'. This switches the keyboard over from page navigation (using the keys to jump to different parts of the page) to allow regular text input. This allows you to type your username, rather than perform browser-related shortcuts. In this mode, <em>only form-related tags</em> are read out. Other tags (apart from links) tend to be ignored as you move around the page.</p>

<p>This means that if the text in your second chunk of label text is important, it may be <em>ignored</em>. This could be a problem:</p>

<code><pre>&lt;label for=&quot;user_code&quot;&gt;Please enter your user code&lt;/label&gt;
&lt;input id=&quot;user_code&quot; type=&quot;text&quot; /&gt;
&lt;span class=&quot;hint&quot;&gt;but only if you want the nuclear reactor 
	 to shut down immediately&lt;/span&gt;
</pre></code>

<h3>The importance of being important</h3>

<p>If the additional chunk of text <em>isn't vital</em> for users to read, then you might say it doesn't matter that it's not available to screenreaders. In the example above, the hint text "Pick a name to use on this site" is arguably not as critical to understanding the form as the nuclear reactor label. But if something's important enough to be in the page, then - all other things being equal - it should be available to everyone... otherwise, it arguably shouldn't be there at all.</p>

<h3>Two for one</h3>

<p>Time for some actual answers. Provided we don't use it as an excuse to write an essay inside the label tag, a solution to the 'two labels' problem is to place both the main and hint chunks <em>together</em>. As they're both important to understand, it's really just one label anyway.</p>

<code><pre>&lt;label for=&quot;username&quot;&gt;
	&lt;span class=&quot;main&quot;&gt;Username&lt;/span&gt;
	&lt;span class=&quot;hint&quot;&gt;must be more than 5 characters&lt;/span&gt;
&lt;/label&gt;
  	
&lt;input type=&quot;text&quot; id=&quot;username&quot; /&gt;
</pre></code>

<p>If a screenreader reads this out, however, it'll join the two hints together as if they're a single sentence, and this might sound slightly odd. To make things read more sensibly, we can insert a hidden full-stop. This makes the screenreader pause for a moment and read the two chunks as we might expect them to be read: "Username [pause] must be more than 5 characters".</p>

<code><pre>&lt;label for=&quot;username&quot;&gt;
	&lt;span class=&quot;main&quot;&gt;Username&lt;/span&gt;
	&lt;span class=&quot;hide&quot;&gt;. &lt;/span&gt;
	&lt;span class=&quot;hint&quot;&gt;must be more than 5 characters&lt;/span&gt;
&lt;/label&gt;

&lt;input type=&quot;text&quot; id=&quot;username&quot; /&gt;
</pre></code>

<h3>Presentation</h3>

<p>There are lots of ways that you might want to present the label and its hint text, and even more approaches to the CSS. But to separate the hint and place it below the field, you could do something like this:</p>

<code><pre>#container {
	background-color: #eee;
	position: relative;
	width: 270px;
}
#container label { display: block; line-height: 1.5em; }

#container span.main {
	font-weight: bold;
	display: block;
}

#container span.hint {
	display: block;
	margin: 1em 0 0 0;
	text-align: right;
	font-size: 0.9em;
}

#container input {
	position: absolute;
	top: 0;
	right: 0;
	width: 13em;
}

.hide { position: absolute; left: -2500px; width: 1px; }
</pre></code>

<p>Which turns out like this:</p>

<p id="container" class="blq-rst">
<label for="username2">
		<span class="main">Username</span>
		<span class="hide">. </span>
		<span class="hint">must be more than 5 characters</span>
</label>

<input type="text" id="username2" />
</p>

<h3>Potential issues</h3>

<p>Nothing is ever simple, though. While this technique works well, it doesn't work everywhere... and in particularly quirky cases, we can end up with a situation where <em>nothing</em> is read out. This is, of course, <em>exactly the problem we were trying to solve in the first place...</em></p>

<p>Voiceover 3.0 on Mac OS X, for example, appears to ignore elements inside the label that are set to <code>display: block</code>; this problem doesn't seem to happen in earlier versions. And using absolute positioning to move the hint chunk into place can, in some situations, cause problems in JAWS. More work needs to be done to pin this one down, but it seems to involve the vertical height of the hint relative to the main label, and which elements (the label and the spans) are set to <code>display: block</code>.</p>

<p>One way to resolve this, although it's a shame to have to do this, is to add the label and hint text as a <code>title</code> attribute on the input tag:</p>

<code><pre>&lt;label for=&quot;username2&quot;&gt;
	&lt;span class=&quot;main&quot;&gt;Username&lt;/span&gt;
	&lt;span class=&quot;hide&quot;&gt;. &lt;/span&gt;
	&lt;span class=&quot;hint&quot;&gt;must be more than 5 characters&lt;/span&gt;
&lt;/label&gt;

&lt;input title=&quot;Username. must be more than 5 characters&quot; type=&quot;text&quot; id=&quot;username2&quot; /&gt;
</pre></code>

<p>In the absence of a label, the title is read out by Voiceover as if it was working normally. When things <em>are</em> working as expected, the title should be ignored in favour of the label.</p>

<code><pre>hammer.crack("nut");</pre></code>

<h3>In summary...</h3>

<ul>
<li>Form &lt;input&gt; fields need to be properly paired with a &lt;label&gt; tag</li>
<li>Screenreaders in forms mode tend to ignore anything other than single &lt;label&gt; tags</li>
<li>If you need to add more than one chunk of text to a label, try putting both chunks inside the label, and then moving the chunks into place with CSS</li>
<li>Use hidden full-stops to make things flow as expected</li>
<li>Always test what you've done as widely as you can, because these things can be unpredictable...</li>
</ul>

<p>This is a tricky problem, so if you have any thoughts or suggestions, or have a chance to try these examples in assistive devices that you have access to, it'd be great to hear from you.</p>


<style type="text/css" media="screen">
		#container {
			background-color: #eee;
			position: relative;
			width: 290px;
			margin: 1em 0 1em 90px;
padding: 1em;
		}
		
		#container label { line-height: 1.5em; }

		#container span.main {
			font-weight: bold;
			display: block;
background: none;
		}

		#container span.hint {
			display: block;
			margin: 1em 0 0 0;
			text-align: right;
			font-size: 0.9em;
		}
		
		#container input {
			position: absolute;
			top: 1em;
			right: 1em;
			width: 13em;
		}
		.hide { position: absolute; left: -2500px; width: 1px;; }</style>]]>
        
    </content>
</entry>

<entry>
    <title>Test-driven Development in Agile Projects</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2009/11/testdriven-development-in-agil.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=167759" title="Test-driven Development in Agile Projects" />
    <id>tag:www.bbc.co.uk,2009:/blogs/webdeveloper//311.167759</id>
    
    <published>2009-11-19T15:15:09Z</published>
    <updated>2009-11-19T15:50:18Z</updated>
    
    <summary>Hi, I&apos;m Giv Parvaneh, and I&apos;m a senior PHP web developer at the BBC. When I started working here earlier this year, I quickly realised that I would have to re-think the way I develop web applications. As a public...</summary>
    <author>
        <name>Giv Parvaneh</name>
        <uri>http://www.givp.org</uri>
    </author>
    
        <category term="Agile" />
    
        <category term="PHP" />
    
        <category term="testing" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Hi, I'm <a href="http://www.givp.org/">Giv Parvaneh</a>, and I'm a senior PHP web developer at the BBC. When I started working here earlier this year, I quickly realised that I would have to re-think the way I develop web applications. As a public service and one of the most visited websites in the UK, the BBC has an obligation to deliver quality products; the websites we build not only have to conform to web standards and be fully accessible, they need to be scalable to handle millions of users. Quickly hacking things together isn't really an option here...</p>

<h3>The need for speed</h3>

<p>Developers at the BBC tend to use <a href="http://en.wikipedia.org/wiki/Agile_software_development">Agile methodologies</a> as a way to quickly release iterations of products. But where does <a href="http://en.wikipedia.org/wiki/Test-driven_development">rigorous code testing</a> fit in with the short development and release cycles? How can we maintain the quality of our code when things need to change so fast?</p>

<h3>A confession</h3>

<p>OK: I'm guilty of releasing untested code in the past, where I've needed to meet deadlines. I'm probably not alone. And if you're a developer who's worked in a big team, you'll know that often you'll have to work with code that was written by your predecessors or contractors who didn't create 'test-friendly' code. Often this means having to waste time re-writing the code so that it can be tested. Naturally, this eats into your valuable development time during <a href="http://en.wikipedia.org/wiki/Sprint_(scrum)">sprint cycles</a>.</p>

<p>The <a href="http://en.wikipedia.org/wiki/Agile_Manifesto">Agile Manifesto</a> states that we should value "<em>Working software over comprehensive documentation</em>". Some might see a problem here, because this seems to place a higher importance on "working software" than the quality of that software. The way I see it, you can't truly maintain "working software" if it's not well-tested... and the truth remains that many developers compromise good test coverage in order to complete tasks by the deadline. So what can we do?</p>

<h3>A compromise</h3>

<p>One thing I love about Python is its built-in support for documentation and testing. Even if you're not in the habit of writing unit tests for your code, you should at least comment your code so that you and other developers know what your classes and methods do. Python's "<a href="http://docs.python.org/library/doctest.html">doctest</a>" kills two birds with one stone: as you write your comments, you can optionally specify how the code should be used and what the expected outcome should be. Comments now serve as valuable documentation for your code, and can be executed as a test to ensure your logic is intact.</p>

<p>This method is not supposed to replace unit tests. In fact, there's only so much you can do with doctests, and your code can quickly become a huge mess if you try to write too many. But the idea is that they can be quickly used when you don't have time to write a full test suite. Some tests is better than no tests.</p>

<p>Let's have a look at an example in Python first:</p>

<pre><code>def greetings(your_name):
    return 'hello, %s!' % (your_name)</code></pre>

<p>This function takes a person's name as an argument and returns a greetings message. Let's add this description and a test to the docs:</p>

<pre><code>def greetings(your_name):
    """
    This function takes a person's name and 
    returns a greetings message
    >>> greetings('Auntie')
    'hello, Auntie!'
    """
    return 'hello, %s!' % (your_name)</code></pre>

<p>When you execute this script, Python is smart enough to know ">>>" means the comment needs to be interpreted as code and what the returned value should be.</p>

<p>We use PHP at the BBC, so I did some research and came across a PHP equivalent called <a href="http://pear.php.net/package/Testing_DocTest/">PHPDT</a>, which can be installed via Pear. Here's the PHP version of the above function:</p>

<pre><code>/**
* This function takes a person's name and 
* returns a greetings message
* <code>
* greetings('Auntie');
* // expects:
* // 'hello, Auntie!'
* </code>
*/
function greetings($your_name)
{
    return 'hello, ' . $your_name . '!';
}</code></pre>

<p>You can test this by running <code>$ phpdt example.php</code> in your terminal. The comments inside the <code>&lt;code&gt;</code> tags will be interpreted as PHP code.</p>

<h3>Testing times</h3>

<p>These are simple examples, but you can see how easily you could combine your comments with some testing to make sure that any accidental changes in your code are caught. Again, doctests aren't meant to replace unit tests, but they might help to keep things working when you're faced with the need to write code faster than your tests can keep up.</p>

<p>I plan to try adding doctests to my code, as well as continue writing proper unit tests in <a href="http://www.phpunit.de/">PHPUnit</a>. I'd be really interested to hear from anyone who has tried this approach: on large applications, is this a good way to move fast without letting your test coverage slip?</p>]]>
        
    </content>
</entry>

<entry>
    <title>Extending OpenSocial and Shindig: a crash course</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2009/11/extending-opensocial-and-shind.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=163911" title="Extending OpenSocial and Shindig: a crash course" />
    <id>tag:www.bbc.co.uk,2009:/blogs/webdeveloper//311.163911</id>
    
    <published>2009-11-06T11:20:11Z</published>
    <updated>2009-11-09T13:22:15Z</updated>
    
    <summary>Hi, I&apos;m Ben Smith, and I&#8217;m developing a new set of web services that add social features to BBC Online. Starting this project was clearly an exciting prospect, but without a handy crash course on how to get going, we...</summary>
    <author>
        <name>Ben Smith</name>
        <uri>http://thesmith.co.uk</uri>
    </author>
    
        <category term="Social" />
    
        <category term="Web Services" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Hi, I'm <a href="http://thesmith.co.uk">Ben Smith</a>, and I&#8217;m developing a new set of web services that add social features to BBC Online. Starting this project was clearly an exciting prospect, but without a handy crash course on how to get going, we ran into our fair share of problems. Now that we&#8217;ve solved a few of them, I thought I&#8217;d better start writing about it.</p>

<h3>Forging ahead</h3>

<p>The BBC&#8217;s overall web architecture has been rebuilt over the last couple of years, and a new breed of websites is now starting to appear (the platform's called 'The Forge', and you'll hear more about it soon). In a nutshell, these new sites are delivered through an application layer that relies on making HTTP calls to <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a>ish web services to get the data they need.</p>

<p>If we want to develop something social, we need some social web-services, and you don&#8217;t have to look too far into this before the <a href="http://www.opensocial.org/">OpenSocial</a> <a href="http://www.opensocial.org/Technical-Resources/opensocial-spec-v09/REST-API.html">RESTful specification</a> jumps out and does a little dance in front of you. (Well, that&#8217;s what it did for me, but I may have been <a href="http://twitter.com/thesmith/status/5388980272">drinking too much coffee</a>.)</p>

<h3>It&#8217;s Open and it&#8217;s Social</h3>

<p>OpenSocial defines a common set of APIs that applications can be developed against. The REST API allows applications to make HTTP requests, and get back things like a list of a user&#8217;s friends</p>

<pre><code>/people/&lt;userId&gt;/@friends</code></pre>

<p>or their recent activity</p>

<pre><code>/activities/&lt;userId&gt;/@friends</code></pre>

<p>Lovely stuff. Not only do we have a specification to work to, we have a popular one that many applications have already been developed against.</p>

<p>Additionally, to aid in the development of OpenSocial-compliant sites, the <a href="http://incubator.apache.org/">Apache Incubator</a> project <a href="http://incubator.apache.org/shindig/">Shindig</a> provides OpenSocial implementations in both <a href="http://svn.apache.org/repos/asf/incubator/shindig/trunk/java/">Java</a> and <a href="http://svn.apache.org/repos/asf/incubator/shindig/trunk/php/">PHP</a>. As the BBC&#8217;s new platform is particularly fond of developing web services in Java, it&#8217;s all looking pretty good.</p>

<h3>Is that it?</h3>

<p>Unfortunately, life is never that easy. OpenSocial is designed to be a generic API to present your data through, whether you&#8217;re a <a href="http://google.com">Google</a>, a <a href="http://myspace.com">MySpace</a> or a jonnynewsite.com. But different websites have different needs: different relationship models, and various data and business logic around the creation of things like new users or relationships between them. It would be presumptuous of OpenSocial to define how a website should approach them, so it doesn&#8217;t.</p>

<p>For example, while OpenSocial allows clients to get a user&#8217;s information:</p>

<pre><code>/people/&lt;userId&gt;/@self</code></pre>

<p>it doesn&#8217;t define a way to create a new user. So we have to do these things ourselves.</p>

<h3>A bit of a Shindig</h3>

<p>Shindig, the OpenSocial container implementation, quite rightly implements the OpenSocial specification and no more. As everyone will have their own infrastructure, with different databases, key-value stores and identity systems, Shindig defines software-level <a href="https://svn.apache.org/repos/asf/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/">interfaces</a> for you to implement. So, for Shindig to be able to respond to:</p>

<pre><code>/people/&lt;userId&gt;/@self</code></pre>

<p>you need to implement:</p>

<pre><code>Future&lt;Person&gt; getPerson(
    UserId id, Set&lt;String&gt; fields, SecurityToken token)
    throws ProtocolException;</code></pre>

<p>which is defined in the <a href="https://svn.apache.org/repos/asf/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/PersonService.java">PersonService</a> interface.</p>

<h3>Extending OpenSocial</h3>

<p>The BBC website has no social graph or any real social features to speak of. This meant that when we started, we were presented with an interesting opportunity: with no existing system to integrate with, could we extend the OpenSocial spec, and Shindig itself, to provide the features we were missing?</p>

<p>As I mentioned before, OpenSocial allows clients to retrieve a user&#8217;s friends:</p>

<pre><code>/people/&lt;userId&gt;/@friends</code></pre>

<p>So, to create a friendship between two users that&#8217;s consistent with the existing API calls, it seemed reasonable to POST a document (JSON in this case) that contains the new friend&#8217;s userId to the same URL:</p>

<pre><code>POST {id: &#8216;&lt;friendId&gt;&#8217;}
/people/&lt;userId&gt;/@friends</code></pre>

<p>Some may argue that a PUT to:</p>

<pre><code>/people/&lt;userId&gt;/@friends/&lt;friendId&gt;</code></pre>

<p>would smell more RESTful, but it&#8217;s not really any better and, considering the <a href="http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven">criticisms</a> of OpenSocial&#8217;s RESTful-ness, keeping the API consistent was most important. However, if we were, say, keeping a description of the type of friendship (colleague, family, etc.) then we would need to be able to update that metadata, and would have PUT to the specific friendship resource:</p>

<pre><code>PUT {type: &#8216;colleague&#8217;}
/people/&lt;userId&gt;/@friends/&lt;friendId&gt;</code></pre>

<h3>Extending Shindig</h3>

<p>To add this function to Shindig, it&#8217;s a matter of extending the right bits. I&#8217;ve created a <a href="http://github.com/thesmith/bbc-shindig-example">repository</a> on <a href="http://github.com">github.com</a> that shows how you can do this, but it&#8217;s worth saying that this isn&#8217;t production code, especially as it is backed by a non-persistent JSON store (and probably has more bugs in it than a <a href="http://www.flickr.com/photos/thesmith/81762463/">student&#8217;s beard</a>). As I mentioned earlier, Shindig specifies a service layer for you to implement. Conveniently, they also provide a <a href="http://svn.apache.org/repos/asf/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java">sample implementation</a> that persists to an in-memory JSON store which is populated with dummy data.</p>

<p>Shindig is sensibly split into layers: the <a href="http://svn.apache.org/repos/asf/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/">domain model layer</a>, the <a href="http://svn.apache.org/repos/asf/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/">service layer</a>, and the <a href="http://svn.apache.org/repos/asf/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/">request handling layer</a> (there&#8217;s actually a lot more to it than that, but you can read about that here). To extend the RESTful API you have to define the new endpoint in the appropriate handler, and a service that will administer the appropriate model objects.</p>

<p>So, to allow clients to POST new friendships to /people/&lt;userId&gt;/@friends, you must firstly extend the <a href="https://svn.apache.org/repos/asf/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java">PersonHandler</a>:</p>
<pre><code>@Service(name = &#8220;people&#8221;, path = &#8220;/{userId}+/{groupId}/{personId}+&#8221;) 
public class PersonHandlerImpl extends PersonHandler {</code></pre>

<p>Now you can implement a createFriends() method that will respond to POSTs to /people/&lt;userId&gt;/@friends:</p>
<pre><code>@Operation(httpMethods = &#8220;POST&#8221;, path = &#8220;/{userId}+/@friends&#8221;)
public Future&lt;?&gt; createFriends(SocialRequestItem request) 
    throws ProtocolException {</code></pre>

<p>You can see exactly how this is done in <a href="http://github.com/thesmith/bbc-shindig-example/blob/master/src/main/java/bbc/social/shindig/example/handler/PersonHandlerImpl.java">PersonHandlerImpl</a>. The annotations are Shindig&#8217;s own home-brewed routing mechanism, but they&#8217;re pretty standard MVC controller fare. The handler itself shouldn&#8217;t do the work of creating a friendship, but should leave this to a service <a href="http://github.com/thesmith/bbc-shindig-example/blob/master/src/main/java/bbc/social/shindig/example/service/RelationshipService.java">interface for the management of relationships</a>:</p>

<pre><code>public interface RelationshipService {
  public void createRelationship(String personId, String friendId);</code></pre>

<p>Now you have to implement the RelationshipService, in much the same way as you need to implement Shindig&#8217;s own standard services. As this is an example I simply <a href="http://github.com/thesmith/bbc-shindig-example/blob/master/src/main/java/bbc/social/shindig/example/service/impl/JsonDbServiceExample.java">extended the JSON implementation</a> to include a fleshed out createRelationship() method:</p>

<pre><code>public class JsonDbServiceExample extends JsonDbOpensocialService
    implements RelationshipService {
  public void createRelationship(String personId, String friendId) {</code></pre>

<h3>Dependency issues</h3>

<p>This is all fine and dandy, but how do any of these pieces actually know to use each other?</p>

<p>Shindig uses <a href="http://code.google.com/p/google-guice/">Google-Guice</a>, a lightweight dependancy injection framework, which you use to tell the system that you actually want to use your handler and service implementations over theirs. To do this, you simply reference your own <a href="http://github.com/thesmith/bbc-shindig-example/blob/master/src/main/java/bbc/social/shindig/example/GuiceModule.java">GuiceModule</a> in your <a href="http://github.com/thesmith/bbc-shindig-example/blob/master/src/main/webapp/WEB-INF/web.xml">web.xml</a> or <a href="http://github.com/thesmith/bbc-shindig-example/blob/master/src/test/java/bbc/social/shindig/example/handler/RestfulJsonPeopleTest.java">tests</a>.</p>

<p>It&#8217;s also worth mentioning that you can integrate Shindig and Guice with <a href="http://www.springsource.org/">Spring</a>, which also provides dependancy injection and is very popular, as <a href="http://twitter.com/ccharlesworth">Chico Charlesworth</a> <a href="http://cwiki.apache.org/SHINDIG/shindig-spring-example.html">documents</a> on the Shindig <a href="http://cwiki.apache.org/SHINDIG/">wiki</a>.</p>

<p>Anyway, if you fancy trying it out, <a href="http://git-scm.com/">git</a> <a href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html">clone</a> the <a href="http://github.com/thesmith/bbc-shindig-example">example</a> and, assuming the code still works, tinker to your heart&#8217;s content.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Introducing BBC iD</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2009/10/introducing-bbc-id.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=161321" title="Introducing BBC iD" />
    <id>tag:www.bbc.co.uk,2009:/blogs/webdeveloper//311.161321</id>
    
    <published>2009-10-29T17:48:04Z</published>
    <updated>2009-11-19T17:53:07Z</updated>
    
    <summary>It&apos;s taken a lot of work, and there&apos;s plenty more to do, but BBC iD is now starting to appear across BBC Online. There&apos;s an article over on the BBC Internet Blog that explains what this means if you have...</summary>
    <author>
        <name>Richard Northover</name>
        <uri>http://richard.northover.info</uri>
    </author>
    
        <category term="BBC iD" />
    
        <category term="Blog" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>It's taken a lot of work, and there's plenty more to do, but BBC iD is now starting to appear across BBC Online.</p>

<p>There's <a href="https://bbcstreaming.pages.dev/blogs/bbcinternet/2009/10/welcome_to_bbc_id.html">an article over on the BBC Internet Blog</a> that explains what this means if you have an existing account, and outlines a few of the changes you can expect over the coming weeks. If you have any problems, you can find answers in the new <a href="https://id.bbc.co.uk/users/help">FAQ section</a>.</p>

<p>As well as supporting existing services, BBC iD will evolve to allow us to start building some new and previously impossible things. This, as they say, is just the beginning... and we'll explain some of the developments here as we go along.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Planning Glow 2 - we want your feedback!</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2009/10/planning-glow-2-we-want-your-f.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=150900" title="Planning Glow 2 - we want your feedback!" />
    <id>tag:www.bbc.co.uk,2009:/blogs/webdeveloper//311.150900</id>
    
    <published>2009-10-26T10:08:20Z</published>
    <updated>2009-10-26T10:17:46Z</updated>
    
    <summary>Now we&apos;ve got Glow 1.7 out the door, our minds are turning towards planning for version 2, our next major release which will be out in the new year. We&apos;re planning a significant overhaul, and as the major version increment...</summary>
    <author>
        <name>Frances Berriman</name>
        <uri>http://fberriman.com</uri>
    </author>
    
        <category term="Glow" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Now we've got <a href="https://bbcstreaming.pages.dev">Glow</a> 1.7 out the door, our minds are turning towards planning for version 2, our next major release which will be out in the new year.  We're planning a significant overhaul, and as the major version increment indicates this will include a fundamental rewrite of large portions of the library.</p>
 
<p>Now is also a great time for users and contributors to get involved. Please tell us what you've liked and disliked about version 1, and what features you'd most like to see in version 2.</p>
 
<p>We have produced a set of four themes that we'd like to explore in Glow 2. These might get you thinking about what your perfect desert island library would contain, or maybe you think we've missed something vital?</p>
 
<ul>
<li>Accessibility - provide a step-change in accessible and usable widgets</li>
<li>Performance - reduce load and execution times to the bare minimum</li>
<li>Design - build widgets that look fantastic alone or in combination</li>
<li>Community - open up the project and help the community thrive</li>
</ul>
 
<p><strong>We really want to hear what you think</strong>.  If you'd like to talk to us about your ideas then join us on our <a href="https://bbcstreaming.pages.dev/glow/community/mailing_lists.shtml">mailing list</a>, chat with us on <a href="https://bbcstreaming.pages.dev/glow/community/irc.shtml">IRC</a> or you can send <a href="http://twitter.com/bbcglow">@bbcglow</a> a message on twitter or by adding the hastag #bbcglow2 - we'll do our best to respond to everyone who sends us a suggestion.</p>]]>
        
    </content>
</entry>

<entry>
    <title>CSS Resets</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2009/10/css-resets.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=155688" title="CSS Resets" />
    <id>tag:www.bbc.co.uk,2009:/blogs/webdeveloper//311.155688</id>
    
    <published>2009-10-20T14:20:04Z</published>
    <updated>2010-01-05T16:17:48Z</updated>
    
    <summary>Like many sites, bbc.co.uk uses a &apos;CSS reset&apos;. What are they, and how did we design ours?</summary>
    <author>
        <name>Mat Hampson</name>
        
    </author>
    
        <category term="Barlesque" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Hi, I'm Mat, and I work on bbc.co.uk's page layout system, Barlesque. You may have seen it, and its amusing name, <a href="https://bbcstreaming.pages.dev/blogs/bbcinternet/2008/05/barlesque.html">discussed before over on the BBC Internet blog</a>, but here I'm going to give you a bit more of a technical insight into how it actually works. Before that though, a quick 140 characters on what it actually does:</p>

<p class="snippet-highlight">Barlesque delivers the head and foot of every page on bbc.co.uk, as well as all the pan-site modules: registration, survey, advertising etc.</p>

<p>There's lots of things I want to talk about at some point: download efficiency for millions of page views per day, writing front end code to play nicely with other people's code, making Barlesque available on lots of different server environments, and so on. However I'm going to start with one of the very first client-side features we wrote: a CSS reset.</p>

<h3>Resetting the scene</h3>

<p>A CSS reset is a snippet that zeroes CSS values for all elements - zero padding and margins, no borders, 100% font sizing and so on. They've been around far longer than Barlesque, for example <a href="http://meyerweb.com/eric/tools/css/reset/">this one from (the extremely smart) Eric Meyer</a>.</p>

<p>When investigating them for Barlesque, we pretty quickly decided a reset would be of overall benefit to developers on bbc.co.uk: we have <a href="https://bbcstreaming.pages.dev/guidelines/futuremedia/technical/browser_support.shtml">a lot of browsers to support</a> and zeroing everything would get rid of those inconsistent default values, like paragraph margins for example, that different browsers have. Also, with so many developers swapping code, moving around the business, debugging each others work and so on, it would be a big win to have everyone's stuff starting from the same known base.</p>

<p>Looking round, though, there were a few things used in some existing resets we weren't so keen on; for example:</p>

<p class="content-image-opposite"><img src="https://bbcstreaming.pages.dev/blogs/webdeveloper/article_resources/2009/10/reset_firebug_pollution.gif" alt="Screenshot of Firebug's CSS inspector showing the potential repetition caused by a 'noisy' reset" width="250" height="342" /></p>

<ul>

<li>Setting a load of values on every element, particularly containing elements like &lt;div&gt;s, makes a right mess of Firebug's CSS inspector - it's a long statement, and if you nest some elements (e.g. an &lt;a&gt; in an &lt;li&gt; in a &lt;ul&gt; in a &lt;div&gt;) then Firebug puts it in the pane multiple times (as shown in the screenshot opposite).</li>

<li>Some stronger resets were putting font-weight:normal on strong, taking the italics off, or other things which I felt would break developer expectations.</li>

<li>Outline was sometimes removed, however it's <a href="http://www.456bereastreet.com/archive/200905/do_not_remove_the_outline_from_links_and_form_controls/">important for keyboard navigation</a>.</li>

</ul>

<p>So we made a key decision for our reset: We'd only change values that varied between browsers. For example since all browsers default to zero margins, padding and borders on a div, we left it alone in the reset.</p>

<p>We did this by making some sample content using all commonly used elements and trying it in lots of browsers. For the fine tuning we took a screenshot the content, then setting that picture as the background to the file so we could see if other browsers overlaid it perfectly.</p>

<p>In doing this we were also able to break the reset down into multiple declarations, thus ensuring it didn't interfere too much with Firebug.</p>

<p><strong><a href="https://bbcstreaming.pages.dev/blogs/webdeveloper/article_resources/2009/10/reset.css">Here's a css file containing the uncompressed reset code as it stands now</a>.</strong></p>

<h3>regret.css</h3>

<p>Of course, there were one or two 'issues' along the way. In the process of trying to get the test page to look consistent, we used <code>list-style:none;</code> on lists, which breaks expectations and causes support queries to this day, but which we can't change without breaking backward compatibility. (Sorry about that, bbc.co.uk devs.)</p>

<p>A more major thing we'd consider changing if we got to do it again is that we'd probably avoid zeroing typographical values, instead applying default padding, margins and header sizing. This wouldn't require any more CSS for those who didn't want the default, but would mean those who didn't mind it would need no code at all. You live and learn. Instead we've provided <a href="https://bbcstreaming.pages.dev/includes/blq/include/help/developer_tools/css_framework01.shtml">a default typography class</a> to help those without a specified typography in their designs.</p>

<h3>Classy</h3>

<p>So that's the basic reset. However, as mentioned before, developers do share code quite a lot around the site. This sometimes means dropping one developer's front end code into a page amongst another's. We thought it would be handy if the reset was available as a CSS class as well, to act as the foundation for embedded snippets. This did mean making more declarations, because it has to override what the sites may have defined, rather than just what the browsers differ on. It's also made more verbose by having to prefix all the elements with the class name (in this case "blq-rst") so this one really does make a mess in Firebug... but at least it's optional.</p>

<p>Coincidentally, the first customer for this reset class was actually Barlesque itself: the masthead and the footer of the page were exactly the sort of snippets that could do with a bit of protection from page-wide declarations made by the sites. Add .blq-rst and they stay looking ok, <a href="https://bbcstreaming.pages.dev/includes/blq/include/help/developer_tools/regression_tests/test_basic_css_override.shtml">as this test page shows</a>.</p>

<p>Of course, Everyone has their own take on these things, so comments and suggestions are welcome as always.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Glow 1.7 release</title>
    <link rel="alternate" type="text/html" href="https://bbcstreaming.pages.dev/blogs/webdeveloper/2009/10/glow-17-release.shtml" />
    <link rel="service.edit" type="application/atom+xml" href="https://bbcstreaming.pages.dev/cgi-perlx/blogs/mt-atom.cgi/weblog/blog_id=311/entry_id=150869" title="Glow 1.7 release" />
    <id>tag:www.bbc.co.uk,2009:/blogs/webdeveloper//311.150869</id>
    
    <published>2009-10-13T11:34:48Z</published>
    <updated>2009-11-24T11:57:41Z</updated>
    
    <summary>Hi, I&apos;m Frances and I work on Glow, the BBC&apos;s JavaScript library, alongside Jake, Michael and Stephen. We&apos;re looking forward to keeping you up to date on what&apos;s going on with the project on this lovely new web developer blog....</summary>
    <author>
        <name>Frances Berriman</name>
        <uri>http://fberriman.com</uri>
    </author>
    
        <category term="Glow" />
    
    <content type="html" xml:lang="en" xml:base="https://bbcstreaming.pages.dev/blogs/webdeveloper/">
        <![CDATA[<p>Hi, I'm <a href="http://fberriman.com">Frances</a> and I work on <a href="https://bbcstreaming.pages.dev/glow">Glow</a>, the BBC's JavaScript library, alongside Jake, Michael and Stephen.  We're looking forward to keeping you up to date on what's going on with the project on this lovely new web developer blog.</p>

<p>The big news this week is that we've released <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/">Glow 1.7.0</a>, which is now available to <a href="https://bbcstreaming.pages.dev/glow/download/">download</a>. This release focuses on stability and overall usability; we've fixed a number of bugs, added handy new features to the DOM module, and improved accessibility for some of the widgets. Here's a quick overview...</p>

<p>The core <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.dom.nodelist.shtml">glow.dom.NodeList</a> class gets a range of new methods:</p>

<ul> 
<li><a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.dom.nodelist.shtml#method:ancestors">ancestors()</a> - get all the ancestors of a node</li>

<li><a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.dom.nodelist.shtml#method:data">data()</a> &amp; <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.dom.nodelist.shtml#method:removedata">removeData()</a> - associate arbitrary data with elements in a memory efficient way</li> 

<li><a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.dom.nodelist.shtml#method:scrollleft">scrollLeft()</a> &amp; <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.dom.nodelist.shtml#method:scrolltop">scrollTop()</a> - get and set the scroll position of the document or elements</li>

<li><a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.dom.nodelist.shtml#method:wrap">wrap()</a> &amp; <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.dom.nodelist.shtml#method:unwrap">unwrap()</a> - add and remove parent nodes to elements</li>

</ul> 

<p>The <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.widgets.autosuggest.shtml">AutoSuggest</a> widget also receives a bit of attention. We have made a few UI bug fixes, changed the behaviour of the left/right keys to be more consistent with similar interfaces (such as Firefox's search box). There are also some new events, the option to filter model data before it is displayed and an way to control the caching of data from URLs. You can also disable the text highlighting feature that is used by default when using the "complete" option.</p>

<p>Other changes include the addition of heading and list formatting options to the <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.widgets.editor.shtml">Editor</a> widget, and an improvement to the <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.net.shtml">glow.net</a> module's handling of XML returned with the wrong mime type.</p>

<p>Last but not least, we have also improved some of our accessibility features. The <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.widgets.overlay.shtml">Overlay</a> widget now prevents focus from going to other elements when set to "modal", <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.widgets.infopanel.shtml">InfoPanel</a> has better ARIA support and the <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/api/glow.widgets.slider.shtml">Slider</a> widget has more intuitive keyboard access for screenreader users.</p>

<p>Take a look at the <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/about/">1.7 overview page</a> for more details, including the full <a href="https://bbcstreaming.pages.dev/glow/docs/1.7/about/#changelog">changelog</a>.</p>

<p>If you're interested in knowing more about Glow, or even if you're already using it, we've got plenty of ways for you to <a href="https://bbcstreaming.pages.dev/glow/community">get in touch</a> with us:</p>

<ul> 
<li>Google Group - join in at <a href="http://groups.google.com/group/glow-users">glow-users</a></li> 
<li>IRC - join us on irc.freenode.net in #glow</li> 
<li>Twitter - follow us at <a href="http://twitter.com/bbcglow">@bbcglow</a></li> 
</ul> 
]]>
        
    </content>
</entry>

</feed> 