blacklisting shit images

This commit is contained in:
Martin Donnelly 2015-08-14 11:16:58 +01:00
parent ab44d3462a
commit 91bac301f9

View File

@ -8,49 +8,62 @@
* https://github.com/luis-almeida * https://github.com/luis-almeida
*/ */
;(function($) { ;
(function($) {
$.fn.unveil = function(threshold, callback) { var blackList = ['feeds.feedburner.com', 'pi.feedsportal.com', 'rc.feedsportal.com'];
$.fn.unveil = function(threshold, callback) {
var $w = $(window), var $w = $(window),
th = threshold || 0, th = threshold || 0,
retina = window.devicePixelRatio > 1, retina = window.devicePixelRatio > 1,
attrib = retina? "data-src-retina" : "data-src", attrib = retina ? "data-src-retina" : "data-src",
images = this, images = this,
loaded; loaded;
this.one("unveil", function() { this.one("unveil", function() {
var source = this.getAttribute(attrib); var source = this.getAttribute(attrib);
source = source || this.getAttribute("data-src"); source = source || this.getAttribute("data-src");
if (source) {
this.setAttribute("src", source);
if (typeof callback === "function") callback.call(this);
}
});
function unveil() { var flag = false;
var inview = images.filter(function() { for (var item in blacklist) {
var $e = $(this); if (source.indexOf(item)) {
// if ($e.is(":hidden")) return; flag = true;
}
}
if (source && !flag) {
this.setAttribute("src", source);
if (typeof callback === "function") callback.call(this);
}
var wt = $w.scrollTop(), if (flag) {
wb = wt + $w.height(), this.hide();
et = $e.offset().top, }
eb = et + $e.height(); });
return eb >= wt - th && et <= wb + th; function unveil() {
}); var inview = images.filter(function() {
var $e = $(this);
// if ($e.is(":hidden")) return;
loaded = inview.trigger("unveil"); var wt = $w.scrollTop(),
images = images.not(loaded); wb = wt + $w.height(),
} et = $e.offset().top,
eb = et + $e.height();
$w.on("scroll.unveil resize.unveil lookup.unveil", unveil); return eb >= wt - th && et <= wb + th;
});
unveil(); loaded = inview.trigger("unveil");
images = images.not(loaded);
}
return this; $w.on("scroll.unveil resize.unveil lookup.unveil", unveil);
}; unveil();
})(window.jQuery || window.Zepto); return this;
};
})(window.jQuery || window.Zepto);