Skip to content

Commit

Permalink
Remember tab when switching locale
Browse files Browse the repository at this point in the history
I've encountered a few usecases where I'd like the localelink to switch to the same tab in the other language. When an editor asked for it I decided to try and add that to the extension. See what you think!
  • Loading branch information
Anke authored Mar 8, 2019
1 parent e6fc44b commit 00446f1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions templates/fields/_locale.twig
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,23 @@
background-color: transparent !important;
}
</style>

<script>
var localeTab = document.querySelector('#locale-select');
if (localeTab !== null) {
var links = localeTab.querySelectorAll('a');
window.onhashchange = function (){
var tab = window.location.hash.substr(1);
Array.prototype.forEach.call(links, function(link) {
var origHref = link.getAttribute('href').split('#')[0];
if (tab.length>0) {
link.setAttribute('href', origHref + '#' + tab);
}
});
};
}
</script>

0 comments on commit 00446f1

Please sign in to comment.