Sha256: 8b21b395c82434509b24d4772bb88f1cfc93c9dc7a9ed0df4d509dc635640a29
Contents?: true
Size: 1.16 KB
Versions: 15
Compression:
Stored size: 1.16 KB
Contents
import { Controller } from "@hotwired/stimulus" import Sortable from "libraries/sortablejs" export default class extends Controller { static get targets() { return [ "collection", "fields" ] } connect() { setTimeout(function() { this.sortable = Sortable.create(this.collectionTarget, { animation: 150 }) }.bind(this), 250) } removeImage(event) { let id = event.currentTarget.dataset.id let image = document.getElementById(id) image.parentElement.removeChild(image) } handleDone(event) { let html = this.element.dataset.fields let range = document.createRange() range.selectNodeContents(document.body) let fragment = range.createContextualFragment(html) fragment.querySelector(`[data-media-picker-target="signedBlobId"]`).value = event.detail.signedBlobId fragment.querySelector(`[data-media-picker-target="filename"]`).value = event.detail.filename fragment.querySelector(`[data-media-picker-target="imageId"]`).value = event.detail.imageId fragment.querySelector('img').src = event.detail.thumbnail // Insert fields this.collectionTarget.appendChild(fragment) } }
Version data entries
15 entries across 15 versions & 1 rubygems