mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Update JavaScriptGenerator#show/hide/toggle/remove to new Prototype syntax for multiple ids, fixes #6068 [petermichaux@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5057 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
00685ad8fd
commit
8734da9bca
3 changed files with 26 additions and 9 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Update JavaScriptGenerator#show/hide/toggle/remove to new Prototype syntax for multiple ids, #6068 [petermichaux@gmail.com]
|
||||
|
||||
* Update UrlWriter to support :only_path. [Nicholas Seckar, Dave Thomas]
|
||||
|
||||
* Fixed JavaScriptHelper#link_to_function and JavaScriptHelper#button_to_function to have the script argument be optional [DHH]. So what used to require a nil, like this:
|
||||
|
|
|
@ -556,22 +556,22 @@ module ActionView
|
|||
|
||||
# Removes the DOM elements with the given +ids+ from the page.
|
||||
def remove(*ids)
|
||||
record "#{javascript_object_for(ids)}.each(Element.remove)"
|
||||
loop_on_multiple_args 'Element.remove', ids
|
||||
end
|
||||
|
||||
# Shows hidden DOM elements with the given +ids+.
|
||||
def show(*ids)
|
||||
call 'Element.show', *ids
|
||||
loop_on_multiple_args 'Element.show', ids
|
||||
end
|
||||
|
||||
# Hides the visible DOM elements with the given +ids+.
|
||||
def hide(*ids)
|
||||
call 'Element.hide', *ids
|
||||
loop_on_multiple_args 'Element.hide', ids
|
||||
end
|
||||
|
||||
# Toggles the visibility of the DOM elements with the given +ids+.
|
||||
def toggle(*ids)
|
||||
call 'Element.toggle', *ids
|
||||
loop_on_multiple_args 'Element.toggle', ids
|
||||
end
|
||||
|
||||
# Displays an alert dialog with the given +message+.
|
||||
|
@ -684,6 +684,14 @@ module ActionView
|
|||
end
|
||||
|
||||
protected
|
||||
def loop_on_multiple_args(method, ids)
|
||||
record (if ids.size>1
|
||||
"#{javascript_object_for(ids)}.each(#{method})"
|
||||
else
|
||||
"#{method}(#{ids.first.to_json})"
|
||||
end)
|
||||
end
|
||||
|
||||
def options_for_ajax(options)
|
||||
js_options = build_callbacks(options)
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ class JavaScriptGeneratorTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_remove
|
||||
assert_equal '["foo"].each(Element.remove);',
|
||||
assert_equal 'Element.remove("foo");',
|
||||
@generator.remove('foo')
|
||||
assert_equal '["foo", "bar", "baz"].each(Element.remove);',
|
||||
@generator.remove('foo', 'bar', 'baz')
|
||||
|
@ -212,17 +212,24 @@ class JavaScriptGeneratorTest < Test::Unit::TestCase
|
|||
def test_show
|
||||
assert_equal 'Element.show("foo");',
|
||||
@generator.show('foo')
|
||||
assert_equal 'Element.show("foo", "bar", "baz");',
|
||||
@generator.show('foo', 'bar', 'baz')
|
||||
assert_equal '["foo", "bar", "baz"].each(Element.show);',
|
||||
@generator.show('foo', 'bar', 'baz')
|
||||
end
|
||||
|
||||
def test_hide
|
||||
assert_equal 'Element.hide("foo");',
|
||||
@generator.hide('foo')
|
||||
assert_equal 'Element.hide("foo", "bar", "baz");',
|
||||
@generator.hide('foo', 'bar', 'baz')
|
||||
assert_equal '["foo", "bar", "baz"].each(Element.hide);',
|
||||
@generator.hide('foo', 'bar', 'baz')
|
||||
end
|
||||
|
||||
def test_toggle
|
||||
assert_equal 'Element.toggle("foo");',
|
||||
@generator.toggle('foo')
|
||||
assert_equal '["foo", "bar", "baz"].each(Element.toggle);',
|
||||
@generator.toggle('foo', 'bar', 'baz')
|
||||
end
|
||||
|
||||
def test_alert
|
||||
assert_equal 'alert("hello");', @generator.alert('hello')
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue