<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.2" -->
<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/"
	>

<channel>
	<title>ShopDev Website Design Blog</title>
	<link>http://www.shopdev.co.uk/blog</link>
	<description>Website Design, XHTML, CSS, jQuery and CubeCart</description>
	<pubDate>Fri, 01 Aug 2008 19:41:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<item>
		<title>Catalyst V4 Update Released</title>
		<link>http://www.shopdev.co.uk/blog/catalyst-v4-update-released/</link>
		<comments>http://www.shopdev.co.uk/blog/catalyst-v4-update-released/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 19:40:17 +0000</pubDate>
		<dc:creator>Homar</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.shopdev.co.uk/blog/catalyst-v4-update-released/</guid>
		<description><![CDATA[An updated version of the Catalyst V4 CubeCart skin has been released.  This latest version corrects a number of reported issues:

Basket &#38; customer details are not passed to the gateway
Missing details on &#8220;confirmed&#8221; page.
Multiple images may have wrong paths - Lightbox not working.
&#8220;Original Images&#8221; not scaled if dimensions are larger than browser window.
Textbox/Textarea product options [...]]]></description>
			<content:encoded><![CDATA[<p>An updated version of the Catalyst V4 CubeCart skin has been released.  This latest version corrects a number of reported issues:</p>
<ul>
<li>Basket &amp; customer details are not passed to the gateway</li>
<li>Missing details on &#8220;confirmed&#8221; page.</li>
<li>Multiple images may have wrong paths - Lightbox not working.</li>
<li>&#8220;Original Images&#8221; not scaled if dimensions are larger than browser window.</li>
<li>Textbox/Textarea product options are not displayed in the product pages.</li>
</ul>
<p>I have been working with a number of clients to correct these issues.  It is highly recommended that you update to this latest version.  Instructions to perform a manual update are included in the version.txt file (supplied inside the downloaded package).</p>
<p>To receive this update, please drop me an email with your Google Checkout Order Number.  You can find contact details on our homepage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shopdev.co.uk/blog/catalyst-v4-update-released/feed/</wfw:commentRss>
		</item>
		<item>
		<title>jQuery From Scratch: Functions</title>
		<link>http://www.shopdev.co.uk/blog/jquery-functions-tutorial/</link>
		<comments>http://www.shopdev.co.uk/blog/jquery-functions-tutorial/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 01:40:52 +0000</pubDate>
		<dc:creator>Homar</dc:creator>
		
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.shopdev.co.uk/blog/jquery-from-scratch-functions/</guid>
		<description><![CDATA[This is part 2 of the "jQuery From Scratch" series of tutorials. If you have not read part 1, you can have a quick read. This tutorial will deal with writing and executing functions in JavaScript.  jQuery does not provide a quick method for creating functions. That's because it doesn't need to. So what are functions? Instead of giving you the standard definition, I'll explain why/when you might want to create and use functions in your code.  Of course, I'll also explain how to write and execute functions.]]></description>
			<content:encoded><![CDATA[<p>This is part 2 of the &#8220;jQuery From Scratch&#8221; series of tutorials.  If you have not read part 1, you can have a <a rel="nofollow" href="http://www.shopdev.co.uk/blog/jquery-from-scratch-a-beginners-guide/" title="jQuery Beginners Guide" target="_blank">quick read</a>.  This tutorial will deal with writing and executing functions in JavaScript.</p>
<p>jQuery does not provide a quick method for creating functions.  That&#8217;s because it doesn&#8217;t need to.  So what are functions?  Instead of giving you the standard definition, I&#8217;ll explain why/when you might want to create and use functions in your code.</p>
<p>Say that you have a block of code that you would like executed on multiple events.  This code could do anything.  The principal to consider is that you will need this code to be executed as multiple events are triggered.  Instead of writing the code over and over again for each event, you could add this code to a function and then execute this function whenever you want the code to be executed.</p>
<h3>Creating Functions</h3>
<p>To create a function called &#8220;aFunction&#8221;, we could write:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> aFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Say that we wanted to alert the user each time this function is executed.  We could write:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> aFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello World!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this example, the user is alerted each time the function is executed.</p>
<h3>Executing Functions</h3>
<p>We can execute the function when any event is triggered.  If we wanted the function to be executed when the page has loaded, we could write:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  aFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is pretty straightforwards&#8230; but there&#8217;s more to functions.</p>
<h3>Passing Arguments</h3>
<p>We can pass values into the function that are used when the code is executed.  To demonstrate this, I&#8217;ll continue with the example that I&#8217;ve been using.  Instead of displaying &#8220;Hello World!&#8221; whenever the function is executed, we could pass the message into the function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> aFunction<span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We could now execute the function as follows (to display any old message to the visitor) when the page has loaded:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  aFunction<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Just a short message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We could pass multiple arguments by separating them with a comma:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> addNumbers<span style="color: #009900;">&#40;</span>num1<span style="color: #339933;">,</span>num2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> total <span style="color: #339933;">=</span> num1 <span style="color: #339933;">+</span> num2<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">return</span> total<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The function above will simply return the total value of the two numbers passed as arguments.  It is important to note that the value returned will not by output to the page.  You could print the returned value to the page by using document.write:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span>addNumbers<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.shopdev.co.uk/blog/jquery-functions-tutorial/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Neutrino - Back To Basics</title>
		<link>http://www.shopdev.co.uk/blog/neutrino-back-to-basics/</link>
		<comments>http://www.shopdev.co.uk/blog/neutrino-back-to-basics/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 23:59:16 +0000</pubDate>
		<dc:creator>Homar</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.shopdev.co.uk/blog/neutrino-back-to-basics/</guid>
		<description><![CDATA[I received a wealth of feedback following the release of the Catalyst skin for CubeCart V4.  The feedback was all extremely positive.  I must thank all my clients for taking the time to forward your suggestions.  Whilst many of you appreciated the bundled mods, it is becoming clear that a proportion would rather not make [...]]]></description>
			<content:encoded><![CDATA[<p>I received a wealth of feedback following the release of the Catalyst skin for CubeCart V4.  The feedback was all extremely positive.  I must thank all my clients for taking the time to forward your suggestions.  Whilst many of you appreciated the bundled mods, it is becoming clear that a proportion would rather not make physical alterations to core PHP files.</p>
<p>Over the past few days, I have been working on a brand new skin.  This skin will be exclusive to CubeCart V4.  Although it would be possible to build a &#8220;plug-and-play&#8221; skin (that includes all our popular mods/tweaks), it just isn&#8217;t fesible.  What I have managed to do is further develop the &#8220;AJAX Add To Cart&#8221; feature.  The latest version will be included with the &#8220;Neutrino&#8221; skin.</p>
<p>So how would one install the Neutrino skin?  Simple&#8230;  Obviously, you will need to upload the skin to your CubeCart directory.  Once you&#8217;ve done that, there are just 4 new files to upload to your CubeCart directory.  Activate the skin through the administration panel and away you go!</p>
<p>Are there any new features?  Well&#8230; there is just one.  Visitors will be able to change the way that products are displayed in the category pages (and search results).  At the click of a mouse, the products can be displayed in a grid or in rows.</p>
<p>Why not take a look at the <a rel="nofollow" href="http://www.shopdev.co.uk/demos/CubeCartV4/index.php" title="Neutrino Demo" target="_blank">demo</a>.  Let me know what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shopdev.co.uk/blog/neutrino-back-to-basics/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sortable Lists Using jQuery UI</title>
		<link>http://www.shopdev.co.uk/blog/sortable-lists-using-jquery-ui/</link>
		<comments>http://www.shopdev.co.uk/blog/sortable-lists-using-jquery-ui/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 23:49:09 +0000</pubDate>
		<dc:creator>Homar</dc:creator>
		
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.shopdev.co.uk/blog/sortable-lists-using-jquery-ui/</guid>
		<description><![CDATA[Unordered lists have a number of useful applications.  They are commonly used to structure a site's navigation.  I have found, in a number of web applications, that the ability to reorder (sort) such lists would be extremely useful.  So, how can this be achieved?]]></description>
			<content:encoded><![CDATA[<p>Unordered lists have a number of useful applications.  They are commonly used to structure a site&#8217;s navigation.  I have found, in a number of web applications, that the ability to reorder (sort) such lists would be extremely useful.  So, how can this be achieved?</p>
<p>I&#8217;m a big fan of the jQuery library.  Since most of the applications I build use jQuery, developing with this library would be the most logical approach.  But wait&#8230;  It looks like there are 2 jQuery plugins that allow elements to be sorted.  These are the <a rel="nofollow" href="http://interface.eyecon.ro/" title="jQuery Interface" target="_blank">jQuery Interface</a> plugin and <a rel="nofollow" href="http://ui.jquery.com/home" title="jQuery UI" target="_blank">jQuery UI</a>.</p>
<p>At first, I started working with &#8220;Interface&#8221;.  I soon ran into problems as I started working with styled lists.  For some reason, the list elements lost their styling as they were being dragged.  I just couldn&#8217;t quite put my finger on the problem - perhaps I missed something.  I then started working with jQuery UI.  This plugin retained the styling - perfect!</p>
<p>However, neither of these plugins provide a method to easily save and reload the list element order.  Hence, should a user change the order of the list, these changes would be lost as the page is refreshed.<br />
<a rel="nofollow" href="http://www.shopdev.co.uk/blog/sortables.html" class="demo" target="_blank" title="Sortable Lists"><span class="demo"></span></a><br style="line-height: 0px" clear="all" /><br style="line-height: 0px" clear="all" /></p>
<h3>Saving the Reordered List</h3>
<p>I determined that the easiest way to accomplish this is through the use of a cookie.  The jQuery UI plugin already allows you to send the ID&#8217;s of the list elements (in order) to an array.  Using Klaus Hart&#8217;s Cookie plugin, we can easily save the list element order to a cookie.  But how do we retain/reload the element order saved to the cookie?</p>
<p>To restore the element order, I decided to remove all the sortable list elements from the DOM and then immediately append them to their parent element (in the order sepcified by the cookie).  This is all done after the document has loaded.</p>
<h3>The HTML Markup</h3>

<div class="wp_syntax"><div class="code"><pre class="html4strict"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;list1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>List Item 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>List Item 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>List Item 3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-4&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>List Item 4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>List Item 5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-6&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>List Item 6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul&gt;</span></span></pre></div></div>

<h3>The Javascript</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #006600; font-style: italic;color: #666666;">/////////////////////////////////////////////////////////////////</span>
<span style="color: #006600; font-style: italic;color: #666666;">/////  EDIT THE FOLLOWING VARIABLE VALUES  //////////////////////</span>
<span style="color: #006600; font-style: italic;color: #666666;">/////////////////////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #006600; font-style: italic;color: #666666;">// set the list selector</span>
<span style="color: #003366; font-weight: bold;">var</span> setSelector <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#list1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;color: #666666;">// set the cookie name</span>
<span style="color: #003366; font-weight: bold;">var</span> setCookieName <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;listOrder&quot;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;color: #666666;">// set the cookie expiry time (days):</span>
<span style="color: #003366; font-weight: bold;">var</span> setCookieExpiry <span style="color: #339933;">=</span> <span style="color: #CC0000;">7</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;color: #666666;">/////////////////////////////////////////////////////////////////</span>
<span style="color: #006600; font-style: italic;color: #666666;">/////  YOU PROBABLY WON'T NEED TO EDIT BELOW  ///////////////////</span>
<span style="color: #006600; font-style: italic;color: #666666;">/////////////////////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #006600; font-style: italic;color: #666666;">// function that writes the list order to a cookie</span>
<span style="color: #003366; font-weight: bold;">function</span> getOrder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;color: #666666;">// save custom order to cookie</span>
	$.<span style="color: #006600;">cookie</span><span style="color: #009900;">&#40;</span>setCookieName<span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span>setSelector<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">sortable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;toArray&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> expires<span style="color: #339933;">:</span> setCookieExpiry<span style="color: #339933;">,</span> path<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;color: #666666;">// function that restores the list order from a cookie</span>
<span style="color: #003366; font-weight: bold;">function</span> restoreOrder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> list <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>setSelector<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>list <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span>
&nbsp;
	<span style="color: #006600; font-style: italic;color: #666666;">// fetch the cookie value (saved order)</span>
	<span style="color: #003366; font-weight: bold;">var</span> cookie <span style="color: #339933;">=</span> $.<span style="color: #006600;">cookie</span><span style="color: #009900;">&#40;</span>setCookieName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>cookie<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;color: #666666;">// make array from saved order</span>
	<span style="color: #003366; font-weight: bold;">var</span> IDs <span style="color: #339933;">=</span> cookie.<span style="color: #006600;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;color: #666666;">// fetch current order</span>
	<span style="color: #003366; font-weight: bold;">var</span> items <span style="color: #339933;">=</span> list.<span style="color: #006600;">sortable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;toArray&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;color: #666666;">// make array from current order</span>
	<span style="color: #003366; font-weight: bold;">var</span> rebuild <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> v<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>items.<span style="color: #006600;">length</span><span style="color: #339933;">;</span> v<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;&gt;</span>
		rebuild<span style="color: #009900;">&#91;</span>items<span style="color: #009900;">&#91;</span>v<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> items<span style="color: #009900;">&#91;</span>v<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> n <span style="color: #339933;">=</span> IDs.<span style="color: #006600;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> n<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;color: #666666;">// item id from saved order</span>
		<span style="color: #003366; font-weight: bold;">var</span> itemID <span style="color: #339933;">=</span> IDs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>itemID <span style="color: #000066; font-weight: bold;">in</span> rebuild<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;color: #666666;">// select item id from current order</span>
			<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> rebuild<span style="color: #009900;">&#91;</span>itemID<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;color: #666666;">// select the item according to current order</span>
			<span style="color: #003366; font-weight: bold;">var</span> child <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul.ui-sortable&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;color: #666666;">// select the item according to the saved order</span>
			<span style="color: #003366; font-weight: bold;">var</span> savedOrd <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul.ui-sortable&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span> <span style="color: #339933;">+</span> itemID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;color: #666666;">// remove all the items</span>
			child.<span style="color: #006600;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;color: #666666;">// add the items in turn according to saved order</span>
			<span style="color: #006600; font-style: italic;color: #666666;">// we need to filter here since the &quot;ui-sortable&quot;</span>
			<span style="color: #006600; font-style: italic;color: #666666;">// class is applied to all ul elements and we</span>
			<span style="color: #006600; font-style: italic;color: #666666;">// only want the very first!  You can modify this</span>
			<span style="color: #006600; font-style: italic;color: #666666;">// to support multiple lists - not tested!</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul.ui-sortable&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:first&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #009900;">&#40;</span>savedOrd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;color: #666666;">// code executed when the document loads</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;color: #666666;">// here, we allow the user to sort the items</span>
	$<span style="color: #009900;">&#40;</span>setSelector<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">sortable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		axis<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;y&quot;</span><span style="color: #339933;">,</span>
		cursor<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;move&quot;</span><span style="color: #339933;">,</span>
		update<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> getOrder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;color: #666666;">// here, we reload the saved order</span>
	restoreOrder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There are 2 functions to be concerned with in the above code.  The first, &#8220;getOrder()&#8221;, writes the order of the list elements to a cookie.  The second, &#8220;restoreOrder()&#8221;, fetches the order saved to the cookie and restores that order.  We execute &#8220;getOrder()&#8221; each time the list order is changed.  We execute &#8220;restoreOrder()&#8221; after the document has loaded.</p>
<p>Using the code provided above, you should only need to change the variables (at the very top) to get this working with your page.  Just remember to include the jQuery library and jQuery UI plugin!  I hope this is helpful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shopdev.co.uk/blog/sortable-lists-using-jquery-ui/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
