clameursmod.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. (function($) {
  2. Clameurs = function(){
  3. function init(){
  4. console.log("Clameurs");
  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) {
  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:true,
  60. functionCallAfterClose:function(){
  61. $('#videoframe').remove();
  62. }
  63. });
  64. };
  65. function onCloseOverlay(){
  66. $('#videoframe').remove();
  67. };
  68. init();
  69. };
  70. $(document).ready(function() {
  71. var clameurs = new Clameurs();
  72. });
  73. })(jQuery);