Created
April 20, 2009 22:39
-
-
Save dwg/98816 to your computer and use it in GitHub Desktop.
Helper to embed flash content in a standards compliant, cross browser fashion. Uses the nested objects method (http://alistapart.com/articles/flashembedcagematch).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module FlashHelper | |
| def embed_flash swf, options={}, &block | |
| outer_options = options.slice(:id, :width, :height).merge(:classid=>'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000') | |
| inner_options = options.slice(:width, :height).merge(:type=>'application/x-shockwave-flash', :data=>swf) | |
| params = options[:params] && options[:params].map {|name, value| tag(:param, :name=>name, :value=>value)}.join || '' | |
| if block_given? | |
| embed_flash_with_block swf, outer_options, inner_options, params, &block | |
| else | |
| embed_flash_without_block swf, outer_options, inner_options, params | |
| end | |
| end | |
| private | |
| def embed_flash_with_block swf, outer_options, inner_options, params, &block | |
| markup = content_tag(:object, outer_options) do | |
| tag(:param, :name=>'movie', :value=>swf) + | |
| params + | |
| '<!--[if !IE]>-->' + | |
| content_tag(:object, inner_options) do | |
| params + | |
| '<!--<![endif]-->' + | |
| capture(&block) + | |
| '<!--[if !IE]>-->' | |
| end + | |
| '<!--<![endif]-->' | |
| end | |
| concat markup, block.binding | |
| end | |
| def embed_flash_without_block swf, outer_options, inner_options, params | |
| content_tag(:object, outer_options) do | |
| tag(:param, :name=>'movie', :value=>swf) + | |
| params + | |
| '<!--[if !IE]>-->' + | |
| content_tag(:object, params, inner_options) + | |
| '<!--<![endif]-->' | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment