better filters
This commit is contained in:
@@ -555,6 +555,8 @@ window.cancelAnimFrame = (function () {
|
|||||||
'content-warning-modal', 'gchat-img-modal', 'image-modal', 'info-modal'
|
'content-warning-modal', 'gchat-img-modal', 'image-modal', 'info-modal'
|
||||||
];
|
];
|
||||||
modalIds.forEach(id => {
|
modalIds.forEach(id => {
|
||||||
|
// Don't close the filter modal during a background mime-filter reload
|
||||||
|
if (id === 'excluded-tags-overlay' && window._keepFilterModal) return;
|
||||||
const el = document.getElementById(id);
|
const el = document.getElementById(id);
|
||||||
if (el) {
|
if (el) {
|
||||||
el.classList.remove('show', 'visible');
|
el.classList.remove('show', 'visible');
|
||||||
@@ -3050,6 +3052,10 @@ window.cancelAnimFrame = (function () {
|
|||||||
// Sync state immediately via cookie to avoid race conditions
|
// Sync state immediately via cookie to avoid race conditions
|
||||||
document.cookie = `mode=${window.activeMode}; Path=/; Max-Age=31536000`;
|
document.cookie = `mode=${window.activeMode}; Path=/; Max-Age=31536000`;
|
||||||
|
|
||||||
|
// Keep filter modal open if the click came from inside it
|
||||||
|
const fromFilterModal = !!modeBtn.closest('#excluded-tags-overlay');
|
||||||
|
if (fromFilterModal) window._keepFilterModal = true;
|
||||||
|
|
||||||
// Update mode via AJAX
|
// Update mode via AJAX
|
||||||
fetch(modeBtn.href, {
|
fetch(modeBtn.href, {
|
||||||
headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
||||||
@@ -3068,21 +3074,28 @@ window.cancelAnimFrame = (function () {
|
|||||||
const isGridView = document.querySelector('.posts, .tags-grid');
|
const isGridView = document.querySelector('.posts, .tags-grid');
|
||||||
const isItemView = document.getElementById('prev') || document.getElementById('next');
|
const isItemView = document.getElementById('prev') || document.getElementById('next');
|
||||||
|
|
||||||
|
let reloadPromise = null;
|
||||||
if (isGridView) {
|
if (isGridView) {
|
||||||
// Reload current page without ?mode= in the URL — server picks up mode from session/cookie
|
// Reload current page without ?mode= in the URL — server picks up mode from session/cookie
|
||||||
const currentUrl = new URL(window.location.href);
|
const currentUrl = new URL(window.location.href);
|
||||||
currentUrl.searchParams.delete('mode');
|
currentUrl.searchParams.delete('mode');
|
||||||
loadPageAjax(currentUrl.toString(), true, { skipCache: true });
|
reloadPromise = loadPageAjax(currentUrl.toString(), true, { skipCache: true });
|
||||||
} else if (isItemView) {
|
} else if (isItemView) {
|
||||||
// Directly update nav links for the new mode without keepMedia complexity
|
// Directly update nav links for the new mode without keepMedia complexity
|
||||||
updateNavForMode(window.activeMode);
|
updateNavForMode(window.activeMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fromFilterModal) {
|
||||||
|
Promise.resolve(reloadPromise).finally(() => { window._keepFilterModal = false; });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (fromFilterModal) window._keepFilterModal = false;
|
||||||
// Fallback
|
// Fallback
|
||||||
window.location.href = modeBtn.href;
|
window.location.href = modeBtn.href;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
if (fromFilterModal) window._keepFilterModal = false;
|
||||||
console.error("Mode update failed:", err);
|
console.error("Mode update failed:", err);
|
||||||
window.location.href = modeBtn.href;
|
window.location.href = modeBtn.href;
|
||||||
});
|
});
|
||||||
@@ -6931,15 +6944,28 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
if (window.updateMimeLabel) window.updateMimeLabel();
|
if (window.updateMimeLabel) window.updateMimeLabel();
|
||||||
|
|
||||||
// Trigger reload context-aware
|
// Trigger reload context-aware
|
||||||
|
const fromModal = !!menu.closest('#excluded-tags-overlay');
|
||||||
const postsEl = document.querySelector('.posts, .tags-grid');
|
const postsEl = document.querySelector('.posts, .tags-grid');
|
||||||
|
let reloadPromise = null;
|
||||||
|
|
||||||
|
// Set flag so hideAllModals (called inside loadPageAjax) skips the filter overlay
|
||||||
|
if (fromModal) window._keepFilterModal = true;
|
||||||
|
|
||||||
if (postsEl) {
|
if (postsEl) {
|
||||||
if (window.loadPageAjax) window.loadPageAjax(url.toString(), { skipPush: true });
|
reloadPromise = window.loadPageAjax ? window.loadPageAjax(url.toString(), { skipPush: true }) : null;
|
||||||
} else if (document.getElementById('main')?.classList.contains('item-view') || document.querySelector('.item-layout-container, .item-main-content')) {
|
} else if (document.getElementById('main')?.classList.contains('item-view') || document.querySelector('.item-layout-container, .item-main-content')) {
|
||||||
// On item view, refresh the context but KEEP media playing
|
// On item view, refresh the context but KEEP media playing
|
||||||
if (window.loadItemAjax) window.loadItemAjax(url.toString(), true, { keepMedia: true });
|
reloadPromise = window.loadItemAjax ? window.loadItemAjax(url.toString(), true, { keepMedia: true }) : null;
|
||||||
} else {
|
} else {
|
||||||
// Fallback for non-AJAX pages
|
// Fallback for non-AJAX pages
|
||||||
window.location.reload();
|
if (!fromModal) window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the flag once the reload finishes (or immediately if no promise)
|
||||||
|
if (fromModal) {
|
||||||
|
Promise.resolve(reloadPromise).finally(() => {
|
||||||
|
window._keepFilterModal = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user