From 171064816cd368cfeacb4b63f4117c864388b549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 14 Jun 2020 02:30:15 +0200 Subject: [PATCH] MAPG-125 add modal design --- public/static/css/mapguesser.css | 43 +++++++++++++++++++ public/static/js/mapguesser.js | 73 ++++++++++++++++++++++++++++++++ views/templates/main_header.php | 6 +++ 3 files changed, 122 insertions(+) diff --git a/public/static/css/mapguesser.css b/public/static/css/mapguesser.css index bddb9f4..1fec7b8 100644 --- a/public/static/css/mapguesser.css +++ b/public/static/css/mapguesser.css @@ -89,10 +89,18 @@ sub { margin-top: 10px; } +.marginLeft { + margin-left: 10px; +} + .marginBottom { margin-bottom: 10px; } +.marginRight { + margin-right: 10px; +} + .right { text-align: right; } @@ -230,6 +238,29 @@ input.big:focus, select.big:focus, textarea.big:focus { padding: 4px; } +div.modal { + position: fixed; + top: 100px; + background-color: #ffffff; + border-radius: 3px; + padding: 20px; + box-sizing: border-box; + z-index: 3; + visibility: hidden; +} + +#cover { + position: fixed; + top: 0; + left: 0; + bottom: 0; + right: 0; + background-color: #000000; + opacity: 0.5; + z-index: 2; + visibility: hidden; +} + p.formError { color: #7f2929; font-weight: 500; @@ -313,7 +344,19 @@ div.box { padding: 0; width: 100%; } + div.modal { + left: 20px; + right: 20px; + } div.box { width: initial; } } + +@media screen and (min-width: 600px) { + div.modal { + width: 540px; + left: 50%; + margin-left: -270px; + } +} diff --git a/public/static/js/mapguesser.js b/public/static/js/mapguesser.js index 06cbc89..92fef9e 100644 --- a/public/static/js/mapguesser.js +++ b/public/static/js/mapguesser.js @@ -18,6 +18,75 @@ var MapGuesser = { } else { xhr.send(); } + }, + + showModal: function (id) { + document.getElementById(id).style.visibility = 'visible'; + document.getElementById('cover').style.visibility = 'visible'; + }, + + showModalWithContent: function (title, body, extraButtons) { + if (typeof extraButtons === 'undefined') { + extraButtons = []; + } + + MapGuesser.showModal('modal'); + + document.getElementById('modalTitle').textContent = title; + + if (typeof body === 'object') { + document.getElementById('modalText').appendChild(body); + } else { + document.getElementById('modalText').textContent = body; + } + + var buttons = document.getElementById('modalButtons'); + buttons.textContent = ''; + + for (extraButton of extraButtons) { + var button = document.createElement(extraButton.type); + + if (extraButton.type === 'a') { + button.classList.add('button'); + } + + for (className of extraButton.classNames) { + button.classList.add(className); + } + + button.classList.add('marginTop'); + button.classList.add('marginRight'); + button.textContent = extraButton.text; + + if (extraButton.type === 'a') { + button.href = extraButton.href; + } else if (extraButton.type === 'button') { + button.onclick = extraButton.onclick; + } + + buttons.appendChild(button); + } + + var closeButton = document.createElement('button'); + + closeButton.classList.add('gray'); + closeButton.classList.add('marginTop'); + closeButton.textContent = 'Cancel'; + closeButton.onclick = function () { + MapGuesser.hideModal(); + }; + + buttons.appendChild(closeButton); + }, + + hideModal: function () { + var modals = document.getElementsByClassName('modal'); + + for (modal of modals) { + modal.style.visibility = 'hidden'; + } + + document.getElementById('cover').style.visibility = 'hidden'; } }; @@ -31,4 +100,8 @@ var MapGuesser = { } } } + + document.getElementById('cover').onclick = function () { + MapGuesser.hideModal(); + }; })(); diff --git a/views/templates/main_header.php b/views/templates/main_header.php index a487f11..6c2bb17 100644 --- a/views/templates/main_header.php +++ b/views/templates/main_header.php @@ -24,4 +24,10 @@
+
+
+ \ No newline at end of file