diff options
author | Thomas <> | 2022-08-17 12:52:38 +0200 |
---|---|---|
committer | Thomas <> | 2022-08-17 12:52:38 +0200 |
commit | e42c64bf1eddbb8f7d93d48b6c8f9481369a751f (patch) | |
tree | 38ccf9df5084e1424c2344d7bb92c5be27ef2b2a /basicConfig/ms-connector/webcontent/js/js_country.js | |
parent | 1f6c93f94b628e9e702f86fcaea6d34c858687fc (diff) | |
parent | d83cf36c1454a10f5a46d677b5f0f30e0cbe7e95 (diff) | |
download | National_eIDAS_Gateway-e42c64bf1eddbb8f7d93d48b6c8f9481369a751f.tar.gz National_eIDAS_Gateway-e42c64bf1eddbb8f7d93d48b6c8f9481369a751f.tar.bz2 National_eIDAS_Gateway-e42c64bf1eddbb8f7d93d48b6c8f9481369a751f.zip |
Merge branch 'nightlybuild' of gitlab.iaik.tugraz.at:egiz/eidas_at_proxy into nightlybuild
Diffstat (limited to 'basicConfig/ms-connector/webcontent/js/js_country.js')
-rw-r--r-- | basicConfig/ms-connector/webcontent/js/js_country.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/basicConfig/ms-connector/webcontent/js/js_country.js b/basicConfig/ms-connector/webcontent/js/js_country.js new file mode 100644 index 00000000..5dcea90e --- /dev/null +++ b/basicConfig/ms-connector/webcontent/js/js_country.js @@ -0,0 +1,42 @@ +function clickCountryFlag(element) { + if (!element) return false; + + var form = element.target.closest("form"); + + if (!form) return false; + + form.submit(); + return false; +} + + +/* Set JS events by EventListener to prevent problems with CSP*/ +document.addEventListener("DOMContentLoaded", function(event) { + + /* Element.closest polyfill - https://developer.mozilla.org/en-US/docs/Web/API/Element/closest License: public domain*/ + if (!Element.prototype.matches) + Element.prototype.matches = Element.prototype.msMatchesSelector || + Element.prototype.webkitMatchesSelector; + + if (!Element.prototype.closest) + Element.prototype.closest = function(s) { + var el = this; + if (!document.documentElement.contains(el)) return null; + do { + if (el.matches(s)) return el; + el = el.parentElement || el.parentNode; + } while (el !== null && el.nodeType === 1); + return null; + }; + + /* set Click events by EventListener to prevent JavaScript in HTML which can be a problem with CSP*/ + var allFlags = document.getElementsByClassName("countryimage"); + for (i=0;i<allFlags.length;i++) { + if(allFlags[i].getAttribute("disabled") == null) { + allFlags[i].closest("a").addEventListener('click', clickCountryFlag, false); + } + } +}); + + + |