Adds reload listener to Carousel Items Block

This commit is contained in:
mateuswetah 2021-07-14 10:06:15 -03:00
parent c03dfb6515
commit 9d25d30f94
2 changed files with 19 additions and 8 deletions

View File

@ -6,18 +6,19 @@ import VueBlurHash from 'vue-blurhash';
// Vue Dev Tools! // Vue Dev Tools!
Vue.config.devtools = process && process.env && process.env.NODE_ENV === 'development'; Vue.config.devtools = process && process.env && process.env.NODE_ENV === 'development';
// This is rendered on the theme side. function renderTainacanItemCarouselBlocks() {
document.addEventListener("DOMContentLoaded", () => {
// Gets all divs with content created by our block; // Gets all divs with content created by our block;
let blocks = document.getElementsByClassName('wp-block-tainacan-carousel-items-list'); let blocksElements = document.getElementsByClassName('wp-block-tainacan-carousel-items-list');
if (blocksElements) {
let blocks = Object.values(blocksElements);
if (blocks) { // Checks if this carousel isn't already mounted
let blockIds = Object.values(blocks).map((block) => block.id); blocks = blocks.filter((block) => block.classList && !block.classList.contains('has-mounted'));
const blockIds = blocks.map((block) => block.id);
// Creates a new Vue Instance to manage each block isolatelly // Creates a new Vue Instance to manage each block isolatelly
for (let blockId of blockIds) { for (let blockId of blockIds) {
// Configure Vue logic before passing it to constructor: // Configure Vue logic before passing it to constructor:
let vueOptions = { let vueOptions = {
data: { data: {
@ -103,4 +104,14 @@ document.addEventListener("DOMContentLoaded", () => {
new Vue( Object.assign({ el: '#' + blockId }, vueOptions) ); new Vue( Object.assign({ el: '#' + blockId }, vueOptions) );
} }
} }
}
// This is rendered on the theme side.
document.addEventListener("DOMContentLoaded", () => {
renderTainacanItemCarouselBlocks();
});
// Also if a theme or plugin requested a reset...
document.addEventListener("TainacanReloadCarouselItemsListBlock", () => {
renderTainacanItemCarouselBlocks();
}); });

View File

@ -1,5 +1,5 @@
<template> <template>
<div :class="className"> <div :class="className + ' has-mounted'">
<div v-if="showCollectionHeader"> <div v-if="showCollectionHeader">
<div <div
v-if="isLoadingCollection" v-if="isLoadingCollection"