Merge pull request #1941 from SchrodingersGat/lazy-loading

Adds one-shot function when a panel is displayed
This commit is contained in:
Oliver 2021-08-11 00:29:06 +10:00 committed by GitHub
commit 2cf7592198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 522 additions and 460 deletions

File diff suppressed because it is too large Load Diff

View File

@ -72,7 +72,12 @@ function activatePanel(panelName, options={}) {
// Display the panel // Display the panel
$(panel).addClass('panel-visible'); $(panel).addClass('panel-visible');
$(panel).fadeIn(100);
// Load the data
$(panel).trigger('fadeInStarted');
$(panel).fadeIn(100, function() {
});
// Un-select all selectors // Un-select all selectors
$('.list-group-item').removeClass('active'); $('.list-group-item').removeClass('active');
@ -81,4 +86,23 @@ function activatePanel(panelName, options={}) {
var select = `#select-${panelName}`; var select = `#select-${panelName}`;
$(select).parent('.list-group-item').addClass('active'); $(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('fadeInStarted', function(e) {
// Trigger the callback
callback();
// Turn off the event
$(panelId).off('fadeInStarted');
});
} }