<?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>Rich Waters &#187; Drag &#8216;n Drop</title>
	<atom:link href="http://www.rich-waters.com/blog/category/drag-n-drop/feed" rel="self" type="application/rss+xml" />
	<link>http://www.rich-waters.com/blog</link>
	<description>Ext, Javascript, Notes/Domino, Ext.nd, Ruby on Rails</description>
	<lastBuildDate>Mon, 25 Jan 2010 19:44:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rico Drag n&#8217;Drop p2: Rico.Draggable</title>
		<link>http://www.rich-waters.com/blog/2006/04/rico-drag-ndrop-p2-ricodraggable.html</link>
		<comments>http://www.rich-waters.com/blog/2006/04/rico-drag-ndrop-p2-ricodraggable.html#comments</comments>
		<pubDate>Sat, 08 Apr 2006 20:25:00 +0000</pubDate>
		<dc:creator>Rich Waters</dc:creator>
				<category><![CDATA[Drag 'n Drop]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.rich-waters.com/blog/?p=14</guid>
		<description><![CDATA[After the overwhelming popularity of my short little blurb on Drag &#038; Drop using Rico, I&#8217;ve decided to write up a couple more articles stepping through the code used in the original example. You can take a look at the original article here.  There I covered the simplest way to get started, though thats [...]]]></description>
			<content:encoded><![CDATA[<p>After the overwhelming popularity of my short little blurb on Drag &#038; Drop using Rico, I&#8217;ve decided to write up a couple more articles stepping through the code used in the original example. You can take a look at the original article <a href="http://www.rich-waters.com/blog/2005/12/fun-with-drag-and-drop-wrico.html">here</a>.  There I covered the simplest way to get started, though thats not what the example used.  The <a href="http://www.rich-waters.com/blog/code/RouteExample2.html">example</a> makes some changes by creating custom draggable and dropable classes.</p>
<p>To start things off, you need to create your own class extending the built in Rico.Draggable class</p>
<blockquote>
<pre>var MyDraggable = Class.create();
MyDraggable.prototype = (new Rico.Draggable()).extend( {

}</pre>
</blockquote>
<p>While not seeming like much, this actually copies all the methods and functionality from the Rico.Draggable class into the MyDraggable class.  You can override any of these methods to change this functionality.  The first one to take a look at is the getSingleObjectDragGUI method.  By default this method just returns &#8216;this.htmlElement&#8217; and is used by other objects and methods to get a handle on the object you want to pick up(drag).  A few minor changes can make things much more aesthetically pleasing.</p>
<blockquote>
<pre>getSingleObjectDragGUI: function() {
new Effect.FadeTo( this.htmlElement,.2,250,10 );
var div = document.createElement("div");
div.id = "fakeitem";
div.className = 'item dragging';
new Insertion.Top( div, this.htmlElement.innerHTML );
return div;
},</pre>
</blockquote>
<p>Breaking that down, The first line uses Rico&#8217;s Effect object to fade the current div to 20% opacity.  On the next line we create a new div element, then assign an id and a couple class names to it (Not required, but nice if you want to apply any styling to it), then use Prototype&#8217;s Insertion to place it onto the page while copying the original divs innerHTML into the new one.  The last line returns a refrence to the newly created div instead of the original div.  This may seem a bit confusing, but the end result is that when you pick up the main div you get a copy.  The original div stays in place, but gets faded so you can tell the difference.</p>
<blockquote>
<pre>cancelDrag: function() {
new Effect.FadeTo( this.htmlElement,1,100,10 );
},</pre>
</blockquote>
<p>The cancelDrag method is called when the div being dragged is dropped anywhere but a drop target.  We call the Rico Effect object again and fade the original element back to 100% opacity.<br />
What happens to our &#8220;fakeitem&#8221; you ask?<br />
Good question, it just so happens that the built in _doCancelDragProcessing that gets called checks to see if the div has a parentNode, if it does not then the element is removed.</p>
<blockquote>
<pre>select: function() {
}</pre>
</blockquote>
<p>Override &#8217;select&#8217; with an empty method? this just stops the defualt selection highlighting.</p>
<p>There are several other methods that you can override to change the look or functionality at different stages.  Methods are: initialize, getMouseDownHTMLElement, select, deselect, isSelected, startDrag, cancelDrag, endDrag, getSingleObjectDragGUI,  getMultiObjectDragGUI, getDroppedGUI.</p>
<ul>
<li>The original example: <a href="http://www.rich-waters.com/blog/code/RouteExample2.html">RouteExample</a></li>
<li>The original Javascript: <a href="http://www.rich-waters.com/blog/code/rich.js">rich.js</a></li>
<li>First Aricle: <a href="http://www.rich-waters.com/blog/2005/12/fun-with-drag-and-drop-wrico.html">Fun with drag and drop w/rico</a></li>
</ul>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F04%2Frico-drag-ndrop-p2-ricodraggable.html&amp;title=Rico%20Drag%20n%27Drop%20p2%3A%20Rico.Draggable&amp;bodytext=After%20the%20overwhelming%20popularity%20of%20my%20short%20little%20blurb%20on%20Drag%20%26%20Drop%20using%20Rico%2C%20I%27ve%20decided%20to%20write%20up%20a%20couple%20more%20articles%20stepping%20through%20the%20code%20used%20in%20the%20original%20example.%20You%20can%20take%20a%20look%20at%20the%20original%20article%20here.%20%20There%20I%20c" title="Digg"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F04%2Frico-drag-ndrop-p2-ricodraggable.html&amp;t=Rico%20Drag%20n%27Drop%20p2%3A%20Rico.Draggable" title="Facebook"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F04%2Frico-drag-ndrop-p2-ricodraggable.html&amp;title=Rico%20Drag%20n%27Drop%20p2%3A%20Rico.Draggable&amp;annotation=After%20the%20overwhelming%20popularity%20of%20my%20short%20little%20blurb%20on%20Drag%20%26%20Drop%20using%20Rico%2C%20I%27ve%20decided%20to%20write%20up%20a%20couple%20more%20articles%20stepping%20through%20the%20code%20used%20in%20the%20original%20example.%20You%20can%20take%20a%20look%20at%20the%20original%20article%20here.%20%20There%20I%20c" title="Google Bookmarks"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://posterous.com/share?linkto=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F04%2Frico-drag-ndrop-p2-ricodraggable.html&amp;title=Rico%20Drag%20n%27Drop%20p2%3A%20Rico.Draggable&amp;selection=After%20the%20overwhelming%20popularity%20of%20my%20short%20little%20blurb%20on%20Drag%20%26%20Drop%20using%20Rico%2C%20I%27ve%20decided%20to%20write%20up%20a%20couple%20more%20articles%20stepping%20through%20the%20code%20used%20in%20the%20original%20example.%20You%20can%20take%20a%20look%20at%20the%20original%20article%20here.%20%20There%20I%20c" title="Posterous"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/posterous.png" title="Posterous" alt="Posterous" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.rich-waters.com/blog/feed" title="RSS"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://twitter.com/home?status=Rico%20Drag%20n%27Drop%20p2%3A%20Rico.Draggable%20-%20http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F04%2Frico-drag-ndrop-p2-ricodraggable.html" title="Twitter"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.rich-waters.com/blog/2006/04/rico-drag-ndrop-p2-ricodraggable.html/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Quick Update &#8211; Drag &amp; Drop</title>
		<link>http://www.rich-waters.com/blog/2006/03/quick-update-drag-drop.html</link>
		<comments>http://www.rich-waters.com/blog/2006/03/quick-update-drag-drop.html#comments</comments>
		<pubDate>Tue, 07 Mar 2006 13:47:00 +0000</pubDate>
		<dc:creator>Rich Waters</dc:creator>
				<category><![CDATA[Drag 'n Drop]]></category>

		<guid isPermaLink="false">http://www.rich-waters.com/blog/?p=10</guid>
		<description><![CDATA[After looking at some stats I found that my drag and drop article seems to be getting the most attention so I added a quick update to give a direct link to the sample javascript file.
DnD Article



Share and Enjoy:


	
	
	
	
	
	


]]></description>
			<content:encoded><![CDATA[<p>After looking at some stats I found that my drag and drop article seems to be getting the most attention so I added a quick update to give a direct link to the sample javascript file.<a href="http://www.rich-waters.com/blog/2005/12/fun-with-drag-and-drop-wrico.html"><br />
DnD Article</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F03%2Fquick-update-drag-drop.html&amp;title=Quick%20Update%20-%20Drag%20%26amp%3B%20Drop&amp;bodytext=After%20looking%20at%20some%20stats%20I%20found%20that%20my%20drag%20and%20drop%20article%20seems%20to%20be%20getting%20the%20most%20attention%20so%20I%20added%20a%20quick%20update%20to%20give%20a%20direct%20link%20to%20the%20sample%20javascript%20file.%0D%0ADnD%20Article" title="Digg"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F03%2Fquick-update-drag-drop.html&amp;t=Quick%20Update%20-%20Drag%20%26amp%3B%20Drop" title="Facebook"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F03%2Fquick-update-drag-drop.html&amp;title=Quick%20Update%20-%20Drag%20%26amp%3B%20Drop&amp;annotation=After%20looking%20at%20some%20stats%20I%20found%20that%20my%20drag%20and%20drop%20article%20seems%20to%20be%20getting%20the%20most%20attention%20so%20I%20added%20a%20quick%20update%20to%20give%20a%20direct%20link%20to%20the%20sample%20javascript%20file.%0D%0ADnD%20Article" title="Google Bookmarks"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://posterous.com/share?linkto=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F03%2Fquick-update-drag-drop.html&amp;title=Quick%20Update%20-%20Drag%20%26amp%3B%20Drop&amp;selection=After%20looking%20at%20some%20stats%20I%20found%20that%20my%20drag%20and%20drop%20article%20seems%20to%20be%20getting%20the%20most%20attention%20so%20I%20added%20a%20quick%20update%20to%20give%20a%20direct%20link%20to%20the%20sample%20javascript%20file.%0D%0ADnD%20Article" title="Posterous"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/posterous.png" title="Posterous" alt="Posterous" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.rich-waters.com/blog/feed" title="RSS"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://twitter.com/home?status=Quick%20Update%20-%20Drag%20%26amp%3B%20Drop%20-%20http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2006%2F03%2Fquick-update-drag-drop.html" title="Twitter"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.rich-waters.com/blog/2006/03/quick-update-drag-drop.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with Drag and Drop w/RICO</title>
		<link>http://www.rich-waters.com/blog/2005/12/fun-with-drag-and-drop-wrico.html</link>
		<comments>http://www.rich-waters.com/blog/2005/12/fun-with-drag-and-drop-wrico.html#comments</comments>
		<pubDate>Sat, 03 Dec 2005 17:22:00 +0000</pubDate>
		<dc:creator>Rich Waters</dc:creator>
				<category><![CDATA[Drag 'n Drop]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.rich-waters.com/blog/?p=6</guid>
		<description><![CDATA[Update 4/8/06 &#8211; Theres a new article available that dives into writing a custom Draggable Class.
Update 3/7/06 &#8211; looks like this is my most popular article and I noticed there&#8217;s no direct link to the sample javascript, so here you go.  rich.js
For those of you who haven&#8217;t seen OpenRico its another AJAX library, with [...]]]></description>
			<content:encoded><![CDATA[<p>Update 4/8/06 &#8211; Theres a new <a href="http://www.rich-waters.com/blog/2006/04/rico-drag-ndrop-p2-ricodraggable.html">article available</a> that dives into writing a custom Draggable Class.</p>
<p>Update 3/7/06 &#8211; looks like this is my most popular article and I noticed there&#8217;s no direct link to the sample javascript, so here you go.  <a href="http://www.rich-waters.com/blog/code/rich.js">rich.js</a></p>
<p>For those of you who haven&#8217;t seen <a href="http://openrico.org/">OpenRico</a> its another AJAX library, with quite a few cool extras. What I&#8217;m going to cover here is my first expiriment with Rico and their &#8216;drag and drop&#8217; functionality. Getting basic drag and drop functionality is extremely easy with this library, and with just a bit of modification you can easily make it fit whatever you could want.</p>
<p>First things first, to use Rico you need to get it: <a href="http://openrico.org/rico/downloads.page">Download Open Rico</a> and <a href="http://prototype.conio.net">Prototype</a> (if you haven&#8217;t seen protyotype before definitely check it out, OO Javascript at its best). Rico is a rather large library for just an everyday site so before deploying anything with it I would reccomend cutting out anything your not using and running it through a <a href="http://dojotoolkit.org/docs/compressor_system.html">JS Compressor</a>.</p>
<p>Import the libraries just like any other javascript, find or create a couple of div&#8217;s within your html to act as the draggable and the drop targets. Now add an onLoad javascript call (or put it elsewhere, perhaps an onclick if you want someone to activate the drag and drop feature) to</p>
<blockquote><p>dndMgr.registerDropZone( new Dropzone( &#8216;your html div&#8217; ) );</p></blockquote>
<p>dndMgr is an object that Rico creates for you to make creating drag and drop objects easy. With the single line above the specified div becomes a drop target for the draggable objects. Now with one more call, a different div can become a draggable object to be dropped on the first.</p>
<blockquote><p>dndMgr.registerDraggable( new Draggable(&#8216;test-rico-dnd&#8217;,'your html div2&#8242;) );</p></blockquote>
<p>Again calling a method of the built in dndMgr object to register a div as a draggable object. Same as before this can be called onLoad, onClick, or in the middle of any other javascript function so you can make it draggable at any point you choose.</p>
<p>To make something happen when an object gets dragged onto a target you need to go a bit more in depth (this is where learnig prototype will come in handy). You need to create your own draggable and Dropzone classes that extend the basic ones provided in Rico. If you look through the Rico classes you&#8217;ll notice methods which correspond to the different events that take place, clicking on a draggable object, dragging a draggable object, hovering over a drop target, releasing on a non-drop target, releasing on a drop target, and quite a few more. To create your own functionality override the method in your custom class and add the functionality that you want. Probably the most useful function to override is the <strong>Dropzone.accept</strong> function, you can use <strong>this.htmlElement</strong> to access the dropZone and <strong>draggableObjects[0].htmlElement</strong> to access the first draggable element being dropped on the target.</p>
<p>Here&#8217;s a toned down version of what I wrote for work: <a href="http://www.rich-waters.com/blog/code/RouteExample.html">RouteExample</a></p>
<p>This page has custom drag and drop objects written to change the effects some, the trash can is the drop target and draggable objects are created on the fly when you press the submit button. Basically we&#8217;re allowing the user to create a list of options, if they mess up all they need to is drag the mistake on the trash can (something most people are familiar with due to windows).</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2005%2F12%2Ffun-with-drag-and-drop-wrico.html&amp;title=Fun%20with%20Drag%20and%20Drop%20w%2FRICO&amp;bodytext=Update%204%2F8%2F06%20-%20Theres%20a%20new%20article%20available%20that%20dives%20into%20writing%20a%20custom%20Draggable%20Class.%0D%0A%0D%0AUpdate%203%2F7%2F06%20-%20looks%20like%20this%20is%20my%20most%20popular%20article%20and%20I%20noticed%20there%27s%20no%20direct%20link%20to%20the%20sample%20javascript%2C%20so%20here%20you%20go.%20%20rich.js%0D%0A%0D%0A" title="Digg"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2005%2F12%2Ffun-with-drag-and-drop-wrico.html&amp;t=Fun%20with%20Drag%20and%20Drop%20w%2FRICO" title="Facebook"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2005%2F12%2Ffun-with-drag-and-drop-wrico.html&amp;title=Fun%20with%20Drag%20and%20Drop%20w%2FRICO&amp;annotation=Update%204%2F8%2F06%20-%20Theres%20a%20new%20article%20available%20that%20dives%20into%20writing%20a%20custom%20Draggable%20Class.%0D%0A%0D%0AUpdate%203%2F7%2F06%20-%20looks%20like%20this%20is%20my%20most%20popular%20article%20and%20I%20noticed%20there%27s%20no%20direct%20link%20to%20the%20sample%20javascript%2C%20so%20here%20you%20go.%20%20rich.js%0D%0A%0D%0A" title="Google Bookmarks"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://posterous.com/share?linkto=http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2005%2F12%2Ffun-with-drag-and-drop-wrico.html&amp;title=Fun%20with%20Drag%20and%20Drop%20w%2FRICO&amp;selection=Update%204%2F8%2F06%20-%20Theres%20a%20new%20article%20available%20that%20dives%20into%20writing%20a%20custom%20Draggable%20Class.%0D%0A%0D%0AUpdate%203%2F7%2F06%20-%20looks%20like%20this%20is%20my%20most%20popular%20article%20and%20I%20noticed%20there%27s%20no%20direct%20link%20to%20the%20sample%20javascript%2C%20so%20here%20you%20go.%20%20rich.js%0D%0A%0D%0A" title="Posterous"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/posterous.png" title="Posterous" alt="Posterous" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.rich-waters.com/blog/feed" title="RSS"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://twitter.com/home?status=Fun%20with%20Drag%20and%20Drop%20w%2FRICO%20-%20http%3A%2F%2Fwww.rich-waters.com%2Fblog%2F2005%2F12%2Ffun-with-drag-and-drop-wrico.html" title="Twitter"><img src="http://www.rich-waters.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.rich-waters.com/blog/2005/12/fun-with-drag-and-drop-wrico.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
