<?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>RentWiz Blog &#187; Development</title>
	<atom:link href="http://getrentwiz.com/blog/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://getrentwiz.com/blog</link>
	<description>Rental Listings Made Easy.</description>
	<lastBuildDate>Sat, 25 Apr 2009 02:23:20 +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>How To: jQuery Event Delegation</title>
		<link>http://getrentwiz.com/blog/how-to-jquery-event-delegation/</link>
		<comments>http://getrentwiz.com/blog/how-to-jquery-event-delegation/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 01:32:52 +0000</pubDate>
		<dc:creator>Art Armstrong</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[bluetux]]></category>
		<category><![CDATA[event delegation]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jquery event delegation]]></category>
		<category><![CDATA[rentwiz]]></category>

		<guid isPermaLink="false">http://getrentwiz.com/blog/?p=57</guid>
		<description><![CDATA[Until now, I&#8217;ve used jQuery for some of its more basic attributes and features like tabs and animation with a lot of customization (which I am going to cover later). Recently I had to do some work involving adding, editing, and deleting files with some ajax to update the page on the fly. After running [...]]]></description>
			<content:encoded><![CDATA[<h3>Until now, I&#8217;ve used jQuery for some of its more basic attributes and features like tabs and animation with a lot of customization (which I am going to cover later). Recently I had to do some work involving adding, editing, and deleting files with some ajax to update the page on the fly. After running into the issue of jQuery animations not working after the update, I had to find a solution; that was Event Delegation.</h3>
<p>As much as I love jQuery and all its great uses I still have a lot to learn from it, and event delegation was one of those useful features. I have become fairly well versed in the animation field with interactions but until now had not dealt with an ajax update of a page that had items hidden by default  after it has loaded. The use for us was within the application section of the listings settings where the administrator is able to add, edit, or delete an application and the page would update the field showing them.</p>
<div class="mceTemp">
<dl id="attachment_69" class="wp-caption alignnone" style="width: 510px;">
<dt class="wp-caption-dt"><a rel="attachment wp-att-69" href="http://getrentwiz.com/blog/how-to-jquery-event-delegation/app-screenshot/"><img class="size-full wp-image-69" title="app-screenshot" src="http://getrentwiz.com/blog/wp/wp-content/uploads/2009/04/app-screenshot.jpg" alt="RentWiz Application Screenshot" width="500" height="135" /></a></dt>
</dl>
</div>
<p>Let&#8217;s get into some of the code and see what is actually happening. This is the html that is being manipulated&#8230;</p>
<pre>&lt;div id="current-applications"&gt;
	&lt;p&gt;
		&lt;a href="#" class="pdf-icon"&gt;My App&lt;/a&gt;
		&lt;a href="#" class="edit-link"&gt;Edit&lt;/a&gt; |
		&lt;a onclick='ajax_delete_app();' class="delete-link"&gt;Delete&lt;/a&gt;
	&lt;/p&gt;
	&lt;form name="myform" method="post" enctype="multipart/form-data"&gt;
	&lt;table class="edit-listings-box" cellpadding="0" cellspacing="0" border="0" width="100%"&gt;
		&lt;tr&gt;
			&lt;td&gt;
			&lt;!-- Information about application --&gt;
                        &lt;input type="submit" class="update-link" value=\"Update\" /&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
	&lt;/form&gt;
&lt;/div&gt;</pre>
<p>By default, the code above will hide the form and show the information only after the user clicks the application name &#8220;My App&#8221; or &#8220;Edit&#8221;. The &#8220;Delete&#8221; link will call some ajax functionality to delete the record and file attached to it; after which, it will redisplay all the information inside of the &lt;div id=&#8221;applications&#8221;&gt;&lt;/div&gt;. Now the event delegation comes in handy. Because the page information is reloading we need to use event delegation to always make the jQuery calls viable on the newly created output. The structure of the above html is used in the jQuery code to handle the animations even after a page update. The classes and ids need to be the same for the links and surrounding elements every time it is outputted so the event delegation can access the the correct segments.</p>
<pre>//jQuery Event Delegation
$('#applications').click(function (e) {
	if($(e.target).attr('class') == 'edit-link') {
		$(e.target).parent().next().contents().filter(".edit-listings-box").toggle("blind");
	}else if($(e.target).attr('class') == 'pdf-icon') {
		$(e.target).parent().next().contents().filter(".edit-listings-box").toggle("blind");
	}else if($(e.target).attr('class') == 'done-link') {
		$(e.target).parent().parent().parent().parent().toggle("blind");
	}else if($(e.target).attr('class') == 'update-link') {
		$(e.target).parent().parent().parent().parent().parent().submit();
        }else if($(e.target).attr('class') == 'delete-icon') {
		if($(e.target).parent().next().contents().filter(".edit-listings-box").is(':visible')) {
			$(e.target).parent().next().contents().filter(".edit-listings-box").hide("blind");
		}
	}

	return false;
});</pre>
<p>As you can observe, the jQuery code above will only deal with &lt;a&gt; tags inside the element with the id=&#8221;applications&#8221;. It will then check the class of the link and take the appropriate action. If you aren&#8217;t familiar with jQuery, the code referencing the element to hide may look odd but it is just  used to traverse the html. Anyway this is just a very basic idea of event delegation and how it was used within our web application. If you have any specific questions regarding the subject you are more than welcome to email me and ask. Take it easy!</p>
<p><a></a></p>
]]></content:encoded>
			<wfw:commentRss>http://getrentwiz.com/blog/how-to-jquery-event-delegation/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How To: Select a tab from a URL using jQuery</title>
		<link>http://getrentwiz.com/blog/jquery-tab-select-from-url/</link>
		<comments>http://getrentwiz.com/blog/jquery-tab-select-from-url/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 18:54:59 +0000</pubDate>
		<dc:creator>Art Armstrong</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tabs]]></category>

		<guid isPermaLink="false">http://getrentwiz.com/blog/?p=37</guid>
		<description><![CDATA[The latest issue that I have run into and had to fix was trying to select a tab from the URL so that we had some dynamic control of what was shown when the page loaded. This was mainly a concern for a couple of pages where the page had to be reloaded or redirected [...]]]></description>
			<content:encoded><![CDATA[<h3>The latest issue that I have run into and had to fix was trying to select a tab from the URL so that we had some dynamic control of what was shown when the page loaded. This was mainly a concern for a couple of pages where the page had to be reloaded or redirected to after a action was performed.</h3>
<p>The <a title="jQuery Tabs" href="http://docs.jquery.com/UI/API/1.7.1/Tabs" target="_blank">tabs</a> that jQuery has made available are some of the most useful and powerful tools that I have used within a new web application for a long time but as with anything there are a few things that aren&#8217;t built in which need to be remedied.</p>
<p><img class="size-full wp-image-55 alignright" title="picture-1" src="http://getrentwiz.com/blog/wp/wp-content/uploads/2009/04/picture-1.png" alt="picture-1" width="300" height="94" /></p>
<p>The first thing we need to do is create the jQuery code and the HTML for the tabs, don&#8217;t forget to include the <a title="Download jQuery" href="http://docs.jquery.com/Downloading_jQuery" target="_blank">jQuery files</a>&#8230;</p>
<p>jQuery Tab Information</p>
<pre>$(function(){

// Initialize Tabs
$('#my-tabs').tabs();

});</pre>
<p>HTML tab code</p>
<pre>&lt;div id="my-tabs"&gt;
	&lt;ul&gt;
    		 &lt;li&gt;&lt;a href="#my-tabs-1"&gt;&lt;span&gt;One&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
    		 &lt;li&gt;&lt;a href="#my-tabs-2"&gt;&lt;span&gt;Two&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
    		 &lt;li&gt;&lt;a href="#my-tabs-3"&gt;&lt;span&gt;Three&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;div id="my-tabs-1"&gt;
		&lt;p&gt;First tab is active by default&lt;/p&gt;
	&lt;/div&gt;
	&lt;div id="my-tabs-2"&gt;
		&lt;p&gt;Second tab&lt;/p&gt;
	&lt;/div&gt;
	&lt;div id="my-tabs-3"&gt;
		&lt;p&gt;Third tab&lt;/p&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre>
<p>Now that we have the basics of the tabs set up you just have to add a little bit of code to check if a hash has been passed through the URL and then select that tab. The way that this would be called would be something like, although <em>it wont work</em>:</p>
<p>http://www.getrentwiz.com/test-tabs/index.html#2</p>
<p>So here is the code that will added below the tab initialization that will allow the tab to be selected.</p>
<pre>$(function(){

// Initialize Tabs
$('#my-tabs').tabs();

if(document.location.hash!='') {
        //get the index from URL hash
      	tabSelect = document.location.hash.substr(1,document.location.hash.length);
	$("#my-tabs").tabs('select',tabSelect-1);
}

});</pre>
<p>Now as you will see in the code that we subtract the number passed through the hash by 1, this is to accommodate the 0-based index that arrays use. So for example, passing 2 would return the select of 1, which is array[1], or the second tab. I hope this helps out a few people that ran into the same problem but I cant take all the credit, most of this was learned from Raymond Camden from <a title="O'Reilly InsideRIA" href="http://www.insideria.com/2009/03/playing-with-jquery-tabs.html" target="_blank">O&#8217;Reilly InsideRIA</a> and a few others.</p>
<p>Thanks for the interest!</p>
]]></content:encoded>
			<wfw:commentRss>http://getrentwiz.com/blog/jquery-tab-select-from-url/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
