|
var tinymceOptions={ |
|
selector: 'textarea', |
|
height: 300, |
|
menubar: true, |
|
plugins: [ |
|
'advlist autolink lists link image charmap print preview hr anchor pagebreak', |
|
'searchreplace wordcount visualblocks visualchars code fullscreen', |
|
'insertdatetime media nonbreaking save table directionality', |
|
'emoticons template paste textpattern imagetools codesample toc' |
|
], |
|
toolbar1: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image', |
|
toolbar2: 'print preview media | forecolor backcolor emoticons | codesample', |
|
valid_elements:"*[*]", |
|
images_upload_url: 'postAcceptor.php', |
|
images_upload_base_path: '/some/basepath', |
|
images_upload_credentials: true, |
|
images_upload_handler: function (blobInfo, success, failure) { |
|
var xhr, formData; |
|
xhr = new XMLHttpRequest(); |
|
xhr.withCredentials = false; |
|
xhr.open('POST', 'postAcceptor.php'); |
|
xhr.onload = function() { |
|
var json; |
|
|
|
if (xhr.status != 200) { |
|
failure('HTTP Error: ' + xhr.status); |
|
return; |
|
} |
|
json = JSON.parse(xhr.responseText); |
|
|
|
if (!json || typeof json.location != 'string') { |
|
failure('Invalid JSON: ' + xhr.responseText); |
|
return; |
|
} |
|
success(json.location); |
|
}; |
|
formData = new FormData(); |
|
formData.append('file', blobInfo.blob(), fileName(blobInfo)); |
|
xhr.send(formData); |
|
}, |
|
image_title: true, |
|
// enable automatic uploads of images represented by blob or data URIs |
|
automatic_uploads: true, |
|
// URL of our upload handler (for more details check: https://www.tinymce.com/docs/configure/file-image-upload/#images_upload_url) |
|
images_upload_url: 'postAcceptor.php', |
|
// here we add custom filepicker only to Image dialog |
|
file_picker_types: 'image', |
|
// and here's our custom image picker |
|
file_picker_callback: function(cb, value, meta) { |
|
var input = document.createElement('input'); |
|
input.setAttribute('type', 'file'); |
|
input.setAttribute('accept', 'image/*'); |
|
|
|
// Note: In modern browsers input[type="file"] is functional without |
|
// even adding it to the DOM, but that might not be the case in some older |
|
// or quirky browsers like IE, so you might want to add it to the DOM |
|
// just in case, and visually hide it. And do not forget do remove it |
|
// once you do not need it anymore. |
|
/* |
|
input.onchange = function() { |
|
var file = this.files[0]; |
|
|
|
// Note: Now we need to register the blob in TinyMCEs image blob |
|
// registry. In the next release this part hopefully won't be |
|
// necessary, as we are looking to handle it internally. |
|
var id = 'blobid' + (new Date()).getTime(); |
|
var blobCache = tinymce.activeEditor.editorUpload.blobCache; |
|
var blobInfo = blobCache.create(id, file); |
|
blobCache.add(blobInfo); |
|
|
|
// call the callback and populate the Title field with the file name |
|
cb(blobInfo.blobUri(), { title: file.name }); |
|
}; |
|
*/ |
|
|
|
input.click(); |
|
} |
|
}; |
|
|
|
Vue.component("vue-tinymce",{ |
|
template:'<textarea :id="id" :value="value"></textarea>', |
|
props:["value","options","id"], |
|
mounted:function(){ |
|
var vm=this, |
|
options=$.extend(true, {}, tinymceOptions); // use jquery temporary |
|
|
|
// make an deep copy of options;should not modify tinymceOptions |
|
//options.selector=undefined; |
|
//options.target=vm.$el; // use options.target instand of options.selector |
|
options.selector = "#"+this.id; |
|
|
|
var oldSetup=options.setup||function(){}; |
|
|
|
options.setup=function(editor){ |
|
console.log("setup"); |
|
|
|
//Decorate origni one |
|
oldSetup(editor); |
|
|
|
// Bind keyup |
|
editor.on("change",function(e){ |
|
var value=editor.getContent(); |
|
vm.$emit("input",value); |
|
}); |
|
editor.on("keyup",function(e){ |
|
var value=editor.getContent(); |
|
vm.$emit("input",value); |
|
}); |
|
}; |
|
/* |
|
Without dummy div I can't made up with re-entering the editor with sameid |
|
*/ |
|
var $dummydiv = $( "<div id='"+this.id+"'></div>" ); |
|
$("BODY").append($dummydiv); |
|
tinymce.init(options).then(function(editors){ |
|
vm.editor=editors[0]; |
|
}); |
|
}, |
|
beforeUpdate () { |
|
if(this.value!==this.editor.getContent()) |
|
this.editor.setContent(this.value); |
|
}, |
|
destroyed () { |
|
tinymce.remove("#"+this.id); |
|
$("div #"+this.id).remove(); //remove dummy div |
|
console.log("Removed #"+this.id); |
|
} |
|
}); |
|
|
|
var vm=new Vue({ |
|
el:"#example", |
|
data:{ |
|
cols: ['Data for col 1', 'Data for col 2', 'Data for Col 3', 'Lorem Ipsum Lorem Ipsum'], |
|
content:"test content", |
|
content1:"text1 content1", |
|
tinymceOptions:tinymceOptions |
|
}, |
|
methods:{ |
|
change: function(){ |
|
this.content="Hello World"; |
|
}, |
|
remove: function(){ |
|
this.cols.shift(); |
|
}, |
|
add: function(){ |
|
this.cols.push("Lorem Ipsum Lorem Ipsum Lorem Ipsum"); |
|
}, |
|
}, |
|
}) |