<?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>Made of Everything You&#039;re Not &#187; jquery</title>
	<atom:link href="http://blog.ericlamb.net/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ericlamb.net</link>
	<description>Thoughts on programming, people and life</description>
	<lastBuildDate>Thu, 27 Oct 2011 01:29:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>jQuery HoverIntent</title>
		<link>http://blog.ericlamb.net/2010/12/jquery-hoverintent/</link>
		<comments>http://blog.ericlamb.net/2010/12/jquery-hoverintent/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 22:35:45 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[hoverIntent]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3425</guid>
		<description><![CDATA[I had a project recently to build a custom tooltip for a client site. The spec called for something the opposite of out of the box so it would have to be done as a custom job; no single off the shelf plugin would work here. There was one in particular that I was really [...]]]></description>
			<content:encoded><![CDATA[<p>I had a project recently to build a custom tooltip for a client site. The spec called for something the opposite of out of the box so it would have to be done as a custom job; no single off the shelf plugin would work here. There was one in particular that I was really stoked I could use to make development a lot easier; <a title="hoverIntent" href="http://cherne.net/brian/resources/jquery.hoverIntent.html" onclick="return TrackClick('http%3A%2F%2Fcherne.net%2Fbrian%2Fresources%2Fjquery.hoverIntent.html','hoverIntent')" target="_blank">hoverIntent</a>.</p>
<p>When I started thinking about how to approach this project an immediate worry I had was how to bypass the snappiness of the default jquery hover behavior. As you&#8217;d probably expect it&#8217;s perfect, which sums up my problem; the project requirements called for an ajax tooltip which means every time it was activated a call to the server would happen. This would SUCK if it happened too much for basic performance reasons so it was important that there wasn&#8217;t any unnecessary server calls. Using the default behavior a user just dragging their mouse over the links would make a server call. This was no good.</p>
<p>Off the top of my head the best way to handle this situation was to write in some timers to delay the server call and add in some checks. Frankly though, I&#8217;m much too lazy for all that so I hit up my goto source for all code related head scratchers: <a title="Delay with hoverintent" href="http://stackoverflow.com/questions/1510804/delay-with-hoverintent" onclick="return TrackClick('http%3A%2F%2Fstackoverflow.com%2Fquestions%2F1510804%2Fdelay-with-hoverintent','Delay+with+hoverintent')" target="_blank">StackOverflow</a>.  There I heard about hoverIntent; a great plugin which handles all of the above and then some.</p>
<p>In a nutshell, hoverIntent works by replacing the normal calls to &#8220;hover&#8221; with &#8220;hoverIntent&#8221; with the same parameters as &#8220;hover&#8221;. A basic example of both techniques would be:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">//default jquery hover usage
$(&quot;#demo1 li&quot;).hover( overCallBack, outCallBack );
&nbsp;
//default jquery hover usage
$(&quot;#demo1 li&quot;).hoverIntent( overCallBack, outCallBack );</pre></div></div>

<p>Note that there are 2 parameters that can be passed and they&#8217;re the same regardless of whether you&#8217;re using &#8220;hover&#8221; or &#8220;hoverIntent&#8221;; both are functions with the first being the over state (when the user mouses over the item) and the second being the out state (when the user moves their mouse off the item). </p>
<p>The above is the easiest and fastest way to use hoverIntent but there&#8217;s another, better, method that allows for much more customization. By passing hoverIntent and single object you can customize how the plugin behaves. hoverIntent allows for customization of the sensitivity and the interval, which according to the official site means:</p>
<blockquote><p>
timeout:<br />
A simple delay, in milliseconds, before the &#8220;out&#8221; function is called. If the user mouses back over the element before the timeout has expired the &#8220;out&#8221; function will not be called (nor will the &#8220;over&#8221; function be called). This is primarily to protect against sloppy/human mousing trajectories that temporarily (and unintentionally) take</p>
<p>sensitivity:<br />
If the mouse travels fewer than this number of pixels between polling intervals, then the &#8220;over&#8221; function will be called. With the minimum sensitivity threshold of 1, the mouse must not move between polling intervals. With higher sensitivity thresholds you are more likely to receive a false positive. Default sensitivity: 7</p>
<p>interval:<br />
The number of milliseconds hoverIntent waits between reading/comparing mouse coordinates. When the user&#8217;s mouse first enters the element its coordinates are recorded. The soonest the &#8220;over&#8221; function can be called is after a single polling interval. Setting the polling interval higher will increase the delay before the first possible &#8220;over&#8221; call, but also increases the time to the next point of comparison. Default interval: 100
</p></blockquote>
<p>The below example illustrates how the object should be created and passed.</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">var settings = {
    sensitivity: 4,
    interval: 75,
    over: overCallBack,
    out: outCallBack
}; 
$(&quot;#demo1 li&quot;).hoverIntent( settings );</pre></div></div>

<p>And there you go; a better way to handle hovering over elements with jquery.</p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2010/12/jquery-hoverintent/' addthis:title='jQuery HoverIntent '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2010/12/jquery-hoverintent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to jQuery UI</title>
		<link>http://blog.ericlamb.net/2009/11/introduction-to-jquery-ui/</link>
		<comments>http://blog.ericlamb.net/2009/11/introduction-to-jquery-ui/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 13:00:49 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=1931</guid>
		<description><![CDATA[Building the fancy, web 2.0 / Ajaxy, user interfaces for a web application we&#8217;ve all come to expect is, frankly, a pain in the ass. Depending on the JavaScript library you&#8217;re using there&#8217;s usually some addon library to extend the functionality for UI which helps make it easier and ease the pain. If you&#8217;re using [...]]]></description>
			<content:encoded><![CDATA[<p>Building the fancy, web 2.0 / Ajaxy, user interfaces for a web application we&#8217;ve all come to expect is, frankly, a pain in the ass. Depending on the JavaScript library you&#8217;re using there&#8217;s usually some addon library to extend the functionality for UI which helps make it easier and ease the pain. If you&#8217;re using <a title="jQuery" href="http://jquery.com/" onclick="return TrackClick('http%3A%2F%2Fjquery.com%2F','jQuery')" target="_blank">jQuery</a> (and to be honest I&#8217;m more of a Prototype guy) a good library is <a title="jQuery Ui" href="http://jqueryui.com/home" onclick="return TrackClick('http%3A%2F%2Fjqueryui.com%2Fhome','jQuery+Ui')" target="_blank">jQuery Ui</a>.</p>
<div id="attachment_2609" class="wp-caption aligncenter" style="width: 268px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/11/JQuery_UI_Logo.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F11%2FJQuery_UI_Logo.png','JQuery+UI')"><img class="size-full wp-image-2609" title="JQuery UI" src="http://blog.ericlamb.net/wp-content/uploads/2009/11/JQuery_UI_Logo.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F11%2FJQuery_UI_Logo.png','JQuery+UI')" alt="JQuery UI" width="258" height="93" /></a><p class="wp-caption-text">JQuery UI</p></div>
<p>According to the official site:</p>
<blockquote><p>jQuery UI is an open source library of interface components — <a href="http://jqueryui.com/demos" onclick="return TrackClick('http%3A%2F%2Fjqueryui.com%2Fdemos','interactions%2C+full-featured+widgets%2C+and+animation+effects')" target="_blank">interactions, full-featured widgets, and animation effects</a> — based on the stellar <a href="http://jquery.com" onclick="return TrackClick('http%3A%2F%2Fjquery.com','jQuery+javascript+library')" target="_blank">jQuery javascript library</a>.  Each component is built according to <a href="http://docs.jquery.com/How_jQuery_Works" onclick="return TrackClick('http%3A%2F%2Fdocs.jquery.com%2FHow_jQuery_Works','jQuery%22s+event-driven+architecture')" target="_blank">jQuery&#8217;s event-driven architecture</a> (find something, manipulate it) and is <a href="http://jqueryui.com/docs/Theming" onclick="return TrackClick('http%3A%2F%2Fjqueryui.com%2Fdocs%2FTheming','themeable')" target="_blank">themeable</a>, making it easy for developers of any skill level to integrate and extend into their own code.</p></blockquote>
<p>I only ran into it because of an update to WP-Click-Track and WordPress uses jQuery so I kinda had to. Not that it&#8217;s a bad thing; I like jQuery a little bit more because of jQuery UI.</p>
<p>One of the really cool things about jQuery UI is that there&#8217;s an online tool to generate a custom download specific to the project. Having worked with JavaScript libraries for a while I appreciate the customization and convenience of having the smallest footprint as possible. Kudos to them on that.</p>
<p>There&#8217;s also a <a title="jQuery UI Theme Builder" href="http://jqueryui.com/themeroller/" onclick="return TrackClick('http%3A%2F%2Fjqueryui.com%2Fthemeroller%2F','jQuery+UI+Theme+Builder')" target="_blank">Theme Builder</a> that gives a good overview of what&#8217;s available by default along with some preset themes to test; there&#8217;s a good deal of widgets there to work with. Almost, <em>almost</em>, makes me want to start a project with it.</p>
<div id="attachment_2617" class="wp-caption aligncenter" style="width: 215px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/11/jQuery-UI-ThemeRoller_1257127607785.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F11%2FjQuery-UI-ThemeRoller_1257127607785.png','jQuery+UI+-+ThemeRoller')"><img class="size-medium wp-image-2617" title="jQuery UI - ThemeRoller" src="http://blog.ericlamb.net/wp-content/uploads/2009/11/jQuery-UI-ThemeRoller_1257127607785-205x300.png" alt="jQuery UI - ThemeRoller" width="205" height="300" /></a><p class="wp-caption-text">jQuery UI - ThemeRoller</p></div>
<p>Implementation is really elegant too; if you know how jQuery works it&#8217;ll be pretty obvious. Otherwise take a look at the below for creating tabs:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;div id=&quot;tab-jquery-id&quot;&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;#tab1&quot;&gt;Tab 1&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tab2&quot;&gt;Tab 2&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tab3&quot;&gt;Tab 3&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tab4&quot;&gt;Tab 4&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tab5&quot;&gt;Tab 5&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;div id=&quot;tab1&quot;&gt;
&nbsp;
	&lt;/div&gt;
	&lt;div id=&quot;tab2&quot;&gt;
&nbsp;
	&lt;/div&gt;
	&lt;div id=&quot;tab3&quot;&gt;
&nbsp;
	&lt;/div&gt;
	&lt;div id=&quot;tab4&quot;&gt;
&nbsp;
	&lt;/div&gt;
	&lt;div id=&quot;tab5&quot;&gt;
&nbsp;
	&lt;/div&gt;
&lt;/div&gt;
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">//&lt;![CDATA[</span>
jQuery<span style="color: #000;">&#40;</span>document<span style="color: #000;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #000;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #000;">&#40;</span>$<span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//jQuery UI 1.5.2 doesn't expect tab ID's at DIV, so we have to apply a hotfix instead</span>
	<span style="color: #003366; font-weight: bold;">var</span> needs_jquery_hotfix <span style="color: #339933;">=</span> <span style="color: #000;">&#40;</span><span style="color: #000;">&#40;</span>$.<span style="color: #660066;">ui</span>.<span style="color: #660066;">version</span> <span style="color: #339933;">===</span> undefined<span style="color: #000;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>$.<span style="color: #660066;">ui</span>.<span style="color: #660066;">version</span>.<span style="color: #660066;">match</span><span style="color: #000;">&#40;</span><span style="color: #009966; font-style: italic;">/^(1\.[7-9]|[2-9]\.)/</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #000;">&#40;</span><span style="color: #3366CC;">&quot;#tab-jquery-id&quot;</span><span style="color: #339933;">+</span><span style="color: #000;">&#40;</span>needs_jquery_hotfix <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;&gt;ul&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">tabs</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#123;</span>
		selected<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
	<span style="color: #000;">&#125;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span> 
	$<span style="color: #000;">&#40;</span><span style="color: #3366CC;">'.tab5:last'</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">'tab5'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//]]&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>As you can see there&#8217;s not much there in so far as design or class decorators go; most of that&#8217;s handled by jQuery itself as well as the generated css. The only thing to really worry about is adding the wrapper div id in the bottom JavaScript. Still, not a bad thing.</p>
<p>This, of course, barely scratched the surface of jQuery UI but it doesn&#8217;t get much more difficult. If you&#8217;re using jQuery for a library and you need to make something cool it&#8217;s definitely worth checking out.</p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2009/11/introduction-to-jquery-ui/' addthis:title='Introduction to jQuery UI '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/11/introduction-to-jquery-ui/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

