Issue 133: Add lazy loading for images support

This commit is contained in:
Nathan Adams
2016-03-05 21:32:34 -06:00
parent b8d6c17308
commit 57641e1661
9 changed files with 85 additions and 5 deletions

View File

@@ -0,0 +1,46 @@
$(function () {
var logoCache = {};
var waiting = 0;
function logoUpdate() {
if (waiting == 0) {
$(".logo").each(function () {
var self = $(this);
var logo = $(this).data("logo");
if (logo == "") {
logo = undefined;
}
self.attr("src", logoCache[logo]);
});
} else {
waiting -= 1;
}
}
$(".logo").each(function () {
var logoSrc = $(this).data("src");
var logo = $(this).data("logo");
var self = $(this);
if (!logoSrc) {
return;
}
if (logo == "") {
logo = undefined;
}
if (!(logo in logoCache)) {
logoCache[logo] = logoSrc;
}
});
waiting = Object.keys(logoCache).length - 1;
$.each(logoCache, function (index, element) {
$.ajax({
url: logoCache[index],
success: function(data) {
logoCache[index] = data;
logoUpdate();
},
async: true
});
});
});