mirror of
https://gitlab.silvrtree.co.uk/martind2000/feedmaster-core.git
synced 2025-02-10 07:39:16 +00:00
110 lines
3.3 KiB
JavaScript
110 lines
3.3 KiB
JavaScript
/**
|
|
* jQuery Unveil
|
|
* A very lightweight jQuery plugin to lazy load images
|
|
* http://luis-almeida.github.com/unveil
|
|
*
|
|
* Licensed under the MIT license.
|
|
* Copyright 2013 Luís Almeida
|
|
* https://github.com/luis-almeida
|
|
*/
|
|
|
|
function Url() {
|
|
|
|
this.protocol = null;
|
|
this.host = null;
|
|
}
|
|
|
|
Url.prototype.parseUrl = function(url)
|
|
{
|
|
var parser = document.createElement('a');
|
|
parser.href = url;
|
|
|
|
this.protocol = parser.protocol; // => "http:"
|
|
this.host = parser.hostname; // => "example.com"
|
|
parser.port; // => "3000"
|
|
parser.pathname; // => "/pathname/"
|
|
parser.search; // => "?search=test"
|
|
parser.hash; // => "#hash"
|
|
parser.host; // => "example.com:3000"
|
|
|
|
}
|
|
|
|
|
|
;
|
|
(function($) {
|
|
|
|
var blackList = ['feeds.feedburner.com', '.feedsportal.co'];
|
|
$.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;
|
|
|
|
this.one("unveil", function() {
|
|
var source = this.getAttribute(attrib);
|
|
|
|
if (!Android.isNetworkAvailable()) {
|
|
console.log('No network, cant unveil pic: ' + source);
|
|
return -1;
|
|
}
|
|
|
|
this.removeAttribute("srcset");
|
|
this.removeAttribute("sizes");
|
|
|
|
var quality = ['960,fit','480,fit,q65'];
|
|
var q = Android.isWiFi() ? quality[0]:quality[1];
|
|
var iserve = 'https://image.silvrtree.co.uk/' + q + '/';
|
|
|
|
source = source || this.getAttribute("data-src");
|
|
|
|
|
|
var flag = false;
|
|
for (var item in blackList) {
|
|
var u = blackList[item];
|
|
if (source.indexOf(u) !== -1) {
|
|
flag = true;
|
|
}
|
|
}
|
|
source = iserve + source;
|
|
console.log(source);
|
|
if (source && !flag) {
|
|
this.setAttribute("src", source);
|
|
if (typeof callback === "function") callback.call(this);
|
|
}
|
|
|
|
if (flag) {
|
|
this.setAttribute("style", 'display:none !important;');
|
|
}
|
|
});
|
|
|
|
|
|
function unveil() {
|
|
var inview = images.filter(function() {
|
|
var $e = $(this);
|
|
// if ($e.is(":hidden")) return;
|
|
|
|
var wt = $w.scrollTop(),
|
|
wb = wt + $w.height(),
|
|
et = $e.offset().top,
|
|
eb = et + $e.height();
|
|
|
|
return eb >= wt - th && et <= wb + th;
|
|
});
|
|
|
|
loaded = inview.trigger("unveil");
|
|
images = images.not(loaded);
|
|
}
|
|
|
|
$w.on("scroll.unveil resize.unveil lookup.unveil", unveil);
|
|
|
|
unveil();
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
})(window.jQuery || window.Zepto);
|