<?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:georss="http://www.georss.org/georss" 
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>bioneural.net &#187; javascript</title>
	<atom:link href="http://www.bioneural.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bioneural.net</link>
	<description>bioneural.net is for stuff worth sharing: commentary by Bruce McKenzie. Major topics covered are gadgets, informatics, Internet, Mac, mobile, musings, New Zealand, photography, Project Koru, quicklinks, rant, rave, travel and Windows</description>
	<pubDate>Thu, 08 May 2008 19:36:56 +0000</pubDate>
	
	<language>en</language>
	<image>
		<title>bioneural.net</title>
		<url>http://www.bioneural.net/images/kiwi-yellow-64px.png</url>
		<link>http://www.bioneural.net</link>
		<width>64</width>
		<height>64</height>
		<description>bioneural.net</description>
	</image>
		<item>
		<title>iBox now at version 2</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F03%2F12%2Fibox-now-at-version-2%2F&amp;seed_title=iBox+now+at+version+2</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F03%2F12%2Fibox-now-at-version-2%2F&amp;seed_title=iBox+now+at+version+2#comments</comments>
		<pubDate>Wed, 12 Mar 2008 19:02:21 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Quicklinks]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/03/12/ibox-now-at-version-2/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>A customised version of <a href="http://gamma.ibegin.com/ibox/" rel="external">iBox</a> is used extensively on bioneural.net (e.g. the Flickr photocast <a href="http://www.bioneural.net/extra/">here</a>) and <a href="http://www.ibegin.com/" rel="external">iBegin</a> have just released version 2. This free JavaScript lets you display automatically scaling images, external documents, or embedded containers in an overlay dialog without needing to reload the page. iBox has gained some weight since v1.2.1 (2006) but remains compact compared to other Lightbox-alike solutions and just as simple to use, now boasting wider browser support and new plug-in capabilities (e.g. for embedding <a href="http://www.youtube.com/" rel="external">YouTube</a> videos). In most cases it degrades gracefully when JavaScript is disabled (it won't display hidden inline containers; JavaScript is required to play YouTube videos).</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F03%2F12%2Fibox-now-at-version-2%2F&amp;seed_title=iBox+now+at+version+2/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>How to safely inject CSS3 using jQuery</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F14%2Fhow-to-safely-inject-css3-using-jquery%2F&amp;seed_title=How+to+safely+inject+CSS3+using+jQuery</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F14%2Fhow-to-safely-inject-css3-using-jquery%2F&amp;seed_title=How+to+safely+inject+CSS3+using+jQuery#comments</comments>
		<pubDate>Thu, 14 Feb 2008 14:14:56 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/02/14/how-to-safely-inject-css3-using-jquery/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>So you fancy using some of that &uuml;ber-cool draft CSS3 that <a href="http://webkit.org/" rel="external">WebKit</a> browsers can handle, such as text shadows, drop shadows, opacity and rounded corners? But at the same time you want to present only valid CSS to the W3C CSS <a href="http://jigsaw.w3.org/css-validator/" rel="external">Validator</a>? It's a dilemma, but it is possible to have your cake and eat it too&mdash;albeit by hiding CSS in JavaScript and thus cheating the Validator. However, there is even a precedent for doing so.<br />
<span id="more-829"></span></p>
<p>During the course of researching my review of the <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">various</a> <a href="http://www.bioneural.net/2008/02/13/corners-gradients-and-shadows-with-jquery/">ways</a> to make rounded corners, drop shadows, and gradients I learned more about <a href="http://www.w3.org/TR/css3-roadmap/" rel="external">CSS3</a> and the <a href="http://jquery.com/" rel="external">jQuery</a> JavaScript library. They just needed introducing to one another.</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/effects.jpg" width="450" height="376" alt="effects.jpg"/><br /><span class="caption">Text shadows, drop shadows, and round corners in Safari 3</span></p>
<h4>A historical precedent</h4>
<p>The concept of tricking the Validator to pass CSS that is incorrectly implemented or proprietary and not part of the W3C spec is not new. Many web developers have found it necessary to employ various hacks in their CSS to accommodate differences in the way browsers interpret the rules. Others have used proprietary code to overcome limitations or quirks in the way some browsers handle certain content. For example, the following in your document head could be used to fix IE6's lack of handling for transparent PNGs and mis-handling of the box model, floats, overflow, <a href="http://www.bioneural.net/2008/02/01/ie6-italics-and-overflow-issues/">italics</a>, etc.:</p>
<pre><code>&lt;!--[if lte IE 6]&gt;
	&lt;style type="text/css"&gt;
	#pnglogo {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src='../logo-trans.png'); padding-top: 57px; }
	&lt;/style&gt;
	&lt;link rel="stylesheet" type="text/css" media="screen" href="../ie6-patches.css" /&gt;
&lt;![endif]--&gt;</code></pre>
<p>It's a hack: there's no other term for it. In the above example we're using proprietary conditional comments and filters to fix proprietary cock-ups. Seems fair, doesn't it?</p>
<p>So, if we can hack our way to supporting inferior or out-dated browsers, why should we not also employ hacks to support leading-edge browsers like Safari 3 that are already capable of rendering much of that draft CSS3 goodness? </p>
<h4>Using jQuery's CSS injector</h4>
<p>There are probably multiple JavaScripts that let you load CSS via the <a href="http://www.w3.org/DOM/" rel="external">DOM</a>, but since I'm using jQuery anyway that's how I've chosen to do it. If you don't have jQuery installed go <a href="http://docs.jquery.com/Downloading_jQuery" rel="external">get</a> it and load it in your document head e.g.:</p>
<pre><code>&lt;script type="text/javascript" src="../jquery-1.2.3.pack.js"&gt;&lt;/script&gt;</code></pre>
<p>Below this we create a <code>$(document).ready()</code> <a href="http://docs.jquery.com/Events/ready#fn" rel="external">function</a> so that the contents load via the DOM and hopefully before the page content is displayed. Inside this function our "content" consists of a series of CSS <a href="http://docs.jquery.com/Selectors" rel="external">selectors</a> (inside the first bracket) paired with the CSS properties we wish to inject (name and value, comma-separated) joined via <a href="http://docs.jquery.com/CSS/css#namevalue" rel="external">.css</a>. Example:</p>
<pre><code>&lt;!-- Have jQuery inject WebKit CSS via DOM on selected elements --&gt;
&lt;script type="text/javascript"&gt;
	$(document).ready(function(){
	$("h1").css("text-shadow","black 0.2em 0.3em 0.2em");
	$(".description").css("text-shadow","black 0.2em 0.3em 0.2em");
	$("#page").css("-webkit-box-shadow","#333 0px 5px 10px");
	$("#footer").css("-webkit-box-shadow","#333 0px 5px 10px");
	$(".container").css("-webkit-box-shadow","#333 0px 5px 10px");
	$(".container").css("-webkit-border-radius","10px");
});
&lt;/script&gt;</code></pre>
<p>If you had a div with the class "container koru", for <a href="http://www.bioneural.net/category/project-koru/">example</a>, Safari 3 will blend the above box-shadow and border-radius styling (as inline CSS3) with any additional CSS2.1 styling for .container or .koru present in your stylesheet. You can see what's going on using that browser's <a href="http://webkit.org/blog/122/webkit-3-10-new-things/" rel="external">Web Inspector</a>:</p>
<p><img src='http://www.bioneural.net/wp-content/uploads/2008/02/s3-inspector.jpg' alt='web-inspector' /></p>
<p class="info"><em>Note</em>: A -webkit- or -moz- prefix on CSS properties is used respectively by the Safari and Mozilla/Firefox browsers to indicate tentative support for as yet non-ratified web standards. Thus <code>-webkit-border-radius: 10px;</code> and <code>-moz-border-radius: 10px;</code> are both potentially differing implementations of "<a href="http://www.w3.org/TR/2005/WD-css3-background-20050216/#the-border-radius" rel="external">border-radius</a>".</p>
<p>OK, so the "how" is easy. Now the "Should you?"</p>
<h4>The positives</h4>
<p class="for">Effects are rendered without requiring images.</p>
<p class="for">Effects are rendered without requiring add-on JavaScript effects libraries.</p>
<p class="for">Effects are rendered without increasing page size or load time.</p>
<p class="for">Effects are rendered that may be impossible with some JavaScript or image-based techniques (e.g. anti-aliasing, liquid layout support).</p>
<p class="for">Effects can be targeted at specific web browser engines.</p>
<p class="for">No changes to semantic mark-up are required.</p>
<p class="for">Your stylesheets remain W3C-valid (if they were before!).</p>
<p class="for">Browsers simply ignore CSS properties they don't understand, so degradation is graceful.</p>
<p class="for">If JavaScript is disabled browsers will still load your stylesheets, so degradation is graceful.</p>
<p class="for">It is compatible with template-based websites in not requiring page-specific effects scripts to be inserted into mark-up.</p>
<p class="for">When the -webkit- or -moz- prefix gives way to the real deal of W3C-ratified CSS3 we can simply remove the script and move the content to our stylesheet without having to re-design effects elements or edit any mark-up.</p>
<p class="for">If you don't start using CSS3 now you might have retired before it becomes W3C-ratified.</p>
<h4>The negatives</h4>
<p class="against">Turning off your stylesheet does not disable styling loaded via the DOM.</p>
<p class="against">Effects can be targeted at specific web browser engines (like browser-targeting, a double-edged sword that undermines the uniformity of the "web experience").</p>
<p class="against">It could be construed as cheating. It is.</p>
<p>What are your views, if you have any, on the merits or otherwise of this technique?</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F14%2Fhow-to-safely-inject-css3-using-jquery%2F&amp;seed_title=How+to+safely+inject+CSS3+using+jQuery/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Corners, gradients and shadows with jQuery</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F13%2Fcorners-gradients-and-shadows-with-jquery%2F&amp;seed_title=Corners%2C+gradients+and+shadows+with+jQuery</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F13%2Fcorners-gradients-and-shadows-with-jquery%2F&amp;seed_title=Corners%2C+gradients+and+shadows+with+jQuery#comments</comments>
		<pubDate>Wed, 13 Feb 2008 15:36:40 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/02/13/corners-gradients-and-shadows-with-jquery/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>Previously we <a href="http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/">looked</a> at moving to jQuery, and then at the best way to do corners and gradients using a variety of <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">techniques</a> (Part 1). In this follow-on article (Part 2) I want to share how jQuery can be extended for similar cornering, gradient, and drop shadow visual effects. Although my JavaScript ability is not much beyond "cut and paste" the idea here is to share how easy it is to create these effects for other folk possessed by similar (in)ability.<br />
<span id="more-826"></span></p>
<h4>Situation recap</h4>
<p>In <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">Part 1</a> we explored various ways to make rounded corners, comprising one or more of JavaScript, CSS, Flash, and SVG. Ditto for drop shadows. Implementing a gradient was restricted to the use of background (or inline) images, or to SVG. There are a few more tricks we might try for gradients:</p>
<ul>
<li>We could load a transparent PNG as a CSS background and vary the fill colour on the container to allow for a multitude of colour-graduated boxes without further image editing (see this ALA <a href="http://www.alistapart.com/articles/supereasyblendys" rel="external">article</a>);</li>
<li>Unfortunately the CSS 3 draft as of this writing doesn't include background gradients, but you might be able to fake it using <a href="http://www.css3.info/preview/colored-border/" rel="external">border-color</a>;</li>
<li>We could use JavaScript effects libraries.</li>
</ul>
<p>It turns out we can use JavaScript to create our corners and drop shadows too. There's also a <a href="http://blue-anvil.com/archives/anti-aliased-rounded-corners-with-jquery" rel="external">plugin</a> for using <a href="http://www.curvycorners.net/" rel="external">curvyCorners</a> with jQuery that more than halves the standalone curvyCorners code size.</p>
<h4>Extending jQuery</h4>
<p>While there are some basic <a href="http://docs.jquery.com/Effects" rel="external">effects</a> (hide, toggle, slide, etc.) and manipulation options in the jQuery core API, jQuery <a href="http://ui.jquery.com/" rel="external">UI</a> is a bolt-on library of interactive controls that deal with mouse interaction (e.g. resizing, dragging) and other "user interface" extensions. As of this writing the jQuery documentation is incomplete and the developers in the process of transitioning visual effects formerly included in jQuery UI to a new sister library called jQuery <a href="http://ui.jquery.com/enchant/" rel="external">Enchant</a>. The controls (also referred to as core interaction plugins, UI widgets, or components) are themselves are almost invariably dependent on other jQuery extensions&mdash;needing at least the <a href="http://jquery.com/plugins/project/dimensions" rel="external">Dimensions</a> plugin.</p>
<p>So jQuery needs to get its act together in respect of naming conventions, but perhaps this is more indicative of active development rather than lack of direction? I guess jQuery UI/ Enchant are to jQuery as <a href="http://script.aculo.us/" rel="external">script.aculo.us</a> is to <a href="http://prototypejs.org/" rel="external">Prototype</a>. In a nutshell we're saying that with some jQuery code that in turn requires a bit more extra code in order to work, in addition to the code that is "jQuery" itself&mdash;we can create visual elements like drop shadows! jQuery is thus readily extendible; to use these extra bits of code you just need to load the relevant add-on script in your document head, after having loaded jQuery itself. A picture may help:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/jquery.jpg" width="383" height="326" alt="jquery.jpg" /></p>
<h4>Test cases</h4>
<p>I've used the same basic test box from Part 1, so our core document structure looks like this:</p>
<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;jQuery test cases&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;script type="text/javascript" src="jquery-1.2.3.pack.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="jquery.dimensions.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="jquery.corner.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="jquery.gradient.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="fx.shadow.js"&gt;&lt;/script&gt;
&lt;style type="text/css"&gt;
	...
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
// &lt;![CDATA[
	$(document).ready(function() {
	...
	});
// ]]&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class="className"&gt;
	&lt;h4&gt;Lorem ipsum&lt;/h4&gt;
	&lt;p&gt;Lorem ipsum dolor...&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>With all the necessary libraries loaded we can start adding effects to our div by calling them within <code>$(document).ready()</code> (in place of ... above).</p>
<p class="download">Download the test files <a href="http://www.bioneural.net/docs/jquery-tests.zip">here</a> (.zip archive, 27KB).</p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/jquery-tests/jquery-test.html">live</a> link.</p>
<h4>Case 1: Round corners</h4>
<p>If you wanted to use fancy images to produce round corners yet avoid extra mark-up, you could use <a href="http://15daysofjquery.com/wrap-it-up-pretty-corners/13/" rel="external">this</a> technique. Alternatively use no images at all via the jQuery corner plugin, available <a href="http://jqueryjs.googlecode.com/svn/trunk/plugins/corner/jquery.corner.js" rel="external">here</a>. The plugin supports a variety of corner types and borders as you can see in the <a href="http://malsup.com/jquery/corner/" rel="external">demos</a>. The following call will add cornering with a radius of 20px to a div with the class .cornered:</p>
<pre><code>$('div.cornered').corner("20px");</code></pre>
<p>This will have the following effect on our test box:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/rounded.jpg" width="265" height="346" alt="rounded.jpg" /></p>
<h4>Case 2: Gradients</h4>
<p>The Element gradient plugin, available <a href="http://plugins.jquery.com/project/elementgradient" rel="external">here</a>, will fill an element (e.g. div) with a linear gradient of specified direction (horizontal or vertical only) and opacity. It requires the <a href="http://plugins.jquery.com/project/dimensions/" rel="external">Dimensions</a> plugin. The following call will add a vertical gradient from black to white with 40% opacity to a div with the class .gradient:</p>
<pre><code>$('div.gradient').gradient({ topcolor: '#000000', bottomcolor: '#ffffff', horizontal: false, opacity: 40 });
</code></pre>
<p>This will have the following effect on our test box:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/gradient.jpg" width="262" height="344" alt="gradient.jpg" /></p>
<p>Note that you can't shorten the hex-code (it must be #ffffff not #fff for white, for example).</p>
<p class="info"><em>Tip</em>: If you leave the gradient as black to white with some opacity you can create colour gradients much more easily but changing only the background colour of the container. This is a jQuery version of the ALA super-easy blendy backgrounds <a href="http://www.alistapart.com/articles/supereasyblendys" rel="external">trick</a>.</p>
<h4>Case 3: Borders</h4>
<p>Back to the jQuery corner plugin; it can also do borders using nested elements i.e. one rounded box inside another. So our mark-up could be edited thus:</p>
<pre><code>&lt;div class="xtra"&gt;
&lt;div class="border"&gt;
	&lt;h4&gt;Lorem ipsum&lt;/h4&gt;
	&lt;p&gt;Lorem ipsum dolor...&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</code></pre>
<p>But we don't want to edit our mark-up do we? We don't have to.</p>
<p class="info"><em>Tip</em>: We can make use of <a href="http://docs.jquery.com/Manipulation/wrap#html" rel="external">.wrap()</a> to inject the extra container into our mark-up on-the-fly with JavaScript.</p>
<p>The following calls will add a wrapper div with the class .xtra to our box, then proceed to round our inner box (.border) with a radius of 15px, before padding .xtra with 5px of "border" (whitened with CSS on .xtra) and rounding with a 20px radius:</p>
<pre><code>$('div.border').wrap("&lt;div class='xtra'&gt;&lt;/div&gt;");
$('div.border').corner("15px").parent().css('padding', '5px').corner("20px");</code></pre>
<p>This will have the following effect on our test box:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/border.jpg" width="274" height="356" alt="border.jpg" /></p>
<h4>Case 4: Drop shadows</h4>
<p>In researching this article I came across three ways to create drop shadows using jQuery:</p>
<ul>
<li><a href="http://edgarverle.com/shadow/default.cfm" rel="external">Shadow</a> is an extension that uses tables with multiple rows subject to CSS styling including varying opacity to create a drop shadow illusion;</li>
<li>A <a href="http://15daysofjquery.com/wrap-it-up-lazy-mans-html-generation-with-jquery/10/" rel="external">method</a> that uses images and "onion skin" CSS added via <a href="http://docs.jquery.com/Manipulation/wrap#html" rel="external">.wrap()</a> to add a drop shadow;</li>
<li>UI/Shadow.</li>
</ul>
<p><a href="http://docs.jquery.com/UI/Shadow" rel="external">UI/Shadow</a>, available to download <a href="http://dev.jquery.com/view/trunk/fx/fx.shadow.js" rel="external">here</a>, is being folded into the yet-to-be-released jQuery Enchant library. It wraps your element in nested divs and uses opacity to create the shadow effect. It also requires the <a href="http://plugins.jquery.com/project/dimensions/" rel="external">Dimensions</a> plugin. The following call will add a drop shadow to a div with the class . dropshadow:</p>
<pre><code>$('div.dropshadow').shadow({ color: "#444", offset: 5, opacity: 0.2 });</code></pre>
<p>This will have the following effect on our test box:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/dropshadow.jpg" width="269" height="350" alt="dropshadow.jpg" /></p>
<h4>Combining effects and liquid layouts</h4>
<p>As you can see while the effects in cases 1&ndash;4 work well enough on their own, they sadly don't play together very well (<a href="http://www.bioneural.net/wp-content/uploads/2008/02/jquery-tests/jquery-test.html">see</a> Case 5). Whether this is a limitation in one or more of the plugins, or in my scripting know-how I'm not sure.</p>
<p>It is possible to create a rounded box with a border that adjusts to change in text size or window width, but using an image to render the gradient (<a href="http://www.bioneural.net/wp-content/uploads/2008/02/jquery-tests/jquery-test.html">see</a> Case 6). Because the Dimensions plugin employs absolute positioning, effects that use it (gradients, drop shadows) will "detach" from their elements if you try resizing your browser window or changing text size (see the effect on cases 2, 4, and 5).</p>
<h4>The final score</h4>
<p>To be fair I guess we should use the same scoring system to evaluate jQuery against the other methods we explored in <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">Part 1</a>.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported (as image or scripted).</p>
<p class="for"><em>Four rounded corners</em>: Yes.</p>
<p class="for"><em>Border</em>: Yes (without extra mark-up).</p>
<p class="for"><em>Drop shadow</em>: Yes (without images).</p>
<p class="for"><em>Minimal mark-up</em>: Extra containers in mark-up can be avoided with <code>.wrap()</code>.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to insert box-specific script.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="against"><em>Anti-aliasing</em>: No.</p>
<p class="against"><em>Small footprint</em>: 29KB for jQuery plus 19KB for add-on libraries (background images additional). Of course if you're already using jQuery you need only consider the additional size of any add-ons (e.g. shadows for 6KB).</p>
<p class="for"><em>Graceful degradation</em>: Renders as per the master if JavaScript disabled but liquid layouts may cause problems if width is set on containers added with <code>.wrap()</code>.</p>
<p class="for"><em>Liquidity</em>: Yes, with the proviso that you avoid Dimensions-reliant effects.</p>
<p>Score: 9/12 (probably less, because of problems combining effects)</p>
<p>Not enough to de-throne CSS 3 which <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">scored</a> 11/12, or 12/12 if it were a standard. But CSS 3 isn't here yet and won't be widely supported by all major browsers for some time. jQuery is here, however, and JavaScript is widely supported. </p>
<p>Upon reflection there's something to be said for the elegant simplicity and refined geometry of straight lines and sharp corners. This is how the Dwarves would choose to build websites, leaving curves and soft edges to the Elves. So the ultimate question, really, is do you relate more to Gimli or Legolas? Your answer to that, Middle-earthlings, will decide the direction you should take ;-)</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F13%2Fcorners-gradients-and-shadows-with-jquery%2F&amp;seed_title=Corners%2C+gradients+and+shadows+with+jQuery/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>The best way to do corners and gradients</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F06%2Fthe-best-way-to-do-corners-and-gradients%2F&amp;seed_title=The+best+way+to+do+corners+and+gradients</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F06%2Fthe-best-way-to-do-corners-and-gradients%2F&amp;seed_title=The+best+way+to+do+corners+and+gradients#comments</comments>
		<pubDate>Wed, 06 Feb 2008 14:36:17 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[svg]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>Rounded corners. Yes, they may be a "Web 2.0" fashion fad, but it has been clearly documented that they're a lot easier to <a href="http://www.drivl.com/posts/view/700" rel="external">make</a> than square ones. As part of my <a href="http://www.bioneural.net/2007/12/27/a-xmas-spent-upgrading-bioneuralnet/">overhaul</a> of bioneural.net I've been optimizing much of the code "under the hood", meaning a lot of the changes aren't even visible. Re-evaluating how things are put together, and considering how they could be done more efficiently or otherwise improved is a valuable exercise&mdash;that it scratches a perfectionist itch is an added bonus. In this article I look at a variety of methods for creating boxes with rounded corners and gradients. Yep, it's a showdown!<br />
<span id="more-809"></span></p>
<h4>The traditional approach</h4>
<p>The well-established method of adding corners or gradients to an element is to use multiple background images. Depending to some extent on your content, this is typically impossible to achieve without the use of non-semantic extra mark-up. For example, this box uses to extra and empty divs:</p>
<pre><code>&lt;div class="curvetop"&gt;&lt;/div&gt;
&lt;div class="curvemid"&gt;
	&lt;h2&gt;Willkommen! Welcome!&lt;/h2&gt;
	&lt;p class="german" xml:lang="de" lang="de"&gt;Willkommen auf der Projekt Koru Seite, wo Simone &amp;amp; Bruce die praktischen Aspekte eines Jahres in Neuseeland mit Euch teilen wollen. Eine Einf&amp;uuml;hrung findet Ihr &lt;a href="http://www.bioneural.net/2006/03/17/introducing-project-koru/"&gt;hier&lt;/a&gt; zusammen mit einer &lt;a href="http://www.bioneural.net/2006/03/30/the-teachings-of-te-koru/"&gt;Erkl&amp;auml;rung&lt;/a&gt; warum wir das Koru als Symbol unserer Reise gew&amp;auml;hlt haben.&lt;/p&gt;
	&lt;p class="english"&gt;Welcome to Project Koru, where Simone &amp;amp; Bruce share insight into the practicalities of organizing a year in New Zealand. You can find an introduction to the project &lt;a href="http://www.bioneural.net/2006/03/17/introducing-project-koru/"&gt;here&lt;/a&gt; together with an &lt;a href="http://www.bioneural.net/2006/03/30/the-teachings-of-te-koru/"&gt;explanation&lt;/a&gt; of why we chose the koru as the symbol for our journey.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="curvebottom"&gt;&lt;/div&gt;</code></pre>
<p>Three gradient images (2 having one rounded corner each) could then be loaded into the background of each of the three "layout classes" via CSS:</p>
<pre><code>.curvetop { height: 15px; background: #fff url('gradient-top.png') bottom left no-repeat; display: block; position: relative; margin-top: 10px; }
.curvemid { background: #fff url('gradient-bg.png') repeat-y; padding: 2px 20px !important; display: block; }
.curvebottom { height: 15px; background: #fff url('gradient-bottom.png') top left no-repeat; display: block; position: relative; margin-bottom: 10px; }</code></pre>
<p>The result:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/rounded-welcome.jpg" width="450" height="161" alt="rounded-welcome.jpg"/></p>
<p>You could use this exact same technique for adding embellishments like borders, drop shadows and the like&mdash;but not without some Photoshop skills and a decent collection of bandwidth-hogging images if you needed multiple box styles.</p>
<h4>The challenge</h4>
<p>I devised a box that I thought would test the mettle of any technique. It consisted of just one div containing a header and a paragraph, the text in each of which should appear over a different background with one of these being a gradient (but not necessarily an image). The box should be formed with rounded corners (including on images), a white border, and a drop shadow. It should also have a number of functional characteristics:</p>
<ul>
<li>Minimal mark-up i.e. avoiding nested and/or empty tags;</li>
<li>No changes to mark-up required (but extra CSS allowed, since this could be moved to an external stlesheet);</li>
<li>Valid XHTML and CSS (2.1);</li>
<li><a href="http://en.wikipedia.org/wiki/Anti-aliasing" rel="external">Anti-aliasing</a> on the corners (inner and outer border edges);</li>
<li>Small footprint (let's say under 20KB);</li>
<li>If using JavaScript it should degrade gracefully (i.e. still looks OK if JavaScript is disabled);</li>
<li>Liquid container (adjusting container width to both content size and browser window dimensions).</li>
</ul>
<p class="info">Why the requirement for minimal markup? Forward planning. Eventually CSS3 will arrive, and there'll be no need to scour your database in order to clean out all that redundant mark-up. Just amend your CSS and delete any unemployed images or JavaScript.</p>
<p>My template XHTML and CSS rendered the following:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/master.jpg" width="271" height="354" alt="master.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/master/master-test.html">live</a> link.</p>
<p>Finding a solution to fulfil most if not all of my form and function requirements was going to be something of a mission. There's a useful roundup of techniques <a href="http://www.smileycat.com/miaow/archives/000044.php" rel="external">here</a>, divided into those based on CSS and those based on JavaScript, with examples in both groups requiring anything from no images at all through to eight images. A particular difficulty was finding techniques not restricted by the dimensions of any required image; many of the earlier established methods were clearly devised before the availability of 23" widescreen displays (<a href="http://www.456bereastreet.com/lab/transparent_custom_corners_borders/customised.html">example</a>.)</p>
<p>I made a shortlist (in no particular order) of techniques that looked promising and set to work. I'm not going to post all the code directly into this article or it will become over-long. The files I used for each technique, together with the master template and original full packages where applicable, are available for download should you wish checkout the code or conduct further experiments. I've tested only in Safari and Firefox.</p>
<p class="download">Download the test files <a href="http://www.bioneural.net/docs/corner-tests.zip">here</a> (.zip archive, 428KB).</p>
<h4>Nifty Corners Cube</h4>
<p>First up is <a href="http://www.html.it/articoli/niftycube/index.html" rel="external">Nifty Corners Cube</a> by Alessandro Fulciniti. This method uses JavaScript and CSS; no images other than those you wish to use as backgrounds are required. Here is the result:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/nifty.jpg" width="285" height="366" alt="nifty.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/nifty/nifty-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported.</p>
<p class="for"><em>Four rounded corners</em>: Yes.</p>
<p class="for"><em>Border</em>: While you can produce a <a href="http://www.html.it/articoli/niftycube/nifty11.html" rel="external">convincing</a> rounded border, using padding on the container, this would require extra mark-up in our example in order to retain the cornering on our background images.</p>
<p class="against"><em>Drop shadow</em>: Not supported.</p>
<p class="against"><em>Minimal mark-up</em>: An extra container is required to render a border with inside and outside rounding.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to add extra container plus insert box-specific script.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="against"><em>Anti-aliasing</em>: Anti-aliasing is not working on the background images or border, although it does work on solid colour boxes in the <a href="http://www.html.it/articoli/niftycube/nifty1.html" rel="external">examples</a>.</p>
<p class="for"><em>Small footprint</em>: 10KB for CSS and JavaScript (background images additional).</p>
<p class="for"><em>Graceful degradation</em>: Renders as per the master if JavaScript disabled.</p>
<p class="for"><em>Liquidity</em>: Overriding fixed width for .cornered (and in the third case for .xtra) supports liquid layouts (case four).</p>
<p>Score: 8/12</p>
<h4>curvyCorners</h4>
<p>Cameron Cooke's <a href="http://www.curvycorners.net/" rel="external">curvyCorners</a> is another image-free JavaScript solution:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/curvy.jpg" width="287" height="373" alt="curvy.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/curvy/curvy-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported.</p>
<p class="against"><em>Four rounded corners</em>: There are rounded corners, but these are rendered adjacent to our background content rather than on top of it. This <a href="http://www.curvycorners.net/examples/demos/demo2.html" rel="external">example</a> illustrates rounding on a background image, but adding a border to the containing div merely fills the cornered area with "extra" offset background (see <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/curvy/offset.jpg">here</a>).</p>
<p class="for"><em>Border</em>: Obtained by applying background and border to container.</p>
<p class="against"><em>Drop shadow</em>: Not a feature of this technique.</p>
<p class="for"><em>Minimal mark-up</em>: Yes.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to insert box-specific script.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="against"><em>Anti-aliasing</em>: Yes, but only on the outside of the rounded border (not on images).</p>
<p class="against"><em>Small footprint</em>: 24KB for JavaScript (background images additional).</p>
<p class="for"><em>Graceful degradation</em>: Renders as per the master if JavaScript disabled.</p>
<p class="for"><em>Liquidity</em>: Overriding fixed width for .cornered supports liquid layouts (case four).</p>
<p>Score: 7/12</p>
<h4>SRCCB</h4>
<p>The "simple rounded corner CSS boxes" technique was <a href="http://www.modxcms.com/simple-rounded-corner-css-boxes.html" rel="external">devised</a> by Ryan Thrash, also accessible in the form of an online generator as <a href="http://spiffybox.com/" rel="external">Spiffy Box</a>. It uses no JavaScript and a single image combined with moderately complex CSS (which would have to be recalculated for each box size):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/simple.jpg" width="268" height="374" alt="simple.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/simple/simple-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported (integrated into container background).</p>
<p class="for"><em>Gradient background</em>: Supported (integrated into container background).</p>
<p class="for"><em>Four rounded corners</em>: Yes (integrated into container background).</p>
<p class="for"><em>Border</em>: Yes (integrated into container background).</p>
<p class="for"><em>Drop shadow</em>: Yes (integrated into container background).</p>
<p class="against"><em>Minimal mark-up</em>: Requires two additional divs for positioning purposes.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to insert two additional divs.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="for"><em>Anti-aliasing</em>: Yes (integrated into container background).</p>
<p class="for"><em>Small footprint</em>: 6KB image overhead compared to master with original 2 background images.</p>
<p class="for"><em>Graceful degradation</em>: Not applicable as no JavaScript.</p>
<p class="against"><em>Liquidity</em>: Depends upon fixed-width images.</p>
<p>Score: 9/12</p>
<h4>swfIR</h4>
<p>The SWF Image Replacement (<a href="http://www.swfir.com" rel="external">swfIR</a>) technique is offered by Jon Aldinger, Mark Huot, and Dan Mall. It applies to inline (cf background) images and uses JavaScript and Flash to swap out the original and deck it out with bling. It does more than we require&mdash;image rotation and stretching for example, and at first glance it certainly looked like the wrong tool for the job. I wondered, however, if we could use CSS positioning to overlay our text on top of the replaced images. It turns out you can:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/swfir.jpg" width="255" height="394" alt="swfir.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/swfir/swfir-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported (as an inline image!).</p>
<p class="for"><em>Gradient background</em>: Supported (as an inline image!).</p>
<p class="against"><em>Four rounded corners</em>: Actually you get 6! (you could potentially blot out the bottom border on the heading using a third positioned inline image&mdash;a real hack!).</p>
<p class="for"><em>Border</em>: Yes (specified in JavaScript).</p>
<p class="for"><em>Drop shadow</em>: Yes (specified in JavaScript).</p>
<p class="against"><em>Minimal mark-up</em>: Requires insertion of two inline images.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to insert inline images plus box-specific script.</p>
<p class="for"><em>W3C validity</em>: Yes. It does validate, but should I say "No" because it depends on Flash?</p>
<p class="for"><em>Anti-aliasing</em>: Yes.</p>
<p class="against"><em>Small footprint</em>: 25KB (24KB JavaScript and SWF; 1KB image overhead compared to master with original 2 background images.)</p>
<p class="for"><em>Graceful degradation</em>: Acceptable (just) with JavaScript disabled.</p>
<p class="against"><em>Liquidity</em>: Positioning depends upon fixed-width images.</p>
<p>Score: 7/12</p>
<h4>ShadedBorder</h4>
<p>Steffen Ruzee brings you <a href="http://www.ruzee.com/blog/shadedborder" rel="external">ShadedBorder</a>, a full-featured solution that uses only JavaScript:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/shaded.jpg" width="273" height="374" alt="shaded.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/shaded/shaded-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported.</p>
<p class="for"><em>Four rounded corners</em>: Yes.</p>
<p class="against"><em>Border</em>: Yes (specified in JavaScript), but height on .sb-inner causes blue background to show through (why isn't this also an issue with the h4 background image?). Setting height to 0 removes the bar but also takes out the gradient! Admittedly, you could style the background to tone in better.</p>
<p class="for"><em>Drop shadow</em>: Yes (specified in JavaScript).</p>
<p class="against"><em>Minimal mark-up</em>: A headline with it's own style can be <a href="http://www.ruzee.com/files/shadedborder/test.html" rel="external">achieved</a> with extra mark-up, and extra script in the head, and another script that <em>must</em> be inserted before the closing body tag. This makes it fatally flawed for use in a templated system like WordPress, IMHO.</p>
<p class="against"><em>Static mark-up</em>: As above, mark-up edited at 3 points, including a necessary change from div class to ID.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="for"><em>Anti-aliasing</em>: Yes.</p>
<p class="for"><em>Small footprint</em>: 9KB JavaScript.</p>
<p class="for"><em>Graceful degradation</em>: Renders as per the master if JavaScript disabled.</p>
<p class="for"><em>Liquidity</em>: Yes (comment out width on #cornered; not shown due to duplicate IDs).</p>
<p>Score: 9/12</p>
<h4>SVG</h4>
<p>Firefox 2 and Safari 3 can both display standalone Scalable Vector Graphics (<a href="http://www.w3.org/TR/SVG/" rel="external">SVG</a>) images, an unloved W3C standard. They can't load SVG from CSS, however, making SVGs unusable as background images at this time. The option to use SVG in CSS hasn't gone beyond a <a href="http://dbaron.org/css/css-vg/" rel="external">proposal</a>, with Wikipedia <a href="http://en.wikipedia.org/wiki/Scalable_Vector_Graphics" rel="external">noting</a> "the use of SVG on the web is in its infancy". It took me quite a few hours to get to grips with the examples in the 1.1 spec and create a <a href="http://validator.w3.org/check?uri=http%3A//www.bioneural.net/wp-content/uploads/2008/02/corner-tests/svg/svg-test.xhtml" rel="external">valid</a> and functional XHTML/SVG file for testing purposes. The basic idea is to create a bordered box with rounded corners, fill it with a gradient, and apply a <a href="http://en.wikipedia.org/wiki/Gaussian_blur" rel="external">Gaussian blur</a> to a slightly offset box of the same dimensions&mdash;all with a few lines of XML. Here is our box using Opera 9.25 (Mac):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/svg.jpg" width="279" height="372" alt="svg.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/svg/svg-test.xhtml">live</a> link (SVG-aware browser required).</p>
<p><strong>Scoresheet:</strong></p>
<p class="against"><em>Photo background</em>: Supported in CSS, but you loose the rounded corners.</p>
<p class="for"><em>Gradient background</em>: Supported without CSS via <code>linearGradient</code>.</p>
<p class="for"><em>Four rounded corners</em>: Yes via <code>rx</code> on <code>rect</code>.</p>
<p class="for"><em>Border</em>: Yes via <code>stroke</code> on <code>rect</code>.</p>
<p class="for"><em>Drop shadow</em>: Yes via <code>filter</code> with <code>feGaussianBlur</code>, <code>feOffset</code>, and <code>feMerge</code>.</p>
<p class="against"><em>Minimal mark-up</em>: Requires insertion of inline SVG image(s).</p>
<p class="against"><em>Static mark-up</em>: SVG must (currently) be added inline; also necessitates DOCTYPE change and .xhtml file extension.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="for"><em>Anti-aliasing</em>: Yes.</p>
<p class="for"><em>Small footprint</em>: 0KB (background image additional; gradient image not required).</p>
<p class="against"><em>Graceful degradation</em>: No (Internet Explorer 6 and 7 choke).</p>
<p class="against"><em>Liquidity</em>: Positioning depends upon fixed-width SVG images; <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/svg/svg-resize-test.xhtml">resizing</a> text size or browser window is problematic.</p>
<p>Score: 7/12</p>
<p><em>Update 18.03.08</em>: Safari 3.1 <a href="http://docs.info.apple.com/article.html?artnum=307467" rel="external">adds</a> support for SVG images in img elements and CSS images.</p>
<h4>CSS3</h4>
<p><a href="http://www.w3.org/TR/css3-roadmap/" rel="external">CSS3</a>, if it ever arrives, promises not only rounded corners but drop shadows and multiple background images too (oddly the draft spec doesn't mention gradients). Apple's <a href="http://www.apple.com/safari/" rel="external">Safari</a> (available for Mac and PC) already includes support for such effects&mdash;but of course it's not valid CSS. You can preview CSS3 rounded corners <a href="http://www.css3.info/preview/rounded-border/" rel="external">here</a> and <a href="http://24ways.org/2006/rounded-corner-boxes-the-css3-way" rel="external">here</a> in Firefox or Safari 3. Here is our box using Safari-specific not-quite-CSS3:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/css3.jpg" width="293" height="371" alt="css3.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/css3/css3-test.html">live</a> link (<a href="http://webkit.org/" rel="external">WebKit</a> browser required).</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported.</p>
<p class="for"><em>Four rounded corners</em>: Yes.</p>
<p class="for"><em>Border</em>: Yes.</p>
<p class="for"><em>Drop shadow</em>: Yes.</p>
<p class="for"><em>Minimal mark-up</em>: Yes.</p>
<p class="for"><em>Static mark-up</em>: Yes.</p>
<p class="against"><em>W3C validity</em>: No, but only because the standard isn't yet established.</p>
<p class="for"><em>Anti-aliasing</em>: Yes, but note anti-aliasing artefact in the bottom corners.</p>
<p class="for"><em>Small footprint</em>: 0KB (background images additional).</p>
<p class="for"><em>Graceful degradation</em>: Yes (non-CSS3 aware browsers see a plain box).</p>
<p class="for"><em>Liquidity</em>: Yes.</p>
<p>Score: 11/12</p>
<h4>Summing up</h4>
<p>Which technique you choose ultimately depends upon what you're after and what you prioritise. There is no one "best" solution that fits all requirements. In terms of form and function CSS3 has to be the clear winner if one must be chosen, with a perfect score blown only by the fact that it isn't a W3C standard (yet). Herein lies CSS3's only significant yet overwhelming drawback: what good is it if the majority users can't see the effects? At the same time I'm not personally sold on any of the alternative methods. The end results may look good; it's <em>how</em> they achieve them that I don't much care for. Although a method validates it typically involves cheating the validator (seemingly JavaScript's <em>raison d'être</em>). Just take a look at the live links with Safari's Web Inspector (<a href="http://www.bioneural.net/wp-content/uploads/2008/02/inspector.jpg">example</a>).</p>
<p>Before I put a lid on this little adventure, as Jobs would <a href="http://en.wikipedia.org/wiki/Stevenote" rel="external">say</a>, there's just <em>one more thing</em>... what about jQuery? The <a href="http://jquery.com/" rel="external">jQuery</a> library (included with WordPress and the K2 theme) can be extended to render corners, shadows, and gradients. If this article was Part 1, then that exposition forms <a href="http://www.bioneural.net/2008/02/13/corners-gradients-and-shadows-with-jquery/">Part 2</a>. <del datetime="2008-02-13T16:15:23+00:00">Coming soon</del>.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F06%2Fthe-best-way-to-do-corners-and-gradients%2F&amp;seed_title=The+best+way+to+do+corners+and+gradients/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>bioneural.net site preference panel revisited</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F22%2Fbioneuralnet-site-preference-panel-revisited%2F&amp;seed_title=bioneural.net+site+preference+panel+revisited</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F22%2Fbioneuralnet-site-preference-panel-revisited%2F&amp;seed_title=bioneural.net+site+preference+panel+revisited#comments</comments>
		<pubDate>Tue, 22 Jan 2008 20:06:51 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/01/22/bioneuralnet-site-preference-panel-revisited/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>The <a href="http://www.bioneural.net/2006/05/11/adding-a-site-preferences-panel/">first</a> version of my site preference panel for <a href="http://wordpress.org/" rel="external">WordPress</a> needed lots of JavaScript for the toggle (<a href="http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/">Proto.aculo.us</a>), more JavaScript to switch styles, and still more JavaScript to change text size. Version 2 still uses JavaScript for the toggle effect&mdash;but no additional load&mdash;since jQuery is already utilised by <a href="http://getk2.com/" rel="external">K2</a>. The rest is accomplished using server-side PHP, and the revised 3-column panel layout makes use of more recent CSS know-how. I've tried to modularize the preferences panel as much as possible, but some simple template editing is still required (at 4 points). It is optimised for K2 (tested using RC3 and RC4) and although I haven't tested it with other themes (that's your job!) I don't see why it couldn't be used (*Some tweaking may be required. Batteries not included.)<br />
<span id="more-785"></span></p>
<h4>Get the files</h4>
<p>Let's get it done, then come back to the how and why if you're interested. Download the files to create your own preference panel as siteprefs.zip, available <a href="http://www.bioneural.net/extra/">here</a>. Expand the archive and upload the folder "siteprefs" into your K2 main directory:</p>
<p>/wp-content/themes/k2/siteprefs/</p>
<p>At this point you may also want to download and activate the <a href="http://wordpress.org/extend/plugins/theme-switcher/" rel="external">Theme Switcher</a> plugin if you plan on allowing your audience to change the WordPress theme they see on a per-user basis (storing their preference in a cookie). Support for the plugin is built into the preference panel (see features, below).</p>
<p>It's yours to play with and customise; all I ask is that you retain the little "i" icon with it's link back to these instructions. Feedback and suggestions for improvement are welcome. If you do modify it in a novel way (or use it in a theme other than K2), please leave a comment so I and others can check it out.</p>
<p>Right then, let's hack some templates!</p>
<h4>Step 1: Look for cookies</h4>
<p>Add the following code into PHP block at the top of K2's header.php (e.g. before the closing "?&gt;"):</p>
<pre><code>// Check cookie for stored site prefs
$layout = (isset($_COOKIE['layout']) &amp;&amp; ($_COOKIE['layout'] == "alternate")) ? "alternate" : "style";</code></pre>
<p>Here, "style" is the name of your main stylesheet (style.css in K2) and "alternate" is the name of a stylesheet we'll create at Step 5. If you're not using K2 pop this between PHP start and end tags at the top of your header template and set "style" to the name of your primary CSS file.</p>
<h4>Step 2: Know your style</h4>
<p>We need to replace the relative link to your stylesheet with one into which we can insert the value of the variable <code>$layout</code>. While we're here, we might as well link to the styling for the preference panel. In the head element of header.php replace this line (or your theme's equivalent):</p>
<pre><code>&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php bloginfo('stylesheet_url'); ?&gt;" /&gt;</code></pre>
<p>with:</p>
<pre><code>&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php bloginfo('template_url'); ?&gt;/&lt;?php echo $layout; ?&gt;.css" /&gt;
&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php bloginfo('template_url'); ?&gt;/siteprefs/siteprefs.css" /&gt;</code></pre>
<p class="info">Your K2 custom stylesheet will still be loaded too, if you're using one.</p>
<h4>Step 3: Flick the switch</h4>
<p>Create a toggle to switch visibility of the preference panel on or off (it will be hidden on page load). The actual "switch" might be a text or an image link, inserted into an appropriate place (e.g your header or sidebar). If you prefer to add the toggle in the form of a tab in your K2 menu, look for <code>ul class="menu"</code> in header.php and replace this code:</p>
<pre><code>	&lt;?php wp_register('&lt;li class="admintab"&gt;','&lt;/li&gt;'); ?&gt;
&lt;/ul&gt;</code></pre>
<p>with the following code:</p>
<pre><code>	&lt;?php wp_register('&lt;li class="admintab"&gt;','&lt;/li&gt;'); ?&gt;
	&lt;li&gt;&lt;a id="siteprefs-toggle" href="#" title="Click to show/hide site preferences (requires JavaScript)"&gt;Prefs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;script type="text/javascript"&gt;
	jQuery(document).ready(function() {

	// hide #siteprefs as soon as the DOM is ready
	jQuery('#siteprefs').hide();

	// toggle #siteprefs on clicking the #prefs-toogle link
	jQuery('a#siteprefs-toggle').click(function() {
	jQuery('#siteprefs').slideToggle(400);
	return false;
	});

});
&lt;/script&gt;</code></pre>
<p>If you'd rather use the supplied image (sitepref2.gif), place the following code after <code>p class="description"</code> (which is within <code>div id="header"</code>) and before <code>ul class="menu"</code> in K2's header.php. </p>
<pre><code>&lt;a id="siteprefs-toggle" href="#" title="Click to show/hide site preferences (requires JavaScript)"&gt;&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/siteprefs/img/sitepref2.gif" width="52" height="28" alt="siteprefs" /&gt;&lt;/a&gt;
&lt;script type="text/javascript"&gt;
	jQuery(document).ready(function() {

	// hide #siteprefs as soon as the DOM is ready
	jQuery('#siteprefs').hide();

	// toggle #siteprefs on clicking the #prefs-toogle link
	jQuery('a#siteprefs-toggle').click(function() {
	jQuery('#siteprefs').slideToggle(400);
	return false;
	});

});
&lt;/script&gt;</code></pre>
<p>The CSS to position the #siteprefs-toggle image within K2's header image area is included in the download (it will be ignored if you create a menu tab instead). If this position doesn't suit your theme of course you can overwrite this in siteprefs.css. </p>
<p class="info">The toggle's "slide" effect depends on jQuery, which comes with K2 by default. If you're not using K2, you'll need to include the jQuery library in your head, find an alternative JavaScript (<a href="http://www.bioneural.net/2006/05/11/adding-a-site-preferences-panel/">here</a> is how v1 did it using Proto.aculo.us), or you may wish to dispense with the toggle altogether and ventilate your preferences permanently.</p>
<h4>Step 4: Feel included</h4>
<p>The file siteprefs.php includes the XHTML and PHP to build your preference panel. As well as providing the Theme Switcher control, it works with layout.php to toggle your main and alternate stylesheets (and store your choice in a cookie), and advises your audience on link behaviour. You can change the content of these three columns as you see fit just by editing siteprefs.php.</p>
<p>To get siteprefs.php into your theme we have to include it e.g. immediately below the closing tag of the div #header in header.php, so it appears to slide out from the K2 menu:</p>
<pre><code>&lt;?php include (TEMPLATEPATH . '/siteprefs/siteprefs.php'); ?&gt;</code></pre>
<p>If you prefer you could put it at the top of your page, in the sidebar, or in the footer. Or anywhere. For sidebar placement, for example, you would likely edit siteprefs.php and siteprefs.css to respectively create and style a single vertical column.</p>
<p>At this point, if you refresh your site you should see the bioneural.net preference panel installed. If all went well and you're using a default K2 installation, you should be something like this:</p>
<p><span class="zoom">Click thumbnail to enlarge image</span><br /><a href="http://www.bioneural.net/images/enlarge/siteprefs-large.jpg" rel="ibox" title="Site preferences installed into default K2 theme (using image toggle)"><img src="http://www.bioneural.net/wp-content/uploads/2008/01/siteprefs-thumb.jpg" width="200" height="81" alt="siteprefs-thumb.jpg" /></a><br /><span class="caption">Site preferences installed into default K2 theme (using image toggle)</span></p>
<h4>Step 5: Go alternative</h4>
<p>Finally we create an alternate stylesheet, named alternate.css (the name is specified in Step 1 and in layout.php).</p>
<p>What you put in here is up to you. You will likely want to import existing styling from your main stylesheet, and then write a handful of rules which, owing to the CSS "cascade", will overwrite some of those you just imported. </p>
<p>Here's a barebones example that increases font size and turns the default K2 fixed-width theme into a fluid/ liquid layout:</p>
<pre><code>@import 'style.css';

body { font-size: 90%; } /* approx 30% larger than K2 default */
#page { width: 100% !important; border: 0; padding: 0; }
#primary { width: 100%; margin-left: -30px; padding-left: 30px; background-color: #fff;}
.content { background-color: #fff; } /* Match bg colour to #primary */
#sidebar-main.secondary { padding-left: 30px; border-right: 10px solid #f2f2f2; padding-bottom: 20px; } /* Border colour matches bg colour of .secondary */
.secondary { width: 100% !important; margin-left: -30px; background: #f2f2f2; }
#footer { background-color: #ccc; }</code></pre>
<p>Upload alternate.css into the same directory as your main stylesheet (e.g. styles.css i.e. /wp-content/themes/k2/). This is <strong>important</strong> as the switch relies on your main and alternate stylesheets being in the same directory.</p>
<p class="info">If you're having trouble overwriting rules for your alternate stylesheet, try !important e.g. <code>width: 100% !important;</code> but bear in mind IE6 will ignore it.</p>
<h4>Build notes, features and credits</h4>
<p>You don't <em>have</em> to read on&mdash;unless you're interested in how, why, and who helped make it work the way it does ;-)</p>
<h4>The toggle effect</h4>
<p>The toggle uses the <a href="http://jquery.com/" rel="external">jQuery</a> JavaScript library and the code for this was covered in a <a href="http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/">previous</a> article.</p>
<p>What if the user doesn't have JavaScript, or has it but disabled it? Version 1 hid the preference panel on page load using CSS, and showing it required JavaScript to change the styling to "display". Version 2 uses JavaScript to initially hide the panel, so if there is no JavaScript the panel will be revealed at the outset. Furthermore, because none of the controls in the panel utilize any JavaScript, no functionality is impaired. The only (minor) outcome is that the panel can't be hidden, but at least the "accessibility" preferences are, err, accessible.</p>
<h4>A flexible 3-column framework</h4>
<p>The XHTML mark-up and CSS for this is adapted from an <a href="http://www.alistapart.com/d/multicolumnlayouts/3ColLiquid.html" rel="external">example</a> multi-column layout given in an ALA <a href="http://www.alistapart.com/articles/multicolumnlayouts" rel="external">article</a> by <a href="http://alttag.org/" rel="external">Alan Pearce</a>. Alan cleverly builds on previous work that makes use of borders to simulate equal-height columns. Initially my mark-up used borders too, but after 2 days of trying to get it to work in IE6 and 7 with in-column padding I realised I didn't need them. </p>
<p>The fixed-width two-column K2 theme I use defaults to a width of 780px. To create our basic layout we create 3 divs (one for each column), and wrap these in a container div. The container sets up the 3 columns using floats and negative margins and then uses padding to effectively pull the outer columns back inside the container! We then create a header div and a footer div, and style the width of the outer columns (including padding) to 260px i.e. one third of our page width:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/3-columns.jpg" width="451" height="203" alt="3-columns" /></p>
<p>We can then apply a horizontally-repeating background image to the header and footer divs, match the background colours, and clear floats for the footer to position correctly. Here's what our panel now looks like topographically:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/topographical.jpg" width="450" height="108" alt="topographical" /></p>
<p>But the preference panel resizes, too. If your alternate stylesheet is "fluid" i.e. page content fits to the width of the browser window, the three columns will automatically space themselves out equally to fill the window:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/fluid.jpg" width="450" height="64" alt="fluid" /></p>
<p class="info">Note that the left and right column width doesn't actually change, but the width of the middle column is no longer an implied 260px since we have set #siteprefs-center to occupy 100% width.</p>
<p>At this point everything is looking good&mdash;in Firefox, Safari, and IE7. You guessed it: Internet Exploder 6 is singing protest songs. We need to patch our CSS to make it work with IE6:</p>
<p class="bug">The IE escaping floats <a href="http://www.positioniseverything.net/explorer/escape-floats.html" rel="external">bug</a> causes the contents of #siteprefs-header not to display. We just add <code>width: 100%;</code> to fix this.</p>
<p class="bug">The IE doubled float-margin <a href="http://www.positioniseverything.net/explorer/doubled-margin.html" rel="external">bug</a> causes #siteprefs-right to float outside of #siteprefs-wrapper! To fix this we add <code>display: inline;</code> to #siteprefs-right.</p>
<h4>Switching whole themes</h4>
<p>The <a href="http://wordpress.org/extend/plugins/theme-switcher/" rel="external">Theme Switcher</a> plugin for WordPress is by <a href="http://boren.nu/" rel="external">Ryan Boren</a>. It sets a cookie so that the user's browser remembers their choice of theme for subsequent visits.</p>
<p>The bioneural.net preference panel uses conditional PHP to show the theme switcher dropdown menu or, if the TS plugin is not present or is present but not activated, they will see a "not enabled" message:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/styling-states.jpg" width="374" height="122" alt="styling-states.jpg" /></p>
<p>There are a few other things you might consider if you allow theme switching on your site; see Ben's <a href="http://www.instigatorblog.com/10-things-you-must-do-when-changing-wordpress-themes/2007/01/15/" rel="external">list</a>. To press the point, the preference panel includes a warning when the switcher is displayed that using it "may reduce functionality". At the very least you need to allow users to easily switch back to the previous theme&mdash;otherwise they'll have to wait a year until the cookie expires (not really; they could just delete the cookie!). In the sidebar of each theme you have installed, just paste the following:</p>
<pre><code>&lt;?php if (function_exists('wp_theme_switcher')) { ?&gt;
	&lt;?php wp_theme_switcher('dropdown'); ?&gt;
&lt;?php } ?&gt;</code></pre>
<p>If you don't like the list styling, this CSS (as used in siteprefs.css) will remove it:</p>
<pre><code>#themeswitcher { list-style: none; padding-left: 0; }</code></pre>
<h4>Switching stylesheets</h4>
<p>Previously I had used JavaScript to effect both a change in layout (fixed or fluid-width) and in text size (smaller, default, larger). Both of these are really accessibility issues&mdash;adapting to the size of your screen or the acuity of your vision. Add to this the observation that enlarging text size very soon causes problems within the confines of a fixed-width layout and it becomes clear why I decided to merge these features in version 2 i.e. biiger text, bigger container.</p>
<p>Stylesheet switching with memory is ideal, for example, if you want your iPhone/ tablet&mdash;or screen resolution-challenged work PC&mdash;to always use an alternative "accessible" layout. Cookies could likewise ensure that a different default style makes full use of your stunning 23" Apple Display.</p>
<p>Having decided against reusing the <a href="http://www.alistapart.com/stories/alternate/" rel="external">original</a> ALA styleswitcher JavaScript, and considered using jQuery (as <a href="http://kelvinluck.com/article/switch-stylesheets-with-jquery" rel="external">here</a>&mdash;also JavaScript, but better), I looked at a few PHP options and settled on Roger Johansson's <a href="http://www.456bereastreet.com/archive/200608/build_your_own_php_style_sheet_switcher/" rel="external">method</a>.</p>
<h4>Identifying off-site links</h4>
<p>By default (Option 1) any link you tag with rel="external" will display the "off-site" icon (dimmed for visited links) using the included CSS. I prefer this option for identifying off-site links because it gives your audience the choice as to how links behave (the alternative is forcing them to open new windows using JavaScript or the depreciated target="_bank"). If you haven't religiously tagged your off-site links with rel="external" (or can't be bothered), you have two alternative options:</p>
<ol>
<li>Open siteprefs.css and uncomment Option 2 (making sure the CSS for Options 1 and 3 is commented); this will apply the icon to all links other than to your own domain (<a href="http://lachy.id.au/log/2005/04/handy-css" rel="external">credit</a>). See the instructions in the file.</li>
<li>A WordPress <a href="http://sw-guide.de/wordpress/plugins/link-indication/" rel="external">plugin</a> is available that will do it for you (Option 3). Once the Link Indication plugin is activated just uncomment the CSS for Option 3 in siteprefs.css (ensuring the CSS for Options 1 and 2 is commented-out).</li>
</ol>
<p class="info">Option 1 works in Firefox, IE7, and Safari (but not IE6). Option 2 works in Firefox and Safari (but not IE7 or IE6). Option 3 works in Firefox, IE7, IE6, and Safari (but does not differentiate between visited/ unvisited links).</p>
<h4>Change log</h4>
<table class="tabulate">
<tr>
<th>Version</th>
<th>Notes</th>
</tr>
<tr>
<td>1.0</td>
<td class="odd"><em>11.05.06</em>. Initial 1.x release.</td>
</tr>
<tr>
<td>2.0</td>
<td class="odd"><em>22.01.08</em>. Initial 2.x release.</td>
</tr>
<tr>
<td>2.1</td>
<td class="odd"><em>28.01.08</em>. Corrected CSS for off-site links. Added alternative methods of identifying off-site links using <a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#pseudo-classes" rel="external">pseudo-class</a> (Option 2) or class (Option 3).</td>
</tr>
</table>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F22%2Fbioneuralnet-site-preference-panel-revisited%2F&amp;seed_title=bioneural.net+site+preference+panel+revisited/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>From Proto.aculo.us to jQuery</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F06%2Ffrom-protoaculous-to-jquery%2F&amp;seed_title=From+Proto.aculo.us+to+jQuery</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F06%2Ffrom-protoaculous-to-jquery%2F&amp;seed_title=From+Proto.aculo.us+to+jQuery#comments</comments>
		<pubDate>Sun, 06 Jan 2008 18:31:03 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[opensource]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>As I recently <a href="http://www.bioneural.net/2007/12/27/a-xmas-spent-upgrading-bioneuralnet/">noted</a>, both WordPress and K2 have migrated from using Prototype plus script.aculo.us to using the <a href="http://jquery.com/" rel="external">jQuery</a> JavaScript library. <a href="http://prototypejs.org/" rel="external">Prototype</a> is a JavaScript framework, including a library of functions used to build <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29" rel="external">Ajax</a> applications. It's best buddies with <a href="http://script.aculo.us/" rel="external">script.aculo.us</a>, an add-on JavaScript effects library that extends the capabilities of the former. So where does jQuery fit in?<br />
<span id="more-760"></span></p>
<h4>The winds of change</h4>
<p><a href="http://wordpress.org" rel="external">WordPress</a> hasn't altogether dropped either Prototype or script.aculo.us. As of version 2.3.2 they're still bundled in wp-includes/js/, but the <a href="http://codex.wordpress.org/Version_2.2" rel="external">Codex</a> notes that since version 2.2:</p>
<blockquote><p>Switched to jQuery for core JS, which is lighter and faster.</p></blockquote>
<p>I'm no programmer, but I do understand that loading a smaller function library is kinder on your bandwidth and browser, and that writing fewer lines of <a href="http://geekgrl.net/2007/01/04/jquery-vs-prototype-wordpress-gone-astray/" rel="external">script</a> to call those functions is kinder on web developers.</p>
<p><a href="http://getk2.com" rel="external">K2</a>, on the other hand, <a href="http://stevelam.org/2007/08/k2-and-jquery/" rel="external">stopped</a> bundling Prototype and script.aculo.us as of revision 382. This popular WordPress theme now does all its Ajax magic&mdash;Live Search, Rolling Archives, and Live Comments&mdash;via jQuery.</p>
<h4>Loosing weight</h4>
<p>As of this writing Prototype (1.6.0.1) weighs in at 121 KB. The six core files that make up script.aculo.us 1.8.1 (sound.js and unittest.js are optional) also happen to total 121 KB, making a combined size of 242 KB. If I could therefore use jQuery 1.2.1 (at 45 KB) to achieve the same JavaScript-mediated effects, I'd be using around one fifth of the code libraries I was previously loading. But it's worse than that, because if I retained Proto.aculo.us for custom effects <em>and</em> loaded jQuery for K2, I'd be wasting bandwidth and CPU cycles like there was no tomorrow.</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/js-libraries.jpg" width="450" height="329" alt="Script library comparison" /></p>
<h4>Prototype plus script.aculo.us</h4>
<p>Here's how I was loading Proto.aculo.us in the head in my old WordPRess K2 r163 theme ("..." is a contracted path):</p>
<pre><code>&lt;script type="text/javascript" src=".../js/prototype.js.php"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src=".../js/effects.js.php"&gt;&lt;/script&gt;</code></pre>
<p>I built a toggle for my sidebar to display a list of category feeds, initially styled not to display on my home page, with the following:</p>
<pre><code>&lt;?php if ((is_home()) &amp;&amp; !(is_paged()) ) { ?&gt;
&lt;div class="sb-catfeeds"&gt;&lt;h2&gt;Category feeds&lt;/h2&gt;
&lt;span class="metalink"&gt;&lt;a href="#catfeed" onclick="Effect.Combo('catfeed', {duration: .5}); return false" title="Click to show/hide category feeds (requires JavaScript)" class="feedlink"&gt;.../styles/bioneural/feedicongrey.png" alt="Feed" /&gt;&lt;/a&gt;&lt;/span&gt;
&lt;noscript&gt;&lt;p class="alert"&gt;Please enable JavaScript for full functionality (toggle feed list visibility)&lt;/p&gt;&lt;/noscript&gt;
&lt;ul id="catfeed" style="display: none;"&gt;
&lt;?php list_cats(0, '', 'name', 'asc', '', 1, 0, 0, 1, 1, 1, 0,'','','Feed','.../images/feedicon16px.png','') ?&gt;
&lt;!-- http://wiki.wordpress.org/list_cats --&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;?php } ?&gt;</code></pre>
<p>A similar arrangement was used to hide and reveal my site <a href="http://www.bioneural.net/2006/05/11/adding-a-site-preferences-panel/">preferences</a> panel. Could I achieve the same using the lightweight jQuery?</p>
<h4>Converting to jQuery</h4>
<p>In my upgraded K2 RC3 theme I'm not loading any additional scripts in the head, because jQuery is already included. If you're not already using jQuery and just want to try it out, you can add it to your head temporarily and without uploading it to your own server like this:</p>
<pre><code>&lt;script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.1.js"&gt;&lt;/script&gt;</code></pre>
<p>Here's what I now have in sidebar.php using jQuery syntax (adapted from <a href="http://www.learningjquery.com/2006/09/slicker-show-and-hide" rel="external">this</a> example):</p>
<pre><code>	&lt;?php if (is_home()) { ?&gt;
	&lt;div class="sb-catfeeds"&gt;&lt;h4&gt;Category feeds&lt;/h4&gt;
	&lt;script type="text/javascript"&gt;
		jQuery(document).ready(function() {

		// hide #catfeed as soon as the DOM is ready
		jQuery('#catfeed').hide();

		// toggle #catfeed on clicking the #catfeed-toogle link
		jQuery('a#catfeed-toggle').click(function() {
		jQuery('#catfeed').slideToggle(400);
		return false;
		});

	});
	&lt;/script&gt;
	&lt;noscript&gt;&lt;p class="alert"&gt;Please enable JavaScript for full functionality (toggle feed list visibility)&lt;/p&gt;&lt;/noscript&gt;
	&lt;span class="metalink"&gt;&lt;a href="#" id="catfeed-toggle" title="Click to show/hide category feeds (requires JavaScript)" class="feedlink"&gt;&lt;img src=".../styles/bioneural/feedicongrey.png" alt="Feed" /&gt;&lt;/a&gt;&lt;/span&gt;
	&lt;ul id="catfeed"&gt;
		&lt;?php wp_list_categories('feed_image=.../images/feedicon16px.png&amp;title_li='); ?&gt;
		&lt;!-- http://codex.wordpress.org/Template_Tags/wp_list_categories --&gt;
	&lt;/ul&gt;
	&lt;/div&gt;
	&lt;?php } ?&gt;</code></pre>
<p>It's as close to poetry as code gets, but initially I was using "$" in place of "jQuery" and the code had no effect at all. Thanks to <a href="http://www.learningjquery.com/2006/09/slicker-show-and-hide#comment-26102">Karl</a> we determined that K2 was already using $, thus leading to the "Error: $ is not a function" I was getting:</p>
<blockquote><p>That error usually occurs when a script tries to use the $ function before the core jQuery file has been loaded or when $ is being used for something else. Try replac[ing] each mention of $ with jQuery and see if that fixes the problem.</p></blockquote>
<h4>Issues</h4>
<p>The only issue I've noticed is that you get a "flash" view of the hidden div when changing pages (on bioneural.net this affects the site preferences panel). While I generally discourage flashing, I don't believe in this case it's an arrestable offence.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F06%2Ffrom-protoaculous-to-jquery%2F&amp;seed_title=From+Proto.aculo.us+to+jQuery/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Valid fix for PNG transparency on a single image</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F08%2F09%2Fvalid-fix-for-png-transparency-on-a-single-image%2F&amp;seed_title=Valid+fix+for+PNG+transparency+on+a+single+image</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F08%2F09%2Fvalid-fix-for-png-transparency-on-a-single-image%2F&amp;seed_title=Valid+fix+for+PNG+transparency+on+a+single+image#comments</comments>
		<pubDate>Wed, 09 Aug 2006 21:59:28 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2006/08/09/valid-fix-for-png-transparency-on-a-single-image/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>As you likely know, IE6 (and below) cannot handle <a href="http://en.wikipedia.org/wiki/PNG" rel="external">PNG</a> images that use alpha transparency. PNG produces graphically superior results compared to a transparent GIF image, which will often have a white fuzzy border. There are various "fixes" for this particular IE problem on the Web, but sometimes their application can have undesirable results, or the fix involves invalid XHTML or CSS. In my case I was prepared to accept grey backgrounds on the mini-icons used on bioneural.net, but there was one particular image where this really bugged me. Here's how I fixed it.<br />
<span id="more-544"></span></p>
<h4>A general fix</h4>
<p>At first I tried a JavaScript-based <a href="http://homepage.ntlworld.com/bobosola/" rel="external">solution</a> which was easy to install and automatically applied to all PNG images. Simply load the script in your header, enclosed in IE-specific conditional comments:</p>
<pre><code>&lt;!--[if lt IE 7.]&gt;
&lt;script defer type="text/javascript" src="pngfix.js"&gt;&lt;/script&gt;
&lt;![endif]--&gt;</code></pre>
<p>You can view and download pngfix.js <a href="http://homepage.ntlworld.com/bobosola/pngfix.js" rel="external">here</a>. Notice all those floats? I suspect they were responsible for my giving up on this method. For example, it messed up the feed icons in my sidebar (right, below), and for some reason that particular icon failed to complete loading in the IE progress bar (even though it was obviously being displayed). Weird. I don't like weird:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/08/js-png-fix.jpg" height="266" width="430" alt="Js-Png-Fix" /></p>
<p>I did initially convert the affected images to .jpg (since this issue only affects floated images with a .png extension), but then decided "Why should I bend over backwards just for IE?". I reverted to the PNGs and continued to look for another solution. There's always another solution...</p>
<h4>A specific fix</h4>
<p>I subsequently discovered a <a href="http://www.tjkdesign.com/articles/png_overlay_with_no_extra_markup.asp" rel="external">solution</a> that makes use of proprietary CSS and conditional comments for IE. I have few qualms about using proprietary tricks to fix proprietary mistakes!</p>
<p>Here's the relevant code that sits in my head element:</p>
<pre><code>&lt;!--[if lte IE 6]&gt;
&lt;style type="text/css"&gt;
#pngfixband {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src='&lt;?php bloginfo('template_directory'); ?&gt;/styles/bioneural/whiteband-9rules-mt.png'); padding-top: 115px; }
&lt;/style&gt;
&lt;![endif]--&gt;</code></pre>
<p>In my header div I've given the image I want to target an id of "pngfixband":</p>
<pre><code>&lt;p id="whiteband"&gt;&lt;a href="http://www.mediatemple.net/.%3E/9r-bioneural.net"&gt;&lt;img id="pngfixband" src="&lt;?php bloginfo('template_directory'); ?&gt;/styles/bioneural/whiteband-9rules-mt.png" alt="White band" width="115" height="115" title="bioneural.net recommends hosting with (mt) Media Temple" /&gt;&lt;/a&gt;&lt;/p&gt;</code></pre>
<p class="info">Notice how the padding (115px) in the styling corresponds to the height of the image specified in the markup? That's important.</p>
<p>In contrast to default behaviour (left, below), IE now does a respectable job of displaying this particular image as per my intentions (right, below)&mdash;but no other PNGs are adversely affected in the process:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/08/png-result.jpg" height="200" width="315" alt="Png-Result" /></p>
<p>No issues either for the XHTML or CSS Validator.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F08%2F09%2Fvalid-fix-for-png-transparency-on-a-single-image%2F&amp;seed_title=Valid+fix+for+PNG+transparency+on+a+single+image/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Embedding iStockPhoto feeds revisited</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F06%2F15%2Fembedding-istockphoto-feeds-revisited%2F&amp;seed_title=Embedding+iStockPhoto+feeds+revisited</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F06%2F15%2Fembedding-istockphoto-feeds-revisited%2F&amp;seed_title=Embedding+iStockPhoto+feeds+revisited#comments</comments>
		<pubDate>Thu, 15 Jun 2006 11:17:53 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Photography]]></category>

		<category><![CDATA[advertising]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[istockphoto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[rss]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2006/06/15/embedding-istockphoto-feeds-revisited/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>In an <a href="http://www.bioneural.net/2005/12/19/how-to-put-istockphoto-images-on-your-website/">earlier</a> post I described a JavaScript-based method to include recently-approved <a href="http://www.istockphoto.com/file_search.php?action=file&amp;userID=430123&amp;refnum=bmckenzie" rel="external">iStockPhoto</a> images in a page on your website. When I <a href="http://www.bioneural.net/2006/05/29/step-by-step-iblog-to-wordpress/">migrated</a> from a static blogging system (iBlog) to WordPress I found a useful plugin that worked very well in <a href="http://www.mamp.info/en/home/" rel="external">MAMP</a>. Unfortunately it <a href="http://www.bioneural.net/2006/03/15/welcome-to-wordpress/">broke</a> when I moved my developmental site to a live <a href="http://www.dreamhost.com/r.cgi?147252" rel="external">DreamHost</a> server. Here is a bit more background to the problem and an eventual solution that uses <a href="http://simplepie.org/" rel="external">SimplePie</a>. Although the focus here is on displaying photographs, it's a solution that should work with practically any feed you might wish to embed.<br />
<span id="more-516"></span></p>
<h4>No go with latestistockimages.php</h4>
<p>I was initially using Christine's (of <a href="http://www.neato.co.nz/ultimate-tag-warrior/" rel="external">UTW</a> fame) iStockPhoto plug-in for WordPress to display my latest approved images. This worked fine under a localhost development environment, but when I went "live" with DreamHost it <a href="http://www.bioneural.net/2006/03/16/welcome-to-wordpress/">stopped</a> working due to the blocking out "outdated" PHP code that posed a security risk. For some reason my e-mails to the author went unanswered, and the download link has been a 404 for ages.</p>
<h4>Plugging the gap with Feed2JS</h4>
<p>I turned back to <a href="http://jade.mcli.dist.maricopa.edu/feed/" rel="external">Feed2JS</a>, with this in my sidebar:</p>
<pre><code>&lt;?php if (is_page("photos")) { ?&gt;
	&lt;div class="sb-istock"&gt;&lt;h2&gt;My iStockPhoto photocast&lt;/h2&gt;
	&lt;span class="metalink"&gt;&lt;a href="http://www.istockphoto.com/istock_myfiles_rss.php?ID=430123&amp;amp;refnum=bmckenzie" title="RSS feed for iStockPhoto photocast" class="feedlink"&gt;&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/images/feedicon16px.png" alt="RSS" /&gt;&lt;/a&gt;&lt;/span&gt;
	&lt;/div&gt;
	&lt;div class="mistock"&gt;
		&lt;script type="text/javascript" src="http://jade.mcli.dist.maricopa.edu/feed/feed2js.php?src=http://www.istockphoto.com/istock_myfiles_rss.php?ID=430123&amp;amp;refnum=bmckenzie&amp;amp;num=3&amp;amp;targ=y&amp;amp;html=a"&gt;&lt;/script&gt;
	&lt;noscript&gt;&lt;p class="alert"&gt;Please enable JavaScript for full functionality&lt;/p&gt;&lt;/noscript&gt;
	&lt;/div&gt;
&lt;?php } ?&gt;</code></pre>
<p>Here's what I got (with appropriate styling):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/06/Picture%201-1.png" height="226" width="237" alt="Picture 1-1" /></p>
<p>It worked pretty well for the most part, although relied on an external server which I had hoped to avoid. Sometimes is did seem to increase page loading times considerably.</p>
<h4>Let's try feedList</h4>
<p>I decided to try and replicate this with <a href="http://rawlinson.us/blog/?p=212" rel="external">feedList</a>, a WordPress plugin by Bill Rawlinson with "the ability to display linked lists imported from an RSS or ATOM feed". Here's what I put in my sidebar:</p>
<pre><code>&lt;?php if (is_page("photos")) { ?&gt;
	&lt;div class="sb-istock"&gt;&lt;h2&gt;My iStockPhoto photocast&lt;/h2&gt;
	&lt;span class="metalink"&gt;&lt;a href="http://www.istockphoto.com/istock_myfiles_rss.php?ID=430123&amp;amp;refnum=bmckenzie" title="RSS feed for iStockPhoto photocast" class="feedlink"&gt;&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/images/feedicon16px.png" alt="RSS" /&gt;&lt;/a&gt;&lt;/span&gt;
	&lt;/div&gt;
	&lt;div class="mistock"&gt;
		&lt;ul&gt;
		&lt;?php
			feedList(array("rss_feed_url"=&gt;"http://www.istockphoto.com/istock_myfiles_rss.php?ID=430123&amp;amp;refnum=bmckenzie",
							"num_items"=&gt;3,
							"show_description"=&gt;true,
							"random"=&gt;false,
							"sort"=&gt;"none",
							"new_window"=&gt;true,
							"show_date"=&gt;false
					)
			);
		?&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
&lt;?php } ?&gt;</code></pre>
<p>The result was the "same"&mdash;except the image was missing altogether!</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/06/Picture%203-1.png" height="134" width="236" alt="Picture 3-1" /></p>
<p>I contacted Bill who felt it was an issue with the built-in XML parser, as called by Magpie (probably not the bird), and resulting from an empty &lt;img&gt; tag embedded within an empty link. Hmmm, I see... Well, we did agree it was "very odd", but no fix was on the horizon.</p>
<h4>SimplePie to the rescue</h4>
<p>SimplePie is:</p>
<blockquote><p>
... a very fast and easy-to-use class, written in PHP, for reading RSS and Atom syndication feeds.
</p></blockquote>
<p>I have to admit when I first encountered SimplePie (as beta 1) I was totally lost. I couldn't make sense of the documentation and was unable to get it working. But <a href="http://blog.skyzyx.com/" rel="external">Ryan</a> and team have done much of late to reach out to those of us with rudimentary knowledge of PHP. Beta 2 sees the release of a WordPress <a href="http://simplepie.org/docs/installation/wordpress/" rel="external">plugin</a>, and SimplePie has matured into a true easy-to-use solution for "the rest of us". It's so simple that even the potentially scary bit&mdash;modifying <a href="http://en.wikipedia.org/wiki/Chmod" rel="external">CHMOD</a> file permissions on the cache folder&mdash;was no big deal using Transmit:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/06/755.jpg" height="342" width="328" alt="755" /></p>
<p>With simplepie.inc installed, the cache folder created with appropriate permissions, and the plugin installed and activated, I could then replace the above code blocks with this:</p>
<pre><code>&lt;?php if (is_page("photos")) { ?&gt;
&lt;div class="sb-istock"&gt;&lt;h2&gt;My iStockPhoto photocast&lt;/h2&gt;
	&lt;span class="metalink"&gt;&lt;a href="http://www.istockphoto.com/istock_myfiles_rss.php?ID=430123&amp;amp;refnum=bmckenzie" title="RSS feed for iStockPhoto photocast" class="feedlink"&gt;&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/images/feedicon16px.png" alt="RSS" /&gt;&lt;/a&gt;&lt;/span&gt;
	&lt;/div&gt;
	&lt;div class="mistock"&gt;
		&lt;?php echo SimplePieWP('http://www.istockphoto.com/istock_myfiles_rss.php?ID=430123&amp;amp;refnum=bmckenzie', 'items:3, showdate:, shortdesc:'); ?&gt;
&lt;/div&gt;
&lt;?php } ?&gt;</code></pre>
<p>The output of the SimplePieWP function is sent to the screen with "echo" and is given user-input values for the parameters of feed URL, and for display characteristics (number of items to show e.g. 3, whether and how to show the post date e.g. blank, and how much of the description to show e.g. all). Now to toss in a bit of CSS to the "mistock" class (credit to Dave Kellam at <a href="http://eightface.com/log/2005/09/17/styling-thumbnail-photos/" rel="external">Eightface</a>):</p>
<pre><code>.mistock {
	text-align: center;
	display: inline;
	}

.mistock ul, .mistock li {
	list-style: none;
	}

.mistock h3 {
	display: none;
	}

.mistock a img {
	background: #fff;
	border: 1px #ccc solid !important;
	padding: 3px;
	margin: 5px 3px 5px;
	}

.mistock a:hover img {
	border: 1px #999 solid !important;
	}</code></pre>
<h4>The finished product</h4>
<p>Your iStockPhoto embedded photocast should now look something like this:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/06/finished.jpg" height="508" width="255" alt="Finished" /></p>
<p>The only persisting problem is that iStockPhoto offer a poorly-formed feed. I've contacted them twice about encoding ampersands and using "alt" tags to avoid validation errors, but I guess they see this as a low priority.</p>
<p class="info"><em>Update 31.08.06</em>: Although I've not seen any official announcements, iStockPhoto began testing new RSS and Atom feeds in June (I was asked to give feedback). They now offer valid <a href="http://www.istockphoto.com/webservices/feeds/?feedFormat=IStockRSS_2_0&amp;feedName=istockfeed.image.newestUploads&amp;feedParams=UserID=430123" rel="external">RSS</a> 2.0 and <a href="http://www.istockphoto.com/webservices/feeds/?feedFormat=IStockATOM_1_0&amp;feedName=istockfeed.image.newestUploads&amp;feedParams=UserID=430123" rel="external">Atom</a> 1.0 feeds, but in the process of testing we discovered some bugs in SimplePie 1.0 beta 2 which, as yet, have not been resolved. The new feeds make it much easier to apply custom CSS when embedding the feed into your site.</p>
<p class="info"><em>Update 05.11.06</em>: SimplePie 1.0 beta 3 has been released and allows you to integrate a valid iStockPhoto RSS feed (entity-encoding issues persist with the Atom feeds)..</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F06%2F15%2Fembedding-istockphoto-feeds-revisited%2F&amp;seed_title=Embedding+iStockPhoto+feeds+revisited/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Adding a site preferences panel</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F05%2F11%2Fadding-a-site-preferences-panel%2F&amp;seed_title=Adding+a+site+preferences+panel</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F05%2F11%2Fadding-a-site-preferences-panel%2F&amp;seed_title=Adding+a+site+preferences+panel#comments</comments>
		<pubDate>Thu, 11 May 2006 16:03:40 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[music]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2006/05/11/adding-a-site-preferences-panel/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>I recently spent an extortionate amount of time adding a site preferences panel to my site design. It's a solution composed of many parts, put together piece-by-piece with the knowledge and assistance of several Netizens. It is by no means perfect and certainly not indispensable&mdash;but it sure put my tinkering skills to the test. It surprises me how obscure information about adding site preferences is; Google searches on the subject have a high signal-to-noise ratio, and a couple of e-mail enquires to webmasters went unanswered. In keeping with my blog's tagline, here is the "stuff worth sharing". But mostly, as usual, I document the process mainly so I can remember how it was put together!<br />
<span id="more-493"></span></p>
<p class="info">The site preference panel as been remade. Details <a href="http://www.bioneural.net/2008/01/22/bioneuralnet-site-preference-panel-revisited/">here</a>.</p>
<h4>Requirements</h4>
<ul>
<li>The panel should be hidden by default;</li>
<li>It should offer a way to read with musical accompaniment;</li>
<li>It should allow CSS to be disabled (e.g. for small screen viewing);</li>
<li>It should allow stylesheet switching, and be resize-able;</li>
<li>It should allow the user to change font size;</li>
<li>It should be constructed and laid out using valid XHTML and CSS;</li>
<li>It should work (well enough) in Safari, Firefox, Internet Explorer 6+.</li>
</ul>
<h4>Toggle the panel on/off</h4>
<p>I wanted to create the effect of the prefs panel sliding out from under the navigation menu in the header. Likewise, it should slide up into the menu when the panel is closed. The <a href="http://getk2.com/" rel="external">K2</a> theme for <a href="http://wordpress.org/" rel="external">WordPress</a> already includes a (partial) <a href="http://script.aculo.us/" rel="external">script.aculo.us</a> JavaScript effects library. Kristin Pishdadi <a href="http://www.wiphey.com/2006/04/11/tutorial-k2-ajax-shelf/" rel="external">blogged</a> her method of utilizing this to toggle site navigation items, and adapting the same trick to display site preferences seemed like a logical development.</p>
<p>Instead of a text link for the toggle, I used a graphical "switch" positioned within the header. Originally this had no label and (according to feedback in the WordPress Forum) could be overlooked. To address this valid criticism I added a text label to make the function a little more transparent. The code for the switch, within div id="header", is:</p>
<pre><code>&lt;p id="prefs"&gt;
&lt;a href="#" onclick="Effect.Combo('sitepref', {duration: .5}); return false" title="Click to show/hide site preferences"&gt;
&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/sitepref2.gif" width="52" height="28" alt="prefs" /&gt;
&lt;/a&gt;
&lt;/p&gt;</code></pre>
<p>Positioning is done with the following CSS:</p>
<pre><code>#prefs {
position: absolute;
float: right;
left: 100%; /* needed for safari + firefox */
top: 130px;
margin-left: -80px;
z-index: 1000000000;
}</code></pre>
<p class="info">Note that the switch won't display the panel unless JavaScript is enabled (as it nearly always is). Which is a good thing, since switching styles and changing font size won't work if JavaScript is disabled anyway.</p>
<p>Now to place that panel. This is added to header.php just below div id="header" (which contains ul class="menu") like this:</p>
<pre><code>&lt;div id="sitepref" style="display: none;"&gt;
&lt;/div&gt;&lt;!-- Close div sitepref --&gt;</code></pre>
<p>Note that the div has an inline style set to hide the div by default. We get to style the div for display below.</p>
<h4>Soundtrack options</h4>
<p>Oh, you're still reading? I like listening to music but I can't make any, and don't want repetitive embedded audio files terrorizing my readers (I hope there's more than one!). What we need is streaming radio&mdash;so how do we deliver it? My solution was to offer a pick-list of several Internet radio stations using various formats, in the hope that a given reader will have a client already installed that will playback at least one. It's perhaps a stretch to call this an "integrated" solution&mdash;but I use it to bookmark my favourite stations without the need to know in advance which client to launch. On my system I simply choose the station I want to hear and the appropriate client launches and begins streaming in the background, while I continue surfing.</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/05/radio.jpg" height="208" width="207" alt="Radio" /></p>
<p>The station selector is added within div id="sitepref" thus:</p>
<pre><code>&lt;div id="prefsnd" class="column"&gt;
&lt;h3&gt;SOUNDTRACK&lt;/h3&gt;
&lt;img src="../control_play.png" alt="snd" /&gt;
&lt;p&gt;Internet radio tuner:&lt;/p&gt;
&lt;form id="radio" action="http://www.bioneural.net"&gt;
&lt;div&gt;
&lt;select class="inputbox" onchange="window.location=this.value;" name="list"&gt;
&lt;option value="selected"&gt;Select station...&lt;/option&gt;
&lt;option value="stream url goes here"&gt;Station name&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;p&gt;
Client: &lt;a href="http://www.whatever.com/"&gt;Player&lt;/a&gt;&lt;br /&gt;
Client may require configuration
&lt;/p&gt;
&lt;/div&gt;</code></pre>
<h4>Turn off CSS</h4>
<p>Note to self: find an evening class to learn PHP! Disabling CSS sounds so simple, but getting this to work proved to be a challenge. When it comes to PHP and JavaScript my knowledge is pretty-much cut-and-paste. </p>
<p>In truth I'm not sure how important this functionality is in the Real World, but here in the Matrix "getting naked" and exposing your (hopefully) <a href="http://www.digital-web.com/articles/writing_semantic_markup/" rel="external">semantic</a> markup is unadulterated nerdiness. There's nothing (much) erotic about looking at a site with no CSS on, but it can be a pleasure to get "back to basics" and relive the early style-constrained days of the web. Ah yes, the browser-default serif font and general lack of excitement that turns beautiful Safari into a <a href="http://en.wikipedia.org/wiki/Mosaic_web_browser" rel="external">Mosaic</a> clone...</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/05/naked.jpg" height="292" width="450" alt="Naked" /></p>
<p>I looked into two ways to toggle CSS off and on, one "styleswitcher" based around JavaScript and the other around PHP. I actually tried several variations of each, but the choice essentially came down to two:</p>
<p><strong>JavaScript styleswitcher</strong></p>
<p>The ALA <a href="http://www.alistapart.com/articles/alternate/" rel="external">styleswitcher.js</a> by Paul Sowden is pretty well-known. As well as a link to the appropriate JavaScript an empty href is required in the header:</p>
<pre><code>&lt;!--Start styles--&gt;
&lt;link rel="stylesheet" type="text/css" href="main.css" title="default" /&gt;
&lt;link rel="alternate stylesheet" type="text/css" title="fluid" href="fluid.css" /&gt;
&lt;link rel="alternate stylesheet" type="text/css" title="none" href="" /&gt;
&lt;!--End styles--&gt;</code></pre>
<p>The actual switch is built like this:</p>
<pre><code>&lt;a href="#" onclick="setActiveStyleSheet('none');return false;" title="turn off"&gt;Off&lt;/a&gt;
 | &lt;a href="#" onclick="setActiveStyleSheet('default');return false;" title="turn on"&gt;On&lt;/a&gt;</code></pre>
<p>The above is simplified; I got unexpected styling results, presumably because of the way K2 separates the default from the user-defined styles. You may fair better. Because styleswitcher.js sets a cookie, the CSS state will persist from page-to-page.</p>
<p><strong>PHP styleswitcher</strong></p>
<p>I found Chris Clark's PHP <a href="http://www.alistapart.com/articles/phpswitch/" rel="external">Switcher</a> difficult to adapt. Although it can be <a href="http://www.stylehack.com/wordpress/index.php?p=8" rel="external">repurposed</a> for WordPress templates I wanted some simple code I could understand and that would keep my template intelligible. And Joe Skidmore <a href="http://www.joe2torials.com/view_tutorial.php?view=50" rel="external">provided</a> it. With help from Joe and Marcus Crestani (who also <a href="http://www.crestani.de/" rel="external">wrote</a> a PHP switcher) I could add a simple CSS toggle thus:</p>
<pre><code>&lt;!--Start styles--&gt;
&lt;?php ini_set('arg_separator.output','&amp;amp;amp;'); ?&gt;
&lt;?php if( $_GET['css'] != 'false' ) { ?&gt;
&lt;link rel="stylesheet" type="text/css" href="main.css" /&gt;
&lt;?php if (get_option('k2scheme') != '') { ?&gt;
&lt;link rel="stylesheet" type="text/css" href="extra.css" /&gt;
&lt;?php } ?&gt;
&lt;link rel="alternate stylesheet" type="text/css" title="fluid" href="fluid.css" /&gt;
&lt;?php } ?&gt;
&lt;!--End styles--&gt;</code></pre>
<p>The first line encodes the ampersand that would otherwise generate a XHTML validation error (see <a href="http://www.w3.org/QA/2005/04/php-session" rel="external">here</a>).</p>
<p>The second and last line of PHP enclose all the stylesheets and form the basis of the toggle (the middle bit is K2-specific). If css=false then nothing will be included between the comments; if css=true you'll get the lot. The actual switch is built like this:</p>
<pre><code>&lt;a href="?css=false"&gt;Off&lt;/a&gt; | &lt;a href="?css=true"&gt;On&lt;/a&gt;</code></pre>
<p>Despite some much-appreciated help, I wasn't able to get the CSS on/off state to persist using a session variable or cookie, in a way that suited my header.php template and its multiple stylesheet links. The solution? Decide persistence doesn't pay.</p>
<h4>Alternative styles</h4>
<p>You already know how this works&mdash;it's styleswitcher.js again! I wrote some rules in fluid.css to break the design out of its fixed-width container, allowing it to re-size according to the width of the browser window, with the primary content stacked on top of the sidebar.</p>
<pre><code>&lt;a href="#" onclick="setActiveStyleSheet('fluid'); return false;"&gt;Fluid&lt;/a&gt;
 | &lt;a href="#" onclick="setActiveStyleSheet(''); return false;"&gt;Fixed&lt;/a&gt;</code></pre>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/05/style.jpg" height="225" width="171" alt="Style" /></p>
<p>What about swapping WordPress themes on the fly? Get <a href="http://dev.wp-plugins.org/file/theme-switcher/trunk/theme-switcher.php" rel="external">this</a> plug-in.</p>
<h4>Changing font size</h4>
<p>Some sites allow the user to specify an exact font size, or even typeface. I wanted a basic "size up" and "size down" control, and found a JavaScript solution <a href="http://www.dynamicdrive.com/forums/archive/index.php/t-7124.html" rel="external">here</a>.</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/05/size.jpg" height="143" width="94" alt="Size" /></p>
<p>It's easy to implement, seems to work across the main browsers, and avoids having to have multiple additional stylesheets for each font size.</p>
<h4>Resize-able three-column CSS layout</h4>
<p>Having ditched the temporary table, I joined Matthew Levine in his <a href="http://www.alistapart.com/articles/holygrail" rel="external">quest</a> for the Holy Grail, and decided to layout the prefs panel as a mini page (with header, 3 columns, and footer) inside a page. It may take some trial-and-error, and a calculator is optional, but the result is something like this (colours changed to highlight divs; the middle div is fluid-width):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/05/3cols.jpg" height="151" width="450" alt="3Cols" /></p>
<p>The footer contains only an image, with the div height set to the height of the image:</p>
<pre><code>#pfooter {
height: 10px;
background: #f2f2f2 url(spike.png) bottom center repeat-x;
}</code></pre>
<p>For the record, here is the markup for the siteprefs div less the actual controls/ toggles:</p>
<pre><code>&lt;div id="sitepref" style="display: none;"&gt;
&lt;div id="pheader"&gt;bioneural.net site preferences&lt;/div&gt;
&lt;div id="pcontainer"&gt;
&lt;div id="prefcss" class="column"&gt;
&lt;h3&gt;STYLING&lt;/h3&gt;
etc.
&lt;/div&gt;
&lt;div id="prefsnd" class="column"&gt;
&lt;h3&gt;SOUNDTRACK&lt;/h3&gt;
etc.
&lt;/div&gt;
&lt;div id="preffnt" class="column"&gt;
&lt;h3&gt;READABILITY&lt;/h3&gt;
etc.
&lt;/div&gt;
&lt;div id="pfooter-wrapper"&gt;
&lt;div id="pfooter"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- Close div sitepref --&gt;</code></pre>
<p>The CSS is slightly modified from <a href="http://www.alistapart.com/d/holygrail/example_3.html" rel="external">this</a> ALA example file.</p>
<p>Wow. What an Odyssey! I ask only, am I at the beginning or the end?</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F05%2F11%2Fadding-a-site-preferences-panel%2F&amp;seed_title=Adding+a+site+preferences+panel/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Lightbox JS v2.0</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F03%2F29%2Flightbox-js-v20%2F&amp;seed_title=Lightbox+JS+v2.0</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F03%2F29%2Flightbox-js-v20%2F&amp;seed_title=Lightbox+JS+v2.0#comments</comments>
		<pubDate>Wed, 29 Mar 2006 18:24:54 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Quicklinks]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[Photography]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2006/03/29/lightbox-js-v20/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p><a href="http://www.huddletogether.com/projects/lightbox2/" rel="external">Lightbox JS v2.0</a>: Lightbox JS is a simple, unobtrusive script used to overlay images on the current page. It's a snap to setup and works on all modern browsers.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F03%2F29%2Flightbox-js-v20%2F&amp;seed_title=Lightbox+JS+v2.0/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.987 seconds -->
