From ce04b268c3add587289e5e787e53a2d94c39417e Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Mon, 5 Feb 2024 15:17:02 -0600 Subject: [PATCH] Cache back button --- resources/common.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/resources/common.js b/resources/common.js index 4281bf5..2f579a7 100644 --- a/resources/common.js +++ b/resources/common.js @@ -467,4 +467,28 @@ $(function() { $nav_list.hide(); }); + $(window).on('beforeunload', function() { + let key = `oj-content-${window.location.href}`; + let $contentClone = $('#content').clone(); + $contentClone.find('.select2').remove(); + $contentClone.find('.select2-hidden-accessible').removeClass('select2-hidden-accessible'); + sessionStorage.setItem(key, JSON.stringify({ + "html": $contentClone.html(), + "page": window.page, + "has_next_page": window.has_next_page, + })); + }); + if (window.performance && + window.performance.navigation.type + === window.performance.navigation.TYPE_BACK_FORWARD) { + let key = `oj-content-${window.location.href}`; + let content = sessionStorage.getItem(key); + if (content) { + content = JSON.parse(content); + $('#content').html(content.html); + onWindowReady(); + window.page = content.page; + window.has_next_page = content.has_next_page; + } + } }); \ No newline at end of file