From a1922bff81ba92ae525ee07c0d830346be1570ef Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 11 Aug 2021 00:09:01 +1000 Subject: [PATCH] Adds one-shot function when a panel is displayed --- InvenTree/templates/js/dynamic/nav.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/js/dynamic/nav.js b/InvenTree/templates/js/dynamic/nav.js index aff3435b21..d3d27d62f7 100644 --- a/InvenTree/templates/js/dynamic/nav.js +++ b/InvenTree/templates/js/dynamic/nav.js @@ -72,7 +72,9 @@ function activatePanel(panelName, options={}) { // Display the panel $(panel).addClass('panel-visible'); - $(panel).fadeIn(100); + $(panel).fadeIn(100, function() { + $(panel).trigger('fadeInComplete'); + }); // Un-select all selectors $('.list-group-item').removeClass('active'); @@ -81,4 +83,24 @@ function activatePanel(panelName, options={}) { var select = `#select-${panelName}`; $(select).parent('.list-group-item').addClass('active'); +} + + + +function onPanelLoad(panel, callback) { + // One-time callback when a panel is first displayed + // Used to implement lazy-loading, rather than firing + // multiple AJAX queries when the page is first loaded. + + var panelId = `#panel-${panel}`; + + $(panelId).on('fadeInComplete', function(e) { + + // Trigger the callback + callback(); + + // Turn off the event + $(panelId).off('fadeInComplete'); + + }); } \ No newline at end of file