Commit 697594cd authored by David Matamoros's avatar David Matamoros Committed by Paul Holden
Browse files

MDL-73011 core: Clean previous tab content when switching tabs



Co-authored-by: Paul Holden's avatarPaul Holden <paulh@moodle.com>
parent e82b2ed8
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -23,6 +23,7 @@
import $ from 'jquery';
import Templates from 'core/templates';
import {addIconToContainer} from 'core/loadingicon';
import Notification from 'core/notification';
import Pending from 'core/pending';
import {get_strings as getStrings} from 'core/str';
......@@ -69,15 +70,24 @@ export const init = () => {
).catch(Notification.exception);
});
// This code listens to Bootstrap event 'shown.bs.tab' which is triggered using JQuery and
// This code listens to Bootstrap events 'show.bs.tab' and 'shown.bs.tab' which is triggered using JQuery and
// can not be converted yet to native events.
tabToggle.on('shown.bs.tab', function() {
const tab = $($(this).attr('href'));
if (tab.length !== 1) {
return;
}
loadTab(tab.attr('id'));
});
tabToggle
.on('show.bs.tab', function() {
// Clean content from previous tab.
const previousTabName = getActiveTabName();
if (previousTabName) {
const previousTab = document.querySelector(SELECTORS.forTabName(previousTabName));
previousTab.textContent = '';
}
})
.on('shown.bs.tab', function() {
const tab = $($(this).attr('href'));
if (tab.length !== 1) {
return;
}
loadTab(tab.attr('id'));
});
if (!openTabFromHash()) {
const tabs = document.querySelector(SELECTORS.allActiveTabs);
......@@ -94,19 +104,6 @@ export const init = () => {
}
};
/**
* Show "loading" template instead of a node
*
* @param {HTMLElement} node
* @return {Promise}
*/
const indicateNodeIsLoading = (node) => {
return Templates.render('core/loading', {})
.then((html, js) => {
return Templates.replaceNodeContents(node, html, js);
}).catch(Notification.exception);
};
/**
* Returns id/name of the currently active tab
*
......@@ -150,9 +147,8 @@ const loadTab = (tabName, additionalData = {}) => {
...additionalData
};
let tabjs = '';
tab.textContent = '';
indicateNodeIsLoading(tab)
addIconToContainer(tab)
.then(() => {
return getContent(tab.dataset.tabClass, JSON.stringify(wsData));
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment