app/models/swf_fu/generator.rb in swf_fu-2.0.3 vs app/models/swf_fu/generator.rb in swf_fu-2.0.4

- old
+ new

@@ -4,16 +4,16 @@ :height => "100%", :flash_version => 7, :mode => :dynamic, :auto_install => "expressInstall", :alt => <<-"EOS".squeeze(" ").strip.freeze - <a href="http://www.adobe.com/go/getflashplayer"> - <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> + <a href="//www.adobe.com/go/getflashplayer"> + <img src="//www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> </a> EOS }.freeze - + class Generator # :nodoc: VALID_MODES = [:static, :dynamic] def initialize(source, options, view) @view = view @source = view.swf_path(source) @@ -47,11 +47,11 @@ def generate(&block) @options[:alt] = @view.capture(&block) if block_given? send(@mode) end - + private def convert_to_hash(s) case s when Hash s @@ -65,17 +65,17 @@ end else raise ArgumentError, "#{s} should be a Hash, a String or nil" end end - + def convert_to_string(h) h.map do |key_value| key_value.map{|val| CGI::escape(val.to_s)}.join("=") end.join("&") end - + def static param_list = @options[:parameters].map{|k,v| %(<param name="#{k}" value="#{v}"/>) }.join("\n") param_list += %(\n<param name="flashvars" value="#{convert_to_string(@options[:flashvars])}"/>) unless @options[:flashvars].empty? html_options = @options[:html_options].map{|k,v| %(#{k}="#{v}")}.join(" ") r = @view.javascript_tag( @@ -97,21 +97,21 @@ EOS r << @view.javascript_tag(extend_js) if @options[:javascript_class] r << library_check r end - + def dynamic @options[:html_options] = @options[:html_options].merge(:id => @options[:id]) @options[:parameters] = @options[:parameters].dup # don't modify the original parameters args = convert_to_escaped_arguments(@source, *(@options.values_at(:div_id,:width,:height,:flash_version).map(&:to_s) + @options.values_at(:auto_install,:flashvars,:parameters,:html_options)) ) preambule = @options[:switch_off_auto_hide_show] ? "swfobject.switchOffAutoHideShow();" : "" - r = @view.javascript_tag(preambule + "swfobject.embedSWF(#{args})") + r = @view.javascript_tag(preambule + "swfobject.embedSWF(#{args})") r << @view.content_tag("div", @options[:alt].html_safe, :id => @options[:div_id]) r << @view.javascript_tag("swfobject.addDomLoadEvent(function(){#{extend_js}})") if @options[:javascript_class] r << library_check r end @@ -124,16 +124,16 @@ def extend_js args = @options[:initialize] args = [args] unless args.is_a?(Array) "SwfFu.setup($('##{@options[:id]}')[0], #{@options[:javascript_class]}, [#{convert_to_escaped_arguments(*args)}])" end - + def library_check return "" unless 'development' == ENV['RAILS_ENV'] @view.javascript_tag(<<-"EOS") if (typeof swfobject == 'undefined') { document.getElementById('#{@options[:div_id]}').innerHTML = '<strong>Warning:</strong> SWFObject.js was not loaded properly. Make sure you require "swfobject" in your main javascript file.'; } EOS end end #class Generator -end \ No newline at end of file +end