<?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>zelph.com &#187; Code related</title>
	<atom:link href="http://www.zelph.com/archives/category/code-related/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zelph.com</link>
	<description>Aaron Barker's random bablings</description>
	<lastBuildDate>Wed, 13 Feb 2008 19:35:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introducing onViewable</title>
		<link>http://www.zelph.com/archives/2006/03/04/introducing-onviewable/</link>
		<comments>http://www.zelph.com/archives/2006/03/04/introducing-onviewable/#comments</comments>
		<pubDate>Sat, 04 Mar 2006 11:38:04 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[JavaScript/DOM]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2006/03/04/introducing-onviewable/</guid>
		<description><![CDATA[Here&#8217;s my second resuable script to hopefully find a home in the wild wild web&#8230; onViewable.   Instead of duplicating all the details of the script here, please see it on it&#8217;s own page.
The jist of the script is that it&#8217;s a function that allows a snippet of code to be fired once an [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s my second resuable script to hopefully find a home in the wild wild web&#8230; <a href="/releases/onviewable/">onViewable</a>.   Instead of duplicating all the details of the script here, please see it on it&#8217;s own page.</p>
<p>The jist of the script is that it&#8217;s a function that allows a snippet of code to be fired once an element is viewable on the screen.</p>
<p>We have a few longish type pages where I work and I wanted to use the <a href="http://www.axentric.com/posts/default/7">Fade Anything Technique</a> to do what it does best, and hilight a few elements on the page.  Well a few of those elements were not viewable on the screen above the fold so I had to come up with something to make them fire when they were viewable.  So long story short&#8230;I slapped together a few miscelaneous things I had laying around and onViewable was born.</p>
<p>Please find the details of the hows and why&#8217;s on the <a href="/releases/onviewable/">onViewable</a> page.  Any updates will be posted there, and I will mention them in the blog so you can be aware of them.</p>
<p>I look forward to any feedback.</p>
<p>I must give credit here (in addition to on the script&#8217;s page) to the great PPK (<font size="-1">Peter-Paul Koch) of <a href="http://www.quirksmode.org/">QuirksMode.org</a>.  Without his invaluable resource and a few functions I borrowed, this wouldn&#8217;t be here today. Thank you PPK for your great contribution to the community.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2006/03/04/introducing-onviewable/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FastrFriends Bookmarklet Version .2</title>
		<link>http://www.zelph.com/archives/2006/01/28/fastrfriends-bookmarklet-version2/</link>
		<comments>http://www.zelph.com/archives/2006/01/28/fastrfriends-bookmarklet-version2/#comments</comments>
		<pubDate>Sat, 28 Jan 2006 15:44:17 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Gaming]]></category>
		<category><![CDATA[JavaScript/DOM]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2006/01/26/fastrfriends-bookmarklet/</guid>
		<description><![CDATA[When playing the fun new game Fastr with a few friends it was difficult to see where they were in the rankings with it being so popular (100+ people in the game at a time).  So I wanted a way to easily see where they were.
So, here&#8217;s a super quick and dirty bookmarklet for [...]]]></description>
			<content:encoded><![CDATA[<p>When playing the fun new game <a href="http://randomchaos.com/games/fastr/">Fastr</a> with a few friends it was difficult to see where they were in the rankings with it being so popular (100+ people in the game at a time).  So I wanted a way to easily see where they were.</p>
<p>So, here&#8217;s a super quick and dirty bookmarklet for tracking friends while playing. This is like 30 mins of work and far from complete and perfect I&#8217;m sure.  It&#8217;s also based on the current DOM of the page, so if that changes, this breaks.  But since it&#8217;s centrally hosted I can compensate if that happens and the next time you use it after I fix it, it will work.</p>
<p>To use it, drag the following link to your toolbar, and then click that button after starting a game of Fastr.  <a href="javascript:s=document.body.appendChild(document.createElement('script'));s.id='fs';s.language='javascript';void(s.src='http://zelph.com/code/fastrfriends/fastrFriends.js');">FastrFriends</a>.  After it&#8217;s loaded up, simply click a name to follow it, and click it again to stop following it (if you got the wrong one or whatever).</p>
<p><str>Potential upgrades I&#8217;m pondering:</str></p>
<ul>
<li>Option to show/hide all users that aren&#8217;t your friends</li>
<li>Different colors depending on how high on the list they are</li>
<li><del datetime="2006-01-28T08:40:1207:00">Track their score and then show what they got on the last guess when it changes.</del></li>
</ul>
<p>I know it works in FF 1.5 and IE 6.  I&#8217;ve been told it doesn&#8217;t work in Safari but I don&#8217;t have easy access to that, so if anyone can tell me what to fix I will give it a try.  Otherwise I will try and get a hold of one at work on Monday.</p>
<p>Report any bugs here&#8230; and enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2006/01/28/fastrfriends-bookmarklet-version2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VisitorMap plugin for ShortStat</title>
		<link>http://www.zelph.com/archives/2005/11/07/visitormap-plugin-for-shortstat/</link>
		<comments>http://www.zelph.com/archives/2005/11/07/visitormap-plugin-for-shortstat/#comments</comments>
		<pubDate>Tue, 08 Nov 2005 06:45:09 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code related]]></category>
		<category><![CDATA[JavaScript/DOM]]></category>
		<category><![CDATA[Tech stuff]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2005/11/04/visitormap-plugin-for-shortstat/</guid>
		<description><![CDATA[This is just a quick plugin for ShortStat  that will put your visitors on a map using the Google Maps API.  I wanted to get a quick visualization of where visitors were coming from, without having to add more scripts to my site from some of the other services that have come up [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.zelph.com/code/visitormap/visitorMap.php"><img src="http://www.zelph.com/code/visitormap/visitorMap.png" alt="VisitorMap" style="float:left; margin:0 10px 10px 0" /></a>This is just a quick plugin for <a href="http://www.shauninman.com/plete/2004/11/shortstat-maintenance">ShortStat </a> that will put your visitors on a map using the <a href="http://maps.google.com/">Google Maps</a> <a href="http://www.google.com/apis/maps/">API</a>.  I wanted to get a quick visualization of where visitors were coming from, without having to add more scripts to my site from some of the other services that have come up lately (<a href="http://www.gvisit.com/">gVisit</a>, <a href="http://mapstats.blogflux.com/">MapStats</a>). </p>
<p>VisitorMap uses the existing information that is already saved by ShortStat.  It is meant to be a plug-n-play addition that doesn&#8217;t require any database or other changes. The only required change is in the file itself to set the <a href="http://www.google.com/apis/maps/signup.html">Google API Key</a> (free) for the folder you are installing it in to.</p>
<p>This is a quick and dirty release.  Some of the data parsing I am doing could probably be done cleaner, but it works for being a late night &#8220;for fun&#8221; project&#8230; at least for now.<br />
<span id="more-50"></span></p>
<p>The data is provided by <a href="http://www.hostip.info/">hostip.info</a> which is a &#8220;Community GEO IP Project&#8221; (thanks to <a href="http://www.codedump.com/">Randy</a> for finding it).  Basically it looks like they rely on visitors to state where IP&#8217;s are located.  So to that end, it&#8217;s not a comprehensive list.  When first testing the script, out of the 50 referers, only 18 had an entry in their database.  But this is the only site we could find that was open and free, so if anyone has a better option (that doesn&#8217;t cost an arm and a leg&#8230; or even a toe) let me know.  At the same time, because it is a free, open-source service&#8230; this may not be the best option for those with lots of traffic as they aren&#8217;t meant to be used for tons of hits.</p>
<p>Version 1.0 includes:</p>
<ul>
<li>Uses ShortStat CSS for similar look and feel</li>
<li>Click on markers for more details (referer,page visited, date/time, browser/os, location)</li>
<li>Text list of visitors with links to open the marker &#8220;balloons&#8221;</li>
<li>Toggle between a small map with the above text links and a bigger map with no link list.</li>
</ul>
<p>That&#8217;s about it&#8230; pretty simple as I said.  But it works.</p>
<p>Please let me know what you think.</p>
<p><a href="http://www.zelph.com/code/visitormap/visitorMap.php">See it in action</a><br />
<a href="http://www.zelph.com/code/visitormap/visitorMap.txt">Download the code</a></p>
<p>Thanks go out to <a href="http://www.codedump.com/">Randy Hall at Code Dump</a> for helping me test.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2005/11/07/visitormap-plugin-for-shortstat/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introducing onDOMload</title>
		<link>http://www.zelph.com/archives/2005/03/31/introducing-ondomload/</link>
		<comments>http://www.zelph.com/archives/2005/03/31/introducing-ondomload/#comments</comments>
		<pubDate>Thu, 31 Mar 2005 20:51:47 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code related]]></category>
		<category><![CDATA[JavaScript/DOM]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2005/03/18/introducing-domscheduler/</guid>
		<description><![CDATA[Today I release my first reuseable script into the wild.  Hopefully it will be found useful and can help other projects move along as well.
Thanks to the new pages function of WordPress 1.5 this will live at it&#8217;s own location, so there can be a single point of reference for any changes and such. [...]]]></description>
			<content:encoded><![CDATA[<p>Today I release my first reuseable script into the wild.  Hopefully it will be found useful and can help other projects move along as well.</p>
<p>Thanks to the new pages function of WordPress 1.5 this will live at it&#8217;s own location, so there can be a single point of reference for any changes and such.  But I will post any updates made to it here in the blog so that anyone who cares to, will know about it.</p>
<p>I will put the full text from the page here for the initial entry (and for searchability since pages aren&#8217;t searchable yet through WordPress), but all future changes will be found on the page itself.</p>
<p>Comments, feedback and suggestions are greatly appreciated.</p>
<h4>Information</h4>
<p>
<strong>Script Name:</strong> onDOMload<br />
<strong>Current version:</strong>  1.1<br />
<strong>Last Updated:</strong> 03.31.2005<br />
<strong>Download:</strong> <a href="http://zelph.com/code/ondomload/ondomload.js">onDOMload</a></p>
<h4>Purpose</h4>
<p>To allow JavaScript to run on a page after the head, but before onload and before an &#8220;at the end of the page&#8221; (in-content) JS script fires.</p>
<h4>What is it?</h4>
<p>This script starts looping trying to run it&#8217;s code until the page is done loading.  The code is continually checking for certain DOM elements to load from when the functions are called, until an onload call stops it.  Using this method, the code you want to run will happen as soon as the loop runs again after a given DOM element with a certain tag/id/class is loaded, not onload or when another in-content JS call is made at the bottom of the page.</p>
<h4>How does it work?</h4>
<p>You provide two things.</p>
<p>1 &#8211; <strong>What you want the code to be run on</strong> &#8211; You can pass an ID (#theID), a class name (div.class), an element name (td) or several, but not all, combinations of the above (div#theID h4).</p>
<p>2 &#8211; <strong>What code you want to be run</strong> &#8211; You can pass it any code that you want, as it does an eval on it when it&#8217;s time to run it.  I know that&#8217;s not super efficient, but if anyone can think of something better, please let me know. Since the code can be run multiple times, it provides a keyword of &#8220;theTarget&#8221; that references the current element being manipulated.</p>
<p>Every X milliseconds the script tries to run your code again, looking for the DOM elements you provided.  When it finds one it runs the code on it, and then keeps track of how many it&#8217;s done.  When the loop happens again it compares how many it did last time, with how many there are now.  If there are more then last time, it starts with the next newest one and runs through the rest of them.  If it doesn&#8217;t find anything new, it keeps looping and checking for new ones each time.</p>
<p>An onload is run that says the page is done loading.  It then stops the loops so that they do not continue to run as you are just looking at the page,  and does one last run just to make sure nothing showed up between the last loop and the onload.</p>
<h4>Why use it?</h4>
<p>As mentioned above, until now there have been 2 ways to fire code later on down the page.  1 &#8211; onload, which waits until every element (img,script,css,etc) has loaded on a page.  If an advertisement, or stat tracking pixel, or whatever hangs for a while&#8230; your script can&#8217;t fire yet. 2 &#8211; &#8220;in-content&#8221; reference. This is a tad better in that you can call it at the bottom of the page, and it runs as soon as it is read by the browser.  This again can potentially be slow if the page is very long, or if something server side hangs the page before it gets to it, but is definitely faster then the onload.</p>
<p>onDOMload allows code to run much sooner during the pageload.  If the code you run makes changes to the looks of the page, then this will allow it to happen much faster then the other versions will.  It also allows you to keep all your code in one location&#8230; at the top.  Instead of needing part of your code at the bottom.</p>
<h4>History</h4>
<p>I had thought of this concept dozens of times, but finally started playing with it after the <a href="http://www.themaninblue.com/writing/perspective/2004/09/29/">Man in blue</a> posted about it and gave an example.  The need for this became pressing for me when working with a <a href="http://www.zelph.com/archives/2004/06/20/using-ifr-at-sprint/">version of IFR</a> which had to wait till the end of the page to do the replacement.  We would always see the headlines loading after the page was mostly rendered, and it didn&#8217;t look all that great.</p>
<p>I have improved on The Man in Blue&#8217;s version (I hope) by adding the ability to run code on elements with a specific class, ID or just on all instances of a given element.  An earlier version of the script just had ID and tags available (the unreleased 1.0 version), but I leveraged the code from Alessandro Fulciniti&#8217;s <a href="http://pro.html.it/esempio/nifty/">Nifty Corners</a> (which are pretty dang nifty, btw) to improve the ability to direct the code.  You can also reference the current element by using &#8220;theTarg&#8221; in the passed code&#8230; kind of like a &#8220;this&#8221; call.</p>
<h4>See it in action</h4>
<p><a href="/code/ondomload/ondomload-example1.php">Example 1</a> &#8211; Several different types of schedulers on the same page.<br />
<a href="/code/ondomload/ondomload-example2.php">Example 2</a> &#8211; Example of how an in-content or onload call can delay your intended actions.</p>
<h4>Compatibility</h4>
<p>Works fine in FireFox 1.0.1, Win IE 6.0 SP2, Safari 1.0.3 (if anyone has a newer version they can confirm in, please let me know)</p>
<p>Partially works in Mac IE 5.22.  I may get this working in the future, but for now it&#8217;s not a priority.</p>
<h4>Changelog</h4>
<p><strong>03.31.2005 &#8211; 1.1</strong>  &#8211; First public release.  Fairly decent overhaul from the unreleased 1.0 version.  Added ability to go off of classes and IDs.  Added final check after onload fires.</p>
<p><strong>1.0</strong> &#8211; Never actually released</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2005/03/31/introducing-ondomload/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>IE6 png Alpha Transparency Script</title>
		<link>http://www.zelph.com/archives/2005/01/28/ie6-png-alpha-transparency-script/</link>
		<comments>http://www.zelph.com/archives/2005/01/28/ie6-png-alpha-transparency-script/#comments</comments>
		<pubDate>Fri, 28 Jan 2005 19:42:22 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript/DOM]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2005/01/28/ie6-png-alpha-transparency-script/</guid>
		<description><![CDATA[Eric Meyer just posted an updateto his s5 script  in which he has added support for alpha transparency for IE6.  The fix comes thanks to Erik Arvidsson&#8217;s pngbehavior.htc.  Very cool&#8230; sucks to have to hack around IE yet again but what are you going to do?
His one lament about this fix:
The one [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://meyerweb.com/">Eric Meyer</a> just posted an <a href="http://meyerweb.com/eric/thoughts/2005/01/28/s5-11b4/">updateto his s5 script</a>  in which he has added support for alpha transparency for IE6.  The fix comes thanks to <a href="http://webfx.eae.net/dhtml/pngbehavior/pngbehavior.html" title="PNG Behavior (WebFX)">Erik Arvidsson&#8217;s pngbehavior.htc</a>.  Very cool&#8230; sucks to have to hack around IE <strong>yet again</strong> but what are you going to do?</p>
<p>His one lament about this fix:</p>
<blockquote><p>The one sort-of drawback to using this approach is that it seems to require that the call to pngbehavior.htc sits in an embedded style sheet, or else nothing happens. This may very well have to do with the way the JavaScript monkeys around with external style sheets during startup. If any of you IE/Win JS gurus can figure out a way to get the behavior to fire without having to embed it into the presentation, that would be stellar. If not, itâ€™ll just be documented as a â€œleave this in if youâ€™re using alpha PNGs; otherwise you can take it outâ€ thing.</p></blockquote>
<p>Now I don&#8217;t pretend to be an &#8220;IE/Win JS guru&#8221; but decided to play around anyway.  Using the simpler example at the top of Erik&#8217;s page I saw what the &#8220;bare necessities&#8221; were.  Now that I go back and look at his .htc behavior closer, I see that I am doing some of what he was doing there&#8230; but just in the JS.</p>
<p>What I came up with is a quick little JS script that cycles through all the images on the page, if an image is a png (detected by the extension) then it applies the appropriate filter and replaces the image with a clear .gif file.  This eliminates the need to have any image specific references in the CSS or JS, and the need for the HTC file altogether.</p>
<p><a href="http://zelph.com/experiments/iePngTransparency.html" title="Demo page">See a demo</a> of the script in action.</p>
<p>I&#8217;d get all fancy and separate out the script and stuff for you to easily peruse, but I probably need to get back to work.  So just view source and poke around.</p>
<p>Hopefully it is found useful, and will be a help to Eric&#8217;s issue.  Thanks to Erik for the initial script and research.   Feedback is welcomed as I&#8217;m always willing to learn.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2005/01/28/ie6-png-alpha-transparency-script/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Contribution to Slayeroffice &#8211; Mouseover DOM Inspector</title>
		<link>http://www.zelph.com/archives/2004/10/25/slayeroffice-contribution-mouseover-dom-inspector/</link>
		<comments>http://www.zelph.com/archives/2004/10/25/slayeroffice-contribution-mouseover-dom-inspector/#comments</comments>
		<pubDate>Mon, 25 Oct 2004 18:58:12 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code related]]></category>
		<category><![CDATA[JavaScript/DOM]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2004/10/25/slayeroffice-contribution-mouseover-dom-inspector/</guid>
		<description><![CDATA[Steve over at Slayeroffice just posted an update to one of his &#8220;favelets&#8221; that I sent to him.  So I thought I&#8217;d do a quick write-up on how it came to be (as I&#8217;m really lacking in content these days).
We are big fans of his Favelet Suite over at Sprint, and use it daily. [...]]]></description>
			<content:encoded><![CDATA[<p>Steve over at <a href="http://www.slayeroffice.com/">Slayeroffice</a> just posted an update to one of his &#8220;favelets&#8221; that I sent to him.  So I thought I&#8217;d do a quick write-up on how it came to be (as I&#8217;m really lacking in content these days).</p>
<p>We are big fans of his <a href="http://slayeroffice.com/index.php?c=/content/tools/suite.html">Favelet Suite</a> over at Sprint, and use it daily.  One of the favelets is the <a href="http://slayeroffice.com/?c=/content/tools/modi.html">Mouseover DOM Inspector</a> (MODI) that we used more then the rest to get a nice quick look at how our CSS based pages are laying out by using the background color that MODI provides.</p>
<p>A favelet (or Bookmarklet as we usually call them here&#8230; same thing) that I had always wanted to make was one that showed the parent structure of the element you moused over.  When I finally got some time, I thought that tweaking Steve&#8217;s MODI favelet would be a natural fit.  So I snagged the parent structure parsing code from our <a href="http://www.zelph.com/archives/2004/06/20/using-ifr-at-sprint/">Sprint IFR</a> implementation and slapped it into a copy of MODI.  After a little tweaking to actually spit out the parent structure, instead of just walk up it, it was working pretty good.  Added the Height/Width while I was at it and called it good.</p>
<p>A few weeks later I was working on another project and was regularly trying to find the X,Y of a given element (X,Y finding thanks to PPK over at <a href="http://www.quirksmode.org/js/findpos.html">quirksmode.org</a>).  Eventually the lightbulb went off and I just added it to the MODI script that was fast becoming the one stop shop for everything we needed.</p>
<p>After using that for a while I finally decided to offer it up to Steve to add to his own script, so that others could use the new features as well. The  <a href="http://slayeroffice.com/index.php?c=/scripts/comment_scripts/comments2.php&#038;id=142">update</a> that I sent him was added today and now I can go back to just needing his Suite, and can remove a bookmark from my toolbar.</p>
<p>Many thanks to Steve for the great resource that he provides in the Favelet Suite (and naturally each individual Favelet).  I know it has saved us a lot of time in various circumstances, and it&#8217;s an honor to be able to contribute to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2004/10/25/slayeroffice-contribution-mouseover-dom-inspector/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>One line to rule them all</title>
		<link>http://www.zelph.com/archives/2004/09/04/one-line-to-rule-them-all/</link>
		<comments>http://www.zelph.com/archives/2004/09/04/one-line-to-rule-them-all/#comments</comments>
		<pubDate>Mon, 28 Jun 2004 17:10:58 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code related]]></category>
		<category><![CDATA[JavaScript/DOM]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2004/09/04/one-line-to-rule-them-all/</guid>
		<description><![CDATA[One line to rule them all,
one line to find them.
One line to bring them all,
and in the function bind them.
The &#8220;One Line&#8221;:
if(!foo.nodeName) foo = document.getElementById(foo);
Imagine you make, borrow or steal a function that does &#8220;something&#8221; to a given element.  The function is setup to require the ID of the element in question, so that [...]]]></description>
			<content:encoded><![CDATA[<p>One line to rule them all,<br />
one line to find them.<br />
One line to bring them all,<br />
and in the function bind them.</p>
<p>The &#8220;One Line&#8221;:</p>
<blockquote><p><code>if(!foo.nodeName) foo = document.getElementById(foo);</code></p></blockquote>
<p>Imagine you make, borrow or steal a function that does &#8220;something&#8221; to a given element.  The function is setup to require the ID of the element in question, so that you can do ye ole &#8220;getElementById&#8221; (gEBI from now on) on it to then do whatever spiffy thing you want to do to it.</p>
<p>But what if you already had already done a gEBI on this element, and the result of that is sitting in a variable just waiting to be used&#8230; why should you waste resources doing it all over again, and have a second variable with all the same information.</p>
<p>Or&#8230; reverse it.  Your function is expecting a gEBI&#8217;d var but you pass just the ID.  It won&#8217;t have the information it needs.</p>
<p>Enter the &#8220;One Line.&#8221; What the code does is check to see if the variable that was passed has an attribute (nodeName) of a gEBI&#8217;d variable (<code>if(!foo.nodeName)</code>).  If it does then it goes merrily on it&#8217;s way.  If it doesn&#8217;t, then it must have just been an ID so the line does a gEBI on it so we can do what we want to do to it (<code>foo = document.getElementById(foo);</code>).  It sets the results of the gEBI to the same variable the ID was, so the code below it is none the wiser.  Whichever thing you send to it, after this line you will have the same thing to work with.</p>
<p>Now granted&#8230; in a perfect world all your functions will be written ever so neatly and you will always remember what to send to them or it would always be one or the other.  But since we are such a generous community, and are always sharing new ideas, I&#8217;m sure your .js files are a hodge podge of functions from various people, and even various scripts that you have written previously and pulled into a new one.  The One Line levels the playing field.</p>
<p>So to sum up&#8230; this one line of code makes it so you don&#8217;t have to worry about what you send to your function.  Either an ID or a gEBI&#8217;d var will work.</p>
<p>A really lame example of a function that changes your text to red:</p>
<blockquote><p><code>function redText(theText){<br />
&nbsp;&nbsp; theText.style.color = "#f00";<br />
}</code></p></blockquote>
<p>In the above, it is looking for a gEBI&#8217;d variable to apply the style to.  So it won&#8217;t work if you just pass the ID.</p>
<blockquote><p><code>function redText(theText){<br />
&nbsp;&nbsp; if(!theText.nodeName) theText= document.getElementById(theText);<br />
&nbsp;&nbsp; theText.style.color = "#f00";<br />
}</code></p></blockquote>
<p>Using the One Line, it can now accept either an ID or a gEBI&#8217;d variable.  Everyone is happy</p>
<p>One line to rule them all,<br />
one line to find them.<br />
One line to bring them all,<br />
and in the function bind them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2004/09/04/one-line-to-rule-them-all/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Chevrolet XHTML/CSS overhaul</title>
		<link>http://www.zelph.com/archives/2004/08/23/chevrolet-xhtmlcss-overhaul/</link>
		<comments>http://www.zelph.com/archives/2004/08/23/chevrolet-xhtmlcss-overhaul/#comments</comments>
		<pubDate>Mon, 23 Aug 2004 16:20:50 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript/DOM]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2004/08/23/chevrolet-xhtmlcss-overhaul/</guid>
		<description><![CDATA[Kudos to Chevrolet for their recent XHTML/CSS overhaul.  The code is extremely clean, and they get extra brownie points for going for (and achieving) XHTML Strict compliance.
After France (who is always in the know) pointed me to the overhaul, I (naturally) went poking through their code and they are doing some sweet stuff.  [...]]]></description>
			<content:encoded><![CDATA[<p>Kudos to <a href="http://www.chevrolet.com/">Chevrolet</a> for their recent XHTML/CSS overhaul.  The code is extremely clean, and they get extra brownie points for going for (and achieving) XHTML Strict compliance.</p>
<p>After <a href="http://www.point-break.com/">France</a> (who is always in the know) pointed me to the overhaul, I (naturally) went poking through their code and they are doing some sweet stuff.  Much of it required by the strict standard not allowing things like &#8220;onclick&#8221; attributes in the code, they use the DOM to parse through all anchor tags on a page to create popup code, status bar messages, and more.</p>
<p>One thing I found weird is that they do the following at the top of each page:</p>
<blockquote><p><code>if (!document.getElementById || !document.createTextNode) { window.location.replace('/upgrade/'); }</code></p></blockquote>
<p>This is presumably to redirect older browsers to their upgrade page.  While I can understand doing this from a standpoint of locking down your audience to your selected/supported browsers, part of the advantage of an XHTML design is that older browsers can view the site in is &#8220;degraded&#8221; form and still be able to get the information they are looking for just without the bells and whistles.  This snippet of code basically eleminates that &#8220;feature&#8221; of an XHTML design, and locks those users out.</p>
<p>That minor confusion aside, this is a great looking rewrite of the site and whoever did the job (inside employees or vendor)  are to be commended for their great job.  They have been able to implement many things that we have pondered at Sprint (parsing in popup code onload, etc) and it will be intersting to see how things shake out for them over time and what others have to say about their implementation.</p>
<p><strong>Edit:</strong><br />
After posting this I went poking around my own site and saw that Chris Moritz made <a href="http://www.zelph.com/archives/2004/06/20/using-ifr-at-sprint/#comment-11">a comment</a> on my <a href="http://www.zelph.com/archives/2004/06/20/using-ifr-at-sprint/">Sprint IFR article</a>.  Wonder if they were pondering using IFR for the Chevy redesign??  Oh, and got Chris&#8217; name from a <a href="http://www.digital-web.com/news/2004/08/chevrolet_goes_valid/">Digital Web mention</a> of the redesign. </p>
<p><strong>Edit 2:</strong><br />
From <a href="http://www.tableless.com.br/mensagem.asp?id=188">another mention</a> (in portuguese) we meet antother developer (search for &#8220;thew&#8221;) who mentions yet another developer, Dave, who <a href="http://www.davezilla.com/">has a site</a>.  Hopefully Dave will put up some kind of a write-up on the launch.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2004/08/23/chevrolet-xhtmlcss-overhaul/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The ActionScript Jabberwocky</title>
		<link>http://www.zelph.com/archives/2004/08/18/the-actionscript-jabberwocky/</link>
		<comments>http://www.zelph.com/archives/2004/08/18/the-actionscript-jabberwocky/#comments</comments>
		<pubDate>Tue, 17 Aug 2004 15:28:58 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code related]]></category>
		<category><![CDATA[Spiffy stuff]]></category>
		<category><![CDATA[Tech stuff]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2004/08/18/the-actionscript-jabberwocky/</guid>
		<description><![CDATA[Someone much geekier then I, wrote the Jabberwocky in ActionScript. This is pure genious.  I can only dream of being cool enough (and geeky enough) to make up something like this.  Kudos to whoever runs turdhead.com for coming up with such beauty.
ActionScript is fairly similar to JavaScript, and if you know any programming [...]]]></description>
			<content:encoded><![CDATA[<p>Someone much geekier then I, wrote the <a href="http://www.turdhead.com/index.php?p=21" title="Bows in awe">Jabberwocky in ActionScript</a>. This is pure genious.  I can only dream of being cool enough (and geeky enough) to make up something like this.  Kudos to whoever runs <a href="http://www.turdhead.com/">turdhead.com</a> for coming up with such beauty.</p>
<p>ActionScript is fairly similar to JavaScript, and if you know any programming language you will be able to appreciate the majority of what is going on, just maybe not the fine details.  But If you know the poem well enough you may be able to get a good enough kick out of it if you are even slightly techy/geeky.</p>
<p>Found via <a href="http://slashdot.org">/.</a></p>
<p><a href="http://www.jabberwocky.com/carroll/jabber/jabberwocky.html">Jabberwocky text</a> to compare to</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2004/08/18/the-actionscript-jabberwocky/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using IFR at Sprint</title>
		<link>http://www.zelph.com/archives/2004/06/20/using-ifr-at-sprint/</link>
		<comments>http://www.zelph.com/archives/2004/06/20/using-ifr-at-sprint/#comments</comments>
		<pubDate>Tue, 25 May 2004 20:21:01 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code related]]></category>
		<category><![CDATA[JavaScript/DOM]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.zelph.com/archives/2004/06/20/using-ifr-at-sprint/</guid>
		<description><![CDATA[Introduction
This lengthy article is here to describe the process of how Shaun Inman&#8217;s IFR technique came to be used on Sprint.com and SprintPCS.com.  This is my first write-up of the process involved in implementing a major new standard, and I didn&#8217;t take the notes I should have along the way&#8230; so please bear with [...]]]></description>
			<content:encoded><![CDATA[<h4>Introduction</h4>
<p>This lengthy article is here to describe the process of how <a href="http://www.shauninman.com/" title="My hero">Shaun Inman</a>&#8217;s IFR technique came to be used on <a href="http://www.sprint.com/">Sprint.com</a> and <a href="http://www.sprintpcs.com/">SprintPCS.com</a>.  This is my first write-up of the process involved in implementing a major new standard, and I didn&#8217;t take the notes I should have along the way&#8230; so please bear with me.</p>
<p><span id="more-11"></span></p>
<p>While the majority of <a href="http://www.shauninman.com/mentary/past/ifr_an_fir_alternative.php" title="The goods are released to the world">Shaun&#8217;s IFR script</a> (<a href="http://www.shauninman.com/mentary/past/ifr_revisited_and_revised.php" title="The goods become gooder">revised</a>) has been re-written for our own use, the basic concepts are already described in his articles above about how it works.  Not all of our pages are updated to use the flash headings yet, and may not be for some time (CMS integration and the like).  On Sprint.com, the <a href="http://www.sprint.com/business/" title="Recently XHTML-ized">business section</a> is using it, and on SprintPCS.com most of the shop side is using it (ex: <a href="http://www1.sprintpcs.com/explore/ueContent.jsp?scTopic=servicesFeatures" title="Whole section is using it">1</a>, <a href="http://www.sprintpcs.com/sitemap/" title="sprintpcs.com sitemap">2</a>, <a href="http://www1.sprintpcs.com/explore/PhonesAccessories/PhoneDetails.jsp?selectSkuId=samsungvi660" title="PCS Phone details">3</a>, <a href="http://www1.sprintpcs.com/explore/ueContent.jsp?scTopic=specialOffers" title="Special Offers - whole section">4</a>, <a href="http://www1.sprintpcs.com/explore/ueContent.jsp?scTopic=greatPhonesServices" title="Why Sprint?">5</a>), but not Manage (yet).</p>
<p>This all started when Shaun first launched IFR on his site, not his official documented launch linked above, but when he first started using it on his site.  A co-worker, <a href="http://www.point-break.com/" title="Sprints resident CSS/Standards Evangelist">France</a>, noticed it and sent me the link.  We were quite impressed and discussed how cool it would be to use on our sites here at work.  At that time we used one of the first <a href="http://www.stopdesign.com/articles/replace_text/">FIR</a> techniques for all H1&#8217;s and H2&#8217;s across the site which ended up being hundreds of titles and the maintenance was insane.</p>
<p>We discussed it kind of as a cool concept and left it at that, thinking that the &#8220;powers that be&#8221; wouldn&#8217;t go for such a prominant Flash element being used across the site.  But when I went home that night, I couldn&#8217;t enjoy my TV shows, I couldn&#8217;t game (*sigh*) and I couldn&#8217;t sleep because I couldn&#8217;t get the concept out of my head.  It was ruining my life. I came back in the next morning and spent every extra second I had on figuring out how I could make it work for us.  I went through every line of his script and picked it apart to see what made it tick.  In the end, I thought that it was something that was doable.</p>
<h4>Difficulties abound</h4>
<p>After making an initial draft of the script and discovering that I actually had a clue about what was going on in it, we started coming up with issues that we would need to overcome for it to work on our site.  Several of them we thought were insurmountable, and would make it so that we couldn&#8217;t complete the project.  But thanks to many great discussions where we just talked things out, and bounced ideas off of each other, we were able to overcome each problem that was presented.  This was a great testament to working as a team and not being afraid to ask for help.  I will go through each of the problems that I can remember, and what we did to overcome them.</p>
<ul>
<li><strong>Special Characters</strong> &#8211; The most troubling issue we saw at the outset was the need to compensate for was our extensive use of special characters in our copyrighted, registered, trademarked, and service marked product names.  This is where I first went to our resident Flash guru Lars Hacking to see what he thought.  This one gave us the biggest hang up.  He had some great ideas, and started tinkering in his free time at how to make it happen.  To compensate for characters that are not easily passed into flash, I check for those characters and replace them with characters we are fairly certain that we won&#8217;t need as themselves (ie: ~`{}[]).  Then on the Flash side, Lars takes them and puts in what it is supposed to be there.</li>
<li><strong>Our grid</strong> &#8211; Our site is based on a grid that we must follow.  We have 3 columns for the content, and a given module can span 1, 2 or 3 of those columns.  So the swf files had to vary in width to fit in the size of module they were currently in.  To do this I walk up the DOM structure (many thanks to PPK and his <a href="http://www.quirksmode.org/">invaluable site</a>) checking the className&#8217;s of each parent until I find one with one of our specific class names that designate width.  Once that is found (and I know which one it is), I can set the width that I have to work with and go from there.</li>
<li><strong>Underlined H2&#8217;s</strong> &#8211; We have two different kinds of titles, plain text, and underlined.  To compensate for this I did the same DOM walking above to see if we were inside of a container that had the className that would dictate an underlined version.</li>
<li><strong>Two-line H2&#8217;s</strong> &#8211; We have some instances where we allow our graphical h2&#8217;s to wrap to two-lines.  Using the same technique that Lars uses for counting in the flash, I find the actual width of the text in question (by character, specific to our font) and if it is greater then the width found in &#8220;Our grid&#8221; above I know to switch to the 2-line .swf version.  We do not allow 2-line underlined headings, so luckily we didn&#8217;t have to compensate for that mixture. As an FYI, H1&#8217;s are not allowed more then one line either.</li>
<li><strong>Error headings</strong> &#8211; Our error module has different font and background colors.  I again walk the DOM to find the container we are in, and then pass along the hex of the colors to be used for this given module.  The flash then applies the passed colors to the output.</li>
<li><strong>FOUC</strong> &#8211; We noticed (as did Shaun&#8217;s readers) that there was a breif Flash Of Unstyled Content before the flash headings kicked in.  To compensate for this, immediately after the flash version check is done, we load a .css file that updates the headings to be white text so that they are not seen.  So we aren&#8217;t really eliminating the FOUC, but changing it to something that you can&#8217;t really see.  We also add a second script (could be a few lines really, but using a remote script gives us better future control) to the end of the page that tells the Flash functions to fire.  This saves us a little more time by firing before the &#8220;onload&#8221; goes, just in case a single graphic is holding things up or something.  We set a variable to make sure that we don&#8217;t run it again &#8220;onload&#8221;.  This way the second file is optional, and can only help if it is used.</li>
<li><strong>Content behind the flash</strong> &#8211; Our H1&#8217;s sometimes sit on top of graphics.  To be more pleasing to the eye, the graphics will some times come up into the H1 row, when there is room for it to do so.  With Flash transparency not being completely sound, we couldn&#8217;t just allow the H1 swf to go the full width of the module overlapping the parts of the image that came up into the H1 space.  We had to use the text width determination mentioned above to determine the width of the text and then call an associated swf file that was sized close to that width (rounded up to the nearest 10px).  So we had 20 some odd templates for each width between 170-360.</li>
</ul>
<h4>Selling it to the people in authority</h4>
<p>After getting the majority of the above squared away so that we could be confident in saying that this is a solution that we could accomplish, we set up a meeting with our Web Standards comittee to show them this crazy idea.  Some of the points we were sure to make are as follows:</p>
<ul>
<li>Stats for our site say that more then 90% of our visitors had the Flash version we were targeting</li>
<li>This would save tons in labor costs</li>
<li>This would make our turn around time much faster</li>
<li>There would be graceful degredation for those without flash, using our accepted &#8220;non-image&#8221; standards</li>
<li>There would be very limited code impact, as all we have to do is add the call to the .js file on any page we want it to work on.  No need to go back to each heading and edit anything (as long as the page was built following our established structure)</li>
<li>Did we mention the large reduction in cost??? =)</li>
</ul>
<p>We must have put just enough &#8220;stuff&#8221; in their coffee cause they said &#8220;ok&#8230; go ahead and test it&#8221;.  So we put up a few test pages in production to see if anyone would notice, or complain.  We asked some visitors if anyone saw any issues on the pages in question.  A few noticed the FOUC, but after the fixes were put in place mentions of that problem went away.  Only one user (at sprintusers.com) noticed that we were using Flash, and that was because he had an extension on Mozilla that put an icon on any Flash elements on the page (asked him in a PM about it for those who can&#8217;t find mention in the thread).</p>
<p>After a few weeks of the above, we met again to discuss the results.  We had received no complaints, were able to show the results from the above informal forum polls, and had a few improvements to show over our first meeting.  They continued to like it (nothing in the coffee this time) and said they would take it to the people who paid the bills.  Since bill payers like numbers, below are some of the numbers we provided to give to them. These numbers are just educated guesses, and I am not sure how far off from reality they are.</p>
<p><strong>Bandwidth</strong><br />
26 K Savings in shop.css code (when we finally remove all reference to graphic titles)<br />
8 k Savings in heads.css code (when we finally remove all reference to graphic titles)<br />
20 K Savings in the actual graphics (average of .5k each X 40 titles per session [total guess])</p>
<p>54 K Total savings per visitor</p>
<p>With an average of 8 Million visitors per month, if on the low end we figure that they each download things only once, and then it&#8217;s cached for the rest of the monthâ€¦ we save 432 Gig a month of traffic.  With a conservative estimate of $1.00 per Gig, that is $5,000 in annual savings.  If we go to the other extreme and say there is NO caching, and every file is downloaded every time, we are looking at 7,000 Gig savings a month, for an annual savings of $84,000. The true amount lies somewhere in between.</p>
<p><strong>Server Load</strong><br />
We will be switching from 3-5 unique titles per page, to 6 total files that will cache for all pages.  Doing some math off the top of my head, that should save us 472 Million file loads per month (130 Million page views per month  X 4 titles per page = 520 Million vs 8 Million visitors X 6 files  = 48 Million files loaded).  This doesn&#8217;t even consider the <a href="http://weblogs.mozillazine.org/hyatt/archives/2003_12.html#004504">Safari bug</a> that loads all 300-500 graphics each time they view a page that won&#8217;t be an issue any more.  I can&#8217;t venture to guess how this will effect server performance, and how that transfers into a dollar amount.</p>
<p>While we were in beta testing with this project, Shaun released his articles on how to implement his IFR solution.  We were able to gleen a few tidbits from the article to reduce our flash file count from 40+ to 6 or so which helped alot.</p>
<p>The above are based off our current standing. It does not consider additional titles and size associated with them that could be added throughout the year.</p>
<p><strong>Work load</strong><br />
Guesses that are probably on the low side:</p>
<ul>
<li>VizD&#8217;s save 30-40 hrs a year</li>
<li>Code save 60-80 hrs a year</li>
</ul>
<p>If you did a conservative estimate of the time to create, cutout, save, add to code, add to stylesheet, test, check in, etcâ€¦ for each title,  we figure around a total of 5 minutes per image.</p>
<p>An example: A recent <a href="http://www.point-break.com/waves/in-the-cove/wwwsprintcombusiness-a-css-mega-relaunch/" title="France's write-up on the launch">business site re-launch</a>, which consolidated and simplified 7,000 pages, started with the flash titles from the get-go.  In the end they had 1,253 H1&#8217;s and 3,841 H2&#8217;s.  At the above average of 5 minutes per imageâ€¦ that is over 400 hours of time saved.  If you figure a professionals time at $50/hr that is a $20,000 savings for this project alone. (wish I could say the check was in the mail Shaun&#8230; but you know how it goes;)</p>
<p>After all of the above, we got approval to move forward with using it on the site and it has become a standard to be used across the comapny.  Naturally something like this doesn&#8217;t happen over night, so we have been updating what we can, when we can.  The above business site launch was a huge proof for the technique in both ease of use, and cost savings.  More pages will come online as they are edited, and as we find ways to get it put into existing Content Management Systems.</p>
<h4>Bring it on home</h4>
<p>To sum up&#8230; our old process for adding a new title was along the lines of the following:</p>
<ol>
<li>Put text inside of h1 or h2 tag</li>
<li>Try and find the title we wanted in our current list of titles in the .css file (an occasionally alphabetized list, that had a few different naming conventions introduced to it as we went along)</li>
<li>If we didn&#8217;t find it in the list, request the title from our Visual Designers</li>
<li>Get the image from VizD, rename as appropriate and place in the correct folder</li>
<li>Add a line to the .css file with a unique ID for this title.</li>
<li>Add the above ID to the .html file</li>
<li>Check the .html, .css and .gif file into cvs</li>
<li>Since the above are in different directoriesâ€¦ go back and check in the ones you missed or forgot to flag correctly.</li>
<li>&#8220;Enjoy&#8221; the fruits of our labor</li>
</ol>
<p>The new process</p>
<ol>
<li>Put text inside of h1 or h2 tag</li>
<li>Check .html into cvs</li>
<li>Enjoy the fruits of our labor</li>
</ol>
<p>Gotta love the simplicity.</p>
<p>Thanks and praise go to Shaun and his innovative thinking and willingness to share with the community (even though I was trying to steal it before he offered it up *gulp*). While our script is 99% re-written, it is still IFR at it&#8217;s heart.  Many thanks also go to all those involved with this project at Sprint for making it happen.  In no particular order&#8230; <a href="http://www.point-break.com/" title="One more link for good measure">France</a>, Lars, Candice, Jenney and Kirk.</p>
<p>If anyone actually reads this, maybe I&#8217;ll do a future article breaking down the actual code and why I did things the way I did&#8230; then the REAL guru&#8217;s can come in and tell me how to do it better =)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zelph.com/archives/2004/06/20/using-ifr-at-sprint/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
