有没有办法完全禁用Summernote中的图像上传功能,但保留图像URL输入框? 最接近的方法是使用disableDragAndDrop: true
选项,但这不会从图像弹出窗口中删除上传按钮。
有没有办法完全禁用Summernote中的图像上传功能,但保留图像URL输入框? 最接近的方法是使用disableDragAndDrop: true
选项,但这不会从图像弹出窗口中删除上传按钮。
可能有更好的方法来实现您想要的效果......但我想到的一个非常简单的解决方案是将以下内容添加到您的样式表中:
.note-group-select-from-files {
display: none;
}
只留下图片URL输入框的方案是完美的,并且可以实现您想要的效果,除非有人检查元素并发现上传元素仍然存在但被隐藏了:
编辑: 我查看了Summernote源代码,发现上述解决方法实际上是一个不错的选择。目前还没有API可以仅禁用文件上传按钮,更别说在保留图像URL输入时执行此操作了。当然,您可以添加它并打开一个拉取请求。
var body = '<div class="form-group note-group-select-from-files">' +
'<label>' + lang.image.selectFromFiles + '</label>' +
'<input class="note-image-input form-control" type="file" name="files" accept="image/*" multiple="multiple" />' +
imageLimitation +
'</div>' +
'<div class="form-group" style="overflow:auto;">' +
'<label>' + lang.image.url + '</label>' +
'<input class="note-image-url form-control col-md-12" type="text" />' +
'</div>';
您可以覆盖工具栏并在那里定义自己的按钮集。这是一个示例代码片段:
$("#summernote").summernote({
height: 300,
toolbar: [
[ 'style', [ 'style' ] ],
[ 'font', [ 'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear'] ],
[ 'fontname', [ 'fontname' ] ],
[ 'fontsize', [ 'fontsize' ] ],
[ 'color', [ 'color' ] ],
[ 'para', [ 'ol', 'ul', 'paragraph', 'height' ] ],
[ 'table', [ 'table' ] ],
[ 'insert', [ 'link'] ],
[ 'view', [ 'undo', 'redo', 'fullscreen', 'codeview', 'help' ] ]
]
});
这段代码生成没有视频和图片插入选项的工具栏,并提供所有其他选项。你可以在这里查看详细的API文档。
使用Jquery 这对我很有效
$('div.note-group-select-from-files').remove();
或者,如果您想在尝试删除元素之前检查该元素是否存在(如dwilda所建议的):
var imageUploadDiv = $('div.note-group-select-from-files');
if (imageUploadDiv.length) {
imageUploadDiv.remove();
}
remove()
。不会抛出任何异常。 - The CoprolaltplDialog = function (lang, options) {
var tplImageDialog = function () {
return '<div class="note-image-dialog modal" aria-hidden="false">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" aria-hidden="true" tabindex="-1">×</button>' +
'<h4>' + lang.image.insert + '</h4>' +
'</div>' +
'<div class="modal-body">' +
'<div class="row-fluid">' +
'<h5>' + lang.image.selectFromFiles + '</h5>' +
'<input class="note-image-input" type="file" name="files" accept="image/*" />' +
'<h5>' + lang.image.url + '</h5>' +
'<input class="note-image-url form-control span12" type="text" />' +
'</div>' +
'</div>' +
'<div class="modal-footer">' +
'<button href="#" class="btn btn-primary note-image-btn disabled" disabled="disabled">' + lang.image.insert + '</button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
};
删除此代码:
'<h5>' + lang.image.selectFromFiles + '</h5>' +
'<input class="note-image-input" type="file" name="files" accept="image/*" />' +
对于summernote .8*版本:
使用以下代码来移除按钮:
.note-insert {
display: none
}
用户仍然可以拖放图片。
在阅读了一些代码后,我发现删除summernote.js中的这段代码将删除上传功能。
只需从您的文件中删除此代码,因为上述任何答案对我都无效。
'<div class="form-group note-form-group note-group-select-from-files">' +
'<label class="note-form-label">' + lang.image.selectFromFiles + '</label>' +
'<input class="note-image-input form-control note-form-control note-input" '+
' type="file" name="files" accept="image/*" multiple="multiple" />' +
imageLimitation +
'</div>' +
$('.note-group-select-from-files').first().remove();
//Disable image button
.note-insert.btn-group>.btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
display:none;
}
//Disable Video button
.note-insert.btn-group>.btn:last-child:not(:first-child), .btn-group>.dropdown-toggle:not(:first-child) {
display:none;
}
我曾经遇到过同样的问题,看起来很复杂,但你可以简单地重新声明工具栏:
`$('#summernote').summernote({
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']]
]
});`