Sha256: 8704d81c0f2cf347e5c13e1736c3ed7534868677c9d5898a7bbf495256786830
Contents?: true
Size: 1.47 KB
Versions: 11
Compression:
Stored size: 1.47 KB
Contents
(() => { const application = Stimulus.Application.start() application.register("gallery-select", class extends Stimulus.Controller { static get targets() { return ["singleImage", "multipleImages", "multiple", "counter"] } select(event) { let item = event.currentTarget let imageId = item.dataset.imageId if (this.multipleTarget.checked) { item.classList.toggle('selected') if (item.classList.contains('selected')) { this.addToMultipleImages(imageId) } else { this.removeFromMultipleImages(imageId) } this.counterTarget.innerText = `(${this.imageCount})` } else { item.parentElement.querySelectorAll('.item').forEach(function(item) { item.classList.remove('selected') }) item.classList.add('selected') this.singleImageTarget.value = imageId } } addToMultipleImages(imageId) { let imageIds = this.multipleImages imageIds.push(imageId) this.multipleImagesTarget.value = [...new Set(imageIds)].join("-") } removeFromMultipleImages(imageId) { let imageIds = this.multipleImages let newImageIds = imageIds.filter(function(id) { return id != imageId }) this.multipleImagesTarget.value = newImageIds.join("-") } get multipleImages() { return this.multipleImagesTarget.value.split("-") } get imageCount() { return this.multipleImages.length } }) })()
Version data entries
11 entries across 11 versions & 1 rubygems