PageSourceSearch

https://thearc.org/wp-content/themes/enfold/config-templatebuilder…/masonry_entries/masonry_entries.js?ver=7.1

js thearc.org collected 2026-10-01 09:03:10 UTC 9,649 bytes, 340 lines download raw bytes

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						post_id = masonry.data( 'post_id' ),
142						container = masonry.find('.av-masonry-container'),
143						items = masonry.find('.av-masonry-entry'),
144						loader = $.avia_utilities.loading(),
145						finished = function(){ loading = false; loader.hide(); the_body.trigger('av_resize_finished'); };
146
147					if( 'undefined' != typeof post_id )
148					{
149						data.post_id = post_id;
150					}
151
152					//calculate a new offset
153					if( ! data.offset )
154					{
155						data.offset = 0;
156					}
157
158					data.offset += data.items;
159					data.action = 'avia_ajax_masonry_more';
160					data.loaded = []; //prevents duplicate entries from beeing loaded when randomized is active
161
162					items.each( function()
163					{
164						var item_id = $(this).data('av-masonry-item');
165						if( item_id )
166						{
167							data.loaded.push( item_id );
168						}
169					});
170
171					$.ajax({
172						url: avia_framework_globals.ajaxurl,
173						type: "POST",
174						data: data,
175						beforeSend: function()
176						{
177							loader.show();
178						},
179						success: function(response)
180						{
181							if( response.indexOf("{av-masonry-loaded}") !== -1 )
182							{
183								//fetch the response. if any php warnings were displayed before rendering of the items the are removed by the string split
184								var response  = response.split('{av-masonry-loaded}'),
185									new_items = $(response.pop()).filter('.isotope-item');
186
187								//check if we got more items than we need. if not we have reached the end of items
188								if( new_items.length > data.items )
189								{
190									new_items = new_items.not( new_items.last() );
191								}
192								else
193								{
194									current.addClass('av-masonry-no-more-items');
195								}
196
197								//	caused by ajax call - remove to prevent immediate animation
198								new_items.find( '.avia-animate-admin-preview' ).removeClass( 'avia-animate-admin-preview' );
199
200								//	hide content to avoid flicker in masonry entries
201								if( new_items.find( '.avia-curtain-reveal-overlay' ).length > 0 )
202								{
203									new_items.css( { visibility: 'hidden' } );
204								}
205
206								var load_container = $('<div class="loadcontainer"></div>').append(new_items);
207
208								$.avia_utilities.preload(
209								{
210									container: load_container,
211									single_callback: function()
212									{
213										var links = masonry.find('.av-masonry-sort a'),
214											filter_container = masonry.find('.av-sort-by-term'),
215											allowed_filters = filter_container.data("av-allowed-sort");
216
217										filter_container.hide();
218
219										loader.hide();
220										container.isotope( 'insert', new_items );
221										$.avia_utilities.avia_ajax_call( masonry );
222
223										setTimeout( function(){ methods.show_bricks( new_items, finished ); }, 150 );
224										setTimeout( function(){ the_win.trigger('av-height-change'); }, 550 );
225
226										if( links )
227										{
228											$( links ).each( function( filterlinkindex )
229											{
230												var filterlink = $(this),
231												sort = filterlink.data('filter');
232
233												if( new_items )
234												{
235													$( new_items ).each( function( itemindex )
236													{
237														var item = $(this);
238
239														if( item.hasClass( sort ) && allowed_filters.indexOf( sort ) !== -1 )
240														{
241															var term_count = filterlink.find('.avia-term-count').text();
242															filterlink.find('.avia-term-count').text(' ' + ( parseInt( term_count ) + 1 ) + ' ' );
243
244															if( filterlink.hasClass('avia_hide_sort') )
245															{
246																filterlink.removeClass('avia_hide_sort').addClass('avia_show_sort');
247																masonry.find('.av-masonry-sort .' + sort + '_sep').removeClass('avia_hide_sort').addClass('avia_show_sort');
248																masonry.find('.av-masonry-sort .av-sort-by-term').removeClass('hidden');
249															}
250														}
251													});
252												}
253											});
254										}
255
256										filter_container.fadeIn();
257									}
258								});
259							}
260							else
261							{
262								finished();
263							}
264						},
265						error: finished,
266						complete: function()
267						{
268							setTimeout(function() { the_win.trigger('debouncedresize'); }, 500);
269						}
270					});
271				}
272			};
273
274		return this.each( function()
275		{
276			var masonry	= $(this),
277				container = masonry.find('.av-masonry-container'),
278				bricks = masonry.find('.isotope-item'),
279				filter = masonry.find('.av-masonry-sort').css({visibility:"visible", opacity:0}).on('click', 'a', methods.masonry_filter),
280				load_more = masonry.find('.av-masonry-load-more').css({visibility:"visible", opacity:0});
281
282			//	hide content to avoid flicker in masonry entries
283			if( bricks.find( '.avia-curtain-reveal-overlay' ).length > 0 )
284			{
285				bricks.css( { visibility: 'hidden' } );
286			}
287
288			$.avia_utilities.preload(
289			{
290				container: container,
291				single_callback: function()
292				{
293					var start_animation = function()
294					{
295						filter.animate({opacity:1}, 400);
296
297						//fix for non aligned elements because of scrollbar
298						if( container.outerHeight() + container.offset().top + $('#footer').outerHeight() > $(window).height() )
299						{
300							$('html').css({'overflow-y':'scroll'});
301						}
302
303						methods.applyMasonry( container, false, function()
304						{
305							masonry.addClass('avia_sortable_active');
306							container.removeClass('av-js-disabled');
307						});
308
309						methods.show_bricks( bricks, function()
310						{
311							load_more.css( {opacity:1} ).on( 'click', methods.loadMore );
312						});
313
314						//container.isotope( 'reLayout' );
315					};
316
317					if( isMobile && mobile_no_animation )
318					{
319						//	start immediatly
320						start_animation();
321					}
322					else
323					{
324						masonry.waypoint( start_animation, { offset: '80%'} );
325					}
326
327					// update columnWidth on window resize
328					$(window).on( 'debouncedresize', function()
329					{
330						methods.applyMasonry( container, false, function()
331						{
332							masonry.addClass('avia_sortable_active');
333						});
334					});
335				}
336			});
337		});
338	};
339
340}(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.