| Module | ActionView::Helpers::SwfObjectHelper::InstanceMethods |
| In: |
lib/swfobject_view_helper.rb
|
Returns a path to a Flash object. The src can be supplied as:
All of the above are expanded to "/assets/applet.swf"
# File lib/swfobject_view_helper.rb, line 19 def swfobject_path(source) compute_public_path(source, 'assets', 'swf') rescue NoMethodError # Rails 2.2 is missing compute_public_path. It's present in # Rails 2.1 and Rails 2.3. The right thing to do is to # conditionally define SwfObjectTag < AssetTag for Rails # 2.2, and return SwfObjectTag.new(self, ???, # source).public_path. Do this instead. javascript_path(source.sub(/\/assets/, '/javascripts')). sub(/\/javascripts/, '/assets'). sub(/\.js$/, '.swf'). sub(/\.swf\.swf$/, 'swf') end
Returns a set of tags that display a Flash object within an HTML page.
Options:
The following options are for developers. They default to true in development mode, and false otherwise.
# File lib/swfobject_view_helper.rb, line 49 def swfobject_tag(source, options={}) path = swfobject_path(source) verify_file_exists = options.fetch(:verify_file_exists, ENV['RAILS_ENV'] == 'development') if verify_file_exists and not File.exists?(File.join(RAILS_ROOT, 'public', path).sub(/\?\d+/, '')) return "<div><strong>Warning:</strong> The file <code>#{File.join('public', path)}</code> does not exist. Execute <tt>rake openlaszlo:build:applets</tt> to create it.</div>" end id = options[:id] || File.basename(source, '.swf') width = options[:width] || '100%' height = options[:height] || '100%' background_color = options[:background_color] || '#ffffff' flash_version = options[:flash_version] || '8,0,24,0' express_install_url = '/expressInstall.swf' variables = options.fetch(:variables, {:lzproxied => false}) parameters = options.fetch(:parameters, {:scale => 'noscale'}) fallback_html = options[:fallback_html] || %q{<p>Requires the Flash plugin. If the plugin is already installed, click <a href="?detectflash=false">here</a>.</p>} if options.fetch(:check_for_javascript_include, ENV['RAILS_ENV'] == 'development') check_for_javascript = "if (typeof swfobject == 'undefined') document.getElementById('\#{id}').innerHTML = '<strong>Warning:</strong> <code>swfobject</code> is undefined. Did you forget to include <code><%= javascript_include_tag :defaults %></code> in your view file?';\n" end return("<div id=\"\#{id}\">\n\#{fallback_html}\n</div>\n<script type=\"text/javascript\">//<![CDATA[\n\#{check_for_javascript}\nswfobject.embedSWF(\"\#{path}\", \"\#{id}\", \"\#{width}\", \"\#{height}\", \"\#{flash_version}\", \#{express_install_url.to_json}, \#{variables.to_json}, \#{parameters.to_json});\n//]]>\n</script>\n") end