<?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>ThinkRobot &#187; jQuery</title>
	<atom:link href="http://think-robot.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://think-robot.com</link>
	<description>Design &#38; Development Blog</description>
	<lastBuildDate>Sun, 22 Apr 2012 23:58:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>jQuery Multiple Events Without Default Behaviour</title>
		<link>http://think-robot.com/2011/03/jquery-multiple-events-without-default-behaviour/</link>
		<comments>http://think-robot.com/2011/03/jquery-multiple-events-without-default-behaviour/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 22:51:34 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://think-robot.com/?p=276</guid>
		<description><![CDATA[Sometimes you trip over the little things. With several people working on the same page while we were recreating some JS functionality from scratch I&#8217;ve noticed one of my buttons suddenly stopped working. Scratched my head a bit, and for a minute thought that maybe it&#8217;s not having a &#8220;return false;&#8221; in my jQuery live() [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you trip over the little things.</p>
<p>With several people working on the same page while we were recreating some JS functionality from scratch I&#8217;ve noticed one of my buttons suddenly stopped working. Scratched my head a bit, and for a minute thought that maybe it&#8217;s not having a &#8220;return false;&#8221; in my jQuery live() event handler.</p>
<p>Turned out though that it was actually one of the other developers actually putting a &#8220;return false;&#8221; in their event handler that just happened to target the same element&#8230; </p>
<p>Ideally we needed to propagate the event through a variable number of events but prevent the default behaviour of a link kicking in. <strong>preventDefault()</strong> to the rescue! <img src='http://think-robot.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre><code>$('#tag').live('click', function(event){
    (...)
    event.preventDefault();
});
</code></pre>
<p>Now, before blindly applying this piece of code I&#8217;d encourage everyone to first read up on <a target="_blank" href="http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/">why &#8220;return false;&#8221; is evil</a>. <img src='http://think-robot.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>And for a quick reference here&#8217;s a table featured on a related <a target="_blank" href="http://stackoverflow.com/questions/5302903/jquery-event-stopimmediatepropagation-vs-return-false">StackOverflow question</a>:</p>
<table>
<thead>
<tr>
<td>&nbsp;</td>
<th>stop propagation</th>
<th>prevent default action</th>
<th>prevent &#8220;same element&#8221; event handlers</th>
</tr>
</thead>
<tbody>
<tr>
<th>return false</th>
<td>X</td>
<td>X</td>
<td>&nbsp;</td>
</tr>
<tr>
<th>preventDefault</th>
<td>&nbsp;</td>
<td>X</td>
<td>&nbsp;</td>
</tr>
<tr>
<th>stopPropagation</th>
<td>X</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<th>stopImmediatePropagation</th>
<td>X</td>
<td>&nbsp;</td>
<td>X</td>
</tr>
</tbody>
</table>
<div id="crp_related"><h2>Related Articles:</h2><ul><li><a href="http://think-robot.com/2009/06/hitch-object-oriented-event-handlers-with-jquery/" rel="bookmark">Hitch. Object-oriented event handlers with jQuery</a></li><li><a href="http://think-robot.com/2008/11/nested-sortable-using-jtree-clickable-links/" rel="bookmark">Nested sortable using jTree - clickable links</a></li><li><a href="http://think-robot.com/2009/04/zend_db_select-multiple-table-joins-explained/" rel="bookmark">Zend_Db_Select multiple table joins explained</a></li><li><a href="http://think-robot.com/2008/11/wordpress-nextgen-gallery-tweak/" rel="bookmark">WordPress NextGen gallery tweak</a></li><li><a href="http://think-robot.com/2011/01/enable-delayed-messages-in-zend_queue/" rel="bookmark">Enable delayed messages in Zend_Queue</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2011/03/jquery-multiple-events-without-default-behaviour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hitch. Object-oriented event handlers with jQuery</title>
		<link>http://think-robot.com/2009/06/hitch-object-oriented-event-handlers-with-jquery/</link>
		<comments>http://think-robot.com/2009/06/hitch-object-oriented-event-handlers-with-jquery/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 20:21:51 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[event handling]]></category>
		<category><![CDATA[hitch]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[object oriented]]></category>

		<guid isPermaLink="false">http://think-robot.com/?p=187</guid>
		<description><![CDATA[Moving to jQuery from YUI has been a 99% positive experience. Probably the only thing I&#8217;ve really missed was the ability provided by YUI Event to control the object scope that an event handler was executed in. When you attach an event to an element in jQuery within the event handler function the this keyword [...]]]></description>
			<content:encoded><![CDATA[<p>Moving to jQuery from YUI has been a 99% positive experience. Probably the only thing I&#8217;ve really missed was the ability provided by <a href="http://developer.yahoo.com/yui/event/" target="_blank">YUI Event</a> to control the object scope that an event handler was executed in.</p>
<p><span id="more-187"></span></p>
<p>When you attach an event to an element in jQuery within the event handler function the this keyword always refers to the element that triggered the event.</p>
<pre><code>$('a').bind('click', function() {
    alert(this);
});</code></pre>
<p>Here this will be the a element that triggered the event. For the majority of the time this behaviour is absolutely ideal. However, if you&#8217;re using object oriented javascript and are trying to handle an event using a method of one of your classes, the chances are you&#8217;d want this to refer to the instance of your class instead of the DOM element.</p>
<pre><code>var Klass = function() {
    this.message = 'hello';
};
Klass.prototype.handleClick = function(e) {
    alert(this.message);
};
var obj = new Klass();

$('a').bind('click', obj.handleClick);</code></pre>
<p>The above fails because when Klass.prototype.handleClick is triggered from the click event this still refers to the a element that was clicked on. Hence this.message is undefined.</p>
<p>To solve this problem I made a small jQuery plugin called hitch that allows you to control the object scope. The above example would be rewritten as</p>
<pre><code>var Klass = function() {
    this.message = 'hello';
};
Klass.prototype.handleClick = function(e) {
    alert(this.message);
};
var obj = new Klass();

$('a').hitch('click', obj.handleClick, obj);</code></pre>
<p>If the handleClick method needs to access the DOM element that triggered the event, that can still be accessed through e.target. If the object scope argument is omitted then hitch should work in the same way as the standard bind method.</p>
<p>The plugin itself is just a few lines</p>
<pre><code>(function($) {
    $.fn.hitch = function(ev, fn, scope) {
        return this.bind(ev, function() {
            return fn.apply(scope || this, Array.prototype.slice.call(arguments));
        });
    };
})(jQuery);</code></pre>
<p>I believe similar functionality is scheduled to be included in an upcoming jQuery release, but for the time being I&#8217;m finding this plugin to be exceptionally useful.</p>
<div id="crp_related"><h2>Related Articles:</h2><ul><li><a href="http://think-robot.com/2011/03/jquery-multiple-events-without-default-behaviour/" rel="bookmark">jQuery Multiple Events Without Default Behaviour</a></li><li><a href="http://think-robot.com/2008/11/nested-sortable-using-jtree-clickable-links/" rel="bookmark">Nested sortable using jTree - clickable links</a></li><li><a href="http://think-robot.com/2011/01/enable-delayed-messages-in-zend_queue/" rel="bookmark">Enable delayed messages in Zend_Queue</a></li><li><a href="http://think-robot.com/2010/03/multiple-changes-and-a-delete-on-same-object-in-doctrine/" rel="bookmark">Multiple changes and a delete on same object in doctrine</a></li><li><a href="http://think-robot.com/2008/10/display-meetings-from-entourage-using-geektool/" rel="bookmark">Display Meetings From Entourage Using GeekTool</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2009/06/hitch-object-oriented-event-handlers-with-jquery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Nested sortable using jTree &#8211; clickable links</title>
		<link>http://think-robot.com/2008/11/nested-sortable-using-jtree-clickable-links/</link>
		<comments>http://think-robot.com/2008/11/nested-sortable-using-jtree-clickable-links/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 11:08:35 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jTree]]></category>

		<guid isPermaLink="false">http://www.think-robot.com/?p=17</guid>
		<description><![CDATA[jTree is a lightweight solution for nested, sortable lists based on jQuery. I&#8217;ve been trying to find a good solution for quite a while, however the only good competitor to jTree is now not compatible with the new jQuery (1.2.6). After getting fed up at work with including totally different sets of javascript files depending [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gimiti.com/kltan/wordpress/?p=29" target="_blank">jTree is a lightweight solution for nested, sortable lists based on jQuery</a>. I&#8217;ve been trying to find a good solution for quite a while, however the only good competitor to jTree is now not compatible with the new jQuery (1.2.6). After getting fed up at work with including totally different sets of javascript files depending on whether the nested sortable was needed on a page or not I have decided it was time for some clean-up.</p>
<p>Minimal is a very good word to describe <a href="http://www.gimiti.com/kltan/wordpress/?p=29" target="_blank">jTree</a>, which most of the time is good, however sometimes you might just want a little bit more. One of the biggest issues for me was lack of clickable links inside the <strong>LI</strong>s. Fortunately after some tweaking I came up with a hacky but working solution:</p>
<pre>if ($("#jTreeHelper").is(":not(:animated)") &amp;&amp; e.button !=2) {
 	//	Allow for clickable links
	<strong>if(new String(e.target).match(/(f|ht)tp(s{0,1}):///ig)){
 		return false;</strong><strong>
	}</strong>
	$("body").css("cursor","move");</pre>
<p>Just add the highlighted lines in the jquery.jtree.js file. Basically it just checks if the target of the click is a link and if it is it ignores the dragging.</p>
<div id="crp_related"><h2>Related Articles:</h2><ul><li><a href="http://think-robot.com/2011/03/jquery-multiple-events-without-default-behaviour/" rel="bookmark">jQuery Multiple Events Without Default Behaviour</a></li><li><a href="http://think-robot.com/2009/04/regex-for-autolinking-urls/" rel="bookmark">Regex for Autolinking URLs</a></li><li><a href="http://think-robot.com/2009/06/hitch-object-oriented-event-handlers-with-jquery/" rel="bookmark">Hitch. Object-oriented event handlers with jQuery</a></li><li><a href="http://think-robot.com/2008/11/wordpress-nextgen-gallery-tweak/" rel="bookmark">WordPress NextGen gallery tweak</a></li><li><a href="http://think-robot.com/2009/02/firefox-ignores-tabs-but-not-spaces-in-a-pre-tag/" rel="bookmark">Firefox ignores tabs but not spaces in a pre tag</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2008/11/nested-sortable-using-jtree-clickable-links/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

