PageRenderTime 29ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/artissime/html/js/jquery.mb.mediaEmbedder.js

http://mbideasproject.googlecode.com/
JavaScript | 202 lines | 162 code | 24 blank | 16 comment | 29 complexity | 614f3c8c68e8e34e90d88315ab18476e MD5 | raw file
Possible License(s): GPL-2.0
  1. /*******************************************************************************
  2. jquery.mb.components
  3. Copyright (c) 2001-2010. Matteo Bicocchi (Pupunzi); Open lab srl, Firenze - Italy
  4. email: info@pupunzi.com
  5. site: http://pupunzi.com
  6. Licences: MIT, GPL
  7. http://www.opensource.org/licenses/mit-license.php
  8. http://www.gnu.org/licenses/gpl.html
  9. ******************************************************************************/
  10. /*
  11. * jQuery.mb.components: mb.mediaEmbedder
  12. * version: 1.0- 23-gen-2010 - 55
  13. * Š 2001 - 2010 Matteo Bicocchi (pupunzi), Open Lab
  14. *
  15. */
  16. (function($){
  17. $.mb_videoEmbedder={
  18. name:"jquery.mb.videoEmbedder",
  19. version:1.0,
  20. author:"Matteo Bicocchi",
  21. defaults:{
  22. width:450,
  23. youtube:{
  24. showTitle:false
  25. }
  26. },
  27. regEx:/\[(.*?)\]/g,
  28. mb_setMovie:function(context,address,string){
  29. function findMovieAndEmbed(node, address,string) {
  30. var skip = 0;
  31. if(address.indexOf("&")!=-1) address=address.replace(/&/g,"&");
  32. if (node.nodeType == 3) {
  33. var pos = node.data.toUpperCase().indexOf(address);
  34. if (pos >= 0) {
  35. var embed = $('<span/>').addClass("mb_video");
  36. var middlebit = node.splitText(pos);
  37. middlebit.splitText(address.length);
  38. embed.append(string);
  39. middlebit.parentNode.replaceChild(embed.get(0), middlebit);
  40. skip = 1;
  41. }
  42. }
  43. else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
  44. for (var i = 0; i < node.childNodes.length; ++i) {
  45. i += findMovieAndEmbed(node.childNodes[i], address.toUpperCase(),string);
  46. }
  47. }
  48. return skip;
  49. }
  50. return context.each(function() {
  51. findMovieAndEmbed(this, address.toUpperCase(), string);
  52. });
  53. },
  54. mb_embedMovies:function(opt){
  55. var context=$(this);
  56. this.options = {};
  57. $.extend (this.options, $.mb_videoEmbedder.defaults, opt);
  58. var movies= $(this).html().match($.mb_videoEmbedder.regEx);
  59. if(!movies) return;
  60. $(movies).each(function(i){
  61. var address=movies[i];
  62. var isYoutube= address.indexOf("youtube=http://")!=-1;
  63. var isVimeo= address.indexOf("vimeo=http://")!=-1;
  64. var isUstream= address.indexOf("ustream=http://")!=-1;
  65. var isLivestream= address.indexOf("livestream=http://")!=-1;
  66. var isFlickr= address.indexOf("flickr=http://")!=-1;
  67. var isVideo = isYoutube || isVimeo || isUstream || isLivestream || isFlickr;
  68. if(!isVideo) return;
  69. var stringToParse=address.replace(/\[/g,"").replace(/\]/g,"");
  70. var showTitle= !$.mb_videoEmbedder.defaults.youtube.showTitle? 0:1;
  71. var vidId=isYoutube?(stringToParse.match( /[\\?&]v=([^&#]*)/))[1]:
  72. isVimeo? (stringToParse.match(/\d+/))[0]:
  73. isUstream?(stringToParse.match(/\d+/))[0]:
  74. isFlickr?(stringToParse.match(/\d+/))[0]:
  75. isLivestream?(stringToParse.replace("livestream=http://www.livestream.com/","").toLowerCase()):
  76. null;
  77. var ratio=isYoutube?(showTitle==1?80.5:68):
  78. isVimeo?57.5:
  79. 65;
  80. var width=$.mb_videoEmbedder.defaults.width;
  81. var height= Math.ceil((width*ratio)/100);
  82. var path= isYoutube?"http://www.youtube.com/v/":
  83. isVimeo?"http://vimeo.com/moogaloop.swf?clip_id=":
  84. isUstream?"http://www.ustream.tv/flash/video/":
  85. isLivestream?"http://cdn.livestream.com/grid/LSPlayer.swf?channel=":
  86. isFlickr?"http://www.flickr.com/apps/video/stewart.swf?photo_id=":
  87. null;
  88. var param=isYoutube?"&fs=1&rel=0&hd=1&showsearch=0&showinfo="+showTitle :
  89. isVimeo?"&amp;server=vimeo.com&amp;show_title="+showTitle+"&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1":
  90. isUstream?"?disabledComment=true&amp;autoplay=false":
  91. isLivestream?"&amp;color=0xe8e8e8&amp;autoPlay=false&amp;mute=false":
  92. "";
  93. var embedstring= '<object width="'+width+'" height="'+height+'">' +
  94. '<param name="movie" value="'+path+vidId+param+'">' +
  95. '<param name="allowFullScreen" value="true">' +
  96. '<param name="wmode" value="transparent">' +
  97. '<param name="allowscriptaccess" value="always">' +
  98. '<param name="flashvars" value="autoplay=false">' +
  99. '<embed src="'+path+vidId+param+'"' +
  100. ' type="application/x-shockwave-flash" ' +
  101. 'wmode="transparent" allowscriptaccess="always" ' +
  102. 'flashvars="autoplay=false"' +
  103. 'allowfullscreen="true" width="'+width+'" height="'+height+'">' +
  104. '</embed>' +
  105. '</object>';
  106. if(isVideo)
  107. $.mb_videoEmbedder.mb_setMovie(context,address,embedstring);
  108. });
  109. }
  110. };
  111. $.mb_audioEmbedder={
  112. name:"jquery.mb.videoEmbedder",
  113. version:1.0,
  114. author:"Matteo Bicocchi",
  115. playerPath:"media/player.swf",
  116. defaults:{
  117. width:300
  118. },
  119. regEx:/\[audio=(.*?)\]/g,
  120. mb_setAudio:function(context,pat,string){
  121. function findAudioAndEmbed(node, pat,string) {
  122. var skip = 0;
  123. if(pat.indexOf("&AMP;")!=-1) pat=pat.replace(/&AMP;/g,"&");
  124. if (node.nodeType == 3) {
  125. var pos = node.data.toUpperCase().indexOf(pat);
  126. if (pos >= 0) {
  127. var embed = $('<span/>').addClass("mb_audio");
  128. var middlebit = node.splitText(pos);
  129. middlebit.splitText(pat.length);
  130. embed.append(string);
  131. middlebit.parentNode.replaceChild(embed.get(0), middlebit);
  132. skip = 1;
  133. }
  134. }
  135. else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
  136. for (var i = 0; i < node.childNodes.length; ++i) {
  137. i += findAudioAndEmbed(node.childNodes[i], pat.toUpperCase(),string);
  138. }
  139. }
  140. return skip;
  141. }
  142. return context.each(function() {
  143. findAudioAndEmbed(this, pat.toUpperCase(), string);
  144. });
  145. },
  146. mb_embedAudio:function(opt){
  147. var context=$(this);
  148. this.options = {};
  149. $.extend (this.options, $.mb_audioEmbedder.defaults, opt);
  150. var audiofiles= $(this).html().match($.mb_audioEmbedder.regEx);
  151. if(!audiofiles) return;
  152. $(audiofiles).each(function(i){
  153. var pat=audiofiles[i];
  154. var isAudio= pat.indexOf("audio=http://")!=-1;
  155. var params=pat.replace(/\[audio=/g,"").replace(/\]/g,"");
  156. var width=$.mb_audioEmbedder.defaults.width;
  157. var embedstring= '<object width="'+width+'" height="24" type="application/x-shockwave-flash"' +
  158. 'style="outline: medium none; visibility: visible;" ' +
  159. 'data="'+$.mb_audioEmbedder.playerPath+'" >' +
  160. '<param name="menu" value="false">'+
  161. '<param name="flashvars" value="soundFile='+params+'">'+
  162. '<param name="wmode" value="transparent">' +
  163. '<param name="allowscriptaccess" value="always">' +
  164. '<embed src="'+$.mb_audioEmbedder.playerPath+'" type="application/x-shockwave-flash" ' +
  165. 'wmode="transparent" allowscriptaccess="always" ' +
  166. 'width="'+width+'" height="24"' +
  167. 'flashvars="soundFile='+params+'">' +
  168. '</embed>' +
  169. '</object>';
  170. if(isAudio)
  171. $.mb_audioEmbedder.mb_setAudio(context,pat,embedstring);
  172. });
  173. }
  174. };
  175. $.fn.mb_embedMovies=$.mb_videoEmbedder.mb_embedMovies;
  176. $.fn.mb_embedAudio=$.mb_audioEmbedder.mb_embedAudio;
  177. })(jQuery);