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() { async init() {
await this.selectors(); await this.selectors();
this.requestApi(); this.verificaPag();
this.addCarrossel(); await this.onUpdate();
this.creatPaymentsIcons(); this.creatPaymentsIcons();
this.creatVtexIconPci(); this.creatVtexIconPci();
this.creatDevIconsM3(); this.creatDevIconsM3();
this.onUpdate(); this.addProdutos();
await this.addCarrossel();
} }
async selectors() { async selectors() {
this.checkoutVazio = await waitElement(".empty-cart-content"); this.checkoutVazio = await waitElement(".empty-cart-content");
this.divPrateleira = await waitElement('.footerCheckout__prateleira'); this.divPrateleira = await waitElement('.footerCheckout__prateleira');
this.tituloPrateleira = await waitElement('#cart-title')
this.payments = await waitElement('.footerCheckout__payments'); this.payments = await waitElement('.footerCheckout__payments');
this.vtexIconPci = await waitElement('.footerCheckout__vtexpci'); this.vtexIconPci = await waitElement('.footerCheckout__vtexpci');
this.devIcons = await waitElement('.footerCheckout__developedBy'); this.devIcons = await waitElement('.footerCheckout__developedBy');
this.continuarComprando = await waitElement('.empty-cart-links');
} }
onUpdate() { async onUpdate() {
let target = this.checkoutVazio; let target = this.checkoutVazio;
let config = { childList: true, attributes: true }; let config = { childList: true, attributes: true };
let observer = new MutationObserver((mutations) => { let observer = new MutationObserver((mutations) => {
mutations.forEach(function (mutation) { mutations.forEach((mutation) => {
console.log(mutation.type); console.log(observer);
const status = mutation.target.attributes.style.nodeValue;
if(status === 'display: none;') {
this.requestApi();
} else {
this.divPrateleira.innerHTML = ``;
}
}); });
}); });
observer.observe(target, config); 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 () { requestApi () {
this.divPrateleira.innerHTML = this.divPrateleira.innerHTML =
`<h3 class="footerCheckout__prateleira-title" >Você também pode gostar:</h3> `<h3 class="footerCheckout__prateleira-title" >Você também pode gostar:</h3>
@ -82,7 +111,13 @@ 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 () { creatPaymentsIcons () {
this.payments.innerHTML = ` this.payments.innerHTML = `
<ul class="footerCheckout__container-ul"> <ul class="footerCheckout__container-ul">
@ -129,6 +164,7 @@ export default class Footer {
<img class="m3-icon" src="https://agenciamagma.vteximg.com.br/arquivos/logoM3M3Academy.png" alt="LogoM3"> <img class="m3-icon" src="https://agenciamagma.vteximg.com.br/arquivos/logoM3M3Academy.png" alt="LogoM3">
</figure> </figure>
</a> </a>
</li>` </li>
`
} }
} }

View File

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

View File

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

View File

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

View File

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