Simplify common.js
This commit is contained in:
parent
7250c71e93
commit
67888bcd27
2 changed files with 8 additions and 66 deletions
|
@ -426,59 +426,6 @@ function submitFormWithParams($form, method) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveCurrentPageToSessionStorage() {
|
|
||||||
const storageLimit = 5;
|
|
||||||
const sessionStorageKey = 'oj-content-keys';
|
|
||||||
|
|
||||||
let key = `oj-content-${window.location.href}`;
|
|
||||||
let $contentClone = $('body').clone();
|
|
||||||
$contentClone.find('.select2').remove();
|
|
||||||
$contentClone.find('.select2-hidden-accessible').removeClass('select2-hidden-accessible');
|
|
||||||
$contentClone.find('.noUi-base').remove();
|
|
||||||
$contentClone.find('.wmd-button-row').remove();
|
|
||||||
|
|
||||||
let contentData = JSON.stringify({
|
|
||||||
"html": $contentClone.html(),
|
|
||||||
"page": window.page,
|
|
||||||
"has_next_page": window.has_next_page,
|
|
||||||
"scrollOffset": $(window).scrollTop(),
|
|
||||||
});
|
|
||||||
|
|
||||||
let keys = JSON.parse(sessionStorage.getItem(sessionStorageKey)) || [];
|
|
||||||
|
|
||||||
// Remove the existing key if it exists
|
|
||||||
if (keys.includes(key)) {
|
|
||||||
keys = keys.filter(k => k !== key);
|
|
||||||
}
|
|
||||||
|
|
||||||
keys.push(key);
|
|
||||||
|
|
||||||
if (keys.length > storageLimit) {
|
|
||||||
let oldestKey = keys.shift();
|
|
||||||
sessionStorage.removeItem(oldestKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionStorage.setItem(sessionStorageKey, JSON.stringify(keys));
|
|
||||||
sessionStorage.setItem(key, contentData);
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadPageFromSessionStorage() {
|
|
||||||
let key = `oj-content-${window.location.href}`;
|
|
||||||
let content = sessionStorage.getItem(key);
|
|
||||||
if (content) {
|
|
||||||
content = JSON.parse(content);
|
|
||||||
$('body').html(content.html);
|
|
||||||
onWindowReady();
|
|
||||||
window.PAGE_FROM_BACK_BUTTON_CACHE = true;
|
|
||||||
setTimeout(() => {
|
|
||||||
$(window).scrollTop(content.scrollOffset - 50);
|
|
||||||
}, 1);
|
|
||||||
window.page = content.page;
|
|
||||||
window.has_next_page = content.has_next_page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let currentRequest = null; // Variable to keep track of the current request
|
|
||||||
|
|
||||||
function navigateTo(url, reload_container, force_new_page=false) {
|
function navigateTo(url, reload_container, force_new_page=false) {
|
||||||
if (url === '#') return;
|
if (url === '#') return;
|
||||||
|
@ -491,17 +438,16 @@ function navigateTo(url, reload_container, force_new_page=false) {
|
||||||
reload_container = "#content";
|
reload_container = "#content";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentRequest) {
|
if (window.currentRequest) {
|
||||||
currentRequest.abort();
|
window.currentRequest.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const signal = controller.signal;
|
const signal = controller.signal;
|
||||||
currentRequest = controller;
|
window.currentRequest = controller;
|
||||||
|
|
||||||
$(window).off("scroll");
|
$(window).off("scroll");
|
||||||
|
|
||||||
saveCurrentPageToSessionStorage();
|
|
||||||
replaceLoadingPage(reload_container);
|
replaceLoadingPage(reload_container);
|
||||||
|
|
||||||
const toUpdateElements = [
|
const toUpdateElements = [
|
||||||
|
@ -774,15 +720,11 @@ function registerNavList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
if (typeof window.currentRequest === 'undefined') {
|
||||||
|
window.currentRequest = null;
|
||||||
|
}
|
||||||
onWindowReady();
|
onWindowReady();
|
||||||
registerNavList();
|
registerNavList();
|
||||||
$(window).on('beforeunload', saveCurrentPageToSessionStorage);
|
|
||||||
|
|
||||||
if (window.performance &&
|
|
||||||
window.performance.navigation.type
|
|
||||||
=== window.performance.navigation.TYPE_BACK_FORWARD) {
|
|
||||||
loadPageFromSessionStorage();
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('popstate', (e) => {
|
window.addEventListener('popstate', (e) => {
|
||||||
window.location.href = e.currentTarget.location.href;
|
window.location.href = e.currentTarget.location.href;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
{{_('Delete')}}
|
{{_('Delete')}}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if request.user.is_staff and request.profile != message.author %}
|
{% if request.user.is_staff and request.profile != message.author and not message.room_id %}
|
||||||
<a class="red chatbtn_remove_mess chat_mute" value="{{message.id}}" style="cursor: pointer;">
|
<a class="red chatbtn_remove_mess chat_mute" value="{{message.id}}" style="cursor: pointer;">
|
||||||
{{_('Mute')}}
|
{{_('Mute')}}
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Reference in a new issue