<?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>User Agent Man &#187; JavaScript</title>
	<atom:link href="http://www.useragentman.com/blog/category/technologies/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.useragentman.com/blog</link>
	<description>A Blog about Client Side Web Technology</description>
	<lastBuildDate>Thu, 26 Jan 2012 03:14:32 +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>Cross Browser HTML5 Progress Bars In Depth</title>
		<link>http://www.useragentman.com/blog/2012/01/03/cross-browser-html5-progress-bars-in-depth/</link>
		<comments>http://www.useragentman.com/blog/2012/01/03/cross-browser-html5-progress-bars-in-depth/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 07:08:54 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[gradients]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Polyfills]]></category>
		<category><![CDATA[progress]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=4016</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2012/01/intro.png" />  As a web application developer,<strong> progress bars are great when you want to show the user that some action is happening,</strong> especially when it can take a long time.  Creating them is easy with the HTML5 <code>&#60;progress&#62;</code> tag.  This article will discuss <strong>how this tag is rendered by default</strong> in all operating systems and browsers and how to <strong>style the <code>progress</code> tag with CSS</strong>, even in browsers that don't officially support the it.  It will also show some <strong>interesting examples using advanced CSS3 techniques.</strong>]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Note:</h3>
<p>The stylesheet for the polyfill was not included correctly when this post was first published, and as a result, the examples below were not showing up correctly on IE7-8 and Safari 5.1+.  The problem has been corrected.</p>
</div>
<p><div id="attachment_4224" class="wp-caption alignleft" style="width: 260px"><img src="http://www.useragentman.com/blog/wp-content/uploads/2012/01/intro.png" alt="" title="intro" width="250" height="180" class="size-full wp-image-4224" /><p class="wp-caption-text">Screenshots of HTML5 progress bars with different styles applied.  Details given below.</p></div> As a web application developer,<strong> progress bars are great when you want to show the user that some action is happening,</strong> especially when it can take a long time.  They can be <strong>animated</strong> (like the one in Gmail does when it shows the user how long it is going to take for it to load and initialize), <strong>or static</strong> (like some shopping cart applications have to show the user how many pages it will take to check out an order).  I used to <a href="http://css-tricks.com/css3-progress-bars/">create progress bars using <code>&lt;div&gt;</code> tags, CSS and a litle bit of math</a>, but now I like to do it the HTML5 way using the <code>&lt;progress&gt;</code> tag.  This article will discuss <strong>how this tag is rendered by default</strong> in all operating systems and browsers and how to <strong>style the <code>progress</code> tag with CSS</strong>, even in browsers that don&#8217;t officially support the it.  It will also discuss some interesting <strong>limitations of all the browser implementations</strong> amd show some <strong>interesting examples using advanced CSS3 techniques.</strong></p>
<h2>The HTML: Simple</h2>
<p>The HTML for a Progress bar is dead simple:</p>
<blockquote class="code">
<pre>
&lt;progress max="100" value="60"&gt;
  &lt;strong&gt;Progress: 60% done.&lt;/strong&gt;
&lt;/progress&gt;
</pre>
</blockquote>
<div class="example">
<progress max="100" value="60"><strong>Progress: 60% done.</strong></progress>
</div>
<p><strong>Note that the HTML inside the <code>&lt;progress&gt;</code> tag is the fallback for browsers that do not support it.</strong>  That, unfortunately, includes all versions of IE and Safari so far, as well older versions of Firefox (5.x and lower) and Opera (10.x and lower).  Although the fallback is acceptable, we can go a step further and use <strong><a href="http://lea.verou.me/">Lea Verou&#8217;s</a> excellent <a href="http://lea.verou.me/2011/07/a-polyfill-for-html5-progress-element-the-obsessive-perfectionist-way/"><code>&lt;progress&gt;</code> tag polyfill</a></strong>, which adds pretty much full-support for all of these browsers <strong>except for Safari 5 and lower</strong> (so you should <em><strong>always put in the fallback HTML just to be on the safe side</strong></em>).  Let&#8217;s take a look at these screenshots to see what how <code>&lt;progress&gt;</code> looks across the browserverse:</p>
<table class="dataTable">
<thead>
<tr>
<th></th>
<th>Windows 7</th>
<th>Windows XP</th>
<th>Mac OS X</th>
<th>Ubuntu Linux</th>
</thead>
<tbody>
<tr>
<th>Firefox</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultFirefoxWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultFirefoxWinXP.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultFirefoxMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultFirefoxLinux.png" alt=""  /></td>
</tr>
<tr>
<th>Chrome</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultChromeWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultChromeWinXP.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultChromeMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultChromeLinux.png" alt=""  /></td>
</tr>
<tr>
<th>IE7+ (polyfill)</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultSafariWin_poly.png" alt=""  /></td>
<td colspan="3" class="na">N/A</td>
</tr>
<tr>
<th>Safari 5.1+ (polyfill)</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultSafariWin_poly.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultSafariWin_poly.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultSafariWin_poly.png" alt=""  /></td>
<td class="na">N/A</td>
</tr>
<tr>
<th>Opera</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultOperaWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultOperaWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultOperaMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultOperaLinux.png" alt=""  /></td>
</tr>
</tbody>
</table>
<p>Note that:</p>
<ul>
<li>Firefox and Chrome will render the progress bar the same way that the host operating system would &#8230; except for Chrome for Linux, which uses it&#8217;s own custom style (thanks to <a href="http://blog.oldworld.fr/">Mounir Lamouri</a> for correcting me on this exception).</li>
<li>The color of the Opera progress value is always green (more on this later).</li>
<li>The browsers that use the polyfill all render the progress bar with a nice bluish gradient effect</li>
</ul>
<p>A progress bar <strong>can also have an <em>&#8220;indeterminate&#8221;</em> state</strong>, which happens when there is <strong>no value attribute</strong>. </p>
<blockquote class="code">
<pre>
&lt;progress max="100"&gt;
  &lt;strong&gt;Progress: 60% done.&lt;/strong&gt;
&lt;/progress&gt;
</pre>
</blockquote>
<div class="example">
<progress max="100" ><strong>Progress: 60% done.</strong></progress>
</div>
<p>This effect is used to show that the state of progress is currently unknown (e.g. how long it will take for a web server to initiate the download of a file if is generating it on the fly).  How this looks varies from browser to browser as well.</p>
<table class="dataTable">
<thead>
<tr>
<th></th>
<th>Windows 7</th>
<th>Windows XP</th>
<th>Mac OS X</th>
<th>Ubuntu Linux</th>
</thead>
<tbody>
<tr>
<th>Firefox</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterFirefoxWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterFirefoxWinXP.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterFirefoxMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterFirefoxLinux.png" alt=""  /></td>
</tr>
<tr>
<th>Chrome</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterChromeWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterChromeWinXP.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterChromeMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterChromeLinux.png" alt=""  /></td>
</tr>
<tr>
<th>IE7+ (polyfill)</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterSafariWin_poly.png" alt=""  /></td>
<td colspan="3" class="na">N/A</td>
</tr>
<tr>
<th>Safari 5.1+ (polyfill)</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterSafariWin_poly.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterSafariWin_poly.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterSafariWin_poly.png" alt=""  /></td>
<td class="na">N/A</td>
</tr>
<tr>
<th>Opera</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterOperaWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterOperaWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterOperaMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterOperaLinux.png" alt=""  /></td>
</tr>
</tbody>
</table>
<p>Note that:</p>
<ul>
<li>Opera is the only browser that doesn&#8217;t distinguish between a progress bar with an indeterminate state and one with a value of zero.</li>
<li>All of the other browsers (including the ones that use the polyfill) animate the indeterminate states.  (I have opted to not show all the animations here to avoid readers getting seizures &#8230; I hear that would be a bad thing).</li>
</ul>
<h2>But I Want To Style Them My Way!</h2>
<p>If you are particular in how you want your <code>&lt;progress&gt;</code> tags to look, the good news is that <strong>you can pretty much style them any way you want</strong>.  You must, however, <strong>be aware about the browser quirks</strong> that can trip you up &#8230; and it isn&#8217;t all IE&#8217;s fault this time!  Follow this three-to-four-step process, and you&#8217;ll be styling progress bars in your sleep in no time:</p>
<h3>Step 1: Turn off default styling</h3>
<p>The first step is to turn off the default styling in all browsers:</p>
<blockquote class="code">
<pre>
progress,          /* All HTML5 progress enabled browsers */
progress[role]     /* polyfill */
{

	/* Turns off styling - not usually needed, but good to know. */
	appearance: none;
	-moz-appearance: none;
	-webkit-appearance: none;

	/* gets rid of default border in Firefox and Opera. */
	border: none;

	/* Needs to be in here for Safari polyfill so background images work as expected. */
	background-size: auto;

	/* Dimensions */
	width: 400px;
	height: 60px;

}

/* Polyfill */
progress[role]:after {
	background-image: none; /* removes default background from polyfill */
}

/* Ensure fallback text doesn't appear in polyfill */
progress[role] strong {
	display: none;
}
</pre>
</blockquote>
<div class="example">
<progress class="example1 a" min="0" max="100" value="50">
<strong>Progress: 60% done.</strong>
</progress>
</div>
<p>Simple stuff: remove the border and add a specific width and height.  I added the second rule to remove the background image inserted by the polyfill&#8217;s stylesheet, but if you wanted, you can  modify the polyfill&#8217;s stylesheet directly (or leave it out completely if you elect not to use the polyfill).   The final rule is to ensure the polyfill doesn&#8217;t display the fallback content &mdash; it assumes that is always wrapped in a <code>&lt;strong&gt;</code> tag, so this may be something you should keep in mind when setting the default content (if you don&#8217;t like using a <code>&lt;strong&gt;</code> tag as a wrapper for your fallback content, use whatever tag you like).</p>
<p>Note that the <code>appearance</code> property (and its vendor-specific brethren) are there to turn off the default operating-system styling on the progress bar &mdash; it doesn&#8217;t seem like it is really necessary, but I put it here for reference in case it becomes mandatory in the future.</p>
<h3>Step 2: The Progress Bar Background.</h3>
<p>Now let&#8217;s change the background color of the progress bar to a light red.  </p>
<blockquote class="code">
<pre>
progress,                          /* Firefox  */
progress[role][aria-valuenow] {    /* Polyfill */
   background: #ffeeee !important; /* !important is needed by the polyfill */
}

/* Chrome */
progress::-webkit-progress-bar {
    background: #ffeeee;
}
</pre>
</blockquote>
<div class="example">
<progress class="example1 a b" min="0" max="100" value="50"></progress>
</div>
<p>Notice that with Firefox and the polyfilled browsers, all you need to do is change the background of just the <code>progress</code> tag itself, while in Chrome (and I assume future versions of Safari) it is necessary to use the <code>-webkit-progress-bar</code> pseudo-element. Note that even though the code inside these rules are the same,<strong> you cannot put all of these selectors in one rule</strong>: doing so breaks Firefox and Opera (so much for degrading gracefully).</p>
<h3>Step 3: The Progress Bar Value</h3>
<p>Now let&#8217;s change the color of progress bar value to black.  The CSS is a <em>wee bit longer than it really should be</em>:</p>
<blockquote class="code">
<pre>
/* Firefox */
progress::-moz-progress-bar {
    background: black;
}

/* Chrome */
progress::-webkit-progress-value {
    background: black;
}

/* Polyfill */
progress[aria-valuenow]:before  {
    background: black;
}
</pre>
</blockquote>
<div class="example">
<progress class="example1 a b c" min="0" max="100" value="50"></progress>
</div>
<p>Yes, three rules to rule them all!  Again, putting them all together in one selector breaks every browser on the planet (including the polyfilled ones), so we have to write three separate rules with the same CSS properties in them! &lt;sarcasm&gt;Yaaayyy!!!!&lt;/sarcasm&gt;</p>
<p><strong>Note that there is no way that I know of to style the progress bar value in Opera 11.52 and lower.</strong>  It just stays the same green no matter what you do. :-( If anyone is reading this and knows otherwise, I would be indebted to you to let me know how.</p>
<h3>Step 4: The Indeterminate Value</h3>
<p>This part is optional, and I would only put these rules in if I know I&#8217;ll need a style for the indeterminate value (not all applications need it):</p>
<blockquote class="code">
<pre>
/* Firefox */
progress:not([value])::-moz-progress-bar {
  background-image:  url(../images/indeter.gif);
}

/* Chrome */
progress:not([value])::-webkit-progress-bar {
  background-image:  url(../images/indeter.gif);
}

/* Polyfill - IE */
progress[role]{
	background-image: url(../images/indeter.gif) !important;
}

/* Polyfill - Safari */
progress:not([value])  {
	background-image: url(../images/indeter.gif) !important;
	background-size: auto;  /* Needs to be in here for Safari */
}
</pre>
</blockquote>
<div class="example">
<progress class="example1 a b c d" min="0" max="100"></progress>
</div>
<p>It even works in Opera! Note that the <code>background-size</code> must be set to <code>auto</code> in order to override the default style in the polyfill.  :-)</p>
<p><a href="http://www.useragentman.com/examples/progress/" class="exampleLink">See the above CSS in action in a &#8220;clean room&#8221; page</a></p>
<h2>That&#8217;s Too Basic! I Want Fancy-Pants&trade; Progress Bars</h2>
<p>So, now that you know the basics, let&#8217;s take a look at some more complicated and interesting progress bars:</p>
<h3>Two Image Effect</h3>
<p>This progress bar uses two versions of the same image (one grey-scale, one color) to differentiate between the progress bar background and value: </p>
<div class="example">
<progress class="example2" min="0" max="100" value="60"></progress>
</div>
<p><a href="http://www.useragentman.com/examples/progress/uam.html" class="exampleLink">See the above example in action in a &#8220;clean room&#8221; page</a></p>
<h3>Gradients</h3>
<p>Note that  not only can you use <code>background-color</code>s and <code>-image</code>s, but also use the variety of gradients that are available for developers today in supported browsers (this does <strong>not</strong> include IE9 and lower).  To prove this, I took Chris Croyer beautiful <code>&lt;div&gt;</code> style progress bars from his <a href="http://css-tricks.com/css3-progress-bars/">blog post on CSS3 based progress bars</a> and HTML5-ified&trade; them here:</p>
<div class="example">
<progress class="example3" min="0" max="100" value="60"></progress>
</div>
<div class="example">
<progress class="example4" min="0" max="100" value="60"></progress>
</div>
<p>Unfortunately, due to CSS gradients being implemented by the browser vendors using vendor-specific prefixes, the CSS tends to be a wee long.  Here is the CSS of the first example (scroll the code to see the whole lot of it):</p>
<blockquote class="code shortened">
<pre>
/*
 * Gradient Shadow
 */

/* All HTML5 progress enabled browsers */
progress.example3 {

	/* Turns off styling - not usually needed, but good to know. */
	appearance: none;
	-moz-appearance: none;
	-webkit-appearance: none;
	/* gets rid of default border in Firefox and Opera. */
	border: solid #cccccc 5px;
	border-radius: 10px;
	/* Dimensions */
	width: 238px;
	height: 45px;
}

/* Polyfill */
progress.example3[role]:after {
	background-image: none; /* removes default background from polyfill */
}

/*
 * Background of the progress bar background
 */

/* Firefox and Polyfill */
progress.example3 {
	background: #cccccc !important; /* !important only needed in polyfill */
}

/* Chrome */
progress.example3::-webkit-progress-bar {
	background: #cccccc;
}

/*
 * Background of the progress bar value
 */

/* Firefox */
progress.example3::-moz-progress-bar {
	border-radius: 5px;
	background-image: -moz-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);
}

/* Chrome */
progress.example3::-webkit-progress-value {
	border-radius: 5px;
	background-image: -webkit-gradient(
		linear,
		left bottom,
		left top,
		color-stop(0, rgb(43,194,83)),
		color-stop(1, rgb(84,240,84))
	);
	background-image: -webkit-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);
}

/* Polyfill */
progress.example3[aria-valuenow]:before {
	border-radius: 5px;
	background-image: -moz-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);
	background-image: -ms-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);
	background-image: -o-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);

}
</pre>
</blockquote>
<p>Note that I did not use the <a href="http://msdn.microsoft.com/en-us/library/ms532997%28v=vs.85%29.aspx"><code>Gradient</code> filter</a> to polyfill CSS3 gradients in IE6-9.  This is because Visual Filters don&#8217;t work in CSS3 pseudo-elements like <code>:before</code> or <code>:after</code>.  Oh well.</p>
<p><a href="http://www.useragentman.com/examples/progress/striping.html" class="exampleLink">See the above CSS in action in a “clean room” page</a></p>
<h3>Monkeys!</h3>
<p>What blog post about HTML5 progress tags would be complete without monkeys?  These simians appear in all browser except for IE8 and lower (as explained below).  </p>

<div class="example">
<progress class="monkey" min="0" max="100" value="60"></progress><div class="after"></div>
</div>
<p>Apologies to the great <a href="http://banksy.co.uk/">Banksy</a> &mdash; it&#8217;s not <a href="http://www.guyhepner.com/index.php?url=images/get/509x397/3087/banksy-paintings-laugh-now-but-one-day-we-ll-be-in-charge.jpg">his monkey</a> but one grabbed from <a href="http://www.animatedgif.net/clockscounters/clockscounters3.shtml">this Animated GIF site</a> and converted into a <a href="http://www.alistapart.com/articles/sprites">CSS sprite</a> using <a href="http://blog.somepixels.net/">André Gil&#8217;s</a> super-cool <a href="http://labs.andregil.net/Gif2TileSet/Gif2TileSet.html">Gif2TileSet tool</a>.  I took this sprite and animated the monkey using blitting whenever the progress bar changes values (thanks to my friend and colleague <a href="http://noel.tibbles.ca/">Noel Tibbles</a> for turning me on to this technique).</p>
<p>Note the HTML has an extra <code>&lt;div&gt;</code> tag so the monkey has a place to live:</p>
<blockquote class="code">
<pre>
&lt;progress class="monkey" min="0" max="100" value="60"&gt;&lt;/progress&gt;
&lt;div class="after"&gt;&lt;/div&gt;
</pre>
</blockquote>
<p><strong>I wish that I could have used <code>:after</code> (or <code>::after</code>) rules</strong> instead, but these pseudo-elements <strong>don&#8217;t work with the <code>progress</code> tags in <em>any</em> browser that doesn&#8217;t use the polyfill</strong>.  And no, <code>:before</code> doesn&#8217;t work either.  I have no idea why it doesn&#8217;t work, but it&#8217;s a shame &mdash; using them would be perfect to get rid of the extra markup.</p>
<p>The CSS that makes the monkey animate when the progress bar changes values is here:</p>
<blockquote class="code">
<pre>
progress.monkey[value="0"] +  .after{
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif');
} 

progress.monkey[value^="1"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -77px ;
}

progress.monkey[value^="2"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -154px ;
}

progress.monkey[value^="3"] +  .after,
progress.monkey[value="100"] +  .after  {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -231px !important ;
}

progress.monkey[value^="4"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -308px ;
}

progress.monkey[value^="5"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -385px ;
}

progress.monkey[value^="6"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -462px ;
}

progress.monkey[value^="7"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -539px ;
}

progress.monkey[value^="8"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -616px ;
}

progress.monkey[value^="9"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -693px ;
}
</pre>
</blockquote>
<p>Each of these rules are applied when the first digit changes in the progress bar, which is done using the ^= attribute rules. This works because the progress bar goes from 0 &#8211; 100 and the progress bar increments by 10.  They monkeys don&#8217;t appear in IE8 and under because of it&#8217;s lack of support of the ^= attribute selector (but it works well in IE9).</p>
<p>Note that <strong>this would be much easier if CSS allowed us to combine the CSS3 <code>calc()</code> and <code>attr()</code> attributes together</strong> like <a href="http://lea.verou.me/2010/09/on-attr-and-calc/">Lea Verou dreams about in one of her blog posts</a>:</p>
<blockquote class="code">
<pre>
/*
 * Don't try this - it doesn't work in any browser, but it would be nice if it did.
 */

progress.monkey::after {
   background-image: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif');
   background-position-x: 0;
   background-position-y: calc(-77 * attr(value), 'px');
}
</pre>
</blockquote>
<p>Hopefully this will come to pass in the future.</p>
<p><a href="http://www.useragentman.com/examples/progress/blit.html" class="exampleLink">See the above CSS in action in a “clean room” page</a></p>
<h3>Speedometer</h3>
<p>My last example is radically different than the others.  How about we apply the speedometer metephor to the progress bar with some fancy-pants CSS3?   This example in all browsers except IE8 and lower (due to lack of support for native CSS3 <code>transform</code>) </p>

