+
Добавьте к напитку:
+
@@ -63,6 +70,20 @@
Напиток №1
+
+
+

+
Заказ принят!
+
+
+
+ | Напиток |
+ Молоко |
+ Дополнительно |
+
+
+
+
diff --git a/index.js b/index.js
index e69de29..42035fb 100644
--- a/index.js
+++ b/index.js
@@ -0,0 +1,151 @@
+let beverageCount = 1;
+let beverageCounter = 1;
+let deleteButton = document.querySelector('.delete-button');
+let textArea = document.querySelector('.text-area');
+
+const addButton = document.querySelector('.add-button');
+const modalWindow = document.querySelector('.modal-window');
+const modalWindowContent = document.querySelector('.modal-window-content');
+const modalWindowButton = document.querySelector('.submit-button');
+
+
+const translation = {'espresso': 'Эспрессо',
+'capuccino': 'Капучино',
+'cacao': 'Какао',
+'usual': 'обычное',
+'no-fat': 'обезжиренное',
+'soy': 'соевое',
+'coconut': 'кокосовое',
+'whipped cream': 'взбитые сливки',
+'marshmallow': 'зефирки',
+'chocolate': 'шоколад',
+'cinnamon': 'корица'}
+
+
+function defineEnding(number, words) {
+ return words[(number % 100 > 4 && number % 100 < 20) ? 2 : [2, 0, 1, 1, 1, 2][(number % 10 < 5) ? Math.abs(number) % 10 : 5]];
+}
+
+function addBeverage() {
+ ++beverageCounter;
+ ++beverageCount;
+ document.querySelector('.add-button').insertAdjacentHTML('beforebegin', `
+
`);
+ const deleteButtons = document.getElementsByClassName('delete-button')
+ Array.from(deleteButtons).forEach(function(deleteButton) {
+ deleteButton.addEventListener('click', deleteBevarage);
+ });
+ const textAreas = document.getElementsByClassName('text-area');
+ Array.from(textAreas).forEach(function(textArea) {
+ textArea.addEventListener('keyup', printWishes);
+ });
+}
+
+function deleteBevarage(event) {
+ if (beverageCount > 1) {
+ const fieldsetID = event.target.parentNode.id;
+ document.getElementById(fieldsetID).remove();
+ --beverageCount;
+ }
+}
+
+function showModalWindow(event) {
+ event.preventDefault();
+ modalWindow.style.display = 'block';
+ modalWindowContent.style.display = 'inline';
+ for (let fieldset of document.querySelectorAll('fieldset')) {
+ const beverageType = translation[fieldset.querySelector('select').value];
+ let milkType;
+ for (const radioButton of document.querySelectorAll(`input[name="milk${fieldset.id}"]`)) {
+ if (radioButton.checked) {
+ milkType = translation[radioButton.value];
+ }
+ }
+ let additionaly = [];
+ for (const checkBox of document.querySelectorAll(`.additionaly${fieldset.id} .checkbox-field input`)) {
+ if (checkBox.checked) {
+ additionaly.push(translation[checkBox.value]);
+ }
+ }
+ document.querySelector('.table').insertAdjacentHTML('beforeend', `
+
+ | ${beverageType} |
+ ${milkType} |
+ ${additionaly.join(', ')} |
+
`)
+ };
+ modalWindowContent.querySelector('p').textContent = `Вы заказали ${beverageCount} ` + defineEnding(beverageCount, ['напиток', 'напитка', 'напитков']);
+}
+
+function hideModalWindow() {
+ modalWindow.style.display = 'none';
+ modalWindowContent.style.display = 'none';
+}
+
+function printWishes(event) {
+ let inputText = event.target.value;
+ const attentionWords = ['срочно', 'быстрее', 'побыстрее', 'скорее', 'поскорее', 'очень нужно'];
+ for (const word of attentionWords) {
+ inputText = inputText.replace(new RegExp(word, 'i'), `
$&`)
+ };
+ event.target.nextSibling.nextSibling.innerHTML = inputText;
+}
+
+addButton.addEventListener('click', addBeverage);
+deleteButton.addEventListener('click', deleteBevarage);
+modalWindowButton.addEventListener('click', showModalWindow);
+modalWindowContent.addEventListener('click', hideModalWindow);
+textArea.addEventListener('keyup', printWishes);
\ No newline at end of file
diff --git a/styles.css b/styles.css
index 68f5581..30cfc84 100644
--- a/styles.css
+++ b/styles.css
@@ -44,4 +44,81 @@
border: 2px solid orange;
border-radius: 5px;
}
+.delete-button img {
+ width: 15px;
+ height: 15px;
+}
+
+.delete-button {
+ position: relative;
+ bottom: 0px;
+ left: 200px;
+}
+
+.modal-window {
+ display: none;
+ position: fixed;
+ z-index: 1;
+ left: 0;
+ top: 0;
+ width: 100%;
+ height: 100%;
+ overflow: auto;
+ background-color: rgb(0,0,0);
+ background-color: rgba(0,0,0,0.4);
+}
+
+.modal-window-content {
+ display: none;
+ position: fixed;
+ z-index: 2;
+ width: 500px;
+ height: 25%;
+ overflow: auto;
+ background-color: rgb(255, 255, 255);
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ border-radius: 2%;
+}
+
+.modal-window-content h2 {
+ position: fixed;
+ text-align: center;
+ top: 5%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+}
+.modal-window-content img {
+ position: relative;
+ width: 7%;
+ height: 7%;
+ margin-left: 93%;
+ margin-top: 1%;
+}
+
+.modal-window-content p {
+ position: fixed;
+ left: 50%;
+ transform: translate(-50%, 50%);
+}
+
+.text-output {
+ word-break: break-word;
+ width: 170px;
+}
+
+.table, tr, td, th {
+ border: 1px solid black;
+}
+
+.table {
+ width: 400px;
+ height: 20px;
+ table-layout: fixed;
+ border-collapse: collapse;
+ margin-top: 50px;
+ margin-left: auto;
+ margin-right: auto;
+}