Quicktime.js 8.3 KB

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