Quicktime.js 8.3 KB

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