wil*_*Liu 10 javascript summernote
我曾尝试过很多WYSIWYG编辑器,如TinyMCE,Ckeditor和Summernote.
我喜欢Summernote的简单性和编辑/保存功能,但是summernote似乎没有像TinyMCE或CKEditor这样的图像管理器插件.
我的webapp有一个可以由个人用户上传的照片池(媒体库).我希望有一个功能允许用户从池中选择照片,并在Summernote中编辑文章时将其添加到textarea中(就像Wordpress一样).
如果真的没有支持插件,任何人都可以给我一些提示如何手动完成此功能吗?
sem*_*lon 10
正如我在summernote github问题上发表的那样.https://github.com/summernote/summernote/issues/1203
这就是我将elFinder文件管理器与Summernote集成的方法.
(function (factory) {
/* global define */
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals: jQuery
factory(window.jQuery);
}
}(function ($){
// template, editor
var tmpl = $.summernote.renderer.getTemplate();
// add plugin
$.summernote.addPlugin({
name: 'genixcms', // name of plugin
buttons: { // buttons
readmore: function () {
return tmpl.iconButton('fa fa-long-arrow-right', {
event: 'readmore',
title: 'Read more',
hide: false
});
},
elfinder: function () {
return tmpl.iconButton('fa fa-list-alt', {
event: 'elfinder',
title: 'File Manager',
hide: false
});
},
},
events: { // events
readmore: function (event, editor, layoutInfo) {
layoutInfo.holder().summernote("insertText", "[[--readmore--]]");
},
elfinder: function (event, editor, layoutInfo) {
elfinderDialog();
},
}
});
}));
Run Code Online (Sandbox Code Playgroud)
我为我的cms制作了两个按钮.看到elfinder文件管理器的按钮.elfinder事件运行elfinderDialog() 函数,之后我们必须创建函数.
之后,在summernote配置中添加按钮.
$('.editor').summernote({
height: 300,
toolbar: [
['style', ['style']],
['style', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']],
['fontname', ['fontname']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['table', ['table']],
['insert', ['link', 'picture', 'video', 'hr', 'readmore']],
['genixcms', ['elfinder']],
['view', ['fullscreen', 'codeview']],
['help', ['help']]
],
onImageUpload: function(files, editor, welEditable) {
sendFile(files[0],editor,welEditable);
}
});
Run Code Online (Sandbox Code Playgroud)
看到这个标签['genixcms', ['elfinder']],它将与其他按钮分开显示按钮,因为它有自己的分区.在summernote图像按钮上有默认图像上传.它可以上传到服务器.我有它工作,运行良好.问题是有时我们需要进行修改,我们需要文件管理器.
毕竟夏季要求已准备好加载按钮.我们需要创建在单击按钮时执行的功能.请参阅下面的代码.
function elfinderDialog(){
var fm = $('<div/>').dialogelfinder({
url : 'http://localhost/genixcms/inc/lib/Vendor/studio-42/elfinder/php/connector.minimal.php',
lang : 'en',
width : 840,
height: 450,
destroyOnClose : true,
getFileCallback : function(files, fm) {
console.log(files);
$('.editor').summernote('editor.insertImage',files.url);
},
commandsOptions : {
getfile : {
oncomplete : 'close',
folders : false
}
}
}).dialogelfinder('instance');
}
Run Code Online (Sandbox Code Playgroud)
要插入图像很简单,只需双击图像,图像就会插入编辑器.
我希望这个小片段可以帮助任何需要文件管理器并希望使用elFinder作为文件管理器的人.
谢谢
| 归档时间: |
|
| 查看次数: |
13383 次 |
| 最近记录: |