Ruby-on-Rails
  Home arrow Ruby-on-Rails arrow Dropping and Sorting with AJAX and script....
Iron Speed
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
RUBY-ON-RAILS

Dropping and Sorting with AJAX and script.aculo.us
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2007-11-29

    Table of Contents:
  • Dropping and Sorting with AJAX and script.aculo.us
  • Droppables with Ajax
  • Sortables
  • Ajax-enabled sortables

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Dropping and Sorting with AJAX and script.aculo.us
    (Page 1 of 4 )

    In this conclusion to a three-part series that explains how to use script.aculo.us on Rails, you'll learn dropping and sorting. This article is excerpted from chapter four of Ajax on Rails, written by Scott Raymond (O'Reilly, 2007; ISBN: 0596527446). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

    Droppable options

    hoverclass is a class name that will be added to the droppable when an accepted draggable is hovered over it, indicating to the user that the droppable is active. We’ve already seen a couple examples of this in the previous section.

    accept can be a string or an array of strings with CSS classes. If provided, the droppable will only accept draggables that have one of these CSS classes. For example:

      <div id="dragGreen" class="green box">drag </div>
      <%= draggable_element :dragGreen, :revert => true %>

      <div id="dragPink" class="pink box">drag </div>
      <%= draggable_element :dragPink, :revert => true %>

      <div id="dropAccept" class="pink box">drop here (green only).</div>
      <%= drop_receiving_element :dropAccept, :hoverclass => "hover",
           :accept => 'green' %>

    containmentspecifies that the droppable will only accept the draggable if it’s contained in the given elements or array of elements. It is evaluated as a JavaScript expression, so specifying a DOM element ID requires two sets of quotation marks. For example:

      <div id="one">
         
    <div id="dragGreen2" class="green box">drag</div>
         
    <%= draggable_element :dragGreen2, :revert => true %>
      </div>

      <div id="two">
          <div id="dragPink2" class="pink box">drag</div>
          <%= draggable_element :dragPink2, :revert => true %>
     
    </div>

      <div id="dropContainment" class="pink box">drop here.</div>
      <%= drop_receiving_element :dropContainment, :hoverclass => "hover",
         :containment => "'one'" %>

    onHoveris a callback function that fires whenever a draggable is moved over the droppable, and the droppable accepts it. The callback gets three parameters: the draggable, the droppable, and the percentage of overlapping as defined by the overlap option. A simple example, without any parameters:

      <div id="dropOnHover" class="pink box">drop</div>
      <%= drop_receiving_element :dropOnHover, :hoverclass => "hover",
           
    :onHover => "function(){  $('dropOnHover').update('hover!'); }" %>

    And here is an example using all three possible callback parameters:

      <div id="dropOnHover" class="pink box">drop</div>
      <%= drop_receiving_element :dropOnHover, :hoverclass => "hover",
            :onHover => "function(draggable, droppable, overlap){
              
    $('dropOnHover').update('you dragged ' + draggable.id +
                    ' over ' + droppable.id + ' by ' + overlap +
                    ' percent'); }" %>

    onDrop is called whenever a draggable is released over the droppable and it’s accepted. The callback gets two parameters: the draggable element and the droppable element. For example:

      <div id="dropOnDrop" class="pink box">drop</div>
      <%= drop_receiving_element :dropOnDrop, :hoverclass => "hover",
          :onDrop => "function(drag, drop){
             alert('you dropped ' + drag.id + ' on ' + drop.id) }" %>

    More Ruby-on-Rails Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Ajax on Rails," published by O'Reilly. We...
     

    Buy this book now. This article is excerpted from chapter four of the book Ajax on Rails, written by Scott Raymond (O'Reilly, 2007; ISBN: 0596527446). Check it out today at your favorite bookstore. Buy this book now.

    RUBY-ON-RAILS ARTICLES

    - Ruby On Rails: Making Your First Dynamic Site
    - Ruby on Rails: Beginning Rails
    - Ruby: Modules, Mixins, Fixins, and Rails
    - Controlling Information Access with the Rail...
    - URLs, Filters and the Rails Action Controller
    - Flash and the Rails Action Controller
    - Rails Action Controller
    - Dropping and Sorting with AJAX and script.ac...
    - Drag and Drop with script.aculo.us and Rails
    - Introducing script.aculo.us
    - Ruby Classes and Objects
    - Ruby Loops
    - Ruby Conditionals
    - Ruby Operators and Arrays
    - Ruby for the Newbie


     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway