PageSourceSearch

https://divigalleryextended.com/wp-content/plugins/divi-gallery-ex…/assets/script.min.js?ver=2.4.0

js divigalleryextended.com collected 2026-10-05 09:52:50 UTC 18,670 bytes, 475 lines download raw bytes

1jQuery( document ).ready( function($) {
2	// This script is loaded both on the frontend page and in the Visual Builder.
3	$.fn.MasonryGalleryExtendedInsertAt = function( index, element ) {
4		let lastIndex = this.children().length;
5		if ( index < 0 ) {
6			index = Math.max(0, lastIndex + 1 + index);
7		}
8		this.append(element);
9		if ( index < lastIndex ) {
10			this.children().eq(index).before(this.children().last());
11		}
12		return this;
13	}
14	$.fn.MasonryGalleryExtendedPagination = function( $options = {} ) {
15		let $defaults = {
16				paginationClass: 'el_masonry_gallery_pagination',
17				hideOnlyOnePage: true,
18				totalPages: 1,
19				visiblePages: 10,
20				startPage: 1,
21				initiateStartPageClick: false,
22				first: false,
23				last: false,
24				prev: false,
25				next: false,
26			},
27			$pagination = this;
28
29		$pagination.twbsPagination( 'destroy' );
30
31		$options = $.extend( {}, $defaults, $options );
32		$pagination.twbsPagination( $options );
33	}
34
35	// Masonry Gallery Script.
36	if ( $(document).find('.el_masonry_gallery').length > 0 ) {
37		$('.el_masonry_gallery').each( function() {
38			dge_init_masonry_gallery( $( this ) );
39		} );
40	}
41} );
42
43// Init masonry gallery.
44function dge_init_masonry_gallery( $this ) {
45	let $         = jQuery,
46		$wrapper  = $this.find('.el_masonry_gallery_wrapper'),
47		$inner    = $this.find('.el_masonry_gallery_module__inner');
48		$options  = {
49			itemSelector: '.el_masonry_gallery_item',
50			layoutMode: 'masonry',
51			percentPosition: true,
52			resize: true,
53			transitionDuration: parseInt( $wrapper.data('isotope_transition_duration') ),
54			masonry: {
55				columnWidth: '.el_masonry_gallery_item',
56				gutter: '.el_masonry_gallery_item_gutter'
57			}
58		};
59
60	let masonryLoadTrigger = false;
61
62	// Display again, if it hide due to pagination.
63	$wrapper.find( '.el_masonry_gallery_item' ).css( 'display', 'inline-block' );
64
65	// Pagination Filter for Isotope.
66	if ( $this.find('.el_masonry_gallery_pagination_wrapper').length > 0 ) {
67		let $paginWrapper = $this.find( '.el_masonry_gallery_pagination_wrapper' ),
68			$perPage      = $paginWrapper.attr( 'data-images_per_page' );
69
70		$options.filter = function() {
71			let $index = $(this).index();
72			return parseInt($index) > 0 && parseInt($index) <= $perPage;
73		}
74	}
75
76	let $gallery = $inner.isotope( $options );
77	$gallery.imagesLoaded( function() {
78		$gallery.isotope( 'layout' );
79		$gallery.isotope( 'reloadItems' );
80	} );
81
82	// Pagination.
83	if ( $this.find( '.el_masonry_gallery_pagination_wrapper ul' ).length > 0 ) {
84		let $paginWrapper = $this.find('.el_masonry_gallery_pagination_wrapper'),
85			$pagination   = $paginWrapper.find('ul'),
86			$perPage      = isNaN( $paginWrapper.attr('data-images_per_page') ) || 0 === parseInt( $paginWrapper.attr('data-images_per_page') ) ? 12 : parseInt( $paginWrapper.attr('data-images_per_page') ),
87			$totalPages   = parseInt( Math.ceil( parseInt( $paginWrapper.data('total_images') ) / $perPage ) ),
88			$options      = {
89				totalPages: $totalPages,
90				onPageClick: function (event, page) {
91					let $startIndex = 0;
92					let $endIndex = $perPage;
93					if ( 1 !== page ) {
94						$startIndex = ( $perPage * ( page - 1 ) );
95						$endIndex = $perPage * page;
96					}
97					$gallery.isotope( {
98						filter: function() {
99							let $index = $(this).index();
100							return parseInt($index) > $startIndex && parseInt($index) <= $endIndex;
101						}
102					} ).isotope( 'revealItemElements', $wrapper.find('.el_masonry_gallery_item').slice( $startIndex, $endIndex ) ).isotope('layout');
103
104					if ( $this.offset().top > 0 ) {
105						let topHeaderHeight  = 0,
106							mainHeaderHeight = 0,
107							tbHeaderHeight   = 0;
108
109						if ( $('body').find('#top-header').length > 0 && $('body').hasClass('et_fixed_nav') ) {
110							topHeaderHeight = parseFloat( $('#top-header').innerHeight() );
111						}
112						if ( $('body').find('#main-header').length > 0 && $('body').hasClass('et_fixed_nav') ) {
113							mainHeaderHeight = parseFloat( $('#main-header').innerHeight() );
114						}
115						if ( $('body').find('.et-l--header').length > 0 && $('body').find('.et-l--header .et_builder_inner_content').hasClass('has_et_pb_sticky') ) {
116							tbHeaderHeight = parseFloat( $('.et-l--header').innerHeight() );
117						}
118
119						let headerHeight = topHeaderHeight + mainHeaderHeight + tbHeaderHeight + 50;
120						$( 'html, body' ).animate( {
121							scrollTop: ( $this.offset().top - headerHeight )
122						} );
123					}
124				}
125			};
126
127		if ( 'on' === $paginWrapper.attr('data-show_prev_next') ) {
128			$options.prev = $paginWrapper.attr('data-prev_text');
129			$options.next = $paginWrapper.attr('data-next_text');
130		}
131		if ( $perPage && '' !== $perPage && ! isNaN( $perPage ) ) {
132			$pagination.MasonryGalleryExtendedPagination( $options );
133		}
134	}
135
136	// Load more button instead of pagination.
137	if ( $this.find('.el_masonry_gallery_pagination_wrapper .el-masonry-gallery-load-more').length > 0 ) {
138		const $paginWrapper = $this.find('.el_masonry_gallery_pagination_wrapper');
139		const $perPage      = isNaN( $paginWrapper.data('images_per_page') ) || 0 === parseInt( $paginWrapper.data('images_per_page') ) ? 12 : parseInt( $paginWrapper.data('images_per_page') );
140		
141		$this.on( 'click', '.el-masonry-gallery-load-more', function() {
142
143			// Check if active category.
144			const activeCat = $wrapper.find( '.el_masonry_gallery_filter_categories .el_masonry_gallery_active_category' ).attr( 'data-category' );
145
146			// Get total images.
147			let totalImages = $paginWrapper.attr( 'data-total_images' );
148			if ( activeCat && '' !== activeCat ) {
149				totalImages = $wrapper.find( '.el_masonry_gallery_item' ).length;
150			}
151			
152			// Calculate total pages.
153			const $totalPages = parseInt( Math.ceil( parseInt( totalImages ) / $perPage ) );
154
155			let page = parseInt( $paginWrapper.attr( 'data-load-page' ) );
156
157			// If all pages are visibled.
158			if ( page > $totalPages ) {
159				$( this ).hide();
160				return;
161			}
162
163			let $startIndex = 0;
164			let $endIndex   = $perPage;
165			if ( 1 !== page ) {
166				$endIndex = $perPage * page;
167			}
168
169			$gallery.isotope( {
170				filter: function() {
171					let $index = $(this).index();
172					return parseInt($index) > $startIndex && parseInt($index) <= $endIndex;
173				}
174			} ).isotope( 'revealItemElements', $wrapper.find('.el_masonry_gallery_item').slice( $startIndex, $endIndex ) ).isotope( 'layout' );
175
176			// If all pages are visibled.
177			if ( page == $totalPages ) {
178				$( this ).hide();
179			}
180			
181			$paginWrapper.attr( 'data-load-page', ( parseInt( page ) + 1 ) );
182		} );
183	}
184
185	// Category Filter.
186	let $detachedImages  = [];
187	let $detachedIndices = [];
188	$this.find( '.el_masonry_gallery_filter_categories li' ).on( 'click', function() {
189		if ( $(this).hasClass( 'el_masonry_gallery_active_category' ) ) {
190			return false;
191		}
192
193		if ( $detachedImages && $detachedIndices && $detachedIndices.length === $detachedImages.length ) {
194			$.map( $detachedImages, function( value, key ) {
195				$inner.MasonryGalleryExtendedInsertAt( $detachedIndices[key], $(value) );
196			} );
197		} else if ( $detachedImages ) {
198			$inner.append( $detachedImages );
199		}
200
201		// Reset tracking after reinsertion, so the next filter starts from a
202		// clean slate instead of accumulating stale entries from every prior
203		// click (mismatched entries here caused items to end up detached at
204		// the wrong index, invisible but still occupying layout space).
205		$detachedImages  = [];
206		$detachedIndices = [];
207
208		$(this).parent( '.el_masonry_gallery_filter_categories' ).find( 'li' ).removeClass( 'el_masonry_gallery_active_category' );
209		$(this).addClass( 'el_masonry_gallery_active_category' );
210		let $category = $(this).data( 'category' );
211
212		if ( '' !== $category ) {
213			let $elements = [];
214			$inner.find( '.el_masonry_gallery_item img' ).each( function() {
215				if ( $(this).data('categories') ) {
216					let $imageCats = $(this).attr('data-categories').split(',');
217					$imageCats = $.map( $imageCats, function( a ) {
218						return parseInt(a);
219					} );
220					if ( -1 === $.inArray( $category, $imageCats ) ) {
221						$detachedIndices.push( $(this).closest('.el_masonry_gallery_item').index() );
222					} else {
223						$elements.push( $(this).closest('.el_masonry_gallery_item') );
224					}
225				} else {
226					$detachedIndices.push( $(this).closest('.el_masonry_gallery_item').index() );
227				}
228			} );
229
230			$gallery.isotope( {
231				filter: function() {
232					if ( $(this).find('img').data('categories') ) {
233						let $imageCats = $(this).find('img').attr('data-categories').split(',');
234						$imageCats = $.map( $imageCats, function( a ) {
235							return parseInt( a );
236						} );
237						if ( -1 !== $.inArray( $category, $imageCats ) ) {
238							return $( this );
239						} else {
240							$detachedImages.push( $(this).detach() );
241						}
242					} else {
243						$detachedImages.push( $(this).detach() );
244					}
245				}
246			} ).isotope( 'revealItemElements', $elements ).isotope( 'layout' );
247
248			// Re-render Pagination.
249			if ( $this.find( '.el_masonry_gallery_pagination_wrapper ul' ).length > 0 ) {
250				let $paginWrapper = $this.find( '.el_masonry_gallery_pagination_wrapper' ),
251					$pagination   = $paginWrapper.find('ul'),
252					$perPage      = isNaN( $paginWrapper.attr('data-images_per_page') ) || 0 === parseInt( $paginWrapper.attr('data-images_per_page') ) ? 12 : parseInt( $paginWrapper.attr('data-images_per_page') ),
253					$totalPages   = parseInt( Math.ceil( parseInt( $wrapper.find('.el_masonry_gallery_item').length ) / $perPage ) ),
254					$options      = {
255						totalPages: $totalPages,
256						initiateStartPageClick: true,
257						onPageClick: function (event, page) {
258							let $startIndex = 0;
259							let $endIndex = $perPage;
260							if ( 1 !== page ) {
261								$startIndex = ( $perPage * ( page - 1 ) );
262								$endIndex = $perPage * page;
263							}
264							$gallery.isotope({
265								filter: function() {
266									let $index = $(this).index();
267									return parseInt($index) > $startIndex && parseInt($index) <= $endIndex;
268								}
269							} ).isotope( 'revealItemElements', $wrapper.find('.el_masonry_gallery_item').slice( $startIndex, $endIndex ) ).isotope('layout');
270
271							if ( $this.offset().top > 0 && masonryLoadTrigger === true ) {
272								let topHeaderHeight  = 0,
273									mainHeaderHeight = 0,
274									tbHeaderHeight   = 0;
275
276								if ( $('body').find('#top-header').length > 0 && $('body').hasClass('et_fixed_nav') ) {
277									topHeaderHeight = parseFloat( $('#top-header').innerHeight() );
278								}
279								if ( $('body').find('#main-header').length > 0 && $('body').hasClass('et_fixed_nav') ) {
280									mainHeaderHeight = parseFloat( $('#main-header').innerHeight() );
281								}
282								if ( $('body').find('.et-l--header').length > 0 && $('body').find('.et-l--header .et_builder_inner_content').hasClass('has_et_pb_sticky') ) {
283									tbHeaderHeight = parseFloat( $('.et-l--header').innerHeight() );
284								}
285
286								let headerHeight = topHeaderHeight + mainHeaderHeight + tbHeaderHeight + 50;
287								$( 'html, body' ).animate( {
288									scrollTop: ( $this.offset().top - headerHeight )
289								} );
290							}
291							masonryLoadTrigger = true;
292						}
293					};
294
295				if ( 'on' === $paginWrapper.attr('data-show_prev_next') ) {
296					$options.prev = $paginWrapper.attr('data-prev_text');
297					$options.next = $paginWrapper.attr('data-next_text');
298				}
299
300				$pagination.MasonryGalleryExtendedPagination( $options );
301
302			} else if ( $this.find('.el_masonry_gallery_pagination_wrapper .el-masonry-gallery-load-more').length > 0 ) {
303				// Re-render Load more.
304				let $paginWrapper = $this.find( '.el_masonry_gallery_pagination_wrapper' ),
305					$pagination   = $paginWrapper.find( '.el-masonry-gallery-load-more' ),
306					$perPage      = isNaN( $paginWrapper.attr('data-images_per_page') ) || 0 === parseInt( $paginWrapper.attr('data-images_per_page') ) ? 12 : parseInt( $paginWrapper.attr('data-images_per_page') ),
307					$totalPages   = parseInt( Math.ceil( parseInt( $wrapper.find('.el_masonry_gallery_item').length ) / $perPage ) );
308
309				$pagination.hide();
310				if ( $totalPages > 1 ) {
311					$paginWrapper.attr( 'data-total_images', parseInt( $wrapper.find('.el_masonry_gallery_item').length ) );
312					$paginWrapper.attr( 'data-load-page', 2 );
313
314					$gallery.isotope( {
315						filter: function() {
316							let $index = $(this).index();
317							return parseInt($index) > 0 && parseInt($index) <= $perPage;
318						}
319					} ).isotope( 'revealItemElements', $wrapper.find('.el_masonry_gallery_item').slice( 0, $perPage ) ).isotope('layout');
320					$pagination.show();
321				}
322			}
323		} else {
324
325			$gallery.isotope( { filter: '*' } );
326
327			// Re-render Pagination.
328			if ( $this.find( '.el_masonry_gallery_pagination_wrapper ul' ).length > 0 ) {
329				let $paginWrapper = $this.find( '.el_masonry_gallery_pagination_wrapper' ),
330					$pagination   = $paginWrapper.find('ul'),
331					$perPage      = isNaN( $paginWrapper.attr('data-images_per_page') ) || 0 === parseInt( $paginWrapper.attr('data-images_per_page') ) ? 12 : parseInt( $paginWrapper.attr('data-images_per_page') ),
332					$totalPages   = parseInt( Math.ceil( parseInt( $paginWrapper.data('total_images') ) / $perPage ) ),
333					$options      = {
334						totalPages: $totalPages,
335						initiateStartPageClick: true,
336						onPageClick: function (event, page) {
337							let $startIndex = 0;
338							let $endIndex = $perPage;
339							if ( 1 !== page ) {
340								$startIndex = ( $perPage * ( page - 1 ) );
341								$endIndex = $perPage * page;
342							}
343							$gallery.isotope( {
344								filter: function() {
345									let $index = $(this).index();
346									return parseInt($index) > $startIndex && parseInt($index) <= $endIndex;
347								}
348							} ).isotope( 'revealItemElements', $wrapper.find( '.el_masonry_gallery_item' ).slice( $startIndex, $endIndex ) ).isotope('layout');
349						}
350					};
351
352				if ( 'on' === $paginWrapper.attr('data-show_prev_next') ) {
353					$options.prev = $paginWrapper.attr('data-prev_text');
354					$options.next = $paginWrapper.attr('data-next_text');
355				}
356
357				$pagination.MasonryGalleryExtendedPagination( $options );
358			} else if ( $this.find('.el_masonry_gallery_pagination_wrapper .el-masonry-gallery-load-more').length > 0 ) {
359				// Re-render Load more.
360				let $paginWrapper = $this.find( '.el_masonry_gallery_pagination_wrapper' ),
361					$pagination   = $paginWrapper.find( '.el-masonry-gallery-load-more' ),
362					$perPage      = isNaN( $paginWrapper.attr('data-images_per_page') ) || 0 === parseInt( $paginWrapper.attr('data-images_per_page') ) ? 12 : parseInt( $paginWrapper.attr('data-images_per_page') ),
363					$totalPages   = parseInt( Math.ceil( parseInt( $wrapper.find('.el_masonry_gallery_item').length ) / $perPage ) );
364
365				$pagination.hide();
366				if ( $totalPages > 1 ) {
367					$paginWrapper.attr( 'data-total_images', parseInt( $wrapper.find('.el_masonry_gallery_item').length ) );
368					$paginWrapper.attr( 'data-load-page', 2 );
369
370					$gallery.isotope( {
371						filter: function() {
372							let $index = $(this).index();
373							return parseInt($index) > 0 && parseInt($index) <= $perPage;
374						}
375					} ).isotope( 'revealItemElements', $wrapper.find('.el_masonry_gallery_item').slice( 0, $perPage ) ).isotope('layout');
376					$pagination.show();
377				}
378			}
379		}
380	} );
381
382	// Lightbox.
383	if ( 'on' === $wrapper.data('click_trigger') || 'lightbox' === $wrapper.data('click_trigger') || 'zoom_n_link' === $wrapper.data('click_trigger') ) {
384		let $orderClass  = $this.prop('class').match(/(el_masonry_gallery\_[^\s]*)/)[0] + '_lightbox',
385			$effect      = $wrapper.data('lightbox_effect'),
386			$zoom        = 'zoom' === $effect ? true : false,
387			$duration    = 'none' !== $effect ? parseInt( $wrapper.data('lightbox_transition_duration') ) : 0,
388			$navigation  = 'on' === $wrapper.data('enable_navigation') ? true : false,
389			$mainClass   = 'mfp-img-mobile el_masonry_gallery_lightbox ' + $orderClass + ' dge_mfp_' + $effect,
390			$prependTo   = $( 'body' );
391
392		if ( $('body').hasClass('et-tb-has-template') ) {
393			if ( $orderClass.includes('_tb_header') ) {
394				$prependTo = $('body').find('#page-container').find('#et-boc .et-l--header');
395			} else if ( $orderClass.includes('_tb_body') ) {
396				$prependTo = $('body').find('#page-container').find('#et-boc .et-l--body');  
397			} else if ( $orderClass.includes('_tb_footer') ) {
398				$prependTo = $('body').find('#page-container').find('#et-boc .et-l--footer');
399			}
400		}
401
402		let clickDeligate = '.el_masonry_gallery_item';
403		if ( 'zoom_n_link' === $wrapper.data('click_trigger') ) {
404			clickDeligate = '.dge-overlay-lightbox';
405		}
406
407		$inner.on( 'click', '.el_masonry_gallery_item', function(e) {
408			e.stopPropagation();
409		} );
410
411		$inner.magnificPopup( {
412			delegate: clickDeligate,
413			type: 'image',
414			prependTo: $prependTo,
415			closeOnContentClick: false,
416			removalDelay: $duration,
417			closeBtnInside: false,
418			mainClass: $mainClass,
419			gallery: {
420				enabled: $navigation,
421				navigateByImgClick: false,
422				tPrev: '',
423				tNext: '',
424				tCounter: ''
425			},
426			zoom: {
427				enabled: $zoom,
428				duration: $duration,
429				easing: 'ease-in-out',
430				opener: function(element) {
431					return element;
432				}
433			},
434			image: {
435				markup: '<div class="mfp-figure">' +
436						'<div class="mfp-close"></div>' +
437						'<div class="mfp-img"></div>' +
438						'<div class="mfp-bottom-bar">' +
439							'<div class="mfp-title"></div>' +
440						'</div>' +
441						'</div>',
442				titleSrc: function(item) {
443					if ( 'zoom_n_link' === $wrapper.data('click_trigger') ) {
444						return item.el.parents( '.el_masonry_gallery_item' ).find('.el_masonry_gallery_title_caption_wrapper').length > 0 ? item.el.parents( '.el_masonry_gallery_item' ).find('.el_masonry_gallery_title_caption_wrapper').html() : '';
445					}
446					return item.el.find('.el_masonry_gallery_title_caption_wrapper').length > 0 ? item.el.find('.el_masonry_gallery_title_caption_wrapper').html() : '';
447				},
448				tError: 'The <a href="%url%">image</a> could not be loaded.',
449			},
450			allowHTMLInTemplate: true
451		} );
452		
453		let $magnificPopup = $.magnificPopup.instance;
454		let $current_page_navigate = ( $wrapper.data('lightbox_navigate_current') ) ? $wrapper.data('lightbox_navigate_current') : 'on';
455		$magnificPopup.open = function(data) {
456			if ( '.el_masonry_gallery_item' === data.delegate ) {
457				let $items = [];
458				$.each( data.items, function( key, value ) {
459					if ( ( $(value).is(':visible') && 0 !== parseFloat( $(value).css('opacity') ) ) || 'on' !== $current_page_navigate ) {
460						$items.push(value);
461					}
462				} );
463				data.items = $( $items );
464			}
465			$.magnificPopup.proto.open.call( this, data );
466		};
467
468		$('body').on( 'swiperight', '.el_masonry_gallery_lightbox .mfp-img', function() {
469			$magnificPopup.prev();
470		} );
471		$('body').on( 'swipeleft', '.el_masonry_gallery_lightbox .mfp-img', function() {
472			$magnificPopup.next();
473		} );
474	}
475}

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.