Changeset 8110
- Timestamp:
- 11/07/07 15:37:06 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/asset_tag_helper.rb (modified) (4 diffs)
- trunk/actionpack/test/template/asset_tag_helper_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8108 r8110 1 1 *SVN* 2 3 * Added :mouseover short-cut to AssetTagHelper#image_tag for doing easy image swaps #6893 [joost] 2 4 3 5 * Fixed handling of non-domain hosts #9479 [purp] trunk/actionpack/lib/action_view/helpers/asset_tag_helper.rb
r8052 r8110 336 336 # ==== Options 337 337 # You can add HTML attributes using the +options+. The +options+ supports 338 # t woadditional keys for convienence and conformance:338 # three additional keys for convienence and conformance: 339 339 # 340 340 # * <tt>:alt</tt> - If no alt text is given, the file name part of the … … 343 343 # width="30" and height="45". <tt>:size</tt> will be ignored if the 344 344 # value is not in the correct format. 345 # * <tt>:mouseover</tt> - Set an alternate image to be used when the onmouseover 346 # event is fired, and sets the original image to be replaced onmouseout. 347 # This can be used to implement an easy image toggle that fires on onmouseover. 345 348 # 346 349 # ==== Examples … … 357 360 # image_tag("/icons/icon.gif", :class => "menu_icon") # => 358 361 # <img alt="Icon" class="menu_icon" src="/icons/icon.gif" /> 362 # image_tag("mouse.png", :mouseover => "/images/mouse_over.png") # => 363 # <img src="/images/mouse.png" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" alt="Mouse" /> 364 # image_tag("mouse.png", :mouseover => image_path("mouse_over.png")) # => 365 # <img src="/images/mouse.png" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" alt="Mouse" /> 359 366 def image_tag(source, options = {}) 360 367 options.symbolize_keys! … … 363 370 options[:alt] ||= File.basename(options[:src], '.*').split('.').first.capitalize 364 371 365 if options[:size] 366 options[:width], options[:height] = options[:size].split("x") if options[:size] =~ %r{^\d+x\d+$} 367 options.delete(:size) 372 if size = options.delete(:size) 373 options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$} 374 end 375 376 if mouseover = options.delete(:mouseover) 377 options[:onmouseover] = "this.src='#{image_path(mouseover)}'" 378 options[:onmouseout] = "this.src='#{image_path(options[:src])}'" 368 379 end 369 380 trunk/actionpack/test/template/asset_tag_helper_test.rb
r7976 r8110 136 136 %(image_tag("error.png", "size" => "45 x 70")) => %(<img alt="Error" src="/images/error.png" />), 137 137 %(image_tag("error.png", "size" => "x")) => %(<img alt="Error" src="/images/error.png" />), 138 %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />) 138 %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />), 139 %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />), 140 %(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />), 141 %(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />) 139 142 } 140 143