Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle hash in url, added navigation for Tabs, Fixes #1155 bug href link with html id does not link to the expected url #1306

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions web/static/custom/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3276,3 +3276,18 @@ function convertToCamelCase(inputString) {

return camelCaseString;
}

function handleHashInUrl(){
// this function handles hash in url used to tab navigation
const hash = window.location.hash;
if (hash) {
const targetId = hash.substring(1);
const tabLink = $(`a[href="#${targetId}"][data-bs-toggle="tab"]`);
if (tabLink.length) {
tabLink.tab('show');
setTimeout(() => {
tabLink.click();
}, 100);
}
}
}
9 changes: 9 additions & 0 deletions web/templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ <h4 class="page-title">{% block page_title %}{% endblock page_title %}</h4>
<script src="https://cdn.datatables.net/rowgroup/1.4.0/js/dataTables.rowGroup.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// for tabs with urls, we need to append the hash in the url
$('a[data-bs-toggle="tab"]').on('shown.bs.tab', function (e) {
var href = $(e.target).attr('href');
if (href && href.startsWith('#')) {
history.pushState(null, null, href);
}
});
$(window).on('hashchange', handleHashInUrl);
render_search_history('{{current_project.slug}}');

// rengine will also check everyday if update exists for rengine
Expand All @@ -132,6 +140,7 @@ <h4 class="page-title">{% block page_title %}{% endblock page_title %}</h4>
else{
$('#dark-mode-check').prop("checked", false).change();
}
handleHashInUrl();
});

function render_search_history(slug){
Expand Down
Loading