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