tinymce.init({
selector: '#質問内容',
language: 'ja' ,
language_url: 'tinymce_6.8.2/tinymce/js/tinymce/langs/ja.js',
autoresize_min_height: 200,
autoresize_max_height: 10000,
promotion: false,
statusbar: false,
plugins: 'autoresize anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount ',
toolbar: 'undo redo | blocks fontfamily fontsize | bold italic underline strikethrough | link image media table mergetags | align lineheight | tinycomments | checklist numlist bullist indent outdent | emoticons charmap | removeformat',
tinycomments_mode: 'embedded',
mergetags_list: [
{ value: 'First.Name', title: 'First Name' },
{ value: 'Email', title: 'Email' },
],
init_instance_callback: editor => {
editor.on('drop', event => {
const file = event.dataTransfer.files[0];
editor.on('Change', () => {
if (file != undefined && file != null && file.name != '') {
const doc = editor.getDoc();
const imgs = Array.from(doc.images);
// const len = imgs.length;
imgs.forEach(img => {
if (img.src.match(/^blob/) || img.currentSrc.match(/^blob/)) {
fetch(img.src)
.then(response => {
return response.blob();
})
.then(blob => {
const fData = new FormData();
fData.append('image', blob, file.name);
fData.append('action_cmd', 'upload');
fetch(
"質問Detail.do",
{
method: 'POST',
body: fData
}
)
.then(response => {
return response.json();
})
.then(json => {
img.src = json.result; // この「img」オブジェクトが挿入される
タグなので、「class」なり「data-caption」なり好きに追加できる
});
});
}
});
}
});
});
}
});