<div class="example speedometer">
<div id="progressContainer">
  <progress id="rot" class="example_r" min="0" max="100" value="60"></progress>
  <div data-arrow-for="rot" class="arrow"><img src="/blog/wp-content/uploads/2012/01/hand.png" /></div>
</div>
</div>
<p>The CSS is similar to the monkey example in that I add an extra <code>&lt;div&gt;</code> after the progress tag, except that it has an image of a pointer inside of it.</p>
<blockquote class="code">
<pre>
&lt;div id="progressContainer"&gt;
  &lt;progress id="rot" class="example_r" min="0" max="100" value="60"&gt;&lt;/progress&gt;
  &lt;div data-arrow-for="rot" class="arrow"&gt;&lt;img src="/blog/wp-content/uploads/2012/01/hand.png" /&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
</blockquote>
<p>I wrapped both these tags inside a relatively positioned container <code>&lt;div&gt;</code>.  This is so I could absolutely position both the progress bar and the arrow in order for them to line up properly.  I make the progress bar into a semi-circle by using <code>border-radius</code> and part of a <a href="http://www.flickr.com/photos/listener42/4991330345/">photo from Flickr user &#8216;listener42&#8242;</a> &#8230;</p>
<blockquote class="code">
<pre>
progress.example_r {

	/* gets rid of default border in Firefox and Opera. */
	border: solid 1px black;
	display: inline-block;

	/* Produces the semi-circle */
	<span class="hilite">border-radius: 238px 238px 0 0;</span>

	/* Dimensions */
	width: 238px;
	height: 126px;
	padding: 0;
}
</pre>
</blockquote>
<p>&#8230; and make the arrow rotate as the progress bar increments by using CSS transforms: </p>
<blockquote class="code shortened">
<pre>
progress.example_r[value="0"] + .arrow {
	-moz-transform: rotate(270deg);
	-webkit-transform: rotate(270deg);
	-o-transform: rotate(270deg);
	-ms-transform: rotate(270deg);
}

progress.example_r[value^="1"]:not([value="1"]):not([value="100"]) + .arrow {
	-moz-transform: rotate(288deg);
	-webkit-transform: rotate(288deg);
	-o-transform: rotate(288deg);
	-ms-transform: rotate(288deg);
}

progress.example_r[value^="2"]:not([value="2"]) + .arrow {
	-moz-transform: rotate(306deg);
	-webkit-transform: rotate(306deg);
	-o-transform: rotate(306deg);
	-ms-transform: rotate(306deg);
}

progress.example_r[value^="3"]:not([value="3"]) + .arrow {
	-moz-transform: rotate(324deg);
	-webkit-transform: rotate(324deg);
	-o-transform: rotate(324deg);
	-ms-transform: rotate(324deg);
}

progress.example_r[value^="4"]:not([value="4"]) + .arrow {
	-moz-transform: rotate(342deg);
	-webkit-transform: rotate(342deg);
	-o-transform: rotate(342deg);
	-ms-transform: rotate(342deg);
}

progress.example_r[value^="5"]:not([value="5"]) + .arrow {
	-moz-transform: rotate(360deg);
	-webkit-transform: rotate(360deg);
	-o-transform: rotate(360deg);
	-ms-transform: rotate(360deg);
}

progress.example_r[value^="6"]:not([value="6"]) + .arrow {
	-moz-transform: rotate(378deg);
	-webkit-transform: rotate(378deg);
	-o-transform: rotate(378deg);
	-ms-transform: rotate(378deg);
}

progress.example_r[value^="7"]:not([value="7"]) + .arrow {
	-moz-transform: rotate(396deg);
	-webkit-transform: rotate(396deg);
	-o-transform: rotate(396deg);
	-ms-transform: rotate(396deg);
}

progress.example_r[value^="8"]:not([value="8"]) + .arrow {
	-moz-transform: rotate(414deg);
	-webkit-transform: rotate(414deg);
	-o-transform: rotate(414deg);
	-ms-transform: rotate(414deg);
}

progress.example_r[value^="9"]:not([value="9"]) + .arrow {
	-moz-transform: rotate(432deg);
	-webkit-transform: rotate(432deg);
	-o-transform: rotate(432deg);
	-ms-transform: rotate(432deg);
}

