From f20bf92503463a8242151213810c33d4b821d769 Mon Sep 17 00:00:00 2001 From: Anke Date: Fri, 8 Mar 2019 16:34:04 +0100 Subject: [PATCH] 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); + } + }); + }; + } - -