vimeo_embed.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*global jQuery, Drupal, drupalSettings*/
  2. /*jslint white:true, multivar, this, browser:true*/
  3. (function($, Drupal, drupalSettings)
  4. {
  5. "use strict";
  6. function vimeoVideoEnable(context)
  7. {
  8. $(context).find(".vimeo-player").once("vimeo-video-enable").each(function()
  9. {
  10. var vimeoID = $(this).attr("data-vimeo-id");
  11. $(this).parent().removeClass("no-js");
  12. if(drupalSettings.urlToVideoFilter.autoload)
  13. {
  14. $(this).empty().append($("<iframe/>").attr("src", "//player.vimeo.com/video/" + vimeoID + "?autopause=1&autoplay=0&badge=1&byline=1&loop=0&portrait=1&autopause=1&fullscreen=1").attr("frameborder", "0").attr("class", "player-iframe vimeo-iframe"));
  15. }
  16. else
  17. {
  18. $.ajax(
  19. {
  20. url:"//vimeo.com/api/v2/video/" + vimeoID + ".json",
  21. context:$(this),
  22. success:function(data)
  23. {
  24. if(data[0] && data[0].thumbnail_large)
  25. {
  26. $(this).empty().append($("<span/>").append($("<img/>", {class:"player-thumb", src:data[0].thumbnail_large})).append($("<span/>", {class:"play-button"})).click(function(e)
  27. {
  28. e.stopPropagation();
  29. Drupal.detachBehaviors($(this).parent().parent());
  30. $(this).replaceWith($("<iframe/>").attr("src", "//player.vimeo.com/video/" + vimeoID + "?autopause=1&autoplay=1&badge=1&byline=1&loop=0&portrait=1&autopause=1&fullscreen=1").attr("frameborder", "0").attr("class", "player-iframe vimeo-iframe"));
  31. }));
  32. }
  33. else
  34. {
  35. $(this).empty().append($("<span/>").append($("<span/>", {class:"play-button"})).click(function(e)
  36. {
  37. e.stopPropagation();
  38. Drupal.detachBehaviors($(this).parent().parent());
  39. $(this).replaceWith($("<iframe/>").attr("src", "//player.vimeo.com/video/" + vimeoID + "?autopause=1&autoplay=1&badge=1&byline=1&loop=0&portrait=1&autopause=1&fullscreen=1").attr("frameborder", "0").attr("class", "player-iframe vimeo-iframe"));
  40. }));
  41. }
  42. }
  43. });
  44. }
  45. });
  46. }
  47. Drupal.behaviors.urlToVideoFilterVimeo = {
  48. attach:function(context)
  49. {
  50. vimeoVideoEnable(context);
  51. },
  52. detach:function(context)
  53. {
  54. $(".vimeo-player", context).unbind("click");
  55. }
  56. };
  57. }(jQuery, Drupal, drupalSettings));