<?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>Stuck Together With Tape &#187; CSS</title>
	<atom:link href="http://www.stucktogetherwithtape.com/blog/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stucktogetherwithtape.com/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 12 Nov 2010 22:38:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Bullet Proof CMS record ordering pattern</title>
		<link>http://www.stucktogetherwithtape.com/blog/2010/10/bullet-proof-cms-record-ordering-pattern/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=bullet-proof-cms-record-ordering-pattern</link>
		<comments>http://www.stucktogetherwithtape.com/blog/2010/10/bullet-proof-cms-record-ordering-pattern/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 17:28:17 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.stucktogetherwithtape.com/blog/?p=137</guid>
		<description><![CDATA[When building a custom backend, quite often a client will ask for the ablilty to order records/posts/images&#8230; Here&#8217;s a tried and tested method i use to build this functionality. It will work with or without js. In this example we will order the traditional post records. 1. The Database Create a table to hold your [...]]]></description>
			<content:encoded><![CDATA[<p>When building a custom backend, quite often a client will ask for the ablilty to order records/posts/images&#8230;</p>
<p>Here&#8217;s a tried and tested method i use to build this functionality. It will work with or without js. In this example we will order the <em>traditional</em> post  records.</p>
<h3>1. The Database</h3>
<p>Create a table to hold your posts and include a column (int) called <strong>order</strong>.</p>
<h3>2. Adding a new record</h3>
<p>Each time a new post is saved, the order column is assigned the auto inc value of the rows <strong>id</strong>. This prevents records from ever having the same order value.</p>
<h3>3. The order view (HTML)</h3>
<p>To provide the user with a way to order posts records, i&#8217;ll start with the HTML. This process is designed to degrade gracefully when JS is disabled. Dont worry if this process seems a bit clunky to the user, chances are they&#8217;ll have js turned on. I have found by restricting yourself to develop for HTML first created better structured and semantic code. Quite often divining straight in there with the javascript will get the job done, but it&#8217;ll be a headache to maintain.<br />
<span id="more-137"></span><br />
We&#8217;ll present the records in a ordered list, <em>cause we roll semantically like that</em>. Each li represents a post in the database They are ordered by their current order value.</p>
<pre><code>form
	ol
		li
			select</code></pre>
<p>Inside each li element is a select dropdown form input to hold each records order value. The possible options of the selectbox should be <strong>limited</strong> to the order values in the current record subset.</p>
<p>Again, this is prevents records having the same order value. Name the select box something like order[record-&gt;id]. So the post array will contain an array of record id =&gt; order value.</p>
<p>Stick a submit button at the bottom of that form and we&#8217;re all set&#8230;</p>
<h3>4. The MySql/Post Process</h3>
<p>A user changes some order values and then submits the form. First thing we need to do is check for duplicate order values. Some bright spark could have set all the select boxes to the same value! A quick way to do this is to use the php <a href="http://php.net/manual/en/function.array-unique.php">array_unique</a> function.<br />
This will return all unique values in the order array, so if all values in the array are unique, we&#8217;re golden.</p>
<pre><code>$unique = array_unique($_POST['order']);
// if arrays are equal no dupicates posted
if($unique == $order_values)</code></pre>
<p>If the user has posted duplicate order values you can provide feedback and get em to try again. After we have added a lick of jquery however, hopefully this will rarely happen!.</p>
<p>Once unique order values have been validated, its just a simple case of updating the order values of each post row by the post array key with the posted order value. Code will vary depending on what frameworks your using. Below is an example of what my Codeigniter Code would look like</p>
<pre><code>foreach($this-&gt;input-&gt;post('order') as $id =&gt; $order)
{
	$post = new Post($id);
	$post-&gt;order = $order;
	$post-&gt;save();
}</code></pre>
<p>Simples.</p>
<h3>The Javascript</h3>
<p>We have a basic, fugly but solid solution working. Now the fun part. With a few lines of jquery we can turn this into a fancy, elegant AND solid solution! We will use the jqueryui sortable plugin so the user can drag and re-order the list items. There is no need to show the selectboxes now because we have visual feedback on the current order. We&#8217;ll hide the selectboxes and then update their value whenever the list is reordered.</p>
<p>Here&#8217;s the code, the ol has an id of record-order.</p>
<pre><code>// updates the order value of all items hidden
// selectbox to the current order after a drag has taken place
$("#record-order").sortable({
	update: function(event, ui){
		var options = new Array();

		// get an array of order option values
		$(this).find('li:first select option').each(
			function(i){
				options[i] = $(this).val();
			}
		);

		$(this).children('li').each(
			function(i){
				var v = $(this).find('select').val(options[i])
			}
		);
	}
});</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.stucktogetherwithtape.com/blog/2010/10/bullet-proof-cms-record-ordering-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Typography Template</title>
		<link>http://www.stucktogetherwithtape.com/blog/2009/10/css-typography-template/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=css-typography-template</link>
		<comments>http://www.stucktogetherwithtape.com/blog/2009/10/css-typography-template/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 18:59:26 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://www.stucktogetherwithtape.com/blog/?p=64</guid>
		<description><![CDATA[Here&#8217;s a quick HTML template to organise your CSS typography. Nothing fancy, just an HTML file containing the most common elements to start your CSS, and a basic typography stylesheet. I used the 960 grid system to reset browser CSS and control the template layout. I find this helpful as a starting point for any [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-89" title="typography-framed" src="http://www.stucktogetherwithtape.com/blog/wp-content/uploads/2009/10/typography-framed.png" alt="typography-framed" width="620" height="220" /></p>
<p>Here&#8217;s a quick HTML template to organise your CSS typography.</p>
<p>Nothing fancy, just an HTML file containing the most common elements to start your CSS, and a basic typography stylesheet. I used the <a href="http://960.gs/" target="_blank">960 grid system</a> to reset browser CSS and control the template layout.</p>
<p>I find this helpful as a starting point for any site. Before I start knocking a CSS class together to style an element up for a specific page, I refer to the sites CSS template to see if  a similar base element already defined.</p>
<p>I would encourage keeping this typography stylesheet as basic as possible. Then use general css classes to add extra style later on.</p>
<p>Both the HTML and CSS files are included in the zip after the jump.</p>
<p><span id="more-64"></span></p>
<p><a href="http://www.stucktogetherwithtape.com/download/typography.zip" target="_blank">Download CSS Typography Template</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.stucktogetherwithtape.com/blog/2009/10/css-typography-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

