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
*/
;(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),
th = threshold || 0,
retina = window.devicePixelRatio > 1,
attrib = retina? "data-src-retina" : "data-src",
images = this,
loaded;
var $w = $(window),
th = threshold || 0,
retina = window.devicePixelRatio > 1,
attrib = retina ? "data-src-retina" : "data-src",
images = this,
loaded;
this.one("unveil", function() {
var source = this.getAttribute(attrib);
source = source || this.getAttribute("data-src");
if (source) {
this.setAttribute("src", source);
if (typeof callback === "function") callback.call(this);
}
});
this.one("unveil", function() {
var source = this.getAttribute(attrib);
source = source || this.getAttribute("data-src");
function unveil() {
var inview = images.filter(function() {
var $e = $(this);
// if ($e.is(":hidden")) return;
var flag = false;
for (var item in blacklist) {
if (source.indexOf(item)) {
flag = true;
}
}
if (source && !flag) {
this.setAttribute("src", source);
if (typeof callback === "function") callback.call(this);
}
var wt = $w.scrollTop(),
wb = wt + $w.height(),
et = $e.offset().top,
eb = et + $e.height();
if (flag) {
this.hide();
}
});
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");
images = images.not(loaded);
}
var wt = $w.scrollTop(),
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);