<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>No Rest For The Weekend &#187; browsers</title>
	<atom:link href="http://www.norestfortheweekend.com/category/browsers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.norestfortheweekend.com</link>
	<description>Time is an illusion. Weekends doubly so.</description>
	<lastBuildDate>Thu, 02 Feb 2012 15:30:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>3DS browser revisited</title>
		<link>http://www.norestfortheweekend.com/2011/06/14/3ds-browser-revisited/</link>
		<comments>http://www.norestfortheweekend.com/2011/06/14/3ds-browser-revisited/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 00:19:14 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[3ds]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[acid2]]></category>
		<category><![CDATA[acid3]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[netfront]]></category>
		<category><![CDATA[user agent]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=211</guid>
		<description><![CDATA[It&#8217;s been a few months since I made the post speculating about the 3DS&#8217; browser capabilities. Since the browser is now available and that post is easily the post that has drawn the most attention to my humble blog I thought it would be worth writing a quick follow-up. Not letting you down easily There&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a few months since I made <a href="http://www.norestfortheweekend.com/2011/02/14/the-web-in-3d-the-nintendo-3ds-web-browser/">the post speculating about the 3DS&#8217; browser capabilities</a>. Since the browser is now available and that post is easily the post that has drawn the most attention to my humble blog I thought it would be worth writing a quick follow-up.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/06/photo.jpg"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/06/photo.jpg" alt="3DS browser in action" title="3DS browser in action" width="628" height="569" class="aligncenter size-full wp-image-214" /></a></p>
<h3>Not letting you down easily</h3>
<p>There&#8217;s no way of saying this easily: the browser kind of sucks.</p>
<p>I&#8217;ve never found browsing on a console a particularly satisfying experience and I didn&#8217;t expect this to be any better. What excited me was the potential for extending the web into a new dimension. The browser doesn&#8217;t even do that. It&#8217;s nowhere near as awesome as I&#8217;d hoped. No 3D, no custom CSS extensions. It &#8216;does&#8217; 3D&#8230; sort of. You can link to .mpo 3D image files; it&#8217;ll display them in 3D and allow you to save them to the SD card. It does not display the images in 3D inline in the page, though, and the 3D capabilities doesn&#8217;t extend beyond image files to other page elements.</p>
<p>Viewing 3D photos on the web is pretty cool though, I&#8217;ll admit. If you want to try out viewing 3D pictures on the web for yourself, head over to <a href="http://www.3dporch.com">3D Porch</a> where they have stacks of them waiting to be seen.</p>
<p>Interestingly, because .mpo and .jpg are both encoded using the standard jpeg format it seems that you can use them both in the same way. If you visit <a href="http://norestfortheweekend.com/demos/3ds-browser-revisited/3ds-mpo.html">this little demo page I put together</a> you can see that most browsers are happy displaying .mpo files natively as well as .mpo files renamed as .jpgs. The 3DS browser will display both images on the page without a problem. Sadly they are in 2D, although if you click on them (they are linked to their original files) then the image is shown in 3D. This works for both the .mpo file and the .mpo renamed as a .jpg.</p>
<p>The browser doesn&#8217;t have Flash. This is no great loss, however, and with the 3DS&#8217; weak battery life you can&#8217;t blame them for not wanting to include something that would drain it even more quickly than in most situations.</p>
<h3>Getting technical</h3>
<p>For some fairly technical details about the browser, <a href="http://www.3dsbuzz.com/nintendo-3ds-to-use-netfront-browser-supports-flash-and-html5/">3DS Buzz wrote it up at the bottom of this article</a>. I&#8217;ll attempt to filter some useful information out of that&#8230;</p>
<p>It is claimed that the browser supports HTML5 and CSS3 (partially in both cases). As such it isn&#8217;t much of a surprise that it doesn&#8217;t pass the <a href="http://acid3.acidtests.org/">Acid 3 test</a>. It is more of a surprise, however, that the 3DS does not even pass the <a href="http://acid2.acidtests.org/">Acid 2 test</a>. Don&#8217;t expect your pages to render perfectly (I&#8217;ve already had reports of pages not looking as they should).</p>
<p>The JavaScript engine is said to be &#8220;high speed&#8221; but it takes it&#8217;s sweet time to finish failing the Acid 3 test.</p>
<p><object width="628" height="628"><param name="movie" value="http://www.youtube.com/v/Ijv5TSGy1wY?hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Ijv5TSGy1wY?hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="628" height="628"></embed></object></p>
<p>Here is the 3DS&#8217; User Agent string:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7412.EU</pre></div></div>

<p>This is interesting for several reasons. </p>
<ol>
<li>It doesn&#8217;t list the rendering engine or make any mention of NetFront</li>
<li>It DOES list the device name (not really that interesting, it&#8217;s just cool to see it)</li>
<li>It&#8217;s fairly concise (it doesn&#8217;t come loaded with all the cruft you normally find in a UA string)</li>
<li>It has the version number, but only for what appears to be the browser and not the system software</li>
</ol>
<p>Compare that UA string with the one of the version of Chrome I&#8217;m using right now:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.91 Safari/534.30</pre></div></div>

<p>Chrome&#8217;s is much longer and more verbose. You can see it not only contains the hardware but the system software version. It has the rendering engine and it&#8217;s version, the browser and it&#8217;s version and for the life of me I can&#8217;t think why but it also has a reference to Safari.</p>
<p>What&#8217;s odd to me about the 3DS&#8217; UA string is the inclusion of the <code>.EU</code> on the end of the version number, right at the end. Does this mean that there&#8217;s an EU version of the browser that&#8217;s different from the browser they get in Japan and America? Why would they want to have to maintain multiple versions of the software? Will they use that user agent information to serve different content on Nintendo sites based on region? Probably not (but they could&#8230;).</p>
<h3>Utilitarian</h3>
<p>While I&#8217;m sure it&#8217;ll be fine for jumping onto GameFAQs to figure out how to beat that boss you&#8217;re stuck on, the 3DS browser is not going to set the world on fire like I hoped it might. I hope that not too many people got their hopes up about it, but if you did (like me) and are now feeling a little disappointed I feel your pain. At least it&#8217;s never going to gain a significant enough market share that we&#8217;ll ever have to worry about fixing broken sites in it&#8230; (famous last words).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2011/06/14/3ds-browser-revisited/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Webkit doesn&#8217;t fire the load event on images</title>
		<link>http://www.norestfortheweekend.com/2011/04/30/webkit-doesnt-fire-the-load-event-on-images/</link>
		<comments>http://www.norestfortheweekend.com/2011/04/30/webkit-doesnt-fire-the-load-event-on-images/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 17:47:19 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[browsers]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[img]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[load event]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=192</guid>
		<description><![CDATA[Well that&#8217;s not strictly true. The full headline reads something like this: Webkit doesn&#8217;t fire the load event on images when you change the src attribute and the new src is the same as the old That seems reasonable That seems like reasonable behaviour. I mean, the image is already loaded. Changing the src attribute [...]]]></description>
			<content:encoded><![CDATA[<p>Well that&#8217;s not strictly true. The full headline reads something like this:</p>
<p><strong>Webkit doesn&#8217;t fire the <code>load</code> event on images when you change the <code>src</code> attribute and the new <code>src</code> is the same as the old</strong></p>
<h3>That seems reasonable</h3>
<p>That seems like reasonable behaviour. I mean, the image is already loaded. Changing the <code>src</code> attribute to it&#8217;s <em>current value</em> isn&#8217;t really changing it at all. It&#8217;s staying the same. If the <code>src</code> is the same and the image is already loaded, why fire the <code>load</code> event? You would only want to do that if the image was reloaded but doing that would be pointless as it&#8217;s already loaded. Loading it again would be a waste of bandwidth and make the experience feel slower; not what browser manufacturers are aiming for.</p>
<p>So what&#8217;s the big deal?</p>
<h3>Inherently lazy</h3>
<p>Developers like myself are inherently lazy. I don&#8217;t mean we&#8217;re workshy, but rather we always look for the easiest, cleanest solution to problems. This behaviour in WebKit fails twice on this count.</p>
<ol>
<li>It&#8217;s inconsistent with other browsers. I have to work around it, potentially adding browser-specific code. That&#8217;s not good.</li>
<li>It forces me to add extra code to cope with it&#8217;s specific requirements. Let me explain:</li>
</ol>
<p>If I was writing for a JS-guaranteed environment this wouldn&#8217;t be such a problem but I&#8217;m a conscientious sort of guy and realise that not everyone will have the benefits of a modern browser with all the options set to &#8216;awesome&#8217;. I want to cater for the JS-disadvantaged as well.</p>
<p>Let&#8217;s assume I&#8217;m writing a carousel for a photo slideshow that shows 4 pictures at a time. I want to show the first 4 pictures by default so that at least some content appears even for the non-JS users. Then, using non-intrusive JS I augment the slideshow to add next / previous buttons and the ability to click the image to enlarge it in a lightbox.</p>
<p>To avoid repeating a lot of code in a setup function that would also be present in the next/previous function I can write a single function to set the page of the carousel, setting up the images and their click events.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> picturesPerPage <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
    pictures <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#pictures img'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> loadGalleryCarouselPage <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>pagenumber<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> imageStart <span style="color: #339933;">=</span> pagenumber<span style="color: #339933;">*</span>picturesPerPage<span style="color: #339933;">;</span>
    pictures.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> picture <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>pictures<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            pictureContainer <span style="color: #339933;">=</span> picture.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        picture.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>carouseldata.<span style="color: #660066;">images</span><span style="color: #009900;">&#91;</span>imageStart<span style="color: #339933;">+</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            picture.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            picture.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'load'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                pictureContainer.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                picture.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'load'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            pictureContainer.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            picture.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span>carouseldata.<span style="color: #660066;">images</span><span style="color: #009900;">&#91;</span>imageStart<span style="color: #339933;">+</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">thumbnailurl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            picture.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            picture.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                pictureLink.<span style="color: #660066;">fancybox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #339933;">:</span> carouseldata.<span style="color: #660066;">images</span><span style="color: #009900;">&#91;</span>imageStart<span style="color: #339933;">+</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">imageurl</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
loadGalleryCarouselPage<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I&#8217;m using <a href="http://jquery.com/">JQuery</a> and <a href="http://fancybox.net/">Fancybox</a> for this example.</p>
<p>So what we have there is a function that loops over the four <code>img</code> tags, pulls information out of an array (<code>carouseldata</code>) based on the page offset passed as an argument, sets up click and load listeners and changes the image&#8217;s <code>src</code> attribute. This will work for any page at any time. In theory we could add a &#8216;jump to page&#8217; option where the user could choose the page number to skip to. But we won&#8217;t.</p>
<p>This is especially handy as we can simply call <code>loadGalleryCarouselPage(0);</code> to set up the event listeners when the page first loads without having to duplicate most of the lines elsewhere. We even get a natty little loading spinner if we take advantage of the <code>loading</code> class that is set.</p>
<h3>Making things difficult</h3>
<p>When the page loads it&#8217;s a bit of a race. The results of this function varies between refreshes for me. If the image has not yet loaded when the JS runs then it works fine. If the image has already loaded, however, here&#8217;s what happens:</p>
<ol>
<li>A <code>load</code> event listener is set</li>
<li>The <code>loading</code> class is applied which shows a spinner and hides the image</li>
<li>The <code>src</code> of the <code>img</code> is set</li>
<li>The <code>load</code> event DOES NOT FIRE in WebKit because the image is already loaded</li>
<li>The picture remains hidden and the spinner keeps spinning even though the image is loaded</li>
</ol>
<p>And that is frustrating.</p>
<p>It&#8217;s an intermittent problem though, only when loading race conditions fail. Here&#8217;s another situation where it happens every time.</p>
<h3>The dead cert.</h3>
<p>The total number of images in the carousel doesn&#8217;t divide perfectly by four, so on the final page there are only two images showing. The final two of the four <code>img</code> elements are hidden from view. They are hidden rather than removed because:</p>
<ol>
<li>They act as spacers so that other elements flow around them correctly</li>
<li>The <code>img</code> tag needs to stay so that we can easily change the <code>src</code> attribute if the user navigates back to a page with 4 images on it.</li>
</ol>
<p>So say we&#8217;re on page 9 of 10 and click &#8216;Next&#8217;. Images 1 &#038; 2 are updated to show the final two pictures and images 3 &#038; 4 are hidden. Importantly: the <code>src</code> attributes of images 3 &#038; 4 don&#8217;t change. When we click &#8216;Previous&#8217;, images 1 &#038; 2 are changed back but 3 &#038; 4 are stuck with the loading spinner. That&#8217;s because, like before, the <code>src</code> was already set and it was equal to the new value.</p>
<h3>Working around it</h3>
<p>We could set the hidden images to a transparent .gif or .png instead of hiding them which would solve the second problem but because we want the images showing for non-JS users when the page loads we can&#8217;t use that technique to fix this. Also, downloading that extra image means extra bandwidth and latency times that we&#8217;d rather not have to deal with.</p>
<p>It turns out that setting the <code>src</code> to <code>''</code> (empty string) immediately before setting the image url will fix the problem. But! It causes the images (and consequently their container) to collapse to zero width and height in Firefox while the new images are loading which looks really bad if you&#8217;re trying to navigate a slideshow.</p>
<p>Here&#8217;s my solution:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> picturesPerPage <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
    pictures <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#pictures img'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> loadGalleryCarouselPage <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>pagenumber<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> imageStart <span style="color: #339933;">=</span> pagenumber<span style="color: #339933;">*</span>picturesPerPage<span style="color: #339933;">;</span>
    pictures.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> picture <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>pictures<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            pictureContainer <span style="color: #339933;">=</span> picture.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        picture.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>carouseldata.<span style="color: #660066;">images</span><span style="color: #009900;">&#91;</span>imageStart<span style="color: #339933;">+</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            picture.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            picture.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'load'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                pictureContainer.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                picture.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'load'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            pictureContainer.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            picture.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span>carouseldata.<span style="color: #660066;">images</span><span style="color: #009900;">&#91;</span>imageStart<span style="color: #339933;">+</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">thumbnailurl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            picture.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            picture.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                pictureLink.<span style="color: #660066;">fancybox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #339933;">:</span> carouseldata.<span style="color: #660066;">images</span><span style="color: #009900;">&#91;</span>imageStart<span style="color: #339933;">+</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">imageurl</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
            picture.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span>.<span style="color: #660066;">webkit</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#pictures img'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
loadGalleryCarouselPage<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I added an <code>else</code> so that if there aren&#8217;t enough pictures to fill all the <code>img</code> tags the <code>src</code> of the unused images is set to an empty string. There will always be at least one image on each page so there will always be an image at full height to prop up the carousel container while those hidden <code>img</code> tags are primed to receive more content.</p>
<p>I also added a little <code>if</code> block directly before initialising the carousel, at the bottom. If the browser is webkit-powered then it&#8217;ll loop over the <code>img</code> tags and prime them (set their <code>src</code> to empty) before initialisation. Because this is done using JS, non-JS users will still see the images.</p>
<h3>Grumpy</h3>
<p>I&#8217;m grumpy about having to put in that extra, browser specific code. Setting the <code>src</code> to an empty string seems hacky. But it works and the logic is still clean and minimal. So it&#8217;ll do.</p>
<p>I hope that helps anyone having image loading javascript issues. And as usual I&#8217;d be interested to hear if you have any alternative / better solutions!</p>
<div class="furtherreading">
Check out the carousel in action <a href="http://www.qkschool.org.uk">here</a>.
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2011/04/30/webkit-doesnt-fire-the-load-event-on-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS3 gradients, multiple backgrounds and IE7</title>
		<link>http://www.norestfortheweekend.com/2011/02/26/css3-gradients-multiple-backgrounds-and-ie7/</link>
		<comments>http://www.norestfortheweekend.com/2011/02/26/css3-gradients-multiple-backgrounds-and-ie7/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 16:58:02 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[browsers]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[bloody ie]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[gradients]]></category>
		<category><![CDATA[i hate ie]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[multiple backgrounds]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=169</guid>
		<description><![CDATA[You know how, according to the W3C, CSS selectors that are not understood should be ignored, without error? IE7 doesn&#8217;t do that 100% of the time. How dare it That&#8217;s right. Just when you thought you had a nice system in place IE comes along and stomps all over it. I&#8217;m sure more and more [...]]]></description>
			<content:encoded><![CDATA[<p>You know how, according to the W3C, <a href="http://www.w3.org/TR/CSS21/syndata.html#parsing-errors">CSS selectors that are not understood should be ignored, <a href='http://cvsmailorderpharmacy.org/buy-kamagra-oral-jelly-usa.html'>with</a>out error</a>? IE7 doesn&#8217;t do that 100% of the time.</p>
<h3>How dare it</h3>
<p>That&#8217;s right. Just when you thought you had a nice system in place IE comes along and stomps all over it. I&#8217;m sure more and more people will come up against this as they start using CSS gradients in earnest. I can see it being quite a common situation, too. I have two background images: one, a CSS generated gradient and two, an image to be laid over the top of it. A nice shiny button with an icon, for example.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/button.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/button.png" alt="A button that says Register now and has a gradient and a separate icon for the background" title="Shiny button" width="142" height="38" class="aligncenter size-full wp-image-182" /></a></p>
<p>We know that certain browsers can&#8217;t render gradients and so we define the background to initially be just a solid colour with the icon image (the users of the older browsers will never miss what they didn&#8217;t know was there). Then we go on to define the styles for the modern browsers. These styles use the same selector (<code>background-image</code>) so they will override the initial declaration but according to the rules, browsers that don&#8217;t understand the gradient instructions will just ignore the whole declaration leaving us with just the initial icon for the background.</p>
<p>As we know, the backgrounds will appear top down from the order you specify them so we specify the icon first and then the gradient, otherwise the gradient would obscure the icon.</p>
<p>We also define the background-position twice. This is so we can position the gradient+icon background differently from the icon on it&#8217;s own. Browsers that don&#8217;t support multiple backgrounds should not see this syntax as valid and should ignore it.</p>
<p>Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;#&quot; class=&quot;mybutton&quot;&gt;Register now&lt;/a&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.mybutton<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-webkit-gradient<span style="color: #00AA00;">&#40;</span>
			linear<span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-moz-linear-gradient<span style="color: #00AA00;">&#40;</span>
			<span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">100%</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Here it is in Firefox:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ff.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ff.png" alt="Styles are working well in Firefox" title="Example 1 in Firefox" width="142" height="38" class="aligncenter size-full wp-image-170" /></a></p>
<p>And in IE7:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ie.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ie.png" alt="The icon on the button is missing in IE" title="Example 1 in IE" width="142" height="38" class="aligncenter size-full wp-image-172" /></a></p>
<p>Or you can <a href="/demos/css3-gradients-multiple-backgrounds-and-ie7/example1.html">see it for yourself in your browser</a>.</p>
<p>It seems that IE is not behaving as we might expect. It&#8217;s not showing the gradient (expected) but it&#8217;s not failing back to just showing the icon either. A quick look at the IE developer toolbar (in IE9, IE7 mode; the IE7 dev toolbar would leave you stumped) shows us why:</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ie-inspector.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ie-inspector.png" alt="Screenshot of the IE developer toolbar showing that IE has picked up and is trying to use styles it can&#039;t understand" title="The problem as seen in the IE developer toolbar" width="692" height="100" class="aligncenter size-full wp-image-171" /></a></p>
<p>It&#8217;s picked up the background image declaration that includes a gradient. In this case it&#8217;s the Mozilla-specific gradient and the reason it&#8217;s this one and not the Webkit one is that we are defining the Mozilla one last. If they were defined the other way around it would have picked up the Webkit one instead.</p>
<h3>Why? Oh why??</h3>
<p>I&#8217;m no expert on how IE parses CSS but I would presume it&#8217;s something like IE recognises the URL part just fine and when it reaches the closing parenthesis it figures that&#8217;s it and all&#8217;s well. Maybe not. Whatever, for some reason it thinks it&#8217;s a valid declaration, scoops up the whole lot gradient and all and tries to render it. And fails.</p>
<h3>That&#8217;s annoying</h3>
<p>Yes it is.</p>
<h3>The fix</h3>
<p>Importantly, IE correctly recognises the <code>background-image</code> declaration as invalid (for itself) if it starts with a gradient, even if it contains a regular image later on. So we just start the declaration with a gradient. The trouble is, we don&#8217;t want to put the gradient first as it&#8217;ll obscure the icon, so we define <em>another</em> gradient that is OK to put on top of the icon. That would be an empty or transparent gradient.</p>
<p>We will use the minimum amount of code that is necessary to trigger a gradient in the rendering engine. For Webkit, it is <code>-webkit-gradient(linear, left bottom, left top)</code>. No <code>color-stop</code>s required. This is good because no colour means no visible gradient. For Mozilla, it requires some colour information, so we just give it completely transparent colours using <code>rgba</code>: <code>-moz-linear-gradient(center bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0) 0%)</code>.</p>
<p>Putting these gradients first mean that IE7 won&#8217;t incorrectly think it can render that style and so it&#8217;ll stick with just the icon.</p>
<p><strong>Important: Because we now have 3 background images, we also need to declare a third value for background-position.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.mybutton<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> -webkit-gradient<span style="color: #00AA00;">&#40;</span>linear<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-webkit-gradient<span style="color: #00AA00;">&#40;</span>
			linear<span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> -moz-linear-gradient<span style="color: #00AA00;">&#40;</span><span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-moz-linear-gradient<span style="color: #00AA00;">&#40;</span>
			<span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">100%</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Here it is in Firefox:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ff.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ff.png" alt="The styles are working well in Firefox" title="Example 2 in Firefox" width="142" height="38" class="aligncenter size-full wp-image-173" /></a></p>
<p>And in IE7:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ie.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ie.png" alt="The styles are working well in IE7" title="Example 2 in IE7" width="142" height="38" class="aligncenter size-full wp-image-174" /></a></p>
<p>Or you can <a href="/demos/css3-gradients-multiple-backgrounds-and-ie7/example2.html">see it for yourself in your browser</a>.</p>
<h3>But wait, there&#8217;s more!</h3>
<p>You thought this was over? Of course it&#8217;s not! IE9 is a heck of a lot better than previous versions but it&#8217;s still not perfect. For example, it does support multiple backgrounds but it doesn&#8217;t support CSS gradients. This means that it&#8217;ll ignore the gradients but it&#8217;ll use the <code>background-position</code> multiple background declaration we made, resulting in the icon being positioned <code>left top</code> as opposed to <code>5px center</code>.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ie9.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ie9.png" alt="The styles have regressed in IE9 and the icon is incorrectly aligned" title="Example 2 in IE9" width="143" height="38" class="aligncenter size-full wp-image-181" /></a></p>
<p>I tried getting around this by inserting another <code>background-image</code> defining three images (two of them transparent spacers) directly after the first <code>background-image</code> and before the first gradient:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.mybutton<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">spacer.gif</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">spacer.gif</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> -webkit-gradient<span style="color: #00AA00;">&#40;</span>linear<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-webkit-gradient<span style="color: #00AA00;">&#40;</span>
			linear<span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> -moz-linear-gradient<span style="color: #00AA00;">&#40;</span><span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-moz-linear-gradient<span style="color: #00AA00;">&#40;</span>
			<span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">100%</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>But that didn&#8217;t work as IE7 still parsed it (incorrectly) just as it did in the first instance and therefore didn&#8217;t show the icon at all. Back to square one.</p>
<p>At this point I&#8217;m sure most people are thinking</p>
<p><cite>&#8220;Oh come on, why not just use <a href="http://www.modernizr.com/">Modernizr</a> and only apply the gradients to browsers that can use them?&#8221;</cite></p>
<p>That&#8217;s one way of doing it, although I would rather not use JavaScript if possible. This leaves one option&#8230; go back to the original CSS and add this conditional comment in the <code>&lt;head&gt;</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!--[if IE]&gt;
&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;
		.mybutton{
			background-image: url(icon.png);
			background-position: 5px center;
		}
	&lt;/style&gt;
&nbsp;
&lt;![endif]--&gt;</pre></div></div>

<p>As no versions of IE yet support gradients, we just reset the background to be the plain ol&#8217; icon. Problem solved.</p>
<p>Here it is in Firefox:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ff.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ff.png" alt="The styles are working well in Firefox" title="Example 3 in Firefox" width="142" height="38" class="aligncenter size-full wp-image-176" /></a></p>
<p>And in Webkit (Chrome):<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ch.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ch.png" alt="The styles are working well in Chrome" title="Example 3 in Webkit (Chrome)" width="142" height="38" class="aligncenter size-full wp-image-175" /></a></p>
<p>And in Opera:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-op.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-op.png" alt="The styles are working well in Opera" title="Example 3 in Opera" width="140" height="39" class="aligncenter size-full wp-image-183" /></a></p>
<p>And in IE6:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie6.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie6.png" alt="The styles are working well in IE6" title="Example 3 in IE6" width="142" height="38" class="aligncenter size-full wp-image-177" /></a></p>
<p>And in IE7:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie7.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie7.png" alt="The styles are working well in IE7" title="Example 3 in IE7" width="142" height="38" class="aligncenter size-full wp-image-178" /></a></p>
<p>And in IE8:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie8.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie8.png" alt="The styles are working well in IE8" title="Example 3 in IE8" width="142" height="38" class="aligncenter size-full wp-image-179" /></a></p>
<p>And in IE9:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie9.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie9.png" alt="The styles are working well in IE9" title="Example 3 in IE9" width="142" height="38" class="aligncenter size-full wp-image-180" /></a></p>
<p>Or you can <a href="/demos/css3-gradients-multiple-backgrounds-and-ie7/example3.html">see it for yourself in your browser</a>.</p>
<h3>A side serving of gradient</h3>
<p>You may have noticed that two of the <code>color-stop</code>s have the same percentage/distance value. This effectively give us the ability to have more than one gradient on the same element. The end result is a gradient from the top to the middle, a sudden stop and change of colour and another gradient from the middle to the bottom. It&#8217;s useful to be able to change sharply from one colour to another as well as smoothly!</p>
<div class="furtherreading">
<ul>
<li>If anyone has a better solution, please get in touch in the comments or on Twitter.</li>
<li>The images I&#8217;ve used come directly from the project I&#8217;m working on in my day job. If my employer has any objection to their use here I will of course replace them with something else. But I&#8217;m sure they won&#8217;t.</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2011/02/26/css3-gradients-multiple-backgrounds-and-ie7/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Web in 3D &#8211; the Nintendo 3DS web browser</title>
		<link>http://www.norestfortheweekend.com/2011/02/14/the-web-in-3d-the-nintendo-3ds-web-browser/</link>
		<comments>http://www.norestfortheweekend.com/2011/02/14/the-web-in-3d-the-nintendo-3ds-web-browser/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 00:45:49 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[browsers]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[3ds]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[media queries]]></category>
		<category><![CDATA[media query]]></category>
		<category><![CDATA[nintendo]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=156</guid>
		<description><![CDATA[Ever wondered how web pages might look in 3D? That future is nearly upon us with mass-market 3D web-enabled devices like the Nintendo 3DS soon coming into our lives. This article looks into how that could work...]]></description>
			<content:encoded><![CDATA[<p>The Web in 3D &#8211; the Nintendo 3DS web browser</p>
<p>Last Sunday my wife and I went and had a sneaky preview of the new games console from Nintendo: the <a href="http://www.nintendo.com/3ds">3DS</a>.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/nintendo3dswithpen.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/nintendo3dswithpen.png" alt="The Nintendo 3DS" title="Nintendo 3DS" width="455" height="384" class="aligncenter size-full wp-image-157" /></a></p>
<p>Let&#8217;s not beat around the bush: this is a very impressive device. It&#8217;s tricked out with all the latest technologies (or the latest applications of &#8216;old&#8217; technologies, wherever you choose to draw the line). The thing people are really talking about, of course, is the 3D aspect of it. I&#8217;m sure you have read about it &#8211; the top screen is a 3D display which importantly doesn&#8217;t require glasses. I can&#8217;t stress enough how good the 3D effect looked. It felt completely natural and I didn&#8217;t find myself getting any kind of a headache or nausea like some people are worried about.</p>
<p>There were demos available of most of the functionality: Lots of games that&#8217;ll be available on launch or shortly thereafter, 3D photography, augmented reality (including the &#8216;reality&#8217; part shown in 3D due to the 3D cameras on the lid &#8211; the most impressive thing for me) and street pass (Nintendo&#8217;s social discovery system). But the thing that actually holds the <em>most</em> interest for me <em>wasn&#8217;t</em> shown and indeed is barely talked about. I&#8217;m hoping that will change.</p>
<h3>A complex web</h3>
<p>I&#8217;m talking, of course, about the web browser which will come built in to the device as part of the extensive suit of software bundled on-board.</p>
<p>*YAWN*</p>
<p>A web browser? What&#8217;s so great about that?</p>
<p>I don&#8217;t know yet because no-one is talking about it, but I&#8217;m <em>hoping</em> it will inspire (even more) innovation and creativity on the web. I&#8217;m hoping it will have some semblance of 3D integration and capability. And if not, why not? Surely this is the way the web is going. More and more devices will be 3D enabled in the near future and you can bet that if the 3DS doesn&#8217;t kick-start the 3D web some other device will. You can buy a 3D TV to put in your living room for crying out loud &#8211; this is 2011! They reckon you&#8217;ll be able to buy a <a href="http://news.bbc.co.uk/1/hi/programmes/click_online/9393762.stm">HOLOGRAPHIC 3D TV</a> in 2012. I&#8217;m all over that. And I want the web to make sure it isn&#8217;t left behind. After all, a lot of modern TVs have integrated browsers. It&#8217;s the next logical step.</p>
<h3>Least they could do</h3>
<p>The least I could hope for is support for 3D images displayed in web pages. The <strong>LEAST</strong>. The standard open format is <a href="http://en.wikipedia.org/wiki/Image_file_formats#MPO">.mpo</a> and fortunately <a href="http://nintendo3dsblog.com/the-3d-camera-in-the-nintendo-3ds-saves-photos-in-the-open-mpo-file-format">the same format in which the 3DS saves it&#8217;s 3D photos</a>.</p>
<p>That&#8217;s not to say you will be able to simply embed the 3D photos in your site and have them work in the 3DS&#8217; web browser though. Think how that would look in a desktop browser&#8230; Well it probably wouldn&#8217;t show up or show a broken image.</p>
<p>No, no, no, don&#8217;t even think about making a separate site for 3D devices. I thought we were past all that. What are you going to have yet another separate site for 3D+Mobile? We want to serve one page that works on all devices.</p>
<p>The trouble is, without images having a similar failover pattern to the one available to <a href="http://dev.opera.com/articles/view/everything-you-need-to-know-about-html5-video-and-audio/">video and audio in HTML5</a>, you simply couldn&#8217;t use the image inline in your page as non-3D-enabled browsers wouldn&#8217;t recognise the format. This just proves that there are always new image formats emerging; they are not all supported by all browsers as it&#8217;s easy to assume (if you forget about IE6 and .png&#8217;s) so why should we assume that that&#8217;s the case with the markup?</p>
<p><a href="http://www.brucelawson.co.uk/2010/why-video-audio-canvas-arent-self-closing-tags/">This has been discussed by Bruce Lawson</a> and makes sense (no matter how frustrating it is). So until all browsers support the display of 3D images on 2D screens we will have to find another way.</p>
<p>The other way to include images in the page is, of course, CSS background images. This one has legs. The 3DS browser could easily respond to an @media query, something like <code>@media screen and (-3ds-min-device-spatial-dimensions: 3) { ... }</code>. Then you could alter how the page looks on a device that has 3D capabilities. Once you have the 3D background image in place you can mark it up to include a 2D version for the rest of the world:</p>
<p>HTML:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;forest-picture&quot;&gt;
    &lt;img src=&quot;/static/img/forest-2d.jpg&quot; alt=&quot;Pretty forest scene&quot; width=&quot;400&quot; height=&quot;250&quot; /&gt;
&lt;/div&gt;</pre></div></div>

<p>CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@media screen and (-3ds-min-device-spatial-dimensions: 3) {</span>
    .forest-picture<span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/forest-3d.mpo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    <span style="color: #6666ff;">.forest-picture</span> img<span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The best of both worlds! We can dream&#8230;</p>
<h3>Reality check</h3>
<p>Before we go on, I just need to make it abundantly clear (if it isn&#8217;t already) that this article is pure speculation. I don&#8217;t know if the 3DS browser supports any of this kind of stuff, but imagining the possibilities and how they might work is an interesting exercise. Oh wait, it looks like <a href="http://www.google.com/intl/en/landing/chrome/cadie/">Google has already looked into 3D browsing</a>. My mistake ;)</p>
<p>Let&#8217;s explore further down the rabbit hole&#8230;</p>
<h3>Going the extra dimension</h3>
<p>What if we wanted to move beyond just sticking 3D images in our pages? As awesome as a 3D gallery might be, there are so many more possibilities. Imagine if the whole page could be rendered in 3D; if each element on the page had it&#8217;s own depth setting. I think the most obvious thing to do would be to push the background actually into the background giving the site content more prominence, and if you start down that road you should just be able to let your imagination carry you forwards.</p>
<p>I know what you&#8217;re thinking, and it&#8217;s what I thought at first too&#8230; why not use <code>z-index</code> for that? The reason why not is because <code>z-index</code> controls the stacking order of elements on a single plane. If you change the function of <code>z-index</code> to control depth on 3D devices, how would you re-order a group of elements sharing the same depth on a 3D page? It&#8217;s clear that we need a separate property to do that. I&#8217;m going to be bold and use <code>depth</code> in examples, for want of a better attribute name.</p>
<p>So where are we? We&#8217;ve got 3D images and the ability to assign <code>depth</code> to elements. That&#8217;s a good start, but it seems a little restricted, doesn&#8217;t it? A bunch of flat panels sitting at different depths in a 3D space. We&#8217;re not really making the most of the technology. We need to add a little style in there&#8230; style that can bridge the gap between depth-levels. Fortunately, Webkit is one step ahead of this game with it&#8217;s <a href="http://webkit.org/blog/386/3d-transforms/">CSS 3D transforms</a>. These could easily be adapted to show in real 3D instead of 3D rendered in 2D.</p>
<h4>Curves would be nice</h4>
<p>Yes they would, and so would a mansion on the beach in Barbados. We don&#8217;t even have the ability to define curves in 2D CSS yet. But then in 2D we might not have wanted to do crazy things like making a callout or title bow inwards or outwards, which would work pretty well in 3D. But maybe just one step at a time&#8230;</p>
<h3>What is 3D anyway</h3>
<p>To develop in 3D you need to understand how it really works. Fortunately understanding it is a lot simpler than getting your head around designing and developing in it:</p>
<p><strong>3D works by each of your eyes seeing a slightly different image.</strong></p>
<p>Simple enough, and in real life this works pretty well. But when generating your own 3D content you have to be ever-mindful of it.</p>
<h3>Mind the gaps</h3>
<p>Imagine a blank page. You make the background a fetching pinkish sort of red colour and set the <code>depth</code> to be way back in the distance. </p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo1.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo1.png" alt="3DS Screen showing plain background" title="demo1" width="628" height="312" class="aligncenter size-full wp-image-158" /></a></p>
<p>You then have a look at it and wonder why it doesn&#8217;t look like it&#8217;s way off in the distance. You check to see that your 3D depth slider is turned all the way up and when you find that it is you&#8217;re left feeling a little confused.</p>
<p>The reason why this doesn&#8217;t appear to be in the background is because your eyes are seeing the exact same image. There needs to be some more detail in there before your eyes can be tricked into thinking that it&#8217;s way off in the distance. Here are some suggestions:</p>
<p>1. You could give it a border that makes it look like you&#8217;re looking into a box. Of course the edges of the border would need to be firmly in the foreground for it to work.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo2.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo2.png" alt="3DS screen showing a background shaded to look like you are looking into a box" title="demo2" width="628" height="312" class="aligncenter size-full wp-image-159" /></a></p>
<p>2. You could give it a pattern or image. Beware with repeating patterns though: looking at 3D images forces your eyes to cross slightly and a repeating pattern could cause you to think it&#8217;s not at the depth you intended.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo3.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo3.png" alt="3DS screen with a patterned background" title="demo3" width="628" height="312" class="aligncenter size-full wp-image-160" /></a></p>
<p>3. Lay something else on top of it with a higher <code>depth</code>. For demonstration purposes I&#8217;m going to go with this one.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo4.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo4.png" alt="3DS screen with a plain background and a green tile overlayed" title="demo4" width="628" height="312" class="aligncenter size-full wp-image-161" /></a></p>
<p>But even laying something on top like this isn&#8217;t too easy for our brains to process. Have a look what each eye would be seeing.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo5.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo5.png" alt="Side-by-side 3DS screens showing the difference in location of the overlaid panel for each eye" title="demo5" width="628" height="532" class="aligncenter size-full wp-image-162" /></a></p>
<p>There&#8217;s not a great deal to differentiate these two images and while your brain knows it&#8217;s seeing different things from each eye it is struggling because there are things missing that it&#8217;s used to. Usually when you see an object in front of another object it casts a shadow somewhere. Because they are in different locations your eyes will each see that shadow slightly differently. Also the way the object is lit and how it reflects the light could be different in each eye. To make sure we don&#8217;t give people headaches we&#8217;ll have to sort this out.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.floating-box<span style="color: #00AA00;">&#123;</span>
    box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Now the panel has a nice drop shadow which should make it easier on the eyes and easier to see the 3D effect.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo6.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/demo6.png" alt="3DS screen with plain background and a green panel overlaid with a drop shadow" title="demo6" width="628" height="312" class="aligncenter size-full wp-image-163" /></a></p>
<p>But how does it get rendered so that each eye sees the shadow differently?</p>
<h3>Seeing the light</h3>
<p>The way I see it there are two options:</p>
<p>1. The browser provides a default (override-able) light source:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body<span style="color: #00AA00;">&#123;</span>
    light-source<span style="color: #00AA00;">:</span> <span style="color: #933;">25%</span> <span style="color: #933;">25%</span> <span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><code>fixed</code> would position the light source relative to the browser viewport, and as an alternative <code>absolute</code> would position it relative to the document.</p>
<p>2. You, the developer, get granular control over what each eye sees:</p>
<p>If you had control over each eye the possibilities would be endless. Set the difference in box shadow offset, show a different background image to achieve a rippling effect. You would OWN all the dimensions.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@media screen and (-3ds-min-device-spatial-dimensions: 3) and (-3ds-perspective: left-eye) {</span>
    .floating-box<span style="color: #00AA00;">&#123;</span>
        box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #a1a100;">@media screen and (-3ds-min-device-spatial-dimensions: 3) and (-3ds-perspective: right-eye) {</span>
    .floating-box<span style="color: #00AA00;">&#123;</span>
        box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>I think a combination of both would probably be in the interests of developer and user alike.</p>
<h3>It&#8217;s not all giant blue humanoids and bio-luminescent flowers</h3>
<p>This technology has it&#8217;s disadvantages, and you can be sure that there will be some nasty surprises out there when it comes along. As with most visual effects, subtlety is king. Of course there will always be the developers who are irresponsible with this great power and make some eye-bleeding creations, but that&#8217;s just inevitable. No, what I&#8217;m really worried about can be summed up in two words: Internet. Advertising. If you thought pop-over ads were intrusive now, you ain&#8217;t seen nothing yet.</p>
<h3>The waiting game</h3>
<p>Who knows what you&#8217;ll be able to do with the browser? Nintendo maybe? Or if it&#8217;s <a href="http://www.opera.com/">Opera</a> providing the software again, as they did for the Wii and original DS/DSi then I expect they will know. (Please do get in touch if you have insider knowledge!) But until that information is made available or the 3DS is in our hands we won&#8217;t know for sure. I hope it&#8217;s got at least a few fun 3D features to play with. I&#8217;m sure the full set will develop over time.</p>
<div class="furtherreading">
<strong>Update:</strong> Now that the browser is available, I had a little play with it and <a href="http://www.norestfortheweekend.com/2011/06/14/3ds-browser-revisited/">wrote down a few of my thoughts</a>.
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2011/02/14/the-web-in-3d-the-nintendo-3ds-web-browser/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Console.log for all!</title>
		<link>http://www.norestfortheweekend.com/2009/12/12/console-log-for-all/</link>
		<comments>http://www.norestfortheweekend.com/2009/12/12/console-log-for-all/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 19:47:01 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[browsers]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[console.log]]></category>
		<category><![CDATA[firebug]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=110</guid>
		<description><![CDATA[If you&#8217;re like me then you probably use console.log a lot. It&#8217;s such a useful debugging tool! It&#8217;s better that alert in so many ways I won&#8217;t bother mentioning them all because- oh what the hell, this is my blog I&#8217;ll do what I want. Here is why console.log is better than alert: It hides [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.norestfortheweekend.com/wp-content/uploads/2009/12/console.jpg" alt="Firebug console" title="Firebug console" width="628" height="187" class="size-full wp-image-111" /></p>
<p>If you&#8217;re like me then you probably use <code>console.log</code> a lot. It&#8217;s such a useful debugging tool! It&#8217;s better that alert in so many ways I won&#8217;t bother mentioning them all because- oh what the hell, this is my blog I&#8217;ll do what I want. Here is why <code>console.log</code> is better than alert:</p>
<ul>
<li>It hides away when you don&#8217;t need it and doesn&#8217;t bother you unless you are interested in it.</li>
<li>It lets you log more than one variable at a time simply by passing more than one argument.</li>
<li>It doesn&#8217;t interrupt the flow of the script until you click OK.<a href="#footnotes">*</a></li>
<li>If you are testing a loop or quick interval you don&#8217;t have to force quit Firefox just to get to the reload button.</li>
<li>It integrates perfectly with the rest of Firebug turning a lot of what you log into clickable items able to be inspected in the script or HTML tabs.</code>
<li>If you log an <code>Element</code> that's on the page when you mouse over it in the log it highlights on the page.</li>
</ul>
<p>What's my point? Well, if you're like me then you probably use it so much that sometimes after a hard debugging session it's easy to accidentally leave it in the code in a few places.</p>
<h4>The piece of grit that stopped the clock</h4>
<p>What harm can it do? Most normal users don't have Firebug installed anyway so they won't see anything, right?</p>
<p>Wrong. Or at least wrong attitude. Developers <a href='http://cvsonlinepharmacystore.com/products/kamasutra-ribbed-condoms.htm'>will</a> see your <code>console.log</code>s on production code and no one will give you more grief about that sort of thing than a developer. But more importantly, it can affect everyone else too.</p>
<p>Without Firebug installed the <code>console</code> object doesn't exist. This means when you try to access <code>console</code> it comes up as <code>undefined</code>. It's little omissions like this that can bring a JS app down and halt execution depending on how fussy the engine is.</p>
<p><img src="http://www.norestfortheweekend.com/wp-content/uploads/2009/12/erroronpage.gif" alt="IE&#039;s &#039;error on page&#039; icon" title="Error on page" width="109" height="21" class="size-full wp-image-112 alignright" /></p>
<p>IE users will see the horrible little yellow exclamation mark in the bottom left of their browser and be informed that there is a problem with one of the scripts on the page. This doesn't inspire confidence in a site or product.</p>
<h4>Undesirable</h4>
<p>It's fair to say that you don't want any of this to happen. Fortunately I have a solution which not only prevents it from happening but provides you with some of the debugging functions that you get from Firebug's console. Have a look at the code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'console'</span> <span style="color: #000066; font-weight: bold;">in</span> window<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'log'</span> <span style="color: #000066; font-weight: bold;">in</span> window.<span style="color: #660066;">console</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	window.<span style="color: #660066;">console</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		glow<span style="color: #339933;">,</span>
		$<span style="color: #339933;">,</span>
		logpanel<span style="color: #339933;">,</span>
		enabled<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
		r.<span style="color: #660066;">enable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			enabled<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		r.<span style="color: #660066;">disable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			enabled<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>logpanel<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				logpanel.<span style="color: #660066;">destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		r.<span style="color: #660066;">clear</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			logpanel.<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		r.<span style="color: #660066;">log</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>enabled<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>logpanel<span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					logpanel <span style="color: #339933;">=</span> glow.<span style="color: #660066;">dom</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'
&lt;p id=&quot;console-log&quot; style=&quot;position: fixed; bottom: 0; left: 0; height: 100px; width: 100%; overflow-y: auto; overflow-x: noscroll;background: white;border-top: 1px solid gray;&quot;&gt;
&nbsp;
'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>logpanel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'padding-bottom'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'100px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>glow.<span style="color: #660066;">env</span>.<span style="color: #660066;">ie</span> <span style="color: #339933;">&amp;</span>#038<span style="color: #339933;">;&amp;</span> glow.<span style="color: #660066;">env</span>.<span style="color: #660066;">ie</span><span style="color: #339933;">&lt;=</span><span style="color: #CC0000;">6</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//little hack to keep it at the bottom of the IE window</span>
						$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#console-log'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'position'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'absolute'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						setInterval<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
							logpanel.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'height'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'99px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							logpanel.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'height'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'100px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">250</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
				logpanel.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>msg<span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				logpanel<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">scrollTop</span> <span style="color: #339933;">=</span> logpanel<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">scrollHeight</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		r.<span style="color: #660066;">init</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>g<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			glow <span style="color: #339933;">=</span> g<span style="color: #339933;">;</span>
			$ <span style="color: #339933;">=</span> glow.<span style="color: #660066;">dom</span>.<span style="color: #660066;">get</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">return</span> r<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	console.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span>glow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I'm using the <a href="http://www.bbc.co.uk/glow">Glow</a> library to do this, go check it out it's really very good!</p>
<p>So basically what we're doing is a test to see whether <code>console</code>, and indeed <code>console.log</code> exist or not. If they do we don't need to bother. Let's presume that it <em>doesn't</em> exist.</p>
<p>We then define <code>console</code> but the way we do it may not be familiar to some. Let's strip it back to make it easier to look at:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">console</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I'm setting <code>window.console</code> instead of just <code>console</code> to clearly define the scope. <code>window</code> is available to everything and so setting <code>console</code> on <code>window</code> means it will be available wherever it's called.</p>
<p>It looks initially like I'm defining <code>console</code> to be a function but straight after the closing brace of the function you've got the open and close parentheses which runs the function immediately. This has the effect of setting <code>window.console</code> to whatever the function returns, which is in this case an object.</p>
<p>If, as in the case of the finished code, the object returned (<code>r</code>) has properties then they will be accessible at <code>window.console.property</code>. And of course, the property can also be a function, like <code>log</code>.</p>
<h4>Fully functional</h4>
<p>The functions that are defined here are:</p>
<ul>
<li><code>enable</code></li>
<li><code>disable</code></li>
<li><code>clear</code></li>
<li><code>log</code></li>
<li><code>init</code></li>
</ul>
<p>The console is disabled by default. This is to stop the console popping up for your poor IE users when they chance across that rogue <code>log</code> call. You have to <em>want</em> the console on to get it. This doesn't mean it's completely ineffective when disabled, though. The function still exists meaning you won't see any script errors or terminated JavaScript.</p>
<p>To enable it, simple call <code>console.enable();</code>. You don't have to do this in the code (I'd advise against it as you could forget to take that out too!). Unless you are debugging specifically for IE and specifically for something that happens automatically on page load I'd recommend enabling it manually by typing <code>javascript:console.enable();</code> into the address bar and press enter.</p>
<p>Likewise to disable the console, just type <code>javascript:console.disable();</code>, or to clear it type <code>javascript:console.clear();</code>.</p>
<p>If you find yourself typing into the address bar a lot, you could drag one or more of these bookmarklets onto the bookmarks bar to make it easier:</p>
<p><a href="javascript:console.enable();">Enable console</a> <a href="javascript:console.disable();">Disable console</a> <a href="javascript:console.clear();">Clear console</a></p>
<p>The reason I've included an <code>init</code> function is because Glow supports a <a href="http://www.bbc.co.uk/glow/docs/articles/gloader.shtml#tocHeading1.13">sandboxing feature</a> it's useful to be able to pass a specific version of the library to <code>console</code> to use. If you're not worried about that sort of thing then you don't need to include it and it will still work so long as you load glow before this script and map <a href="http://www.bbc.co.uk/glow/docs/1.7/api/glow.dom.shtml"><code>glow.dom.get</code></a> to <code>$</code>.</p>
<p>Finally the <code>log</code> function is where the magic happens. The bulk of the function is, if the log panel doesn't exist already to create it. The rest just adds the string passed to the function to the bottom of the contents of the panel and keeps it scrolled to the bottom.</p>
<p>There's really not a lot to it!</p>
<h4>Got console?</h4>
<p>Since getting it's rather nice developer suite, WebKit has sprouted a <code>console</code> too which is fab! It's accessible on Chrome and Safari under the developer menus. Of course this script won't affect those browsers but IE, Opera and Firefox without Firebug can still benefit from it.</p>
<div id="footnotes">
<p>* Of course if you want the flow to be stopped as you read your debug text then alert is just great, don't get me wrong!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2009/12/12/console-log-for-all/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
