mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Added script.aculo.us drag and drop helpers to RJS [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3667 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
*SVN*
|
||||
|
||||
* Added script.aculo.us drag and drop helpers to RJS [Thomas Fuchs]. Examples:
|
||||
|
||||
page.draggable 'product-1'
|
||||
page.drop_receiving 'wastebasket', :url => { :action => 'delete' }
|
||||
page.sortable 'todolist', :url => { action => 'change_order' }
|
||||
|
||||
* Fixed that form elements would strip the trailing [] from the first parameter #3545 [ruby@bobsilva.com]
|
||||
|
||||
* During controller resolution, update the NameError suppression to check for the expected constant. [Nicholas Seckar]
|
||||
|
||||
@@ -565,12 +565,32 @@ module ActionView
|
||||
record "}, #{(seconds * 1000).to_i})"
|
||||
end
|
||||
|
||||
# Starts a Scriptaculous visual effect. See
|
||||
# Starts a script.aculo.us visual effect. See
|
||||
# ActionView::Helpers::ScriptaculousHelper for more information.
|
||||
def visual_effect(name, id, options = {})
|
||||
record @context.send(:visual_effect, name, id, options)
|
||||
end
|
||||
|
||||
# Creates a script.aculo.us sortable element. Useful
|
||||
# to recreate sortable elements after items get added
|
||||
# or deleted.
|
||||
# See ActionView::Helpers::ScriptaculousHelper for more information.
|
||||
def sortable(id, options = {})
|
||||
record @context.send(:sortable_element_js, id, options)
|
||||
end
|
||||
|
||||
# Creates a script.aculo.us draggable element.
|
||||
# See ActionView::Helpers::ScriptaculousHelper for more information.
|
||||
def draggable(id, options = {})
|
||||
record @context.send(:draggable_element_js, id, options)
|
||||
end
|
||||
|
||||
# Creates a script.aculo.us drop receiving element.
|
||||
# See ActionView::Helpers::ScriptaculousHelper for more information.
|
||||
def drop_receiving(id, options = {})
|
||||
record @context.send(:drop_receiving_element_js, id, options)
|
||||
end
|
||||
|
||||
private
|
||||
def include_helpers_from_context
|
||||
@context.extended_by.each do |mod|
|
||||
|
||||
@@ -67,6 +67,10 @@ module ActionView
|
||||
# You can change the behaviour with various options, see
|
||||
# http://script.aculo.us for more documentation.
|
||||
def sortable_element(element_id, options = {})
|
||||
javascript_tag(sortable_element_js(element_id, options).chop!)
|
||||
end
|
||||
|
||||
def sortable_element_js(element_id, options = {}) #:nodoc:
|
||||
options[:with] ||= "Sortable.serialize('#{element_id}')"
|
||||
options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
|
||||
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
|
||||
@@ -78,7 +82,7 @@ module ActionView
|
||||
options[:containment] = array_or_string_for_javascript(options[:containment]) if options[:containment]
|
||||
options[:only] = array_or_string_for_javascript(options[:only]) if options[:only]
|
||||
|
||||
javascript_tag("Sortable.create('#{element_id}', #{options_for_javascript(options)})")
|
||||
%(Sortable.create('#{element_id}', #{options_for_javascript(options)});)
|
||||
end
|
||||
|
||||
# Makes the element with the DOM ID specified by +element_id+ draggable.
|
||||
@@ -87,9 +91,13 @@ module ActionView
|
||||
# <%= draggable_element("my_image", :revert => true)
|
||||
#
|
||||
# You can change the behaviour with various options, see
|
||||
# http://script.aculo.us for more documentation.
|
||||
# http://script.aculo.us for more documentation.
|
||||
def draggable_element(element_id, options = {})
|
||||
javascript_tag("new Draggable('#{element_id}', #{options_for_javascript(options)})")
|
||||
javascript_tag(draggable_element_js(element_id, options).chop!)
|
||||
end
|
||||
|
||||
def draggable_element_js(element_id, options = {}) #:nodoc:
|
||||
%(new Draggable('#{element_id}', #{options_for_javascript(options)});)
|
||||
end
|
||||
|
||||
# Makes the element with the DOM ID specified by +element_id+ receive
|
||||
@@ -104,14 +112,18 @@ module ActionView
|
||||
# You can change the behaviour with various options, see
|
||||
# http://script.aculo.us for more documentation.
|
||||
def drop_receiving_element(element_id, options = {})
|
||||
javascript_tag(drop_receiving_element_js(element_id, options).chop!)
|
||||
end
|
||||
|
||||
def drop_receiving_element_js(element_id, options = {}) #:nodoc:
|
||||
options[:with] ||= "'id=' + encodeURIComponent(element.id)"
|
||||
options[:onDrop] ||= "function(element){" + remote_function(options) + "}"
|
||||
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
|
||||
|
||||
|
||||
options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
|
||||
options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass]
|
||||
|
||||
javascript_tag("Droppables.add('#{element_id}', #{options_for_javascript(options)})")
|
||||
|
||||
%(Droppables.add('#{element_id}', #{options_for_javascript(options)});)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../abstract_unit'
|
||||
module BaseTest
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::PrototypeHelper
|
||||
include ActionView::Helpers::ScriptaculousHelper
|
||||
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
@@ -255,4 +256,29 @@ Element.update("baz", "<p>This is a test</p>");
|
||||
@generator.select('p.welcome b').first.hide
|
||||
assert_equal %($$('p.welcome b').first().hide();), @generator.to_s
|
||||
end
|
||||
|
||||
def test_visual_effect
|
||||
assert_equal %(new Effect.Puff('blah',{});),
|
||||
@generator.visual_effect(:puff,'blah')
|
||||
end
|
||||
|
||||
def test_visual_effect_toggle
|
||||
assert_equal %(Effect.toggle('blah','appear',{});),
|
||||
@generator.visual_effect(:toggle_appear,'blah')
|
||||
end
|
||||
|
||||
def test_sortable
|
||||
assert_equal %(Sortable.create('blah', {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize('blah')})}});),
|
||||
@generator.sortable('blah', :url => { :action => "order" })
|
||||
end
|
||||
|
||||
def test_draggable
|
||||
assert_equal %(new Draggable('blah', {});),
|
||||
@generator.draggable('blah')
|
||||
end
|
||||
|
||||
def test_drop_receiving
|
||||
assert_equal %(Droppables.add('blah', {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
|
||||
@generator.drop_receiving('blah', :url => { :action => "order" })
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user