<?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>dooza.tv &#187; spry</title>
	<atom:link href="http://www.dooza.tv/tag/spry/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dooza.tv</link>
	<description>The online adventures of dooza</description>
	<lastBuildDate>Wed, 01 Feb 2012 21:42:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spry External Link Icon</title>
		<link>http://www.dooza.tv/2009/12/spry-external-link-icon.html</link>
		<comments>http://www.dooza.tv/2009/12/spry-external-link-icon.html#comments</comments>
		<pubDate>Tue, 08 Dec 2009 21:03:41 +0000</pubDate>
		<dc:creator>Dooza</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[spry]]></category>

		<guid isPermaLink="false">http://www.dooza.tv/?p=794</guid>
		<description><![CDATA[

This is the first bit of code that I have created that I think is good enough to share. I didn&#8217;t come up with this on my own, I drew inspiration from this blog post, and had some help from V1 over at the Adobe Spry Forum.
This simple bit of JavaScript will give your external [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.dooza.tv%252F2009%252F12%252Fspry-external-link-icon.html%22%2C%20%22shorturl%22%3A%20%22http%3A%2F%2Fbit.ly%2F8Ev2SZ%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Spry%20External%20Link%20Icon%22%20%7D);"></div>
<p><img class="alignleft size-full wp-image-797" title="Spry Logo" src="http://www.dooza.tv/wordpress/wp-content/uploads/2009/12/SpryLogo.JPG" alt="Spry Logo" width="250" height="136" />This is the first bit of code that I have created that I think is good enough to share. I didn&#8217;t come up with this on my own, I drew inspiration from <a href="http://pinoytech.org/blog/post/Add-Icons-to-External-Links-with-Mootools-and-CSS">this blog post</a>, and had some help from V1 over at the <a href="http://forums.adobe.com/community/labs/spry">Adobe Spry Forum</a>.</p>
<p>This simple bit of JavaScript will give your external links on your page an icon to indicate that you will be leaving the site. I previously would have done this using a CSS selector that targeted all links in a paragraph that had the target attribute set to &#8220;_blank&#8221;, but I wanted a fool-proof way of doing this without having to remember to set the target.</p>
<h2>How does it work?</h2>
<p>It works by manipulating the DOM using the Spry Dom Utils JS. It creates an observer that on page load adds the class called &#8220;external&#8221; to all links that are on a different domain.</p>
<p>To use it, just put this in your head section:</p>
<pre name="code" class="html">&lt;script src="SpryAssets/SpryDOMUtils.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="SpryAssets/SpryExternalLinkIcon.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;link href="SpryAssets/SpryExternalLinkIcon.css" rel="stylesheet" type="text/css" /&gt;</pre>
<p>The first file is from the current Spry library.</p>
<p>The second is my custom code, and the third is a small bit of CSS.</p>
<p>This is SpryExternalLinkIcon.js:</p>
<pre name="code" class="javascript">function externalLinkIcon(){
  Spry.$$("a").forEach(function(href) {
  	if( href.hostname != window.location.host ){
  Spry.Utils.addClassName( href, 'external');}
  });
}
Spry.Utils.addLoadListener(externalLinkIcon);</pre>
<p>This is SpryExternalLinkIcon.css</p>
<pre name="code" class="css">.external {
    background: url('external.png') 100% 60% no-repeat;
    padding:  0 15px 0 0;
}</pre>
<p>Now any link that is on a different domain will get assigned the class &#8220;external&#8221;, which in turns puts an external link icon at the end of it.</p>
<h2>Demo</h2>
<p>You can see what I have been talking about here: <a href="http://www.dooza.tv/spry/SpryExternalLinkIcon.html">http://www.dooza.tv/spry/SpryExternalLinkIcon.html</a></p>
<h2>Download</h2>
<p>You can download the files here: <a href="http://www.dooza.tv/spry/SpryExternalLinkIcon.zip">http://www.dooza.tv/spry/SpryExternalLinkIcon.zip</a></p>
<h2>Conclusion</h2>
<p>Using JavaScript to add this icon is <a href="http://www.alistapart.com/articles/understandingprogressiveenhancement">progressive enhancement</a>, the page doesn&#8217;t break, the link still works, but in browsers with JavaScript support you get the added functionality of an icon that helps the visitor recognise an external link. The visitor might want to open the link in another tab or window, knowing its an external link before having to click it will save time.</p>
<p>I would love to hear your opinions on this little bit of code that I have presented here. There aren&#8217;t many Spry tutorials or blogs about, which is a shame, its got potential.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 170px; width: 1px; height: 1px;">
<pre id="line1"><a href="view-source:http://www.ac-et.com/SpryAssets/SpryDOMUtils.js">/SpryAssets</a></pre>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dooza.tv/2009/12/spry-external-link-icon.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

