Class: Flowplayer::Player
- Inherits:
-
Object
- Object
- Flowplayer::Player
show all
- Defined in:
- lib/flowplayer/player.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(dom_id, swf, lib = 'jquery', &block) ⇒ Player
Returns a new instance of Player.
5
6
7
8
9
10
11
|
# File 'lib/flowplayer/player.rb', line 5
def initialize(dom_id, swf, lib='jquery', &block)
@dom_id, @swf, @lib = dom_id, swf, lib
@options = {}
@functions = {}
block.call(self)
self
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/flowplayer/player.rb', line 86
def method_missing(method, *args, &block)
raise "Setters are not supported use method('whatever') to set configs" if /\=$/.match(method.to_s)
if block.nil?
options[method] = args.first
else
params = block.parameters.collect {|param| param[1]}
functions[method] = "function(#{params.join(", ")}) { #{block.call.gsub(/\;$/, '')}; }"
end
return method
end
|
Instance Attribute Details
#dom_id ⇒ Object
Returns the value of attribute dom_id.
4
5
6
|
# File 'lib/flowplayer/player.rb', line 4
def dom_id
@dom_id
end
|
#functions ⇒ Object
Returns the value of attribute functions.
4
5
6
|
# File 'lib/flowplayer/player.rb', line 4
def functions
@functions
end
|
#options ⇒ Object
Returns the value of attribute options.
4
5
6
|
# File 'lib/flowplayer/player.rb', line 4
def options
@options
end
|
#swf ⇒ Object
Returns the value of attribute swf.
4
5
6
|
# File 'lib/flowplayer/player.rb', line 4
def swf
@swf
end
|
Instance Method Details
#jquery(func) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/flowplayer/player.rb', line 39
def jquery(func)
<<-EOS
$(document).ready(function() {
#{func}
});
EOS
end
|
#library(func) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/flowplayer/player.rb', line 30
def library(func)
case @lib
when 'jquery'
jquery(func)
when 'prototype'
prototype(func)
end
end
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/flowplayer/player.rb', line 55
def only_play_button!(opts = {})
options[:plugins] ||= {}
options[:plugins][:controls] ||= {}
hash = {
:mute => false,
:slowForward => false,
:time => false,
:slowBackwards => false,
:volume => false,
:scrubber => false,
:stop => false,
:fullscreen => false,
:play => true
}
hash.merge!(opts)
options[:plugins][:controls].merge!(hash)
end
|
#prototype(func) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/flowplayer/player.rb', line 47
def prototype(func)
<<-EOS
document.observe("dom:loaded", function() {
#{func}
});
EOS
end
|
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/flowplayer/player.rb', line 19
def script_tags
final = library("flowplayer(\"#{dom_id}\", #{swf.to_json}, #{to_js});")
<<-EOS
<script type='text/javascript'>
//<![CDATA[
#{final}
//]]>
</script>
EOS
end
|
#to_js ⇒ Object
13
14
15
16
17
|
# File 'lib/flowplayer/player.rb', line 13
def to_js
json = options_to_javascript
json += functions_to_javascript
"{#{json.join(', ')}}"
end
|