Scroll down to view images
`
this.removeSpinner = () => {
jQuery(slideshowInstance.itemContainerSelector + ‘ div[uk-spinner]’).remove()
};
this.prevPageLinkHTML = `
Previous Page
`
this.nextPageLinkHTML = `
Next Page
`
Object.defineProperties(this, {
‘items’: {
get: function() {
return jQuery(this.itemContainerSelector).find(this.itemSelector)
}
},
‘currentItem’: {
get: function() {
var foundItem = null
var foundItemInView = null
this.items.each(function () {
var currentInView = elementInView(jQuery(this), scrollTopOffset, 0)
if (currentInView) {
// An in view item is already located extra logic
if (foundItemInView && foundItemInView.inView) {
// The entire previously found item is visible – it wins
if (foundItemInView.topInView && foundItemInView.bottomInView) return
// The previously found item covers the visible area – it wins
if (foundItemInView.middleCoversView) return
// The previously found item has more surface area – it wins
if (foundItemInView.percentVisable > currentInView.percentOfViewHeight) return
}
foundItem = jQuery(this)
foundItemInView = currentInView
}
})
return foundItem
}
},
‘currentItemIndex’: {
get: function() {
var currentElement = this.currentItem.closest(‘[slide-index]’)
if(currentElement) {
return parseInt(currentElement.attr(‘slide-index’))
}
return null
}
},
‘currentItemId’: {
get: function() {
var currentElement = this.currentItem.closest(‘[slide-id]’)
if(currentElement) {
return currentElement.attr(‘slide-id’)
}
return null
}
}
})
var slideshowInstance = this
// xxx for debuggering – ig
window.slideshowInstance = slideshowInstance;
var scrollTopOffset = window.innerHeight > this.smallMenuBreakPoint ? 110 : 140
var originUrl = window.location.href
this.scrollToIndex = function (index) {
var slideItem = this.items.filter(‘[slide-index=”‘ + index + ‘”]’)
if (slideItem.length) {
var topOffset = slideItem.offset().top – scrollTopOffset
// window.scrollTo({ top: topOffset, behavior: ‘smooth’ })
window.scrollTo({ top: topOffset, behavior: ‘auto’ })
}
else {
this.fetchMore(index, function () {
slideshowInstance.scrollToIndex(index)
})
}
}
this.fetchMore = function (startIndex, callback) {
var currentItemOnFetch = this.currentItem
var url=”https://www.sacurrent.com/sanantonio/this-san-antonio-home-for-sale-has-a-saltwater-pool-a-basketball-court-and-a-chicken-coop/Slideshow/34911597″
var params = {
ajaxComponent: componentId,
action: ‘grabMore’,
startIndex: startIndex,
oid: slideshowOid,
cb: ‘1719669635’,
}
if (paginate) {
params.paginate = paginate;
}
var keywords = currentItemOnFetch.attr(‘slide-keywords’)
if (keywords) {
params.keywords = keywords
}
if (editorView === true) {
params.editor = true
}
//
jQuery.ajax({
url: url,
type: ‘GET’,
data: params,
dataType: ‘json’,
//
beforeSend: function () { console.log(‘Fetching results’) },
success: function (data) {
console.log(‘success’, data.results, data.results.length, data.error, data)
if (data) {
if (data.error) {
console.log(data.error)
}
else if (data.results) {
console.log(‘slideshowInstance.items’, slideshowInstance.items)
for (var i = 0; i < data.results.length; i++) {
var resultItem = jQuery(data.results[i])
//
// var resultItem = jQuery.parseHTML(data.results[i], document, true);
var resultItemIndex = parseInt(resultItem.attr(‘slide-index’))
var resultAlreadyInserted = slideshowInstance.items.filter(‘[slide-index=”‘ + resultItemIndex + ‘”]’).length > 0
console.log(‘result’, resultItemIndex)
var previousItem = null
var previousItemIndex = 0
if (!resultAlreadyInserted) {
slideshowInstance.items.each(function () {
if (resultAlreadyInserted) return
var currentItem = jQuery(this)
var currentItemIndex = parseInt(currentItem.attr(‘slide-index’))
if (resultItemIndex === currentItemIndex ) {
resultAlreadyInserted = true
return
}
else if (resultItemIndex > previousItemIndex
&& resultItemIndex < currentItemIndex) {
var topOffsetBeforeInsert = currentItemOnFetch.get(0).getBoundingClientRect().top
resultItem.insertBefore(currentItem)
resultAlreadyInserted = true
var adjustedTopPosition = currentItemOnFetch.offset().top – topOffsetBeforeInsert
window.scrollTo({ top: adjustedTopPosition, behavior: ‘auto’ })
}
previousItem = currentItem
previousItemIndex = currentItemIndex
})
if (!resultAlreadyInserted) {
var topOffsetBeforeInsert = currentItemOnFetch.get(0).getBoundingClientRect().top
resultItem.insertAfter(slideshowInstance.items.last())
resultAlreadyInserted = true
var adjustedTopPosition = currentItemOnFetch.offset().top – topOffsetBeforeInsert
window.scrollTo({ top: adjustedTopPosition, behavior: ‘auto’ })
if (typeof instgrm === ‘object’ && instgrm.Embeds && typeof instgrm.Embeds.process === ‘function’) {
setTimeout(instgrm.Embeds.process, 200);
}
}
}
}
}
else { console.log(‘How did we get here?’) }
}
else { console.log(‘No result or error returned from content request.’) }
},
complete: function () {
slideshowInstance.items = jQuery(slideshowInstance.itemSelector) // Update items result
slideshowInstance.removeSpinner();
if (typeof callback === ‘function’) { callback() }
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
if (textStatus === ‘timeout’) {
slideshowInstance.removeSpinner();
if (paginate === true) return;
paginate = true;
if (slideshowInstance.items.length < totalSlides) {
var firstLoadedIndex = parseInt(slideshowInstance.items.first().attr(‘slide-index’)) || 1;
var lastLoadedIndex = parseInt(slideshowInstance.items.last().attr(‘slide-index’)) || totalSlides;
if(firstLoadedIndex > 1) {
var prevLink = jQuery(slideshowInstance.prevPageLinkHTML);
var prevLinkUrl = new URL(url, `https://www.sacurrent.com`);
prevLinkUrl.searchParams.append(‘startIndex’, firstLoadedIndex – 1);
prevLinkUrl.searchParams.append(‘paginate’, ‘true’);
prevLink.attr(‘href’, prevLinkUrl.href);
jQuery(slideshowInstance.itemContainerSelector).prepend(prevLink);
}
if(lastLoadedIndex < totalSlides) {
var nextLink = jQuery(slideshowInstance.nextPageLinkHTML);
var nextLinkUrl = new URL(url, `https://www.sacurrent.com`);
nextLinkUrl.searchParams.append(‘startIndex’, lastLoadedIndex + 1);
nextLinkUrl.searchParams.append(‘paginate’, ‘true’);
nextLink.attr(‘href’, nextLinkUrl.href);
jQuery(slideshowInstance.itemContainerSelector).append(nextLink);
}
}
}
}
})
}
// //
// var lazyLoadSurroundingItemsInterval = null;
// var lazyLoadTimeout = null;
// var lazyLoadSurroundingItems = function (index) {
// if (paginate) return;
// if (slideshowInstance.items.length >= totalSlides) {
// clearInterval(lazyLoadSurroundingItemsInterval);
// }
// if (slideshowInstance.lazyLoadMoreResults) {
// // Rate limit lazyloading more slides
// clearTimeout(lazyLoadTimeout);
// lazyLoadTimeout = setTimeout(function () {
// var prevIndex = Math.max(index – 1, 1)
// var prevPrevIndex = Math.max(index – 2, 1)
// var nextIndex = index + 1
// var nextNextIndex = index + 2
// var prevIndexLoaded = slideshowInstance.items.filter(‘[slide-index=”‘ + prevIndex + ‘”]’).length > 0
// var prevPrevIndexLoaded = slideshowInstance.items.filter(‘[slide-index=”‘ + prevPrevIndex + ‘”]’).length > 0
// var nextIndexLoaded = slideshowInstance.items.filter(‘[slide-index=”‘ + nextIndex + ‘”]’).length > 0
// var nextNextIndexLoaded = slideshowInstance.items.filter(‘[slide-index=”‘ + nextNextIndex + ‘”]’).length > 0
// if(!prevIndexLoaded) {
// slideshowInstance.removeSpinner();
// // jQuery(slideshowInstance.itemContainerSelector).prepend(slideshowInstance.spinnerHTML)
// slideshowInstance.fetchMore(Math.max(prevIndex – (fetchMoreMaxCount – 1), 1))
// }
// else if(!prevPrevIndexLoaded) {
// slideshowInstance.removeSpinner();
// // jQuery(slideshowInstance.itemContainerSelector).prepend(slideshowInstance.spinnerHTML)
// slideshowInstance.fetchMore(Math.max(prevPrevIndex – (fetchMoreMaxCount – 1), 1))
// }
// if(!nextIndexLoaded) {
// slideshowInstance.removeSpinner();
// jQuery(slideshowInstance.itemContainerSelector).append(slideshowInstance.spinnerHTML)
// slideshowInstance.fetchMore(nextIndex)
// }
// else if(!nextNextIndexLoaded) {
// slideshowInstance.removeSpinner();
// jQuery(slideshowInstance.itemContainerSelector).append(slideshowInstance.spinnerHTML)
// slideshowInstance.fetchMore(nextNextIndex)
// }
// }, 200)
// }
// }
// //
// var lazyLoadLastCheckedIndex = slideshowInstance.currentItemIndex
// lazyLoadSurroundingItemsInterval = setInterval(function () {
// var currentIndex = slideshowInstance.currentItemIndex
// console.log(`lazyLoadSurroundingItemsInterval – currentIndex: ${currentIndex}; lazyLoadLastCheckedIndex: ${lazyLoadLastCheckedIndex}`);
// if(currentIndex !== lazyLoadLastCheckedIndex) {
// lazyLoadLastCheckedIndex = currentIndex;
// lazyLoadSurroundingItems(currentIndex);
// }
// }, 1000);
var onScrollLastCheckedIndex = slideshowInstance.currentItemIndex
jQuery(window).on(‘scroll resize’, function () {
var currentIndex = slideshowInstance.currentItemIndex
if(currentIndex !== onScrollLastCheckedIndex) {
onScrollLastCheckedIndex = currentIndex
// console.log(`Slide Item index: ${currentIndex}`)
fireEvent(‘foundation:slideshow:slidechange’)
}
});
// var onScrollTimeout = null;
// jQuery(window).on(‘scroll resize’, function () {
// // Rate limit lazyloading more slides
// clearTimeout(onScrollTimeout);
// onScrollTimeout = setTimeout(function () {
// var currentIndex = slideshowInstance.currentItemIndex
// if(currentIndex !== onScrollLastCheckedIndex) {
// onScrollLastCheckedIndex = currentIndex
// console.log(`Slide Item index: ${currentIndex}`)
// fireEvent(‘foundation:slideshow:slidechange’)
// }
// }, 100);
// });
this.initialized = false
this.init = function () {
if (this.initialized === true) return
// Prevent the browser from trying to scroll to the last scroll position before reload
if (history.scrollRestoration) {
history.scrollRestoration = ‘manual’
}
var startIndex = this.items.first().attr(‘slide-index’)
var oid = window.location.pathname.match(/d+$/)
if (oid) {
var grabIndex = parseInt(this.items.closest(‘[slide-id=”‘ + oid[0] + ‘”]’).attr(‘slide-index’))
if (!isNaN(grabIndex)) {
var startIndex = grabIndex
}
}
// if (startIndex > 1) {
// this.scrollToIndex(startIndex)
// }
// if(jQuery(this.itemContainerSelector + ‘[single-listing]’).length === 0) {
// this.lazyLoadMoreResults = true
// }
this.lazyLoadMoreResults = true
this.initialized = true
// lazyLoadSurroundingItems(startIndex)
}
return this
}
var SlideshowItems = new SlideshowItemsObj()
// Ad refresh on slide change handling
var adSlideChangeRefreshThreshold = 10;
var adSlideChangeRefreshTimeout = null;
//
adSlideChangeRefreshTimeout = setTimeout(function () {
adSlideChangeRefreshTimeout = null; // Set timer to null
}, adSlideChangeRefreshThreshold)
// Timeout to prevent fast jogging from item to item
var itemChangeTimeout = null
jQuery(document).on(‘foundation:slideshow:slidechange’, function () {
if (editorView !== true) {
updateMetaDataFromElement(SlideshowItems.currentItem)
}
// Google Anayltics track pageview
if (typeof ga === ‘function’) {
console.log(“foundation:slideshow:slidechange event”, “sending pageview navigation to:”, window.location.href);
ga(‘set’, ‘location’, window.location.href)
for (let i = 1; i <= 3; i++) {
let currentDimension = jQuery(SlideshowItems.currentItem).attr(‘ga-dimension’+i)
if (typeof currentDimension === ‘string’) {
ga(‘set’, ‘dimension’ + i, currentDimension)
}
else {
ga(‘set’, ‘dimension’ + i, ”)
}
}
ga(‘send’, ‘pageview’)
}
//
if (adSlideChangeRefreshTimeout === null) {
//
adSlideChangeRefreshTimeout = setTimeout(function () {
adSlideChangeRefreshTimeout = null; // Set timer to null
}, adSlideChangeRefreshThreshold)
//
if (Foundation.Ad && Foundation.Ad.slots) {
if (typeof (Foundation.Ad.slots[‘_Footer-1’]) === ‘object’) {
Foundation.Ad.showFooter(‘_Footer-1’);
}
}
//
if (Foundation.Gpt && Foundation.Gpt.getInPageSlotDataById) {
var gptSlots = window.googletag.pubads().getSlots();
var gptSlotFixedFooter = gptSlots.filter((slot) => slot.getSlotElementId() === `FixedFooter`)
if (gptSlotFixedFooter.length) {
Foundation.Gpt.ShowAd.refreshFixedFooter(gptSlotFixedFooter[0]);
}
}
}
});
// Try to init immediately
SlideshowItems.init()
// On document loaded
jQuery(function () {
SlideshowItems.init()
})
// })();