Skip to content

Commit

Permalink
Added a modalIsOpen check, so that the openModal doesnt add a duplica…
Browse files Browse the repository at this point in the history
…te modal when its already open
  • Loading branch information
esens-bob committed Jul 5, 2021
1 parent 0ce9dca commit 189f2db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/AMPEr/js/AMPEr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* AMPEr is a vanilla js cookiebanner compliant with eu gdpr.
* (A)nalytic (M)arketing (P)ersonalization (E)ssential rozekoek.
*
* @version 2.1
* @version 2.2
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @author Bob Vrijland <bob@bahbv.net>
* @updated 15-12-2020
Expand All @@ -23,6 +23,7 @@ var AMPEr = (function () {
let settings;
let firstFocusedElement;
let firstTime = false;
let modalIsOpen = false;
let modal;
let modal1;
let modal2;
Expand Down Expand Up @@ -101,7 +102,7 @@ var AMPEr = (function () {
*/
const showCookieWindow = function () {
let html;

modalIsOpen = true;

html = '<div class="' + settings.classPrefix + '_modal '+ settings.extraClass + '" id="AMPEr_Cookies" role="dialog" aria-labelledby="AMPEr_title" aria-describedby="AMPEr_description">';
html += '<div class="' + settings.classPrefix + '_modal_inner">';
Expand Down Expand Up @@ -238,6 +239,7 @@ var AMPEr = (function () {
*/
const closeModal = function () {
const modal = document.getElementById("AMPEr_Cookies");
modalIsOpen = false;
modal.remove();
firstFocusedElement.focus();

Expand Down Expand Up @@ -383,7 +385,9 @@ var AMPEr = (function () {
* Add the modal to the html
*/
publicMethod.openModal = function () {
showCookieWindow();
if (!modalIsOpen){
showCookieWindow();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/AMPEr/scss/AMPEr.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* AMPEr is a vanilla js cookiebanner compliant with eu gdpr.
* (A)nalytic (M)arketing (P)ersonalization (E)ssential rozekoek.
*
* @version 2.1
* @version 2.2
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @author Bob Vrijland <bob@bahbv.net>
* @updated 15-12-2020
Expand Down

0 comments on commit 189f2db

Please sign in to comment.