(function ($) { Drupal.behaviors.colorboxVideo = { attach: function (context, settings) { var initwidth = 0; var initheight = 0; var windowwidth = $(window).width(); var windowheight = $(window).height(); if ((windowwidth > windowheight) && (windowheight > 400) && (windowwidth > 660)) { initwidth = "640"; initheight = "393"; } else if (windowwidth > windowheight) { if (((windowwidth - 70)*9)/16 < (windowheight - 93)) { initwidth = windowwidth - 40; initheight = Math.floor(((windowwidth - 70)*9)/16) + 93; } else { initheight = windowheight - 40; initwidth = Math.floor(((windowheight - 93)*16)/9) + 70; } } else if ((windowheight > windowwidth) && (windowwidth > 660)) { initwidth = "640"; initheight = "393"; } else { initwidth = windowwidth - 40; initheight = Math.floor(((windowwidth - 70)*9)/16) + 93; } $(".cboxvideo1").colorbox({iframe:true, width:initwidth, height:initheight}); $(".cboxvideo2").colorbox({iframe:true, width:initwidth, height:initheight}); $(".cboxvideo3").colorbox({iframe:true, width:initwidth, height:initheight}); $(".cboxvideo4").colorbox({iframe:true, width:initwidth, height:initheight}); $(".cboxvideo5").colorbox({iframe:true, width:initwidth, height:initheight}); $(".cboxvideo6").colorbox({iframe:true}); } }; Drupal.behaviors.colorboxVideoResize = { attach: function (context, settings) { $.colorbox.settings.onLoad = function() { colorboxResize(); } //Customize colorbox dimensions var colorboxResize = function(resize) { var width = 0; var height = 0; var nwindowwidth = $(window).width(); var nwindowheight = $(window).height(); if ((nwindowwidth > nwindowheight) && (nwindowheight > 400) && (nwindowwidth > 660)) { width = "640"; height = "393"; } else if (nwindowwidth > nwindowheight) { if (((nwindowwidth - 70)*9)/16 < (nwindowheight - 93)) { width = nwindowwidth - 40; height = Math.floor(((nwindowwidth - 70)*9)/16) + 93; } else { height = nwindowheight - 40; width = Math.floor(((nwindowheight - 93)*16)/9) + 70; } } else if ((nwindowheight > nwindowwidth) && (nwindowwidth > 660)) { width = "640"; height = "393"; } else { width = nwindowwidth - 40; height = Math.floor(((nwindowwidth - 70)*9)/16) + 93; } //if window is resized while lightbox open if(resize) { $.colorbox.resize({ 'height': height, 'width': width }); } } //In case of window being resized $(window).resize(function() { colorboxResize(true); }); } }; })(jQuery);