window.eventList = () => { return { showSoldout: true, showOnlyDigital: false, showExternal: true, selectedCategory: '0', visibleItems: 0, showHideSoldout() { this.showEvent = !this.showEvent }, init() { this.watchVisibleItems(); this.$watch('showSoldout', () => this.watchVisibleItems()); this.$watch('showOnlyDigital', () => this.watchVisibleItems()); this.$watch('selectedCategory', () => this.watchVisibleItems()); }, visibleByFilter(isDigital, categoryArr) { if (!this.showOnlyDigital && this.selectedCategory == '0') { return true; } if (this.showOnlyDigital && !isDigital) { return false; } if (this.selectedCategory == '0') { return true; } return categoryArr.includes(parseInt(this.selectedCategory)); }, // watch and count the visible .event-list-item-wrap items watchVisibleItems() { this.visibleItems = 0; setTimeout(() => { const items = document.querySelectorAll('.event-list-item-wrap'); let visibleItems = 0; items.forEach(item => { if (item.style.display !== 'none') { visibleItems++; } }); this.visibleItems = visibleItems; console.log('this.visibleItems: ', this.visibleItems) }, 1); } } }