added jquery and prototype support
This commit is contained in:
parent
8396c51976
commit
c8a551b552
BIN
assets/flowplayer-3.2.4.min.js
vendored
BIN
assets/flowplayer-3.2.4.min.js
vendored
Binary file not shown.
@ -2,8 +2,8 @@ require 'json'
|
|||||||
module Flowplayer
|
module Flowplayer
|
||||||
class Player
|
class Player
|
||||||
attr_accessor :options, :functions, :dom_id, :swf
|
attr_accessor :options, :functions, :dom_id, :swf
|
||||||
def initialize(dom_id, swf, &block)
|
def initialize(dom_id, swf, lib='jquery', &block)
|
||||||
@dom_id, @swf = dom_id, swf
|
@dom_id, @swf, @lib = dom_id, swf, lib
|
||||||
@options = {}
|
@options = {}
|
||||||
@functions = {}
|
@functions = {}
|
||||||
block.call(self)
|
block.call(self)
|
||||||
@ -17,15 +17,41 @@ module Flowplayer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def script_tags
|
def script_tags
|
||||||
|
final = library("flowplayer(\"#{dom_id}\", \"#{swf}\", #{to_js});")
|
||||||
<<-EOS
|
<<-EOS
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
flowplayer("#{dom_id}", "#{swf}", #{to_js});
|
#{final}
|
||||||
//]]>
|
//]]>
|
||||||
</script>
|
</script>
|
||||||
EOS
|
EOS
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def functions_to_javascript
|
def functions_to_javascript
|
||||||
@ -34,11 +60,7 @@ module Flowplayer
|
|||||||
|
|
||||||
def options_to_javascript
|
def options_to_javascript
|
||||||
options.map do |option, value|
|
options.map do |option, value|
|
||||||
if value.is_a?(String)
|
"\"#{option}\":#{value.to_json}"
|
||||||
"\"#{option}\":\"#{value.to_json}\""
|
|
||||||
else
|
|
||||||
"\"#{option}\":#{value.to_json}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,8 +6,9 @@ module Flowplayer
|
|||||||
require File.join(File.expand_path('../', __FILE__), 'railties', 'generator', 'install_generator.rb')
|
require File.join(File.expand_path('../', __FILE__), 'railties', 'generator', 'install_generator.rb')
|
||||||
end
|
end
|
||||||
initializer "flowplayer.configure_rails_initialization" do
|
initializer "flowplayer.configure_rails_initialization" do
|
||||||
#ApplicationHelper.send(:include, Flowplayer::Helper)
|
ActionController::Base.instance_eval do
|
||||||
ApplicationController.instance_eval { helper Flowplayer::Helper }
|
helper Flowplayer::Helper
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -6,7 +6,7 @@ module Flowplayer
|
|||||||
argument :install_type, :type => :string, :banner => "commercial", :required => false, :default => ''
|
argument :install_type, :type => :string, :banner => "commercial", :required => false, :default => ''
|
||||||
|
|
||||||
def install_flowplayer
|
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
|
end
|
||||||
|
|
||||||
def install_swfs
|
def install_swfs
|
||||||
|
@ -58,4 +58,19 @@ describe Flowplayer::Player do
|
|||||||
end.should raise_error
|
end.should raise_error
|
||||||
end
|
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
|
end
|
Loading…
Reference in New Issue
Block a user