<?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>KirkHings.com &#187; accessibility</title>
	<atom:link href="http://kirkhings.com/tag/accessibility/feed/" rel="self" type="application/rss+xml" />
	<link>http://kirkhings.com</link>
	<description>The '-berger' part trips up so many folks that I sometimes simplify my name for you. Yes, just for you.</description>
	<lastBuildDate>Sat, 13 Jun 2009 18:35:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Accessible JavaScript Rollover with Three-State Functionality</title>
		<link>http://kirkhings.com/code/javascript/accessible-javascript-rollover-with-three-state-functionality/319/</link>
		<comments>http://kirkhings.com/code/javascript/accessible-javascript-rollover-with-three-state-functionality/319/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 18:55:08 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[lynda]]></category>
		<category><![CDATA[self-instructional challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=319</guid>
		<description><![CDATA[ photo credit: Rhian vK
This programming challenge is from a Lynda.com instructional video, featuring Dori Smith, which I studied/practiced last summer but once again spring 2009. I do not mean to just re-post the wonderful Lynda.com code, but rather add instructional value to it by way of clearer variable names and explanatory comments. The end [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/javascript/three-state-javascript-rollover/312/' rel='bookmark' title='Permanent Link: Three-State JavaScript Rollover'>Three-State JavaScript Rollover</a> <small> photo credit: chimothy27 This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/disjointed-javascript-rollover-causes-separate-animation/324/' rel='bookmark' title='Permanent Link: Disjointed JavaScript Rollover Causes Separate Animation'>Disjointed JavaScript Rollover Causes Separate Animation</a> <small> photo credit: Matt McGee This programming challenge is from...</small></li>
<li><a href='http://kirkhings.com/code/javascript/simple-and-improved-image-rollovers/298/' rel='bookmark' title='Permanent Link: Simple and Improved Image Rollovers'>Simple and Improved Image Rollovers</a> <small> photo credit: Etwood This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/random-image-display-with-javascript/406/' rel='bookmark' title='Permanent Link: Random Image Display with JavaScript'>Random Image Display with JavaScript</a> <small> photo credit: davidChief This programming challenge is from a...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/34764035@N00/2258204466/" title="PRIORITE" target="_blank"><img src="http://farm3.static.flickr.com/2391/2258204466_3162c3f37f.jpg" alt="PRIORITE" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/34764035@N00/2258204466/" title="Rhian vK" target="_blank">Rhian vK</a></small></div>
<p>This programming challenge is from a Lynda.com instructional video, featuring Dori Smith, which I studied/practiced last summer but once again spring 2009. I do not mean to just re-post the wonderful Lynda.com code, but rather add instructional value to it by way of clearer variable names and explanatory comments. The end result itself is not terribly sexy, but I liked the algorithm construction process.</p>
<p>I post these self-instructional challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it. Finally, self-instructional challenges are interesting and different than academic challenges because I sought, discovered, and performed them on my own volition without anyone else telling me to do so. I did it because I wanted to learn and practice.</p>
<blockquote><p>Challenge: Create a JavaScript image rollover animation which includes a default image, a hover over image, and an image when the link is clicked. Use abstracted functions. Improve accessibility by creating onfocus and onblur event handlers for users without mice.
</p></blockquote>
<p>The HTML solution:</p>
<pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;An Accessible Three-State Rollover&lt;/title&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;script.js&quot;&gt;&lt;/script&gt;
	&lt;link rel=&quot;stylesheet&quot; rev=&quot;stylesheet&quot; href=&quot;styles.css&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;a href=&quot;next1.html&quot;&gt;
		&lt;img src=&quot;images/button1_off.gif&quot; width=&quot;113&quot; height=&quot;33&quot; alt=&quot;button1&quot; id=&quot;button1&quot; /&gt;
	&lt;/a&gt;&amp;nbsp;&amp;nbsp;
	&lt;a href=&quot;next2.html&quot;&gt;
		&lt;img src=&quot;images/button2_off.gif&quot; width=&quot;113&quot; height=&quot;33&quot; alt=&quot;button2&quot; id=&quot;button2&quot; /&gt;
		&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The CSS solution:</p>
<pre class="brush: css;">
body {
	background-color: white;
}
img {
	border-width: 0;
}
</pre>
<p>The JavaScript solution:</p>
<pre class="brush: jscript;">
// initialize the rollovers when window loads
window.onload = rolloverInit;

function rolloverInit() {
	// loop through all images on page
	for (var i = 0; i &lt; document.images.length; i++) {
		// if current image is wrapped in an anchor tag (i.e. &lt;a href=&quot;&quot;&gt;&lt;img&gt;&lt;/a&gt;)
		if (document.images[i].parentNode.tagName == &quot;A&quot;) {
			// initiate rollover setup for this current image, pass the current image to that function
			setupRollover(document.images[i]);
		}
	}
}

// 'thisImage' passed from rolloverInit, meaning we need to setup the rollover for this particular image
function setupRollover(thisImage) {
	// create new child image object for thisImage object's outImage property
	thisImage.outImage = new Image();
	// store current image src as the source for outimage, so it stays same when not rolled over
	thisImage.outImage.src = thisImage.src;
	// capture rollOut function as behavior when thisImage's onmouseout event handler is triggered
	thisImage.onmouseout = rollOut;

	// create new child image object for thisImage object's overImage property
	thisImage.overImage = new Image();
	// store preconsructed '_on'-state image src (using thisImage's captured id/name) as the source for overimage, so it stays changes when rolled over
	thisImage.overImage.src = &quot;images/&quot; + thisImage.id + &quot;_on.gif&quot;;
	// capture rollOver function as behavior when thisImage's onmouseover event handler is triggered
	thisImage.onmouseover = rollOver;

	// create new child image object for thisImage object's clickImage property
	thisImage.clickImage = new Image();
	// store preconsructed '_on'-state image src (using thisImage's captured id/name) as the source for overimage, so it stays changes when rolled over
	thisImage.clickImage.src = &quot;images/&quot; + thisImage.id + &quot;_click.gif&quot;;
	// capture rollClick function as behavior when thisImage's onmousedown event handler is triggered
	thisImage.onmousedown = rollClick;

	// improve accessibility
	// set image's parent anchor child Image to thisImage
	thisImage.parentNode.childImage = thisImage;
	// when image's achor tag is unselected (an event handler)
	thisImage.parentNode.onblur = rollOutChild;
	// when image's achor tag is selected (an event handler)
	thisImage.parentNode.onfocus = rollOverChild;
}

function rollOut() {
	// change thisImage's src to the outImage source property (already captured)
	this.src = this.outImage.src;
}

function rollOver() {
	// change thisImage's src to the overImage source property (already captured)
	this.src = this.overImage.src;
}

function rollClick() {
	// change thisImage's src to the clickImage source property (already captured)
	this.src = this.clickImage.src;
}

function rollOutChild() {
	// change the achor tag's childImage src to the childImage's outImage source property (already captured)
	this.childImage.src = this.childImage.outImage.src;
}

function rollOverChild() {
	// change the achor tag's childImage src to the childImage's overImage source property (already captured)
	this.childImage.src = this.childImage.overImage.src;
}
</pre>
<p>And finally here is a screenshot of the improved end rollover result: </p>
<p>Rollover state A: <div id="attachment_301" class="wp-caption alignleft" style="width: 278px"><img src="http://kirkhings.com/wp-content/uploads/improvedrollovera.png" alt="Improved rollover state A" title="improvedrollovera" width="268" height="73" class="size-full wp-image-301" /><p class="wp-caption-text">Improved rollover state A</p></div></p>
<p>
Rollover state B: <div id="attachment_302" class="wp-caption alignleft" style="width: 263px"><img src="http://kirkhings.com/wp-content/uploads/improvedrolloverb.png" alt="Improved rollover state B" title="improvedrolloverb" width="253" height="51" class="size-full wp-image-302" /><p class="wp-caption-text">Improved rollover state B</p></div></p>
<p>
Rollover state C (clicked button): <div id="attachment_313" class="wp-caption alignleft" style="width: 264px"><img src="http://kirkhings.com/wp-content/uploads/improvedrolloverc.png" alt="Button state when button is clicked" title="improvedrolloverc" width="254" height="51" class="size-full wp-image-313" /><p class="wp-caption-text">Button state when button is clicked</p></div></p>
<div id="attachment_320" class="wp-caption alignleft" style="width: 408px"><img src="http://kirkhings.com/wp-content/uploads/accessiblerollover.png" alt="Demonstrating accessible rollover when button is selected but not moused over." title="accessiblerollover" width="398" height="58" class="size-full wp-image-320" /><p class="wp-caption-text">Demonstrating accessible rollover when button is selected but not moused over.</p></div>
<p></p>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/javascript/three-state-javascript-rollover/312/' rel='bookmark' title='Permanent Link: Three-State JavaScript Rollover'>Three-State JavaScript Rollover</a> <small> photo credit: chimothy27 This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/disjointed-javascript-rollover-causes-separate-animation/324/' rel='bookmark' title='Permanent Link: Disjointed JavaScript Rollover Causes Separate Animation'>Disjointed JavaScript Rollover Causes Separate Animation</a> <small> photo credit: Matt McGee This programming challenge is from...</small></li>
<li><a href='http://kirkhings.com/code/javascript/simple-and-improved-image-rollovers/298/' rel='bookmark' title='Permanent Link: Simple and Improved Image Rollovers'>Simple and Improved Image Rollovers</a> <small> photo credit: Etwood This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/random-image-display-with-javascript/406/' rel='bookmark' title='Permanent Link: Random Image Display with JavaScript'>Random Image Display with JavaScript</a> <small> photo credit: davidChief This programming challenge is from a...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/javascript/accessible-javascript-rollover-with-three-state-functionality/319/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
