Adds one-shot function when a panel is displayed

This commit is contained in:
Oliver 2021-08-11 00:09:01 +10:00
parent b92ec751ef
commit a1922bff81

View File

@ -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');
});
}