2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-04 06:18:48 +00:00

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
$(panel).addClass('panel-visible');
$(panel).fadeIn(100);
// Load the data
$(panel).trigger('fadeInStarted');
$(panel).fadeIn(100, function() {
});
// Un-select all selectors
$('.list-group-item').removeClass('active');
@ -82,3 +87,22 @@ function activatePanel(panelName, options={}) {
$(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');
});
}