var ngg_mosaic_methods={
high_dpi: false,
init: function(){
this.high_dpi=this.getDPIRatio() > 1;
_.each(document.getElementsByClassName('ngg-pro-mosaic-container'), function(self){
var gallery_id=self.getAttribute('data-ngg-pro-mosaic-id');
var gallery=ngg_mosaic_methods.get_gallery(gallery_id);
const container=self.parentElement;
const styleName='firstload';
if(ngg_mosaic_methods.get_setting(gallery_id, 'lazy_load_enable', false, 'bool')){
var initial_load=ngg_mosaic_methods.get_setting(gallery.ID, 'lazy_load_initial', 35, 'int');
gallery.mosaic_loaded=[];
_.each(gallery.images_list,
function(image, index){
if(index < initial_load){
gallery.mosaic_loaded.push(image.image_id);
self.appendChild(ngg_mosaic_methods.create_image(gallery,
image,
undefined,
'1'===self.parentElement.dataset['firstloadEnabled']
));
}}
);
}else{
_.each(gallery.images_list,
function(image){
self.appendChild(ngg_mosaic_methods.create_image(gallery,
image,
undefined,
'1'===self.parentElement.dataset['firstloadEnabled']
));
}
);
}
if('1'===container.dataset[`${styleName}Enabled`]){
const style=container.dataset[`${styleName}Style`];
const duration=parseInt(container.dataset[`${styleName}Duration`]);
const delay=parseInt(container.dataset[`${styleName}Delay`]);
const items=self.querySelectorAll('.ngg-pro-mosaic-item');
items.forEach(function(image, index){
image.style.setProperty('--animate-duration', `${duration}ms`);
if(index===(items.length - 1)){
setTimeout(()=> {
animateNextGENImage(image, style).then((message)=> {
if(ngg_mosaic_methods.get_setting(gallery_id, 'lazy_load_enable', false, 'bool')){
jQuery(window).on('scroll', function(){
window.ngg_mosaic_methods_two.scroll_action(gallery.ID, self);
});
jQuery(window).trigger('scroll');
}
return "Message received";
});
}, (0===index ? 0:index * delay));
}else{
setTimeout(()=> {
animateNextGENImage(image, style);
}, (0===index ? 0:index * delay));
}}
);
}else{
if('1'===container.dataset['paginationEnabled']){
if(ngg_mosaic_methods.get_setting(gallery_id, 'lazy_load_enable', false, 'bool')){
jQuery(window).on('scroll', function(){
window.ngg_mosaic_methods_two.scroll_action(gallery.ID, self);
});
jQuery(window).trigger('scroll');
}}
}});
},
getDPIRatio: function(){
var ratio=1;
if(window.screen.systemXDPI!==undefined
&&  window.screen.logicalXDPI!==undefined
&&  window.screen.systemXDPI > window.screen.logicalXDPI){
ratio=window.screen.systemXDPI / window.screen.logicalXDPI;
}else if(window.devicePixelRatio!==undefined){
ratio=window.devicePixelRatio;
}
return ratio;
},
get_gallery: function (gallery_id){
var result=null;
if('undefined'==typeof window.galleries){
return result;
}
return _.find(galleries, function(gallery){
return (gallery.ID==gallery_id);
});
},
get_setting: function(gallery_id, name, def, type){
type=type||'bool';
var gallery=this.get_gallery(gallery_id);
if(gallery&&typeof gallery.display_settings[name]!='undefined')
def=gallery.display_settings[name];
if(type=='bool'){
if(def==1||def=='1')
def=true;
if(def==0||def=='0')
def=false;
}else if(type=='int'){
def=parseInt(def);
}else if(type=='string'){
}
return def;
},
create_image: function(gallery, image, onload, addAnimationClass){
var self=this;
var div=document.createElement('div');
div.setAttribute('class', 'ngg-pro-mosaic-item');
if(addAnimationClass){
div.classList.add('nextgen-pro-animate-images-loading');
}
var img=document.createElement('img');
var url=image.image;
if(self.high_dpi&&image.use_hdpi){
url=image.srcsets.hdpi;
}
img.setAttribute('title', sanitizeToPlainText(image.title));
img.setAttribute('alt',   sanitizeToPlainText(image.title));
img.setAttribute('src',   url);
img.setAttribute('width', image.width);
img.setAttribute('height', image.height);
var anchor=document.createElement('a');
var clauses=gallery.mosaic_effect_code.match(/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/ig);
if(clauses){
for (var i=0; i < clauses.length; i++){
var claus=clauses[i].match(/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/i);
anchor.setAttribute(claus[1], claus[2]);
}}
anchor.setAttribute('href',             image.full_image);
anchor.setAttribute('title',            image.description);
anchor.setAttribute('data-image-id',    image.image_id);
anchor.setAttribute('data-src',         image.image);
anchor.setAttribute('data-thumbnail',   image.thumb);
anchor.setAttribute('data-title',       image.title);
anchor.setAttribute('data-description', image.description);
anchor.setAttribute('data-image-name',  image.full_image ? image.full_image.split('/').pop().split('?')[0]:(image.title||''));
anchor.setAttribute('data-ngg-captions-nostylecopy', '1');
if(image.tiktok_play_url){
anchor.setAttribute('data-tiktok-play-url', image.tiktok_play_url);
}
if(image.tiktok_share_url){
anchor.setAttribute('data-tiktok-share-url', image.tiktok_share_url);
}
if(image.tiktok_embed_url||image.tiktok_embed_link){
anchor.setAttribute('data-tiktok-embed-url', image.tiktok_embed_url||image.tiktok_embed_link);
}
if(image.video_link){
anchor.setAttribute('data-video-url', image.video_link);
}
if(image.is_dribbble===1||image.is_dribbble==='1'||image.is_dribbble===true){
anchor.setAttribute('data-ngg-dribbble', '1');
anchor.setAttribute('data-dribbble-link', image.dribbble_link);
if(image.dribbble_target&&image.dribbble_target==='_blank'){
anchor.setAttribute('data-dribbble-target', '_blank');
}}
if(typeof onload!='undefined'){
anchor.setAttribute('onload', onload);
}
anchor.appendChild(img);
if((image.is_tiktok==1||image.is_tiktok=='1'||image.is_tiktok===true)
&& (image.show_play_button==1||image.show_play_button=='1'||image.show_play_button===true)){
var overlay=document.createElement('span');
overlay.setAttribute('class', 'ngg-video-play-overlay');
overlay.setAttribute('aria-hidden', 'true');
anchor.appendChild(overlay);
}else if((image.is_video_link==1||image.is_video_link=='1'||image.is_video_link===true)
&& image.video_link&&image.video_link.length > 0){
var overlay=document.createElement('span');
overlay.setAttribute('class', 'ngg-video-play-overlay');
overlay.setAttribute('aria-hidden', 'true');
anchor.appendChild(overlay);
}
div.appendChild(anchor);
return div;
}};
function sanitizeToPlainText(value){
const tempDiv=jQuery("<div>").html(value);
let plainText=tempDiv.text();
tempDiv.remove();
plainText=plainText.replace(/['"`~!@#$%^&*()_+=\[\]{}|;:,.<>?/\\-]/g, "");
return plainText.trim();
}
(function($){
"use strict";
var mosaic_methods={
image_loaded: function(image_id){
this.scroll_pending=_.without(this.scroll_pending, image_id);
},
scroll_action_running: null,
scroll_timer: null,
scroll_step: 5,
scroll_pending: [],
scroll_more_to_find: true,
scroll_action: function(gallery_id, myself){
if(this.scroll_action_running==true
||  this.scroll_timer
||  !this.scroll_more_to_find
||  (this.scroll_pending.length >=1)){
return;
}
this.scroll_action_running=true;
var self=this;
this.scroll_timer=setTimeout(function(){
clearTimeout(self.scroll_timer);
self.scroll_timer=false;
}, 500);
setTimeout(function(){
var $self=$(myself);
var window_height=$(window).height();
var window_position=$(window).scrollTop();
var window_bottom=window_height + window_position;
var container_bottom=$self.height() + $self.offset().top;
var row_height=$self.find('.ngg-pro-mosaic-item.entry-visible').first().height();
var last_height=$self.find('.ngg-pro-mosaic-item.entry-visible').last().height();
if(window_bottom <=(container_bottom - last_height - (row_height * 2))){
self.scroll_action_running=false;
return;
}
var gallery=ngg_mosaic_methods.get_gallery(gallery_id);
var scroll_step=ngg_mosaic_methods.get_setting(gallery_id, 'lazy_load_batch', this.scroll_step, 'int');
if((gallery.images_list.length - gallery.mosaic_loaded.length) < scroll_step){
scroll_step=gallery.images_list.length - gallery.mosaic_loaded.length;
self.scroll_more_to_find=false;
}
let newImages=[];
const container=myself.parentElement;
const styleName='pagination';
for (var i=0; i < scroll_step; i++){
var image=_.find(gallery.images_list, function(image){
return (_.indexOf(gallery.mosaic_loaded, image.image_id)==-1)
});
gallery.mosaic_loaded.push(image.image_id);
let newImage=ngg_mosaic_methods.create_image(gallery,
image,
self.image_loaded(image.image_id),
'1'===container.dataset[`${styleName}Enabled`]
);
newImages.push(newImage);
$self.append(newImage);
}
$self.justifiedGallery('norewind');
if('1'===container.dataset[`${styleName}Enabled`]){
const style=container.dataset[`${styleName}Style`];
const duration=parseInt(container.dataset[`${styleName}Duration`]);
const delay=parseInt(container.dataset[`${styleName}Delay`]);
newImages.forEach(function(image, index){
image.style.setProperty('--animate-duration', `${duration}ms`);
setTimeout(()=> {
animateNextGENImage(image, style);
}, (0===index ? 0:index * delay));
}
);
}
self.scroll_action_running=false;
}, 60);
}};
window.ngg_mosaic_methods_two=mosaic_methods;
ngg_mosaic_methods.init();
_.each($('.ngg-pro-mosaic-container'), function(self){
var $self=$(self);
var gallery_id=$self.data('ngg-pro-mosaic-id');
var jgoptions={
captions: false,
cssAnimation: true,
waitThumbnailsLoad: false,
justifyThreshold: 0.9,
rowHeight: ngg_mosaic_methods.get_setting(gallery_id, 'row_height', 200, 'int'),
margins:   ngg_mosaic_methods.get_setting(gallery_id, 'margins',    15,  'int'),
lastRow:   ngg_mosaic_methods.get_setting(gallery_id, 'last_row',   'justify', 'string')
};
var gallery=ngg_mosaic_methods.get_gallery(gallery_id);
$self.css({
'min-height': ngg_mosaic_methods.get_setting(gallery_id, 'row_height', 200, 'int') + 'px'
});
if('undefined'===typeof self.parentElement.dataset['paginationEnabled']
||  '0'===self.parentElement.dataset['paginationEnabled']){
if(ngg_mosaic_methods.get_setting(gallery_id, 'lazy_load_enable', false, 'bool')){
$(window).on('scroll', function(){
mosaic_methods.scroll_action(gallery.ID, self);
});
}}
$self.on('jg.complete', function(){
$(window).trigger('ngg.mosaic.complete', [$self]);
$(window).trigger('resize', [$self]);
$self.waitForImages(function(){
$(window).trigger('refreshed');
});
});
$self.justifiedGallery(jgoptions);
$(window).on('npl_initialization_complete', function(){
$('#npl_content').on('npl_opening', function(){
$self.justifiedGallery('disableRefresh');
});
$('#npl_content').on('npl_closing', function(){
$self.justifiedGallery('enableRefresh');
});
});
});
})(jQuery);