From 00446f1cc3d7a68229cff07d571c83d900c6edf2 Mon Sep 17 00:00:00 2001 From: Anke Date: Fri, 8 Mar 2019 16:15:48 +0100 Subject: [PATCH 1/2] Remember tab when switching locale 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! --- templates/fields/_locale.twig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/templates/fields/_locale.twig b/templates/fields/_locale.twig index 3975d43..16582ee 100644 --- a/templates/fields/_locale.twig +++ b/templates/fields/_locale.twig @@ -114,3 +114,23 @@ background-color: transparent !important; } + + From f20bf92503463a8242151213810c33d4b821d769 Mon Sep 17 00:00:00 2001 From: Anke Date: Fri, 8 Mar 2019 16:34:04 +0100 Subject: [PATCH 2/2] Add script to existing script tags --- templates/fields/_locale.twig | 38 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/templates/fields/_locale.twig b/templates/fields/_locale.twig index 16582ee..f345ea0 100644 --- a/templates/fields/_locale.twig +++ b/templates/fields/_locale.twig @@ -77,6 +77,24 @@ ); {% endif %} }); + + 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); + } + }); + }; + } - -