Module: BivouacHelpers::ScriptAculoUsView
- Defined in:
- lib/bivouac/helpers/view/goh/scriptaculous.rb
Constant Summary collapse
- TOGGLE_EFFECTS =
[:toggle_appear, :toggle_slide, :toggle_blind]
Instance Method Summary collapse
-
#draggable_element(element_id, options = {}) ⇒ Object
Makes the element with the DOM ID specified by
element_iddraggable. -
#draggable_element_js(element_id, options = {}) ⇒ Object
:nodoc:.
-
#drop_receiving_element(element_id, options = {}) ⇒ Object
Makes the element with the DOM ID specified by
element_idreceive dropped draggable elements (created by draggable_element). -
#drop_receiving_element_js(element_id, options = {}) ⇒ Object
:nodoc:.
-
#sortable_element(element_id, options = {}) ⇒ Object
Makes the element with the DOM ID specified by
element_idsortable by drag-and-drop and make an Ajax call whenever the sort order has changed. -
#sortable_element_js(element_id, options = {}) ⇒ Object
:nodoc:.
-
#unsortable_element_js(element_id) ⇒ Object
:nodoc:.
-
#visual_effect(name, element_id = false, js_options = {}) ⇒ Object
Returns a JavaScript snippet to be used on the Ajax callbacks for starting visual effects.
Instance Method Details
#draggable_element(element_id, options = {}) ⇒ Object
Makes the element with the DOM ID specified by element_id draggable.
Example:
draggable_element("my_image", :revert => true)
You can change the behaviour with various options, see script.aculo.us for more documentation.
94 95 96 |
# File 'lib/bivouac/helpers/view/goh/scriptaculous.rb', line 94 def draggable_element(element_id, = {}) javascript_tag(draggable_element_js(element_id, ) + ";\n") end |
#draggable_element_js(element_id, options = {}) ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/bivouac/helpers/view/goh/scriptaculous.rb', line 98 def draggable_element_js(element_id, = {}) #:nodoc: %(new Draggable(#{element_id.inspect}, #{()})) end |
#drop_receiving_element(element_id, options = {}) ⇒ Object
Makes the element with the DOM ID specified by element_id receive dropped draggable elements (created by draggable_element). and make an AJAX call. By default, the action called gets the DOM ID of the element as parameter.
Example:
drop_receiving_element("my_cart", :onDrop => {
:url => R(CartAdd),
:update => 'drop-info'
} )
You can change the behaviour with various options, see script.aculo.us for more documentation.
115 116 117 |
# File 'lib/bivouac/helpers/view/goh/scriptaculous.rb', line 115 def drop_receiving_element(element_id, = {}) javascript_tag(drop_receiving_element_js(element_id, ) + ";\n") end |
#drop_receiving_element_js(element_id, options = {}) ⇒ Object
:nodoc:
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/bivouac/helpers/view/goh/scriptaculous.rb', line 119 def drop_receiving_element_js(element_id, = {}) #:nodoc: if [:onDrop].is_a?( Hash) [:onDrop][:with] = "'id=' + encodeURIComponent(element.id)" [:onDrop] = "function(element){" + remote_function([:onDrop]) + "}" elsif [:onDrop].is_a?( String ) [:onDrop] = "function(){" + [:onDrop] + ";}" end [:accept] = array_or_string_for_javascript([:accept]) if [:accept] [:hoverclass] = "'#{[:hoverclass]}'" if [:hoverclass] %(Droppables.add(#{element_id.inspect}, #{()})) end |
#sortable_element(element_id, options = {}) ⇒ Object
Makes the element with the DOM ID specified by element_id sortable by drag-and-drop and make an Ajax call whenever the sort order has changed. By default, the action called gets the serialized sortable element as parameters.
See script.aculo.us for avalaible options.
If you wan’t to use onChange and/or onUpdate you can pass a javascript string or a Hash, if you want to call a remote function.
Example:
ul( :id => 'my_list' ) do
li "Google"
li "Yahoo"
li "Accoona"
li "Ask.com"
li "Baidu"
li "Exalead"
li "Voila"
li "Lycos"
end
sortable_element( 'my_list',
:onChange => {
:url => R(SaveListOrder),
:success => visual_effect( :highlight, 'my_list' )
}
)
54 55 56 |
# File 'lib/bivouac/helpers/view/goh/scriptaculous.rb', line 54 def sortable_element( element_id, = {} ) javascript_tag( sortable_element_js( element_id, ) + ";\n" ) end |
#sortable_element_js(element_id, options = {}) ⇒ Object
:nodoc:
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bivouac/helpers/view/goh/scriptaculous.rb', line 58 def sortable_element_js( element_id, = {} ) #:nodoc: if [:onUpdate].is_a?( Hash ) [:onUpdate][:with] ||= "Sortable.serialize('#{element_id}')" [:onUpdate] = "function(){" + remote_function([:onUpdate]) + "}" elsif [:onUpdate].is_a?( String ) [:onUpdate] = "function(){" + [:onUpdate] + ";}" end if [:onChange].is_a?( Hash ) [:onChange][:with] ||= "Sortable.serialize('#{element_id}')" [:onChange] = "function(){" + remote_function([:onChange]) + "}" elsif [:onChange].is_a?( String ) [:onChange] = "function(){" + [:onChange] + ";}" end [:tag, :overlap, :constraint, :handle].each do |option| [option] = "'#{[option]}'" if [option] end [:containment] = array_or_string_for_javascript([:containment]) if [:containment] [:only] = array_or_string_for_javascript([:only]) if [:only] %(Sortable.create(#{element_id.inspect}, #{()})) end |
#unsortable_element_js(element_id) ⇒ Object
:nodoc:
83 84 85 |
# File 'lib/bivouac/helpers/view/goh/scriptaculous.rb', line 83 def unsortable_element_js( element_id ) #:nodoc: %(Sortable.destroy(#{element_id.inspect})) end |
#visual_effect(name, element_id = false, js_options = {}) ⇒ Object
Returns a JavaScript snippet to be used on the Ajax callbacks for starting visual effects.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bivouac/helpers/view/goh/scriptaculous.rb', line 11 def visual_effect(name, element_id = false, = {}) element = element_id ? element_id : "element" [:queue] = if [:queue].is_a?(Hash) '{' + [:queue].map {|k, v| k == :limit ? "#{k}:#{v}" : "#{k}:'#{v}'" }.join(',') + '}' elsif [:queue] "'#{[:queue]}'" end if [:queue] if TOGGLE_EFFECTS.include? name.to_sym %(Effect.toggle(#{element.inspect},'#{name.to_s.gsub(/^toggle_/,'')}',#{()})) else %(new Effect.#{name.to_s.camelize}('#{element}',#{()})) end end |