<?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>Ryan Coughlin &#124; Web and Graphic Designer &#187; jquery</title>
	<atom:link href="http://www.ryancoughlin.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryancoughlin.com</link>
	<description></description>
	<lastBuildDate>Fri, 26 Mar 2010 00:07:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Another jQuery UI Slider Example</title>
		<link>http://www.ryancoughlin.com/2009/09/12/another-jquery-ui-slider-example/</link>
		<comments>http://www.ryancoughlin.com/2009/09/12/another-jquery-ui-slider-example/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 18:03:14 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=501</guid>
		<description><![CDATA[First post in a very long time. Finally the summer is over and I am back at school for my last year. Now finally I have a lot of free time to work on this new layout and getting it solid, and getting back to blog posts to catch up on what I missed. 
The [...]


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/using-the-jquery-ui-slider/' rel='bookmark' title='Permanent Link: Using the jQuery UI Slider'>Using the jQuery UI Slider</a> <small>Utilize the jQuery UI Slider to change CSS properties or...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/working-with-the-jquery-live-function/' rel='bookmark' title='Permanent Link: Working with the jQuery live function'>Working with the jQuery live function</a> <small>Find out how to use jQuery .live() and how it...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/16/two-panel-slick-drop-down-using-jquery/' rel='bookmark' title='Permanent Link: Two Panel Slick Drop Down Using jQuery'>Two Panel Slick Drop Down Using jQuery</a> <small>Publish a great looking two panel drop down with animations...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>First post in a very long time. Finally the summer is over and I am back at school for my last year. Now finally I have a lot of free time to work on this new layout and getting it solid, and getting back to blog posts to catch up on what I missed. </p>
<p>The jQuery UI Slider is one part of the jQuery UI collection that is really neat and can have many uses. So last year I created this jQuery UI Slider never posted about it and I figured now would be the best time. </p>
<p>I  wrote this <a href="http://www.ryancoughlin.com/2008/11/04/using-the-jquery-ui-slider/" target="_blank">tutorial</a> on using the slider close to a year ago.</p>
<p>Now I created another version of it, with some different styles, with full code examples as well. This will display the current value of the slider as you move up and down bar. <strong>Check out the <a href="http://www.ryancoughlin.com/demos/interactive-slider/" target="_blank">jQuery UI Slider</a> and start playing around with it.</strong></p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/using-the-jquery-ui-slider/' rel='bookmark' title='Permanent Link: Using the jQuery UI Slider'>Using the jQuery UI Slider</a> <small>Utilize the jQuery UI Slider to change CSS properties or...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/working-with-the-jquery-live-function/' rel='bookmark' title='Permanent Link: Working with the jQuery live function'>Working with the jQuery live function</a> <small>Find out how to use jQuery .live() and how it...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/16/two-panel-slick-drop-down-using-jquery/' rel='bookmark' title='Permanent Link: Two Panel Slick Drop Down Using jQuery'>Two Panel Slick Drop Down Using jQuery</a> <small>Publish a great looking two panel drop down with animations...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/09/12/another-jquery-ui-slider-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to load data using JSON/PHP using jQuery</title>
		<link>http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/</link>
		<comments>http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/#comments</comments>
		<pubDate>Wed, 06 May 2009 16:00:53 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=463</guid>
		<description><![CDATA[I have seen a good amount of people wanting to see learn how to load data on their website using jQuery, JSON, and PHP. I thought I would show a simple example that should give you a jump start to your project.
We are going to use $.getJSON() function, you have something like:
$.getJSON("readJSON.php",function(data){
    [...]


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/' rel='bookmark' title='Permanent Link: How to use jQuery to Serialize Ajax Forms'>How to use jQuery to Serialize Ajax Forms</a> <small>When I first started working with jQuery and submitting forms...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/05/time-for-another-igoogle-theme/' rel='bookmark' title='Permanent Link: Time for another iGoogle theme?'>Time for another iGoogle theme?</a> <small>Thinking about making another iGoogle theme and almost done with...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I have seen a good amount of people wanting to see learn how to load data on their website using jQuery, JSON, and PHP. I thought I would show a simple example that should give you a jump start to your project.</p>
<p>We are going to use $.getJSON() function, you have something like:</p>
<pre class="js" title="code">$.getJSON("readJSON.php",function(data){
    $.each(data.posts, function(i,post){
          content = '
<div id="post-'+ post.id +'">\n';
	  content += '
<h3>' + post.author + '</h3>

\n';
	  content += '+ post.date_added + '\n';
          content += '' + post.post_content + ';
	  content += ''
<hr />';
	  $("#contents").append(content).fadeIn("slow");
   });
});</div>
</pre>
<p>And example of JSON from the PHP page could look like:</p>
<pre class="js" title="code">{ posts: [{"id":"151","date_added":"2009-05-05 13:40:34","post_content":"This is a test post. jQuery!","author":"Ryan"},
{"id":"152","date_added":"2009-05-05 13:40:55","post_content":"Hey, you got to love Ajax","author":"John"}] }</pre>
<p>That JSON above loads two records that will be displayed on to the page.</p>
<p>The results are being pulled from a MySQL database with tables: <em>id, author, post_content, date_added, and author.</em></p>
<p>I am going to wrap up and article on the jQuery/PHP/JSON comment form with the results loaded on to the page after form submission, stay tuned for a much more in depth explanation of using JSON with PHP and  jQuery.</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/' rel='bookmark' title='Permanent Link: How to use jQuery to Serialize Ajax Forms'>How to use jQuery to Serialize Ajax Forms</a> <small>When I first started working with jQuery and submitting forms...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/05/time-for-another-igoogle-theme/' rel='bookmark' title='Permanent Link: Time for another iGoogle theme?'>Time for another iGoogle theme?</a> <small>Thinking about making another iGoogle theme and almost done with...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Time for another iGoogle theme?</title>
		<link>http://www.ryancoughlin.com/2009/05/05/time-for-another-igoogle-theme/</link>
		<comments>http://www.ryancoughlin.com/2009/05/05/time-for-another-igoogle-theme/#comments</comments>
		<pubDate>Tue, 05 May 2009 17:30:43 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Ranting]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[igoogle]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=461</guid>
		<description><![CDATA[Thinking about making another iGoogle theme and almost done with a PHP/JSON/jQuery comment form - live updates.


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/12/14/busybusy/' rel='bookmark' title='Permanent Link: Busy&#8230;Busy'>Busy&#8230;Busy</a> <small>Finally...the end of the semester is here, no more finals...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/new-layout-and-trip/' rel='bookmark' title='Permanent Link: New Layout and Trip'>New Layout and Trip</a> <small>Its been a very long time! I have been extremely...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/10/28/coroflot/' rel='bookmark' title='Permanent Link: Coroflot and New Design'>Coroflot and New Design</a> <small>Just added some more work to my Coroflot.com portfolio and...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>So i came across my <a href="http://www.google.com/ig/directory?hl=en&amp;type=themes&amp;url=landscape-google-theme.googlecode.com/svn/trunk/google-theme/landscape-theme.xml" target="_blank">old iGoogle theme</a> I made in the fall and was thinking of making another one. Shockingly, they&#8217;re extremely easy to create. Its a large XML document.  I have been working on a <a href="http://ryancoughlin.com/nightday/" target="_self">new layout</a> for my site. I was thinking of another landscape but similar to the landscape, but different style.<br />
<a href="http://www.ryancoughlin.com/wp-content/uploads/2009/05/skin_fetch.jpg"><img src="http://www.ryancoughlin.com/wp-content/uploads/2009/05/skin_fetch-300x57.jpg" alt="Summer Landscape - iGoogle Theme" title="Summer Landscape - iGoogle Thehe" width="300" height="57" class="aligncenter size-medium wp-image-466" /></a></p>
<p>I am trying to free my schedule from client work to start working on the new layout, stil need to work on the move right text, bottom posts boxes, colors, and what the single page is going to look like, all in all its a work in progress. Almost done with a jQuery tutorial on submitting a  comment form and having the results loaded using jQuery/Ajax. The comments on the page are loading using PHP, JSON, and jQuery, very slick. Expect that very soon.</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/12/14/busybusy/' rel='bookmark' title='Permanent Link: Busy&#8230;Busy'>Busy&#8230;Busy</a> <small>Finally...the end of the semester is here, no more finals...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/new-layout-and-trip/' rel='bookmark' title='Permanent Link: New Layout and Trip'>New Layout and Trip</a> <small>Its been a very long time! I have been extremely...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/10/28/coroflot/' rel='bookmark' title='Permanent Link: Coroflot and New Design'>Coroflot and New Design</a> <small>Just added some more work to my Coroflot.com portfolio and...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/05/05/time-for-another-igoogle-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use jQuery to Serialize Ajax Forms</title>
		<link>http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/</link>
		<comments>http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/#comments</comments>
		<pubDate>Mon, 04 May 2009 15:17:08 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[serialize]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=455</guid>
		<description><![CDATA[When I first started working with jQuery and submitting forms via Ajax, I&#8217;ve never really used .serialize() and wasn&#8217;t too familiar with it. I started to look in to how it works and what it can do. It can be a huge time saver, especially for larger forms.
Instead of declaring all of your data to [...]


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When I first started working with jQuery and submitting forms via Ajax, I&#8217;ve never really used .serialize() and wasn&#8217;t too familiar with it. I started to look in to how it works and what it can do. It can be a huge time saver, especially for larger forms.</p>
<p>Instead of declaring all of your data to be sent using something like:</p>
<pre class="js" title="code">
var fname     = $('#fname').attr('value');
var lname     = $('#lname').attr('value');
$.ajax({
     data: “fname=”+ fname + “&amp; lname=” + lname,
});
</pre>
<p>For a couple of fields above, that is fine, but what if you were creating a form with a large amount of fields. The last thing you would want to do is want to copy/paste that line 20 times for your field. Instead of grabbing each value of each form field we can use jQuery&#8217;s .serialize() to do the dirty work for us, which is a huge time saver. We can use something like:</p>
<pre class="js" title="code">
$(function() {
     $('form').bind('submit',function() { showValues(); return false; });
});
function showValues() {
     var str = $("form").serialize();
     $(".results-box").fadeIn();
     $(".results").text(str);
}
</pre>
<p>The first section binds the submit to a function. When a user submits the form call the function showValues(), the next bit. We grab the form and attach .serialize() to it. We want to serialize all fields within this form and display what data is going to be sent to the sever. A <a href="http://www.ryancoughlin.com/demos/serialize/jquery.serialize.html" target="_blank">working demo</a> has been uploaded.</p>
<p>Now with our data serialized it is ready to be sent over to the server side. Using jQuery .serialize() is much more effiecient compared to retrieving the value using .val().</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Working with the jQuery live function</title>
		<link>http://www.ryancoughlin.com/2009/05/04/working-with-the-jquery-live-function/</link>
		<comments>http://www.ryancoughlin.com/2009/05/04/working-with-the-jquery-live-function/#comments</comments>
		<pubDate>Mon, 04 May 2009 13:56:18 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[click]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[live]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=450</guid>
		<description><![CDATA[Find out how to use jQuery .live() and how it compares with .click()


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/01/22/jquery-timeout-function/' rel='bookmark' title='Permanent Link: jQuery Timeout Function'>jQuery Timeout Function</a> <small>A neat and simple way to creating a jQuery function...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/03/30/create-a-jquery-accordion-remain-open-after-page-load/' rel='bookmark' title='Permanent Link: Create a jQuery Accordion &#8211; remain open after page load'>Create a jQuery Accordion &#8211; remain open after page load</a> <small>Quick fix to keep accordion section open after loading different...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/' rel='bookmark' title='Permanent Link: Combining Selectables And Draggables Using jQuery UI'>Combining Selectables And Draggables Using jQuery UI</a> <small>Learn how to work with both selectable and draggable with...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The other day, I wasn&#8217;t really too acquainted with the .live() jQuery function. I did some research and it finally clicked for me. I put together a <a href="http://ryancoughlin.com/demos/live/jquery.live.html" target="_blank">quick example</a> that can I uploaded. The basics of the function can be known as:</p>
<blockquote><p>Binds a handler to an event (like click) for all current &#8211; and future &#8211; matched element.  Can also bind custom events. &#8211; (source: jquery.com)</p></blockquote>
<p>This function is extremely similar to the .click() but .click() will only match elements that are created via the XHTML with DOM is loaded. With that said, using .live() is extremely useful for dynamic websites, where you are creating/removing elements on you&#8217;re website.</p>
<p>Lets see the base example of using .live()</p>
<pre class="js" title="code">
$('a.edit').live('click', function() {
     alert("The power of .live() - dynamically created objects will have bound events!")
     return false;
});
</pre>
<p>This code will work for all links that have the class edit, even when new a.link tags are created dynamically after DOM has been loaded. If your code looked like:</p>
<pre class="js" title="code">
$('a.edit-nolive').click(function() {
     alert("Items created via AJAX will be called on using .live()")
     return false;
});</pre>
<p>It would not work on dynamically created items. Lets take another look at the <a href="http://ryancoughlin.com/demos/live/jquery.live.html" target="_blank">full demo</a>. Hopefully this will clear up any problems with understanding how the jQuery .live() function works in comparison to the .click() event. Like to see something else like this? Drop me a line.</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/01/22/jquery-timeout-function/' rel='bookmark' title='Permanent Link: jQuery Timeout Function'>jQuery Timeout Function</a> <small>A neat and simple way to creating a jQuery function...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/03/30/create-a-jquery-accordion-remain-open-after-page-load/' rel='bookmark' title='Permanent Link: Create a jQuery Accordion &#8211; remain open after page load'>Create a jQuery Accordion &#8211; remain open after page load</a> <small>Quick fix to keep accordion section open after loading different...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/' rel='bookmark' title='Permanent Link: Combining Selectables And Draggables Using jQuery UI'>Combining Selectables And Draggables Using jQuery UI</a> <small>Learn how to work with both selectable and draggable with...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/05/04/working-with-the-jquery-live-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create a jQuery Accordion &#8211; remain open after page load</title>
		<link>http://www.ryancoughlin.com/2009/03/30/create-a-jquery-accordion-remain-open-after-page-load/</link>
		<comments>http://www.ryancoughlin.com/2009/03/30/create-a-jquery-accordion-remain-open-after-page-load/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 19:28:50 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[accordion]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=411</guid>
		<description><![CDATA[Quick fix to keep accordion section open after loading different URL. Without any use of history plugins.


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/05/04/working-with-the-jquery-live-function/' rel='bookmark' title='Permanent Link: Working with the jQuery live function'>Working with the jQuery live function</a> <small>Find out how to use jQuery .live() and how it...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/' rel='bookmark' title='Permanent Link: Combining Selectables And Draggables Using jQuery UI'>Combining Selectables And Draggables Using jQuery UI</a> <small>Learn how to work with both selectable and draggable with...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I am currently working on this site for a client: http://www.hornedpout.com/ &#8211; a very basic portfolio website for a designer/writer. I didn&#8217;t want to use the bulky code of the jQuery UI so I decided to use the smaller version, below:</p>
<pre class="js" title="code">$(".menu-header").click(function() {
        $(this).next().toggle('slow');
        return false;
}).next().hide();</pre>
<p>The HTML would look something similar to:</p>
<pre class="html" title="code">
<h2 class="menu-header">art gallery</h2>
<ul>
<li class="item"><a title="Traditional Art Work" href="?c=traditional">traditional</a></li>
<li class="item"><a title="Digital" href="?c=digital">digital</a></li>
<li class="item"><a title="Posters" href="?c=posters">posters</a></li>
<li class="item"><a title="Icons" href="?c=icons">icons</a></li>
<li class="item"><a title="Fonts" href="?c=fonts">fonts</a></li>
</ul>
<h2 class="menu-header">verse</h2>
<ul>
<li><a title="Poems" href="?c=poems">Poems</a></li>
<li><a title="Stories" href="?c=stories">Stories</a></li>
</ul>
</pre>
<p>That code will use jQuery&#8217;s <strong>toggle()</strong> function. When the user clicks the <strong>h2</strong> tag it will close all elements until the next<br />
tag. This snippet is very handy for creating a quick accordion effect, this can also be found on the jQuery&#8217;s <a href="http://docs.jquery.com/UI/Accordion">documentation</a></p>
<p>Now we have the guts sorted out, but the problem is if you travel to another page within that category, it will close. I&#8217;m sure you want to check out the code that is going to do this.</p>
<p><strong>Keep that open!</strong></p>
<pre class="js" title="code">var matches;
     if( matches = (new String(document.location)).match(/?c=w+/) ) {
        $("a[href=" + matches[0] + "]").parents("ul").toggle();
     }</pre>
<p>The code above is fairly straight forward. The first line checks to see if we already have a sub-menu open. It evaluates by looking at the current pages URL <strong>&#8220;?c=page_here&#8221;</strong>.</p>
<p>The latter part of the code. Now that we grabbed the current URL of the sub-menu, we can use this to find the parent menu which is the<br />
<strong>ul</strong> and display it:</p>
<pre class="js" title="code">$("a[href=" + matches[0] + "]").parents("ul").toggle();</pre>
<p>The quick fix to keep your accordion block open while traveling to different URLS. To achieve the URLS of &#8220;?c=page&#8221;. I am using this PHP code below save it as index.php, also create a header.php and a footer.php.</p>
<p>Give it a shot, hope that this can work for you, it did wonders for my project. Also thanks to <a href="http://kent-fredric.fox.geek.nz/">Kent</a>, for helping me. If it did work post some examples!</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/05/04/working-with-the-jquery-live-function/' rel='bookmark' title='Permanent Link: Working with the jQuery live function'>Working with the jQuery live function</a> <small>Find out how to use jQuery .live() and how it...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/' rel='bookmark' title='Permanent Link: Combining Selectables And Draggables Using jQuery UI'>Combining Selectables And Draggables Using jQuery UI</a> <small>Learn how to work with both selectable and draggable with...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/03/30/create-a-jquery-accordion-remain-open-after-page-load/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Timeout Function</title>
		<link>http://www.ryancoughlin.com/2009/01/22/jquery-timeout-function/</link>
		<comments>http://www.ryancoughlin.com/2009/01/22/jquery-timeout-function/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 02:35:35 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=399</guid>
		<description><![CDATA[A neat and simple way to creating a jQuery function to call setTimeout(); in a different, smaller, and reusable fashion.


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/05/04/working-with-the-jquery-live-function/' rel='bookmark' title='Permanent Link: Working with the jQuery live function'>Working with the jQuery live function</a> <small>Find out how to use jQuery .live() and how it...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/' rel='bookmark' title='Permanent Link: Combining Selectables And Draggables Using jQuery UI'>Combining Selectables And Draggables Using jQuery UI</a> <small>Learn how to work with both selectable and draggable with...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>jQuery does offer callbacks for most of its functions, but what if you want to delay/timeout a certain effect or function. Well with this article, this should help you achieve that.</p>
<p>I have been trying to search for a nice and reusable way to use jQuery to timeout effects or functions. We are familiar with using</p>
<pre class="js" title="code">setTimeout (function,timeout);</pre>
<p>After putting in some data we can come up with something like this:</p>
<pre class="js" title="code">setTimeout (showBox(),2500);</pre>
<p>Remember that the value <em>2500</em> is in MS (milliseconds), we equates to <em>2.5 seconds</em>. When this function is called, it will execute <em>2500ms</em> later. I was using this for one of my projects where I wanted two effects/functions not after, but during. I could have used very handy jQuery callback and load in a function, but it would have been executed after the first function is completed.</p>
<p>The solution for this? Quite simple, check out the <em>jQuery $ function</em>, which allows us to call jQuery as &#8220;$&#8221; the example is below.</p>
<pre class="js" title="code">(function($) {
    // Within this function $ is a reference to jQuery
    // I love this framework
})(jQuery);</pre>
<p>Lets jump right into the belly of the beast and view the code to call our handy jQuery timeout function.</p>
<pre class="js" title="code">(function($){
	jQuery.fn.idle = function(time){
		var i = $(this);
		i.queue(function(){
			setTimeout(function(){
				i.dequeue();
			}, time);
		});
	};
})(jQuery);</pre>
<p>This might look like a bit overload, but it is really simple, we just learned how to create the skeleton of the function, so without it we:</p>
<pre class="js" title="code">jQuery.fn.idle = function(time){
	var i = $(this);
	i.queue(function(){
		setTimeout(function(){
			i.dequeue();
		}, time);
	});
};</pre>
<p>You see on the first line above we create the idle function: jQuery.fn.<em>idle</em>. We created the variable I to store $(this), which is going to be element that is running the $.idle(); function.</p>
<p>We then use the jQuery <em>queue();</em> function whose documentation can be found on the <a href="http://docs.jquery.com/Core/queue#namequeue">jQuery</a> website. Then we attach the <em>$(this);</em> variable we created called:  <em>i</em> to it, and create the <em>setTimeout()</em>, which then uses <em>dequeue();</em> with our variable connected to it.</p>
<p>The last part, where we create the <em>time</em> parameter for the function, so we call the following code and:</p>
<pre class="js" title="code">$.idle(2500);</pre>
<p><em>time</em> gets replaced with the user input of 2500ms to the function. Say if you want to call a function you can use it in this context instead of the messy old fashion <em>setTimeout();</em> function.</p>
<pre class="js" title="code">$('.myelement').fadeIn().idle(2000).fadeOut('slow');</pre>
<p>The above simple reads: fade in my element, then wait 200ms or 2 seconds then slowly fade out the same element. BOOM! There it is, the quick n&#8217; dirty method to timing functions out using jQuery.</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/05/04/working-with-the-jquery-live-function/' rel='bookmark' title='Permanent Link: Working with the jQuery live function'>Working with the jQuery live function</a> <small>Find out how to use jQuery .live() and how it...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/' rel='bookmark' title='Permanent Link: Combining Selectables And Draggables Using jQuery UI'>Combining Selectables And Draggables Using jQuery UI</a> <small>Learn how to work with both selectable and draggable with...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/01/22/jquery-timeout-function/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>jQuery Search And Highlight</title>
		<link>http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/</link>
		<comments>http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 20:38:18 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=233</guid>
		<description><![CDATA[Work with the jQuery framework to create a fast Ajax in place search and highlight, that also returns the number of results found.


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/' rel='bookmark' title='Permanent Link: Combining Selectables And Draggables Using jQuery UI'>Combining Selectables And Draggables Using jQuery UI</a> <small>Learn how to work with both selectable and draggable with...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/' rel='bookmark' title='Permanent Link: How to use jQuery to Serialize Ajax Forms'>How to use jQuery to Serialize Ajax Forms</a> <small>When I first started working with jQuery and submitting forms...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I was sitting in class and wanted to come up with some simple way to add a inline same page ajax search on a website. I came across the jQuery selector :contains(text), check out the <a href="http://docs.jquery.com/Selectors/contains" target="_blank">documentation</a> for this.  <span class="highlight">Now the to the final product, lets check out the <a title="View the search and highlight demo" href="http://www.ryancoughlin.com/demos/highlight/index.html" target="_blank">demo</a>.</span> We are going to have our main components for this:</p>
<ul>
<li>The form (1 input and submit)</li>
<li>The :contains selector</li>
<li>The fadeIn() effect</li>
<li>The addClass()</li>
</ul>
<p>The approach for the code is going to be like</p>
<ul>
<li>User will enter term in form</li>
<li>Save data to a variable</li>
<li>Place variable in to :contains selector</li>
<li>Fade in the highlight class (using <strong>fadeIn()</strong> and <strong>addClass()</strong>)</li>
</ul>
<p><span id="more-233"></span></p>
<p>See, there it is simple? Just about! Next lets take a look at the jquery</p>
<pre class="js" title="code">$(document).ready(function(){
	$("#submit").click(function(){

		// start variables as empty
		var term = "";
		var n = "0";

		// hide the results at first
		$("p.results").hide().empty();
        // grab the input value and store in variable
        term = $('#term').attr('value');
		console.log("The value of term is: "+term);

		$('span.highlight').each(function(){
			$(this).after($(this).html()).remove();
		});

		if($('#term').val() == ""){
			$("p.results").fadeIn().append("Enter term in field above");
			$('#term').fadeIn().addClass("error");
			return false;
		}else{
			$('div.container :contains("'+term+'")').each(function(){
				$(this).html($(this).html().replace(new RegExp(term,'g'), '<span class="highlight">'+term+'</span>'));
				$(this).find('span.highlight').fadeIn("slow");
			});

			// how many did it find?
			n = $("span.highlight").length;
			console.log("The there is a total of: "+n);

			if(n == 0){
				$("p.results").fadeIn().append("No results were returned");
			}else{
				$("p.results").fadeIn().append("<strong>Returned:</strong> "+n+" result(s) for the search term of: <em><strong>"+term+"</strong></em>.");
			}
			return false;
		}
	});
});</pre>
<p>And now the HTML structure:</p>
<pre class="html" title="code">
<div class="container">
<div class="span-24">
<h1>Welcome to my site!</h1>
<hr />
<form id="search-highlight" action="#" method="post">
                                <label>Search Term:</label>
<input id="term" class="text" name="term" size="25" type="text" />
<input id="submit" name="submit" type="submit" value="Search and Highlight" />
                        </form>
</div>
<hr />

Kind of a late start here today. I have been reading this book online lately called Learning Rails that covers version 2.0 unlike most of the books that are out there. I was able to follow and understand this book to guide me through Rails and its done wonders. I havenâ€™t seen to many typos and the code is easy to understand. There is one chapter that floats away from the rest and its a bummer because its the rails and Ajax section, but besides that, its a great learning tool.

						I released an Illustrator tutorial yesterday on creating nautical floatie buoys, a simple and straight forward tutorial. Let me know what you think!

						I was talking to Richard Worth and I am going to be writing a post on working with the jQuery UI and implementing the draggables and selectables together, which is very interesting. I have tried this approach about a year ago with Worth, but it was kind of buggy, Richard released a working version that I will be covering and hopefully try to work it in to the UI API. So stay tuned for that post.

						I am also going to be working on some other posts overtime working with jQuery and various ajax methods and functions. Loading data, displaying data, and all sorts of other goodies

						I have been making small modifications to the site, as you can see I added in the top menu bar, and I know it is broken in IE, im on it! I will be working in a home made small jQuery menu to bring down subcategories of what you see up top.

						Have an idea for a post that you want to see on here? Let me know</div>
</pre>
<p>Now that we have the outline of the code that we will be using, lets breakdown the bulk of it. If you notice we have the click event handler, which means that the code will not execute until someone has pressed the submit button. The first couple of lines take care of initializing of the script.</p>
<pre lang="javascript">
var term,n;
// hide the results at first
$("p.results").hide().empty();
// grab the input value and store in variable
term = $('#term').attr('value');
console.log("The value of term is: "+term);</pre>
<p>I have commented the code for it is easier to retain the information when you come back for future reference. So the first two lines just sets two variables <strong>term</strong> and <strong>n</strong>. The next line hides the <strong>p.results</strong> element and empties it, our results after form submission will be loaded in here. Lets come back to the variable that we created we set <strong>term</strong> to whatever the value that was entered in the input box. We are going to use the console.log to make sure our variable is receiving the data.</p>
<h2>Lets make it highlight.</h2>
<p>The next section of the code is going to to reset the and remove all <strong>span.highlight</strong> classes for when you enter another term you will <em>only</em> have the <em>new</em> results entered via the form and not both old and new terms.</p>
<pre class="js" title="code">$('span.highlight').each(function(){
     $(this).after($(this).html()).remove();
});</pre>
<p>The code is going to run through each of the <strong>span.highlight</strong> and manually remove the tag. This will be executed every time the form is submitted. Its main purpose is to clear the results.  The next part is a quick validation making sure that the form cannot be submitted without some type of data, this is the first section of the conditional:</p>
<pre class="js" title="code">if($('#term').val() == ""){
    $("p.results").fadeIn().append("Enter term in field above");
    $('#term').fadeIn().addClass("error");
    return false;</pre>
<p>That part reads if the element #term returns empty, then <strong>fadeIn()</strong> and <strong>append()</strong> text. The line after adds the class error to the input field to give us as red border indicating there has been some type of error. The return false is in place for the form is not submitted. The latter of the conditional will look like:</p>
<pre class="js" title="code">}else{
    $('div.container :contains("'+term+'")').each(function(){
        $(this).html($(this).html().replace(new RegExp(term,'g'), '<span class="highlight">'+term+'</span>'));
        $(this).find('span.highlight').fadeIn("slow");
    });</pre>
<p>This occurs when there is data in the input, and it takes the term and we find it using :contains, it runs through each element and replaces the text by wrapping a <strong>span</strong> tag with the class <strong>highlight</strong> around the term. After, it finds each of those elements and fades them in.</p>
<h2>Displaying our results</h2>
<p>The last part is going to display our results, it is going to tell us:</p>
<ul>
<li>The term we searched for</li>
<li>How many results were found</li>
</ul>
<p>Lets take a look at the code:</p>
<pre class="js" title="code">
// how many did it find?
n = $("span.highlight").length;
console.log("The there is a total of: "+n);
     if(n == 0){
         $("p.results").fadeIn().append("No results were returned");
     }else{
         $("p.results").fadeIn().append("<strong>Returned:</strong> "+n+" result(s) for the search term of: <em><strong>"+term+"</strong></em>.");
     }
     return false;
     }
     });
});</pre>
<p>We are going to retrieve the number of results returned by storing it in the variable <strong>n</strong> and searching for every <strong>span.highlight</strong> element and using <strong>.length()</strong> to retrieve the amount. I have added the <strong>console.log()</strong> to see what is going on in the back end.</p>
<p>The next part is a simple conditional if <strong>n</strong> returns no results, then <strong>fadeIn()</strong> and <strong>append()</strong> text &#8211; &#8220;No results were found.&#8221; If results were found, then do the same but tell us how many were found and what term the user searched for.</p>
<p>There you have it, a very quick and clean same page search and highlight using jQuery. If you have any recommendations or other features you would like to see, drop a comment or email me. What did you think of it ?</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/' rel='bookmark' title='Permanent Link: Combining Selectables And Draggables Using jQuery UI'>Combining Selectables And Draggables Using jQuery UI</a> <small>Learn how to work with both selectable and draggable with...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/' rel='bookmark' title='Permanent Link: How to use jQuery to Serialize Ajax Forms'>How to use jQuery to Serialize Ajax Forms</a> <small>When I first started working with jQuery and submitting forms...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Busy&#8230;Busy</title>
		<link>http://www.ryancoughlin.com/2008/12/14/busybusy/</link>
		<comments>http://www.ryancoughlin.com/2008/12/14/busybusy/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 01:49:48 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Ranting]]></category>
		<category><![CDATA[college]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=329</guid>
		<description><![CDATA[Finally...the end of the semester is here, no more finals or projects. More posts coming up soon.


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/05/30/around-in-europe/' rel='bookmark' title='Permanent Link: Around in Europe'>Around in Europe</a> <small>Wanted to write a quick post while overseas. Just wanted...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/new-layout-and-trip/' rel='bookmark' title='Permanent Link: New Layout and Trip'>New Layout and Trip</a> <small>Its been a very long time! I have been extremely...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/09/9-personal-web-design-inspiration/' rel='bookmark' title='Permanent Link: 9 Personal Web Design Inspiration'>9 Personal Web Design Inspiration</a> <small>There has been many websites that i have come across...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Hey everyone! I have been extremely busy with the past couple of weeks due to the end of the semester coming and trying to get my finals and projects out of the way. Just about done with my ASP shopping cart application and my usability project. I am just about done with the fall semester, so expect some posts here soon in a week. I also meant to post my <a title="Check out my iGoogle theme" href="http://www.google.com/ig/directory?hl=en&amp;url=landscape-google-theme.googlecode.com/svn/trunk/google-theme/landscape-theme.xml&amp;type=themes" target="_blank">iGoogle theme</a> I created, its nothing crazy, but thought I would make some fun of it. Try it <a title="Check out my iGoogle theme" href="http://www.google.com/ig/directory?hl=en&amp;url=landscape-google-theme.googlecode.com/svn/trunk/google-theme/landscape-theme.xml&amp;type=themes" target="_blank">out</a>!<a  rel="lightbox"><img class="alignleft size-medium wp-image-333" title="iGoogle Theme - Summer Landscape" src="http://www.ryancoughlin.com/wp-content/uploads/2008/12/picture-1-300x178.jpg" alt="iGoogle Theme - Summer Landscape" width="210" height="125" /></a></p>
<p>If you have any ideas or requests that you would like to see, please let me know, drop an e-mail or comment.</p>
<p>Finally updated my WP and I love the new interface so far, they did a great job on it.  Install went smooth as always.</p>
<p>I am currently working on a <strong>same page ajax search and highlight script using jQuery</strong>, it is almost done, so stay tuned. I am also going to make some tweaks to the layout, I need more color on this temporary one, you will probably be seeing some changes over the next couple of weeks.</p>
<p>Take care! Cheers.</p>
<p>Ryan</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/05/30/around-in-europe/' rel='bookmark' title='Permanent Link: Around in Europe'>Around in Europe</a> <small>Wanted to write a quick post while overseas. Just wanted...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/new-layout-and-trip/' rel='bookmark' title='Permanent Link: New Layout and Trip'>New Layout and Trip</a> <small>Its been a very long time! I have been extremely...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/09/9-personal-web-design-inspiration/' rel='bookmark' title='Permanent Link: 9 Personal Web Design Inspiration'>9 Personal Web Design Inspiration</a> <small>There has been many websites that i have come across...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2008/12/14/busybusy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Combining Selectables And Draggables Using jQuery UI</title>
		<link>http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/</link>
		<comments>http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 19:59:36 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[combining]]></category>
		<category><![CDATA[draggable]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[selectable]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=258</guid>
		<description><![CDATA[Learn how to work with both selectable and draggable with the jQuery UI to select and drag numerous elements around a web page. Great for Web 2.0 applications.


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/01/22/jquery-timeout-function/' rel='bookmark' title='Permanent Link: jQuery Timeout Function'>jQuery Timeout Function</a> <small>A neat and simple way to creating a jQuery function...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/04/using-the-jquery-ui-slider/' rel='bookmark' title='Permanent Link: Using the jQuery UI Slider'>Using the jQuery UI Slider</a> <small>Utilize the jQuery UI Slider to change CSS properties or...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There are two powerful and fun elements that the jQuery UI provides. When both of them work together you will be able to come up with some creative web application uses for them. The two I am going to be covering are:</p>
<ul>
<li><strong>UI Selectable</strong> &#8211; <a href="http://dev.jquery.com/view/tags/ui/1.5b2/demos/ui.selectable.html" target="_blank">Demo</a> &#8211; <a href="http://docs.jquery.com/UI/Draggables" target="_blank">Documentation</a></li>
<li><strong>UI Draggable</strong> &#8211; <a href="http://dev.jquery.com/view/tags/ui/1.5b2/demos/ui.draggable.html" target="_blank">Demo</a> &#8211; <a href="http://docs.jquery.com/UI/Draggables" target="_blank">Documentation</a></li>
</ul>
<p><span class="highlight">I am sure you all want to see what the final product will look like, <a title="View the final demo using selectables and draggables" href="http://www.ryancoughlin.com/demos/dragselect/index.html" target="_blank">check it out</a>.</span></p>
<p><span id="more-258"></span></p>
<p>To start working with the jQuery UI you are going to need to add the following files to the head of your document:</p>
<ul>
<li><strong>jquery-1.2.6.min.js</strong> &#8211; <em>the main core jquery framework</em></li>
<li><strong>ui.core.js</strong> &#8211; <em>the UI core javascript</em></li>
<li><strong>ui.draggable.js </strong>- <em>the draggable javascript</em></li>
<li><strong>ui.selectable.js</strong> &#8211; <em>the selectable javascript</em></li>
</ul>
<p>Before we get started let me just say, <span class="highlight">thanks a ton to Richard Worth who has helped develop the jQuery UI and provided a ton of help to me last year trying to get this to work, and boom here is the working copy, you can find Richards blog <a href="http://rdworth.org/blog/" target="_blank">here</a>.</span></p>
<p>The jQuery UI adds classes for different mouse events, for instance:</p>
<ul>
<li><strong>jQuery UI Draggable</strong>
<ul>
<li><strong>.ui-draggable</strong> &#8211; <em>the class it adds you when create the draggable(); object</em></li>
<li><span style="color: #888888;"><span style="color: #000000;"><strong>.ui-draggable</strong></span></span><strong><span style="color: #000000;">-</span></strong><strong><span style="color: #000000;">dragging </span></strong><em>- the class it adds when you are dragging the object around the page</em></li>
</ul>
</li>
<li><strong>jQuery UI Selectable</strong>
<ul>
<li><strong>.ui-selectee<span style="color: #000000;"> </span></strong><strong><span style="color: #000000;">- </span></strong><em>the class it adds when you create the selectable(); object</em></li>
<li><strong>.ui-selectable</strong> &#8211; <em>the class it adds when you select the object</em></li>
<li><strong>.ui-selecting</strong><em> &#8211; the class it adds when you click and start to create the bounding box around the elements you wish to select, once you let go, it becomes <strong>.ui-selectable</strong></em></li>
</ul>
</li>
</ul>
<p>That is the basic structure how how the jQuery UI draggable and selectable generates classes to manipulate change for each action.</p>
<p>I am going to be using console.log(); to report what the code is doing after different steps throughout the page. Make sure you have <a title="Get FireBug!" href="https://addons.mozilla.org/en-US/firefox/addon/1843" target="_blank">Firebug</a> installed if you are on Firefox. If you are unsure what console.log() does view the <a href="http://getfirebug.com/console.html" target="_blank">documentation</a>. Be sure that if you use this technique in a real world example, remove the console.log() functions to decrease page loading time. This neat little function allows us to see what our code is doing, we can call:</p>
<pre lang="javascript">console.log(variable);</pre>
<p>When we open up the page and open Firebug, it will print out what the variable contains, it is a great tool for debugging, keep it handy.</p>
<p>Now that we have the understanding on how it works with different classes, lets start looking at the code that makes it work. I have commented it to make it easier for you to translate on your own time.</p>
<p><strong>The first bits of the code</strong></p>
<pre lang="javascript">// creates the selected variable
// we are going to be storing the selected objects in here
var selected = $([]), offset = {top:0, left:0};
console.log("This is the value of selected when it is created " +selected + "");</pre>
<p>As you can see from above, our first line creates the variable selected and is able to store numerous values because we are setting up an array for this variable. And the offset, resets the top and left values. If you use console.log it will output: <span class="highlight">Object length=0 prevObject=Object jquery=1.2.6</span> notice the length is 0 that is fine we haven&#8217;t selected any items yet.</p>
<pre lang="javascript">// initiate the selectable id to be recognized by UI
$("#selectable1").selectable();</pre>
<p>This part above, calls the selectable to generate the selectable region. <strong>NOTE:</strong> that #selectable is container and is the box not each element we are selecting.</p>
<p>The following part is important because, this is the where we start to hook up selectables with the draggables.</p>
<pre lang="javascript">// declare draggable UI and what we are going to be doing on start
$("#selectable1 div").draggable({
     start: function(ev, ui) {
          $(this).is(".ui-selected") || $(".ui-selected").removeClass("ui-selected");
	  console.log("The value of 'this' currently is: "+this);
          selected = $(".ui-selected").each(function() {
               var el = $(this);
	       el.data("offset", el.offset());
	       $(this).text("Selected and dragging object(s)");
	  });
console.log(selected);
offset = $(this).offset();
},</pre>
<p>The part below, tells the draggable UI to create every element within to have dragging.</p>
<div>
<div id="selectable">
<pre lang="javascript">$("#selectable1 div").draggable({</pre>
<pre lang="javascript">$(this).is(".ui-selected") || $(".ui-selected").removeClass("ui-selected");
console.log("The value of 'this' currently is: "+this);</pre>
<p>This next section above resets the select and drag, by removing the ui-selected class, when we output using console.log, to see the value of this is <span class="highlight">The value of &#8216;this&#8217; currently is: [object HTMLDivElement]</span>.</p>
<pre lang="javascript">selected = $(".ui-selected").each(function() {
     var el = $(this);
     console.log("The value of el is: "+el);
     el.data("offset", el.offset());
     $(this).text("Selected and dragging object(s)");
});</pre>
<p>Now we are finally working with the selected variable we created at the start of this, we are to run through each element with the class of ui-selected. We are going to be storing the value of $(this) in the variable el, to make it easier to call and to work with the offset(); property later on.</p>
<pre lang="javascript">el.data("offset", el.offset());
$(this).text("Selected and dragging object(s)");</pre>
<p>We are going back to out el variable and working with the <a href="http://docs.jquery.com/Internals/jQuery.data">data object</a> and the <a href="http://docs.jquery.com/CSS/offset">offset object</a>. The offset object returns two integer values: <span class="highlight">top and right</span>. The definition of the offset(); from the jQuery documentation is: <span class="highlight">Get the current offset of the first matched element relative to the view port.</span></p>
<p>The other line, changes the text of the elements to let us know that we have selected and are now dragging the objects stored in the variable selected.</p>
<p>Now that we have called offset we want to store it in the variable offset, for each DOM elements selected. The code that follows this part is below:</p>
<pre lang="javascript">console.log("The new value of selected is now "+selected);
offset = $(this).offset();
console.log("The value of top value is "+offset.top+" and the left value is "+offset.left);</pre>
<p>We have another console.log() to print out the selected value and it is storing the DOM element. Next we create the variable offset and store the offset() of the elements, I have printed the top and left values using console.log() above, the output is similar to: <span class="highlight">The value of top value is 207 and the left value is 672</span>.</p>
<p>The next section below is the section of code that handles what is going to go on while we are dragging our selected elements. This part is also very important because we are bringing back the values of offset with the current values of the draggable ui, it stores the ui properties in ui.position.top and ui.position.left. Further down the code we will use the offset values to update the CSS top and left properties of the selected elements.</p>
<pre lang="javascript">drag: function(ev, ui) {
     var dt = ui.position.top - offset.top, dl = ui.position.left - offset.left;
     console.log("The value of dt is "+dt);
     selected.not(this).each(function() {
          var el = $(this), off = el.data("offset");
          el.css({top: off.top + dt, left: off.left + dl});
     });
},</pre>
<p>We are creating the variable dt on the second line there and this value is equal to <span class="highlight">ui.position.top &#8211; offset.top</span> and we are also creating the variable dl that is <span class="highlight">dl = ui.position.left &#8211; offset.left</span>. So we have:</p>
<ul>
<li><strong>var dl</strong> &#8211; <em>working with the x axis or the left coordinates</em></li>
<li><strong>var dt</strong> &#8211; <em>working with the y axis or the top coordinates</em></li>
</ul>
<p>Lets add a console.log to see what these values are before we do the math. Add the following code to see what our variables and math are doing:</p>
<pre lang="javascript">console.log("The value of dt is "+dt+" and is equal to "+ui.position.top+" - "+offset.top);
console.log("The value of dl is "+dl+" and is equal to "+ui.position.left+" - "+offset.left);
console.log("The value of ui.position.top is "+ui.position.top);
console.log("The value of ui.position.left is "+ui.position.left);
console.log("The value of offset.left is "+offset.top);
console.log("The value of offset.left is "+offset.left);</pre>
<p>When you run the code the console.log() outputs the following:</p>
<pre lang="javascript">The value of dt is 37 and is equal to 237 - 200
The value of dl is 152 and is equal to 352 - 200
The value of ui.position.top is 237
The value of ui.position.left is 352
The value of offset.top is 200
The value of offset.left is 200</pre>
<p>Notice what the code is printing out, it is taking the ui.position.top and subtracting the value of offset.top and giving us the difference to equal variable dt. We do this math so we can update the top and left CSS properties in the next section of code, if we didn&#8217;t do this math, we would select and drag our elements and they would move sporadically on the page.</p></div>
</div>
<p>Next we are going to cover the other each function that loops through each of the selected elements expect $(&#8221;this&#8221;):</p>
<pre lang="javascript">// take all the elements that are selected expect $("this"), which is the element being dragged and loop through each.
selected.not(this).each(function() {
     // create the variable for we don't need to keep calling $("this")
     // el = current element we are on
     // off = what position was this element at when it was selected, before drag
     var el = $(this), off = el.data("offset");
     el.css({top: off.top + dt, left: off.left + dl});
});</pre>
<p>So we have the last big piece of code to make this script work. Like I said, you have the each function that runs through each element expect $(&#8221;this&#8221;), then we create two variables:</p>
<ul>
<li><strong>el</strong> &#8211; <em>which is the current element we are on</em></li>
<li><strong>off</strong> &#8211; <em>which is the position of the elements when they were selected, before any type of movement and drag</em></li>
</ul>
<p>The last segment: we are going to be adding or subtracting (we will subtract if the dt or dl is negative). The dl stands for delta left and dt stands for delta top. For instance lets set something up:</p>
<p><span class="highlight">The current element we are on start at the coordinates: 10, 30, now we drag that to: 8, 15. Now lets run the math, the new position of the element is: 2, 15. Say, you drag it again, it runs the loop once again, and the off will be 2, 15 and the new value will be wherever the new coordinates are subtract the total delta from when the drag started until now, not just the last mouse movement.</span></p>
<p>Now that we did the math and we have captured the new value, update it is the css property and plug in the top and left coordinates.</p>
<p>So what did you think of it? Pretty interesting effect when you combine both of those UI elements to create select and drag. Share your thoughts and make sure to bookmark using the button below. Any improvements? Contact me.</p>
<p>Enjoy!</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/01/22/jquery-timeout-function/' rel='bookmark' title='Permanent Link: jQuery Timeout Function'>jQuery Timeout Function</a> <small>A neat and simple way to creating a jQuery function...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/11/04/using-the-jquery-ui-slider/' rel='bookmark' title='Permanent Link: Using the jQuery UI Slider'>Using the jQuery UI Slider</a> <small>Utilize the jQuery UI Slider to change CSS properties or...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2008/11/23/combining-selectables-and-draggables-using-jquery-ui/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
