feat(Footer): Adiciona função observer

This commit is contained in:
William Simão Cavalcante 2022-12-16 19:49:26 -03:00
parent 6d2af82fc7
commit 1b7b5f7edf
5 changed files with 125 additions and 77 deletions

View File

@ -7,34 +7,63 @@ export default class Footer {
async init() {
await this.selectors();
this.requestApi();
this.addCarrossel();
this.verificaPag();
await this.onUpdate();
this.creatPaymentsIcons();
this.creatVtexIconPci();
this.creatDevIconsM3();
this.onUpdate();
this.addProdutos();
await this.addCarrossel();
}
async selectors() {
this.checkoutVazio = await waitElement(".empty-cart-content");
this.divPrateleira = await waitElement('.footerCheckout__prateleira');
this.tituloPrateleira = await waitElement('#cart-title')
this.payments = await waitElement('.footerCheckout__payments');
this.vtexIconPci = await waitElement('.footerCheckout__vtexpci');
this.devIcons = await waitElement('.footerCheckout__developedBy');
this.continuarComprando = await waitElement('.empty-cart-links');
}
onUpdate() {
async onUpdate() {
let target = this.checkoutVazio;
let config = { childList: true, attributes: true };
let observer = new MutationObserver((mutations) => {
mutations.forEach(function (mutation) {
console.log(mutation.type);
mutations.forEach((mutation) => {
console.log(observer);
const status = mutation.target.attributes.style.nodeValue;
if(status === 'display: none;') {
this.requestApi();
} else {
this.divPrateleira.innerHTML = ``;
}
});
});
observer.observe(target, config);
}
verificaPag () {
if(this.checkoutVazio.attributes.style.nodeValue === 'display: none;') {
if(window.location.hash == '#/cart') {
this.requestApi();
}
} else {
this.divPrateleira.innerHTML= ``;
}
window.addEventListener('hashchange',() => {
if(this.checkoutVazio.attributes.style.nodeValue === 'display: none;') {
if(window.location.hash == '#/cart') {
this.requestApi();
}
} else if (window.location.hash == '#/email' || window.location.hash == '#/profile' || window.location.hash == '#/shipping') {
this.divPrateleira.innerHTML= ``;
}else if (window.location.href == "https://m3academy.myvtex.com/checkout/#/payment") {
this.divPrateleira.innerHTML= ``;
}
})};
requestApi () {
this.divPrateleira.innerHTML =
`<h3 class="footerCheckout__prateleira-title" >Você também pode gostar:</h3>
@ -54,19 +83,19 @@ export default class Footer {
const linkProd = prod.link;
ulProdut.innerHTML += `
<li class="footerCheckout__prateleira-li-prod">
<figure class="footerCheckout__prateleira-figure-prod">
<img src="${imgProd}" alt="Imagem Produto">
</figure>
<div class="footerCheckout__prateleira-div-text">
<h2>${nameProd}</h2>
<ul>
${prod.items.map((name) => `<li>
${name.name}</li>`).join('')}
</ul>
<a href="${linkProd}">
Ver Produto
</a>
</div>
<figure class="footerCheckout__prateleira-figure-prod">
<img src="${imgProd}" alt="Imagem Produto">
</figure>
<div class="footerCheckout__prateleira-div-text">
<h2>${nameProd}</h2>
<ul>
${prod.items.map((name) => `<li>
${name.name}</li>`).join('')}
</ul>
<a href="${linkProd}">
Ver Produto
</a>
</div>
</li>`
})
});
@ -82,53 +111,60 @@ export default class Footer {
});
}
}
addProdutos() {
this.continuarComprando.innerHTML = `<a href="/" id="cart-choose-products" class="btn btn-large btn-success link-choose-products" data-i18n="cart.chooseProducts">continuar comprando</a>`
}
// removePrateleira() {
// this.divPrateleira.style.display = 'none'
// };
creatPaymentsIcons () {
this.payments.innerHTML = `
<ul class="footerCheckout__container-ul">
<li class="footerCheckout__wrapper-li">
<figure class="footerCheckout__figure-img-tickets">
<img src="https://agenciamagma.vteximg.com.br/arquivos/masterCardM3Academy.png" alt="MasterCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/visaM3Academy.png" alt="VisaCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/amexM3Academy.png" alt="AmericaExpress"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/eloM3Academy.png" alt="VisaCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/hiperCardM3Academy.png" alt="HiperCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/visaM3Academy.png" alt="VisaCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/payPalM3Academy.png" alt="PayPal"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/boletoM3Academy.png" alt="Boleto"/>
</figure>
</li>
</ul>`;
<ul class="footerCheckout__container-ul">
<li class="footerCheckout__wrapper-li">
<figure class="footerCheckout__figure-img-tickets">
<img src="https://agenciamagma.vteximg.com.br/arquivos/masterCardM3Academy.png" alt="MasterCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/visaM3Academy.png" alt="VisaCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/amexM3Academy.png" alt="AmericaExpress"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/eloM3Academy.png" alt="VisaCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/hiperCardM3Academy.png" alt="HiperCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/visaM3Academy.png" alt="VisaCard"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/payPalM3Academy.png" alt="PayPal"/>
<img src="https://agenciamagma.vteximg.com.br/arquivos/boletoM3Academy.png" alt="Boleto"/>
</figure>
</li>
</ul>`;
}
creatVtexIconPci () {
this.vtexIconPci.innerHTML = `
<ul class="footerCheckout__container-ul">
<li class="footerCheckout__wrapper-li">
<figure class="footerCheckout__figure-img-vtex">
<img src="https://agenciamagma.vteximg.com.br/arquivos/vtexPCIM3Academy.png" alt="Logo Vtex"/>
</figure>
</li>
</ul>`
<ul class="footerCheckout__container-ul">
<li class="footerCheckout__wrapper-li">
<figure class="footerCheckout__figure-img-vtex">
<img src="https://agenciamagma.vteximg.com.br/arquivos/vtexPCIM3Academy.png" alt="Logo Vtex"/>
</figure>
</li>
</ul>`
}
creatDevIconsM3 () {
this.devIcons.innerHTML = `
<li class="footerCheckout__container-li-m3Icon">
<a href="https://vtex.com/br-pt/">
<span>Powered By</span>
<figure class="footerCheckout__figure-img-vtexIcon">
<img class="vtex-icon" src="https://agenciamagma.vteximg.com.br/arquivos/logoVTEXM3Academy.png" alt="LogoVTEX">
</figure>
</a>
</li>
<li class="footerCheckout__container-li-m3Icon">
<a href="https://agenciam3.com/">
<li class="footerCheckout__container-li-m3Icon">
<a href="https://vtex.com/br-pt/">
<span>Powered By</span>
<figure class="footerCheckout__figure-img-vtexIcon">
<img class="vtex-icon" src="https://agenciamagma.vteximg.com.br/arquivos/logoVTEXM3Academy.png" alt="LogoVTEX">
</figure>
</a>
</li>
<li class="footerCheckout__container-li-m3Icon">
<a href="https://agenciam3.com/">
<span>Developed By</span>
<figure class="footerCheckout__figure-img-m3Icon">
<img class="m3-icon" src="https://agenciamagma.vteximg.com.br/arquivos/logoM3M3Academy.png" alt="LogoM3">
</figure>
</a>
</li>`
}
<figure class="footerCheckout__figure-img-m3Icon">
<img class="m3-icon" src="https://agenciamagma.vteximg.com.br/arquivos/logoM3M3Academy.png" alt="LogoM3">
</figure>
</a>
</li>
`
}
}

View File

@ -49,10 +49,6 @@ body {
.container-order-form,
.container-cart {
width: 80%;
#cart-title {
display: none !important;
}
}
}
@ -71,20 +67,24 @@ body {
#cart-title,
#orderform-title {
color: $color-gray2;
font-family: $font-family;
font-weight: 500;
font-size: 36px;
line-height: 42px;
margin: 40px 0 30px;
letter-spacing: 0.1em;
font-weight: 700;
font-size: 24px;
line-height: 33px;
margin: 16px 0;
letter-spacing: 0.05em;
text-transform: uppercase;
color: $color-black-500;
@include mq(md, max) {
margin-left: 30px;
}
.activeTitle {
display: none;
}
}
.dropdown {
&__content {
&--closed {

View File

@ -13,6 +13,13 @@
-ms-touch-action: pan-y;
touch-action: pan-y;
-webkit-tap-highlight-color: transparent;
// .slick-slide:first-child {
// margin-right: 8px;
// }
// .slick-slid:last-child {
// margin-left: 8px;
// }
}
.slick-list {
position: relative;
@ -46,7 +53,7 @@
display: flex;
margin-left: auto;
margin-right: auto;
column-gap: 16px;
gap: 16px;
&:before,
&:after {

View File

@ -211,7 +211,6 @@
align-items: center;
text-align: center;
margin: 0;
padding: 0;
background-color: $color-blue-200;
color: $color-white;
border-radius: 8px;
@ -222,8 +221,6 @@
font-style: normal;
line-height: 18px;
padding: 5px;
transition: ease-in-out 250ms;
border: 1px solid $color-blue-200;
}
&__prateleira-div-text a {
@ -231,7 +228,6 @@
justify-content: center;
display: flex;
width: 100%;
max-width: 242px;
background: $color-blue-200;
height: 42px;
align-items: center;
@ -244,14 +240,22 @@
font-style: normal;
text-transform: uppercase;
letter-spacing: 0.05em;
transition: ease-in-out 250ms;
border: 1px solid $color-blue-200;
transition: ease-in-out 280ms;
&:hover {
background-color: $color-white;
color: $color-blue-200;
background-color: $color-blue-100;
}
}
&__prateleira-div-text ul li {
text-transform: uppercase;
font-family: $font-family;
font-size: 13px;
font-weight: 700;
line-height: 18px;
font-style: normal;
}
}
@media only screen and (width: 1280px){

View File

@ -16,6 +16,7 @@ $color-gray3: #f0f0f0;
$color-gray4: #8d8d8d;
$color-gray5: #e5e5e5;
$color-blue-100: #6fd5f2;
$color-blue-200: #00C8FF;
$color-blue: #4267b2;