Skip to content

Instantly share code, notes, and snippets.

@vitobotta
Created April 26, 2020 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitobotta/6f36e959955c2f27caa918b72cca60b2 to your computer and use it in GitHub Desktop.
Save vitobotta/6f36e959955c2f27caa918b72cca60b2 to your computer and use it in GitHub Desktop.
import { Controller } from "stimulus"
import ImageUpload from "../classes/image_upload"
export default class extends Controller {
static targets = [ "draftTextarea" ]
connect() {
console.log(12331)
// if (this.draftTextareaTarget.dataset.initialised != "true") {
this.initEditor()
// }
}
initEditor() {
const that = this
console.log(this.draftTextareaTarget)
const editor = ArticleEditor(this.draftTextareaTarget, {
source: false,
plugins: ['reorder', 'style', 'inlineformat', 'specialchars', 'selector', 'counter', 'blockcode'],
editor: {
focus: true,
scrollTarget: "#mainContainer"
},
code: {
template: "<pre><code></code></pre>"
},
layer: false,
image: {
url: false,
upload(upload, data) {
const toUpload = []
// find files to upload
for (let key in data.files) {
if (typeof data.files[key] === 'object') {
const file = data.files[key]
file.id = Math.random().toString(36).substr(2, 9)
toUpload.push(file)
}
}
if (toUpload.length === 0) { return }
new ImageUpload(toUpload, upload, data, that.draftTextareaTarget.dataset.uploadUrl).startUpload()
}
}
})
this.draftTextareaTarget.dataset.initialised = "true"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment