source: Dev/branches/rest-dojo-ui/client/dojox/embed/Quicktime.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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