Turned lazyload into jquery plugin, used for announcements

On call of the lazyload plugin, all matched img elements will be
checked if they have a data-src attribute. If so, their src attribute
will be replaced with the contents of the data-src attribute
(effectively loading the image) and the data-src attribute will be
removed (so that multiple calls don't call multiple processing).
This commit is contained in:
Gina Häußge 2017-04-10 11:54:03 +02:00
parent 7c8f148fa8
commit 9f32e91e05
2 changed files with 13 additions and 7 deletions

View file

@ -144,13 +144,7 @@ $(function() {
if (!self.loginState.isAdmin()) return;
// lazy load images that still need lazy-loading
$("#plugin_announcements_dialog_content article img").each(function (index, element) {
var src = element.getAttribute("data-src");
if (src) {
element.setAttribute("src", src);
element.removeAttribute("data-src");
}
});
$("#plugin_announcements_dialog_content article img").lazyload();
self.announcementDialogContent.scrollTop(0);

View file

@ -444,6 +444,18 @@ $(function() {
}
};
$.fn.lazyload = function() {
return this.each(function() {
if (this.tagName.toLowerCase() != "img") return;
var src = this.getAttribute("data-src");
if (src) {
this.setAttribute("src", src);
this.removeAttribute("data-src");
}
});
};
// Use bootstrap tabdrop for tabs and pills
$('.nav-pills, .nav-tabs').tabdrop();