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BAAiB,SAAS,KAAQzC,MAAMiB,aAAY,IAGjE,GAGFhC,OAAOwD,iBAAiB,QAAQ,KAAQvD,eAAeiD,MAAK","sources":["webpack://build/../barrocaneon/assets/javascripts/infinity_scroll.js"],"sourcesContent":["window.infiniteScroll = {\n\n // variável criada no arquivo _infinity_scroll.liquid\n pagination: window._pagination,\n\n // wrapper que contém/recebe os produtos\n productsWrapper: document.querySelector('[data-products-wrapper]'),\n productsList: document.querySelector('[data-products-wrapper] .list-products'),\n\n // elemento que ativa a busca por mais produtos\n loadEl: document.querySelector('[data-load-more]'),\n\n stopLoading: function() {\n const loadEl = this.loadEl;\n if (loadEl != null) loadEl.parentElement.removeChild(loadEl);\n },\n\n setCurrentPage: function (_number) {\n const _this = this;\n const totalPages = _this.pagination.total_pages;\n\n // Verifica se a página atual não é maior que o total de páginas\n if (_number <= totalPages) {\n\n // Atualiza a página atual\n _this.pagination.current_page = _number;\n\n // Desabilita prosseguimento caso tenha chegado na última página, removendo o elemento que dá trigger\n if (_this.pagination.current_page >= totalPages) _this.stopLoading();\n\n // Atualiza a URL da próxima página\n if (_number < totalPages)\n return _this.pagination.next_url = _this.pagination.pages[_number].url\n }\n },\n\n loadProducts: async function() {\n const nextUrl = this.pagination.next_url;\n\n // Busca próxima leva de produtos\n const response = await fetch(nextUrl);\n const data = await response.text();\n\n // Parse e retorno da resposta\n const parser = new DOMParser();\n const doc = parser.parseFromString(data, \"text/html\");\n return doc.querySelectorAll('.product-block');\n },\n\n getNextPage: async function() {\n const _this = this;\n const currentPage = _this.pagination.current_page;\n const wrapper = _this.productsWrapper;\n const wrapperProductsList = _this.productsList;\n\n if (!wrapper.classList.contains('searching')) {\n\n // Busca e adiciona novos produtos\n _this.productsWrapper.classList.add('searching');\n const newProducts = await _this.loadProducts();\n newProducts.forEach(product => { wrapperProductsList.appendChild(product) });\n\n // Atualiza página atual carregada e próxima etapa se tiver\n _this.setCurrentPage(currentPage + 1);\n\n // Atualiza o lazy load\n lazyLoadInstance.update();\n\n // Busca preços por ajax\n window.store.getPriceProd();\n\n // libera o processo de busca de novas páginas\n wrapper.classList.remove('searching');\n\n Vnda.Component.Price.update()\n }\n },\n\n init: function() {\n const _this = this;\n const loadEl = _this.loadEl;\n\n // Verifica se há paginação definida antes de iniciar\n if (typeof _this.pagination != undefined) {\n\n window.scrollTo({\n top: 0,\n left: 0,\n behavior: 'smooth'\n })\n\n if (loadEl != null) {\n // Inicia com clique no botão\n loadEl.addEventListener('click', () => { _this.getNextPage() })\n }\n }\n }\n}\n\nwindow.addEventListener('load', () => { infiniteScroll.init() })\n"],"names":["window","infiniteScroll","pagination","_pagination","productsWrapper","document","querySelector","productsList","loadEl","stopLoading","this","parentElement","removeChild","setCurrentPage","_number","_this","totalPages","total_pages","current_page","next_url","pages","url","loadProducts","async","nextUrl","response","fetch","data","text","DOMParser","parseFromString","querySelectorAll","getNextPage","currentPage","wrapper","wrapperProductsList","classList","contains","add","forEach","product","appendChild","lazyLoadInstance","update","store","getPriceProd","remove","Vnda","Component","Price","init","undefined","scrollTo","top","left","behavior","addEventListener"],"sourceRoot":""}