| 5 | | # Provides a set of helpers for calling Scriptaculous JavaScript |
|---|
| 6 | | # functions, including those which create Ajax controls and visual effects. |
|---|
| 7 | | # |
|---|
| 8 | | # To be able to use these helpers, you must include the Prototype |
|---|
| | 5 | # Scriptaculous[http://script.aculo.us] is a JavaScript library that provides a set of functions |
|---|
| | 6 | # for creating Ajax controls and visual effects. This helper provides a |
|---|
| | 7 | # set of methods for calling these Scriptaculous functions using Ruby code |
|---|
| | 8 | # to generate the JavaScript. |
|---|
| | 9 | # |
|---|
| | 10 | # === Usage |
|---|
| | 11 | # To be able to use these helpers, you must first include the Prototype |
|---|
| 13 | | # The Scriptaculous helpers' behavior can be tweaked with various options. |
|---|
| 14 | | # See the documentation at http://script.aculo.us for more information on |
|---|
| 15 | | # using these helpers in your application. |
|---|
| | 15 | # <%= |
|---|
| | 16 | # javascript_include_tag 'prototype' |
|---|
| | 17 | # javascript_include_tag 'scriptaculous' |
|---|
| | 18 | # %> |
|---|
| | 19 | # |
|---|
| | 20 | # (See the documentation for ActionView::Helpers::JavaScriptHelper |
|---|
| | 21 | # for more information on including this and other JavaScript files) |
|---|
| | 22 | # |
|---|
| | 23 | # Once those are included, you are able to use Ruby to generate Scriptaculous |
|---|
| | 24 | # calls. For example, let's say you wanted to highlight a shopping cart's total |
|---|
| | 25 | # after an item had been added to it over Ajax. You could do something like this: |
|---|
| | 26 | # |
|---|
| | 27 | # <%= |
|---|
| | 28 | # # Generates: <a href="#" onclick="new Ajax.Updater('total', '/testing/add_to_cart', {asynchronous:true, |
|---|
| | 29 | # # evalScripts:true, onComplete:function(request){new Effect.Highlight("total",{duration:0.75});}}); |
|---|
| | 30 | # # return false;">Add to cart</a> |
|---|
| | 31 | # link_to_remote "Add to cart", :update => "total", |
|---|
| | 32 | # :url => { :action => "add_to_cart" }, |
|---|
| | 33 | # :complete => visual_effect(:highlight, "total", :duration => 0.75) |
|---|
| | 34 | # %> |
|---|
| | 35 | # |
|---|
| | 36 | # The visual_effect method allows you to use various visual effects built-in to Scriptaculous |
|---|
| | 37 | # (in this case, a faint, fading highlight); see the visual_effect method's documentation for more information. |
|---|
| | 38 | # |
|---|
| | 39 | # ScriptaculousHelper's behavior can be tweaked using the +js_options+ parameter. |
|---|
| | 40 | # See the documentation at http://script.aculo.us for more information. |
|---|
| 21 | | # Returns a JavaScript snippet to be used on the Ajax callbacks for |
|---|
| 22 | | # starting visual effects. |
|---|
| | 46 | # The Scriptaculous visual effects library has a number of effects built-in, such as changing opacity, highlighting, |
|---|
| | 47 | # pulsating, fading out, and so on (see the documentation[http://wiki.script.aculo.us/scriptaculous/show/VisualEffects] for |
|---|
| | 48 | # the visual effects for more information). The visual_effect method allow you to use these visual effects in Ajax callbacks |
|---|
| | 49 | # by returning a JavaScript snippet to be used as the callback. |
|---|
| 25 | | # <%= link_to_remote "Reload", :update => "posts", |
|---|
| | 52 | # <%= |
|---|
| | 53 | # # Generates: <a href="#" onclick="new Ajax.Updater('posts', '/mycontroller/reload', |
|---|
| | 54 | # # {asynchronous:true, evalScripts:true, onComplete:function(request){new Effect.Highlight("posts", |
|---|
| | 55 | # # {duration:0.5});}}); return false;">Reload</a> |
|---|
| | 56 | # link_to_remote "Reload", :update => "posts", |
|---|
| 38 | | # For toggling visual effects, you can use :toggle_appear, :toggle_slide, and |
|---|
| 39 | | # :toggle_blind which will alternate between appear/fade, slidedown/slideup, and |
|---|
| 40 | | # blinddown/blindup respectively. |
|---|
| | 70 | # For toggling visual effects, you can use <tt>:toggle_appear</tt>, <tt>:toggle_slide</tt>, and |
|---|
| | 71 | # <tt>:toggle_blind</tt> in the +js_options+ parameter which will alternate between appear/fade, slidedown/slideup, and |
|---|
| | 72 | # blinddown/blindup, respectively. |
|---|
| 60 | | # Makes the element with the DOM ID specified by +element_id+ sortable |
|---|
| 61 | | # by drag-and-drop and make an Ajax call whenever the sort order has |
|---|
| 62 | | # changed. By default, the action called gets the serialized sortable |
|---|
| | 92 | # Scriptaculous allows you to make container elements (for example, <ul>) sortable. |
|---|
| | 93 | # The sortable_elements makes the element with the DOM ID specified by +element_id+ sortable |
|---|
| | 94 | # by drag-and-drop; it will also make an Ajax call whenever the sort order has |
|---|
| | 95 | # changed. By default, the action called gets the JSON serialized sortable |
|---|
| 72 | | # Important: For this to work, the sortable elements must have id |
|---|
| 73 | | # attributes in the form "string_identifier". For example, "item_1". Only |
|---|
| 74 | | # the identifier part of the id attribute will be serialized. |
|---|
| | 109 | # <b>Important:</b> For this to work, the sortable elements must have +id+ |
|---|
| | 110 | # attributes in the form "string_identifier" (for example, "item_1"). Only |
|---|
| | 111 | # the identifier part of the +id+ attribute will be serialized. |
|---|
| 113 | | # Makes the element with the DOM ID specified by +element_id+ receive |
|---|
| 114 | | # dropped draggable elements (created by draggable_element). |
|---|
| 115 | | # and make an AJAX call By default, the action called gets the DOM ID |
|---|
| 116 | | # of the element as parameter. |
|---|
| | 153 | # Scriptaculous allows you to easily create interfaces with drag and drop functionality; the |
|---|
| | 154 | # drop_receiving_element method makes the element with the DOM ID specified by +element_id+ receive |
|---|
| | 155 | # dropped draggable elements (created by draggable_element). It will also make an Ajax call when the item |
|---|
| | 156 | # is dropped. By default, the action called gets the DOM ID of the element as parameter. |
|---|
| 119 | | # <%= drop_receiving_element("my_cart", :url => |
|---|
| 120 | | # { :controller => "cart", :action => "add" }) %> |
|---|
| | 159 | # <%= |
|---|
| | 160 | # # Generates: Droppables.add("my_cart", {onDrop:function(element){ |
|---|
| | 161 | # # new Ajax.Request('/cart/add', {asynchronous:true, evalScripts:true, |
|---|
| | 162 | # # parameters:'id=' + encodeURIComponent(element.id)})}}) |
|---|
| | 163 | # drop_receiving_element("my_cart", :url => |
|---|
| | 164 | # { :controller => "cart", :action => "add" }) |
|---|
| | 165 | # %> |
|---|