mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make new AJAX helpers aware of more of their options #1622 [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1729 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
93ec99c246
commit
2186ed83dd
2 changed files with 26 additions and 3 deletions
|
@ -441,6 +441,16 @@ module ActionView
|
||||||
options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
|
options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
|
||||||
options.delete_if { |key, value| AJAX_OPTIONS.include?(key) }
|
options.delete_if { |key, value| AJAX_OPTIONS.include?(key) }
|
||||||
|
|
||||||
|
[:tag, :overlap, :constraint].each do |option|
|
||||||
|
options[option] = "'#{options[option]}'" if options[option]
|
||||||
|
end
|
||||||
|
|
||||||
|
if options[:containment] and options[:containment].kind_of?(Array)
|
||||||
|
options[:containment] = "['#{options[:containment].join('\',\'')}']"
|
||||||
|
elsif options[:containment]
|
||||||
|
options[:containment] = "'#{options[:containment]}'" if options[:containment]
|
||||||
|
end
|
||||||
|
|
||||||
javascript_tag("Sortable.create('#{element_id}', #{options_for_javascript(options)})")
|
javascript_tag("Sortable.create('#{element_id}', #{options_for_javascript(options)})")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -470,7 +480,12 @@ module ActionView
|
||||||
options[:onDrop] ||= "function(element){" + remote_function(options) + "}"
|
options[:onDrop] ||= "function(element){" + remote_function(options) + "}"
|
||||||
options.delete_if { |key, value| AJAX_OPTIONS.include?(key) }
|
options.delete_if { |key, value| AJAX_OPTIONS.include?(key) }
|
||||||
|
|
||||||
|
if options[:accept] and options[:accept].kind_of?(Array)
|
||||||
|
options[:accept] = "['#{options[:accept].join('\',\'')}']"
|
||||||
|
elsif options[:accept]
|
||||||
options[:accept] = "'#{options[:accept]}'" if options[:accept]
|
options[:accept] = "'#{options[:accept]}'" if options[:accept]
|
||||||
|
end
|
||||||
|
|
||||||
options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass]
|
options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass]
|
||||||
|
|
||||||
javascript_tag("Droppables.add('#{element_id}', #{options_for_javascript(options)})")
|
javascript_tag("Droppables.add('#{element_id}', #{options_for_javascript(options)})")
|
||||||
|
|
|
@ -103,6 +103,12 @@ class JavaScriptHelperTest < Test::Unit::TestCase
|
||||||
def test_sortable_element
|
def test_sortable_element
|
||||||
assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>),
|
assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>),
|
||||||
sortable_element("mylist", :url => { :action => "order" })
|
sortable_element("mylist", :url => { :action => "order" })
|
||||||
|
assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {tag:'div', constraint:'horizontal', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>),
|
||||||
|
sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" })
|
||||||
|
assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {constraint:'horizontal', containment:['list1','list2'], onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>),
|
||||||
|
sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" })
|
||||||
|
assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {constraint:'horizontal', containment:'list1', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>),
|
||||||
|
sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" })
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_draggable_element
|
def test_draggable_element
|
||||||
|
@ -115,10 +121,12 @@ class JavaScriptHelperTest < Test::Unit::TestCase
|
||||||
def test_drop_receiving_element
|
def test_drop_receiving_element
|
||||||
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Request('http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
|
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Request('http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
|
||||||
drop_receiving_element('droptarget1')
|
drop_receiving_element('droptarget1')
|
||||||
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Request('http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}, accept:'products'})</script>),
|
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Request('http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
|
||||||
drop_receiving_element('droptarget1', :accept => 'products')
|
drop_receiving_element('droptarget1', :accept => 'products')
|
||||||
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}, accept:'products'})</script>),
|
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
|
||||||
drop_receiving_element('droptarget1', :accept => 'products', :update => 'infobox')
|
drop_receiving_element('droptarget1', :accept => 'products', :update => 'infobox')
|
||||||
|
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
|
||||||
|
drop_receiving_element('droptarget1', :accept => ['tshirts','mugs'], :update => 'infobox')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update_element_function
|
def test_update_element_function
|
||||||
|
|
Loading…
Reference in a new issue