fix: prevent scrolling when switching between tabs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2023-03-30 11:44:07 +08:00
parent 40ebdae256
commit c5129082b7
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 24 additions and 19 deletions

View File

@ -580,10 +580,18 @@ if (UOJContest::cur()) {
// Change hash for page-reload // Change hash for page-reload
$('.nav-pills a').on('shown.bs.tab', function(e) { $('.nav-pills a').on('shown.bs.tab', function(e) {
var hash = e.target.hash;
if (e.target.hash == '#statement') { if (e.target.hash == '#statement') {
window.location.hash = ''; hash = '#';
}
if (window.history.pushState) {
// Update the address bar
window.history.pushState({}, '', hash);
} else { } else {
window.location.hash = e.target.hash; // Fallback for the old browsers which do not have `history.pushState()`
window.location.hash = hash;
} }
}); });
}); });

View File

@ -1340,21 +1340,6 @@ if ($cur_tab == 'index') {
</div> </div>
</div> </div>
</div> </div>
<script>
$(document).ready(function() {
// Javascript to enable link to tab
var hash = location.hash.replace(/^#/, '');
if (hash) {
bootstrap.Tab.jQueryInterface.call($('.nav-tabs a[href="#' + hash + '"]'), 'show').blur();
}
// Change hash for page-reload
$('.nav-tabs a').on('shown.bs.tab', function(e) {
window.location.hash = e.target.hash;
});
});
</script>
<?php elseif ($cur_tab == 'users') : ?> <?php elseif ($cur_tab == 'users') : ?>
<div class="card mt-3 mt-md-0"> <div class="card mt-3 mt-md-0">
<div class="card-header"> <div class="card-header">
@ -1791,7 +1776,13 @@ EOD;
// Change hash for page-reload // Change hash for page-reload
$('.nav-tabs a').on('shown.bs.tab', function(e) { $('.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;
}
}); });
}); });
</script> </script>

View File

@ -47,7 +47,13 @@ $(document).ready(function() {
// Change hash for page-reload // Change hash for page-reload
$('.nav-tabs a').on('shown.bs.tab', function(e) { $('.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;
}
}); });
}); });
</script> </script>