//jQuery(document).ready(function($) //{ jQuery.noConflict(); (function($) { $.fn.colgrid = function(col, grid) { $(this).addClass('col-' + col + '-' + grid).attr('data-col', col).attr('data-grid', grid); }; $.fn.maxwidth = function(exclude) { var $this = $(this); var width = 0; $this.siblings().each(function(index, element) { if ( !$(this).hasClass(exclude)) width += $(this).outerWidth(true); }); $this.css('max-width', 'calc(100% - ' + width + 'px - 1px)'); }; $.fn.getDynamicWidth = function(margin, grid) { var $this = $(this); var width = $this.outerWidth(true); var row = $this.parent('.row'); var row_width = row.outerWidth(true); var decimal = (width + margin) / (row_width + margin); //console.log(width); return Math.round(decimal * grid);//ceil / if ( r > 12 ) return 12 else.. }; $.fn.dynamicWidth = function(margin, grid, exclude)//dynamicGrid { var $this = $(this); var row = $this.parent('.row'); var vip_col = $this.getDynamicWidth(margin, grid); var remaining = grid - vip_col; $this.colgrid(vip_col, grid); var includes = []; //console.log(remaining); $this.siblings().each(function(index, element) { if ( remaining <= 0 ) { $(this).colgrid(grid, grid); return; } if ( $(this).prop('data-col')) { var col = $(this).prop('data-col'); } else if ( $(this).hasClass(exclude)) { var col = $(this).getDynamicWidth(margin, grid); } if ( $(this).prop('data-col') || $(this).hasClass(exclude)) { remaining -= col; $(this).colgrid(col, grid); } else includes.push(index);// = index; }); var size = remaining / includes.length; //console.log(remaining); $this.siblings().each(function(index, element) { if ($.inArray(index, includes) !== -1) { if (includes[includes.length-1] === index) $(this).colgrid(remaining, grid); else { var col = Math.floor(size); remaining -= col; $(this).colgrid(col, grid); } } }); }; //}); })(jQuery);