source: Dev/trunk/src/client/dojox/embed/Quicktime.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 7.6 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dojo/_base/lang",
4        "dojo/_base/sniff",
5        "dojo/_base/window",
6        "dojo/dom",
7        "dojo/dom-construct",
8        "dojo/domReady!" // fixes doc.readyState in Fx<=3.5
9], function (dojo, lang, has, windowUtil, domUtil, domConstruct) {
10        // module:
11        //              dojox/embed/Quicktime
12        // summary:
13        //              Base functionality to insert a QuickTime movie
14        //              into a document on the fly.
15
16        var qtMarkup,
17                qtVersion = { major: 0, minor: 0, rev: 0 },
18                installed,
19                __def__ = {
20                        width: 320,
21                        height: 240,
22                        redirect: null
23                },
24                keyBase = "dojox-embed-quicktime-",
25                keyCount = 0,
26                getQTMarkup = 'This content requires the <a href="http://www.apple.com/quicktime/download/" title="Download and install QuickTime.">QuickTime plugin</a>.',
27                embed = dojo.getObject("dojox.embed", true);
28
29        //      *** private methods *********************************************************
30        function prep(kwArgs){
31                kwArgs = dojo.mixin(lang.clone(__def__), kwArgs || {});
32                if(!("path" in kwArgs) && !kwArgs.testing){
33                        console.error("dojox.embed.Quicktime(ctor):: no path reference to a QuickTime movie was provided.");
34                        return null;
35                }
36                if(kwArgs.testing){
37                        kwArgs.path = "";
38                }
39                if(!("id" in kwArgs)){
40                        kwArgs.id = keyBase + keyCount++;
41                }
42                return kwArgs;
43        }
44
45        if(has("ie")){
46                installed = (function(){
47                        try{
48                                var o = new ActiveXObject("QuickTimeCheckObject.QuickTimeCheck.1");
49                                if(o!==undefined){
50                                        //      pull the qt version too
51                                        var v = o.QuickTimeVersion.toString(16);
52                                        function p(i){ return (v.substring(i, i+1)-0) || 0; }
53                                        qtVersion = {
54                                                major: p(0),
55                                                minor: p(1),
56                                                rev: p(2)
57                                        };
58                                        return o.IsQuickTimeAvailable(0);
59                                }
60                        } catch(e){ }
61                        return false;
62                })();
63
64                qtMarkup = function(kwArgs){
65                        if(!installed){ return { id: null, markup: getQTMarkup }; }
66                       
67                        kwArgs = prep(kwArgs);
68                        if(!kwArgs){ return null; }
69                        var s = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '
70                                + 'codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" '
71                                + 'id="' + kwArgs.id + '" '
72                                + 'width="' + kwArgs.width + '" '
73                                + 'height="' + kwArgs.height + '">'
74                                + '<param name="src" value="' + kwArgs.path + '"/>';
75                        for(var p in kwArgs.params||{}){
76                                s += '<param name="' + p + '" value="' + kwArgs.params[p] + '"/>';
77                        }
78                        s += '</object>';
79                        return { id: kwArgs.id, markup: s };
80                }
81        } else {
82                installed = (function(){
83                        for(var i=0, p=navigator.plugins, l=p.length; i<l; i++){
84                                if(p[i].name.indexOf("QuickTime")>-1){
85                                        return true;
86                                }
87                        }
88                        return false;
89                })();
90
91                qtMarkup = function(kwArgs){
92                        if(!installed){ return { id: null, markup: getQTMarkup }; }
93
94                        kwArgs = prep(kwArgs);
95                        if(!kwArgs){ return null; }
96                        var s = '<embed type="video/quicktime" src="' + kwArgs.path + '" '
97                                + 'id="' + kwArgs.id + '" '
98                                + 'name="' + kwArgs.id + '" '
99                                + 'pluginspage="www.apple.com/quicktime/download" '
100                                + 'enablejavascript="true" '
101                                + 'width="' + kwArgs.width + '" '
102                                + 'height="' + kwArgs.height + '"';
103                        for(var p in kwArgs.params||{}){
104                                s += ' ' + p + '="' + kwArgs.params[p] + '"';
105                        }
106                        s += '></embed>';
107                        return { id: kwArgs.id, markup: s };
108                }
109        }
110
111        /*=====
112        var __QTArgs = {
113                // path: String
114                //              The URL of the movie to embed.
115                // id: String?
116                //              A unique key that will be used as the id of the created markup.  If you don't
117                //              provide this, a unique key will be generated.
118                // width: Number?
119                //              The width of the embedded movie; the default value is 320px.
120                // height: Number?
121                //              The height of the embedded movie; the default value is 240px
122                // params: Object?
123                //              A set of key/value pairs that you want to define in the resultant markup.
124                // redirect: String?
125                //              A url to redirect the browser to if the current QuickTime version is not supported.
126        };
127        =====*/
128
129        var Quicktime=function(/* __QTArgs */kwArgs, /* DOMNode */node){
130                // summary:
131                //              Returns a reference to the HTMLObject/HTMLEmbed that is created to
132                //              place the movie in the document.  You can use this either with or
133                //              without the new operator.  Note that with any other DOM manipulation,
134                //              you must wait until the document is finished loading before trying
135                //              to use this.
136                //
137                // example:
138                //              Embed a QuickTime movie in a document using the new operator, and get a reference to it.
139                //      |       var movie = new dojox.embed.Quicktime({
140                //      |               path: "path/to/my/movie.mov",
141                //      |               width: 400,
142                //      |               height: 300
143                //      |       }, myWrapperNode);
144                //
145                // example:
146                //              Embed a movie in a document without using the new operator.
147                //      |       var movie = dojox.embed.Quicktime({
148                //      |               path: "path/to/my/movie.mov",
149                //      |               width: 400,
150                //      |               height: 300
151                //      |       }, myWrapperNode);
152
153                return Quicktime.place(kwArgs, node);   //      HTMLObject
154        };
155
156        dojo.mixin(Quicktime, {
157                // summary:
158                //              A singleton object used internally to get information
159                //              about the QuickTime player available in a browser, and
160                //              as the factory for generating and placing markup in a
161                //              document.
162                //
163                // minSupported: Number
164                //              The minimum supported version of the QuickTime Player, defaults to
165                //              6.
166                // available: Boolean
167                //              Whether or not QuickTime is available.
168                // supported: Boolean
169                //              Whether or not the QuickTime Player installed is supported by
170                //              dojox.embed.
171                // version: Object
172                //              The version of the installed QuickTime Player; takes the form of
173                //              { major, minor, rev }.  To get the major version, you'd do this:
174                //              var v=dojox.embed.Quicktime.version.major;
175                // initialized: Boolean
176                //              Whether or not the QuickTime engine is available for use.
177                // onInitialize: Function
178                //              A stub you can connect to if you are looking to fire code when the
179                //              engine becomes available.  A note: do NOT use this stub to embed
180                //              a movie in your document; this WILL be fired before DOMContentLoaded
181                //              is fired, and you will get an error.  You should use dojo.addOnLoad
182                //              to place your movie instead.
183
184                minSupported: 6,
185                available: installed,
186                supported: installed,
187                version: qtVersion,
188                initialized: false,
189                onInitialize: function(){
190                        Quicktime.initialized = true;
191                },      //      stub function to let you know when this is ready
192
193                place: function(kwArgs, node){
194                        var o = qtMarkup(kwArgs);
195
196                        if(!(node = domUtil.byId(node))){
197                                node=domConstruct.create("div", { id:o.id+"-container" }, windowUtil.body());
198                        }
199                       
200                        if(o){
201                                node.innerHTML = o.markup;
202                                if(o.id){
203                                        return has("ie") ? dom.byId(o.id) : document[o.id];     //      QuickTimeObject
204                                }
205                        }
206                        return null;    //      QuickTimeObject
207                }
208        });
209
210        //      go get the info
211        if(!has("ie")){
212                var id = "-qt-version-test",
213                        o = qtMarkup({ testing:true , width:4, height:4 }),
214                        c = 10, // counter to prevent infinite looping
215                        top = "-1000px",
216                        widthHeight = "1px";
217
218                function getVer(){
219                        setTimeout(function(){
220                                var qt = document[o.id],
221                                        n = domUtil.byId(id);
222
223                                if(qt){
224                                        try{
225                                                var v = qt.GetQuickTimeVersion().split(".");
226                                                Quicktime.version = { major: parseInt(v[0]||0), minor: parseInt(v[1]||0), rev: parseInt(v[2]||0) };
227                                                if((Quicktime.supported = v[0])){
228                                                        Quicktime.onInitialize();
229                                                }
230                                                c = 0;
231                                        } catch(e){
232                                                if(c--){
233                                                        getVer();
234                                                }
235                                        }
236                                }
237
238                                if(!c && n){ domConstruct.destroy(n); }
239                        }, 20);
240                }
241
242                domConstruct.create("div", {
243                        innerHTML: o.markup,
244                        id: id,
245                        style: { top:top, left:0, width:widthHeight, height:widthHeight, overflow:"hidden", position:"absolute" }
246                }, windowUtil.body());
247                getVer();
248        }else if(has("ie") && installed){
249                // we already know if IE has QuickTime installed, but we need this to seem like a callback.
250                setTimeout(function(){
251                        Quicktime.onInitialize();
252                }, 10);
253        }
254
255        lang.setObject("dojox.embed.Quicktime", Quicktime);
256
257        return Quicktime;
258});
Note: See TracBrowser for help on using the repository browser.