lightbox_video.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* $Id: lightbox_video.js,v 1.1.4.20 2010/09/21 17:57:22 snpower Exp $ */
  2. /**
  3. * Lightbox video
  4. * @author
  5. * Stella Power, <http://drupal.org/user/66894>
  6. */
  7. var Lightvideo;
  8. // start jQuery block
  9. (function ($) {
  10. Lightvideo = {
  11. // startVideo()
  12. startVideo: function (href) {
  13. if (Lightvideo.checkKnownVideos(href)) {
  14. return;
  15. }
  16. else if (href.match(/\.mov$/i)) {
  17. if (navigator.plugins && navigator.plugins.length) {
  18. Lightbox.modalHTML ='<object id="qtboxMovie" type="video/quicktime" codebase="http://www.apple.com/qtactivex/qtplugin.cab" data="'+href+'" width="'+Lightbox.modalWidth+'" height="'+Lightbox.modalHeight+'"><param name="allowFullScreen" value="true"></param><param name="src" value="'+href+'" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
  19. } else {
  20. Lightbox.modalHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+Lightbox.modalWidth+'" height="'+Lightbox.modalHeight+'" id="qtboxMovie"><param name="allowFullScreen" value="true"></param><param name="src" value="'+href+'" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
  21. }
  22. }
  23. else if (href.match(/\.wmv$/i) || href.match(/\.asx$/i)) {
  24. Lightbox.modalHTML = '<object NAME="Player" WIDTH="'+Lightbox.modalWidth+'" HEIGHT="'+Lightbox.modalHeight+'" align="left" hspace="0" type="application/x-oleobject" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"><param name="allowFullScreen" value="true"></param><param NAME="URL" VALUE="'+href+'"></param><param NAME="AUTOSTART" VALUE="true"></param><param name="showControls" value="true"></param><embed WIDTH="'+Lightbox.modalWidth+'" HEIGHT="'+Lightbox.modalHeight+'" align="left" hspace="0" SRC="'+href+'" TYPE="application/x-oleobject" AUTOSTART="false"></embed></object>';
  25. }
  26. else {
  27. Lightbox.videoId = href;
  28. variables = '';
  29. if (!href.match(/\.swf$/i)) {
  30. href = Lightbox.flvPlayer + '?file=' + href;
  31. if (Lightbox.flvFlashvars.length) {
  32. variables = Lightbox.flvFlashvars;
  33. }
  34. }
  35. Lightvideo.createEmbed(href, "flvplayer", "#ffffff", variables);
  36. }
  37. },
  38. // createEmbed()
  39. createEmbed: function(href, id, color, variables) {
  40. var bgcolor = 'bgcolor="' + color + '"';
  41. var flashvars = '';
  42. if (variables) {
  43. flashvars = 'flashvars="' + variables + '"';
  44. }
  45. Lightbox.modalHTML = '<embed type="application/x-shockwave-flash" ' +
  46. 'src="' + href + '" ' +
  47. 'id="' + id + '" name="' + id + '" ' + bgcolor + ' ' +
  48. 'quality="high" wmode="transparent" ' + flashvars + ' ' +
  49. 'height="' + Lightbox.modalHeight + '" ' +
  50. 'width="' + Lightbox.modalWidth + '" ' +
  51. 'allowfullscreen="true" ' +
  52. '></embed>';
  53. },
  54. // checkKnownVideos()
  55. checkKnownVideos: function(href) {
  56. if (Lightvideo.checkYouTubeVideo(href) || Lightvideo.checkGoogleVideo(href) ||
  57. Lightvideo.checkMySpaceVideo(href) || Lightvideo.checkLiveVideo(href) ||
  58. Lightvideo.checkMetacafeVideo(href) ||
  59. Lightvideo.checkIFilmSpikeVideo(href)
  60. ) {
  61. return true;
  62. }
  63. return false;
  64. },
  65. // checkYouTubeVideo()
  66. checkYouTubeVideo: function(href) {
  67. var patterns = [
  68. 'youtube.com/v/([^"&]+)',
  69. 'youtube.com/watch\\?v=([^"&]+)',
  70. 'youtube.com/\\?v=([^"&]+)'
  71. ];
  72. for (var i = 0; i < patterns.length; i++) {
  73. var pattern = new RegExp(patterns[i], "i");
  74. var results = pattern.exec(href);
  75. if (results !== null) {
  76. Lightbox.videoId = results[1];
  77. var href = "http://www.youtube.com/v/"+Lightbox.videoId;
  78. var variables = 'fs=1';
  79. if (Lightbox.flvFlashvars.length) {
  80. variables = variables + '&' + Lightbox.flvFlashvars;
  81. href = href + '&' + variables;
  82. }
  83. Lightvideo.createEmbed(href, "flvvideo", "#ffffff", variables);
  84. return true;
  85. }
  86. }
  87. return false;
  88. },
  89. // checkGoogleVideo()
  90. checkGoogleVideo: function(href) {
  91. var patterns = [
  92. 'http://video.google.[a-z]{2,4}/googleplayer.swf\\?docId=(-?\\d*)',
  93. 'http://video.google.[a-z]{2,4}/videoplay\\?docid=([^&]*)&',
  94. 'http://video.google.[a-z]{2,4}/videoplay\\?docid=(.*)'
  95. ];
  96. for (var i = 0; i < patterns.length; i++) {
  97. var pattern = new RegExp(patterns[i], "i");
  98. var results = pattern.exec(href);
  99. if (results !== null) {
  100. Lightbox.videoId = results[1];
  101. var href = "http://video.google.com/googleplayer.swf?docId="+Lightbox.videoId+"&hl=en";
  102. var variables = 'fs=true';
  103. if (Lightbox.flvFlashvars.length) {
  104. variables = variables + '&' + Lightbox.flvFlashvars;
  105. href = href + '&' + variables;
  106. }
  107. Lightvideo.createEmbed(href, "flvvideo", "#ffffff", variables);
  108. return true;
  109. }
  110. }
  111. return false;
  112. },
  113. // checkMetacafeVideo()
  114. checkMetacafeVideo: function(href) {
  115. var patterns = [
  116. 'metacafe.com/watch/(\.[^/]*)/(\.[^/]*)/',
  117. 'metacafe.com/watch/(\.[^/]*)/(\.*)',
  118. 'metacafe.com/fplayer/(\.[^/]*)/(\.[^.]*).'
  119. ];
  120. for (var i = 0; i < patterns.length; i++) {
  121. var pattern = new RegExp(patterns[i], "i");
  122. var results = pattern.exec(href);
  123. if (results !== null) {
  124. Lightbox.videoId = results[1];
  125. Lightvideo.createEmbed("http://www.metacafe.com/fplayer/"+Lightbox.videoId+"/.swf", "flvvideo", "#ffffff");
  126. return true;
  127. }
  128. }
  129. return false;
  130. },
  131. // checkIFilmSpikeVideo()
  132. checkIFilmSpikeVideo: function(href) {
  133. var patterns = [
  134. 'spike.com/video/[^/&"]*?/(\\d+)',
  135. 'ifilm.com/video/[^/&"]*?/(\\d+)',
  136. 'spike.com/video/([^/&"]*)',
  137. 'ifilm.com/video/([^/&"]*)'
  138. ];
  139. for (var i = 0; i < patterns.length; i++) {
  140. var pattern = new RegExp(patterns[i], "i");
  141. var results = pattern.exec(href);
  142. if (results !== null) {
  143. Lightbox.videoId = results[1];
  144. Lightvideo.createEmbed("http://www.spike.com/efp", "flvvideo", "#000", "flvbaseclip="+Lightbox.videoId+"&amp;");
  145. return true;
  146. }
  147. }
  148. return false;
  149. },
  150. // checkMySpaceVideo()
  151. checkMySpaceVideo: function(href) {
  152. var patterns = [
  153. 'src="myspace.com/index.cfm\\?fuseaction=vids.individual&videoid=([^&"]+)',
  154. 'myspace.com/index.cfm\\?fuseaction=vids.individual&videoid=([^&"]+)',
  155. 'src="myspacetv.com/index.cfm\\?fuseaction=vids.individual&videoid=([^&"]+)"',
  156. 'myspacetv.com/index.cfm\\?fuseaction=vids.individual&videoid=([^&"]+)'
  157. ];
  158. for (var i = 0; i < patterns.length; i++) {
  159. var pattern = new RegExp(patterns[i], "i");
  160. var results = pattern.exec(href);
  161. if (results !== null) {
  162. Lightbox.videoId = results[1];
  163. Lightvideo.createEmbed("http://lads.myspace.com/videos/vplayer.swf", "flvvideo", "#ffffff", "m="+Lightbox.videoId);
  164. return true;
  165. }
  166. }
  167. return false;
  168. },
  169. // checkLiveVideo()
  170. checkLiveVideo: function(href) {
  171. var patterns = [
  172. 'livevideo.com/flvplayer/embed/([^"]*)"',
  173. 'livevideo.com/video/[^/]*?/([^/]*)/',
  174. 'livevideo.com/video/([^/]*)/'
  175. ];
  176. for (var i = 0; i < patterns.length; i++) {
  177. var pattern = new RegExp(patterns[i], "i");
  178. var results = pattern.exec(href);
  179. if (results !== null) {
  180. Lightbox.videoId = results[1];
  181. Lightvideo.createEmbed("http://www.livevideo.com/flvplayer/embed/"+Lightbox.videoId, "flvvideo", "#ffffff");
  182. return true;
  183. }
  184. }
  185. return false;
  186. }
  187. };
  188. //End jQuery block
  189. }(jQuery));