<?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>Kombine &#187; jQuery</title>
	<atom:link href="http://www.kombine.net/category/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://www.kombine.net</link>
	<description></description>
	<lastBuildDate>Tue, 07 Jul 2009 00:15:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery UI Cursor Selection</title>
		<link>http://www.kombine.net/jquery/jquery-ui-cursors</link>
		<comments>http://www.kombine.net/jquery/jquery-ui-cursors#comments</comments>
		<pubDate>Sat, 28 Jun 2008 01:27:12 +0000</pubDate>
		<dc:creator>Kreg Wallace</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kombine.net/news/?p=25</guid>
		<description><![CDATA[An examination of the appropriate cursor properties to be used with jQuery UI-enabled page elements. Working examples for draggable(), resizable() and AJAX post are provided.]]></description>
			<content:encoded><![CDATA[<p>In a recent post on providing <a href="http://www.kombine.net/jquery/jquery-draggable-icons/">jQuery UI Draggable Icons</a>, I noted that switching the cursor setting to &#8220;pointer&#8221; on draggable page elements was a good idea because it indicated that the draggable element was actionable. While this was an improvement over the text-selection cursor the browser provided by default, I completely overlooked the existence of the <strong style="cursor: move;border-bottom: 1px dotted #ddd;">move cursor</strong>. The move cursor is clearly the better choice in this case and I have updated my <a href="http://www.kombine.net/examples/icons/jquery/draggable/">example code</a> to use it.</p>
<p>I searched around and it turns out there are around thirty different cursors available to the browser that can easily be set with CSS. The Mozilla Developer Center offers a handy <a href="http://developer.mozilla.org/en/docs/CSS:cursor#Supported_CSS_standard_values">cursor test page</a>, allowing us to view each of the standard cursors in action (by mousing over the values in the &#8220;CSS name&#8221; column). So, how can we use these cursor options to improve the usability of jQuery UI effects?</p>
<h3>Resizables</h3>
<p>Eight of those cursors are handles for manipulating the edges and corners of resizable elements. jQuery UI includes a resizable method, so let&#8217;s test it out. This is the HTML element we&#8217;ll be resizing:<br />
<code class="html"><br />
&lt;div class="resizable"&gt;I'm resizable&lt;/div&gt;<br />
</code></p>
<p>And this is the jQuery UI JavaScript code need to make it resizable:<br />
<code class="js"><br />
$('.resizable').resizable();<br />
</code></p>
<p>And a little CSS to style our HTML:<br />
<code class="css"><br />
.resizable {<br />
	background-color: #ff8998;<br />
	border: 2px solid #d2412c;<br />
	height: 100px;<br />
	text-align: center;<br />
	width: 100px;<br />
}<br />
</code></p>
<dl class="icon-48 icon-48-javascript">
<dt class="title"><a href="http://www.kombine.net/examples/icons/jquery/cursors/jquery_cursors.zip">Get the Code</a></dt>
<dd>or see the <a href="http://www.kombine.net/examples/icons/jquery/cursors/">working examples</a></dd>
</dl>
<p><strong>Not bad at all!</strong> Notice how the correct cursor styles are displayed by the resizable handles even though we haven&#8217;t assigned any cursor styles in our CSS. jQuery UI takes care of selecting the cursors for us by default. It&#8217;s a great example of foresight by the jQuery UI team. But what about those draggables?</p>
<h3>Draggables?</h3>
<p>Unfortunately, jQuery UI does not automatically set the cursor to &#8220;move&#8221; when the user hovers over a draggable element. This seems like an oversight to me, but perhaps a default move cursor for draggables will make it&#8217;s way into a future release. In any case, it&#8217;s simple enough to set this property for ourselves. Just add <strong>cursor: move</strong> to the CSS definitions of all of your draggable elements.</p>
<h3>What about AJAX?</h3>
<p>AJAX routines are another aspect of jQuery that could be improved with some default cursor styling. Did you notice the animated <strong style="cursor: progress;border-bottom: 1px dotted #ddd;">progress cursor</strong> example on the Mozilla page? This is a great cursor for indicating that a process is operating in the background which will be completed shortly.</p>
<h4>Where to attach it?</h4>
<p>When we try to use this cursor on an AJAX form submission, one question quickly becomes apparent: Where should we attach it? <strong>Cursors change in accordance with the page element that is being hovered.</strong> But we want the progress cursor to remain on display regardless of which element the user hovers over, until the AJAX operation returns it&#8217;s data from the server. The solution is to assign the &#8220;progress&#8221; cursor to the &lt;body&gt; tag when the form is submitted and then reset the &lt;body&gt; tag&#8217;s cursor to &#8220;auto&#8221; when the return data arrives from the server. We can accomplish this with the following commands:<br />
<code class="js"><br />
document.body.style.cursor = 'progress';<br />
</code></p>
<p>and:<br />
<code class="js"><br />
document.body.style.cursor = 'auto';<br />
</code></p>
<p>Here&#8217;s how they might be used in an AJAX request script:<br />
<code class="js"><br />
$('#my_form').submit(function() {<br />
	document.body.style.cursor = 'progress';<br />
	$.post('my_script.php', {<br />
		my_key: my_input_field_value<br />
	},<br />
	function(data) {<br />
		code_to_update_page;<br />
		document.body.style.cursor = 'auto';<br />
	});<br />
	return false;<br />
});<br />
</code></p>
<h4>Pseudo example</h4>
<p>On my example page, the &#8220;ajax post&#8221; box provides a visual example of this effect. However, it is not a true working example, as no AJAX routine is actually being performed. Clicking the box simply sets the &lt;body&gt; cursor to &#8220;progress&#8221; for three seconds and then resets it to &#8220;auto&#8221;.</p>
<dl class="icon-48 icon-48-javascript">
<dt class="title"><a href="http://www.kombine.net/examples/icons/jquery/cursors/jquery_cursors.zip">Get the Code</a></dt>
<dd>or see the <a href="http://www.kombine.net/examples/icons/jquery/cursors/">working examples</a></dd>
</dl>
<h2>Useful links:</h2>
<ul>
<li><a href="http://jquery.com/">Get jQuery</a></li>
<li><a href="http://jqueryui.com/">Get jQuery UI</a></li>
</ul>
<p><ins> I changed the AJAX example above to reset the <body> cursor to &#8220;auto&#8221;, instead of resetting it to &#8220;default&#8221; as I had originally written. Using default will force the arrow cursor to display, while using auto allows the browser to display whichever cursor is appropriate to the page element that is being hovered, and is thus the preferred solution.</ins></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kombine.net/jquery/jquery-ui-cursors/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Poof Effect</title>
		<link>http://www.kombine.net/jquery/jquery-poof-effect</link>
		<comments>http://www.kombine.net/jquery/jquery-poof-effect#comments</comments>
		<pubDate>Tue, 24 Jun 2008 17:55:24 +0000</pubDate>
		<dc:creator>Kreg Wallace</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kombine.net/news/?p=22</guid>
		<description><![CDATA[A Mac OS X dock - style "poof" sprite animation effect for use with jQuery hide(), remove(), and fadeOut() methods. Free original poof source graphics and example JavaScript code are provided.]]></description>
			<content:encoded><![CDATA[<p>Following up on my last post, <a href="http://www.kombine.net/jquery/jquery-draggable-icons/">jQuery UI Draggable Icons</a>, which offered a way of presenting visual cues to help users identify draggable page elements, this article examines a technique for providing visual feedback when a page element is removed.</p>
<h3>The poof effect</h3>
<p>Mac OS X users will be familiar with the poof animation that occurs when application icons are removed from the dock. The animation looks nice, is unobtrusive, and provides a clear indication of the function being performed. Why not bring this effect to the web?</p>
<dl class="icon-48 icon-48-javascript">
<dt class="title"><a href="http://www.kombine.net/examples/icons/jquery/poof/jquery_poof_effect.zip">Download the Script</a></dt>
<dd>or check out the <a href="http://www.kombine.net/examples/icons/jquery/poof/">demo page</a></dd>
</dl>
<h3>Hiding and removing elements with jQuery</h3>
<p>The jQuery library provides several methods for hiding the display of page elements or removing them entirely from the document tree. The <strong>remove()</strong> and <strong>hide()</strong> methods cause elements to disappear instantaneously. The sudden disappearance can leave your site visitors wondering exactly what happened when they clicked that delete button. The <strong>fadeOut()</strong> method, however, provides a more graceful exit. We&#8217;ll use that in our example. Let&#8217;s get started with the code:<br />
<code class="html"><br />
&lt;div class=&quot;deleteme&quot;&gt;<br />
	delete me<br />
&lt;/div&gt;<br />
</code></p>
<p>Above is the HTML for the element we&#8217;ll be removing from the page. Now let&#8217;s remove it with jQuery:<br />
<code class="js"><br />
$(document).ready(function() {<br />
	$(&#39;.deleteme&#39;).click(function() {<br />
		$(this).fadeOut(&#39;fast&#39;);<br />
	});<br />
});<br />
</code></p>
<p>Here we use the standard jQuery technique of attaching event handlers to page elements when the document structure has finished loading. In the above code, each element that has a class name of &#8220;deleteme&#8221; is assigned an onclick event that when performed, causes the clicked element to quickly fade and become hidden. It works nicely and provides a base level of visual feedback for the user. But we can do better.</p>
<h3>Elements of a poof</h3>
<p><img src="http://www.kombine.net/wp-content/uploads/poof.png" alt="Poof for jQuery" title="Poof for jQuery" width="32" height="160" style="float: right;padding: 0 0 20px 20px;" />We&#8217;ll be creating our poof using sprite animation. Sprite animation is a technique in which all of the frames used in an animation sequence are collected side-by-side in a single image file. Only a small portion, or frame, of the complete image is displayed at a given time and the animation is composed by sequentially adjusting the visible portion of the image, much like a filmstrip. You can see the image we&#8217;ll be using for our animation to the right. It is divided into five frames.</p>
<h3>Why use sprite animation?</h3>
<p>Using an animated GIF might be easier and wouldn&#8217;t require as much coding, but sprite animation offers two distinct advantages: First, with sprite animation we have the option of using PNG images with alpha transparency (GIF offers only binary transparency and <a href="http://www.libpng.org/pub/mng/">MNG</a> support by the major browsers just never took off). Second, we can control the frame rate of sprite animations programatically, so a single image file can be animated at any speed by simply typing in the desired frame rate&mdash;no need to create a whole new version of the image file.</p>
<h3>Displaying and animating the sprite</h3>
<p>First, we&#8217;ll place an empty &lt;div&gt; tag on the page to hold the poof sprite:<br />
<code class="html"><br />
&lt;div class=&quot;poof&quot;&gt;&lt;/div&gt;<br />
</code></p>
<p>Then we can style it with CSS:<br />
<code class="css"><br />
.poof {<br />
	background: transparent url(../images/poof.png) no-repeat 0 0;<br />
	cursor: pointer;<br />
	display: none;<br />
	height: 32px;<br />
	position: absolute;<br />
	width: 32px;<br />
}<br />
</code></p>
<p>Here, the poof sprite (poof.png) is set as the background image and its top and left positions are both set to 0. The display is set to none, so the element is currently invisible. The height and width are both set to 32 pixels, which is the size of each frame in our animation. We have set the position type to absolute, but have not specified the top and left values. These we will handle in JavaScript with jQuery:<br />
<code class="js"><br />
$(document).ready(function() {<br />
	$(&#39;.deleteme&#39;).click(function(e) {<br />
		var xOffset = 24;<br />
		var yOffset = 24;<br />
&nbsp;<br />
		$(this).fadeOut(’fast’);<br />
&nbsp;<br />
		$(’.poof’).css({<br />
			left: e.pageX - xOffset + ‘px’,<br />
			top: e.pageY - yOffset + ‘px’<br />
		}).show();<br />
&nbsp;<br />
		animatePoof();<br />
	});<br />
});<br />
</code></p>
<p>Now, when the &#8220;.deleteme&#8221; element is clicked, the &#8220;.poof&#8221; animation is positioned next to our cursor (see the <a href="http://docs.jquery.com/Tutorials:Mouse_Position" class="nobreak">jQuery docs</a> for more on how to use <strong>pageX</strong> and <strong>pageY</strong> to determine the cursor position). Its position relative to the cursor is determined by the <strong>xOffset</strong> and <strong>yOffset</strong> variables we defined. Next, we use .show() to turn the display of the poof animation on and run the animation by calling a separate function, <strong>animatePoof()</strong>:<br />
<code class="js"><br />
function animatePoof() {<br />
	var bgTop = 0;<br />
	var frames = 5;<br />
	var frameSize = 32;<br />
	var frameRate = 80;<br />
&nbsp;<br />
	for(i = 1; i &lt; frames; i ++) {<br />
		$(&#39;.poof&#39;).animate({<br />
			backgroundPosition: &#39;0 &#39; + (bgTop - frameSize) + &#39;px&#39;<br />
		}, frameRate);<br />
&nbsp;<br />
		bgTop -= frameSize;<br />
	}<br />
&nbsp;<br />
	setTimeout(&quot;$(&#39;.poof&#39;).hide()&quot;, frames * frameRate);<br />
}<br />
</code></p>
<p>The animatePoof() function is composed of a loop that resets the background-position of the .poof &lt;div&gt; by the height of one frame per iteration, creating a simple animation effect. The <strong>bgPosition</strong> variable represents the initial top position of the background-image. This value is decreased by 32 pixels on each iteration of the loop. The <strong>frameRate</strong> variable determines the speed of the animation. Here, each frame is displayed for 80 milliseconds. Once the animation has completed, we need to hide the poof &lt;div&gt; so that its presence (though invisible) will not block attempts to click other elements we want to delete. This is accomplished with the <strong>setTimeout</strong> call.</p>
<h3>License</h3>
<p>The poof image used in this example was created by <a href="http://www.kombine.net/">The&nbsp;Kombine&nbsp;Group</a> and is modeled after the Apple OS X dock poof. It is provided here for free and is licensed under both the GPL and MIT licenses&mdash;the same licensing used by the jQuery library itself.</p>
<h3>Download</h3>
<p>Clicking the “Download the Script” link below will download a ZIP file containing the poof as a PNG file, a copy of the working example code, the MIT and GPL licenses and a layered PSD source file. In the PSD, each frame is 128 &times; 128 pixels, so you can use it for creating much larger poofs if you desire.</p>
<dl class="icon-48 icon-48-javascript">
<dt class="title"><a href="http://www.kombine.net/examples/icons/jquery/poof/jquery_poof_effect.zip">Download the Script</a></dt>
<dd>or check out the <a href="http://www.kombine.net/examples/icons/jquery/poof/">demo page</a></dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://www.kombine.net/jquery/jquery-poof-effect/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>jQuery UI Draggable Icons</title>
		<link>http://www.kombine.net/jquery/jquery-draggable-icons</link>
		<comments>http://www.kombine.net/jquery/jquery-draggable-icons#comments</comments>
		<pubDate>Mon, 23 Jun 2008 06:27:03 +0000</pubDate>
		<dc:creator>Kreg Wallace</dc:creator>
				<category><![CDATA[Icons]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kombine.net/news/?p=18</guid>
		<description><![CDATA[An original icon design (two icons, actually) for indicating which HTML page elements are draggable. Made for use with the jQuery UI JavaScript library. The icon is free and licensed under GPL and MIT. A layered source PSD is also provided.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been working with <a href="http://jqueryui.com/">jQuery UI</a> draggable and droppable components and while the functionality is great and easy to implement, drag-and-drop does present a potential usability problem: drag-and-drop components are not yet in widespread use on the web and the average web surfer will not be expecting to discover them on your web site. Because of this, drag-and-drop components could get overlooked completely. How do we solve the problem?</p>
<dl class="icon-48 icon-48-download">
<dt class="title"><a href="http://www.kombine.net/examples/icons/jquery/draggable/jquery_draggable_icons.zip">Download the Icons</a></dt>
<dd>or check out the <a href="http://www.kombine.net/examples/icons/jquery/draggable/">demo page</a></dd>
</dl>
<h3>Users need a hint</h3>
<p>We could provide text instructions on the page, explaining which objects are draggable and what to do with them, but we all know that people don&#8217;t <em>read</em> on the web; they scan. So, let&#8217;s give visitors a <strong>visual cue</strong> to help them quickly identify draggable components.</p>
<h3>The icons</h3>
<p>I&#8217;ve created a draggable icon to help address the problem. Actually, there are two icons: one for use on light backgrounds and another for dark backgrounds. The icons are 16 × 16 pixel PNG images with alpha transparency. Here&#8217;s the quick preview:</p>
<table cellpadding="0" cellspacing="0 border="0" width="64" height="32" style="margin-bottom: 1em;">
<tr>
<td style="background-color: #000;padding: 8px;" width="32" heigh="32">
<img src="http://www.kombine.net/wp-content/uploads/icon_draggable_dark.png" alt="" width="16" height="16" />
</td>
<td style="background-color: #fff;padding: 8px;" width="32" heigh="32">
<img src="http://www.kombine.net/wp-content/uploads/icon_draggable_light.png" alt="" width="16" height="16" />
</td>
</tr>
</table>
<p>You can see the draggable icons in action on the <a title="jQuery UI draggable icons example" href="http://www.kombine.net/examples/icons/jquery/draggable/">demo&nbsp;page</a>.</p>
<h3>Making use of the icons</h3>
<p>In the example, I put the icons to use as background images in the headers of my draggable boxes. Here is the HTML:<br />
<code class="html"><br />
&lt;div class=&quot;draggable dark&quot;&gt;<br />
	&lt;h3 class=&quot;title&quot;&gt;Dark background&lt;/h3&gt;<br />
&lt;/div&gt;<br />
</code></p>
<p>In the CSS, .draggable h3 gets the background image and is assigned a 24 pixel left padding. Its line height is also set to 24 pixels and the icon is positioned 4 pixels from the top of it&#8217;s containing h3 tag in order to keep everything vertically aligned. Here is that bit of CSS:<br />
<code class="css"><br />
.dark h3.title {<br />
	background: #36c url(../images/icon_draggable_dark.png) no-repeat 2px 4px;<br />
	color: #fff;<br />
	font-size: 12px;<br />
	font-weight: bold;<br />
	line-height: 24px;<br />
	margin: 0;<br />
	padding-left: 24px;<br />
}<br />
</code></p>
<p><strong>Note:</strong> line-height and padding-left should be set to at least 16 pixels each in order to display the full icon.</p>
<p><del>Also note that the draggable boxes have been assigned cursor: pointer in their CSS styles in order to display the pointing hand cursor when a user hovers over them.</del> <ins> The cursor style has now been changed to &#8220;move&#8221;. This is the better option and one I had previously overlooked.</ins> This helps to indicate that the draggable box is an actionable object. Without this style, the default cursor in our example would have been the text selector, which is less suited to the functionality we are trying to emphasize.</p>
<h3>License</h3>
<p>The jQuery UI draggable icons are free and licensed under both the GPL and MIT licenses—the same licensing used for the jQuery JavaScript library itself. Basically, you can put the icons to any use you wish, whether personal or commercial, and you won&#8217;t have to jump through any special hoops in order to do so.</p>
<dl class="icon-48 icon-48-download">
<dt class="title"><a href="http://www.kombine.net/examples/icons/jquery/draggable/jquery_draggable_icons.zip">Download the Icons</a></dt>
<dd>or check out the <a href="http://www.kombine.net/examples/icons/jquery/draggable/">demo page</a></dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://www.kombine.net/jquery/jquery-draggable-icons/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
