<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blue Arena &#187; Tutorials</title>
	<atom:link href="http://www.bluearena.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bluearena.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 05 Jun 2010 17:23:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascript: Shortening a breadcrumb using JQuery</title>
		<link>http://www.bluearena.com/2010/01/javascript-shortening-a-breadcrumb-using-jquery/</link>
		<comments>http://www.bluearena.com/2010/01/javascript-shortening-a-breadcrumb-using-jquery/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 12:50:19 +0000</pubDate>
		<dc:creator>Maloric</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[accessible]]></category>
		<category><![CDATA[breadcrumb]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[short]]></category>
		<category><![CDATA[shorten]]></category>
		<category><![CDATA[too long]]></category>
		<category><![CDATA[trail]]></category>

		<guid isPermaLink="false">http://www.bluearena.com/?p=188</guid>
		<description><![CDATA[A lot of sites these days use breadcrumb trails to make navigation easier for their users. This is essentially a list of every parent category/section of the page you&#39;re on, and might look something like this:
Home &#62; About us &#62; Meet the team
Each of these is typically a hyperlink back to the relevant section. Now [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of sites these days use breadcrumb trails to make navigation easier for their users. This is essentially a list of every parent category/section of the page you&#39;re on, and might look something like this:</p>
<p><a href="#">Home</a> &gt; <a href="#">About us</a> &gt; <a href="#">Meet the team</a></p>
<p>Each of these is typically a hyperlink back to the relevant section. Now these are great, but what happens if your breadcrumb isn&#39;t that small? It&#39;s easy to see a situation where you have a bunch of really long titles that cause the breadcrumb to span over two or three lines. This isn&#39;t always what you want, since it can make the breadcrumb look broken. You might just decide to make some of the titles smaller, but with content managed sites and page names stuffed with SEO keywords, this is often easier said than done.</p>
<p><span id="more-188"></span>So I came up with a solution to this problem using <a href="http://jquery.com/">JQuery</a>. It relies on a certain kind of markup; you must use &lt;ul&gt; and &lt;li&gt; tags to build your breadcrumb rather than a continuous string of text. Hopefully you already know how to style a &lt;ul&gt; as a breadcrumb, but if not, the following should help:</p>
<ul>
<li>Use either float:left, display:inline, or display:inline-block on your &lt;li&gt; tags.</li>
<li>If you want to seperate each item with an image, use the following as well:
<ul>
<li>padding-left:24px (or whathever you need) on your &lt;li&gt; tag</li>
<li>background:url(/images/breadcrumb.gif) left no-repeat; on your &lt;li&gt;</li>
</ul>
</li>
</ul>
<p><em>(I realise the background image could be applied instead as a bullet image, but this doesn&#39;t look great in some older browsers, so the above method is a little safer)</em></p>
<p>You should be able to figure out the rest of the styling from there, but if not, drop me a comment and I&#39;ll help you out.</p>
<h2>The Javascript</h2>
<p>Ok, let me explain what the script does and then I&#39;ll post the code. Firstly, the script has two properties: &quot;breadcrumb&quot; and &quot;maxWidth&quot;. The first is a <a href="http://jquery.com/">JQuery</a> selector for the &lt;ul&gt; element. If not supplied, this defaults to &quot;$(&#39;div#breadcrumb &gt; ul&#39;); a &lt;ul&gt; that is the immediate descendant of a div with the ID of &quot;breadcrumb&quot;. The second is the maximum width in pixels the breadcrumb should be, which defaults to the <a href="http://docs.jquery.com/CSS/outerWidth">outerWidth</a> of the &lt;ul&gt;. If it goes over this width, the breadcrumb is shortened until it fits.</p>
<p>Essentially, what the script does is check the combined width of the breadcrumb&#39;s &lt;li&gt; elements. If this total exceeeds the &quot;maxWidth&quot; property, the script will shorten the first non-shortened list item and check again. It continues doing this until the combined width of all of the list items is less than &quot;maxWidth&quot;. When each item in shortened, the text is replaced by &quot;&#8230;&quot; and to keep things nice and accessible, a title tag is added with the original text.</p>
<p>And that&#39;s that. All that&#39;s left is to show you the script and how to call it:</p>
<pre>function shortenBreadcrumb(options){
    /*
        Shortens the breadcrumb to a specified width by removing the text from one list item
        at a time and replacing it with &quot;...&quot; - accepts an options object as an optional
        parameter with two options:
            shortenBreadcrumb({
                breadcrumb : $(&#39;div#breadcrumb &gt; ul&#39;),
                maxWidth : 725
            });

        The first is the selector for the breadcrumb ul, the second is the maximum width you
        want it to be.
    */

    var breadcrumb = $(&#39;div#breadcrumb &gt; ul&#39;);
    var maxWidth = $(&#39;div#breadcrumb&#39;).innerWidth();

    if (options != undefined){
        if (options.breadcrumb != null) { breadcrumb = options.breadcrumb; }
        if (options.maxWidth != null) { maxWidth = options.maxWidth; }
    }

    var levelCount = breadcrumb.find(&#39;li&#39;).size();
    var shortEnough = false;
    var totalWidth;
    while (shortEnough == false) {
        totalWidth = 0;
        breadcrumb.children(&#39;li&#39;).each (function(){
            totalWidth += $(this).outerWidth(true);
        });
        if (totalWidth &gt; maxWidth){
            var li = breadcrumb.children(&#39;li&#39;).not(&#39;.short&#39;).eq(1);
            li.addClass(&#39;short&#39;);
            li.children(&#39;a&#39;).attr(&#39;title&#39;, li.children(&#39;a&#39;).html());
            li.children(&#39;a&#39;).html(&#39;...&#39;);
        }
        else {
            shortEnough = true;
        }
    }
}
</pre>
<p>Include this script in your page and call using:</p>
<pre>$(document).ready(function(){
    shortenBreadcrumb({
        breadcrumb : $(&#39;ul#breadcrumb&#39;),
        maxWidth : 600
    });
});
</pre>
<p>Of course, any of these two options can be left blank, so you can call it like so:</p>
<pre>    shortenBreadcrumb();
</pre>
<p>It goes without saying that this script requires the <a href="http://jquery.com/">JQuery</a> library. If you want to use the script in your site, please do, but a mention of Blue Arena or a comment would be appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bluearena.com/2010/01/javascript-shortening-a-breadcrumb-using-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Checking if a javascript function exists</title>
		<link>http://www.bluearena.com/2009/08/quick-tip-checking-if-a-javascript-function-exists/</link>
		<comments>http://www.bluearena.com/2009/08/quick-tip-checking-if-a-javascript-function-exists/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 13:14:15 +0000</pubDate>
		<dc:creator>Maloric</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[exist]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.bluearena.com/?p=184</guid>
		<description><![CDATA[I recently had to write a javascript function that would be used across several sites, and it would call another function that might or might not exist on any of these sites.  There are probably a couple of ways you could get around the inevitable error caused by calling a function that doesn&#8217;t exist (I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to write a javascript function that would be used across several sites, and it would call another function that might or might not exist on any of these sites.  There are probably a couple of ways you could get around the inevitable error caused by calling a function that doesn&#8217;t exist (I&#8217;m thinking some sort of overload here), but I found that the simplest method is to wrap the function call in an if statement like so:</p>
<pre>if(typeof myFunction == 'function') {
	myFunction();
}</pre>
<p>Handy, huh?</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">if(typeof yourFunctionName == &#8216;function&#8217;) {<br />
yourFunctionName();<br />
}</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bluearena.com/2009/08/quick-tip-checking-if-a-javascript-function-exists/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rounded Corners and Fluid Boxes</title>
		<link>http://www.bluearena.com/2009/05/rounded-corners-and-fluid-boxes/</link>
		<comments>http://www.bluearena.com/2009/05/rounded-corners-and-fluid-boxes/#comments</comments>
		<pubDate>Fri, 22 May 2009 23:09:17 +0000</pubDate>
		<dc:creator>Maloric</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[corner]]></category>
		<category><![CDATA[corners]]></category>
		<category><![CDATA[cross]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[expand]]></category>
		<category><![CDATA[explorer]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[fluid]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[ie7]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[round]]></category>
		<category><![CDATA[rounded]]></category>

		<guid isPermaLink="false">http://wordpress.bluearena.com/?p=41</guid>
		<description><![CDATA[Rounded corners have long been a hot topic for web developers, with several methods out there, each with their benefits and disadvantages.  Although rounded corners seem to have fallen out of favour recently in favour of simple, clean designs, they still remain a powerful tool in any designer&#8217;s arsenal, which means knowing how to create [...]]]></description>
			<content:encoded><![CDATA[<p>Rounded corners have long been a hot topic for web developers, with several methods out there, each with their benefits and disadvantages.  Although rounded corners seem to have fallen out of favour recently in favour of simple, clean designs, they still remain a powerful tool in any designer&#8217;s arsenal, which means knowing how to create them is essential.  This tutorial will show you how to create tableless rounded corners than scale with fluid width and height, and can be expanded on to incorporate drop shadows or custom borders.<span id="more-41"></span></p>
<h2>What you need</h2>
<p>This tutorial assumes that you have a decent working knowledge of CSS and a little javascript (necessary if you want full IE6 support).  You&#8217;ll also need some sort of graphics editing software such as Adobe Photoshop or <a title="Go to the GIMP website" href="http://www.gimp.org/" target="_blank">the GIMP</a>.  I&#8217;ll be using Photoshop.</p>
<h2>Step 1: Design Your Box</h2>
<p><img class="alignleft size-medium wp-image-42" title="testbox" src="http://www.bluearena.com/wp-content/uploads/2009/05/testbox.gif" alt="testbox" width="197" height="126" />You&#8217;ll need to start off by creating an image of how your box will look when it&#8217;s finished.  For now I&#8217;m going to create a simple grey box with dark grey corners, something like the image you see here.  To create something similar simply draw a rectangle with rounded corners and add a 1px stroke.</p>
<p>It&#8217;s important that your box goes right to the edge of the image, so trim off any unneccessary white space.  You can save this as box1.gif.</p>
<h2>Step 2: The corners include</h2>
<p>The concept of this solution is to include four divs &#8211; one for each corner &#8211; that will be positioned absolutely within our both and styled appropriately.  Since this is the sort of technique that gets reused many times in the site, I prefer to create an include that contains all four corners.  Create a new file called &#8216;corners.html&#8217; and place the following markup inside:</p>
<pre>&lt;div class="tl corner"&gt;&lt;/div&gt;
&lt;div class="tr corner"&gt;&lt;/div&gt;
&lt;div class="bl corner"&gt;&lt;/div&gt;
&lt;div class="br corner"&gt;&lt;/div&gt;</pre>
<p>You&#8217;ll have noticed that each div has two classes.  The first just tells us which corner it is (top left, top right, bottom left and bottom right respectively).  The second lets us easily apply styles that all four corners will use.</p>
<h2>Step 3: The Box</h2>
<p>Let&#8217;s create the box and the markup we&#8217;ll need now, and then we&#8217;ll style it up once we&#8217;re done.  Where you want your box to appear, type the following code:</p>
<pre>&lt;div class="box1 corners"&gt;
    &lt;!--#include virtual='/path/to/corners.html'--&gt;
    &lt;div class="boxContent"&gt;
        &lt;p&gt;This is where your content will go&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;</pre>
<p>I&#8217;d better explain some of this.  The outer div is the box itself.  This will be styled to match your design and hads the extra class &#8220;corners&#8221; there to allow you to apply classes to all of your boxes, as well as making some of the javascript easier later.</p>
<p>Next is the corners include, which includes the four divs you created a moment ago.  Much nicer than including those manually every time, huh?</p>
<p>Last is a div called &#8220;boxContent&#8221;.  This is the div you&#8217;ll apply all of your padding to (allowing you to declare width:100% on the box itself without breaking anything).  It&#8217;s also useful to put overflow:hidden on the inner div to prevent the Firefox Float Bug if you float the contents of the box &#8211; this wouldn&#8217;t work on the outer box as the corners will need to be placed outside the box in order to work.  If all isn&#8217;t clear, don&#8217;t worry, just read on.</p>
<h2>Step 4: The CSS</h2>
<p>Ok, now for the fun part.  We&#8217;re going to start by styling up the basic box without rounded corners.  Basically what we need is a background colour, border and some padding.  Copy the following into your stylesheet:</p>
<pre>/* This allows us to position the corners relative to the box instead of the page */
div.corners { position:relative; }

/* This will make sure your corners never display over your content */
div.boxContent { position:relative; z-index:3; }

/* Styles specific to box1 */
div.box1 { color:#000; background:#E0E0E0; border:1px solid #666; }
div.box1 div.boxContent { padding:12px; overflow:hidden; }</pre>
<p>That&#8217;s it for the box.  Now for the corners.  They&#8217;re all going to be the same size and have many similar properties.  I like to create a seperate stylesheet for box/corner styles, but you&#8217;re welcome to put them where you like.</p>
<pre>div.corner { width:12px; height:12px; position:absolute; z-index:2;}
div.tl { top:-1px; left:-1px; background-position:top left; }
div.tr { top:-1px; right:-1px; background-position:top right; }
div.bl { bottom:-1px; left:-1px; background-position:bottom left; }
div.br { bottom:-1px; right:-1px; background-position:bottom right; }</pre>
<p>This has given us some universal corner styles.  Now we need to point our box 1 corners at the correct background image.  Add this line to your stylesheet and you&#8217;re good to go:</p>
<pre>div.box1 div.corner { background-image:url(/path/to/box1.gif); }</pre>
<p>Go on &#8211; check out your box now.  If you&#8217;re thinking that it can&#8217;t be that easy, think again.  You only had to cut out one image, not 4, and the box resizes perfectly in every modern browser.</p>
<h2>The Exception to the Rule</h2>
<p>Unfortunately if you&#8217;re using IE6 you&#8217;ll notice a rather frustrating bug.  If your box width or height is an odd number the bottom and right coordinates of your boxes will be 1px too short, meaning the border will show through.  There are two solutions.  The first uses javascript, and is my preferred method, to be covered in another post.  The second method involves only css:</p>
<p>The easiest way to fix the right coordinate is to fix the width of each box to an even number.  This isn&#8217;t too bad for fixed width sites, though could pose a problem for fluid layouts.  Unfortunately the bottom coordinate can&#8217;t be so easily fixed due to the fact that boxes should expand downward depending on the content.  So we need a more complex solution.</p>
<p>First, add the following line to corners.html:</p>
<pre>&lt;div class="btm corner"&gt;&lt;/div&gt;</pre>
<p>This div will be styled to mimic the bottom edge of the box.  We&#8217;ll need a background image for it, which will be a 2px or greater slice of the bottom of the box.  This will need to be repeated horizontally, so make sure there&#8217;s nothing else in the image.</p>
<p>Now you&#8217;ll need to change the &#8220;bottom&#8221; coordinate of your &#8220;bl&#8221; and &#8220;br&#8221; corners to -2px instead of -1px.  This means the corners will display 1px further down than they should.  This is where the &#8220;btm&#8221; div comes into play.  Add the following to your stylesheet:</p>
<pre>div.btm {
    height:12px;
    width:100%;
    bottom:-2px;
    left:-1px;
    background:url(/path/to/box1-btm.gif) bottom repeat-x;
    z-index:1;
}</pre>
<p>Now the bottom div will display 1px out the same as the corners, but because the three divs cover the bottom edge of the box, you can&#8217;t see the discrepancy, providing a CSS only solution to the problem.  Note that the bottom div needs to be placed below the two corners, hence a z-index of 1.</p>
<h3>Next time: A Javascript Solution</h3>
<p>Next time we&#8217;ll look at fixing the IE6 problem using JQuery to reposition the corners depending on the width of their parent.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bluearena.com/2009/05/rounded-corners-and-fluid-boxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
