Skip to content

Commit

Permalink
[bug 842882] Fix lazyloading on mobile wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
rehandalal committed Mar 25, 2013
1 parent 7bf4ac9 commit e8abc3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions media/js/libs/jquery.lazyload.js
Expand Up @@ -10,16 +10,17 @@
var opts = $.extend($.fn.lazyload.defaults, options);
var elements = this;
var didScroll = false;
var boundElem = opts['bindTo']
loaded = elements.length;

$(window).bind('scroll', function(e){
$(boundElem).bind('scroll', function(e){
didScroll = true;
});

loadAboveTheFoldImages(elements, opts, null);

// Safari doesn't load images until scroll, sometimes
$(window).trigger('scroll');
$(boundElem).trigger('scroll');

var prevHash = window.location.hash;

Expand All @@ -28,7 +29,7 @@

var intv = setInterval(function() {
if(loaded <= 0) {
$(window).unbind('scroll');
$(boundElem).unbind('scroll');
clearInterval(intv);
return;
}
Expand All @@ -49,7 +50,7 @@
return this;
};

$.fn.lazyload.defaults = {threshold: 750};
$.fn.lazyload.defaults = {threshold: 750, bindTo: window};

function resetHashPosition() {
if(window.location.hash) {
Expand All @@ -59,7 +60,8 @@
}

function aboveTheFold(element, options){
var fold = $(window).height() + $(window).scrollTop();
var boundElem = options['bindTo'];
var fold = $(boundElem).height() + $(boundElem).scrollTop();
return fold >= $(element).offset().top - (options['threshold']);
};

Expand Down
2 changes: 1 addition & 1 deletion media/js/mobile/wiki.js
Expand Up @@ -84,5 +84,5 @@
});
}

$('img.lazy').lazyload();
$('img.lazy').lazyload({bindTo: $('#page > .scrollable')});
})(jQuery);

0 comments on commit e8abc3a

Please sign in to comment.