Skip to content

Commit

Permalink
Fix hashchange event issue in custom.html
Browse files Browse the repository at this point in the history
  • Loading branch information
jmservera committed May 23, 2024
1 parent 0d3d50d commit b15b85f
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions web/_layouts/custom.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@
var level = parseInt(heading.tagName.slice(1));
var id = $(heading).attr('id');
var text = $(heading).text();
var link = $('<a>').attr('href', '#').text(text);
var link = $('<a>').attr('href', `#${id}`).text(text);

link.click(function() {
var step;

if(level==2){
step=$($(heading).parents('.section')[0]).find('.step:first')[0];
}
else{
step=$(heading).parents('.step')[0];
//TODO: manage hashchange at main level
$(window).on('hashchange', function(e){
if(location.hash==`#${id}`){
var step;
if(level==2){
step=$($(heading).parents('.section')[0]).find('.step:first')[0];
}
else{
step=$(heading).parents('.step')[0];
}
let current=steps.index(step);
changeIndex(current);
}
let current=steps.index(step);
changeIndex(current);
});



var item = $('<li>').append(link);

Expand Down Expand Up @@ -148,5 +148,9 @@
$(document).ready(function() {
codeCopy();
tutorial();
//TODO: Fix the issue with the hashchange event
let oldLoc=location;
window.location=location+"&";
window.location=oldLoc;
});
</script>

0 comments on commit b15b85f

Please sign in to comment.