HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<header>
<h1>Máquina de vendas JS ™</h1>
</header>
<main>
<dialog open class="init-dialog">
<p>Encontre o código do item que deseja comprar. Geralmente é listado em cada produto e organizado por linha ou coluna.</p>
<p>Insira suas notas de dinheiro e moedas para pagar pelos itens que deseja. Como alternativa, deslize, insira ou toque em um cartão de crédito/débito.</p>
<p>Se o item ficar preso durante a dispensação, você pode tentar abrir e fechar a porta da área de coleta para criar uma sucção que puxa o item para baixo.</p>
<button class="fechar-dialog">Fechar</button>
</dialog>
<dialog class="compra-dialog">
<div id="divAdd">
<label for="coin" id="coinBlk">Adicionar Moeda:
<select id="coin">
<option selected value="0.05">R$ 0.05</option>
<option value="0.10">R$ 0.10</option>
<option value="0.25">R$ 0.25</option>
<option value="0.50">R$ 0.50</option>
<option value="1.00">R$ 1.00</option>
</select><button id="addCoinBtn">Adicionar <br />R$ 0.05</button>
</label>
<label for="bill" id="billBlk">Adicionar Cédula:
<select id="bill">
<option selected value="1.00">R$ 1.00</option>
<option value="2.00">R$ 2.00</option>
<option value="5.00">R$ 5.00</option>
<option value="10.00">R$ 10.00</option>
<option value="20.00">R$ 20.00</option>
<option value="50.00">R$ 50.00</option>
<option value="100.00">R$ 100.00</option>
<option disabled value="200.00">R$ 200.00</option>
</select><button id="addBillBtn">Adicionar <br />R$ 1.00</button>
</label>
</div>
<button class="fechar-dialog">Fechar</button>
</dialog>
<section id="sectLeft">
<div class="productsContainer">
<div data-letterid="A" data-numberid="1" class="item">
<h2>Item 1</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/A1.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="B" data-numberid="1" class="item">
<h2>Item 2</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/B1.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="C" data-numberid="1" class="item">
<h2>Item 3</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/C1.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="D" data-numberid="1" class="item">
<h2>Item 4</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/D1.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="A" data-numberid="2" class="item">
<h2>Item 5</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/A2.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="B" data-numberid="2" class="item">
<h2>Item 6</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/B2.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="C" data-numberid="2" class="item">
<h2>Item 7</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/C2.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="D" data-numberid="2" class="item">
<h2>Item 8</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/D2.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="A" data-numberid="3" class="item">
<h2>Item 9</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/A3.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="B" data-numberid="3" class="item">
<h2>Item 10</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/B3.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="C" data-numberid="3" class="item">
<h2>Item 11</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/C3.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="D" data-numberid="3" class="item">
<h2>Item 12</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/D3.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="A" data-numberid="4" class="item">
<h2>Item 13</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/A4.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="B" data-numberid="4" class="item">
<h2>Item 14</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/B4.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="C" data-numberid="4" class="item">
<h2>Item 15</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/C4.png" alt="" />
<p>R$ 1.00</p>
</div>
<div data-letterid="D" data-numberid="4" class="item">
<h2>Item 16</h2>
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/D4.png" alt="" />
<p>R$ 1.00</p>
</div>
</div>
</section>
<section id="sectRight">
<div class="displayContainer">
<span id='responseDate'>--</span>
<span id='responseHour'>--</span>
<span id='responseTxt'>txt output</span>
</div>
<div id="displayTxt">
</div>
<label>Selecionar id:
<div class="button-grid">
<button class="button btn-letter">A</button>
<button class="button btn-letter">B</button>
<button class="button btn-letter">C</button>
<button class="button btn-letter">D</button>
<button class="button btn-number">1</button>
<button class="button btn-number">2</button>
<button class="button btn-number">3</button>
<button class="button btn-number">4</button>
<!-- <button class="button">5</button>
<button class="button">6</button>
<button class="button">7</button>
<button class="button">8</button>
<button class="button">9</button>
<button class="button">0</button> -->
<button id="btnCorrigir" class="button">Corrigir</button>
<button id="btnConfirmar" class="button">Confirmar</button>
</div></label>
<div id="blkimg" style="">
<img src="https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/00insert2.png" id="imgInsertBill" style="cursor: url(../img/00cursorInsert.png), auto;transform:scale(0.989);width:35%;height:auto;margin:auto" alt="" />
<!-- <img src="img/00insert3.png" id="imgInsertCoin" style="transform:scale(0.889);width:25%;height:auto;margin:auto" alt="" /> -->
<img src="img/00insert1.png" id="imgInsertCoin" style="cursor: url(https://raw.githubusercontent.com/Giusley/MaquinaDeVendasJS/main/img/00cursorInsert.png), auto;transform:scale(0.889);width:25%;height:auto;margin:auto" alt="" />
</div>
</section>
</main>
* {
scrollbar-width: auto;
scrollbar-color: #5588f8 #12034f;
box-sizing: border-box;
margin:0;padding:0;
/*font-size:1.2rem;
cursor:default; */
list-style: none;
-webkit-tap-highlight-color: rgba(41, 24, 113, 0.1);
text-transform: uppercase;
}
/* Chrome, Edge, and Safari */
*::-webkit-scrollbar {
width: 13px;
}
*::-webkit-scrollbar-track {
background: transparent;
}
*::-webkit-scrollbar-thumb {
background-color: #10CC00;
border-radius: 8px;
border: 2px inset #10CC0012;
}
dialog::backdrop {
position: fixed;
inset: 0px;
background: rgba(0, 0, 0, 0.25);
overflow-y:hidden!important;
backdrop-filter:blur(3.333px);
}
body{
padding:0;
font-family: Arial;
min-height: 100vh;
margin: 0;
background: rgb(24,26,29);
background: linear-gradient(180deg, rgba(24,26,29,1) 0%, rgba(0,0,0,1) 100%); background-attachment: fixed;
color:#cdcdcd;
overflow-y:auto;
overflow-x:hidden;
}
header{
width:80vw;
height:10vh;
background-color:transparent;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-content: center;
justify-content: center;
align-items: baseline;
}
header h1{
transform-origin: right;
color:#D0FF00;
text-align: center;
}
main{
display: flex;
width:100vw;
height:90vh;
flex-direction: row;
flex-wrap: wrap;
align-content: center;
justify-content: center;
align-items: flex-start;
}
#sectLeft{
width:60vw;
height:90vh;
padding:0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-content: center;
justify-content: flex-end;
align-items: center;
}
#sectRight{
width:40vw;
height:90vh;
padding:0;
display: flex;
flex-wrap: nowrap;
align-content: center;
align-items: stretch;
flex-direction: column;
}
.displayContainer{
min-width:160px;
min-height:60px;
width: 14vw;
height: 6vh;
background-color: #000;
color: #0fff0f;
border-radius:8px;
border:inset 1px rgba(24,26,29,1);
position:relative;
display:flex;
top:-5vh;
flex-direction: column;
align-items: center;
align-self:center;
justify-content: center;
align-content: center;
flex-wrap: nowrap;
}
.productsContainer {
transform:scale(.888);
transform-origin:center top;
top:0;
background-color:transparent;
border-radius:1em;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: .3em;
grid-row-gap: .3em;
justify-items: center;
align-items: center;
justify-content: center;
align-content: center;
}
.item {
width:96%;
transform:scale(1);
margin: 0;
border-radius: 4px;
border:solid 1px #A5A6AA12;
text-align: center;
background-color:#15161A34;
position:relative;
display: grid;
align-content: center;
justify-content: center;
align-items: end;
justify-items: center;
gap: 0;
}
.item:nth-child(1):before {position:absolute;top:-25px;left:48px;content:'A';}
.item:nth-child(2):before {position:absolute;top:-25px;left:48px;content:'B';}
.item:nth-child(3):before {position:absolute;top:-25px;left:48px;content:'C';}
.item:nth-child(4):before {position:absolute;top:-25px;left:48px;content:'D';}
.item:nth-child(1):after {position:absolute;top:40%;left:-25px;content:'1';}
.item:nth-child(5):after {position:absolute;top:40px;left:-25px;content:'2';}
.item:nth-child(9):after {position:absolute;top:40px;left:-25px;content:'3';}
.item:nth-child(13):after {position:absolute;top:40%;left:-25px;content:'4';}
.item h2{
width:100%;
transform:translateY(1vh);
place-self:baseline;
text-align:center;
position:absolute;
font-family:verdana;
font-size:.75rem;
z-index:2;
}
.item img{
width: 90%;
height:8vh;
top:0;
left:5%;
height:auto;
position:relative;
image-rendering: -webkit-optimize-contrast;
transform: scale(0.75);
filter:drop-shadow(0px 0px 3px #15161A);
}
.item p{
text-align:center;
place-self:baseline;
position:absolute;
bottom:0px;left:0px;
width:100%;
border-radius: 4px;
z-index:3;
color:#0fff0f;
}
/* //////////////////////////////////////////// */
#displayTxt{
min-width:320px;
min-height:120px;
width: 28vw;
height: 10vh;
background-color: #000;
color: #0fff0f;
font-size: 20px;
text-align: left;
text-align-last:left;
padding:0.225rem;
border-radius:8px;
border:inset 1px rgba(24,26,29,1);
font-family: "Courier New", monospace;
font-variant-numeric: tabular-nums;
font-size: 1.25rem; /* Tamanho da fonte em relação ao valor padrão do navegador */
line-height: 1.25rem; /* Altura da linha em relação ao tamanho da fonte */
line-break: loose;
overflow-y:auto;
overflow-x:none;
direction: ltr;
}
#divAdd{
display: grid;
align-content: space-between;
justify-content: start;
align-items: start;
justify-items: stretch;
gap: .81em;
}
#blkimg{
display:flex;
}
label {
display: block;
margin-top: 10px;
font-weight: bold;
color: #eee;
}
select {
width: 206px;
padding: 10px;
font-size: 16px;
border-radius: 4px;
border: 1px solid #ccc;
background-color: #fff;
}
select:focus, button:focus {
outline: none;
border-color: #8fd0d2;
}
select option {
font-size: 14px;
}
button{
padding: 10px;
font-size: 14px;
border-radius: 4px;
border: 1px solid #ccc;
background-color: #fff;
}
.button-grid {
width:fit-content;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 2px;
justify-items: center;
}
.button {
padding: 0px!important;
width: 50px;
height: 50px;
border: none;
border-radius: 4px;
background-color: #ccc;
color: #333;
font-size: 22px;
font-weight: bold;
cursor: url(../img/00padIco.png), auto;
transition: background-color 0.3s ease;
}
.button:nth-child(9),.button:nth-child(10){
font-size: 8px;
}
.button:hover {
background-color: #999;
}
.activeLetter{
background-color: #555;
color:white;
}
.activeNumber{
background-color: #555;
color:white;
}
label[for=coin], label[for=bill] {
display: none;
}
.compra-dialog,.init-dialog {
display:flex;
flex-direction:column;
width: 400px;
padding: 20px;
background-color: #f0f0f0;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
text-align: center;
z-index:88;
align-self:center;
position:absolute;
left:auto;
right:auto;
}
.compra-dialog{display:none}
.fechar-dialog {
margin-top: 20px;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
.fechar-dialog:hover {
background-color: #0056b3;
}
console.log(...['%c█ Máquina de vendas JS ™ \n',
'font-size: 1.6em; color: blue; text-shadow: 2px 2px 4px #000000;']);
console.log(...['%cMáquina de vendas JS ™ - por Giusley Camilo',
`background:#ffffff23;font-size: 1.2em; color: cyan;
text-shadow: 2px 2px 4px #000000; color: 110% blue;`]);
/**████████████████████████████████████████████████████████████████████████*/
/** @App: Máquina de vendas JS ™███████████████████████████████████████████*/
/** @Version: 1.0 - jun2023; ███████████████████████████████████████████*/
/** @author: Giusley Camilo; ███████████████████████████████████████████*/
/** @Data: jun2023| -- ; ███████████████████████████████████████████*/
/**████████████████████████████████████████████████████████████████████████*/
const textRandomArray = [
'Bem vindo!',
'Máquina de vendas JS ™',
'Desenvolvido por:Giusley Camilo',
'Escolha algum item'
];
var currentCredits = 0;
var pLetterId = null;
var pNumberId = null;
var boolSelected = false;
var nomeDoProduto = pLetterId + pNumberId;
let currentTxtIndex = 0;
let animateTextInterval;
let updateDateTimeInterval;
const responseDate = document.getElementById('responseDate');
const responseHour = document.getElementById('responseHour');
const responseTxt = document.getElementById('responseTxt');
const displayTxt = document.getElementById('displayTxt');
const btnLetter = document.querySelectorAll('.btn-letter')
const btnNumber = document.querySelectorAll('.btn-number')
const btnCorrigir = document.querySelector('#btnCorrigir')
const btnConfirmar = document.querySelector('#btnConfirmar')
const divAdd = document.querySelector('#divAdd')
const coin = document.querySelector('#coin')
const bill = document.querySelector('#bill')
const coinSelect = document.getElementById('coin');
const billSelect = document.getElementById('bill');
const imgInsertBill = document.getElementById('imgInsertBill');
const imgInsertCoin = document.getElementById('imgInsertCoin');
const addCoinBtn = document.getElementById('addCoinBtn');
const addBillBtn = document.getElementById('addBillBtn');
const compraDialog = document.querySelector('.compra-dialog');
const initDialog = document.querySelector('.init-dialog');
const fecharDialogButton = document.querySelectorAll('.fechar-dialog');
const productsContainer = document.querySelector('.productsContainer')
const itemBlk = document.querySelectorAll('.item')
var updateCredit = `CRÉDITOS: R$ ${currentCredits.toFixed(2)}`;
var produtosDisp = {
A1: { NOME: "nuts azul", PRECO: 1.25 },
B1: { NOME: "nuts amarelo", PRECO: 1.15 },
C1: { NOME: "chips bacon", PRECO: 0.99 },
D1: { NOME: "chocolate green", PRECO: 2.49 },
A2: { NOME: "chips pote", PRECO: 3.00 },
B2: { NOME: "aneis de cebola", PRECO: 1.50 },
C2: { NOME: "batata palito", PRECO: 1.10 },
D2: { NOME: "batata ondulada", PRECO: 1.20 },
A3: { NOME: "biscoito green", PRECO: 0.75 },
B3: { NOME: "biscoito vermelho", PRECO: 0.80 },
C3: { NOME: "amendoim vermelho", PRECO: 0.95 },
D3: { NOME: "batata chips", PRECO: 1.05 },
A4: { NOME: "chocolate black", PRECO: 2.80 },
B4: { NOME: "chocolate meio-amargo", PRECO: 2.50 },
C4: { NOME: "pastilhas chocolate", PRECO: 1.30 },
D4: { NOME: "chocolate pastilhas", PRECO: 1.40 }
};
window.getSelection().removeAllRanges(); // remover seleção de texto
for (const img of document.querySelectorAll("img")) {
img.draggable = false;
}
document.getElementById("billBlk").style.display = "grid"
document.getElementById("coinBlk").style.display = "grid"
/*██ PAINEL EXIBIR ITENS ████████████████████████████████████████████████████*/
imgInsertBill.addEventListener('click',()=>{
//imgInsertBill.style.display = "none"
compraDialog.setAttribute('open','');
compraDialog.style.display = 'flex';
})
imgInsertCoin.addEventListener('click',()=>{
//imgInsertCoin.style.display = "none"
compraDialog.setAttribute('open','');
compraDialog.style.display = 'flex';
})
Array.from(productsContainer.children).forEach((element)=>{
let novoFilho = document.createElement("div");
let imageName = element.firstElementChild.nextElementSibling.getAttribute('src')
let fileName = imageName.split('/').pop().substr(0, 2); // Extrai apenas o nome do arquivo
//console.log(produtosDisp[fileName].NOME)
element.firstElementChild.textContent = produtosDisp[fileName].NOME
element.lastElementChild.textContent = `R$ ${produtosDisp[fileName].PRECO}`;
element.addEventListener('click', (e)=>{
Array.from(productsContainer.children).forEach(e=>{
e.style.filter = 'none';
e.firstElementChild.nextElementSibling.style.filter = 'none';
})
element.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
element.firstElementChild.nextElementSibling.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
clearTxtDisplay()
pLetterId = element.dataset.letterid;
pNumberId = element.dataset.numberid;
boolSelected = true
novoFilho.innerHTML = `<div>CRÉDITOS: R$ ${currentCredits.toFixed(2)}<br>
Produto: ${element.firstElementChild.textContent} <br>Preço: R$ ${parseFloat(element.lastElementChild.textContent.substring(2))} <br>
CONFIRMAR|CORRIGIR</div>`
checkItem(element.dataset.letterid + element.dataset.numberid)
displayTxt.appendChild(novoFilho);
})
})
/*██ PAINEL SELECIONAR:NÚMEROS ██████████████████████████████████████████████*/
Array.from(btnNumber).forEach(element=>{
element.addEventListener('click', (e)=>{
pNumberId = parseInt(element.textContent)
clearTxtDisplay()
let novoFilho = document.createElement("div");
if(pLetterId != null){
boolSelected = true
novoFilho.innerHTML = `<div>CRÉDITOS: R$ ${currentCredits.toFixed(2)}<br>
Produto: ${pLetterId}${pNumberId} – ${produtosDisp[pLetterId + pNumberId].NOME} <br>
CONFIRMAR|CORRIGIR</div>`
checkItem(pLetterId + pNumberId)
} else {
boolSelected = false
pNumberId = null
novoFilho.innerHTML = `<div><div>CRÉDITOS: R$ ${currentCredits.toFixed(2)}<br>
Primeiro, selecione a identificação <br>(letra e numero do produto)</div>`
}
displayTxt.appendChild(novoFilho);
for(let rm of btnNumber) rm.classList.remove('activeNumber')
element.classList.add('activeNumber')
})
element.addEventListener('mouseover', (e)=>{
let chk = element.textContent
Array.from(productsContainer.children).forEach(e=>{
e.style.filter = 'none';
e.firstElementChild.nextElementSibling.style.filter = 'none';
})
const nums = productsContainer.querySelectorAll(`[data-numberid="${e.target.textContent}"]`);
//elm.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
//elm.firstElementChild.nextElementSibling.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
Array.from(nums).forEach((elm) => {
//console.log(elm)
if(elm.dataset.letterid == pLetterId){
elm.setAttribute("style", "filter: drop-shadow(0px 0px 4px #15ff1A);");
const childElement = elm.firstElementChild.nextElementSibling;
if (childElement) {
childElement.setAttribute("style", "filter: drop-shadow(0px 0px 4px #15ff1A);");
}
} else {
elm.style.filter = 'none';
elm.firstElementChild.nextElementSibling.style.filter = 'none';
}
});
});
})
/*██ PAINEL SELECIONAR:LETRAS ██████████████████████████████████████████████*/
Array.from(btnLetter).forEach(element=>{
element.addEventListener('click', (e)=>{
pLetterId = element.textContent
clearTxtDisplay()
let novoFilho = document.createElement("div");
novoFilho.innerHTML = `<div><div>CRÉDITOS: R$ ${currentCredits.toFixed(2)}<br>
Produto: ${pLetterId} - <br>Selecione o numero de identificação do produto</div>`;
displayTxt.appendChild(novoFilho);
for(let rm of btnLetter) rm.classList.remove('activeLetter')
element.classList.add('activeLetter')
})
element.addEventListener('mouseover', (e)=>{
let chk = element.textContent
clearSelected()
switch(chk){
case 'A' :
Array.from(productsContainer.children).forEach((elm,idx)=>{
if(elm.dataset.letterid == "A"){
elm.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
elm.firstElementChild.nextElementSibling.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
}
})
;break;
case 'B' :
Array.from(productsContainer.children).forEach((elm,idx)=>{
if(elm.dataset.letterid == "B"){
elm.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
elm.firstElementChild.nextElementSibling.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
}
})
;break;
case 'C' :
Array.from(productsContainer.children).forEach((elm,idx)=>{
if(elm.dataset.letterid == "C"){
elm.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
elm.firstElementChild.nextElementSibling.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
}
})
;break;
case 'D' :
Array.from(productsContainer.children).forEach((elm,idx)=>{
if(elm.dataset.letterid == "D"){
elm.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
elm.firstElementChild.nextElementSibling.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
}
})
;break;
default :
console.log('default');break;
}
});
})
function clearSelected(){
Array.from(productsContainer.children).forEach(e=>{
e.style.filter = 'none';
e.firstElementChild.nextElementSibling.style.filter = 'none';
})
}
coinSelect.addEventListener('change', () => {updateTxtDisplay()});
billSelect.addEventListener('change', () => {updateTxtDisplay()});
addCoinBtn.addEventListener('click', () => {
currentCredits += parseFloat(coinSelect.value);
updateTxtDisplay()
});
addBillBtn.addEventListener('click', () => {
currentCredits += parseFloat(billSelect.value);
updateTxtDisplay()
});
btnCorrigir.addEventListener('click', () => {
clearTxtDisplay()
let novoFilho = document.createElement("div");
if(pLetterId == null){
novoFilho.innerHTML = `<div>${updateCredit}<br>` + `<br>Selecione a letra de identificação</div>`;
} else {
novoFilho.innerHTML = `<div><div>CRÉDITOS: R$ ${currentCredits.toFixed(2)}<br>Selecione novamente a letra de identificação</div>`;
console.log(pLetterId.target)
}
displayTxt.appendChild(novoFilho);
pLetterId = null;
pNumberId = null;
boolSelected = false;
for(let rm of btnLetter) rm.classList.remove('activeLetter')
for(let rm of btnNumber) rm.classList.remove('activeNumber')
});
btnConfirmar.addEventListener('click', () => {
clearTxtDisplay()
let novoFilho = document.createElement("div");
if(currentCredits == 0){
novoFilho.innerHTML = `<div>CRÉDITOS: R$ ${currentCredits.toFixed(2)}<br>SALDO INSUFICIENTE<br>inserir dinheiro</div>`
displayTxt.appendChild(novoFilho);
return;
}
if(boolSelected){
const nowData = new Date();
if(Number(currentCredits.toFixed(2)) < produtosDisp[pLetterId + pNumberId].PRECO){
console.log(`valor: ${produtosDisp[pLetterId + pNumberId].PRECO}\ncréditos: ${parseFloat(currentCredits.toFixed(2))}`)
novoFilho.innerHTML = `<div>
VALOR INSUFICIENTE ****<br>
Valor: R$ ${produtosDisp[pLetterId + pNumberId].PRECO}<br>
CRÉD.: R$ ${currentCredits.toFixed(2)}<br>
<br></div>`;
displayTxt.appendChild(novoFilho);
return;
} else {
let troco = Number(currentCredits.toFixed(2) - produtosDisp[pLetterId + pNumberId].PRECO).toFixed(2)
currentCredits = parseFloat(troco)
responseTxt.textContent = `CRÉDITOS: R$ ${currentCredits.toFixed(2)}`
novoFilho.innerHTML = `<div>
Produto: ${produtosDisp[pLetterId + pNumberId].NOME}<br>
Valor: R$ ${produtosDisp[pLetterId + pNumberId].PRECO}<br>
Troco: R$ ${troco}<br>
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■<br>
OBRIGADO PELA PREFERÊNCIA!<br>
<br>
</div>`;
displayTxt.appendChild(novoFilho);
}
pLetterId = null;
pNumberId = null;
boolSelected = false;
for(let rm of btnLetter) rm.classList.remove('activeLetter')
for(let rm of btnNumber) rm.classList.remove('activeNumber')
return;
}
if(pLetterId == null && pNumberId == null){
novoFilho.innerHTML = `<div>CRÉDITOS: R$ ${currentCredits.toFixed(2)}<br>O Produto não foi selecionado.<br> Selecione a letra e o número de identificação</div>`;
}
if(pLetterId == null){
if(pNumberId == null){
novoFilho.innerHTML = `<div>CRÉDITOS: R$ ${currentCredits.toFixed(2)}<br>O Produto não foi selecionado.<br> Selecione o número de identificação</div>`;
}
novoFilho.innerHTML = `<div>CRÉDITOS: R$ ${currentCredits.toFixed(2)}<br>O Produto não foi selecionado</div>`;
displayTxt.appendChild(novoFilho);
return;
}
if(pNumberId == null){
if(pLetterId == null){
novoFilho.innerHTML = `<div>Selecione a letra de identificação</div>`;
}
novoFilho.innerHTML = `<div>Número de identificação não foi selecionado</div>`;
displayTxt.appendChild(novoFilho);
return;
}
displayTxt.appendChild(novoFilho);
});
btnConfirmar.addEventListener('mouseover', () => {
clearSelected()
Array.from(productsContainer.children).forEach((elm,idx)=>{
if(elm.dataset.letterid == pLetterId && elm.dataset.numberid == pNumberId){
console.log(elm)
elm.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
elm.firstElementChild.nextElementSibling.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
}
})
})
function checkItem(item){
const strCompare = `${produtosDisp[pLetterId + pNumberId].NOME}`
const itemElements = document.querySelectorAll('.item');
const elementoEncontrado = Array.from(itemElements).find(item => {
const h2Element = item.querySelector('h2');
return h2Element && h2Element.textContent.includes(strCompare);
});
const imageElement = elementoEncontrado.firstElementChild.nextElementSibling
Array.from(itemElements).forEach(e=>{
e.style.filter = 'none';
e.firstElementChild.nextElementSibling.style.filter = 'none';
})
elementoEncontrado.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
imageElement.setAttribute("style", "filter:drop-shadow(0px 0px 4px #15ff1A);");
}
function updateDateTime() {
const now = new Date();
const dateTimeStringOptions = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false
};
const dateStringOptions = {
day: '2-digit',
month: '2-digit',
year: '2-digit'
};
const timeStringOptions = {
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
//const dateTimeString = now.toLocaleString('pt-BR', dateTimeStringOptions);
const dateString = now.toLocaleDateString('pt-BR', dateStringOptions);
const timeString = now.toLocaleTimeString('pt-BR', timeStringOptions);
responseDate.textContent = dateString;
responseHour.textContent = timeString;
responseTxt.textContent = `CRÉDITOS: R$ ${currentCredits.toFixed(2)}`//dateTimeString;
}
let displayCounter = document.querySelector('#displayTxt').children.length
function clearTxtDisplay(){
while(document.getElementById('displayTxt').firstChild){
document.getElementById('displayTxt').removeChild(displayTxt.firstChild);
}
}
function updateTxtDisplay(){
clearTxtDisplay()
updateCredit = `CRÉDITOS: R$ ${currentCredits.toFixed(2)}`;
let novoFilho = document.createElement("div");
novoFilho.innerHTML = `<div>${updateCredit}<br></div>`;
displayTxt.appendChild(novoFilho);
addCoinBtn.lastChild.textContent = `R$ ${parseFloat(coinSelect.value).toFixed(2)}`
addBillBtn.lastChild.textContent = `R$ ${parseFloat(billSelect.value).toFixed(2)}`
responseTxt.textContent = `CRÉDITOS: R$ ${currentCredits.toFixed(2)}`
//displayTxt.textContent = updateCredit + randomTxt
}
function animateText() {
updateTxtDisplay();
currentTxtIndex = (currentTxtIndex + 1) % textRandomArray.length;
}
document.addEventListener('DOMContentLoaded', () => {
//animateTextInterval = setInterval(animateText, 5000);
updateDateTimeInterval = setInterval(updateDateTime, 1000);
startCounter();
});
function startCounter() {
let count = 0;
const interval = setInterval(() => {
count++;
let novoFilho = document.createElement("div");
novoFilho.innerHTML = `<div>Carregando...<br></div>`;
displayTxt.appendChild(novoFilho);
if (count >= 4) {
updateTxtDisplay();
clearInterval(interval);
}
}, 1000);
}
Array.from(fecharDialogButton).forEach(e=>{
e.addEventListener('click', () => {
compraDialog.removeAttribute('open');
initDialog.removeAttribute('open');
compraDialog.style.display = 'none';
initDialog.style.display = 'none';
});
})
window.addEventListener('click', (event) => {
if (event.target === compraDialog) {
compraDialog.removeAttribute('open');
}
});
Also see: Tab Triggers