(function( $ ) { var catGallery3 = function(element, options){ var settings = $.extend({}, $.fn.catGallery3.defaults, options); settings.tabScale = tabScale[settings.countImage]; var isFlex = false; var d = document.documentElement.style if (('flexWrap' in d) || ('WebkitFlexWrap' in d) || ('msFlexWrap' in d)){ isFlex = true; } var tabImg = []; var countDef = settings.countImage; $(element).find('ul li').css('visibility','hidden'); if(isFlex){ $(element).find('ul').addClass('flexGal'); } var changeCountOne = function(){ $(tabImg).each(function(index){ $(this).parent().parent().css('width','100%'); }); } var changeCount = function(){ var tabTmp = []; var tabTmp2 = []; var i = 0; var y = 1; tabTmp[i] = []; $(tabImg).each(function(index){ tabTmp[i].push(this); $(this).parent().parent().removeClass('sep'); if(y%countDef == 0 && index>0){ i++; tabTmp[i] = []; } if(index%countDef == 0 && index>0){ $(this).parent().parent().addClass('sep'); } y++; }) $(tabTmp).each(function(index){ var wI = 0; $(this).each(function(){ var wia = parseInt(this.data('w')); var hia = parseInt(this.data('h')); wI += wia/hia; }) hi = Math.round(settings.widthGallery/wI *1000)/1000; $(this).each(function(){ var widthImg = parseInt(this.data('w')); var heightImg = parseInt(this.data('h')); var ratio = widthImg / heightImg; var imgWw = Math.round(hi*ratio*1000)/1000; var imgWwProc = Math.round(imgWw/settings.widthGallery*100*1000)/1000; $(this).parent().parent().css('width',imgWwProc+'%'); }) }); } $(window).on('load',function(){ $(element).find('ul li').each(function(){ tabImg.push($(this).find('img')); }) var tabScale = settings.tabScale; var tabScaleCount = []; var tabSc = {}; var zmiana = settings.countImage; $(element).find('ul li').css('visibility','visible'); for(var i=0;i0){ tabScaleCount.push(tabScale[i]); tabSc[tabScale[i]] = zmiana; } zmiana--; } var maxCell = 0; var countImg = settings.countImage; $(window).on('resize', function(){ var screen_width = screen.width; var maxCell = 1; function isBigEnough(element, index, array) { return element <= screen_width; } filtered = tabScaleCount.filter(isBigEnough); if(typeof filtered[0] != 'undefined'){ maxCell = tabSc[filtered[0]]; } if(maxCell != countDef){ countDef = maxCell; if(countDef == 1){ changeCountOne(); } else{ changeCount(); } } //var procIgw = Math.round((100/maxCell) * 100) / 100 var procIgw = Math.floor(100/maxCell); //$(element).find('ul li').css('width',procIgw+'%'); }).trigger('resize'); }); return this; }; $.fn.catGallery3 = function(options) { return this.each(function(key, value){ var element = $(this); if (element.data('c3')) return element.data('c3'); var c3 = new catGallery3(this, options); element.data('c3', c3); }); }; $.fn.catGallery3.defaults = { countImage: 3, widthGallery : 990, widthImg: 100 } })( jQuery );