aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-11-07 15:37:06 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-11-07 15:37:06 +0000
commit6b018e3d08c52417034cd648952668192327a9b7 (patch)
tree2729387895e1244606cd62c6075339ae3a2ddd82 /actionpack/lib/action_view/helpers
parent37adea6ff1fba85c29406bbe2af4831f4c6beeec (diff)
downloadrails-6b018e3d08c52417034cd648952668192327a9b7.tar.gz
rails-6b018e3d08c52417034cd648952668192327a9b7.tar.bz2
rails-6b018e3d08c52417034cd648952668192327a9b7.zip
Added :mouseover short-cut to AssetTagHelper#image_tag for doing easy image swaps (closes #6893) [joost]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8110 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index f0229980b0..47bbe2f995 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -335,13 +335,16 @@ module ActionView
#
# ==== Options
# You can add HTML attributes using the +options+. The +options+ supports
- # two additional keys for convienence and conformance:
+ # three additional keys for convienence and conformance:
#
# * <tt>:alt</tt> - If no alt text is given, the file name part of the
# +source+ is used (capitalized and without the extension)
# * <tt>:size</tt> - Supplied as "{Width}x{Height}", so "30x45" becomes
# width="30" and height="45". <tt>:size</tt> will be ignored if the
# value is not in the correct format.
+ # * <tt>:mouseover</tt> - Set an alternate image to be used when the onmouseover
+ # event is fired, and sets the original image to be replaced onmouseout.
+ # This can be used to implement an easy image toggle that fires on onmouseover.
#
# ==== Examples
# image_tag("icon") # =>
@@ -356,15 +359,23 @@ module ActionView
# <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
# image_tag("/icons/icon.gif", :class => "menu_icon") # =>
# <img alt="Icon" class="menu_icon" src="/icons/icon.gif" />
+ # image_tag("mouse.png", :mouseover => "/images/mouse_over.png") # =>
+ # <img src="/images/mouse.png" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" alt="Mouse" />
+ # image_tag("mouse.png", :mouseover => image_path("mouse_over.png")) # =>
+ # <img src="/images/mouse.png" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" alt="Mouse" />
def image_tag(source, options = {})
options.symbolize_keys!
options[:src] = path_to_image(source)
options[:alt] ||= File.basename(options[:src], '.*').split('.').first.capitalize
- if options[:size]
- options[:width], options[:height] = options[:size].split("x") if options[:size] =~ %r{^\d+x\d+$}
- options.delete(:size)
+ if size = options.delete(:size)
+ options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
+ end
+
+ if mouseover = options.delete(:mouseover)
+ options[:onmouseover] = "this.src='#{image_path(mouseover)}'"
+ options[:onmouseout] = "this.src='#{image_path(options[:src])}'"
end
tag("img", options)