added jquery and prototype support

This commit is contained in:
Scott Davis 2011-02-01 17:58:56 -05:00
parent 8396c51976
commit c8a551b552
5 changed files with 49 additions and 11 deletions

Binary file not shown.

View File

@ -2,8 +2,8 @@ require 'json'
module Flowplayer
class Player
attr_accessor :options, :functions, :dom_id, :swf
def initialize(dom_id, swf, &block)
@dom_id, @swf = dom_id, swf
def initialize(dom_id, swf, lib='jquery', &block)
@dom_id, @swf, @lib = dom_id, swf, lib
@options = {}
@functions = {}
block.call(self)
@ -17,15 +17,41 @@ module Flowplayer
end
def script_tags
final = library("flowplayer(\"#{dom_id}\", \"#{swf}\", #{to_js});")
<<-EOS
<script type='text/javascript'>
//<![CDATA[
flowplayer("#{dom_id}", "#{swf}", #{to_js});
#{final}
//]]>
</script>
EOS
end
def library(func)
case @lib
when 'jquery'
jquery(func)
when 'prototype'
prototype(func)
end
end
def jquery(func)
<<-EOS
$(document).ready(function() {
#{func}
});
EOS
end
def prototype(func)
<<-EOS
document.observe("dom:loaded", function() {
#{func}
});
EOS
end
private
def functions_to_javascript
@ -34,11 +60,7 @@ module Flowplayer
def options_to_javascript
options.map do |option, value|
if value.is_a?(String)
"\"#{option}\":\"#{value.to_json}\""
else
"\"#{option}\":#{value.to_json}"
end
"\"#{option}\":#{value.to_json}"
end
end

View File

@ -6,8 +6,9 @@ module Flowplayer
require File.join(File.expand_path('../', __FILE__), 'railties', 'generator', 'install_generator.rb')
end
initializer "flowplayer.configure_rails_initialization" do
#ApplicationHelper.send(:include, Flowplayer::Helper)
ApplicationController.instance_eval { helper Flowplayer::Helper }
ActionController::Base.instance_eval do
helper Flowplayer::Helper
end
end
end
end

View File

@ -6,7 +6,7 @@ module Flowplayer
argument :install_type, :type => :string, :banner => "commercial", :required => false, :default => ''
def install_flowplayer
copy_file 'flowplayer-3.2.4.min.js', Rails.root.join('public', 'javascript', 'flowplayer.min.js')
copy_file 'flowplayer-3.2.4.min.js', Rails.root.join('public', 'javascripts', 'flowplayer.min.js')
end
def install_swfs

View File

@ -58,4 +58,19 @@ describe Flowplayer::Player do
end.should raise_error
end
it "should support jquery" do
flow_player = Flowplayer::Player.new('my_video', 'commericial.swf') do |player|
player.fullscreen true
player.logo(:url => nil, :opacity => 0, :fullscreenOnly => true)
end
flow_player.should include('$(document).ready(function(){')
end
it "should support prototype" do
flow_player = Flowplayer::Player.new('my_video', 'commericial.swf', 'prototype') do |player|
player.fullscreen true
player.logo(:url => nil, :opacity => 0, :fullscreenOnly => true)
end
flow_player.should include('document.observe(function(){')
end
end