1/******************************************************************************/ 2/******************************************************************************/ 3 4;(function($,doc,win) 5{ 6 "use strict"; 7 8 var GalleryMasonry=function(object,option) 9 { 10 /**********************************************************************/ 11 12 var $self=this; 13 var $this=$(object); 14 var $option=option; 15 16 /**********************************************************************/ 17 18 this.build=function() 19 { 20 var i=0; 21 var imageList=$this.find('img'); 22 var imageListCount=imageList.length; 23 24 imageList.each(function() 25 { 26 $(this).one('load',function() 27 { 28 if((++i)===imageListCount) 29 { 30 $self.createCategoryList(); 31 $self.createIsotope(true); 32 $this.css('opacity','1'); 33 } 34 }).each(function() 35 { 36 if(this.complete) $(this).load(); 37 }); 38 }); 39 }; 40 41 /**********************************************************************/ 42 43 this.setSelected=function(object) 44 { 45 $this.find('.theme-component-gallery-masonry-filter-list>li>a').removeClass('theme-state-selected'); 46 $(object).addClass('theme-state-selected'); 47 }; 48 49 /**********************************************************************/ 50 51 this.createIsotope=function(bind) 52 { 53 var glutter=60; 54 var marginBottom=60; 55 56 var columnCount=3; 57 var columnWidth=350; 58 59 var imageList=$this.children('ul.theme-component-gallery-masonry-image-list'); 60 var imageListWidth=imageList.actual('width'); 61 62 if(typeof(bind)==='undefined') bind=true; 63 64 if(imageListWidth<=300) 65 { 66 glutter=0; 67 columnCount=1; 68 marginBottom=30; 69 } 70 else if(imageListWidth<=460) 71 { 72 glutter=30; 73 columnCount=2; 74 marginBottom=30; 75 } 76 else if(imageListWidth<=760) 77 { 78 glutter=30; 79 columnCount=2; 80 marginBottom=30; 81 } 82 83 columnWidth=(imageListWidth-((columnCount-1)*glutter))/columnCount; 84 85 imageList.children('li').css('margin-bottom',marginBottom+'px').each(function() 86 { 87 var widthCount=parseInt($(this).data('width-count'),10); 88 89 if(widthCount===1) $(this).css('width',columnWidth); 90 else 91 { 92 $(this).css('width',(columnWidth*widthCount)+(glutter*(widthCount-1))); 93 } 94 }); 95 96 $self.setFilter(); 97 98 var itemReveal=Isotope.Item.prototype.reveal; 99 Isotope.Item.prototype.reveal=function() 100 { 101 itemReveal.apply(this,arguments); 102 103 var link=$(this.element).find('a'); 104 link.attr('data-fancybox-group',link.attr('data-fancybox-group-temp')).removeAttr('data-fancybox-group-temp'); 105 }; 106 107 var itemHide=Isotope.Item.prototype.hide; 108 Isotope.Item.prototype.hide=function() 109 { 110 itemHide.apply(this,arguments); 111 var link=$(this.element).find('a'); 112 link.attr('data-fancybox-group-temp',link.attr('data-fancybox-group')).removeAttr('data-fancybox-group'); 113 }; 114 115 if(marginBottom==30) 116 $this.css('padding-bottom','30px'); 117 118 imageList.isotope( 119 { 120 filter : '.theme-state-filter', 121 masonry: 122 { 123 gutter : glutter 124 } 125 }); 126 127 if(bind) 128 { 129 $(window).resize(function() 130 { 131 $self.createIsotope(false); 132 }); 133 } 134 }; 135 136 /**********************************************************************/ 137 138 this.setFilter=function() 139 { 140 var imageList=$this.children('ul.theme-component-gallery-masonry-image-list'); 141 var imageListItem=imageList.children('li'); 142 143 imageListItem.removeClass('theme-state-filter'); 144 145 var filterList=$this.children('.theme-component-gallery-masonry-filter-list'); 146 if(filterList.length!==1) 147 { 148 imageListItem.addClass('theme-state-filter'); 149 return; 150 } 151 152 var categoryIdSelected=parseInt(filterList.find('a.theme-state-selected').attr('data-category-id'),10); 153 if(parseInt(categoryIdSelected,10)===-1) 154 { 155 imageListItem.addClass('theme-state-filter'); 156 imageListItem.first().children('a').addClass('theme-state-selected'); 157 return; 158 } 159 160 imageList.children('li').each(function() 161 { 162 if(String($(this).attr('data-category'))!=='undefined') 163 { 164 var c=JSON.parse($(this).attr('data-category')); 165 for(var i in c) 166 { 167 if(parseInt(c[i].id,10)===categoryIdSelected) 168 $(this).addClass('theme-state-filter'); 169 } 170 } 171 }); 172 }; 173 174 /**********************************************************************/ 175 176 this.createCategoryList=function() 177 { 178 if(!$this.hasClass('theme-component-gallery-masonry-with-filter')) return; 179 180 var html=''; 181 var category=[]; 182 var imageList=$this.children('ul.theme-component-gallery-masonry-image-list'); 183 var imageListItem=imageList.children('li'); 184 185 imageListItem.each(function() 186 { 187 if(String($(this).attr('data-category'))!=='undefined') 188 { 189 var c=JSON.parse($(this).attr('data-category')); 190 for(var i in c) category[c[i].id]=c[i].name; 191 } 192 }); 193 194 if(!category.length) return; 195 196 html+='<li><a href="#" data-category-id="-1">'+themeOption.config.text.all+'</a></li>'; 197 198 for(var i in category) html+='<li><a href="#" data-category-id="'+i+'">'+category[i]+'</li>'; 199 200 $this.prepend('<ul class="theme-component-gallery-masonry-filter-list">'+html+'</ul>'); 201 202 var filterList=$this.children('.theme-component-gallery-masonry-filter-list'); 203 filterList.find('>li>a').on('click',function(e) 204 { 205 e.preventDefault(); 206 $self.setSelected(this); 207 $self.createIsotope(); 208 }); 209 210 filterList.children('li:not(:first)').sort(function(a,b) { return(($(b).text())<($(a).text()) ? 1 : -1); }).appendTo(filterList); 211 212 filterList.find('>li:first>a').addClass('theme-state-selected'); 213 }; 214 215 /**********************************************************************/ 216 }; 217 218 /**************************************************************************/ 219 220 $.fn.galleryMasonry=function(option) 221 { 222 return this.each(function() 223 { 224 var object=new GalleryMasonry(this,option); 225 object.build(); 226 return(object); 227 }); 228 }; 229 230 /**************************************************************************/ 231 232})(jQuery,document,window); 233 234/******************************************************************************/ 235/******************************************************************************/
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.