<?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>Haastek &#187; JavaScript</title>
	<atom:link href="http://haastek.co.uk/category/js/feed/" rel="self" type="application/rss+xml" />
	<link>http://haastek.co.uk</link>
	<description>the blog of Luke Haas, focused on design and web-development</description>
	<lastBuildDate>Wed, 20 Oct 2010 11:18:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create a Tabbed Interface jQuery Plug-in</title>
		<link>http://haastek.co.uk/2010/10/create-a-tabbed-interface-jquery-plug-in/</link>
		<comments>http://haastek.co.uk/2010/10/create-a-tabbed-interface-jquery-plug-in/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 18:38:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://haastek.co.uk/?p=64</guid>
		<description><![CDATA[
In this tutorial I explain how to create a jQuery plug-in for tabbed interfaces. This is intended to demonstrate how to create simple jQuery plug-ins, the advantages of abstracting your code, and also a few of the things you can do with jQuery.

Get SourceSee Demo
Step 1: Setting up
You can start by defining the HTML structure. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://haastek.co.uk/2010/10/create-a-tabbed-interface-jquery-plug-in//"><img src="http://haastek.co.uk/wp-content/uploads/2010/10/tabs.jpg" alt="Preview" width="580" height="151" /></a><br />
In this tutorial I explain how to create a jQuery plug-in for tabbed interfaces. This is intended to demonstrate how to create simple jQuery plug-ins, the advantages of abstracting your code, and also a few of the things you can do with jQuery.</p>
<p><span id="more-64"></span></p>
<p><a href="http://haastek.co.uk/wp-content/uploads/2010/10/tabbed-interface.zip" class="linkgs">Get Source</a><a href="http://haastek.co.uk/gallery/tabbed-interface" class="linkgs">See Demo</a></p>
<h2>Step 1: Setting up</h2>
<p>You can start by defining the HTML structure. It&#8217;s fairly simple and consists of a div wrapper, which will make it easier when we start working with jQuery, an unordered list, which will house the tab links, and then a div for each tab container.
<pre class="brush: html">
&lt;div id=&quot;tabs&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#tab1&quot; class=&quot;link_tab&quot; id=&quot;selected&quot;&gt;Tab 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#tab2&quot; class=&quot;link_tab&quot; &gt;Tab 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#tab3&quot; class=&quot;link_tab&quot; &gt;Tab 3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#tab4&quot; class=&quot;link_tab&quot; &gt;Tab 4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#tab5&quot; class=&quot;link_tab&quot; &gt;Tab 4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div id=&quot;tab1&quot;&gt;
&lt;h1&gt;Tab 1&lt;/h1&gt;
&lt;p&gt;Example content&lt;/p&gt;

&lt;/div&gt;

&lt;div id=&quot;tab2&quot;&gt;
&lt;h1&gt;Tab 2&lt;/h1&gt;
&lt;p&gt;Example content&lt;/p&gt;
&lt;/div&gt;

&lt;div id=&quot;tab3&quot;&gt;
&lt;h1&gt;Tab 3&lt;/h1&gt;
&lt;p&gt;Example content&lt;/p&gt;
&lt;/div&gt;

&lt;div id=&quot;tab4&quot;&gt;
&lt;h1&gt;Tab 4&lt;/h1&gt;
&lt;p&gt;Example content&lt;/p&gt;
&lt;/div&gt;

&lt;div id=&quot;tab5&quot;&gt;
&lt;h1&gt;Tab 5&lt;/h1&gt;
&lt;p&gt;Example content&lt;/p&gt;
&lt;/div&gt;
</pre>
<h2>Step 2: Styling</h2>
<p>As far as aesthetic styling goes, you can do whatever you want. However, there are a couple of important structural rules to apply. As the tab content divs will need to be on top of each other, they will need to be positioned absolutely which means that the div wrapper will need to be relative so that you can position those divs against the wrapper rather than the page.</p>
<p>The styling I have applied is as follows:</p>
<pre class="brush: css">
#tabs {
	position: relative;
	float: left;
	font-family: verdana, sans-serif;
}
#tabs ul {
	list-style: none;
	margin-left: 12px;
	padding: 0;
}
#tabs li {
	float: left;
	margin-right: 4px;
}
.link_tab {
	text-decoration: none;
	width: 105px;
	height: 21px;
	display: block;
	text-align: center;
	color: #047198;
	font-weight: bold;
	background-color: #DFEDF0;
	padding: 3px;

}
.link_tab:hover {
	background-color: #D1E3E7;
}
.link_tab:focus {
	outline: 0 none;
}
#tabs div {
	-moz-box-shadow: 0 -5px 15px #E1E1E1;
	-webkit-box-shadow: 0 -5px 15px #E1E1E1;
	z-index: 1;
	top: 43px;
	left: 0px;
	width: 580px;
	padding: 0 10px 0 10px;

}
#tabs h1 {
	color: #047198;
	font-weight: normal;
}
#selected {
	-moz-box-shadow: 0 -6px 15px #E1E1E1;
	-webkit-box-shadow: 0 -6px 15px #E1E1E1;
	background-color: #fff;
	z-index: 2;
	position: relative;
}
</pre>
<h2>Step 3: Defining a plug-in</h2>
<p>Plug-ins are a good idea as they increase the reusability of code. It makes sense, if there&#8217;s a segment of code you use a lot, to define it as a plug-in and then just drop it in wherever you need it. One of the necessities of this is that the code is nonspecific, with as few ID and class names as possible so that the code can easily be used in other instances.</p>
<p>To define a jQuery plug-in, you&#8217;ll need to wrap it in a function that looks like this:</p>
<pre class="brush: js">
(function($) {

})(jQuery);
</pre>
<p>Within that we&#8217;re going to define the main plug-in function which looks like this:</p>
<pre class="brush: js">
$.fn.tabbed = function() {

};
</pre>
<p>&#8216;tabbed&#8217; being my chosen name for this plug-in.</p>
<h2>Step 4: Functionality</h2>
<p>Within the main function, defined above, we can add the functionality that is going to perform the intended task. In this case, handling the tab clicks and then transitioning across tab content.</p>
<p>The code for this is as follows:</p>
<pre class="brush: js">
//assign &#039;this&#039; to a variable for scope
var elem = this;
$(elem).children(&#039;ul&#039;).children(&#039;li&#039;).children(&#039;a&#039;).click(function() {
	//show which tab is now selected
	$(&#039;.link_tab&#039;).removeAttr(&#039;id&#039;);
	$(this).attr(&#039;id&#039;,&#039;selected&#039;);
    $(elem).children(&#039;div&#039;).fadeOut(400).filter(this.hash).fadeIn(400);
	//return false so the link is not followed
	return false;
});
$(elem).children(&#039;div&#039;).css(&#039;position&#039;,&#039;absolute&#039;).not(&#039;:first&#039;).hide();
</pre>
<p>
This code just assigns a click event to the tab links and then performs a fadout animation on the current tab content, followed by a fadein animation on the tab content to be shown. The tab link that was clicked on is filtered to get the hash value. This is a value that can safely be added to the end of any link as it only has relevance to the client-side. The final line is predominantly for accessibility, if a user has JavaScript disabled then each tabs contents will still be displayed.</p>
<h2>Step 5: Invoking</h2>
<p>This is the final step and it just involves attaching the plug-in to the tab wrapper. In this case, the tab wrapper has an ID of &#8216;tabs&#8217; and the plug-in is called &#8216;tabbed&#8217; so the code looks like this.</p>
<pre class="brush: js">
$(document).ready(function() {
	$(&#039;#tabs&#039;).tabbed();
});
</pre>
<h2>Conclusion</h2>
<p>
I hope this has given you an idea of how to create jQuery plug-ins and the advantages of abstracting code. Or if your interest was simply in creating a tabbed interface then I hope this was sufficiently explanatory. Thanks for reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://haastek.co.uk/2010/10/create-a-tabbed-interface-jquery-plug-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to jQuery</title>
		<link>http://haastek.co.uk/2009/12/introduction-to-jquery/</link>
		<comments>http://haastek.co.uk/2009/12/introduction-to-jquery/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 19:00:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://haastek.co.uk/?p=19</guid>
		<description><![CDATA[
jQuery is a javascript framework, first released by John Resig in 2006. Today it is the most popular JavaScript framework in the world. jQuery appeals to a wide variety of JavaScript developers, from those just starting out, to seasoned experts. This is in no small part due to the elegance and simplicity of jQuery, with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://haastek.co.uk/2009/12/introduction-to-jquery/"><img class="alignnone size-full wp-image-20" title="jquery" src="http://haastek.co.uk/wp-content/uploads/2009/12/jquery.jpg" alt="jquery" width="565" height="96" /></a><br />
jQuery is a javascript framework, first released by John Resig in 2006. Today it is the most popular JavaScript framework in the world. jQuery appeals to a wide variety of JavaScript developers, from those just starting out, to seasoned experts. This is in no small part due to the elegance and simplicity of jQuery, with just a few lines of clear and concise code you can create anything from complex animations to advanced ajax functionality.</p>
<p>In this tutorial I will start from the beginning and give you a brief introduction to some of jQuery&#8217;s core concepts such as element selection, manipulation and events.
<p><span id="more-19"></span></p>
<p>The first thing you&#8217;ll need to do is download the jQuery core library from <a href="http://jquery.com/">jquery.com</a> and add a reference to it in your html page.</p>
<p>Now we can start writing some code. As the majority of stuff you&#8217;re most likely to do with jQuery will involve the DOM in some way, we&#8217;ll need to start with the jQuery ready event. This is an event that gets triggered when the page has loaded and the DOM is ready to be accessed.</p>
<pre class="brush: js">
$(document).ready(function() {

});
</pre>
<p>From within this function we can select and manipulate DOM elements. If, for example, you wanted to select an element by it&#8217;s ID, or select a group of elements by their class name, you can do this by using CSS selectors. This is done like this:</p>
<pre class="brush: js">
$(&quot;#nav&quot;)
//this would select an element with the ID of nav
$(&quot;.title&quot;)
//this would select all elements with the class name title
$(&quot;p&quot;)
//this would select all paragraphs
</pre>
<p>Once you have selected an element, or a group of elements, you have a vast array of options when it comes to dealing with that selection. You could:</p>
<pre class="brush: js">
$(&quot;#nav&quot;).css({&#039;width&#039;:&#039;500px&#039;,&#039;height&#039;:&#039;200px&#039;});
//alter it&#039;s css properties
var cont = $(&quot;#nav&quot;).html();
//assign its contents to a variable
$(&quot;#nav&quot;).html(&quot;insert this text&quot;);
//assign content to it
$(&quot;#nav&quot;).hide();
//perform an animation on it
</pre>
<p>And much more, you can also apply events to the elements you have selected. Here are some examples:</p>
<pre class="brush: js">
$(&quot;.title&quot;).click(function() {
//this triggers on a mouse click
});

$(&quot;input&quot;).focus(function() {
//this triggers when an input field gets focus
});

$(&quot;input&quot;).blur(function() {
//this triggers when an input field loses focus
});

$(&quot;#nav&quot;).mouseenter(function() {
//this triggers when the mouse moves over the element
});

$(&quot;#nav&quot;).mouseleave(function() {
//this triggers when the mouse moves over the element
});
</pre>
<p>Now we can put this all togther and create a basic function that gets triggered when an element with the ID of &#8216;nav&#8217; gets clicked on, which then causes the text colour of all the paragraphs on the page to be set to red and their content to be set to the text &#8216;This is a paragraph&#8217;:</p>
<pre class="brush: js">
$(document).ready(function() {
	$(&quot;#nav&quot;).click(function() {
	$(&quot;p&quot;).css({&#039;color&#039;:&#039;#ff0000&#039;});
	$(&quot;p&quot;).html(&quot;This is a paragraph&quot;);
});
});
</pre>
<p>This has been a basic introduction to jQuery, showing you some of the core concepts and functionality. The amount you can do with jQuery is vast and to get a better idea of this, I suggest you have a read through the documentation on the <a href="http://jquery.com/">jQuery</a> site.  It&#8217;s very thorough and informative with lots of great examples and demonstrations. Other useful jQuery sites include <a href="http://jqueryfordesigners.com/">jQuery for Designers</a> and <a href="http://jquery-howto.blogspot.com/">jQuery Howto</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://haastek.co.uk/2009/12/introduction-to-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

