<?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>Neo-Archaic Blog &#187; javascript</title>
	<atom:link href="http://neo-archaic.ie/blog/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://neo-archaic.ie/blog</link>
	<description></description>
	<lastBuildDate>Mon, 25 May 2009 19:07:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>More IE Madness &amp; Object Swap Goes OOP</title>
		<link>http://neo-archaic.ie/blog/2008/02/more-ie-madness-object-swap-goes-oop/</link>
		<comments>http://neo-archaic.ie/blog/2008/02/more-ie-madness-object-swap-goes-oop/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 18:25:10 +0000</pubDate>
		<dc:creator>Karina</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.neo-archaic.net/2008/02/06/more-ie-madness-object-swap-goes-oop.htm</guid>
		<description><![CDATA[A couple of days ago, having just installed a new version of the Flash player in Internet Explorer, I tested recent updates to an ongoing Flash project. Imagine my amazement when, instead of an interactive Flash exhibition, I got a notice that my Flash version was not up to date. Thinking that maybe something went [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago, having just installed a new version of the Flash player in Internet Explorer, I tested recent updates to an ongoing Flash project. Imagine my amazement when, instead of an interactive Flash exhibition, I got a notice that my Flash version was not up to date. Thinking that maybe something went wrong with the recent installation, I went to the Adobe website and reinstalled. Still, no luck.<br />
ObjectSwap has a nifty param line for version checking, and in this project it looks like this:</p>
<blockquote><p><code>&lt;param name="flashVersion" value="8" /&gt; </code></p></blockquote>
<p>The current flash version in my browser is: 9,0,115,0, and up until now, the version checking code worked in such a way that if the version declared in the param is lower than or equal to the installed version, the Flash content will be displayed, and otherwise you get the alternate content &#8211; in this case, a request to download the latest player. After playing around with it, I saw that either I had to change the version to 9 in the param, or remove it altogether. In other words, all of a sudden, IE requires the exact flash version of the <strong>player</strong>, rather than the version of the <strong>movie</strong>. Madness&#8230;<br />
<span id="more-30"></span></p>
<p>The workaround for that, was to include an iteration of version checking in the script &#8211; first, you check for the movie&#8217;s version, as defined in the param, if that fails, you increase the version three times, until you either get a success, or all four attempts fail.</p>
<blockquote>
<pre>} else if (this.ie &amp;&amp; typeof (ActiveXObject) == "function"){
   //IE flash detection.
   //Try 3 versions higher than specified
   var maxCount = Number(version) + 3;
   for(var i=version; i&lt;=maxCount; i++){
      try{
         var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
         return true;
      }
      catch(e){
        //continue
     }
  }
  return false;
}</pre>
</blockquote>
<p>Unfortunately, this is not one hundred percent future proof. If you&#8217;re publishing for 8, you might want to keep an eye on it after version 11. Unless, of course, IE recognises it as a bug and fixes it for later updates. Shall we all have a breath-holding competition?</p>
<p>In the meantime, this fix seems to work for IE7 and amazingly didn&#8217;t break in IE6 when I was showing the aforementioned project on a client&#8217;s PC. Miracles do happen.</p>
<p>Ok, so this is the bugfix issue. The second subject of this conversation, is the complete redesign of the ObjectSwap script, so it now uses objects, prototype functions, namespaces, and general best practices of OOP. Perhaps even more importantly, it now uses DOM event listeners instead of window.onload event.</p>
<p>The new code was written in July, and together with the latest bug fix, I feel it&#8217;s about time to release the update.</p>
<p>So here it is: <a id="p31" href="http://blog.neo-archaic.ie/wp-content/uploads/2008/02/ObjectSwap_download_080206.zip">Object Swap Updates</a></p>
]]></content:encoded>
			<wfw:commentRss>http://neo-archaic.ie/blog/2008/02/more-ie-madness-object-swap-goes-oop/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XHTML Definition List Tree</title>
		<link>http://neo-archaic.ie/blog/2007/02/definition-list-tree/</link>
		<comments>http://neo-archaic.ie/blog/2007/02/definition-list-tree/#comments</comments>
		<pubDate>Mon, 19 Feb 2007 23:15:09 +0000</pubDate>
		<dc:creator>Karina</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.neo-archaic.net/2007/02/19/definition-list-tree.htm</guid>
		<description><![CDATA[Seeing as the Neo-Archaic logo is a tree, I just couldn&#8217;t resist adding a JavaScript tree component to the GrannySmith blog. The need for a tree-view arose when I was adding a FAQ page to the Pediatric Center website. I didn&#8217;t want a long scrolling page, and it appeared to be a tedious affair to [...]]]></description>
			<content:encoded><![CDATA[<p>Seeing as the Neo-Archaic logo is a tree, I just couldn&#8217;t resist adding a JavaScript tree component to the GrannySmith blog.</p>
<p>The need for a tree-view arose when I was adding a <a href="http://www.belilovskypediatrics.com/en/faq.htm">FAQ page</a> to the Pediatric Center website. I didn&#8217;t want a long scrolling page, and it appeared to be a tedious affair to create all those internal links and anchors. A treeview structure seemed ideal for a FAQ, but then I couldn&#8217;t find anything usable on google (At this point you might say that my google skills could do with some polishing, and come up with a list of wonderful scripts that I completely overlooked&#8230;), and besides, good clean dynamic xhtml is still not that easy to come by.</p>
<p>The result is a Definition List Tree component &#8211; That is, a bit of JavaScript code that you can add to your page to create a treeview component out of a humble DL.<br />
<span id="more-27"></span><br />
<strong>The Definition List xhtml:</strong></p>
<p>The script will operate on any definition list on the page that has the class attribute &#8220;tree&#8221;, and ignore all others. If you&#8217;d rather use a differnt className or operate on all DLs regardless of class, you could change the init() function so it either uses another className, or passes a null &#8211; in which case all definition trees on the page will be affected. You can call your tree a &#8220;spade&#8221; if you like, but I call my tree a &#8220;tree&#8221;.</p>
<p>Each term/definitions pair should only have one &lt;dt&gt; tag with its text enclosed in a hyperlink, and a single &lt;dd&gt; tag.</p>
<p>The &lt;dd&gt; tag can then include other html structures, such as paragraphs, tables, other lists etc.</p>
<p>The resulting tree structure can be used for multiple purposes, such as FAQs, sitemaps, menus, directories and other listings.</p>
<p><strong>For example:</strong></p>
<blockquote>
<pre>&lt;dl class="tree"&gt;
&lt;dt&gt;&lt;a href="#"&gt;Are you open on the weekends? &lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;The Brooklyn (Brighton) office is open all weekends, all holidays,
and in all weather conditions.&lt;/dd&gt;
&lt;dt&gt;&lt;a href="#"&gt;Do you accept my insurance?&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;If we do NOT accept your insurance, it is either (a) because it is
very rarely seen in the areas we cover, or (b) because it endangers the
health of the patients it covers by making essential services difficult
to obtain. &lt;a href="insurances.htm"&gt;Click here for a partial
listing of insurances we accept&lt;/a&gt;.&lt;/dd&gt;
&lt;/dl&gt;</pre>
</blockquote>
<p><strong>The JavaScript:</strong></p>
<p>The DLTree script needs to be linked at the head of the html page in the usual manner:</p>
<blockquote>
<pre>&lt;script language="JavaScript" type="text/javascript"
src="scripts/DLTree.js"&gt;&lt;/script&gt;</pre>
</blockquote>
<p>Â &#8230;and is executed with the window.onLoad event, using a function that works without conflicting with the window.onload event of any preceding scripts.</p>
<p>At the top of the script, there are a few customisable variables:</p>
<blockquote>
<pre>//Icon images
var plus = "url(images/plus.gif)"
var minus = "url(images/minus.gif)"
//Padding for the icons
var padding = "14px"</pre>
</blockquote>
<p>These variables refer to the plus and minus icons that display the state of each node &#8211; <em>plus</em> to expand a collapsed node, and <em>minus</em> to collapse it. You need to create your own graphics here and place them in the images folder. The url for images can be changed here to suit your own folder structure, and is relative to the <em>html document</em>, rather than the javaScript. The images can be safely omitted, or designed to look like anything that indicates tree nodes. The <code>padding</code> variable corresponds to the space that the image takes up, including a bit of horizontal padding (for example, padding of 14 for an image of 12 pixels).</p>
<p><strong>Expand All / Collapse All:</strong></p>
<p>To expand &amp; collapse all the nodes in the tree, you can add two links to the top or bottom of your page:</p>
<blockquote>
<pre>&lt;p&gt;&lt;a href="#" onclick="expandDLTree('tree')"&gt;
Expand All&lt;/a&gt;&amp;nbsp; &amp;#8226; &amp;nbsp; &lt;a href="#"
onclick="initDLTree('tree')"&gt; Collapse All&lt;/a&gt;&lt;/p&gt;</pre>
</blockquote>
<p><strong>Examples and Download:</strong></p>
<p>The downloadable example contains a simplified excerpt from the <a href="http://www.belilovskypediatrics.com/en/faq.htm">Belilovsky Pediatric Center FAQ</a> page, and contains all the xhtml and JavaScript mentioned above, including the treeview icons.</p>
<p><a id="p28" href="http://blog.neo-archaic.ie/wp-content/uploads/2007/02/DLTree.zip">Download the DLTree code and examples</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://neo-archaic.ie/blog/2007/02/definition-list-tree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NoCache for JavaScript and Flash</title>
		<link>http://neo-archaic.ie/blog/2006/08/nocache-for-javascript-and-flash/</link>
		<comments>http://neo-archaic.ie/blog/2006/08/nocache-for-javascript-and-flash/#comments</comments>
		<pubDate>Wed, 02 Aug 2006 22:55:46 +0000</pubDate>
		<dc:creator>Karina</dc:creator>
				<category><![CDATA[actionscript2]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.neo-archaic.net/2006/08/02/nocache-for-javascript-and-flash.htm</guid>
		<description><![CDATA[I just spent a very frustrating day wrangling with cached images. Both JavaScript and Flash have trouble updating dymanic images, when these are cached by the browser. This can be a problem if, for example, your website has sets of images, such as catalogues, that could be updated at any time. Or if the website [...]]]></description>
			<content:encoded><![CDATA[<p>I just spent a very frustrating day wrangling with cached images. Both JavaScript and Flash have trouble updating dymanic images, when these are cached by the browser. This can be a problem if, for example, your website has sets of images, such as catalogues, that could be updated at any time. Or if the website needs to constantly reload a single image with the same filename, such as a self-updating webcam image.</p>
<p>In my case, it was both. After delving into numerous Internet sources, with some trial and even more error, I finally distilled a solution that, with slight adjustments, works for both JavaScript and Flash.<br />
<span id="more-26"></span></p>
<p><strong>The basic principle</strong> is to trick the browser into thinking that a different image, with a different name, is being loaded. This can be achieved by appending a constantly changing variable into the url of the loaded image:</p>
<blockquote><p><code>myImage.jpg?nocache=" + new Date().getTime();</code></p></blockquote>
<p>The <code>getTime() </code>method of the Date object returns the number of milliseconds since January 1, 1970 to this date, (or another date specified in the instance). This is perfect for us, because this means that you get a unique number, each time &#8211; unless you can refresh faster than a speeding millisecond&#8230;</p>
<p>You could also play with the Date object&#8217;s methods and exchange <code>getTime() </code>for <code>getHours() </code>or <code>getDate()</code>. This would refresh the images every hour or every day, keeping them in the cache for the current session, which could be useful in some instances.</p>
<p><strong>In JavaScript</strong> all you need now is to assign this to the src property of an image, for example:</p>
<blockquote><p><code>var cam1 = document.getElementById("cam1");<br />
cam1.src = "../images/cam1.jpg?nocache="<br />
+new Date().getTime();</code></p></blockquote>
<p>If you trace out the resulting src or nameProp of the image (I tend to use alerts for this), the returned string will include the url encoding &#8211; but will display the correct image, fresh from the HTTP oven.</p>
<p><strong>In Flash </strong>you&#8217;d use essentially the same syntax, but it&#8217;s slightly more complicated. If you attempt to load an image with this url from the IDE, it won&#8217;t find the image and will return an error instead. However, it will work fine when embedded in a browser.</p>
<p>To make it work in both, you need to test for the playerType first, before adding the url encoded variable:</p>
<blockquote>
<div></div>
<p><code></p>
<pre>var loader:MovieClipLoader;
var viewLoader:MovieClip;
var url:String = "images/catalogue/collection/cat1.jpg";
if (System.capabilities.playerType == "PlugIn"
|| System.capabilities.playerType == "ActiveX"){
      url+="?nocache="+new Date().getTime();
}
loader.loadClip (url, viewLoader);</pre>
<p> </p>
<p> </p>
<p></code></p></blockquote>
<p><strong>This solution </strong>is not only limited to images &#8211; it can also be used when loading other file types that you wouldn&#8217;t like cached, such as XML, SWFs and other files or assets.</p>
]]></content:encoded>
			<wfw:commentRss>http://neo-archaic.ie/blog/2006/08/nocache-for-javascript-and-flash/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>NavSwap: Semantic XHTML Menus into Designer Images</title>
		<link>http://neo-archaic.ie/blog/2006/07/navswap-semantic-xhtml-menus-into-designer-images/</link>
		<comments>http://neo-archaic.ie/blog/2006/07/navswap-semantic-xhtml-menus-into-designer-images/#comments</comments>
		<pubDate>Sat, 29 Jul 2006 16:10:40 +0000</pubDate>
		<dc:creator>Karina</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.neo-archaic.net/2006/07/29/navswap-semantic-xhtml-menus-into-designer-images.htm</guid>
		<description><![CDATA[The Problem: If you are a web designer who tries to combine high standard graphic design with top-notch web-standards xhtml, you can&#8217;t escape a certain degree of conflict of interests. This can be especially acute when it comes to designing a menu. You want it to have a strong graphic look, elegant and glossy, and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The Problem:</strong><br />
If you are a web designer who tries to combine high standard graphic design with top-notch web-standards xhtml, you can&#8217;t escape a certain degree of conflict of interests. This can be especially acute when it comes to designing a menu. You want it to have a strong graphic look, elegant and glossy, and yet you&#8217;d rather use a semantic xhtml list with text links.</p>
<p>Your life might get somewhat easier when it comes to headings, with various <a href="http://www.alistapart.com/articles/fir/">CSS Image Replacement techniques.</a> But they&#8217;re not perfect either, and for menus you need be able to hyperlink the image.</p>
<p><strong>Available Solutions</strong></p>
<ol>So what can you do?</p>
<li>Use CSS to format your textual menu to it&#8217;s best abilities, using the same old fonts and maybe a background image to make it look nicer. Don&#8217;t even think about using an interesting font like Arcitectura, or adding some layer effects in PhotoShop, because then you&#8217;ll have to use images.</li>
<li>Employ images, which is not very semantic and requires you to add lots of additional markup, such as <em>img </em>and <em>alt</em> tags, and then you&#8217;ll need to add JavaScript calls for rollovers, and change the image of the current menu item on each page. What&#8217;s next? Design with tables&#8230;?</li>
<li>Design a Flash navigation bar, which is again not very semantic, SO friendly, or accessible. I&#8217;ve nothing against Flash, in fact, I I&#8217;m a huge fan. It can be used to great effect to add an extra dimension to the website with animation and interactivity. But just like salt and pepper, you need to know when to <em>stop </em>adding it. Graphics or drop down menus are not a good enough reason for a Flash menu &#8211; these can always be accomplished by dhtml. A Flash navigation needs to be exceptional (or at least quite interesting) to justify itself, and even then you&#8217;ll need to add textual navigation somewhere on the page, at least for the search engines.</li>
</ol>
<p>Most of my xhtml websites up to date have been achieved with the first method. Take a look at <a href="http://www.neo-archaic.net">my own website</a>, for example &#8211; it uses CSS and background images for formatting, and the font defaults to a generic serif. Even then, it took a lot of work and a bit of extra markup to achieve the look.</p>
<p><strong>NavSwap:</strong><br />
My latest website project (not yet published as this goes to &#8220;print&#8221;, but soon to come) is for a glossy fashion wholesaler, and that meant top-notch graphics, even for the menu. For this I came up with option #4 &#8211; NavSwap, which happens to be the object of this article. It took some code wrangling to write, but is quite easy to implement.<br />
<a id="p25" href="http://blog.neo-archaic.net/wp-content/uploads/2006/07/navSwap.zip">You can download the script and examples here&#8230;</a></p>
<p>NavSwap serves two functions:</p>
<ol>
<li>Swaps semantic xhtml into images, using unobtrusive JavaScript. That is, if JavaScript is unsupported, you get an xhtml text menu, otherwise you get images, complete with alt tags generated on the fly.</li>
<li>Automatically swaps images on rollovers and swaps the current menu item with an active state item on each page.</li>
</ol>
<p><span id="more-23"></span><br />
<strong>The html markup:</strong></p>
<blockquote><p><code>&lt;ul class="nav" id="nav"&gt;<br />
&lt;li&gt;&lt;a href="index.htm"&gt;Home&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="about.htm"&gt;About&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="awards.htm"&gt;Awards&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="emporium.htm"&gt;Emporium&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="suppliers.htm"&gt;Suppliers&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="contact.htm"&gt;Contact&lt;/a&gt;&lt;/li&gt;<br />
&lt;/ul&gt;</code></p></blockquote>
<p>This is mostly all the html you will require. The script will cycle through the menu items and use each item&#8217;s text value for the name of the image that will be replaced (converted to lowercase, with extension and directory path added), and also uses it to generate the alt text.<br />
If, however, your menu item&#8217;s text requires spaces, characters or markup unsuitable for file names, or is duplicated across menus (with different images), or for any other reason, you can assign a className to the item&#8217;s to override it. For example:</p>
<blockquote><p><code>&lt;li&gt;&lt;a href="joinus.htm" class="joinus" &gt;Join Us &lt;/a&gt;&lt;/li&gt;</code></p></blockquote>
<p>You can also add an <em>id</em>to the <em>body </em>tag. The id&#8217;s value should correspond to the text of the menu item, or the overriding className. This will mark the page as active, and the script will automatically change the image of the corresponding item to the active state:</p>
<blockquote><p><code>&lt;body id="home"&gt;</code></p></blockquote>
<p><strong>Organising The Images:</strong><br />
Next, you&#8217;ll need to prepare the images using PhotoShop or your favourite image editing software. You will need to create images for two or three different states, using the same file names (home.jpg, about.jpg etc.) but organised in different directories:</p>
<ol>
<li><strong>Up:</strong> The images as they appear in their normal, or &#8220;up&#8221; state.<br />
Default directory: &#8220;<strong>images/nav_up/</strong>&#8220;.</li>
<li><strong>Over:</strong> The rollover images.<br />
Default directory: &#8220;<strong>images/nav_over/</strong>&#8220;.</li>
<li><strong>Active:</strong> The active images for each page. By default, the script uses the Over images for the Active state. But it is possible to create separate images for this purpose, by switching a variable in the script.<br />
Default directory: &#8220;<strong>images/nav_over/</strong>&#8221; &#8211; but can be changed, for example, to: &#8220;images/nav_active/&#8221;.</li>
</ol>
<p>These paths are user-customisable by passing the through the following variables in the navSwap.js file:</p>
<blockquote><p><code>var navUpPath = "images/nav_up/";<br />
var navOverPath = "images/nav_over/";<br />
var navActivePath = "images/nav_over/";<br />
</code></p></blockquote>
<p>- Or by passing the new directory paths to the <em>navSwap()</em> method (see below).</p>
<p>The names of the images should be the same throughout the directories, and consistent with the text of the menu items. For example:</p>
<blockquote><p><code>&lt;li&gt;&lt;a href="index.htm"&gt;Home&lt;/a&gt;&lt;/li&gt;<br />
--&gt; home.jpg<br />
&lt;li&gt;&lt;a href="about.htm"&gt;About&lt;/a&gt;&lt;/li&gt;<br />
--&gt; about.jpg<br />
</code></p></blockquote>
<p><strong>The JavaScript:</strong><br />
The text menu will be swapped for the images using JavaScript. To do this, you need to add the link to the external script to the head of the page:</p>
<blockquote><p><code>&lt;script type="text/javascript"<br />
src="scripts/navSwap.js"&gt;&lt;/script&gt; </code></p></blockquote>
<p>And place a call to the method right after the menu:</p>
<blockquote><p><code>&lt;script type="text/javascript"&gt;<br />
navSwap("nav", 90, 30, "jpg", "images/nav_up/", "images/nav_over/");<br />
&lt;/script&gt;</code></p></blockquote>
<p>For each menu or submenu in your document you need to use a separate call to the navSwap method, passing the following optional parameters: (id, w, h, suffix, upPath, overPath, activePath):</p>
<ol>
<li><strong>id:</strong> The id of the menu &lt;ul&gt; that is to be replaced. If this parameter is not passed it defaults to &#8220;nav&#8221;. However, it can be particularly useful if you have multiple menus or submenus. Each of these will need its own id.</li>
<li><strong>w:</strong> Width of the images that replace the menu. The images should all be the same width if this parameter is used.</li>
<li><strong>h:</strong> Height of the images that replace the menu. The images should all be the same height if this parameter is used.</li>
<li><strong>suffix:</strong> The default is &#8220;.jpg&#8221;, but could be changed to &#8220;.gif&#8221; or &#8220;.png&#8221;.</li>
<li><strong>upPath:</strong> The up state images path.</li>
<li><strong>overPath:</strong> The over state images path.</li>
<li><strong>activePath:</strong> The active state images path.</li>
</ol>
<p>The script works with multiple menus, as long as each has it&#8217;s own id, so you could combine this method with <a href="http://www.alistapart.com/articles/dropdowns/">drop-down menus</a> and other techniques.</p>
<p><strong>Design Issues</strong><br />
Of course, menus don&#8217;t always come in the shape of a list, so you will need some CSS formatting to finish off the look. You can use CSS to position the menu, add margins or padding, and maybe change it from vertical to horizontal ( <code>.nav li {display:inline}</code>).</p>
<p>Also, since we&#8217;re adding the JavaScript unobtrusively, you could add a bit of extra styling to the menu with CSS, to make it look as good as it can when JavaScript is disabled.</p>
<p>Unfortunately, I couldn&#8217;t find a way to detect if images are disabled in the browser. If anyone knows how to do that, please let me know. If, however, images are disabled, this technique at least ensures that you see their alt tag replacements instead. This looks better in Firefox than in IE, but at least it&#8217;s still useable.</p>
<p><strong>Examples and download:</strong><br />
<a href="http://blog.neo-archaic.ie/wp-content/uploads/2006/07/navSwap.htm">You can see the example in action here.</a></p>
<p><a id="p25" href="http://blog.neo-archaic.ie/wp-content/uploads/2006/07/navSwap.zip">The script, example and all supporting files can be downloaded here.</a>. If you want to have a look under the hood, the script is commented throughout.</p>
<p>I hope you find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://neo-archaic.ie/blog/2006/07/navswap-semantic-xhtml-menus-into-designer-images/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>ObjectSwap Revisited</title>
		<link>http://neo-archaic.ie/blog/2006/06/objectswap-revisited/</link>
		<comments>http://neo-archaic.ie/blog/2006/06/objectswap-revisited/#comments</comments>
		<pubDate>Wed, 14 Jun 2006 09:56:26 +0000</pubDate>
		<dc:creator>Karina</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.neo-archaic.net/blog/2006/06/14/objectswap-revisited.htm</guid>
		<description><![CDATA[Hi everyone, Since the ObjectSwap article appeared on this blog in April, the code has changed a number of times. To reflect those changes, and give you a bit more insight on how to use it, I bundled up a few ObjectSwap Examples together with the script: In addition to that, I sent an updated version [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>Since the <a href="http://www.neo-archaic.ie/blog/2006/04/objectswap/">ObjectSwap article</a> appeared on this blog in April, the code has changed a number of times. To reflect those changes, and give you a bit more insight on how to use it, I bundled up a few <a id="p21" href="http://www.neo-archaic.ie/blog/wp-content/uploads/2006/06/ObjectSwap_download.zip">ObjectSwap Examples</a> together with the script:</p>
<p>In addition to that, I sent an updated version of the article to SitePoint, and I&#8217;m happy to announce that it&#8217;s been recently published: <a title="Link to 'ObjectSwap: Bypassing the ActiveX Activation Issue in IE'" href="http://www.sitepoint.com/article/1535" target="_blank">ObjectSwap: Bypassing the ActiveX Activation Issue in IE</a>.</p>
<p>I hope this script has been as useful to you as it has been to me. Thank you for your great feedback and for your patience with all the changes and bugfixes. I hope that no more will be necessary, but if there are, please let me know.</p>
<p>Karina</p>
]]></content:encoded>
			<wfw:commentRss>http://neo-archaic.ie/blog/2006/06/objectswap-revisited/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>ObjectSwap: Bypassing the ActiveX Activation Issue in Internet Explorer</title>
		<link>http://neo-archaic.ie/blog/2006/04/objectswap/</link>
		<comments>http://neo-archaic.ie/blog/2006/04/objectswap/#comments</comments>
		<pubDate>Tue, 25 Apr 2006 13:56:48 +0000</pubDate>
		<dc:creator>Karina</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.neo-archaic.net/blog/2006/04/25/objectswap.htm</guid>
		<description><![CDATA[The Problem: Microsoft&#8217;s decision to change the way ActiveX objects are handled in Internet Explorer, following the patent law suit by EOLAS, has left the developer community in uproar. Soon all the ActiveX controls in Internet Explorer, among them Flash and Shockwave, will need to be activated by a click or a tab and an [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The Problem: </strong></p>
<p>Microsoft&#8217;s decision to change the way ActiveX objects are handled in Internet Explorer, following the patent law suit by EOLAS, has left the developer community in uproar. Soon all the ActiveX controls in Internet Explorer, among them Flash and Shockwave, will need to be activated by a click or a tab and an enter key before they can interact with the control. This is bound to impair the user experience of any website that embeds Flash &#8211; and there are many such sites out there - and make a good deal of trouble for the Flash developers, who are left to clean up the mess.</p>
<p><strong>Available Solutions: </strong></p>
<p>You can bypass the activation requirement by using an externally linked script, such as JavaScript, to embed the ActiveX content. There are currently available solutions for Flash, such as <a href="http://blog.deconcept.com/swfobject">SWFObject</a> and <a href="http://www.bobbyvandersluis.com/ufo">UFO</a>. These work well for embedding new Flash content using JavaScript. But what about existing &lt;object&gt; tags, which will need to be rewritten, or browsers with disabled JavaScript? These would require an alternative solution.</p>
<p><strong>ObjectSwap: </strong></p>
<p>Neo-Archaic&#8217;s ObjectSwap solution (downloadable from <a href="http://www.neo-archaic.net/scripts/objectSwap.js">www.neo-archaic.net/scripts/objectSwap.js</a>) takes all these issues into account. It captures all existing &lt;object&gt; tags and replaces them with themselves. This forces an automatic activation in Internet Explorer, while leaving other browsers alone. <a href="http://www.unfocus.com/projects/PatentMagic/)">Similar solutions</a> have been developed in parallel, but this article will only concern itself with ObjectSwap. Although this solution was developed primarily with Flash in mind, it should also work with other ActiveX controls, such as Shockwave. The script affects all the &lt;object&gt; tags in the page, but the user can exclude specific objects by setting their class name to  &#8221;noswap&#8221;.</p>
<p><span id="more-12"></span></p>
<p><strong>Implementation: </strong></p>
<p>ObjectSwap was written with a view to make implementation as easy as possible, with minimum disruption to existing code. The only change needed to your html page is placing the script in the &lt;head&gt; tag for every page that includes ActiveX objects, like this:</p>
<blockquote>
<pre>&lt;script type="text/javascript" src="scripts/objectSwap.js"&gt; &lt;/script&gt;</pre>
</blockquote>
<p>After that, you can keep on using your favourite technique for embedding ActiveX content. For Flash it&#8217;s either the Adobe/Macromedia default setting using object/embed tags, or the standards compliant technique that uses only the object tag (better known as <a href="http://www.alistapart.com/articles/flashsatay/">Flash Satay</a>).</p>
<p><strong>How it Works: </strong></p>
<p>First, the script cycles through all the &lt;object&gt; tags in the html source code and retrieves their outerHTML value:</p>
<blockquote>
<pre>var objects = document.getElementsByTagName ('object');
for (var i=0; i&lt;objects.length; i++){
  var o = objects[i];
  var h = o.outerHTML;</pre>
</blockquote>
<p>Since Internet Explorer does not include any of the Object&#8217;s param tags in its outerHTML (or innerHTML), they need to be extracted separately into a string:</p>
<blockquote>
<pre>var params = "";
for (var j = 0; ji&lt;o.childNodes.length; j++) {
	var p = o.childNodes[j];
	if (p.tagName == "PARAM"){
			....
		params += p.outerHTML;
	}
}</pre>
</blockquote>
<p>The generated  &#8220;params&#8221; string is spliced into the outerHTML code:</p>
<blockquote>
<pre>var tag = h.split("&gt;")[0] + "&gt;";
var newObject = tag + params + o.innerHTML + " ";</pre>
</blockquote>
<p>And, finally, the new generated html replaces the original:</p>
<blockquote>
<pre>o.outerHTML = newObject;</pre>
</blockquote>
<p><strong>Hiding The Objects: </strong></p>
<p>There are still a few things to be done. First of all, we want to prevent the objects from loading twice - once when they are initiated in the html code, and again after they are swapped. This is achieved by writing a new stylesheet to the document before the page loads. The style uses display:none to take the object out of the document&#8217;s flaw and delay their loading until the swap is complete:</p>
<blockquote>
<pre>document.write ("&lt;style id='hideObject'&gt; object {display:none;} &lt;/style&gt;");</pre>
</blockquote>
<p>After the swap, the style is disabled and the objects are allowed to load:</p>
<blockquote>
<pre>document.getElementById("hideObject").disabled = true;</pre>
</blockquote>
<p><strong>Initiating The ObjectSwap: </strong></p>
<p>The function must be called after all the objects have loaded by binding the objectSwap() function to the window.onload event. The catch, however, is that other linked scripts in your page might have their functions bound to the same event; the last script to do so will override all the earlier bindings, causing other scripts to fail. This is resolved by catching existing functions bound to the event, and calling them as well:</p>
<blockquote>
<pre>var tempFunc = window.onload;
window.onload = function(){
	if (typeof (tempFunc) == "function"){
		try{
			tempFunc();
		} catch(e){}
	}
	objectSwap();
}</pre>
</blockquote>
<p>This will naturally fail if following scripts use window.onload, so you must ensure that either this script comes last, or the following scripts use a similar technique.</p>
<p><strong>Flash Detection: </strong></p>
<p>So far, so good. But since we&#8217;re already using JavaScript, why not avail of the opportunity to add some Flash Detection to the mix? This can be achieved by adding a new param definition to the flash object, for example:</p>
<blockquote>
<pre>&lt;param name="flashVersion" value="6" /&gt;</pre>
</blockquote>
<p>As it cycles through the parameters list, the script checks for the existence of this param and, if it finds it, calls the flash detection method. If it doesn&#8217;t find the Flash plugin, or the installed version number is less than the one required, the code turns the object into a simple &lt;div&gt; and displays the alternative content. This content must already reside inside the &lt;object&gt; tag, and display alternative text, images, links to the Flash installer, and so forth. The object tag normally ignores this content if Flash is present. Of course, you can also chose to ignore the flash detection option or use Adobe&#8217;s express installation for Flash 8 instead.</p>
<p><strong>Browser Support: </strong></p>
<p>The activation issue of ActiveX objects affects only Internet Explorer, and so most of the code will only affect IE. The flash detection code, however, needs to work with other browsers as well. This means that the objectSwap() function will be called for all the browsers, perform the flash detection service if required, but will only execute the Object Swap on IE, leaving other browsers unaffected.</p>
<p><strong>Examples and Download: </strong></p>
<p>You can find an example of this code in use on <a href="http://www.neo-archaic.net/">the Neo-Archaic home page</a> and the <a href="http://www.neo-archaic.net/images.htm">images page in the gallery</a>. Both pages use the Flash Satay method to embed Flash. The script is located here: <a href="http://www.neo-archaic.net/scripts/objectSwap.js">http://www.neo-archaic.net/scripts/objectSwap.js </a>.</p>
<p>A new examples bundle (<em>last updated in Februray 2008</em>) can be found here:<a id="p21" href="http://blog.neo-archaic.net/wp-content/uploads/2008/02/ObjectSwap_download_080206.zip"> ObjectSwap Update</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://neo-archaic.ie/blog/2006/04/objectswap/feed/</wfw:commentRss>
		<slash:comments>56</slash:comments>
		</item>
	</channel>
</rss>
