/** * Tosom Live Cams script * * @author: Toniolo Marco * @version: 1.0 * @requires: jQuery * */ jQuery(document).ready(function(){ updateYTBoxes(); window.onresize = function(){ updateYTBoxes(); } }); function updateYTBoxes() { var ns = calcBoxSize() ; console.log( "NBS "+ns[0],","+ns[1] ) jQuery( ".box-yt" ).css({ width:ns[0]+"px" , height:ns[1]+"px" }); jQuery( ".box-yt iframe" ).css({ width:ns[0]+"px" , height:ns[1]+"px" }); } /** * If elem is a query selector with more than 1 result, the size is the size of the first element * @param {Object}||{String} elem jquery obj or selector */ function getSize( elem ) { var jqn = elem ; if( typeof elem == "string" ) { jqn = jQuery(elem) ; } console.log(jqn) if( !jqn || jqn.length<=0 ){ return false ; } var size = [0,0] ; // [ Width , Height ] size[0] = Math.floor( jqn.width() ); size[1] = Math.floor( jqn.height() ); return size; } function calcBoxSize() { // FULL HD SIZE & RATIO var s1 = [1920,1080] ; var r1 = s1[0]/s1[1] ; var bs = getSize( "#content" ) var cols = 3 ; var w2 = 0 ; var h2 = 0 ; if( jQuery(window).width()<=1200 ) { cols = 2 ; } if( jQuery(window).width()<=1000 ) { cols = 1 ; } console.log( "BOX "+bs[0]+" , "+bs[1] ) console.log( "COLS "+cols ) // TODO ADD A COUNTER FOR THE LINES TO UPDATE w2 = Math.floor( bs[0] / cols ); // New width for X cols // Consider the container padding hardcoded no time to get it from the node. w2 -= (4)*cols ; console.log( "MARGIN: "+((4*2)*cols) ) h2 = Math.floor( w2/r1 ) ; return [w2,h2] ; }