clameursmod.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. (function($) {
  2. Clameurs = function(){
  3. function init(){
  4. console.log("Clameurs Mod");
  5. initVideoEvents();
  6. }
  7. function initVideoEvents(){
  8. $('.field-type-video-embed-field a').on('click', clickVideo);
  9. };
  10. function clickVideo(event){
  11. event.preventDefault();
  12. console.log('Click video', this);
  13. var vid_src = $(this).attr('href');
  14. console.log("vid_src", vid_src);
  15. getEmVidField(vid_src);
  16. return false;
  17. };
  18. function getEmVidField(src){
  19. $.getJSON('clameursmod/getemvidfield',
  20. {'src':src},
  21. function(json){
  22. console.log("json loaded", json);
  23. displayVid(json)
  24. }
  25. );
  26. };
  27. function displayVid(json){
  28. $('#videoframe').remove();
  29. $vid = $('<div>')
  30. .attr('id', 'videoframe')
  31. .append(json.embed)
  32. .hide()
  33. .appendTo('body');
  34. var iframe = $('iframe', $vid)[0];
  35. var winwidth = $(window).width();
  36. var winheight = $(window).height();
  37. console.log('win :'+winwidth+' | '+winheight);
  38. if (winwidth / winheight < 640 / 360) {
  39. // console.log("Width target");
  40. var w = winwidth*0.9;
  41. var h = w*(360/640);
  42. }else{
  43. // console.log("height target");
  44. var h = winheight*0.9;
  45. var w = h*(640/360);
  46. }
  47. console.log('win :'+w+' | '+h);
  48. $.openDOMWindow({
  49. loader:0,
  50. windowPadding:10,
  51. overlay:1,
  52. overlayColor:'#fff',
  53. overlayOpacity:'90',
  54. borderColor:'transparent',
  55. borderSize:'0',
  56. width:w,
  57. height:h,
  58. windowSourceID:"#videoframe",
  59. // functionCallOnClose:function(){
  60. // console.log('overlay closed');
  61. // $('#videoframe').remove();
  62. // },
  63. // functionCallAfterClose:function(){
  64. // console.log('overlay closed');
  65. // $('#videoframe').remove();
  66. // }
  67. });
  68. // autoplay vid youtube
  69. // see patch https://www.drupal.org/node/2685721#comment-11032685
  70. };
  71. function onCloseOverlay(){
  72. $('#videoframe').remove();
  73. };
  74. init();
  75. };
  76. $(document).ready(function() {
  77. var clameurs = new Clameurs();
  78. });
  79. })(jQuery);