]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/av/_base/quicktime.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / av / _base / quicktime.js
1 if(!dojo._hasResource["dojox.av._base.quicktime"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.av._base.quicktime"] = true;
3 dojo.provide("dojox.av._base.quicktime");
4
5 (function(){
6         /*******************************************************
7                 dojox.av.quicktime
8
9                 Base functionality to insert a QuickTime movie
10                 into a document on the fly.
11          ******************************************************/
12
13         var qtMarkup, qtVersion, installed, __def__={
14                 width: 320,
15                 height: 240,
16                 redirect: null,
17                 params: []
18         };
19         var keyBase="dojox-av-quicktime-", keyCount=0;
20
21         //      reference to the test movie we will use for getting QT info from the browser.
22         var testMovieUrl=dojo.moduleUrl("dojox", "av/resources/version.mov");
23
24         //      *** private methods *********************************************************
25         function prep(kwArgs){
26                 kwArgs = dojo.mixin(dojo.clone(__def__), kwArgs || {});
27                 if(!("path" in kwArgs)){
28                         console.error("dojox.av._base.quicktime(ctor):: no path reference to a QuickTime movie was provided.");
29                         return null;
30                 }
31                 if(!("id" in kwArgs)){
32                         kwArgs.id=(keyBase + keyCount++);
33                 }
34                 return kwArgs;
35         }
36         
37         var getQTMarkup = 'This content requires the <a href="http://www.apple.com/quicktime/download/" title="Download and install QuickTime.">QuickTime plugin</a>.';
38         if(dojo.isIE){
39                 installed = (function(){
40                         try{
41                                 var o = new ActiveXObject("QuickTimeCheckObject.QuickTimeCheck.1");
42                                 if(o!==undefined){
43                                         return o.IsQuickTimeAvailable(0);
44                                 }
45                         } catch(e){ }
46                         return false;
47                 })();
48
49                 qtMarkup = function(kwArgs){
50                         if(!installed){ return { id: null, markup: getQTMarkup }; }
51                         
52                         kwArgs = prep(kwArgs);
53                         if(!kwArgs){ return null; }
54                         var s = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '
55                                 + 'codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" '
56                                 + 'id="' + kwArgs.id + '" '
57                                 + 'width="' + kwArgs.width + '" '
58                                 + 'height="' + kwArgs.height + '">'
59                                 + '<param name="src" value="' + kwArgs.path + '" />';
60                         for(var i=0, l=kwArgs.params.length; i<l; i++){
61                                 s += '<param name="' + kwArgs.params[i].key + '" value="' + kwArgs.params[i].value + '" />';
62                         }
63                         s += '</object>';
64                         return { id: kwArgs.id, markup: s };
65                 }
66         } else {
67                 installed = (function(){
68                         for(var i=0, l=navigator.plugins.length; i<l; i++){
69                                 if(navigator.plugins[i].name.indexOf("QuickTime")>-1){
70                                         return true;
71                                 }
72                         }
73                         return false;
74                 })();
75
76                 qtMarkup = function(kwArgs){
77                         if(!installed){ return { id: null, markup: getQTMarkup }; }
78
79                         kwArgs = prep(kwArgs);
80                         if(!kwArgs){ return null; }
81                         var s = '<embed type="video/quicktime" src="' + kwArgs.path + '" '
82                                 + 'id="' + kwArgs.id + '" '
83                                 + 'name="' + kwArgs.id + '" '
84                                 + 'pluginspage="www.apple.com/quicktime/download" '
85                                 + 'enablejavascript="true" '
86                                 + 'width="' + kwArgs.width + '" '
87                                 + 'height="' + kwArgs.height + '"';
88                         for(var i=0, l=kwArgs.params.length; i<l; i++){
89                                 s += ' ' + kwArgs.params[i].key + '="' + kwArgs.params[i].value + '"';
90                         }
91                         s += '></embed>';
92                         return { id: kwArgs.id, markup: s };
93                 }
94         }
95         
96         qtVersion = { major: 0, minor: 0, rev: 0 };
97
98         // *** This is an offical kludge, but it seems to work everywhere.  Sigh. *************************
99         dojo.addOnLoad(function(){
100                 var n = document.createElement("div");
101                 n.style.cssText = "top:0;left:0;width:1px;height:1px;overflow:hidden;position:absolute;";
102                 var o = qtMarkup({ path: testMovieUrl, width:4, height:4 });
103
104                 document.body.appendChild(n);
105                 n.innerHTML = o.markup;
106                 var qt = (dojo.isIE) ? dojo.byId(o.id) : document[o.id]; 
107                 
108                 //      Let Safari and IE have a moment to init the QT object before trying to query it.
109                 setTimeout(function(){
110                         var v = [ 0, 0, 0 ];
111                         if(qt){
112                                 try {
113                                         v = qt.GetQuickTimeVersion().split(".");
114                                         qtVersion = { major: parseInt(v[0]||0), minor: parseInt(v[1]||0), rev: parseInt(v[2]||0) };
115                                 } catch(e){ 
116                                         qtVersion = { major: 0, minor: 0, rev: 0 };
117                                 }
118                         }
119
120                         dojox.av.quicktime.supported = v[0];
121                         dojox.av.quicktime.version = qtVersion;
122                         if(dojox.av.quicktime.supported){
123                                 dojox.av.quicktime.onInitialize();
124                         }
125
126                         //      fricking IE.  gonna end up leaving the movie in the doc, for some
127                         //              reason getting an unspecified error when trying to remove it.
128                         if(!dojo.isIE){
129                                 document.body.removeChild(n);
130                         } else {
131                                 //      move it out of the way.
132                                 n.style.top = "-10000px";
133                                 n.style.visibility="hidden";
134                         }
135                 }, 10);
136         });
137         
138         //      *** The public interface. ****************************************************************
139         dojox.av.quicktime={
140                 minSupported: 6,
141                 available: installed,
142                 supported: installed,
143                 version: qtVersion,
144                 initialized: false,
145                 onInitialize: function(){ dojox.av.quicktime.initialized = true; },     //      stub function to let you know when this is ready
146
147                 place: function(/* DOMElement */node, /* Object */kwArgs){
148                         node = dojo.byId(node);
149                         var o = qtMarkup(kwArgs);
150                         if(o){
151                                 node.innerHTML = o.markup;
152                                 if(o.id){
153                                         return (dojo.isIE)? dojo.byId(o.id) : document[o.id];   //      QuickTimeObject
154                                 }
155                         }
156                         return null;    //      QuickTimeObject
157                 }
158         };
159 })();
160
161 }