From c5129082b7c54caecf0f1512191bb57b283cdab8 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 30 Mar 2023 11:44:07 +0800 Subject: [PATCH] fix: prevent scrolling when switching between tabs --- web/app/controllers/problem.php | 12 ++++++++++-- web/app/controllers/super_manage.php | 23 +++++++---------------- web/app/views/contest-backstage.php | 8 +++++++- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/web/app/controllers/problem.php b/web/app/controllers/problem.php index a3a1eee..1b9b4ea 100644 --- a/web/app/controllers/problem.php +++ b/web/app/controllers/problem.php @@ -580,10 +580,18 @@ if (UOJContest::cur()) { // Change hash for page-reload $('.nav-pills a').on('shown.bs.tab', function(e) { + var hash = e.target.hash; + if (e.target.hash == '#statement') { - window.location.hash = ''; + hash = '#'; + } + + if (window.history.pushState) { + // Update the address bar + window.history.pushState({}, '', hash); } else { - window.location.hash = e.target.hash; + // Fallback for the old browsers which do not have `history.pushState()` + window.location.hash = hash; } }); }); diff --git a/web/app/controllers/super_manage.php b/web/app/controllers/super_manage.php index c576e83..f39c980 100644 --- a/web/app/controllers/super_manage.php +++ b/web/app/controllers/super_manage.php @@ -1340,21 +1340,6 @@ if ($cur_tab == 'index') { - -
@@ -1791,7 +1776,13 @@ EOD; // Change hash for page-reload $('.nav-tabs a').on('shown.bs.tab', function(e) { - window.location.hash = e.target.hash; + if (window.history.pushState) { + // Update the address bar + window.history.pushState({}, '', e.target.hash); + } else { + // Fallback for the old browsers which do not have `history.pushState()` + window.location.hash = e.target.hash; + } }); }); diff --git a/web/app/views/contest-backstage.php b/web/app/views/contest-backstage.php index 4b25088..3035a1d 100644 --- a/web/app/views/contest-backstage.php +++ b/web/app/views/contest-backstage.php @@ -47,7 +47,13 @@ $(document).ready(function() { // Change hash for page-reload $('.nav-tabs a').on('shown.bs.tab', function(e) { - window.location.hash = e.target.hash; + if (window.history.pushState) { + // Update the address bar + window.history.pushState({}, '', e.target.hash); + } else { + // Fallback for the old browsers which do not have `history.pushState()` + window.location.hash = e.target.hash; + } }); });