You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
6.4 KiB

2 years ago
  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. ps: 'docs',
  96. controls: 1
  97. },
  98. type: 'iframe',
  99. url: '//www.youtube.com/embed/$3'
  100. },
  101. vimeo: {
  102. matcher: /(?:vimeo(?:pro)?.com)\/(?:[^\d]+)?(\d+)(?:.*)/,
  103. params: {
  104. autoplay: 1,
  105. hd: 1,
  106. show_title: 1,
  107. show_byline: 1,
  108. show_portrait: 0,
  109. fullscreen: 1
  110. },
  111. type: 'iframe',
  112. url: '//player.vimeo.com/video/$1'
  113. },
  114. metacafe: {
  115. matcher: /metacafe.com\/(?:watch|fplayer)\/([\w\-]{1,10})/,
  116. params: {
  117. autoPlay: 'yes'
  118. },
  119. type: 'swf',
  120. url: function (rez, params, obj) {
  121. obj.swf.flashVars = 'playerVars=' + $.param(params, true);
  122. return '//www.metacafe.com/fplayer/' + rez[1] + '/.swf';
  123. }
  124. },
  125. dailymotion: {
  126. matcher: /dailymotion.com\/video\/(.*)\/?(.*)/,
  127. params: {
  128. additionalInfos: 0,
  129. autoStart: 1
  130. },
  131. type: 'swf',
  132. url: '//www.dailymotion.com/swf/video/$1'
  133. },
  134. twitvid: {
  135. matcher: /twitvid\.com\/([a-zA-Z0-9_\-\?\=]+)/i,
  136. params: {
  137. autoplay: 0
  138. },
  139. type: 'iframe',
  140. url: '//www.twitvid.com/embed.php?guid=$1'
  141. },
  142. twitpic: {
  143. matcher: /twitpic\.com\/(?!(?:place|photos|events)\/)([a-zA-Z0-9\?\=\-]+)/i,
  144. type: 'image',
  145. url: '//twitpic.com/show/full/$1/'
  146. },
  147. instagram: {
  148. matcher: /(instagr\.am|instagram\.com)\/p\/([a-zA-Z0-9_\-]+)\/?/i,
  149. type: 'image',
  150. url: '//$1/p/$2/media/?size=l'
  151. },
  152. google_maps: {
  153. matcher: /maps\.google\.([a-z]{2,3}(\.[a-z]{2})?)\/(\?ll=|maps\?)(.*)/i,
  154. type: 'iframe',
  155. url: function (rez) {
  156. return '//maps.google.' + rez[1] + '/' + rez[3] + '' + rez[4] + '&output=' + (rez[4].indexOf('layer=c') > 0 ? 'svembed' : 'embed');
  157. }
  158. }
  159. },
  160. beforeLoad: function (opts, obj) {
  161. var url = obj.href || '',
  162. type = false,
  163. what,
  164. item,
  165. rez,
  166. params;
  167. for (what in opts) {
  168. if (opts.hasOwnProperty(what)) {
  169. item = opts[what];
  170. rez = url.match(item.matcher);
  171. if (rez) {
  172. type = item.type;
  173. params = $.extend(true, {}, item.params, obj[what] || ($.isPlainObject(opts[what]) ? opts[what].params : null));
  174. url = $.type(item.url) === "function" ? item.url.call(this, rez, params, obj) : format(item.url, rez, params);
  175. break;
  176. }
  177. }
  178. }
  179. if (type) {
  180. obj.href = url;
  181. obj.type = type;
  182. obj.autoHeight = false;
  183. }
  184. }
  185. };
  186. }(jQuery));