diff --git a/README.md b/README.md index d724b75..f98bd8d 100644 --- a/README.md +++ b/README.md @@ -30,13 +30,20 @@ You can use the following options. `cookieDays` default: 365 // Amount of days the cookie is saved before erased by the browser. `classPrefix` default: "AMPEr" // If you want to use you own styling. `debugMode` default: false // Change this to true if you want to open the modal every pageload. -`extraClass` default: "" // Put an extra class for styling on the modal +`extraClass` default: "" // Put an extra class for styling on the modal +`underlay` default: false // Adds an div with id AMPEr_underlay to the document when the modal is active. +`instantSettings` default: false // Skips the intro and go straight to the settings. `language` default: "en" // What language from the lexicon we want to use. `lexicon` // see below for more information. `analyticCallback` default: `function () { console.log("Consent for analytic cookies!");` // Triggers when it has consent for analytic cookies. `marketingCallback` default: `function () { console.log("Consent for marketing cookies!");` // Triggers when it has consent for marketing cookies. `personalizationCallback` default: `function () { console.log("Consent for personalization cookies!");` // Triggers when it has consent for personalization cookies. +## extraClass +I added some default extra classes for a little different out of the box styling +We can use the following as a value for `extraClass` +`AMPEr--centered` This style has the modal centered in the screen, could be used with an underlay and instantSettings. +`AMPEr--bottom` This style has the intro modal as a bottom bar without the title, the settings are centered. # Lexicon options I'm just gonna paste the default lexicon here, you can change these values to make use of other icons / text. diff --git a/dist/AMPEr/css/AMPEr.css b/dist/AMPEr/css/AMPEr.css index a6c1e19..31c6ddc 100644 --- a/dist/AMPEr/css/AMPEr.css +++ b/dist/AMPEr/css/AMPEr.css @@ -208,12 +208,15 @@ html.using-mouse :focus + label span:last-child { display: block; } /* 7. Extra styling options */ +/* 7.1 bottom bar */ .AMPEr_modal.AMPEr--bottom { bottom: 0; left: 0; right: 0; width: 100%; border-radius: 0; } + .AMPEr_modal.AMPEr--bottom.AMPEr--settings-active { + padding: 0; } .AMPEr_modal.AMPEr--bottom #AMPEr_modal_1 { align-items: center; justify-content: space-between; } @@ -232,11 +235,12 @@ html.using-mouse :focus + label span:last-child { background-color: white; padding: 1rem; border-radius: 0.625rem; - max-width: 700px; + max-width: 400px; position: fixed; top: 50%; left: 50%; - transform: translate(-50%, -50%); } + transform: translate(-50%, -50%); + width: 100%; } @media screen and (max-width: 768px) { .AMPEr_modal.AMPEr--bottom #AMPEr_modal_1 { flex-wrap: wrap; } @@ -247,3 +251,46 @@ html.using-mouse :focus + label span:last-child { margin-top: 0; display: flex; justify-content: flex-end; } } + @media screen and (max-width: 420px) { + .AMPEr_modal.AMPEr--bottom #AMPEr_modal_2 { + width: 100%; + max-width: none; + top: unset; + left: unset; + bottom: 0; + transform: none; + border-radius: 0; + border-top-left-radius: 0.625rem; + border-top-right-radius: 0.625rem; } + .AMPEr_modal.AMPEr--bottom #AMPEr_modal_2 .AMPEr_modal_buttons { + justify-content: flex-end; } } + +/* 7.2 Centered (good for instant settings */ +.AMPEr_modal.AMPEr--centered { + left: 0; + right: 0; + margin-right: 0; + bottom: 0; + width: 100%; + border-radius: 0; + border-top-left-radius: 0.625rem; + border-top-right-radius: 0.625rem; } + @media screen and (min-width: 480px) { + .AMPEr_modal.AMPEr--centered { + position: fixed; + top: 50%; + left: 50%; + bottom: unset; + transform: translate(-50%, -50%); + width: 22rem; + border-radius: 0.625rem; } } + +/* 8 Underlay */ +#AMPEr_Underlay { + z-index: -1; + position: fixed; + left: 0; + right: 0; + top: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.4); } diff --git a/dist/AMPEr/js/AMPEr.js b/dist/AMPEr/js/AMPEr.js index 3d87789..eba0093 100644 --- a/dist/AMPEr/js/AMPEr.js +++ b/dist/AMPEr/js/AMPEr.js @@ -39,6 +39,8 @@ var AMPEr = function () { extraClass: "", debugMode: false, language: "en", + underlay: false, + instantSettings: false, lexicon: { en: { modalTitle: "Cookies!", @@ -135,10 +137,19 @@ var AMPEr = function () { html += ''; html += ''; html += ''; + + if (settings.underlay) { + html += '
'; + } + document.body.insertAdjacentHTML('beforeend', html); modal = document.getElementById('AMPEr_Cookies'); setFocus(); addModalListeners(); + + if (settings.instantSettings) { + showSettings(); + } }; /** * Adds all the functions for the checkboxes, buttons and keydown's @@ -273,6 +284,11 @@ var AMPEr = function () { var modal = document.getElementById("AMPEr_Cookies"); modal.remove(); firstFocusedElement.focus(); + + if (settings.underlay) { + var underlay = document.getElementById("AMPEr_Underlay"); + underlay.remove(); + } }; /** * Shows the settings content, sets focus to it @@ -283,8 +299,10 @@ var AMPEr = function () { var showSettings = function showSettings() { modal1 = document.getElementById("AMPEr_modal_1"); modal2 = document.getElementById("AMPEr_modal_2"); + var modal = document.getElementById("AMPEr_Cookies"); modal1.classList.remove("AMPEr--active"); modal2.classList.add("AMPEr--active"); + modal.classList.add("AMPEr--settings-active"); setFocusSettings(); }; /** diff --git a/dist/js/build/main.js b/dist/js/build/main.js index 8dd9fd1..cf1441d 100644 --- a/dist/js/build/main.js +++ b/dist/js/build/main.js @@ -4,8 +4,10 @@ function main() { a11yFocus(); AMPEr.init({ debugMode: true, - extraClass: "AMPEr--bottom", - language: "en" + extraClass: "AMPEr--centered", + language: "en", + underlay: true, + instantSettings: true }); } diff --git a/dist/js/main-concat.js b/dist/js/main-concat.js index 7dd6c6f..bf5b181 100644 --- a/dist/js/main-concat.js +++ b/dist/js/main-concat.js @@ -7,8 +7,10 @@ function main() { a11yFocus(); AMPEr.init({ debugMode: true, - extraClass: "AMPEr--bottom", - language: "en" + extraClass: "AMPEr--centered", + language: "en", + underlay: true, + instantSettings: true }); } diff --git a/src/AMPEr/js/AMPEr.js b/src/AMPEr/js/AMPEr.js index 5cdb56d..8e2105d 100644 --- a/src/AMPEr/js/AMPEr.js +++ b/src/AMPEr/js/AMPEr.js @@ -41,6 +41,8 @@ var AMPEr = (function () { extraClass: "", debugMode: false, language: "en", + underlay: false, + instantSettings: false, lexicon: { en: { modalTitle: "Cookies!", @@ -100,6 +102,7 @@ var AMPEr = (function () { const showCookieWindow = function () { let html; + html = '