progress.example_r[value="100"] + .arrow {
	-moz-transform: rotate(450deg);
	-webkit-transform: rotate(450deg);
	-o-transform: rotate(450deg);
	-ms-transform: rotate(450deg);
}
</pre>
</blockquote>
<p>Again, the CSS would be much smaller in size if I could use <code>calc()</code> and <code>attr()</code> together, but again, oh well.   Also note that this example doesn&#8217;t work in Opera very well because we cannot turn of the green in the progress bar value.  :-(</p>
<p><a href="http://www.useragentman.com/examples/progress/rotate.html" class="exampleLink">See the above CSS in action in a “clean room” page</a></p>
<h2>Summary of Gotchas</h2>
<p>As mentioned before, there are a few annoyances I have found with they way the browsers have implemented HTML5 progress bars:</p>
<ol>
<li>You cannot use <code>:before</code>/<code>::before</code> or <code>:after</code>/<code>::after</code> pseudo-elements on the <code>progress</code> element.  Why this is not allowed is unclear to me, and I hope this is allowed in the future.</li>
<li>Safari 5.0 and lower cannot use the polyfill, so you should always use the fallback HTML inside the <code>&lt;progress&gt;</code> tag.</li>
<li>It seems like it is impossible to change Opera&#8217;s progress bar style to anything besides green.</li>
<li>There is a <strong>small bug in the polyfill</strong> when applying borders to the progress bar.  I have <a href="https://github.com/zoltan-dulac/HTML5-Progress-polyfill">a fix</a> that has been <a href="https://github.com/LeaVerou/HTML5-Progress-polyfill/pull/6">submitted as a pull request</a> and I assume being reviewed, but in the meantime, you can <a href="https://github.com/zoltan-dulac/HTML5-Progress-polyfill">get my forked version of the polyfill (with the bug fix) on GitHub</a>.</li>
</ol>
<h2>Help Me Keep This Page Up-To-Date!</h2>
<p>If you find out more information about the HTML5 <code>progress</code> tag, I&#8217;d love to hear from you!  Please let me know in the comments below.  I will add relevant information to the above article and credit you fully. :-)</p>
<p><script src="/shared/js/lea.verou.me/progressPolyfill/progress-polyfill.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2012/01/03/cross-browser-html5-progress-bars-in-depth/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Clipping JPEG Images Into Non-Rectangular Polygons Using polyClip.js</title>
		<link>http://www.useragentman.com/blog/2011/10/29/clipping-jpeg-images-into-non-rectangular-polygons-using-polyclip-js/</link>
		<comments>http://www.useragentman.com/blog/2011/10/29/clipping-jpeg-images-into-non-rectangular-polygons-using-polyclip-js/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 15:20:29 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[VML]]></category>
		<category><![CDATA[arbitrary clipping]]></category>
		<category><![CDATA[clipping]]></category>
		<category><![CDATA[non-rectangular clipping. polygon clipping]]></category>
		<category><![CDATA[polyClip]]></category>
		<category><![CDATA[polygon]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3526</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissorsTeaser.jpg" /> Up until now, if a developer needed to clip an image in a non-rectangular shape, it was necessary to save the image as a PNG with an alpha channel. If the image is a photograph, the file-size balloons up to unacceptable levels. My new library, polyClip.js, allows developers to clip these images using photograph friendly JPEGs instead. This article guides you step by step on how to use it yourself.]]></description>
			<content:encoded><![CDATA[<div class="box">
<div id="explanation1">This photo is not a PNG image with an alpha channel.</div>
<div id="explanation2"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.jpg">It is a JPEG</a> that has been clipped with polyClip.js</div>
<div id="explanation3">
<p>The text was rotated using CSS3 Transforms, with alternate CSS for older IE using the <a href="http://www.useragentman.com/IETransformTranslator">IE Transform Translator</a>.  Original photo by <a href="http://www.flickr.com/photos/free-stock/4816852597/">Emilian Robert Vicol</a> clipped with polyClip.js</p>
</p></div>
<div class="clipParent"><img data-polyclip=" 0,0,45,3,55,8,64,18,74,24,80,32,86,45,82,32,83,38,86,46,88,52,90,62,90,68,91,76,91,82,91,83,103,87,112,91,121,97,127,102,133,106,136,112,138,116,139,121,139,122,147,125,154,127,163,129,178,131,190,132,204,132,210,131,225,124,286,107,332,96,370,88,401,83,425,79,450,76,457,77,456,80,446,85,430,91,406,99,383,108,365,114,352,119,384,117,416,116,453,114,472,113,474,113,472,118,446,126,419,132,390,138,362,144,343,148,307,153,282,157,266,159,245,160,234,160,219,160,209,163,198,167,182,175,170,183,158,194,156,195,157,201,157,204,157,204,157,210,153,219,148,229,143,236,137,244,132,250,124,258,118,263,113,267,98,276,87,281,77,283,0,284,1,191,10,190,16,191,20,191,21,192,28,191,37,190,39,189,38,190,40,190,48,190,53,191,57,191,69,188,77,187,91,183,109,179,127,173,146,166,162,158,173,153,158,151,144,150,127,151,105,152,86,154,66,157,53,160,49,161,46,165,44,167,41,168,33,168,28,167,28,166,21,170,16,171,11,171,4,170,0,168" src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.jpg" alt=""  width="480" height="360" class="alignleft size-full wp-image-3771" /></div>
</div>
<p>There have been many times I have come across the need to <strong>take an image and cut an irregular shape out of it.</strong>  Normally, when a developer comes across this requirement, the only thing to do is to open the image up with your favorite graphics editor, use the select tool to cut out the shape you want, and then save the result as a <a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</a>, since it is the only image format used by all web browsers that support alpha channels.  The problem is that <strong>PNG images, while compressed, are not as small as <a href="http://en.wikipedia.org/wiki/Jpeg">JPEGs</a> if the source image is a photograph</strong>, and the download time of a page can balloon to unacceptable levels if there are many of these types of image on a page.  When I first came across this problem, I didn&#8217;t think there was an obvious solution, but after a lot of thought, I created <strong>a library that uses <a href="http://en.wikipedia.org/wiki/HTML_canvas">HTML5 <code>canvas</code></a> to clip a JPEG </strong> (or any other image for that matter).  <strong>The library also supports older versions of IE</strong> (7-8) using the <a href="http://excanvas.sourceforge.net/">Excanvas JavaScript library</a> which polyfills <code>canvas</code> using <a href="http://en.wikipedia.org/wiki/Vector_Markup_Language">VML</a>.</p>
<h2>Okay, How Can I Do The Same Thing?</h2>
<ul>
<li><a href="https://github.com/zoltan-dulac/polyClip">Download my script from github</a> (It includes jQuery 1.6.4 and excanvas release 3.  It should work with later versions &mdash; if it doesn&#8217;t, please let me know and I&#8217;ll fix it ;-) ) .</li>
<li>Include them into the head of your document.<br />
<blockquote class="code">
<pre>
  &lt;script src="/path/to/js/jquery-1.6.2.min.js"&gt;&lt;/script&gt;

  &lt;!--[if lt IE 9 ]&gt;
   &lt;script src="/path/to/js/excanvas/excanvas.compiled.js"&gt;&lt;/script&gt;
  &lt;![endif]--&gt;

  &lt;script src="/path/to/js/polyClip-p.js"&gt;&lt;/script&gt;
</pre>
</blockquote>
</li>
<li>Layout your page as normal, placing <code>img</code> tags where you want the clipped images to go:<br />
<blockquote class="code">
<pre>
&lt;div class="clipParent"&gt;
  &lt;img src="images/image.jpg" /&gt;
&lt;/div&gt;
</pre>
</blockquote>
<p><strong>Note the <code>div</code> tag with the class of <code>clipParent</code></strong>.  You must surround all the image tags with <code>data-polyclip</code> attributes set one.  This is so you can style the image correctly, since the library will remove the image tag and replace it with a <code>canvas</code> element.
</p></blockquote>
</li>
<li>For every image on your page that you want to clip, calculate the points of the shape you want to cut out of the image and place them in the <code>data-polyclip</code> attribute.  For example, let&#8217;s say you have the following shape you want to cut out of a photograph:
<div class="centered ghost">
  <img src="/tests/polyClip/images/crop.jpg"   />
</div>
<div class="clipParent centered inFront">
  <img src="/tests/polyClip/images/crop.jpg" data-polyclip="487, 4, 500, 239, 19, 239, 43, 195" data-stroke="rgb(0, 0, 0)" /></p>
<div class="point" id="pt1" style="left: 487px; top: 4px; "><span>(487, 4)</span></div>
<div class="point" id="pt2" style="left: 500px; top: 239px"><span>(500, 239)</span></div>
<div class="point" id="pt3" style="left: 19px; top: 239px"><span>(19, 239)</span></div>
<div class="point" id="pt4" style="left: 43px; top: 195px; "><span>(43, 195)</span></div>
</div>
<p>You would then just set the <code>data-polyclip</code> attribute to those points:</p>
<blockquote class="code">
<pre>
&lt;img src="image.jpg" <span class="hilite">data-polyclip="487, 4, 500, 239, 19, 239, 43, 195"</span> /&gt;
</pre>
</blockquote>
<p>Note that the point co-ordinates are comma delimited.  If you don&#8217;t want to calculate these numbers by hand, you can use your favorite imagemap generation tool to do generate the list of coordinates.  Just remember to take the coordinates out of the imagemap code and stick it in the <code>data-polyclip</code> attribute (for the examples on this page, I used the on-line tool available at <a href="http://www.image-maps.com">image-maps.com</a>).</li>
</ul>
<h2>Why Should I Do This Instead of Using a PNG?</h2>
<p>Compare the image above with a PNG clipped with the GIMP.   Even when I compressed the PNG with <a href="http://www.useragentman.com/blog/2009/09/16/optimizing-png-files-for-both-web-and-print/">my PNG optimization script</a>, the 191K PNG file is huge compared to it&#8217;s tiny 18K polyclipped JPEG analogue (<strong>Note:</strong> file sizes refer to the size of the full image as displayed at the top of this article):</p>
<table class="dataTable">
<thead>
<tr>
<th>JPG using polyClip.js (18K)</th>
<th>PNG (191K)</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="clipParent"><img data-polyclip="0,0,55,0,64,4,70,12,80,22,82,32,86,45,82,32,83,38,86,46,88,52,90,62,90,68,91,76,91,82,91,83,103,87,112,91,121,97,127,102,133,106,136,112,138,116,139,121,139,122,147,125,154,127,163,129,178,131,190,132,204,132,210,131,225,124,286,107,332,96,370,88,401,83,425,79,450,76,457,77,456,80,446,85,430,91,406,99,383,108,365,114,352,119,384,117,416,116,453,114,472,113,474,113,472,118,446,126,419,132,390,138,362,144,343,148,307,153,282,157,266,159,245,160,234,160,219,160,209,163,198,167,182,175,170,183,158,194,156,195,157,201,157,204,157,204,157,210,153,219,148,229,143,236,137,244,132,250,124,258,118,263,113,267,98,276,87,281,77,283,0,284,1,191,10,190,16,191,20,191,21,192,28,191,37,190,39,189,38,190,40,190,48,190,53,191,57,191,69,188,77,187,91,183,109,179,127,173,146,166,162,158,173,153,158,151,144,150,127,151,105,152,86,154,66,157,53,160,49,161,46,165,44,167,41,168,33,168,28,167,28,166,21,170,16,171,11,171,4,170,0,168" src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.jpg" alt=""  width="480" height="360" class="alignleft size-full wp-image-3771" /></div>
</td>
<td>
<div class="pngImage">
  <img src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.png" />
  </div>
</td>
</tr>
</tbody>
</table>
<p>You may ask whether the amount of JavaScript used in this solution is greater than the bandwidth saved by using JPEG compression.  <strong>Not including jQuery, the amount of JavaScript clocks in at 2K or 13K</strong>, depending on the browser used (2K for the compressed polyClip script and 11K for excanvas, which will only be loaded by IE7-8). Although jQuery adds 91K to this equation, it doesn&#8217;t matter that much to me personally since I am probably using it for other parts of my page anyways.  <strong>Even with jQuery, the amount of JavaScript downloaded outweighs using a PNG,</strong> especially if your are clipping a larger image or a huge amount of smaller images.</p>
<p><a class="exampleLink" href="https://github.com/zoltan-dulac/polyClip">Download the latest version of polyClip.js from github.</a></p>
<h2>A Few Caveats</h2>
<ul>
<li>In IE7 and 8, the image may appear briefly as a black outline before the image appears. Other than that, it looks about the same as the other browsers.</li>
<li>The image does not show up correctly in Opera Mini.  Then again, a lot of things (e.g. CSS3 text-shadows, CSS3 Transforms, etc.) don&#8217;t show up correctly in Opera Mini. :-)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/10/29/clipping-jpeg-images-into-non-rectangular-polygons-using-polyclip-js/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Full CSS3 Text-Shadows &#8212; Even In IE</title>
		<link>http://www.useragentman.com/blog/2011/06/29/full-css3-text-shadows-even-in-ie/</link>
		<comments>http://www.useragentman.com/blog/2011/06/29/full-css3-text-shadows-even-in-ie/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 04:04:29 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[ClearType]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[IE Visual Filters]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Polyfills]]></category>
		<category><![CDATA[text-shadow]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3296</guid>
		<description><![CDATA[<img src="/blog/wp-content/uploads/2011/06/splash.png" />While researching the possibilities of using text-shadows in IE, I noticed that there wasn't any silver bullet that produced multiple CSS3-like text-shadows in IE.  However, combining my cssSandpaper script with a refactored version of a text-shadowing script by Kazumasa Hasegawa, we can now have IE text-shadow goodness.]]></description>
			<content:encoded><![CDATA[<div id="intro" class="alignLeft">
<span id="css3And">CSS3 &amp;</span><br /><span id="html5">HTML5</span>
</div>
<p>In the last few months, <strong>I have written two articles where I discussed a few strategies to do CSS3-style transforms in IE</strong> (<a href="http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/">CSS3 Text-Shadow – Can It Be Done in IE Without JavaScript?</a> and <a href="http://www.useragentman.com/blog/2011/04/23/css-blurred-text-shadow-in-ie-part-i/">CSS Blurred Text-Shadow in IE — Part I</a>).  While demonstrating the possibilities to creating a varied range of text-shadows in IE, there wasn&#8217;t any silver bullet that produced what I considered one of the Holy Grails of CSS polyfills: <strong>a method that could take an existing page and render multiple CSS3 text-shadows in IE</strong> with few, if any, changes to the CSS code. To that end, at the end of my last article, I dropped the gauntlet at the end of my last article  and challenged the web development community to help come up with a better solution.  I got a few takers, but one stood out from the rest. <strong><a href="http://asamuzak.jp/">Kazumasa Hasegawa</a> submitted his script and blog post <a href="http://asamuzak.jp/html/321">(in Japanese</a> and then <a href="http://asamuzak.jp/html/322">in English</a>) about his script that could do exactly what I asked: full CSS3-style text-shadowing in IE.</strong>   It can do multiple blurred and unblurred shadows per block of text.  The only caveat is that one would have to set the CSS selectors inside a JavaScript file.  However, the code was extremely well written, and it was very easy for me to refactor it to become a plug-in for my CSS3 polyfill library, <a href="http://www.useragentman.com/blog/current-projects/cross-browser-css-transforms-even-in-ie/">cssSandpaper</a>.  Now, all a developer has to do now is include a few <code>&lt;script&gt;</code> tags into the <code>&lt;head&gt;</code>, and<strong> BAM!!! &mdash; instant text-shadow goodness in IE7+.</strong></p>
<h2>Yeah Whatever!  Show Me Proof!</h2>
<p>If you are viewing this page in IE7+, here are the droids you are looking for:</p>
<table class="dataTable">
<thead>
<tr>
<th>
Live CSS/HTML
</th>
<th class="screenshot">
IE9
</th>
<th class="screenshot">
Firefox
</th>
<th>
Text-Shadow Syntax<br />
</tr>
</thead>
<tbody>
<tr  id="example1">
<td  class="example">
<span><strong>Simple</strong></span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie01.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff01.png" alt=""  />
</td>
<td class="code">
<pre>
2px 2px 0 #E51919
</pre>
</td>
</tr>
<tr id="example2">
<td  class="example">
<span>Blurred</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie02.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff02.png" alt=""  />
</td>
<td class="code">
<pre>
3px 3px 3px #B24C4C
</pre>
</td>
</tr>
<tr id="example3">
<td  class="example cssSandpaper-IEuseGradientFilter">
<span>Etched</span>
</td>
<td class="cssSandpaper-IEuseGradientFilter">
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie03.png" alt=""  />
</td>
<td class="cssSandpaper-IEuseGradientFilter">
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff03.png" alt=""  />
</td>
<td class="code">
<pre>
0px 1px 0px white
</pre>
</td>
</tr>
<tr  id="example4">
<td  class="example">
<span>Flaming</span>
</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie04.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff04.png" alt=""  /></td>
<td class="code">
<pre>
0px   0px  4px white,    0px  -5px  4px #FFFF33,
2px -10px  6px #FFDD33, -2px -15px 11px #FF8800,
2px -25px 18px #FF2200 </pre>
</td>
</tr>
<tr  id="example5">
<td  class="example">
<span>Neon</span>
</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie05.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff05.png" alt=""  /></td>
<td class="code">
<pre>
0 0 1px  #ffffff, 0 0 2px  #ffffff,
0 0 3px  #ffffff, 0 0 4px  #ff00de,
0 0 7px  #ff00de, 0 0 8px  #ff00de,
0 0 10px #ff00de, 0 0 15px #ff00de;
</pre>
</td>
</tr>
<tr  id="example6">
<td  class="example">
<span>Unfocused</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie06.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff06.png" alt=""  />
</td>
<td class="code">
<pre>
0 0 3px #fff
</pre>
</td>
</tr>
<tr  id="example7" >
<td class="example">
<span>Glowing</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie07.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff07.png" alt=""  />
</td>
<td class="code">
<pre>
0 0 20px yellow, 0 0 60px yellow
</pre>
</td>
</tr>
<tr  id="example8">
<td  class="example">
<span>Embossed</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie08.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff08.png" alt=""  />
</td>
<td class="code">
<pre>
-1px -1px white, 1px 1px #333333
</pre>
</td>
</tr>
<tr  id="example9">
<td  class="example">
<span>Pillow</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie09.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff09.png" alt=""  />
</td>
<td class="code">
<pre>
1px 1px white, -1px -1px #444
</pre>
</td>
</tr>
<tr  id="example10">
<td  class="example">
<span>Fake 3D</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie10.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff10.png" alt=""  />
</td>
<td class="code">
<pre>
1px 1px rgba(255,128,0,.7),
2px 2px rgba(255,128,0,.7),
3px 3px rgba(255,128,0,.7),
4px 4px rgba(255,128,0,.7),
5px 5px rgba(255,128,0,.7)
</pre>
</td>
</tr>
</tbody>
</table>
<p>(Note that the Blur example does not appear correctly in IE7 and 8, due to lack of support of the <code>transparent</code> color)</p>
<p>These examples were inspired by these excellent examples on the web:</p>
<ul>
<li><a href="http://www.css3.info/preview/text-shadow/">Text-shadow, Photoshop like effects using CSS</a> by <a href="http://www.css3.info">CSS3.info</a> (<a href="http://www.useragentman.com/packages/cssSandpaper-1.5/tests/csssandpaper/textshadowcss3info.html">cssSandpaper version</a>)</li>
<li><a href="http://line25.com/articles/using-css-text-shadow-to-create-cool-text-effects">Using CSS Text-Shadow to Create Cool Text Effects</a> from <a href="http://line25.com/">Chris Spooner</a> (<a href="http://www.useragentman.com/packages/cssSandpaper-1.5/tests/csssandpaper/textshadowline25.html">cssSandpaper version</a>)</li>
<li><a href="http://themegamag.com/coding/css-coding/8-css3-text-shadow-effects/">8 css3 text-shadow effects</a> by <a href="http://falemadi.com/">Fatma Alemadi</a> (<a href="http://www.useragentman.com/packages/cssSandpaper-1.5/tests/csssandpaper/textshadowthemegamag.html">cssSandpaper version</a>)</li>
</ul>
<h2>How Can cssSandpaper Give Me <code>text-shadow</code> Goodness?</h2>
<ol>
<li><a href="https://github.com/zoltan-dulac/cssSandpaperhttps://github.com/zoltan-dulac/cssSandpaper">Download the code from github</a>.</li>
<li>Include the following in the <code>head</code> of the document you have <code>text-shadow</code>ing on:<br />
<blockquote class="code">
<pre>
&lt;script type="text/javascript" src="/path/to/EventHelpers.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/textshadow.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/cssQuery-p.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/cssSandpaper.js"&gt;
&lt;/script&gt;
</pre>
</blockquote>
</li>
<li>It should now work in IE.  With the HTML5 Doctype, <a href="http://mathiasbynens.be/notes/html5-levels#level-1">you can remove the <code>type="text/javascript"</code> attributes</a>.</li>
</ol>
<p><a href="https://github.com/zoltan-dulac/cssSandpaper" class="exampleLink">Download the latest version of cssSandpaper with IE <code>text-shadow</code> support.</a></p>
<h2>Okay, What Are The Caveats</h2>
<p>Like any polyfill solution, there are a few things one has to keep in mind when using a solution like this. </p>
<ol>
<li>As you can see from the above examples, blurred text-shadows in IE look slightly different because of the different algorithm IE&#8217;s Blur Visual Filter uses compared to what CSS3 text-shadow uses.  This is not so obvious on the second example above, but becomes more obvious the more blurred text-shadows are applied on the same text.  For most applications, this is acceptable, but for those of us who like to pixel-bitch (i.e. complain when something is not pixel-perfect), you should be aware of this difference (No, I don&#8217;t know where I got that term from.  I may have made it up.  Anyone else heard of it before?)</li>
<li>Creating a large text-shadow blur (i.e. greater than 70px) on a large piece of text can cause Internet Explorer&#8217;s rendering engine to slow down when the text is scrolled into view.</li>
<li>Sometimes IE cuts off the shadows when the <code>line-height</code> is too small:<br />
<div id="attachment_3452" class="wp-caption aligncenter" style="width: 312px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie01-cutoff.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie01-cutoff.png" alt="" title="ie01-cutoff" width="302" height="98" class="size-full wp-image-3452" /></a><p class="wp-caption-text">The letter 'P' and other letters with descenders may get cut off if the line-height is not set to be larger than the actual font-size.</p></div></p>
<li>In IE7-8, elements above text-shadowed text that have a <code>line-height</code> property measured in <code>em</code> units may effect the text-shadow in IE.  If there is a problem, the shadow is one pixel off from where it is supposed to be, as shown in this screenshot:<br />
<div id="attachment_3460" class="wp-caption aligncenter" style="width: 626px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/06/1pxOff.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/1pxOff.png" alt="" title="1pxOff" width="616" height="201" class="size-full wp-image-3460" /></a><p class="wp-caption-text">Examples of a correct looking text-shadow (left) and a text shadow that is a pixel off (right).</p></div></p>
<p>As you can see from the screenshots above, this problem is much more obvious when there is no blur-radius in the text-shadow.  I am trying to see if I can work around this problem, but it looks like it has to do rounding errors when IE converts <code>em</code> units to pixels.  If you have a lot <code>em</code> units in your document, you may want to consider using <a href="/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/">my non-JavaScript solution</a> when using a single, non-blurred text-shadows.
</li>
<li>Sometimes, in order for the text-shadows to render correctly when using ClearType, you may have to use the <code>-sand-chroma-override</code> CSS property on the HTML you applied the <code>text-shadow</code> on.  This property is used by cssSandpaper to fix a problem with ClearType and IE&#8217;s Visual Filters, as described in my previous blog post, <a href="http://www.useragentman.com/blog/2010/09/02/how-to-make-cleartype-font-face-fonts-and-css-visual-filters-play-nicely-together/" >How to Make ClearType, @font-face Fonts and CSS Visual Filters Play Nicely Together</a>.  Most of the time, this property should be set to be the color that that is behind the text value of the background of the text, but sometimes you will have to look at the outline of the texts and the solid shadows to get an idea as to how it should be set.  Let&#8217;s take, for example, the &#8220;Law and Order&#8221; style text at the top of this page.  We used the following CSS to produce the text-shadow on the &#8220;CSS3&#8243; text:<br />
<blockquote class="code">
<pre>
-sand-chroma-override: #666666;
text-shadow:
	-4px 0px 0px #0f1128,
	-8px 0px 4px rgb(50, 152, 234),
	-10px 0px 4px rgba(50, 152, 234, 0.3),
	-8px -4px 4px rgba(50, 152, 234, 0.6),
	-8px 4px 4px rgba(50, 152, 234, 0.6);
</pre>
</blockquote>
<p>Why did I end up using <code>#666666</code>?  It is a greyscale color that is roughly between the brightness of the off-white text and the blue shadow.   If I set it to black instead, the outline of the text&#8217;s first dark text-shadow would be blocky, as seen here:</p>
<table class="dataTable detailedScreenshots">
<thead>
<th></th>
<th><code>-sand-chroma-override: #000000</code></th>
<th><code>-sand-chroma-override: #666666</code></th>
</thead>
<tbody>
<tr>
<th>Scale 100%</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/lawAndOrderIEChromaBlack.png" alt="" title="lawAndOrderIEChromaBlack"/></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/lawAndOrderIEChromaGray.png" alt="" title="lawAndOrderIEChromaBlack"/</td>
</tr>
<tr>
<th>Scale 300%</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/lawAndOrderIEChromaBlack_Detail1.png" alt="" title="lawAndOrderIEChromaBlack"/</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/lawAndOrderIEChromaGray_Detail1.png" alt="" title="lawAndOrderIEChromaBlack"/</td>
</tbody>
</table>
<p>What you set this value to will depend on the text-shadow recipe you are using and, to paraphrase my Mathematics text-books in college, I leave it up to the reader to play around with the <code>-sand-chroma-override</code> value to see what looks best in which situation.
</li>
</ol>
<h2>In Conclusion</h2>
<p>This script opens up a lot of great possibilities for styling text in IE.  There is still some work to be done to make the script even better with some inevitable bugs that will need to be fixed, and I will continue to work on it to make improvements.  If you see areas for improvement, or any bugs that you see with the code, please make a comment on the <a href="https://github.com/zoltan-dulac/cssSandpaper/issues">cssSandpaper issues page on github</a>.  If you have something to contribute, I would be most grateful. :-)</p>
<p>Other changes that I am planning for cssSandpaper will include:</p>
<ol>
<li><strong>Choice of Selector Library:</strong> I will be refactoring cssSandpaper to use other selector libraries besides cssQuery, which is currently bundled with it.  <strong>This will include, but not restricted to, jQuery. </strong> This will allow developers to reduce the number of libraries included in their documents and reduce load time.</li>
<li><strong>Modularity:</strong> I will make it easy for developers to make their own plugins to support CSS properties not currently supported by cssSandpaper.  This module framework will also allow developers to only add support for the CSS properties they want to use (e.g. if a developer doesn&#8217;t use any CSS3 transforms, then they don&#8217;t have include that code or supporting libraries, like Sylvester.js).</li>
<li><strong>Only Download Code If Needed:</strong> I want to make cssSandpaper only download plugins if actually needed.  This will probably be done with Alex Sexton&#8217;s and Ralph Holzmann&#8217;s excellent <a href="http://yepnopejs.com/">yepnope.js</a> library.  While this library can be used today to speed things up, I want to look into making a little more integrated, if possible.</li>
<li><strong>Further CSS3 Support:</strong> I am looking into polyfills at the moment, like <code>border-image</code>.  Any other ideas for plugins will be most welcome.</li>
</ol>
<h2>Download cssSandpaper</h2>
<p><a href="https://github.com/zoltan-dulac/cssSandpaper" class="exampleLink">Download the latest version of cssSandpaper with IE <code>text-shadow</code> support.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/06/29/full-css3-text-shadows-even-in-ie/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Fixing oninput in IE Using html5Widgets</title>
		<link>http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/</link>
		<comments>http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/#comments</comments>
		<pubDate>Thu, 12 May 2011 18:43:43 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Polyfills]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html5Widgets]]></category>
		<category><![CDATA[IE9]]></category>
		<category><![CDATA[Internet Explorer 9]]></category>
		<category><![CDATA[javascript events]]></category>
		<category><![CDATA[onforminput]]></category>
		<category><![CDATA[oninput]]></category>
		<category><![CDATA[oninput backspace]]></category>
		<category><![CDATA[oninput cut]]></category>
		<category><![CDATA[oninput delete]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3174</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/oninput.png" alt="" title="oninput" width="250" height="140" class="alignleft size-full wp-image-3197" /> Even though <code>onforminput</code> is deprecated, <code>oninput</code> will allow developers to do dynamic calculations on forms with little JavaScript knowledge.  Unfortunately, it doesn't work in IE8 and lower, and there are some small bugs in IE9's implementation when trying to delete characters inside a form field. So I implemented a fix for these issues with an update to my cross-browser HTML5 Forms polyfill, html5Widgets.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/oninput.png" alt="" title="oninput" width="250" height="140" class="alignleft size-full wp-image-3197" /> In my <a href="/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/#comment-12167">previous blog post</a>, I wished that the <code>onforminput</code> event was not deprecated in the HTML5 specification.  I have used this attribute in the past to show values in range elements and show calculations of values inside a form, and thought it was perfect for those who know little JavaScript to implement features like this very easily. <a href="http://www.boogdesign.com/b2evo/">Rob Crowther</a> made <a href="/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/#comment-12167">pointed out</a> that the <code>oninput</code> event, which has a similar function as <code>onforminput</code> the main argument behind dropping <code>onforminput</code> event.  Makes sense, and I was happy &mdash; it works in all modern web browsers, including IE.  But as you would guess, there has to be at least one problem with a cool bit of new web technology when it comes to cross-browser implementation.</p>
<h2>What are the issues?</h2>
<p>IE has three issues related to <code>oninput</code>:</p>
<ol>
<li><code>oninput</code> is not supported at all in IE8 and lower.</li>
<li>IE9 does not allow referring to form fields directly in the <code>oninput</code> expression.  For example, this code works in all browsers except IE9:<br />
<blockquote class="code">
<pre>
&lt;form name="f1" <span class="hilite">oninput="output.value = parseFloat(darkness.value);"</span>&gt;
    Darkness Level:
    &lt;input type="range" name="darkness" value="0" min="0" max="255"&gt;
    &lt;output name="output"&gt;
&lt;/form&gt;
</pre>
</blockquote>
<p>This is not so bad, since one could refactor the event code like this:</p>
<blockquote class="code">
<pre>
&lt;form name="f1"
  <span class="hilite">oninput="document.getElementById('output').innerHTML = parseFloat(darkness.value);"</span>&gt;
    Darkness Level:
    &lt;input type="range" name="darkness" value="0" min="0" max="255"&gt;
    &lt;output id="output"&gt;
&lt;/form&gt;
</pre>
</blockquote>
</li>
<li>If you use the backspace key while entering in a value, IE9 doesn&#8217;t fire the <code>oninput</code> event.  This, in my opinion, is really bad, because it does affect how the form behaves.  For example, take the following form in IE9:<br />
<form oninput="document.getElementById('tax').innerHTML = (parseFloat(amount.value) * parseFloat(price.value) * 0.15).toFixed(2); document.getElementById('total').innerHTML = (parseFloat(amount.value) * parseFloat(price.value) * 1.15).toFixed(2)">
<table class="formTable">
<tbody>
<tr>
<th>
Amount:
</th>
<td>
<input name="amount" value="1" min="1" max="100" type="number">
</td>
</tr>
<tr>
<th>
Item:
</th>
<td>
<input name="price" value="299.99" min="1" step="0.01" type="number">
</td>
</tr>
<tr>
<th>Tax:</th>
<td><output id="tax">45.00</output></td>
</tr>
<tr>
<th>Total:</th>
<td><output id="total">344.99</output>
</td>
</tr>
</tbody>
</table>
</form>
<p>As the user types in values for the amount and price into the form, the <code>oninput</code> event calculates the tax and total.  <strong>However, if the user is entering a value into, say, the price and make a mistake and press the backspace, IE9 will not update the tax and total.</strong>  Your application will give erroneous information, the user will be surprised at the total being larger than he expected, says &#8220;screw this&#8221; and leaves the application.  Your company loses the big sale, your boss fires you, and <strong>next thing you know you are on a street, or worse, coding <a href="http://drdobbs.com/architecture-and-design/210602491">COBOL</a> on a 30 year old IBM PC running MS-DOS 1.0 in some fishing tackle store.</strong>  Not pretty.</li>
</ol>
<h2>Oh The Humanity! How Can I Prevent Such a Fate?</h2>
<p>Since I hate COBOL, I decided to update my html5Widgets library to:</p>
<ol>
<li>Add support for <code>oninput</code> for browsers that don&#8217;t support it (e.g. IE7 and 8)</li>
<li>Force IE9 to fire a form&#8217;s <code>oninput</code> when the backspace and delete keys are pressed inside any of the <code>input</code> nodes.</li>
<li>Force IE9 to fire a form&#8217;s <code>oninput</code> when the <code>cut</code> event is fired on any of the <code>input</code> nodes.</li>
</ol>
<p>Using the link below, you can see an example similar to the one above using html5Widgets to fix these issues.</p>
<p><a class="exampleLink" href="/examples/html5Widgets/tests/html5Widgets/outputWithOninput.html">Let&#8217;s see html5Widgets give IE some <code>oninput</code> goodness</a></p>
<p>In order to do this, I used ideas from <a href="http://blog.danielfriesen.name">Daniel Friesen&#8217;s</a> blog post, <em><a href="http://blog.danielfriesen.name/2010/02/16/html5-browser-maze-oninput-support/">A HTML5 Browser Maze, Oninput Support</a></em> (thanks to <a href="www.paulirish.com">Paul Irish</a> for pointing me into that direction).  The result works rather well.  Note that I did not fix the IE9 &#8220;cannot use <code>.value</code>, must use <code>.innerHTML</code>&#8221; bug described earlier. It&#8217;s a little bit more verbose, but for now it&#8217;s what a developer needs to do for true cross-browser <code>oninput</code> support. I have also kept <code>onforminput</code> support in the code, just in case anyone has used it in the past (e.g. me).  To ensure the best experience, I wouldn&#8217;t use both events on the same page.  </p>
<p>Note also I did not add support for <code>oninput</code> in any element other than <code>form</code>.  I may do this after further research in the way it supported across browsers (for example, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=195696">Firefox has an issue with <code>oninput</code> being used on <code>textarea</code> elements</a>).</p>
<h2>Download</h2>
<p><a class="exampleLink" href="https://github.com/zoltan-dulac/html5Widgets">Download the latest version of html5Widgets, which includes <code>oninput</code> support, from github.</a></p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://blog.danielfriesen.name">Daniel Friesen&#8217;s</a> blog post, <em><a href="http://blog.danielfriesen.name/2010/02/16/html5-browser-maze-oninput-support/">A HTML5 Browser Maze, Oninput Support</a></em>.</li>
<li><a href="http://help.dottoro.com/ljhxklln.php">oninput event | input event</a> from the <a href="http://help.dottoro.com/">Dottoro Web Reference</a></li>
<li><a href="http://mathiasbynens.be/notes/oninput">Using the oninput event with onkeydown as its fallback</a> by the ever talented <a href="http://mathiasbynens.be/">Mathias Bynens</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Is onforminput Deprecated in HTML5 Forms? (And Why Should I Care Anyways?)</title>
		<link>http://www.useragentman.com/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/</link>
		<comments>http://www.useragentman.com/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/#comments</comments>
		<pubDate>Tue, 10 May 2011 19:16:01 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Polyfills]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3065</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/deprecated.png" alt="" title="deprecated" width="250" height="140" class="alignleft size-full wp-image-3112" /> The <code>onforminput</code> event has been stripped out of HTML5, and it makes me sad.  This article will show examples of how it works, how you can use it today in browsers that don't support it, and hopefully will also present a good case as to why it should be put back into the HTML5 specification.  Should something this useful and easy-to-use be abandoned?]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Update:</h3>
<p><strong>Newer versions of all browsers support the <code>form</code> element&#8217;s <code>oninput</code> attribute, which replaces the functionality of <code>onforminput</code>, and as a result I wrote a related article <a href="http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/">Fixing <code>oninput</code> in IE Using html5Widgets</a>.</strong>  Thanks to <a href="http://www.boogdesign.com/b2evo/">Rob Crowther</a> for setting me straight and providing <a href="http://jsfiddle.net/robertc/YCEKQ/">a great example</a>, which <a href="http://jsfiddle.net/dYSS6/">I have forked</a> to work for IE9.  I will refactor html5Widgets to support <code>oninput</code> in IE very soon.  I will leave this article as is for the benefit of anyone who is Googling for <code>onforminput</code> and why it was deprecated.
</p>
</div>
<p><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/deprecated.png" alt="" title="deprecated" width="250" height="140" class="alignleft size-full wp-image-3112" /></p>
<p>I was just doing some regression testing on <a href="http://www.useragentman.com/blog/2010/07/27/cross-browser-html5-forms-using-modernizr-webforms2-and-html5widgets/">html5Widgets</a>, and noticed that the <code>onforminput</code> event wasn&#8217;t working in Firefox 4.  This didn&#8217;t make sense to me: I designed html5Widgets to detect if the <code>output</code> tag is supported, and if not, add support for it.  I believed that if a browser supported the <code>output</code> tag, it also had to support the <code>onforminput</code> event, since I assumed that this was one of the main reasons of having the <code>output</code> tag in the first place.  However, <strong>Firefox 4 supports the <code>output</code> tag, but doesn&#8217;t support <code>onforminput</code>.</strong>  After doing a bit of light research, I came across this <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=11129">this bug report</a> that seems to indicate that <code>onforminput</code> is deprecated.  This article will discuss<strong> what <code>onforminput</code> does</strong>, why it is very <strong>useful to designers are not so strong in JavaScript</strong>, how one can <strong>add support for <code>onforminput</code> to browsers that don&#8217;t</strong>, and why I really <strong>hope someone in power adds it back to the HTML5 Forms specification,</strong> or at least something very similar.</p>
<h2>Why Do I Care</h2>
<p>For those that don&#8217;t know what this is, <strong><code>onforminput</code> is an attribute</strong> that a web author can use on the <code>output</code> tag <strong>to do some calculations with the values in a form&#8217;s input fields</strong> and show that calculation to a user.  Right now, Opera is the only browser that natively supports it, but <a href="http://www.useragentman.com/blog/2010/07/27/cross-browser-html5-forms-using-modernizr-webforms2-and-html5widgets/">in an earlier post</a> I showed how one could use it with my html5Widgets polyfill library in all the other browsers.  How does it work? To illustrate a very simple use case, let&#8217;s say I have a <code>range</code> input field:</p>

<table class="dataTable">
<thead>
<tr>
<th>HTML</th>
<th>Output</th>
</tr>
</thead>
<tbody>
<tr>
<td class="withCode">
<blockquote class="code">
<pre>
&lt;form&gt;
  Darkness Level:
  &lt;input type="range" name="darkness"
         value="0" min="0" max="255" /&gt;
&lt;/form&gt;
</pre>
</blockquote>
</td>
<td>
<form>
Darkness Level: 
<input type="range" 
       name="darkness"
       value="0"
       min="0"
       max="255" />
</form>
</td>
</tr>
</tbody>
</table>
<p>(Note the <code>range</code> element is <a href="http://remysharp.com/2010/10/08/what-is-a-polyfill/">polyfilled</a> with html5Widgets if your browser doesn&#8217;t support it).</p>
<p>The <code>range</code> input type is a slider widget, and we use it here so the user can choose a number between 0 and 255.  The slider looks cool, but from a usability standpoint, there is no feedback of what value the user is sliding to.  It would make more sense to show a number next to the slider. which gives feedback to the user as to what the slider&#8217;s value is.  This is where <code>onforminput</code> comes in:</p>

<table class="dataTable">
<thead>
<tr>
<th>HTML</th>
<th>Output</th>
</tr>
</thead>
<tbody>
<tr>
<td class="withCode">
<blockquote class="code">
<pre>
&lt;form&gt;
  Darkness Level:
  &lt;input type="range"
     name="darkness"
     value="0" min="0" max="255" /&gt;
  <span class="hilite">&lt;output 
     onforminput="this.value = darkness.value"
  &gt;0&lt;/output&gt; / 255</span>
&lt;/form&gt;

</pre>
</blockquote>
</td>
<td>
<form>
  Darkness Level:
  <input type="range" name="darkness"
         value="0" min="0" max="255" />
  <output 
         onforminput="this.value = darkness.value"
  >0</output> / 255
</form>
</td>
</tr>
</tbody>
</table>
<p><strong>Immediate user feedback!  Great user experience! <em>And simple syntax!</em></strong>  Even a person who is not familiar with JavaScript can figure it out.  But it&#8217;s deprecated!  So, even though the <code>output</code> tag is supported by Firefox 4, <code>onforminput</code> is not.  Oh-noes!!!!</p>
<p>Luckily, my html5Widgets library adds support for it in browsers that don&#8217;t, including Firefox 4.  I just made a small change that worked around an issue preventing Firefox from supporting it, and BAM!  Instant support.</p>
<p>Another good (and common) example for using <code>output</code> would be a form for an online tool that calculates a total automatically.  Enter in values into the following form and see the calculations magically appear:</p>

<form>
<table class="formTable">
<tbody>
<tr>
<th>
Amount:
</th>
<td>
<input type="number" name="amount" value="1" min="1" max="100" />
</td>
</tr>
<tr>
<th>
Item:
</th>
<td>
<input type="number" name="price" value="299.99" min="1" step="0.01" />
</td>
</tr>
<tr>
<th>Tax:</th>
<td><output onforminput="this.value = (parseFloat(amount.value) * parseFloat(price.value) * 0.15).toFixed(2)"
>0</output></td>
</tr>
<tr>
<th>Total:</th>
<td><output onforminput="this.value = (parseFloat(amount.value) * parseFloat(price.value) * 1.15).toFixed(2)"
>0</output>
</tr>
</tbody>
</table>
</form>
<h2>But, why is it depreciated in the first place?</h2>
<p>It seems the decision has been made to remove <code>onforminput</code> from the HTML5 specification since it&#8217;s purpose can be easily done with capturing events (at least, that&#8217;s what I understood from <a href="http://lists.w3.org/Archives/Public/public-webapps/2010OctDec/0177.html">this thread about <code>onforminput</code> and <code>onformchange</code> on the public-webapps mailing list</a>).  </p>
<p>While this is true, I think keeping it in would be a huge help to designers and developers.  I even think that having it declared inline like I do in the code examples above is useful.  Even though it breaks the separation of document structure and behavior, it allows a developer with practically no JavaScript knowledge to implement this simple feature in a form.  According to the <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=11129">Bug Report</a>, designers shouldn&#8217;t have to use <code>onforminput</code> since they can do this instead: </p>
<blockquote class="code">
<pre>
&lt;form name="f1"&gt;
Darkness Level:
<div class="hilite">    &lt;script type="text/javascript"&gt;
      document.addEventListener("input",
        function(e) {
          if (document.forms.f1 == e.target.form)
            e.target.form.output.value =
              parseFloat(e.target.form.darkness.value);
        }, true);
    &lt;/script&gt;</div>

    &lt;input type="range" name="darkness"
         value="0" min="0" max="255" /&gt;
    &lt;output name="output"&gt;
  &lt;/form&gt;
</pre>
</blockquote>
<p><strong>This is uglier than your Mom&#8217;s mood when you don&#8217;t call her on Mother&#8217;s Day</strong> (not that I&#8217;m speaking from any recent experience). Even though it is dead easy for a JavaScript programmer to implement this without <code>onforminput</code>, some web designers wouldn&#8217;t have the knowledge or the patience to do so.  This is not a slight to those designers &mdash; after all, they can probably make better looking web pages than the average programmer. So I am keeping <code>onforminput</code> in html5Widgets.  It is really convenient and easy to understand.</p>
<h2>A Note To Those In Power</h2>
<p><strike>To anyone at the W3C who has the power to do so, I am politely asking to reconsider and <strong>please put <code>onforminput</code> back into the specification</strong> or <strong>at least replace it with something just as simple</strong> (the latter being attractive to those who want to continue separating the structure of the document (i.e. HTML) from the behavior (i.e. JavaScript)).</strike> As mention in the update on the top of the page, <code>oninput</code> is a great replacement for <code>onforminput</code> and it works in all modern browsers.  </p>
<p>In my humble opinion, creating calculations the old-fashioned way with events and lines and lines of JavaScript is painful for designers who aren&#8217;t scripters.  After all, isn&#8217;t this the reason why <code>required</code> and <code>pattern</code> were created?</p>
<p><a class="exampleLink" href="https://github.com/zoltan-dulac/html5Widgets">Download the latest version of html5Widgets, which includes <code>onforminput</code> support, from github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cross Browser HTML5 Ruby Annotations Using CSS</title>
		<link>http://www.useragentman.com/blog/2010/10/29/cross-browser-html5-ruby-annotations-using-css/</link>
		<comments>http://www.useragentman.com/blog/2010/10/29/cross-browser-html5-ruby-annotations-using-css/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 04:17:18 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Internationalization]]></category>
		<category><![CDATA[Polyfills]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[bopomofo]]></category>
		<category><![CDATA[chinese]]></category>
		<category><![CDATA[furigana]]></category>
		<category><![CDATA[hangul]]></category>
		<category><![CDATA[hanja]]></category>
		<category><![CDATA[hiragana]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[japanese]]></category>
		<category><![CDATA[kanji]]></category>
		<category><![CDATA[katakana]]></category>
		<category><![CDATA[korean]]></category>
		<category><![CDATA[multilanguage]]></category>
		<category><![CDATA[multilingual]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[xhtml]]></category>
		<category><![CDATA[xhtml 2.0]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=1658</guid>
		<description><![CDATA[<img src="/blog/wp-content/uploads/2010/10/containerFirefox2.png"  /> Ruby Characters, although used originally to help people read complicated Chinese and Japanese characters, can also be used to annotate all types of information to written text.  This article shows how you can use it in browsers that support it, but also in ones that don't using a simple stylesheet.]]></description>
			<content:encoded><![CDATA[<div id="attachment_1735" class="wp-caption alignright" style="width: 419px"><a href="http://www.flickr.com/photos/eliazar/3193967863/"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/rubyExample.jpg" alt="An example of ruby text, from a photo by Flickr user eliazar" title="screenshot" width="409" height="261" class="size-full wp-image-1619" /></a>
<p class="wp-caption-text">An example of ruby text, from <a href="http://www.flickr.com/photos/eliazar/3193967863/">a photo</a> by Flickr user <a href="http://www.flickr.com/photos/eliazar/">eliazar</a>.&#8221;</p>
</div>
<p>When talking about <strong>Ruby Annotations</strong>, I don&#8217;t mean Ruby on Rails, or anything related to the Ruby programming language.  I am talking about <a href="http://en.wikipedia.org/wiki/Ruby_character"><strong>ruby characters</strong></a> which <strong>are used to annotate text with supplementary information.</strong>  For example if some readers wouldn&#8217;t know what the term &#8220;WWW&#8221; means, we can use ruby annotations to help them out like this:</p>
<div class="rubyExample">
<p>I love the <ruby><rb>WWW</rb><rp> （</rp><rt class="small" style="font-size: 0.37em">World Wide Web</rt><rp>） </rp></ruby>.</p>
</div>
<p>The <strong>ruby base</strong> (in this case &#8220;WWW&#8221;) is annotated by <strong>ruby text</strong> (&#8220;World Wide Web&#8221;).  In this case, the ruby text appears in a small font-size above the base.  Traditionally, ruby annotations have been used in Chinese, Korean and Japanese text-books to help students of those languages sound out more complicated characters:</p>
<div class="rubyExample japanese">
  <ruby><rb>東京</rb><rp> （</rp><rt>とうきょう</rt><rp>） </rp></ruby>に<ruby>行<rp> （</rp><rt>い</rt><rp>） </rp></ruby>きたい。
</div>
<p>In the text above, the <strong>ruby base is written in Kanji</strong>, many of which are only readable by Japanese with a high-school education. The <strong>ruby text is written in Hiragana</strong>, which all Japanese grade-schoolers can understand. </p>
<p>I can hear you saying to yourself <strong>&#8220;Who cares?  I&#8217;m not Japanese!  I can&#8217;t read any of it!&#8221;</strong>. Ruby annotations can also be used to help those who don&#8217;t speak the language at all.  An author can use ruby to help English speakers  pronounce Japanese &#8230; </p>
<div class="rubyExample japanese">
  <ruby><rb>東京</rb><rp> (</rp><rt><span class="romaji">tō kyō</span></rt><rp>) </rp></ruby> <ruby>に<rp> (</rp><rt><span class="romaji">ni</span></rt><rp>) </rp></ruby><ruby>行き<rp> (</rp><rt><span class="romaji">iki</span></rt><rp>) </rp></ruby><ruby>たい<rp> (</rp><rt><span class="romaji">tai</span></rt><rp>) </rp></ruby>。
</div>
<p>.. or, for that matter, any other language, like Ukrainian.</p>
<div class="rubyExample">
<ruby><rb>Золтан </rb><rp> (</rp><rt>zol-tan</rt><rp>)</rp></ruby> <ruby><rb>Євгенович </rb><rp> (</rp><rt>yew-hen-o-vich</rt><rp>)</rp></ruby> <ruby><rb>Гаврилюк </rb><rp> (</rp><rt>how-real-luke</rt><rp>)</rp></ruby>.
</div>
<p>It can also allow an author to give translations on top of foreign words.</p>
<div class="rubyExample japanese">
  <ruby><rb>東京 に 行き たい</rb><rp> (</rp><rt><span class="romaji">I want to go to Tokyo.</span></rt><rp>) </rp></ruby>。
</div>
<h2>But I Have a Hard Enough Time With English!</h2>
<p>Ruby text can also be used for help foreign students pronounce English words that may difficult to read:</p>
<div class="rubyExample">
His <ruby><rb>communication </rb><rp> (</rp><rt class="phonetic">k&#601;-my<span class="long">oo</span>-n&#301;-<strong>k&#257;&#180;</strong>-sh&#601;n</rt><rp>) </rp></ruby> skills are quite bad.
</div>
<p>It can be also be used to help English speakers read intimidating Eastern European surnames transliterated into English:</p>
<div class="rubyExample">
My name is Zoltan <ruby><rb>Hawryluk</rb><rp> (pronounced: </rp><rt>how-real-luke</rt><rp>)</rp></ruby>.
</div>
<p>(<strong>An aside note to telemarketers:</strong> if you call my home and ask my to speak to &#8220;Mister Have &#8212;- um &#8212; uk&#8221; , &#8220;Mister Hawww &#8212; ahh &#8212; uhhh&#8221; <strong><em>or especially &#8220;Mr. Zoltar&#8221;</em></strong>, I will hang up immediately.  If you actually pronounce my name correctly, I&#8217;ll give you at least five minutes of my time.  I mean it.)</p>
<h2>Okay, how is this coded?</h2>
<p>Let&#8217;s take a look at the markup of the above example:</p>
<blockquote class="code">
<pre>
My name is Zoltan
&lt;ruby&gt;
   &lt;rb&gt;Hawryluk&lt;/rb&gt;
   &lt;rp&gt; (&lt;/rp&gt;
   &lt;rt&gt;how-real-luke&lt;/rt&gt;
   &lt;rp&gt;) &lt;/rp&gt;
&lt;/ruby&gt;
</pre>
</blockquote>
<p>Let&#8217;s break down what each of these tags do:</p>
<table class="dataTable">
<thead>
<tr>
<th>Tag</th>
<th>Name</th>
<th>Function</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>&lt;ruby&gt;</code>
</td>
<td>Ruby Tag</td>
<td>Used to specify a Ruby Annotation.</td>
</tr>
<tr>
<td>
<code>&lt;rb&gt;</code>
</td>
<td>Ruby Base Tag</td>
<td>Used to specify the text that is to be annotated.</td>
</tr>
<tr>
<td><code>&lt;rt&gt;</code></td>
<td>Ruby Text</td>
<td>The actual ruby text, which contains the actual annotation.  By default, it appears above the actual text.</td>
</tr>
<tr>
<td><code>&lt;rp&gt;</code></td>
<td>Ruby Parenthesis</td>
<td>These are displayed to browsers that cannot display ruby text, and permits graceful degradation.  It also allows the text to be copied and pasted into another document without the formatting.</td>
</tr>
</tbody>
</table>
<p>To illustrate the last point about the <code>&lt;rp&gt;</code> tag, copy and paste the following ruby text into notepad, vi or any other plain text editor:</p>
<div class="rubyExample">
My name is Zoltan <ruby><rb>Hawryluk</rb><rp> (pronounced: </rp><rt>how-real-luke</rt><rp>)</rp></ruby>.
</div>
<p>You will see the following in your text editor:</p>
<blockquote class="code">
<pre>
My name is Zoltan Hawryluk (pronounced: how-real-luke).
</pre>
</blockquote>
<p>This is because the of how the <code>&lt;rp&gt;</code> tags are defined:</p>
<blockquote class="code">
<pre>
My name is Zoltan &lt;ruby&gt;&lt;rb&gt;Hawryluk&lt;/rb&gt;<span class="hilite">&lt;rp&gt; (pronounced: &lt;/rp&gt;</span>&lt;rt&gt;how-real-luke&lt;/rt&gt;<span class="hilite">&lt;rp&gt;)&lt;/rp&gt;</span>
</pre>
</blockquote>
<h2>Browser Support</h2>
<p>So what browsers support these tags?  Originally, the <code>&lt;ruby&gt;</code> tag was a proprietary Microsoft tag that worked in IE 5+.  Since then it has become a part of HTML5 and WebKit based browsers like Safari and Chrome now support it as well.  In order for Firefox and Opera to join the party, I <a href="http://www.useragentman.com/shared/css/ruby/screen.css">remixed a stylesheet</a> developed for <a href="http://www.princexml.com/bb/viewtopic.php?t=81">Prince XML</a> by <a href="http://www.chavchanidze.com/">George Chavchanidze</a> of Opera Software.  Below are some screenshots of how the ruby text looks in the various browsers with or without the stylesheet.</p>
<table class="dataTable">
<thead>
<tr>
<th></th>
<th>With stylesheet set</th>
<th>Without stylesheet set</th>
</tr>
</thead>
<tbody>
<tr>
<th>IE 6.0+</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-IE-with.png" alt="example screenshot with IE with stylesheet set"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-IE-without.png" alt="example screenshot with IE with stylesheet set"   /></td>
</tr>
<tr>
<th>Firefox 3.6+</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-Firefox-with.png" alt="example screenshot with Firefox with stylesheet set" title="example-IE-without"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-Firefox-without.png" alt="example screenshot with Firefox with stylesheet set"   /></td>
</tr>
<tr>
<th>Safari 5.0+</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-safari-with.png" alt="example screenshot with Safari with stylesheet set"   /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-safari-without.png" alt="example screenshot with Safari with stylesheet set"  /></td>
</tr>
<tr>
<th>Chrome 7.0+</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-chrome-with.png" alt="example screenshot with Chrome with stylesheet set" title="example-IE-without"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-chrome-without.png" alt="example screenshot with Chrome with stylesheet set" title="example-IE-without"  /></td>
</tr>
<tr>
<th>Opera 10.63+</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-opera-with.png" alt="example screenshot with Opera with stylesheet set"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/example-opera-without.png" alt="example screenshot with Opera with stylesheet set"  /></td>
</tr>
</tbody>
</table>
<p><a class="exampleLink" href="http://www.useragentman.com/shared/css/ruby/screen.css">Download the stylesheet used in the examples on this page</a></p>
<p>I took George&#8217;s <strong>excellent</strong> work and added a few additional features:</p>
<ul>
<li>It tells IE to ignore the Firefox and Opera styles (since they don&#8217;t look so good in IE)</li>
<li>It makes the font size smaller in Chrome and Safari (a personal preference).</li>
<li>It sets the <code>&lt;ruby&gt;</code> tag&#8217;s <code>ruby-align</code> CSS property to <code>center</code>, so that IE mimics the way the WebKit browser display ruby text by default (IE&#8217;s default seems to be <code>distribute-letter</code>, which looks horrible in a lot of situations).</li>
</ul>
<p>Also note that without the stylesheet, the ruby text gracefully degrades in Firefox and Opera, so it is still readable, and illustrates the usefulness of the <code>&lt;rp&gt;</code> tags.  This stylesheet occasionally cause some unusual rendering in some older browsers (such as Safari 4.0 for Mac), but on the whole it does a pretty good job.</p>
<p>Note that in order to make the stylesheet set to work correctly, you must replace the <code>&lt;body&gt;</code> tag with this variation of <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">Paul Irish&#8217;s Conditional CSS design pattern</a>:</p>
<blockquote class="code">
<pre>
&lt;!--[if lt IE 7 ]&gt; &lt;body class="ie6"&gt; &lt;![endif]--&gt;
&lt;!--[if IE 7 ]&gt;    &lt;body class="ie7"&gt; &lt;![endif]--&gt;
&lt;!--[if IE 8 ]&gt;    &lt;body class="ie8"&gt; &lt;![endif]--&gt;
&lt;!--[if IE 9 ]&gt;    &lt;body class="ie9"&gt; &lt;![endif]--&gt;
&lt;!--[if (gt IE 9)]&gt;&lt;body class="modern"&gt; &lt;![endif]--&gt;
&lt;!--[!(IE)]&gt;&lt;!--&gt;  &lt;body class="notIE modern"&gt; &lt;!--&lt;![endif]--&gt;
</pre>
</blockquote>
<p>Using this declaration of the <code>&lt;body&gt;</code> blocks the Firefox and Opera styles in IE.</p>
<h2>Advanced Ruby Annotations</h2>
<p>Using the stylesheet, it is possible to also <strong>break ruby text into parts (e.g. syllables) without using a separate <code>&lt;ruby&gt;</code> tag for each part</strong>.  This is done with the <code>&lt;rbc&gt;</code> (ruby base container) and <code>&lt;rtc&gt;</code> (ruby text container).  Here is an example:</p>
<div class="rubyExample">
His <ruby class="syllables unicodeRubyText"><rbc><rb>com</rb><rb>mu</rb><rb>ni</rb><rb>ca</rb><rb>tion </rb></rbc><rp> (</rp><rtc><rt >k&#601;m</rt><rt>myoo</rt><rt>n&#301;</rt><rt><strong>k&#257;&#180;</strong></rt><rt  >sh&#601;n</rt></rtc><rp>) </rp></ruby> skills are quite bad.
</div>
<p>Although Internet Explorer does not understand these new tags, it does degrade gracefully.  Here is a comparison of how IE renders the above and how Firefox does.</p>
<table class="dataTable">
<thead>
<tr>
<th>Firefox 3.6</th>
<th>Internet Explorer 6+</th>
</tr>
</thead>
<tbody>
<tr>
<td style="width: 50%"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/containerFirefox.png" alt="[Screenshot of rbc/rtc tag example in Firefox]"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/containerExplorer.png" alt="[Screenshot of rbc/rtc tag example in IE]"  /></td>
</tr>
</tbody>
</table>
<p>Here is the code that generated the example above.  </p>
<blockquote class="code">
<pre>
&lt;ruby class="syllables unicodeRubyText"&gt;
<span class="hilite">  &lt;rbc&gt;
    &lt;rb&gt;com&lt;/rb&gt;&lt;rb&gt;mu&lt;/rb&gt;&lt;rb&gt;ni&lt;/rb&gt;&lt;rb&gt;ca&lt;/rb&gt;&lt;rb&gt;tion &lt;/rb&gt;
  &lt;/rbc&gt;</span>
  &lt;rp&gt; (&lt;/rp&gt;
<span class="hilite">  &lt;rtc&gt;
    &lt;rt&gt;k&#601;m&lt;/rt&gt;&lt;rt&gt;myoo&lt;/rt&gt;&lt;rt&gt;n&#301;&lt;/rt&gt;&lt;rt&gt;&lt;strong&gt;k&#257;&lt;/strong&gt;&lt;/rt&gt;&lt;rt&gt;sh&#601;n&lt;/rt&gt;
  &lt;/rtc&gt;</span>
  &lt;rp&gt;) &lt;/rp&gt;
&lt;/ruby&gt;
</pre>
</blockquote>
<p>Note that the <code>&lt;ruby&gt;</code> tag is a member of the classes <code>syllables</code> and <code>unicodeRubyText</code>, which are defined in the stylesheet.  The <code>syllables</code> class tells the browser to separate the ruby base text into syllables, separated by the <a href="http://en.wikipedia.org/wiki/Middot">&#8220;Interpunct&#8221;</a> symbol, while the <code>unicodeRubyText</code> tells the browser to render the ruby text with a Unicode font, so that the pronunciation symbols are printed correctly (it seems that this is only a requirement in Explorer, since the other browsers handle this automatically).</p>
<p>Here is a rundown of these advanced tags:</p>
<table class="dataTable">
<thead>
<tr>
<th>Tag</th>
<th>Name</th>
<th>Function</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>&lt;rbc&gt;</code>
</td>
<td>Ruby Base Container</td>
<td>Contains a list of <code>&lt;rb&gt;</code> tags.  This list is usually separated into syllables or some other logical order to make the text easier to read.</td>
</tr>
<tr>
<td>
<code>&lt;rtc&gt;</code>
</td>
<td>Ruby Text Container</td>
<td>Contains a list of <code>&lt;rt&gt;</code> tags.  Each <code>&lt;rt&gt;</code> tag in this list corresponds to the respective <code>&lt;rb&gt;</code> tag in the <code>&lt;rtc&gt;</code> list.</td>
</tr>
</tbody>
</table>
</blockquote>
<p>Unfortunately, there is a bug in older WebKit browsers that gives very strange results. Here are screen shots of the above code as viewed in Chrome 7.0 for Windows, with and without my stylesheet:</p>
<table class="dataTable">
<thead>
<tr>
<th>Chrome 7.0 Windows (with stylesheet) </th>
<th>Chrome 7.0 Windows (without stylesheet) </th>
</tr>
</thead>
<tbody>
<tr>
<td style="width: 50%"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/containerChromeWithStylesheet.png" alt="[Screenshot of rbc/rtc tag example in Chrome 7.0 With My Stylesheet]"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/10/containerChromeWithoutStylesheet.png" alt="[Screenshot of rbc/rtc tag example in Chrome 7.0 Without My Stylesheet]"  /></td>
</tr>
</tbody>
</table>
<p>This bug appears in Safari 4.x and lower and the current version of Chrome (7.0), for both Windows and Mac.  Since this has been fixed in Safari 5.0, I am assuming that this will be fixed in the next version of Chrome as well.</p>
<h2>Ruby CSS3 Properties</h2>
<p>There are three main CSS3 properties that can be used today &#8230; but in Internet Explorer only.  Here are a list of them, along with additional properties that the <a href="http://www.w3.org/TR/2001/WD-css3-ruby-20010216/">W3C put in their recommendation back in 2001</a>.</p>
<table class="dataTable">
<thead>
<tr>
<th>Property Name</th>
<th>Description</th>
<th>Support</th>
<th>More Info</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>ruby-align</code></td>
<td>Affects the horizontal alignment of the Ruby Text with respect to the ruby base.   Default value is <code>auto</code> (which is the same as <code>center</code>).  Other values are <code>left</code>, <code>right</code>, as well as <code>distribute-letter</code>, <code>distribute-space</code>, <code>line-edge</code>, <code>start</code> and <code>end</code>.</td>
<td><code>left</code>, <code>right</code>, as well as <code>distribute-letter</code>, <code>distribute-space</code>, <code>line-edge</code> work in IE5+.</td>
<td style="white-space: nowrap">
<ul>
<li><a href="http://www.w3.org/International/articles/ruby/#Slide0210">W3C Reference</a>
<li><a href="http://msdn.microsoft.com/en-us/library/ms531150%28VS.85%29.aspx">MSDN</a></li>
<li><a href="http://www.blooberry.com/indexdot/css/properties/intl/ralign.htm">Index  DOT  Css</a></li>
</ul>
</td>
</tr>
<tr>
<td><code>ruby-overhang</code></td>
<td>
Affects how the ruby text will &#8220;hang&#8221; over the ruby base if the ruby-text is wider than the ruby-base.  Valid values are <code>auto</code>, <code>none</code>, <code>whitespace</code>, <code>start</code> and <code>end</code>.</td>
<td><code>auto</code>, <code>none</code> and <code>whitespace</code> work in IE 5+</td>
<td>
<ul>
<li><a href="http://www.w3.org/International/articles/ruby/#Slide0260">W3C Reference</a>
<li><a href="http://msdn.microsoft.com/en-us/library/ms531151%28VS.85%29.aspx">MSDN</a></li>
<li><a href="http://www.blooberry.com/indexdot/css/properties/intl/roverhang.htm">Index  DOT  Css</a></li>
</ul>
</tr>
<tr>
<td><code>ruby-position</code></td>
<td>Indicates where ruby text should appear relative to the base text.  Default is <code>before</code>. Other values are <code>after</code> (which makes it appear underneath the text), <code>inline</code>, <code>left</code> and <code>right</code>.</td</p>
<td>Only <code>above</code> and <code>inline</code> work in IE5+</td>
<td>
<ul>
<li><a href="http://www.w3.org/International/articles/ruby/#Slide0180">W3C Reference</a>
<li><a href="http://msdn.microsoft.com/en-us/library/ms531152(VS.85).aspx">MSDN</a></li>
<li><a href="http://www.blooberry.com/indexdot/css/properties/intl/rposition.htm">Index  DOT  Css</a></li>
</ul>
</tr>
</tbody>
</table>
<p>Hopefully the other browsers will support these eventually.</p>
<h2>And So, In Conclusion &#8230;</h2>
<p>Here is a quick recap of the various things you should keep in mind when using Ruby Text:</p>
<ul>
<li>Firefox 3.6 and Opera 10.x need the stylesheet in order to show ruby text correctly.</li>
<li>Recent versions of Safari and Chrome don&#8217;t need it, but using the stylesheet won&#8217;t harm the display of simple ruby text.</li>
<li>IE doesn&#8217;t need the styleheet, but if you use the stylesheet to ensure cross-browser display of ruby text, you must use the special body tag declaration above.</li>
<li><code>&lt;rbc&gt;</code> and <code>&lt;rtc&gt;</code> are not recognized in any version of IE, but they will degrade gracefully.</li>
<li>Ruby text inside of <code>&lt;rtc&gt;</code> tags doesn&#8217;t look right in Chrome 7 or Safari 4.  Since they do show up right in Safari 5, I assume/hope this will be fixed in the next version of Chrome.</li>
<li>The advanced CSS3 <code>ruby-</code> properties, such as <code>ruby-align</code>, <code>ruby-overhang</code> and <code>ruby-position</code> are only supported by IE5+.</li>
</ul>
<h2>Additional Reading</h2>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ff460533%28v=VS.85%29.aspx">[MS-RUBY]: Internet Explorer Ruby Annotation Standards Support Document</a> from the <a href="http://msdn.microsoft.com/">MSDN Web Site</a>.
<li><a href="http://webkit.org/blog/948/ruby-rendering-in-webkit/">Ruby Rendering in WebKit</a> from the <a href="http://webkit.org/blog/">Surfin’ Safari</a> Blog archive
<li><a href="http://www.w3.org/TR/css3-ruby/">The W3C Recommendation document for Ruby Annotations</a>, dated 31 May 2001 with corrections made on 25 June 2008</a></li>
<li><a href="http://www.w3.org/TR/2001/WD-css3-ruby-20010216/">The W3C CSS3 Rub Module Working Draft</a> dated 14 May 2003.</a>.  There is also <a href="http://dev.w3.org/csswg/css3-ruby/">an editor&#8217;s copy</a> dated 04 March 2010.</li>
<li><a href="http://princecss.com/bb/viewtopic.php?f=5&#038;t=81">XHTML Ruby in Prince</a>, the forum thread where the original stylesheet was developerd.  Great to see as a reference.</li>
</ul>
<p><a class="exampleLink" href="http://www.useragentman.com/shared/css/ruby/screen.css">Download the stylesheet used in the examples on this page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2010/10/29/cross-browser-html5-ruby-annotations-using-css/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Coding Colors Easily Using CSS3 hsl() Notation</title>
		<link>http://www.useragentman.com/blog/2010/08/28/coding-colors-easily-using-css3-hsl-notation/</link>
		<comments>http://www.useragentman.com/blog/2010/08/28/coding-colors-easily-using-css3-hsl-notation/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 12:11:59 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Color]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[hsl/hsla]]></category>
		<category><![CDATA[Polyfills]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=1443</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2010/08/colorWheelFront.png" /> The seemingly impossible task of coming up with color codes off the top of your head can be done easily using CSS3's <code>hsl</code> color notation.  Read how you can use this "human-friendly" and how it can work in the few browsers that don't support it natively.]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Update: Jan 6, 2011</h3>
<p>Check out Paul Irish&#8217;s <a href="http://mothereffinghsl.com/">Mother Effing HSL</a> for a nice color-picker you can play with to get the hang of HSL.</p>
</div>
<div >
<dl id="attachment_822" class="wp-caption alignleft" style="width: 267px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-822 " title="CSS3 Cube Layout Example" src="http://www.useragentman.com/blog/wp-content/uploads/2010/08/colorWheel.jpg" alt="" width="257" /></dt>
<dd class="wp-caption-dd">
<div>A remix of <a href="http://commons.wikimedia.org/wiki/File:Bezold_Farbentafel_1874.jpg">Wilhelm von Bezold&#8217;s Farbentafel Color Wheel</a>.</div>
</dd>
</dl>
</div>
<p>I have heard stories about <strong>&#8220;<em>those</em> people&#8221;</strong> that see a color and can immediately calculate the RGB hex code in their head, without any tool whatsoever. Since I have never actually met one of <strong>&#8220;<em>those</em> people&#8221;</strong>, I don&#8217;t think they really exist.  However, it <strong>would</strong> be a nice skill to have, especially when presenting a new design to a client and they say &#8220;Perfect!  But can make that box a brighter orange, and that do-hickey a less pronounced purple?  And can you show us how it would look <strong>right now?</strong>&#8221;   </p>
<p>This seemingly impossible task of coming up with color codes off the top of your head can be done using CSS3&#8242;s <code>hsl</code> color notation.  <strong>HSL is a much more &#8220;human-friendly&#8221; notation than RGB</strong>, and with it you can code colors in your head easily <strong>without using The GIMP&#8217;s or Photoshop&#8217;s color-wheel</strong>.</p>
<p>Don&#8217;t believe me?  Read on and I&#8217;ll show you.  You&#8217;ll never want to go back to RGB again.  And even though IE 6-8 doesn&#8217;t support HSL natively, we will cover how support can be added.</p>
<h2>Notation</h2>
<p>An HSL color code uses the following CSS3 notation:</p>
<blockquote class="code"><pre>#myObject {
    background: <span class="hilite">hsl(120, 50%, 50%);</span>
}
</pre>
</blockquote>
<p>The first number is the <strong>hue</strong>, the second number is the <strong>saturation</strong>, and the third is the <strong>lightness</strong>.  These three terms are what HSL stand for.  But how does one manipulate these numbers?  Easily.</p>
<h2>Step 1: &#8220;Young Guys Can Be Messy Rascals&#8221;</h2>
<div id="colorwheel">
<div class="testBlock"  id="o1">
				<span><strong>R</strong>ed: 360&deg;</span>
			</div>
<div class="testBlock"  id="o2">
				<span><strong>Y</strong>ellow: 60&deg;</span>
			</div>
<div class="testBlock"  id="o3">
				<span><strong>G</strong>reen: 120&deg;</span>
			</div>
<div class="testBlock"  id="o4">
				<span><strong>C</strong>yan: 180&deg;</span>
			</div>
<div class="testBlock"  id="o5">
				<span><strong>B</strong>lue: 240&deg;</span>
			</div>
<div class="testBlock"  id="o6">
				<span><strong>M</strong>agenta: 300&deg;</span>
			</div>
<p>This diagram is not an image.  It was generated with HTML using <a href="/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/">CSS3 <code>transform</code> functions</a> and <code>hsl()</code> color notation, and cssSandpaper for browsers that don&#8217;t support it.</p>
</p></div>
<p><strong>Memorize this sentence.</strong>  If you do, you will be to remember the six major colors in the HSV color wheel: Yellow, Green, Cyan, Blue, Magenta and Red.  <strong>These colors are spaced out by angles of 60 degrees.</strong>  If you follow the mnemonic, you should be able to remember the diagram on the left very easily.</p>
<p>So, if you want to pick green, you would code:</p>
<blockquote class="code smaller"><pre>hsl(<span class="hilite">120</span>, 100%, 50%)</pre>
</blockquote>
<p>(Don&#8217;t worry about the second and third parameters for now &#8230; we will get to that in a second).</p>
<p>Blue would be:</p>
<blockquote class="code smaller"><pre>hsl(<span class="hilite">240</span>, 100%, 50%)</pre>
</blockquote>
<p>Let&#8217;s say you wanted a color that is not on the wheel, like purple.  Purple is halfway between blue (240&deg;) and magenta (300&deg;) so we should pick something in between:</p>
<div class="example purple">background-color: hsl(270, 100%, 50%)</div>
<p>Think it should be more blue?  Choose an angle closer to blue!</p>
<div class="example bluePurple">background-color: hsl(255, 100%, 50%);</div>
<p>Want more magenta instead?  Then choose angle closer to magenta:</p>
<div class="example magentaPurple">background-color: hsl(285, 100%, 50%);</div>
<p>Note that you do not put use the <code>deg</code> keyword link in CSS3 Transforms.  It seems a little inconsistent, but at least it&#8217;s less typing. </p>
<h2>Step 2: Choose Your Intensity</h2>
<p>The second parameter is the colorfulness, or <a href="http://en.wikipedia.org/wiki/Colorfulness">saturation</a>.  The larger the percentage, the more &#8220;colorful&#8221; this color is.  Let&#8217;s take a look at what happens when we change green&#8217;s (120&deg;) colorfulness:</p>
<table id="colorfulnessTable" class="dataTable">
<thead>
<tr>
<th>hsl(120, 0%, 50%)</th>
<th>hsl(120, 25%, 50%)</th>
<th>hsl(120, 50%, 50%)</th>
<th>hsl(120, 75%, 50%)</th>
<th>hsl(120, 100%, 50%)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="c1"></td>
<td class="c2"></td>
<td class="c3"></td>
<td class="c4"></td>
<td class="c5"></td>
</tr>
</table>
<p>The more the saturation percentage, the less &#8220;gray&#8221; it is.</p>
<h2>Step 3: Lighten it up</h2>
<p>The final step is to lighten up the color to the right level.  That can be done with the final parameter: </p>
<table id="brightnessTable" class="dataTable">
<thead>
<tr>
<th>hsl(120, 50%, 0%)</th>
<th>hsl(120, 50%, 25%)</th>
<th>hsl(120, 50%, 50%)</th>
<th>hsl(120, 50%, 75%)</th>
<th>hsl(120, 50%, 100%)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="c1"></td>
<td class="c2"></td>
<td class="c3"></td>
<td class="c4"></td>
<td class="c5"></td>
</tr>
</table>
<h2>That&#8217;s It!</h2>
<p>Try it when you are using color on your next project.  <strong>You&#8217;ll find using the HSL color-space is <em>much</em> easier than using RGB</strong></p>
<h2>Browser Support</h2>
<p>HSL is supported in almost all the major browsers: Firefox 3.0+, Safari 3.0+, Chrome 5.0+, Opera 10+ and Explorer 9.0+.  <strong>For the browsers that don&#8217;t support it, I have updated <a href="/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/">cssSandpaper</a> to implement HSL with the CSS <code>color</code> property</strong>, as well as the <code>border</code>, <code>background</code> family of properties (i.e. <code>border-right</code>, <code>background-color</code>, etc).</p>
<p>Also supported by cssSandpaper is HSLA, which is to HSL, as RGBA is to RGB.  It contains a fourth element, the alpha channel, that is a number from 0 to 1.  To illustrate how this works, let&#8217;s say an HTML element has a grid as a background image.  How can you shade that background image so that it looks, say, more green?</p>
<table id="alphaTable" class="dataTable">
<thead>
<tr>
<th>hsla(120, 50%, 50%, 0.25)</th>
<th>hsla(120, 50%, 50%, 0.5)</th>
<th>hsla(120, 50%, 50%, 0.75)</th>
<th>hsla(120, 50%, 50%, 1)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="c2"></td>
<td class="c3"></td>
<td class="c4"></td>
<td class="c5"></td>
</tr>
</table>
<p>The table above is not an image &mdash; it is a real example of <code>hsla()</code> in action. Pretty neat, huh?  You can also use HSL and HSLA color in gradients.  The <a href="/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/">cssSandpaper</a> library has supported WebKit style gradients with it&#8217;s own <code>-sand-gradient</code> property.  Now it supports HSLA gradients, like this 80% opaque yellow to 20% opaque blue linear gradient:</p>
<table id="gradientTable" class="dataTable">
<thead>
<tr>
<th>	-sand-gradient(linear, center top, center bottom, from(hsla(60, 100%, 50%, 0.8)), to(hsla(255, 100%, 50%, 0.2)));
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="c1"></td>
</tr>
</tbody>
</table>
<p>Unfortunately, cssSandpaper only supports HSLA for background coloring only, not border or text coloring, but one would just use progressive enhancement to take care of that edge case, since what it does support, in my humble opinion, is rather cool.  Download the latest version from the link below and use HSL and HSLA color notation now!  You&#8217;ll impress your developer friends with your off-the-top-of-your-head color-coding skillz.  :-)</p>
<p><a class="exampleLink" href="/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/">Get the latest version of cssSandpaper from the official documentation page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2010/08/28/coding-colors-easily-using-css3-hsl-notation/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Creating Cross Browser HTML5 Forms Now, Using modernizr, webforms2 and html5Widgets</title>
		<link>http://www.useragentman.com/blog/2010/07/27/cross-browser-html5-forms-using-modernizr-webforms2-and-html5widgets/</link>
		<comments>http://www.useragentman.com/blog/2010/07/27/cross-browser-html5-forms-using-modernizr-webforms2-and-html5widgets/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 03:50:06 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Forms]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Polyfills]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=1110</guid>
		<description><![CDATA[<img src="/blog/wp-content/uploads/2010/07/html5Calendar.png" />Next generation web forms using HTML5 is hard to do today due to spotty browser support.  I demonstrate how a suite of JavaScript libraries can be used to help us use HTML5 Forms <strong>today</strong>.]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Updates:</h3>
<ul>
<li><strong>Sept. 10, 2010:</strong> This webforms2 script in the link below has been modified to fix validation issues with the newer versions of Safari and Chrome.</li>
<li><strong>Aug. 6, 2010:</strong> This article has been <a href="http://nz.pe.kr/wordpress/?p=547">translated into Korean</a>.</li>
<li><strong>May 12, 2011:</strong> html5Widgets has been <a href="http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/">updated to support the <code>oninput</code> event</a>. </li>
</ul>
</div>
<div class="wp-caption alignright" style="width: 298px; border: solid 3px black;">
<div class="size-full wp-image-1387" style="width: 288px">
<form action="javascript:void(0)">
<table class="html5ExampleTable">
<tr>
<th>Range:</th>
<td>
<input type="range" /></td>
</tr>
<tr>
<th>Placeholder:</th>
<td>
<input type="text" placeholder="This is a test" /></td>
</tr>
<tr>
<th>Color:</th>
<td>
<input type="color" /></td>
</tr>
</table>
</form>
</div>
<p class="wp-caption-text" style="width: 288px;">Working example HTML5 Form using <a href="http://www.modernizr.com">Modernizr</a>, <a href="https://github.com/westonruter/webforms2">webforms2</a> and my new script, html5Widgets.  Go ahead &#8230; try them out.  You know you wanna!</p>
</div>
<p>Calendars, colour swatches, sliding widgets, client side validation: this is the nirvana that the HTML5 forms module promises. Some would say &#8220;So what? I&#8217;ve seen this on the web for years!&#8221;, and they&#8217;d be right. There have been some really brilliant people coding some really interesting widget and validation frameworks, so why should we change?</p>
<ul>
<li><strong>Ease the markup learning curve:</strong> HTML5 form widgets and validation have been built to be as dead simple to markup as a select box with no JavaScript knowledge required</li>
<li><strong>It&#8217;s a W3C standard:</strong> so you know that it&#8217;ll work for years to come and if you have problems, you could always ask almost anyone in the web development community for help.</li>
<li><strong>Cellular phone support:</strong> HTML5 form fields will have optimized user interfaces appropriate for the type of device.  <a href="http://devblog.blackberry.com/2010/03/use-html5-in-your-blackberry-web-content/">Blackberry already has optimized versions of the date/time and color widgets</a> and, according to <a href="http://diveintohtml5.org/">Mark Pilgrim&#8217;s</a> article <a href="http://diveintohtml5.org/forms.html">A Form of Madness</a>, the virtual keyboards that appear when using HTML5 form fields are optimized for the data being input.</li>
<li><strong>Web development tools will have to support it:</strong> It&#8217;s a safe bet that Aptana, Dreamweaver, and all the other IDEs out there will have HTML5 support.</li>
<li><strong>It&#8217;s HTML5:</strong> when you tell your non-techie co-workers that you use it, you will be the envy of all &mdash; after all, it <strong>must</strong> be five times better than regular HTML, right?  Your boss will be so impressed that you are now a guru in this futuristic technology with a cool numbered acronym that he or she will give you a big fat raise!!!
<p>(Okay, okay.  Don&#8217;t try to laugh too hard &#8230; your co-workers will start to worry).</li>
</ul>
<h2>The Support Dilemma</h2>
<p>Unfortunately, today&#8217;s support for the HTML5 Form Module is spotty with each browser supporting different parts of the specification.  Take a look at Wikipedia&#8217;s<a href="http://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28HTML5%29"> HTML5 Forms comparison chart</a>.  You&#8217;ll see each browser supporting a different set of features, but the lowest common denominator they all support is rather small.</p>
<h2>But I Want To Use It <strong>Now!!!</strong></h2>
<p>HTML5 Forms started off as <a href="http://www.whatwg.org/specs/web-forms/2004-06-27-call-for-comments/">WebForms 2.0 back in 2004</a>, so I wasn&#8217;t surprised to see that a few developers had already coded some JavaScript implementations.  Weston Ruter&#8217;s cross browser library, <code>webforms2.js</code>, implements a huge chunk of it, including parts that didn&#8217;t make the transition from WebForms 2.0 to HTML5 forms (e.g. <a href="http://www.whatwg.org/specs/web-forms/current-work/#repeatingFormControls">Webform 2.0&#8242;s Repetition Model</a>).</p>
<p>Since widgets weren&#8217;t implemented in <code>webforms2</code>, I created <code>html5Widgets.js</code>.  This interface library is independent of <code>webforms2</code> &#8211; if all you want is a cross-browser HTML5 form with validation, then all you need is the original <code>webforms2.js</code>.  If you want special widgets that are not available for all browsers, include <code>html5Widgets.js</code>.  Since I did not want to re-invent the wheel by creating widgets from scratch, <code>html5Widgets.js</code> uses some really nice third party JavaScript libraries to create them (more on that below).  It also uses <code><a href="http://www.modernizr.com">Modernizr</a></code> to detect if there is native support for each of the HTML5 form widgets &#8211; if not, <code>html5Widgets</code> steps in to put the right widget in place.  To save bandwidth, developers only need to include the third party libraries for the widgets they need.</p>
<p>In the rest of this article, I will go over different parts of the HTML5 specification and show how you can use them in your applications today, step-by-step.  Each section will state which browser natively supports that part of the specification, and what is needed for browsers that don&#8217;t.  Eventually, when the browser manufacturers catch up with the standard, you won&#8217;t need to use any JavaScript at all.</p>
<h2>Form Validation Using the <code>required</code> and <code>pattern</code> Attributes</h2>
<p>The <code>required</code> attribute makes an input field mandatory and forces the user to enter in a value in order to submit the form data.  The markup is simple</p>
<blockquote class="code">
<pre>&lt;input type="text" name="firstName" value="" required="required" /&gt;
</pre>
</blockquote>
<p>(<strong>Note:</strong>, you can also just use <code>required</code> on its own if you aren&#8217;t trying to be XHTML compliant.)</p>
<p>The <code>pattern</code> attribute forces the user to enter in a value using a specified format.  It uses <a href="http://en.wikipedia.org/wiki/Regular_expressions">regular expressions</a> to define this format. For example, if you want to force the user to input a U.S. Zip Code inside a form field, you would use the following markup.</p>
<blockquote class="code">
<pre>&lt;--
     zip code regular expression from
     <a href="http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256F6B005294C2">http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256F6B005294C2</a>
--&gt;
&lt;input type="text" name="zipCode" value=""
   pattern="\d{5}([\-]\d{4})?" required="required"  /&gt;
</pre>
</blockquote>
<p>Note that <code>required</code> and <code>pattern</code> are independent from each other.  You can have a <code>pattern</code> set on a form field without it being <code>mandatory</code>  (i.e. the pattern would only be checked if the user enters in data into the field).</p>
<p>Opera 10+ (mobile and desktop editions) is the only browser that supports the validation routines natively.  To use this in all other browsers, all you need is to include the following script tags in the <code>head</code> of your document.</p>
<blockquote class="code">
<pre>&lt;script type="text/javascript" src="/path/to/archive/js/weston.ruter.net/webforms2/webforms2_src.js"&gt;
&lt;/script&gt;
</pre>
</blockquote>
<p>Let&#8217;s take a look at how this looks visually:</p>
<table class="screenshots">
<thead>
<tr>
<th>Opera 10+ Windows</th>
<th>Firefox 3.6 with webforms2.js</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href="/tests/html5Widgets/patternRequired.html"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/07/validityOpera.png" alt="[Screenshot of HTML5 Validation using Opera]" title="Screenshot of HTML5 Validation using Opera"  class="alignnone size-full wp-image-1282" /></a>
</td>
<td>
<a href="/tests/html5Widgets/patternRequired.html"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/07/validityFirefoxWithHTML5Widgets.png" alt="[Screenshot of HTML5 Validation using Firefox and webforms2.js]" title="Screenshot of HTML5 Validation using Firefox and webforms2.js"  class="alignnone size-full wp-image-1282" /></a>
</td>
</tr>
</tbody>
</table>
<p>Note the &#8220;starred&#8221; style of the form field &mdash; this is not the default look and feel of the <code>required</code> fields, but something I added with a simple amount of CSS:</p>
<blockquote class="code">
<pre>input[required], select[required] {
	background: #ffffee url("../images/asterix.gif")  no-repeat left 2px;
	padding-left: 1.5em;
	width: 13.5em !important;
}
</pre>
</blockquote>
<p>(<strong>This CSS does <em>not</em> work in Internet Explorer 6.</strong>  Given that <strong>everything else in this article does</strong>, I hope the reader will overlook this one oversight considering that this browser should have entered retirement years ago (and have its driving license taken away, and shipped off to some really horrible nursing home watching really crappy talk shows all day and eating bad food &#8230;)</p>
<p><a class="exampleLink" href="/tests/html5Widgets/patternRequired.html">See an example of <code>pattern</code> and <code>required</code> in action.</a></p>
<p>Note that the same validation framework checks the values of inputs of type <code>email</code>, <code>url</code> and <code>number</code> to ensure that the values are in their respective valid formats.  As an added bonus, if you are using the iPhone or iPad version of Safari, the virtual keyboard that appears will be optimized for these type of form fields (e.g. when editing a <code>number</code> field, the keyboard that appears contains only digits and the &#8220;+&#8221;, &#8220;-&#8221;, and &#8220;.&#8221; keys.  This is native behaviour for iOS, and I hope other mobile browsers, such the Android&#8217;s, follow suit.</p>
<h2>The <code>autofocus</code> Attribute</h2>
<p>The <code>autofocus</code> attribute allows developers to choose which element has focus when the page is loaded.  The Google front page has done this via JavaScript, and now, 12 years later, there is finally an HTML attribute to easily handle this.</p>
<blockquote class="code">
<pre>&lt;input type="text" name="fullName" value=""
  required="required" autofocus="autofocus" /&gt;
</pre>
</blockquote>
<p>Safari, Chrome and Opera support it natively.  To make it work in other browsers, include the <code>webforms2.js</code> library, as we did in the <code>required</code> and  <code>pattern</code> examples.</p>
<p><a class="exampleLink" href="/tests/html5Widgets/autofocus.html">See an example of <code>autofocus</code> in action</a></p>
<h2>The <code>placeholder</code> Attribute</h2>
<p>A placeholder is a great visual cue to communicate any special information about a field (e.g. a description<br />
of the data to be input, if the field is required, etc). </p>
<p><div id="attachment_1317" class="wp-caption aligncenter" style="width: 397px"><a href="/tests/html5Widgets/placeholder.html"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/07/placeholder.png" alt="An example of placeholder text.  The text disappears when the field has focus or if the user types information into the field." title="placeholder" width="387" height="94" class="size-full wp-image-1317" /></a><p class="wp-caption-text">An example of placeholder text.  The text disappears when the field has focus or if the user types information into the field.</p></div></p>
<p>Syntax is simple:</p>
<blockquote class="code">
<pre>&lt;input type="text" name="fullName" value="" required="required"
   placeholder="Required information" /&gt;
</pre>
</blockquote>
<p>Safari, Chrome and Firefox support this attribute natively.  To make it work in other browsers, it is necessary to load the html5Widgets library, with the necessary supporting libraries:</p>
<blockquote class="code">
<pre>&lt;script type="text/javascript"
   src="/path/to/shared/js/modernizr.com/modernizr-1.5.min.js"&gt;
&lt;/script&gt;

&lt;script type="text/javascript" src="/path/to/shared/js/EventHelpers.js"&gt;
&lt;/script&gt;

&lt;script type="text/javascript" src="/path/to/shared/js/html5Widgets.js"&gt;
&lt;/script&gt;
</pre>
</blockquote>
<p>What do these libraries do?</p>
<ul>
<li><a href="http://modernizr.com"><code>modernizr</code></a> is used to detect which HTML5 attributes and tags are supported by the users&#8217; browser</li>
<li><code>html5Widgets</code> is what actually does the placeholder logic, with <code>EventHelpers.js</code> providing cross-browser event-handling routines.</li>
</ul>
<p><a class="exampleLink" href="/tests/html5Widgets/placeholder.html">See an example of the HTML5 <code>placeholder</code><br />
tag in action.</a></p>
<h2>The <code>range</code> Input Type and <code>output</code> Tag</h2>
<p>Easily my favourite of the HTML5 widgets, <code>range</code> gives developers a sliding control to put inside their forms.  </p>
<p>The syntax is simple:</p>
<blockquote class="code">
<pre>&lt;input type="range"  name="rangeEl" value="" min="0" max="150" step="1" /&gt;
</pre>
</blockquote>
<p>The <code>min</code> and <code>max</code> attributes contain the minimum and maximum values, and <code>step</code> denotes by what increments the range slider increments by when moved.  Note that you can use these attributes with the <code>number</code> input type as well, but instead of having the fancy interface, it will use the validation engine to ensure the value follows what these attributes dictate.</p>
<p>At the time of this writing, Opera and WebKit based browsers (like Safari and Chrome), support it natively, and html5Widgets uses <a href="http://www.frequency-decoder.com/demo/slider-revisited/">the Frequency Decoder Slider Widget</a> to implement it in unsupported browsers.  To ensure cross-browser HTML5 range element goodness, place the following script tags in your document:</p>
<blockquote class="code">
<pre>&lt;!-- Needed for Range Element --&gt;
&lt;link type="text/css" rel="stylesheet" href="/path/to/shared/css/slider.css"&gt;

&lt;!--[if lte IE 6]&gt;
&lt;link type="text/css" rel="stylesheet" href="/path/to/shared/css/slider_ie.css" /&gt;
&lt;![endif]--&gt;

&lt;script type="text/javascript" src="/path/to/shared/js/frequency-decoder.com/slider.js"&gt;
&lt;/script&gt;

&lt;!-- Needed for Validation --&gt;
&lt;script type="text/javascript" src="/path/to/shared/js/weston.ruter.net/webforms2/webforms2_src.js"&gt;
&lt;/script&gt;

&lt;!-- Need for HTML5Widgets --&gt;
&lt;script type="text/javascript"
  src="/path/to/shared/js/modernizr.com/modernizr-1.5.min.js"&gt;
&lt;/script&gt;

&lt;script type="text/javascript" src="/path/to/shared/js/html5.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/shared/js/EventHelpers.js"&gt;
&lt;/script&gt;

&lt;script type="text/javascript" src="/path/to/shared/js/html5Widgets.js"&gt;
&lt;/script&gt;</pre>
</blockquote>
<p>Take a look at the screenshots below.  You will see that the way a <code>range</code> field varies among the browsers that natively support it, and even in some of the browsers that use html5Widgets:</p>
<table class="screenshots">
<thead>
<tr>
<th></th>
<th>Explorer 6.x+<br />
(html5Widgets support)</th>
<th>Firefox 3.5+<br />
(html5Widgets support)</th>
<th>Safari 4.0+<br />
(native support)</th>
<th>Chrome 3.0+<br />
(native support)</th>
<th>Opera 10.0+<br />
(native support)</th>
</tr>
</thead>
<tbody>
<tr>
<th>Windows</th>
<td><a href="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeExplorerWindows.png"><img title="Screenshot of range field for Internet Explorer 6" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeExplorerWindows.png" alt="Screenshot of range field for Internet Explorer 6" width="120" height="68" /></a></td>
<td><img title="Screenshot of range field for Windows Firefox" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeFirefoxWindows.png" alt="Screenshot of range field for Windows Firefox" width="120" height="68" /></td>
<td><img title="Screenshot of range field for Windows Safari" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeSafariWindows.png" alt="Screenshot of range field for Windows Safari " width="120" height="68" /></td>
<td><img title="Screenshot of range field for Chrome Windows" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeChromeWindows.png" alt="Screenshot of range field for Chrome Windows" width="120" height="68" /></td>
<td><img title="Screenshot of range field for Windows Opera" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeOperaWindows.png" alt="Screenshot of range field for Windows Opera" width="120" height="68" /></td>
</tr>
<tr>
<th>Mac</th>
<td>Not Applicable</td>
<td><img title="Screenshot of range field for Mac Firefox" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeFirefoxMac.png" alt="Screenshot of range field for Mac Firefox" width="120" height="68" /></td>
<td><img title="Screenshot of range field for Mac Safari" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeSafariMac.png" alt="Screenshot of range field for Mac Safari " width="120" height="68" /></td>
<td><img title="Screenshot of range field for Chrome Mac" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeChromeMac.png" alt="Screenshot of range field for Chrome Mac" width="120" height="68" /></td>
<td><img title="Screenshot of range field for Mac Opera" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeOperaMac.png" alt="Screenshot of range field for Mac Opera" width="120" height="68" /></td>
</tr>
<tr>
<th>Linux</th>
<td>Not Applicable</td>
<td><img title="Screenshot of range field for Linux Firefox" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeFirefoxUbuntu.png" alt="Screenshot of range field for Linux Firefox" width="120" height="68" /></td>
<td>Not Applicable</td>
<td><img title="Screenshot of range field for Linux Chrome" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeChromeUbuntu.png" alt="Screenshot of range field for Linux Chrome" width="120" height="68" /></td>
<td><img title="Screenshot of range field for Linux Opera" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/rangeOperaUbuntu.png" alt="Screenshot of range field for Linux Opera" width="120" height="68" /></td>
</tr>
</tbody>
</table>
<p>The <code>output</code> tag can be used to show the value of a field, or the result of an operation performed on a number of fields, using JavaScript expressions.  Although the <code>output</code> tag may calculate fomulas referencing <em>any</em> form fields, it is useful especially for the <code>range</code> input type so users can see what value the range element is pointing to:</p>
<blockquote class="code">
<pre><span class="hilite">&lt;output onforminput="this.value = rangeEl.value"&gt;-&lt;/output&gt;</span>
&lt;input type="range"  name="rangeEl" value="" min="0" max="150" step="1" /&gt;
</pre>
</blockquote>
<p>The contents of the <code>output</code> tag is the default value.  Note the <code>this.value</code> syntax &#8211; I am not sure why the W3C HTML5 working group decided it was needed (why not just have the formula?), but it is.  If there are other types of expressions supported in the final specification, they are not supported by <code>html5Widgets</code> at this time.  Note that in order to apply CSS to the <code>output</code> tag in IE, it is necessary to use <a href="http://remysharp.com/2009/01/07/html5-enabling-script/">Remy Sharp&#8217;s HTML5 Enabling Script</a>.</p>
<p><a class="exampleLink" href="/tests/html5Widgets/range.html">See an example of the <code>range</code> input being used with the <code>output</code> tag.</a></p>
<p><a class="exampleLink" href="/tests/html5Widgets/output.html">See an example of the <code>output</code> tag being used <em>without</em> a <code>range</code> field.</a></p>
<div class="importantNotes">
<h3>Update (May 12. 2011):</h3>
<p>Since this article was written, the <code>onforminput</code> event has been deprecated in favor of the <code>oninput</code>.  I have updated html5Widgets to support <code>oninput</code>, and <a href="http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/">have written article about its <code>oninput</code> support</a>.  I encourage you to see the different between the above to examples and the <code>oninput</code> method of <a href="http://www.useragentman.com/examples/html5Widgets/tests/html5Widgets/range.html">using the <code>output</code> tag with <code>range</code></a> and <a href="http://www.useragentman.com/examples/html5Widgets/tests/html5Widgets/output.html">without <code>range</code></a>
</div>
<h2>The <code>datetime</code>, <code>datetime-local</code>, <code>date</code>, <code>week</code> and <code>week</code> Input Types</h2>
<p>At the time of this writing, Opera is the only desktop browser that supports HTML5 date fields.  To support the other browsers, html5Widgets uses a slightly modified version of <a href="http://www.dynarch.com/">DynArch.com</a>&#8216;s <a href="http://www.dynarch.com/projects/calendar/old/">Ex-&#8221;Coolest&#8221; DHTML Calendar</a> (I decided not to use <a href="http://www.dynarch.com/projects/calendar/">the coolest one</a> because the Ex-Coolest has a more permissive license and it works really well). Now all browsers can support the <code>datetime</code>, <code>datetime-local</code>, <code>date</code>, <code>month</code> and <code>week</code> input fields, and submit these values in a consistent format.</p>
<p>Here are the scripts needed for the browsers that need it:</p>
<blockquote class="code">
<pre>
&lt;!-- Needed for Date/Time Elements --&gt;
&lt;link type="text/css" rel="stylesheet" href="/path/to/shared/js/jscalendar-1.0/calendar-win2k-1.css" /&gt;
&lt;script type="text/javascript" src="/path/to/shared/js/jscalendar-1.0/calendar.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/shared/js/jscalendar-1.0/lang/calendar-en.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/shared/js/jscalendar-1.0/calendar-setup.js"&gt;&lt;/script&gt;

&lt;!-- Needed for Validation --&gt;
&lt;script type="text/javascript" src="/path/to/shared/js/weston.ruter.net/webforms2/webforms2_src.js"&gt;
&lt;/script&gt;

&lt;!-- What glues all the above together --&gt;

&lt;script type="text/javascript" src="/path/to/shared/js/modernizr.com/modernizr-1.5.min.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/shared/js/EventHelpers.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/shared/js/html5Widgets.js"&gt;
&lt;/script&gt;
</pre>
</blockquote>
<p>Note that the calendar widget uses language packs and that I am using the English one (<code>calendar-en.js</code>.  Other language packs are included.</p>
<p>Below is a comparison between Opera&#8217;s native date widget vs. the one provided by the DynArch/HTML5Widget combo:</p>
<table class="screenshots">
<thead>
<tr>
<th></th>
<th>DateTime Widget</th>
<th>Month Widget</th>
</tr>
<tr>
<th>Opera Windows</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/dateTimeOperaWindows.png" /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/monthOperaWindows.png" /></td>
</tr>
<tr>
<th>Opera Mac</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/dateTimeOperaMac.png" /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/monthOperaMac.png" /></td>
</tr>
<tr>
<th>Firefox 3.5+ Windows<br />
(html5Widgets support)</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/datetimeFirefoxWithHTML5Widgets.png" /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/monthFirefoxWithHTML5Widgets.png" /></td>
</tr>
</table>
<p>It looks like the native calendar for Opera for Mac is a smaller than the Windows version &#8211; hopefully this is just on my copy of the browser.</p>
<p>The display formats, and they values that they submit to the server, are pretty much the same</p>
<table class="screenshots">
<thead>
<tr>
<th>Input type</th>
<th>Format displayed on page</th>
<th>Format sent to server</th>
</tr>
</thead>
<tbody>
<tr>
<td>datetime</td>
<td><em>yyyy-mm-dd HH:MM</em></td>
<td><em>yyyy-mm-dd</em>T<em>HH:MM</em>Z</td>
</tr>
<tr>
<td>datetime-local</td>
<td><em>yyyy-mm-dd HH:MM</em></td>
<td><em>yyyy-mm-dd</em>T<em>HH:MM</em></td>
</tr>
<tr>
<td>date</td>
<td><em>yyyy-mm-dd</em></td>
<td><em>yyyy-mm-dd</em></td>
</tr>
<tr>
<td>month</td>
<td><em>yyyy-mm</em></td>
<td><em>yyyy-mm</em></td>
</tr>
<tr>
<td>week</td>
<td><em>yyyy-mm</em>W</td>
<td><em>yyyy-mm</em>W</td>
</tr>
</tbody>
</table>
<p><a class="exampleLink" href="/tests/html5Widgets/dateTime.html">See the HTML5 <code>date</code> widgets in action.</a></p>
<p><strong>Note:</strong> In this example, The Opera Mobile Windows Emulator incorrectly displays the <code>datetime</code> and <code>datetime-local</code> calendars in the upper left-hand corner of the screen, but <strong>not</strong> the other ones.  Since this is Opera&#8217;s own calendar widget, and not html5Widgets&#8217;, this bug will have to fixed by Opera.  </p>
<p><div id="attachment_1269" class="wp-caption aligncenter" style="width: 501px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2010/07/operaMobileDateTimeBug.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/07/operaMobileDateTimeBug.png" alt="Screenshot of Opera Mobile bug" title="operaMobileDateTimeBug" width="491" height="768" class="size-full wp-image-1269" /></a><p class="wp-caption-text">Screenshot of Opera Mobile bug</p></div></p>
<h2>The <code>color</code> Input Type</h2>
<p>Currently <strong>none</strong> of the desktop browser manufacturers support the <code>color</code> input type (although the new WebKit based <a href="http://devblog.blackberry.com/2010/03/use-html5-in-your-blackberry-web-content">Blackberry browser seems to have a neat implementation</a>). While we wait to see how the major browser manufacturers decide to implement <code>color</code>, you can use html5Widgets&#8217; implementation which uses <a href="http://www.softwareishard.com">Jan Odvarko</a>&#8216;s <a href="http://jscolor.com">jscolor</a>.  The script has been configured to allow only allow lower case hexadecimal rgb values to be entered, and that a blank value not be allowed, as per the W3C spec.</p>
<p>Here are the script tags needed to implement this in all browsers:</p>
<blockquote class="code"><pre>&lt;!-- Needed for Color Element --&gt;
&lt;script type="text/javascript" src="../../shared/js/jscolor/jscolor.js"&gt;
&lt;/script&gt;

&lt;!-- What glues all the above together --&gt;
&lt;script type="text/javascript" src="../../shared/js/modernizr.com/modernizr-1.5.min.js"&gt;
&lt;/script&gt;

&lt;script type="text/javascript" src="../../shared/js/EventHelpers.js"&gt;
&lt;/script&gt;

&lt;script type="text/javascript" src="../../shared/js/html5Widgets.js"&gt;
&lt;/script&gt;
</pre>
</blockquote>
<p>Below is a comparison between the Blackberry&#8217;s implementation (grabbed from <a href="http://devblog.blackberry.com/">the Blackberry Development Blog</a>) and HTML5Widget/jscolor&#8217;s. </p>
<table class="screenshot">
<thead>
<tr>
<th>Blackberry Web Browser</th>
<th>Firefox 3.5 with html5Widgets.js</th>
</thead>
<tbody>
<tr>
<td>
<a href="http://www.useragentman.com/blog/wp-content/uploads/2010/07/html5-color-input.jpg"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/07/html5-color-input.jpg" alt="HTML5 Color form field, Blackberry" title="html5-color-input"  class="alignnone size-full wp-image-1292" /></a>
</td>
<td><a href="http://www.useragentman.com/blog/wp-content/uploads/2010/07/jscolor.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/07/jscolor.png" alt="HTML5 color input field with html5Widgets and jscolor." title="jscolor"  class="alignnone size-full wp-image-1291" /></a>
</td>
</tr>
</tbody>
</table>
<p><a class="exampleLink" href="/tests/html5Widgets/color.html">See HTML5Widget&#8217;s implementation of the<br />
<code>color</code> input type.</a></p>
<p><strong>Note:</strong> Like other HTML syntax, <code>color</code> uses the unfortunate American spelling instead of the Queen&#8217;s Proper English (i.e. colour). Ensure you spell it incorrectly in order to make this work.  ;-)</p>
<h2>How Well Do These Libraries Handle the Official Specification?</h2>
<p>I have done some testing on some existing examples that use HTML5 forms to ensure that it works the way developers expect.  Here are a few examples that I have taken, with the necessary JavaScript added:</p>
<ul>
<li><a href="/tests/html5Widgets/24ways.org/index.html"><strong>A cool looking payment form</strong></a> by <a href="http://yaili.com/">Inayaili de León</a> (originally from<a href="http://24ways.org/2009/have-a-field-day-with-html5-forms"> her HTML5 forms tutorial</a>)</li>
<li><a href="/tests/html5Widgets/bradshawenterprises.com/index.html"><strong>An HTML5 Form Demo</strong></a> by <a href="http://www.bradshawenterprises.com/">Richard Bradshaw</a> (originally from his <a href="http://www.bradshawenterprises.com/blog/2010/fancy-forms-html5-css3-js/"><em>Fancy Forms: HTML5 + CSS3 – JS</em></a> article)</li>
<li><a href="/tests/html5Widgets/dev.opera.com"><strong>Another cool Example</strong></a> by <a href="http://annevankesteren.nl/">Anne van Kesteren</a> (originally from his article <a href="http://dev.opera.com/articles/view/improve-your-forms-using-html5/"><em>Improve your forms using HTML5!</em></a> on the <a href="http://dev.opera.com">The Opera Developer Community Website</a>).</li>
</ul>
<p>However, the HTML5 Forms specification is large, and unfortunately, the <code>webforms2</code> and <code>html5Widgets</code> libraries don&#8217;t implement everything &#8230; <strong>yet!!!!</strong>  Since I am really motivated with what HTML5 forms can do, I am committed to completing support to most, if not all, of the HTML5 Forms specification.  The version of <code>webforms2</code> in this blog post has been modified from Weston Ruter&#8217;s original verison, but it will be merged with the official Google Code version in the next week or so and will include compressed versions of all the library. The <code>html5Widgets</code> library will also have a permanent home there.</p>
<p>Things that I will be working on in the near future are:</p>
<ul>
<li><strong>Support for other HTML5 form elements</strong>, among other things, <code>datalist</code>, <code>number</code>, <code>keygen</code>, <code>progress</code>, <code>time</code> and <code>meter</code></li>
<li><strong>Support for CSS styling of HTML5 form widgets</strong> as well as the ability to style form fields according to their validation state (e.g. <code>:valid</code> and <code>:invalid</code> psudo-classes).  Opera seems to be the only browser currently supporting this.</li>
<li><strong>Default styling for some of the new input types</strong>, like <code>tel</code>, <code>email</code>, <code>url</code>.  Opera for Mac and Opera Mobile are the only browsers I know of that support this for <code>email</code> and <code>url</code>.
<p><div id="attachment_1298" class="wp-caption aligncenter" style="width: 340px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2010/07/operaMacURLandEmail.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/07/operaMacURLandEmail.png" alt="email and url form fields in Opera Mac" title="" width="330" height="156" class="size-full wp-image-1298" /></a><p class="wp-caption-text"><code>email</code> and <code>url</code> form fields in Opera Mac</p></div></li>
<li><strong>Support for customizing the validation look and feel.</strong>  This is one I would love to do, since I&#8217;m sure a lot of developers would want to change how validation errors appear on the screen.  Unfortunately, the HTML5 specification doesn&#8217;t describe a standard way of doing this.  It will be interesting to see how the browser manufacturers deal with this issue (<em><strong>To any browser developer reading this is working on the display form validation errors:</strong> I would love to know how you are doing this if you are willing to share.  <strong>Hint, HINT! ;-)</strong></em>)</li>
<li><strong>In Internet Explorer 7 and lower, the ability to style input types it doesn&#8217;t support natively</strong> with CSS code like <code>input[type="range"]</code></li>
<li><strong>Enabling HTML5 forms validation on the server side</strong> to ensure data integrity for browser that don&#8217;t support HTML5 forms that have JavaScript disabled.</li>
<li><strong>Support for internationalization of the error messages used in <code>webforms2</code>.</strong>  If anyone wants to help in the translation of these error messages, please drop me a line &mdash; I need help!</li>
</ul>
<p>Below is a modified version of the Wikipedia&#8217;s HTML5 forms compatibility table and see what how things the support situation stands today.</p>
<table class="screenshots">
<thead>
<tr>
<th></th>
<th>Trident</th>
<th>Gecko</th>
<th>WebKit</th>
<th>Presto</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="5">Attributes</th>
</tr>
<tr>
<th><code>autocomplete</code></th>
<td class="table-yes">Yes</td>
<td class="table-yes">Yes</td>
<td class="table-yes">Yes</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>list</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>required</code></th>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>multiple</code></th>
<td class="table-no">No</td>
<td class="table-yes">1.9.2</td>
<td class="table-yes">526</td>
<td class="table-no">No</td>
</tr>
<tr>
<th><code>pattern</code></th>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="nightly table-yesWithWebforms2 table-nightly">Yes (with webforms2, and natively in Nightly build)</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>min</code>, <code>max</code></th>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>step</code></th>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="nightly table-nightly table-yesWithWebforms2">Yes (with webforms2 and Nightly build natively)</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>placeholder</code></th>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
<td class="nightly table-nightly">1.9.3</td>
<td class="table-yes">Yes</td>
<td class="table-yesWithWebforms2">Yes (with webforms2)</td>
</tr>
<tr>
<th><code>form</code></th>
<td class="table-no">No</td>
<td class="nightly table-nightly">1.9.3</td>
<td class="table-no">No</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>autofocus</code></th>
<td class="table-yesWithhtml5Widgets">Yes (with html5Widgets)</td>
<td class="nightly table-nightly">1.9.3</td>
<td class="nightly table-nightly table-yesWithhtml5Widgets">Yes (with html5Widgets and Nightly build natively)</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>maxlength</code></th>
<td class="table-no">No</td>
<td class="nightly table-nightly">1.9.3</td>
<td class="nightly table-nightly">Nightly build</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>novalidate</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="nightly table-nightly">Nightly build</td>
<td class="table-no">No</td>
</tr>
<tr>
<th><code>control</code></th>
<td class="table-no">No</td>
<td class="nightly table-nightly">1.9.3</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
</tr>
<tr>
<th><code>accept</code></th>
<td class="table-no">No</td>
<td class="nightly table-nightly">1.9.3</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
</tr>
<tr>
<th><code>formtarget</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
</tr>
<tr>
<th><code>formaction</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
</tr>
<tr>
<th colspan="5">Elements</th>
</tr>
<tr>
<th><code>datalist</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>keygen</code></th>
<td class="table-no">No</td>
<td class="incorrect">1.0</td>
<td class="table-yes">125</td>
<td class="table-yes">1.0</td>
</tr>
<tr>
<th><code>output</code></th>
<td class="table-no">No</td>
<td class="nightly table-nightly">1.9.3</td>
<td class="table-no">No</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>progress</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="nightly table-nightly">Nightly build</td>
<td class="table-no">No</td>
</tr>
<tr>
<th><code>meter</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="table-no">No</td>
</tr>
<tr>
<th colspan="5">Input types</th>
</tr>
<tr>
<th><code>search</code></th>
<td class="table-no">No</td>
<td class="nightly table-nightly">1.9.3</td>
<td class="table-yes">312</td>
<td class="table-no">No</td>
</tr>
<tr>
<th><code>tel</code></th>
<td class="table-no">No</td>
<td class="nightly table-nightly">1.9.3</td>
<td class="nightly table-nightly">Nightly build</td>
<td class="table-no">No</td>
</tr>
<tr>
<th><code>url</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="nightly table-nightly">Nightly build</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>email</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="nightly table-nightly">Nightly build</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>datetime</code></th>
<td class="table-yesWithhtml5Widgets" rowspan="6">Yes (with html5Widgets)</td>
<td class="table-yesWithhtml5Widgets" rowspan="6">Yes (with html5Widgets)</td>
<td class="nightly table-nightly table-yesWithhtml5Widgets" rowspan="6">Yes (with html5Widgets and Nightly build natively)</td>
<td class="table-yes" rowspan="6">2.0</td>
</tr>
<tr>
<th><code>date</code></th>
</tr>
<tr>
<th><code>month</code></th>
</tr>
<tr>
<th><code>week</code></th>
</tr>
<tr>
<th><code>time</code></th>
</tr>
<tr>
<th><code>datetime-local</code></th>
</tr>
<tr>
<th><code>number</code></th>
<td class="table-no">No</td>
<td class="table-no">No</td>
<td class="nightly table-nightly">Nightly build</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>range</code></th>
<td class="table-yesWithhtml5Widgets">Yes (with html5Widgets)</td>
<td class="table-yesWithhtml5Widgets">Yes (with html5Widgets)</td>
<td class="table-yes">Yes</td>
<td class="table-yes">2.0</td>
</tr>
<tr>
<th><code>color</code></th>
<td class="table-yesWithhtml5Widgets">Yes (with html5Widgets)</td>
<td class="table-yesWithhtml5Widgets">Yes (with html5Widgets)</td>
<td class="nightly table-nightly table-yesWithhtml5Widgets">Yes (with html5Widgets and Nightly build natively)</td>
<td class="table-yesWithhtml5Widgets">Yes (with html5Widgets)</td>
</tr>
</tbody>
</table>
<h2>Integrating With <code>visibleIf</code> To Make Even <strong>Cooler</strong> Looking Forms</h2>
<p>The <code>webforms2</code> and <code>html5Widgets</code> libraries are designed to co-exist well with <code><a href="http://www.useragentman.com/blog/2010/06/20/visibleif-html5-custom-data-attributes-with-javascript-make-dynamic-interactive-forms/">visibleIf</a></code> to create interactive forms with fields that only validate the ones that visibleIf is displaying.</p>
<p><a class="exampleLink" href="/tests/html5Widgets/patternRequiredWithVisibleIf.html">See an example of HTML5 validation working with the <code>visibleIf</code> JavaScript library</a></p>
<h2>Acknowledgments, Shout-outs and Kudos</h2>
<ul>
<li><strong><a href="http://farukat.es/">Faruk Ates</a> and <a href="http://paulirish.com/">Paul Irish</a></strong> for <em>the</em> definitive HTML5 and CSS3 feature detector, <a href="http://www.modernizr.com/">modernizr</a>.</li>
<li><strong><a href="http://weston.ruter.net/">Weston Ruter</a></strong> for doing the insane amount of work on <a href="https://github.com/westonruter/webforms2">webforms2</a> <em>years ago</em>.</li>
<li><strong><a href="http://www.frequency-decoder.com/">Brian McAllister:</a></strong> for making the excellent <a href="http://www.frequency-decoder.com/2008/08/01/unobtrusive-slider-control-v2">Unobtrusive slider control</a> which I used for the range element.</li>
<li><strong><a href="http://www.dynarch.com/">Mihai Bazon</a></strong> for keeping the <a href="http://www.dynarch.com/projects/calendar/old/">The Ex-“Coolest” DHTML Calendar</a> around even though he has a paid product.</li>
<li><strong><a href="http://www.softwareishard.com">Jan Odvárko</a></strong> for his rocking <a href="http://jscolor.com/">jscolor</a> widget.</li>
<li><strong><a href="http://remysharp.com/">Remy Sharp</a></strong> for his fine <a href="<a href="http://remysharp.com/2009/01/07/html5-enabling-script/">HTML5 Enabling Script</a> so we can force IE to style things like the <code>output</code> tag.</li>
<li><strong><a href="http://yaili.com/">Inayaili de Leon</a>, <a href="http://annevankesteren.nl/">Anne van Kesteren</a> and <a href="http://www.bradshawenterprises.com/">Richard Bradshaw</a></strong> for allowing me to show how easy it is to make their original HTML5 Form demos work with html5Widgets.</li>
</ul>
<h2>Further Reading</h2>
<ul>
<li><strong><a href="http://www.w3.org/TR/html5/forms.htm">The W3C HTML5 Forms Specification Working Draft:</a></strong> The Working Draft is in &#8220;Last call for comments&#8221; status, so there may be some last minute changes.</li>
<li><strong><a href="http://diveintohtml5.org/forms.html">A Form of Madness:</a></strong> Chapter 10 of Mark Pilgrim&#8217;s great reference on HTML5.</li>
<li><strong><a href="http://www.whatwg.org/specs/web-forms/current-work/">Web Forms 2.0 Working Draft:</a></strong> The WHATWG spec that the W3C spec is based on.  It includes the repetition model which didn&#8217;t make it into the W3C spec</li>
</ul>
<h2>Download</h2>
<p><del datetime="2011-05-12T23:52:56+00:00">This archive is the temporary home for <code>html5Widgets</code>.  It will soon be hosted at the <a href="http://code.google.com/p/webforms2/"><code>webforms2</code> Google Code page</a>.</del>  Both <a href="https://github.com/zoltan-dulac/html5Widgets">html5Widgets</a> and <a href="https://github.com/westonruter/webforms2">webforms2</a> both have permanent homes at github (however, the html5Widgets github page contains a copy of webforms2 in it for your convenience).  Weston Ruter has been kind to give me deciding rights over the destiny of this code.  I <em>will</em> be updating webforms2 in the near future.</p>
<p><a class="exampleLink" href="https://github.com/zoltan-dulac/html5Widgets">Download the latest version of html5Widgets, which includes webforms2, from github.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2010/07/27/cross-browser-html5-forms-using-modernizr-webforms2-and-html5widgets/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>visibleIf – Dynamic and Complex Interactive Forms Using HTML5 Custom Data Attributes</title>
		<link>http://www.useragentman.com/blog/2010/06/20/visibleif-html5-custom-data-attributes-with-javascript-make-dynamic-interactive-forms/</link>
		<comments>http://www.useragentman.com/blog/2010/06/20/visibleif-html5-custom-data-attributes-with-javascript-make-dynamic-interactive-forms/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 00:49:36 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Custom Data Attributes]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=1251</guid>
		<description><![CDATA[One thing HTML5 forms can't do is dynamically show and hide form elements according to the data that the user has already entered.  My new library, <code>visibleIf</code> gives you a very easy way to do this using the HTML5 <code>data-</code> attributes.]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Update (July 28, 2010):</h3>
<p>I have fixed a minor bug in this script to ensure compatibility with webforms2, part of <a href="http://www.useragentman.com/blog/2010/07/27/cross-browser-html5-forms-using-modernizr-webforms2-and-html5widgets/">a suite of scripts that implement cross-browser compatibility with the HTML5 forms specification</a>.</p>
</div>
<p>I have been following the progression of the HTML5 Forms standard with great interest.  It promises a whole slew of new visual and usability goodness to existing HTML forms (e.g. slider and calendar widgets), a client-side validation framework, and so much more.  One of the things I was disappointed with, though, was that <strong>HTML5 cannot hide and show form elements depending on what the user has input into the form so far.</strong>  To give a very simple example of what I am talking about, select a country of origin in the form below:</p>
<form>
<table class="formTable">
<tbody>
<tr>
<th>Country of Origin: </th>
<td>
<select name="country">
<option> Select One&#8230; </option>
<option value="Canada"> Canada </option>
<option value="United States"> United States </option>
</select>
</td>
</tr>
<tr class="visibleIf" data-visibleif-rule=" country == 'Canada'">
<th>Postal Code: </th>
<td>
<input name="postalCode" type="text" /></td>
</tr>
<tr class="visibleIf" data-visibleif-rule=" country == 'United States'">
<th>Zip Code: </th>
<td>
<input name="zipCode" type="text" /></td>
</tr>
</tbody>
</table>
</form>
<p>In HTML5, there is no way for a developer to tell the browser <em>&#8220;only show me this block of HTML if </em><code>country == 'Canada'</code><em>&#8220;</em>.  This is not a criticism of HTML5 or its authors &mdash; HTML5 forms has a lot of awesomeness in it (some of which I will blog about in my next article) and we can&#8217;t expect it to do everything. However, I have been using custom JavaScript to do this kind of stuff all the time, and wouldn&#8217;t it be great if the JavaScript challenged could do so?  In the ideal world graphic designers, J2EE programmers with minimal front-end experience, and even my 75-year-old mom should be able to do this.</p>
<p>As a result, I present a JavaScript library, <code>visibleIf</code>, which allows web developers to use <a href="http://ejohn.org/blog/html-5-data-attributes/">HTML5 custom data attributes</a> to define when blocks of HTML should be visible or invisible.  <strong>Even if you are not a JavaScript genius, you will be able to make cool looking dynamic forms with very simple markup.</strong>  For example, let&#8217;s take a look at the HTML of the example above:</p>
<blockquote class="code">
<pre>&lt;form&gt;
    &lt;table class="formTable"&gt;
        &lt;tr&gt;
            &lt;th&gt;Country of Origin&lt;/th&gt;

            &lt;td&gt;&lt;select name="country"&gt;
                &lt;option value=""&gt;
                    Select One...
                &lt;/option&gt;

                &lt;option value="Canada"&gt;
                    Canada
                &lt;/option&gt;

                &lt;option value="United States"&gt;
                    United States
                &lt;/option&gt;
            &lt;/select&gt; &lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr <span class="hilite">class="visibleIf" data-visibleif-rule="country == 'Canada'"</span>&gt;
            &lt;th&gt;Postal Code&lt;/th&gt;

            &lt;td&gt;&lt;input type="text" name="postalCode"
            value="" /&gt; &lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr <span class="hilite">class="visibleIf" data-visibleif-rule="country == 'United States'"</span>&gt;
            &lt;th&gt;Zip Code&lt;/th&gt;

            &lt;td&gt;&lt;input type="text" name="zipCode"
            value="" /&gt; &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/form&gt;
</pre>
</blockquote>
<p>This example is rather simple: the Postal Code form field is shown when <code>country == 'Canada'</code> and Zip Code is shown when <code>country == 'United States'</code>.  Note that in order to hide and show a block of HTML, you must set two attributes inside the containing tag:</p>
<ul>
<li><strong><code>class="visibleIf"</code>:</strong> which lets the visibleIf.js script know that this block of HTML is to be hidden or shown according to the <code>data-visibleif-rule</code></li>
<li><strong><code>data-visibleif-rule='<em>rule expression'</em></code>:</strong> which contains the visibility rule.  The rule variables are form element names, like <code>country</code> is in the above example. You can do simple equality rules like this, or complex ones like:<br />
<blockquote class="code"><pre>
&lt;div class="visibleIf"
   data-visibleif-rule="country == 'Canada' &#038;&#038; (city == 'Toronto' || city == 'Vancouver')"&gt;
  ...
&lt;/div&gt;
</pre>
</blockquote>
<p>If you know a little bit of JavaScript, you will note that you can use JavaScript functions to do interesting rules like:</p>
<blockquote class="code"><pre>
&lt;div class="visibleIf" data-visibleif-rule="parseInt(total) &gt; 100"&gt;
  ...
&lt;/div&gt;
</pre>
</blockquote>
</li>
</ul>
<p>Note that the above examples have visibleIf rules inside a <code>tr</code> tag, <strong>they can be used in any tag inside an HTML form</strong>. </p>
<p>Although the above example is quite simple, you can use visibleIf to make really complex forms &mdash; you can even put visibleIf blocks inside of visibleIf blocks.  To illustrate this I have created <a href="/tests/visibleIf/example1.html">a more interesting form</a> that shows what can be done using visibleIf.</p>
<p><a href="/tests/visibleIf/example1.html" class="exampleLink">See a more complex visibleIf form example</a></p>
<h2>Hidden Fields &#8211; To Clear Or Not To Clear</h2>
<p>If the user does something that hides some form fields (e.g. clicks on a checkbox) and then reverses that action (in this case clicking on the same checkbox), the fields will reappear with any previously filled-in data erased. Developers can override this default behavior by setting the class of the fields that shouldn&#8217;t be erased to <code>visibleIf-doNotReset</code>.  To illustrate this, I have created a page with two identical forms on it &mdash; one that erases the values inside hidden fields, and one that doesn&#8217;t.  Play with the example and you&#8217;ll see what I mean.</p>
<p><a class="exampleLink" href="/tests/visibleIf/example2-dotNotReset.html">See an example of a form with and without <code>visibleIf-doNotReset</code> fields.</a></p>
<h2>Hidden Fields &#8211; Submit To The Server, Or Not?</h2>
<p>Also note that by default, only the visible form elements are submitted to the server (this is because when a form element is hidden by <code>visibleIf</code>, its <code>disabled</code> attribute is set to <code>true</code> when the form is submitted).  If developers wants to override this behavior, they can simply set the form&#8217;s <code>class</code> to <code>visibleIf-submitInvisibleData</code>.</p>
<p><a  class="exampleLink"  href="/tests/visibleIf/example2-submitInvisibleData.html">See an example of a form with and without <code>visibleIf-submitInvisibleData</code> class set.</a></p>
<h2>The Quick &#8220;How-To&#8221; Guide&#8221;</h2>
<p>Setting up your existing forms to use visibleIf is a quick, three-step process:</p>
<ol>
<li>Download the source from the visibleIf Project Page</li>
<li>Include the visibleIf.css stylesheet, EventHelpers.js and visibleIf.js JavaScript files into your web page:<br />
<blockquote class="code">
<pre>&lt;link rel="stylesheet" href="/path/to/visibleIf.css" type="text/css" /&gt;

&lt;script type="text/javascript" src="/path/to/EventHelpers.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/visibleIf.js"&gt;
&lt;/script&gt;
</pre>
</blockquote>
</li>
<li>Use the visibleIf rules as seen in the example above.  Note that <code>&amp;&amp;</code>, <code>||</code> and other logical operators are allowed in the expressions, as are JavaScript functions (e.g. parseInt, parseFloat, etc).</li>
</ol>
<h2>A Note On The Use Of Custom Data Attributes</h2>
<p>Why did I bother with custom data attributes when making <code>visibleIf</code>?  Why did I just use the attribute <code>data-visibleif-rule</code> instead of just <code>visibleif-rule</code> or just <code>rule</code> to place the visibility rule? Wouldn&#8217;t that be simpler?</p>
<ul>
<li><strong><code>data-</code> attributes are HTML compliant: </strong>.  Their use ensure that <code>visibleIf</code> will be compatible with future versions of HTML since <strong><code>data-</code> attributes are reserved to be used for JavaScript libraries</strong>.  As long as you use the <a href="http://dev.w3.org/html5/spec/syntax.html#the-doctype">HTML5 DOCTYPE</a>, your forms should also validate.</li>
<li><strong>The <code>data-visibleif-</code> prefix will not collide with attributes used in other JavaScript libraries. </strong> There is a high chance that <code>data-rule</code> could be used by another library.  Using the name of the library in the attribute significantly reduces that possibility.
</ul>
<h2>Download</h2>
<p><a href="/downloads/visibleIf-2.1.zip" class="exampleLink"><code>visibleIf.js</code> v. 2.1 and example code (zip format)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2010/06/20/visibleif-html5-custom-data-attributes-with-javascript-make-dynamic-interactive-forms/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>cssSandpaper Now Supports transform: translate() and rgba() Gradients</title>
		<link>http://www.useragentman.com/blog/2010/05/06/csssandpaper-now-supports-transform-translate-and-rgba-gradients/</link>
		<comments>http://www.useragentman.com/blog/2010/05/06/csssandpaper-now-supports-transform-translate-and-rgba-gradients/#comments</comments>
		<pubDate>Thu, 06 May 2010 22:01:22 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Color]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[IE Visual Filters]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Polyfills]]></category>
		<category><![CDATA[rgb/rgba]]></category>
		<category><![CDATA[transform]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=1060</guid>
		<description><![CDATA[In the first in a planned series of posts, I update cssSandpaper with new features.  This week I add IE support for <code>translate()</code> support to CSS transforms and alpha channel support to linear gradients.  ]]></description>
			<content:encoded><![CDATA[<p>I have been really happy with the great feedback I&#8217;ve been getting about <a href="http://www.useragentman.com/blog/csssandpaper-a-css3-javascript-library/">cssSandpaper</a>. <strong> CSS3 gives web developers  some great design tools to work with</strong> and it is my hope that this library will encourage more developers to use the <strong>use of these new features today</strong>, even if they have to code <strong>in older browsers.</strong> Even though Internet Explorer 9 will be supporting a few of these features, <strong>it will be quite a while before the number of users of IE8 will be at an ignorable level</strong> and we won&#8217;t need cssSandpaper any longer.  Until then, I will work hard to make cssSandpaper better.</p>
<p><a href="http://www.useragentman.com/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/">When I released cssSandpaper</a> a few months ago, I was disappointed that I couldn&#8217;t support CSS3 transform&#8217;s <code>translate()</code> function in IE due to a limitation in the <a href="http://msdn.microsoft.com/en-us/library/ms533014%28VS.85%29.aspx"><code>DXImageTransform.Microsoft.Matrix</code> CSS <code>filter</code></a>.  However, with the gracious help of <a href="http://www.nicolarizzo.com/">Nicola Rizzo</a> (who has already used his Matrix filter skills coding <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/html/tests/test_style-html.html">a really cool dojox transformation plugin</a>) and Tomasz Tunik, we now have a version of cssSandpaper that supports it.  I also got a few requests to have IE support for CSS3 gradients that can use <a href="http://www.css3.info/preview/rgba/">the <code>rgba()</code> color space</a>, and with the help of information on <a href="http://css3please.com">CSS3 Please</a>, it was easily added.</p>
<h2>transform: translate</h2>
<p>The CSS <code>transform</code> property allows for 2D translations of a box.  What this means is, no matter which way you want to rotate or skew the object, you can move the object horizontally and vertically from the object&#8217;s perspective.  Some of you may ask &#8220;How is this different from changing the object&#8217;s  <code>top</code> and <code>left</code> properties?  Let&#8217;s take a look at an example below to see how it differs:</p>
<p><div id="attachment_1063" class="wp-caption aligncenter" style="width: 478px"><a href="http://www.useragentman.com/tests/cssSandpaper/simpleTranslate.html"><img class="size-full wp-image-1063" title="translateExample1" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/translateExample1.png" alt="" width="468" height="458" /></a><p class="wp-caption-text">An example of CSS3 transform: translate() using cssSandpaper (click the image above to see it in action)</p></div></p>
<p>In the example above you&#8217;ll see two white boxes, one without any transforms performed, and the other translated 200 pixels to the right.  Just what you would expect.  Now take a look at the two red boxes &#8230; they are both rotated 45 degrees, but the second one is then<strong> translated 200 pixels to the right from the object&#8217;s perspective</strong>.</p>
<p>The translations are done with some very simple CSS:</p>
<blockquote class="code">
<pre>/*
 * This object is rotated 45 degrees and then translated 200 pixels to the
 * right and 100 pixels down, with respect to the object's perspective
 */

#o2 {
	-sand-transform: translate(200px, 100px);
}</pre>
</blockquote>
<p><code>translate()</code> takes two parameters, the x and y translation offsets (currently, cssSandpaper only supports <code>px</code> units for these offsets).  There are also <code>translateX()</code> and <code>translateY()</code> if a developer only wants to translate in one direction.</p>
<h2>rgba() Gradients</h2>
<p>The rgba color space adds alpha channeling to the rgb color space you know and love.  When using it in gradients, developers can make parts of an elements background-color semi-transparent.  The two examples below illustrate the effects that be done with <code>rgba()</code>.</p>
<table>
<tbody>
<tr>
<td>
<p><div id="attachment_1073" class="wp-caption aligncenter" style="width: 244px"><a href="/tests/cssSandpaper/rgbaGradientTest.html"><img class="size-full wp-image-1073 " title="gradients" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/gradients.png" alt="" width="234" height="330" /></a><p class="wp-caption-text">A few rgba() gradients on top of each other to demonstrate their semi-transparency.</p></div></td>
<td>
<p><div id="attachment_1072" class="wp-caption aligncenter" style="width: 244px"><a href="/tests/cssSandpaper/rgbaGradient.html"><img class="size-full wp-image-1072 " title="gradientAnimation" src="http://www.useragentman.com/blog/wp-content/uploads/2010/05/gradientAnimation.png" alt="" width="234" height="330" /></a><p class="wp-caption-text">An example of an animation using rgba() gradients (click on the above images to show the examples in action).</p></div></td>
</tr>
</tbody>
</table>
<p>The following code illustrates how to perform an rgba() gradient:</p>
<blockquote class="code">
<pre>/*
 * The following is a horizontal gradient that blends red to blue, with a 50% opacity level
 */

#o2 {
   background-image: -sand-gradient(linear, left top, right top,
      from(rgba(255, 0, 0,  0.5)), to(rgba(0, 0, 255, 0.5)));
}</pre>
</blockquote>
<p>Note that as before, IE only supports two color gradients that are strictly horizontal or vertical.  I hope to support multiple color stops in IE in a future release.  Also note that in IE, the alpha channel is removed from an object if you apply a transform on it. This may be a limitation of <a href="http://msdn.microsoft.com/en-us/library/ms532997%28VS.85%29.aspx">IE&#8217;s  Gradient filter</a>, which cssSandpaper uses to implement CSS3 gradients.</p>
<p>In order to translate <code>rgba()</code> notation to ARGB notation with IE&#8217;s gradient filter understands (e.g. <code>#aarrggbb</code>, where <code>aa</code> are two hex digits representing the amount of opacity), I modified <a href="http://www.phpied.com/">Stoyan Stefanov</a>&#8216;s <a href="http://www.phpied.com/rgb-color-parser-in-javascript/">RGBColor script</a> (which translates from one color notation to another) and added ARGB support.</p>
<p>For information about the rgba color space, read the <a href="http://www.css3.info">CSS3.info&#8217;s</a> <a href="http://www.css3.info/introduction-opacity-rgba/">brief introduction to Opacity and RGBA</a>.</p>
<h2>Future Roadmap</h2>
<p>There is quite a bit more I would like to see cssSandpaper support, including:</p>
<ol>
<li><strong><a href="http://css-tricks.com/rgba-browser-support/">solid rgba() background colors</a>:</strong> this should be quite easy to support, given it is a special case of an rgba() gradient (i.e. a transition from a color to the same color).</li>
<li><strong><a href="http://vision-media.ca/resources/css/css-transformations-animations-and-transitions-examples">CSS3 transitions</a>:</strong> performing animations with only a bit of CSS would be sweet for those who are afraid of <a href="http://en.wikipedia.org/wiki/Recursion">recursive programming</a> with the JavaScript <a href="http://www.w3schools.com/js/js_timing.asp"><code>setTimeout()</code></a> function.</li>
<li><strong><a href="https://developer.mozilla.org/en/CSS/-moz-transform-origin">transform-origin</a>:</strong> modify the origin for transformations of an element (this would allow, for example, developers to produce an animation of planets rotating around the sun, which would be the transform-origin point for all the planets).</li>
<li><strong><a href="http://www.the-art-of-web.com/css/border-radius/">border-radius</a>: </strong> Firefox and Safari have slightly diffferent methods of rounding corners of a block-level element, and it would be useful to simplify this.  It would also be nice to have support for it in any version of IE (there are<a href="http://fetchak.com/ie-css3/"> a few excellent solutions involving VML</a> are out there today, but it would be great if there was one that supported all the features that CSS3 supports, including different radii for each corner, as well as co-existance with the other features of cssSandpaper, which may not be an easy thing to do).</li>
<li><strong>CSS3 gradients with multiple color-stops:</strong> cssSandpaper uses <a href="http://msdn.microsoft.com/en-us/library/ms532997%28VS.85%29.aspx">IE&#8217;s Gradient filter</a>, which only supports two color-stops.  It would be great to do some JavaScript magic to emulate multiple color-stops.</li>
<li><strong>radial gradients in IE: </strong>although IE&#8217;s Gradient filter doesn&#8217;t support it, VML does (I found <a href="http://sample.revulo.com/VML/radial-gradient-clip.html">a really cool example of an VML</a> radial gradient, but it can only be viewed in IE).</li>
<li><strong>better support for other units of measure besides px: </strong>I personally love to use em units in my design work, and want cssSandpaper to support this and other units, like cm, in, and percentages.</li>
</ol>
<p>If <strong>anyone </strong>would like to help me implement these features or any others in cssSandpaper, please contact me either in the discussion below or at the email address at the top of this page (I can <strong>really</strong> use any assistance anyone can give). Even if you don&#8217;t know JavaScript, any comments you have on this library would be most welcome. Let&#8217;s prevent older browsers from keeping us from using CSS3 and doing some really cool design work.</p>
<p><a class="exampleLink" href="http://www.useragentman.com/blog/csssandpaper-a-css3-javascript-library/">Get the latest version of cssSandpaper from the official documentation page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2010/05/06/csssandpaper-now-supports-transform-translate-and-rgba-gradients/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

