diff options
author | Thomas <> | 2022-06-03 16:04:40 +0200 |
---|---|---|
committer | Thomas <> | 2022-06-03 16:04:40 +0200 |
commit | 0f0dcfc7a01c4b3a8b15b12b5257f08797fd0926 (patch) | |
tree | 7ec4e2d622a1fe848fcc3f941936bfe62b3c844a /ms_specific_connector/src/main/webapp/js/js_country.js | |
parent | 9d1d6626032aa59eb169e310ed239b94c0bc5447 (diff) | |
download | National_eIDAS_Gateway-0f0dcfc7a01c4b3a8b15b12b5257f08797fd0926.tar.gz National_eIDAS_Gateway-0f0dcfc7a01c4b3a8b15b12b5257f08797fd0926.tar.bz2 National_eIDAS_Gateway-0f0dcfc7a01c4b3a8b15b12b5257f08797fd0926.zip |
refactor(connector): move MS-Connector from new directory 'connector' to 'ms_specific_connector'
Diffstat (limited to 'ms_specific_connector/src/main/webapp/js/js_country.js')
-rw-r--r-- | ms_specific_connector/src/main/webapp/js/js_country.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/ms_specific_connector/src/main/webapp/js/js_country.js b/ms_specific_connector/src/main/webapp/js/js_country.js new file mode 100644 index 00000000..5dcea90e --- /dev/null +++ b/ms_specific_connector/src/main/webapp/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); + } + } +}); + + + |