-
-
Save vitobotta/6f36e959955c2f27caa918b72cca60b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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