librenms/html/js/lazyload.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-06-30 14:41:09 +00:00
/*
* LibreNMS module to initialize and support lazy loading of graph images
*
* Copyright (c) 2015 Travis Hegner <http://travishegner.com/>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
2015-06-29 17:44:19 +00:00
$(document).ready(function(){
2015-06-30 14:41:09 +00:00
//initialize jquery lazyload for all '.lazy' img tags
$("img.lazy").load(lazyload_done).lazyload({
effect: "fadeIn",
threshold: 300,
placeholder: ""
2015-06-29 20:28:11 +00:00
});
2015-06-29 17:44:19 +00:00
2015-06-30 14:41:09 +00:00
//re-initializes images loaded after an ajax call
2015-06-29 17:44:19 +00:00
$(document).ajaxStop(function() {
2015-06-29 20:28:11 +00:00
$("img.lazy").load(lazyload_done).lazyload({
2015-06-29 18:28:31 +00:00
effect: "fadeIn",
2015-06-30 14:41:09 +00:00
threshold: 300,
placeholder: ""
2015-06-29 20:28:11 +00:00
});
2015-06-29 17:44:19 +00:00
});
});
2015-06-29 20:28:11 +00:00
function lazyload_done() {
2015-06-30 14:41:09 +00:00
//Since RRD takes the width and height params for only the canvas, we must unset them
//from the final (larger) image to prevent the browser from resizing them.
$(this).removeAttr('height').removeClass('lazy');
}