From ca3e77fa1bbc67be0670a1e85364a2fc19f93e62 Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Thu, 16 Jul 2015 12:46:36 -0400 Subject: [PATCH] add lazyload.js --- html/js/lazyload.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 html/js/lazyload.js diff --git a/html/js/lazyload.js b/html/js/lazyload.js new file mode 100644 index 000000000..723d4e7e6 --- /dev/null +++ b/html/js/lazyload.js @@ -0,0 +1,36 @@ +/* + * LibreNMS module to initialize and support lazy loading of graph images + * + * Copyright (c) 2015 Travis Hegner + * + * 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. + */ +$(document).ready(function(){ + + //initialize jquery lazyload for all '.lazy' img tags + $("img.lazy").load(lazyload_done).lazyload({ + effect: "fadeIn", + threshold: 300, + placeholder: "" + }); + + + //re-initializes images loaded after an ajax call + $(document).ajaxStop(function() { + $("img.lazy").load(lazyload_done).lazyload({ + effect: "fadeIn", + threshold: 300, + placeholder: "" + }); + }); +}); + +function lazyload_done() { + //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('width').removeAttr('height').removeClass('lazy'); +} \ No newline at end of file