Don't load Pins "in background" when lightbox is active.

Remove the scroll event handler when lightbox is active, so pins are
not loaded in background breaking the page layout.
This commit is contained in:
Krzysztof Klimonda
2013-04-14 15:51:39 +02:00
parent cecc88f068
commit defbd50445
2 changed files with 19 additions and 5 deletions

View File

@@ -22,12 +22,22 @@ $(window).load(function() {
'margin-top': -$('body').data('scroll-level') 'margin-top': -$('body').data('scroll-level')
}); });
$(window).scrollTop(0); $(window).scrollTop(0);
/* disable the global pin-loading scroll handler so we don't
load pins when scrolling a selected image */
$(window).off('scroll');
} else { } else {
$('#pins').css({ $('#pins').css({
'position': 'static', 'position': 'static',
'margin-top': 0 'margin-top': 0
}); });
$(window).scrollTop($('body').data('scroll-level')); $(window).scrollTop($('body').data('scroll-level'));
/* enable the pin-loading scroll handler unless we've already
loaded all pins from the server (in which case an element
with id 'the-end' exists */
var theEnd = document.getElementById('the-end');
if (!theEnd) {
$(window).scroll(scrollHandler);
}
} }
} }
// End Helper Functions // End Helper Functions

View File

@@ -91,6 +91,14 @@ $(window).load(function() {
blockContainer.css('height', colHeights.sort().slice(-1)[0]); blockContainer.css('height', colHeights.sort().slice(-1)[0]);
} }
/**
* On scroll load more pins from the server
*/
window.scrollHandler = function() {
var windowPosition = $(window).scrollTop() + $(window).height();
var bottom = $(document).height() - 100;
if(windowPosition > bottom) loadPins();
}
/** /**
* Load our pins using the pins template into our UI, be sure to define a * Load our pins using the pins template into our UI, be sure to define a
@@ -138,11 +146,7 @@ $(window).load(function() {
$('body').append(theEnd); $('body').append(theEnd);
} }
} else { } else {
$(window).scroll(function() { $(window).scroll(scrollHandler);
var windowPosition = $(window).scrollTop() + $(window).height();
var bottom = $(document).height() - 100;
if(windowPosition > bottom) loadPins();
});
} }
}); });