Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions assets/src/js/admin-dashboard/segments/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ window.readyState_complete = (func) => {
document.addEventListener('readystatechange', (e) => e.target.readyState === 'complete' ? (typeof func == 'function' ? setTimeout(() => _caller(func)) : '') : '');
}

window.addBodyClass = (currentUrl) => {
// History push
const url = new URL(currentUrl);
const tabPage = url.searchParams.get('tab_page');
const tabPageEdit = url.searchParams.get('edit') && '_edit';
document.body.classList.add(tabPage);
document.body.classList.add(tabPage + tabPageEdit);
};

window.selectorById = (selector) => {
return document.getElementById(selector);
};
Expand Down
58 changes: 21 additions & 37 deletions assets/src/js/admin-dashboard/segments/navigation.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,63 @@

/**
* Navigation tab
*/
const navTabLists = document.querySelectorAll('[tutor-option-tabs]');
const navTabItems = document.querySelectorAll('[tutor-option-tabs] li > a');
const navPages = document.querySelectorAll('.tutor-option-nav-page');
readyState_complete(() => {
const navTabLists = document.querySelectorAll('[tutor-option-tabs]');
const navTabItems = document.querySelectorAll('[tutor-option-tabs] li > a');
const navPages = document.querySelectorAll('.tutor-option-nav-page');

function enableSaveButton() {
if (document.getElementById('save_tutor_option')) {
document.getElementById('save_tutor_option').disabled = false;
if (!navTabLists.length) {
return;
}
}

readyState_complete(() => {
const loadNavItem = document.querySelector('[tutor-option-tabs] li > a.is-active');
if (null !== loadNavItem) {
document.title = loadNavItem.querySelector('[tutor-option-label]').innerText + ' < ' + _tutorobject.site_title;
}

const tabPage = new URL(window.location).searchParams.get('tab_page');
if (tabPage) {
document.body.classList.add(tabPage);
}

navTabLists.forEach((list) => {
list.addEventListener('click', (e) => {
const dataTab = e.target.parentElement.dataset.tab || e.target.dataset.tab;
const pageSlug = e.target.parentElement.dataset.page || e.target.dataset.page;

if (dataTab) {
// Set page title on changing nav tabs
document.title = e.target.innerText + ' < ' + _tutorobject.site_title;
// remove active from other buttons

navTabItems.forEach((item) => {
item.classList.remove('is-active');
document.body.classList.remove(item.dataset.tab);
if (e.target.dataset.tab) {
document.body.classList.add(e.target.dataset.tab);
e.target.classList.add('is-active');
} else {
e.target.parentElement.classList.add('is-active');
}
});
// hide other tab contents
document.body.classList.add(dataTab);
const activeItem = e.target.dataset.tab ? e.target : e.target.parentElement;
activeItem.classList.add('is-active');

navPages.forEach((content) => {
content.classList.remove('is-active');
});
// add active to the current content
const currentContent = document.querySelector(`#${dataTab}`);
currentContent.classList.add('is-active');
document.querySelector(`#${dataTab}`).classList.add('is-active');

// History push
const url = new URL(window.location);

const params = new URLSearchParams({ page: pageSlug, tab_page: dataTab });
const pushUrl = `${url.origin + url.pathname}?${params.toString()}`;

window.history.pushState({}, '', pushUrl);
addBodyClass(window.location);
window.history.pushState({}, '', `${url.origin + url.pathname}?${params.toString()}`);

const loadingSpinner = document.getElementById(dataTab).querySelector('.loading-spinner');
if (loadingSpinner) {
document.getElementById(dataTab).querySelector('.loading-spinner').remove();
loadingSpinner.remove();
}

// Update certificate pagination on tab change
if (dataTab === 'tutor_certificate') {
const paginationLinks = document.querySelectorAll('#tutor-settings-tab-certificate_list .tutor-pagination a');

paginationLinks.forEach((link) => {
document.querySelectorAll('#tutor-settings-tab-certificate_list .tutor-pagination a').forEach((link) => {
const url = new URL(link.href);
url.searchParams.set('tab_page', dataTab); // Update the 'tab_page' parameter
url.searchParams.set('tab_page', dataTab);
link.href = url.toString();
});
}

}

});
});
});

addBodyClass(window.location);
Loading