Pra*_*hal 1 tinymce tinymce-4 angular angular5
我在 Angular 5 项目中使用 TinyMCE 编辑器,并且想要处理图像上传,但我目前无法做到这一点。这是我当前的代码:
<editor
name="questionStatement"
apiKey="somekey"
[init]='{
plugins : [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern"
],
toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
past_date_images: true,
external_plugins: { tiny_mce_wiris: "https://www.wiris.net/demo/plugins/tiny_mce/plugin.js" },
toolbar: "tiny_mce_wiris_formulaEditor, tiny_mce_wiris_formulaEditorChemistry"
}'
</editor>
Run Code Online (Sandbox Code Playgroud)
我正在遵循此代码示例https://codepen.io/nirajmchauhan/pen/EjQLpV 来处理图像上传。我不明白,如何将file_picker_callback函数传递给角度编辑器?
还有其他方法吗,我应该如何处理图片上传?
我尝试阅读文档,但找不到任何内容。我已经被这个问题困扰很长时间了,如果有人能够帮助我解决这个问题,那就太好了。
这对我有用(我正在使用@tinymce/tinymce-angular):
<editor [(ngModel)]="source" [init]="tinymceInit"></editor>
Run Code Online (Sandbox Code Playgroud)
在构造函数或初始化中:
...
this.tinymceInit = {
plugins : [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern"
],
toolbar : 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat',
image_advtab : true,
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 = input.files[0];
var reader = new FileReader();
reader.onload = function () {
// 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 base64 = reader.result.split(',')[1];
var blobInfo = blobCache.create(id, file, base64);
blobCache.add(blobInfo);
// call the callback and populate the Title field with the file name
cb(blobInfo.blobUri(), { title: file.name });
};
reader.readAsDataURL(file);
};
input.click();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:要添加,您也可以使用该功能来上传文件,如您所知。我更愿意拥有我正在从事的特定项目的 base64 数据。
| 归档时间: |
|
| 查看次数: |
5735 次 |
| 最近记录: |