1// ------------------------------------------------------------------------------------------- 2// Masonry 3// ------------------------------------------------------------------------------------------- 4 5(function($) 6{ 7 "use strict"; 8 9 $.fn.avia_masonry = function(options) 10 { 11 //return if we didnt find anything 12 if(!this.length) return this; 13 14 var the_body = $('body'), 15 the_win = $(window), 16 isMobile = $.avia_utilities.isMobile, 17 loading = false, 18 methods = { 19 20 21 masonry_filter: function() 22 { 23 var current = $(this), 24 linktext = current.html(), 25 selector = current.data('filter'), 26 masonry = current.parents('.av-masonry:eq(0)'), 27 container = masonry.find('.av-masonry-container:eq(0)'), 28 links = masonry.find('.av-masonry-sort a'), 29 activeCat = masonry.find('.av-current-sort-title'); 30 31 links.removeClass('active_sort'); 32 current.addClass('active_sort'); 33 container.attr('id', 'masonry_id_'+selector); 34 35 if(activeCat.length) activeCat.html(linktext); 36 37 methods.applyMasonry(container, selector, function() 38 { 39 container.css({overflow:'visible'}); 40 }); 41 42 setTimeout(function() { the_win.trigger('debouncedresize'); }, 500); 43 44 return false; 45 }, 46 47 applyMasonry: function(container, selector, callback) 48 { 49 var filters = selector ? {filter: '.'+selector} : {}; 50 51 filters['layoutMode'] = 'packery'; 52 filters['packery'] = {gutter:0}; 53 filters['percentPosition'] = true; 54 filters['itemSelector'] = "a.isotope-item, div.isotope-item"; 55 56 container.isotope(filters, function() 57 { 58 the_win.trigger('av-height-change'); 59 }); 60 61 if(typeof callback === 'function') 62 { 63 setTimeout(callback, 0); 64 } 65 }, 66 67 show_bricks: function(bricks, callback) 68 { 69 bricks.each(function(i) 70 { 71 var currentLink = $(this), 72 browserPrefix = $.avia_utilities.supports('transition'), 73 multiplier = isMobile ? 0 : 100; 74 75 setTimeout(function() 76 { 77 if(browserPrefix === false) 78 { 79 currentLink.css({visibility:"visible", opacity:0}).animate({opacity:1},1500); 80 } 81 else 82 { 83 currentLink.addClass('av-masonry-item-loaded'); 84 } 85 86 if(i == bricks.length - 1 && typeof callback == 'function') 87 { 88 callback.call(); 89 the_win.trigger('av-height-change'); 90 } 91 92 }, (multiplier * i)); 93 }); 94 }, 95 96 loadMore: function(e) 97 { 98 e.preventDefault(); 99 100 if(loading) return false; 101 102 loading = true; 103 104 var current = $(this), 105 data = current.data(), 106 masonry = current.parents('.av-masonry:eq(0)'), 107 container = masonry.find('.av-masonry-container'), 108 items = masonry.find('.av-masonry-entry'), 109 loader = $.avia_utilities.loading(), 110 finished = function(){ loading = false; loader.hide(); the_body.trigger('av_resize_finished'); }; 111 112 //calculate a new offset 113 if(!data.offset){ data.offset = 0; } 114 data.offset += data.items; 115 data.action = 'avia_ajax_masonry_more'; 116 data.loaded = []; //prevents duplicate entries from beeing loaded when randomized is active 117 118 items.each(function(){ 119 var item_id = $(this).data('av-masonry-item'); 120 if(item_id) data.loaded.push( item_id ); 121 }); 122 123 $.ajax({ 124 url: avia_framework_globals.ajaxurl, 125 type: "POST", 126 data:data, 127 beforeSend: function() 128 { 129 loader.show(); 130 }, 131 success: function(response) 132 { 133 if(response.indexOf("{av-masonry-loaded}") !== -1) 134 { 135 //fetch the response. if any php warnings were displayed before rendering of the items the are removed by the string split 136 var response = response.split('{av-masonry-loaded}'), 137 new_items = $(response.pop()).filter('.isotope-item'); 138 139 //check if we got more items than we need. if not we have reached the end of items 140 if(new_items.length > data.items) 141 { 142 new_items = new_items.not(':last'); 143 } 144 else 145 { 146 current.addClass('av-masonry-no-more-items'); 147 } 148
149 var load_container = $('<div class="loadcontainer"></div>').append(new_items); 150 151 152 153 $.avia_utilities.preload({container: load_container, single_callback: function() 154 { 155 var links = masonry.find('.av-masonry-sort a'), 156 filter_container = masonry.find('.av-sort-by-term'), 157 allowed_filters = filter_container.data("av-allowed-sort"); 158 159 filter_container.hide(); 160 161 loader.hide(); 162 container.isotope( 'insert', new_items); 163 $.avia_utilities.avia_ajax_call(masonry); 164 setTimeout( function(){ methods.show_bricks( new_items , finished); },150); 165 setTimeout(function(){ the_win.trigger('av-height-change'); }, 550); 166 if(links) 167 { 168 $(links).each(function(filterlinkindex) 169 { 170 var filterlink = $(this), 171 sort = filterlink.data('filter'); 172 173 if(new_items) 174 { 175 $(new_items).each(function(itemindex){ 176 var item = $(this); 177 178 if(item.hasClass(sort) && allowed_filters.indexOf(sort) !== -1) 179 { 180 var term_count = filterlink.find('.avia-term-count').text(); 181 filterlink.find('.avia-term-count').text(' ' + (parseInt(term_count) + 1) + ' '); 182 183 if(filterlink.hasClass('avia_hide_sort')) 184 { 185 filterlink.removeClass('avia_hide_sort').addClass('avia_show_sort'); 186 masonry.find('.av-masonry-sort .'+sort+'_sep').removeClass('avia_hide_sort').addClass('avia_show_sort'); 187 masonry.find('.av-masonry-sort .av-sort-by-term').removeClass('hidden'); 188 } 189 } 190 }); 191 } 192 }); 193 194 } 195 196 filter_container.fadeIn(); 197 } 198 }); 199 } 200 else 201 { 202 finished(); 203 } 204 }, 205 error: finished, 206 complete: function() 207 { 208 setTimeout(function() { the_win.trigger('debouncedresize'); }, 500); 209 } 210 }); 211 } 212 213 }; 214 215 return this.each(function() 216 { 217 var masonry = $(this), 218 container = masonry.find('.av-masonry-container'), 219 bricks = masonry.find('.isotope-item'), 220 filter = masonry.find('.av-masonry-sort').css({visibility:"visible", opacity:0}).on('click', 'a', methods.masonry_filter), 221 load_more = masonry.find('.av-masonry-load-more').css({visibility:"visible", opacity:0}); 222 223 $.avia_utilities.preload({container: container, single_callback: function() 224 { 225 var start_animation = function() 226 { 227 filter.animate({opacity:1}, 400); 228 229 //fix for non aligned elements because of scrollbar 230 if(container.outerHeight() + container.offset().top + $('#footer').outerHeight() > $(window).height()) 231 { 232 $('html').css({'overflow-y':'scroll'}); 233 } 234 235 methods.applyMasonry(container, false, function() 236 { 237 masonry.addClass('avia_sortable_active'); 238 container.removeClass('av-js-disabled '); 239 }); 240 241 methods.show_bricks(bricks, function() 242 { 243 load_more.css({opacity:1}).on('click', methods.loadMore); 244 }); 245 246 //container.isotope( 'reLayout' ); 247 248 }; 249 250 if(isMobile) 251 { 252 start_animation(); 253 } 254 else 255 { 256 masonry.waypoint(start_animation , { offset: '80%'} ); 257 } 258 259 // update columnWidth on window resize 260 $(window).on( 'debouncedresize', function() 261 { 262 methods.applyMasonry(container, false, function() 263 { 264 masonry.addClass('avia_sortable_active'); 265 }); 266 }); 267 } 268 }); 269 270 271 }); 272 }; 273 274 275}(jQuery));
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.