1 | /* |
---|
2 | --- |
---|
3 | description: MooTools wrapper to embed QuickTime movies. |
---|
4 | |
---|
5 | license: MIT-style |
---|
6 | |
---|
7 | authors: |
---|
8 | - Jose Prado |
---|
9 | |
---|
10 | requires: |
---|
11 | core/1.2.4: [Browser, Class.Extras, Array, Hash, Element, Element.Event] |
---|
12 | |
---|
13 | provides: |
---|
14 | Quickie |
---|
15 | Browser.Plugins.QuickTime |
---|
16 | |
---|
17 | ... |
---|
18 | */ |
---|
19 | (function() { |
---|
20 | var qtEvents = ['begin', 'loadedmetadata', 'loadedfirstframe', 'canplay', 'canplaythrough', |
---|
21 | 'durationchange', 'load', 'ended', 'error', 'pause', 'play', 'progress', 'waiting', 'stalled', |
---|
22 | 'timechanged', 'volumechange']; |
---|
23 | |
---|
24 | Quickie = new Class({ |
---|
25 | |
---|
26 | Implements: [Options, Events], |
---|
27 | version: '2.1', |
---|
28 | options: {/* |
---|
29 | onPlay: $empty, |
---|
30 | onStop: $empty,*/ |
---|
31 | id: null, |
---|
32 | height: 1, |
---|
33 | width: 1, |
---|
34 | container: null, |
---|
35 | attributes: { |
---|
36 | controller: "true", |
---|
37 | postdomevents: "true" |
---|
38 | } |
---|
39 | }, |
---|
40 | |
---|
41 | initialize: function(path, options){ |
---|
42 | this.setOptions(options); |
---|
43 | options = this.options; |
---|
44 | this.id = this.options.id || 'Quickie_' + $time(); |
---|
45 | this.path = path; |
---|
46 | var container = options.container; |
---|
47 | |
---|
48 | // Extra attributes |
---|
49 | options.attributes = $H(options.attributes); |
---|
50 | options.attributes.src = path; |
---|
51 | |
---|
52 | // Get Browser appropriate HTML code |
---|
53 | this.html = this.toHTML(); |
---|
54 | |
---|
55 | if (Browser.Engine.trident) { |
---|
56 | document.getElementById(container).innerHTML = this.html; |
---|
57 | this.quickie = document.getElementById(this.id); |
---|
58 | this.ieFix.delay(10, this); |
---|
59 | } else { |
---|
60 | var wrapper = document.createElement('div'); |
---|
61 | wrapper.innerHTML = this.html; |
---|
62 | this.quickie = wrapper.firstChild; |
---|
63 | this.transferEvents(); |
---|
64 | document.id(container).empty(); |
---|
65 | document.getElementById(container).appendChild(this.quickie); |
---|
66 | } |
---|
67 | }, |
---|
68 | |
---|
69 | toHTML: function() { |
---|
70 | if (!this.html) { |
---|
71 | var attributes = this.options.attributes, |
---|
72 | height = (attributes.controller == "true") ? this.options.height + 16 : this.options.height, |
---|
73 | width = this.options.width, |
---|
74 | element = ''; |
---|
75 | |
---|
76 | if (Browser.Engine.trident) { |
---|
77 | element = '<object id="'+this.id+'" '; |
---|
78 | element += 'width="'+width+'" '; |
---|
79 | element += 'height="'+height+'" '; |
---|
80 | element += 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '; |
---|
81 | element += 'style="behavior:url(#qt_event_source);" '; |
---|
82 | element += 'codebase="http://www.apple.com/qtactivex/qtplugin.cab">'; |
---|
83 | |
---|
84 | attributes.each(function(value, key) { |
---|
85 | element += '<param name="'+key+'" value="'+value+'" />'; |
---|
86 | }); |
---|
87 | |
---|
88 | element += '</object>'; |
---|
89 | } else { |
---|
90 | element = '<embed id="'+this.id+'" '; |
---|
91 | element += 'width="'+width+'" '; |
---|
92 | element += 'height="'+height+'" '; |
---|
93 | element += 'pluginspage="http://www.apple.com/quicktime/download/" '; |
---|
94 | |
---|
95 | attributes.each(function(value, key) { |
---|
96 | element += key+'="'+value+'" '; |
---|
97 | }); |
---|
98 | |
---|
99 | element += '/>'; |
---|
100 | } |
---|
101 | this.html = element; |
---|
102 | } |
---|
103 | return this.html; |
---|
104 | }, |
---|
105 | |
---|
106 | ieFix: function() { |
---|
107 | document.getElementById(this.id).SetResetPropertiesOnReload(false); |
---|
108 | document.getElementById(this.id).SetURL(this.path); |
---|
109 | this.transferEvents.delay(10, this); |
---|
110 | }, |
---|
111 | |
---|
112 | transferEvents: function() { |
---|
113 | var element = this.quickie; |
---|
114 | |
---|
115 | qtEvents.each(function(evType) { |
---|
116 | addQTEvent(element, evType, this.fireEvent.pass(evType, this)); |
---|
117 | }.bind(this)); |
---|
118 | } |
---|
119 | |
---|
120 | }); |
---|
121 | |
---|
122 | function addQTEvent(el, evType, fn, useCapture) { |
---|
123 | evType = 'qt_' + evType; |
---|
124 | if (el.addEventListener) { |
---|
125 | el.addEventListener(evType, fn, useCapture); |
---|
126 | return true; |
---|
127 | } else if (el.attachEvent) { |
---|
128 | var r = el.attachEvent('on' + evType, fn); |
---|
129 | return r; |
---|
130 | } else { |
---|
131 | el[evType] = fn; |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | })(); |
---|
136 | |
---|
137 | Browser.Plugins.QuickTime = (function(){ |
---|
138 | if (navigator.plugins) { |
---|
139 | for (var i = 0, l = navigator.plugins.length; i < l; i++) { |
---|
140 | if (navigator.plugins[i].name.indexOf('QuickTime') >= 0) { |
---|
141 | return true; |
---|
142 | } |
---|
143 | } |
---|
144 | } else { |
---|
145 | try { var test = new ActiveXObject('QuickTime.QuickTime'); } |
---|
146 | catch(e) {} |
---|
147 | |
---|
148 | if (test) { return true; } |
---|
149 | } |
---|
150 | return false; |
---|
151 | })(); |
---|