jquery.fancybox-media.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*!
  2. * Media helper for fancyBox
  3. * version: 1.0.6 (Fri, 14 Jun 2013)
  4. * @requires fancyBox v2.0 or later
  5. *
  6. * Usage:
  7. * $(".fancybox").fancybox({
  8. * helpers : {
  9. * media: true
  10. * }
  11. * });
  12. *
  13. * Set custom URL parameters:
  14. * $(".fancybox").fancybox({
  15. * helpers : {
  16. * media: {
  17. * youtube : {
  18. * params : {
  19. * autoplay : 0
  20. * }
  21. * }
  22. * }
  23. * }
  24. * });
  25. *
  26. * Or:
  27. * $(".fancybox").fancybox({,
  28. * helpers : {
  29. * media: true
  30. * },
  31. * youtube : {
  32. * autoplay: 0
  33. * }
  34. * });
  35. *
  36. * Supports:
  37. *
  38. * Youtube
  39. * http://www.youtube.com/watch?v=opj24KnzrWo
  40. * http://www.youtube.com/embed/opj24KnzrWo
  41. * http://youtu.be/opj24KnzrWo
  42. * http://www.youtube-nocookie.com/embed/opj24KnzrWo
  43. * Vimeo
  44. * http://vimeo.com/40648169
  45. * http://vimeo.com/channels/staffpicks/38843628
  46. * http://vimeo.com/groups/surrealism/videos/36516384
  47. * http://player.vimeo.com/video/45074303
  48. * Metacafe
  49. * http://www.metacafe.com/watch/7635964/dr_seuss_the_lorax_movie_trailer/
  50. * http://www.metacafe.com/watch/7635964/
  51. * Dailymotion
  52. * http://www.dailymotion.com/video/xoytqh_dr-seuss-the-lorax-premiere_people
  53. * Twitvid
  54. * http://twitvid.com/QY7MD
  55. * Twitpic
  56. * http://twitpic.com/7p93st
  57. * Instagram
  58. * http://instagr.am/p/IejkuUGxQn/
  59. * http://instagram.com/p/IejkuUGxQn/
  60. * Google maps
  61. * http://maps.google.com/maps?q=Eiffel+Tower,+Avenue+Gustave+Eiffel,+Paris,+France&t=h&z=17
  62. * http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
  63. * http://maps.google.com/?ll=48.859463,2.292626&spn=0.000965,0.002642&t=m&z=19&layer=c&cbll=48.859524,2.292532&panoid=YJ0lq28OOy3VT2IqIuVY0g&cbp=12,151.58,,0,-15.56
  64. */
  65. ;(function ($) {
  66. "use strict";
  67. //Shortcut for fancyBox object
  68. var F = $.fancybox,
  69. format = function( url, rez, params ) {
  70. params = params || '';
  71. if ( $.type( params ) === "object" ) {
  72. params = $.param(params, true);
  73. }
  74. $.each(rez, function(key, value) {
  75. url = url.replace( '$' + key, value || '' );
  76. });
  77. if (params.length) {
  78. url += ( url.indexOf('?') > 0 ? '&' : '?' ) + params;
  79. }
  80. return url;
  81. };
  82. //Add helper object
  83. F.helpers.media = {
  84. defaults : {
  85. youtube : {
  86. matcher : /(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(watch\?v=|v\/|u\/|embed\/?)?(videoseries\?list=(.*)|[\w-]{11}|\?listType=(.*)&list=(.*)).*/i,
  87. params : {
  88. autoplay : 1,
  89. autohide : 1,
  90. fs : 1,
  91. rel : 0,
  92. hd : 1,
  93. wmode : 'opaque',
  94. enablejsapi : 1
  95. },
  96. type : 'iframe',
  97. url : '//www.youtube.com/embed/$3'
  98. },
  99. vimeo : {
  100. matcher : /(?:vimeo(?:pro)?.com)\/(?:[^\d]+)?(\d+)(?:.*)/,
  101. params : {
  102. autoplay : 1,
  103. hd : 1,
  104. show_title : 1,
  105. show_byline : 1,
  106. show_portrait : 0,
  107. fullscreen : 1
  108. },
  109. type : 'iframe',
  110. url : '//player.vimeo.com/video/$1'
  111. },
  112. metacafe : {
  113. matcher : /metacafe.com\/(?:watch|fplayer)\/([\w\-]{1,10})/,
  114. params : {
  115. autoPlay : 'yes'
  116. },
  117. type : 'swf',
  118. url : function( rez, params, obj ) {
  119. obj.swf.flashVars = 'playerVars=' + $.param( params, true );
  120. return '//www.metacafe.com/fplayer/' + rez[1] + '/.swf';
  121. }
  122. },
  123. dailymotion : {
  124. matcher : /dailymotion.com\/video\/(.*)\/?(.*)/,
  125. params : {
  126. additionalInfos : 0,
  127. autoStart : 1
  128. },
  129. type : 'swf',
  130. url : '//www.dailymotion.com/swf/video/$1'
  131. },
  132. twitvid : {
  133. matcher : /twitvid\.com\/([a-zA-Z0-9_\-\?\=]+)/i,
  134. params : {
  135. autoplay : 0
  136. },
  137. type : 'iframe',
  138. url : '//www.twitvid.com/embed.php?guid=$1'
  139. },
  140. twitpic : {
  141. matcher : /twitpic\.com\/(?!(?:place|photos|events)\/)([a-zA-Z0-9\?\=\-]+)/i,
  142. type : 'image',
  143. url : '//twitpic.com/show/full/$1/'
  144. },
  145. instagram : {
  146. matcher : /(instagr\.am|instagram\.com)\/p\/([a-zA-Z0-9_\-]+)\/?/i,
  147. type : 'image',
  148. url : '//$1/p/$2/media/?size=l'
  149. },
  150. google_maps : {
  151. matcher : /maps\.google\.([a-z]{2,3}(\.[a-z]{2})?)\/(\?ll=|maps\?)(.*)/i,
  152. type : 'iframe',
  153. url : function( rez ) {
  154. return '//maps.google.' + rez[1] + '/' + rez[3] + '' + rez[4] + '&output=' + (rez[4].indexOf('layer=c') > 0 ? 'svembed' : 'embed');
  155. }
  156. }
  157. },
  158. beforeLoad : function(opts, obj) {
  159. var url = obj.href || '',
  160. type = false,
  161. what,
  162. item,
  163. rez,
  164. params;
  165. for (what in opts) {
  166. if (opts.hasOwnProperty(what)) {
  167. item = opts[ what ];
  168. rez = url.match( item.matcher );
  169. if (rez) {
  170. type = item.type;
  171. params = $.extend(true, {}, item.params, obj[ what ] || ($.isPlainObject(opts[ what ]) ? opts[ what ].params : null));
  172. url = $.type( item.url ) === "function" ? item.url.call( this, rez, params, obj ) : format( item.url, rez, params );
  173. break;
  174. }
  175. }
  176. }
  177. if (type) {
  178. obj.href = url;
  179. obj.type = type;
  180. obj.autoHeight = false;
  181. }
  182. }
  183. };
  184. }(jQuery));