jQuery(function($) { var updateArrows = function(){ $('.carouselGallery-right').removeClass('disabled'); $('.carouselGallery-left').removeClass('disabled'); var curIndex = $('.carouselGallery-carousel.active').data('index'); updateArrows.nbrOfItems = updateArrows.nbrOfItems || $('.carouselGallery-carousel').length -1; curIndex === updateArrows.nbrOfItems && $('.carouselGallery-right').addClass('disabled'); curIndex === 0 && $('.carouselGallery-left').addClass('disabled'); } $('.carouselGallery-carousel').on('click', function(e){ scrollTo = $('body').scrollTop(); $('body').addClass('noscroll'); $('body').css('position', 'fixed'); $('.carouselGallery-col-1, .carouselGallery-col-2').removeClass('active'); $(this).addClass('active'); showModal($(this)); updateArrows(); }); $('body').on('click', '.carouselGallery-right, .carouselGallery-left', function(e){ if($(this).hasClass('disabled')) return; var curIndex = $('.carouselGallery-carousel.active').data('index'); var nextItemIndex = parseInt(curIndex+1); if($(this).hasClass('carouselGallery-left')){ nextItemIndex-=2; } var nextItem = $('.carouselGallery-carousel[data-index='+nextItemIndex+']'); // console.log(nextItemIndex); if(nextItem.length > 0){ $('.carouselGallery-col-1, .carouselGallery-col-2').removeClass('active'); $('body').find('.carouselGallery-wrapper').remove(); showModal($(nextItem.get(0))); nextItem.first().addClass('active'); } updateArrows(); }); var modalHtml = ''; showModal = function(that){ // console.log(that); var username = that.data('username'), location = that.data('location'), imagetext = that.data('imagetext'), likes = that.data('likes'), imagepath = that.data('imagepath'), carouselGalleryUrl = that.data('url'); postURL = that.data('posturl'); maxHeight = $(window).height()-100; if ($('.carouselGallery-wrapper').length === 0) { if(typeof imagepath !== 'undefined') { modalHtml = "
"; modalHtml += "
"; modalHtml += "
"; modalHtml += ""; modalHtml += "
"; modalHtml += "carouselGallery image"; modalHtml += "
"; modalHtml += "
"; modalHtml += ""+username+" " modalHtml += ""+location+""; modalHtml += ""; modalHtml += ""; modalHtml += "

"+imagetext+"

"; modalHtml += "
"; $('body').append(modalHtml).fadeIn(2500); } } }; $('body').on( 'click','.carouselGallery-wrapper', function(e) { if($(e.target).hasClass('.carouselGallery-wrapper')){ removeModal(); } }); $('body').on('click', '.carouselGallery-modal .iconscircle-cross', function(e){ removeModal(); }); var removeModal = function(){ $('body').find('.carouselGallery-wrapper').remove(); $('body').removeClass('noscroll'); $('body').css('position', 'static'); $('body').animate({scrollTop: scrollTo}, 0); }; // Avoid break on small devices var carouselGalleryScrollMaxHeight = function() { if ($('.carouselGallery-scrollbox').length) { maxHeight = $(window).height()-100; $('.carouselGallery-scrollbox').css('max-height',maxHeight+'px'); } } $(window).resize(function() { // set event on resize clearTimeout(this.id); this.id = setTimeout(carouselGalleryScrollMaxHeight, 100); }); document.onkeydown = function(evt) { evt = evt || window.event; if (evt.keyCode == 27) { removeModal(); } }; });