作者:冷漠自逍遥2602897565 | 来源:互联网 | 2021-09-23 23:40
这篇文章主要为大家分享一款所见即所得的富文本编辑器bootstrap-wysiwyg,并详细告诉大家文本编辑器bootstrap-wysiwyg的使用方法,感兴趣的小伙伴们可以参考一下
本文教大家如何使用bootstrap-wysiwyg文本编辑器,充分发挥编辑器的优势,希望大家可以有所收获。
主要特性:
超小5kb
自动的热键支持(MAC和windows)
拖放的插入图片,支持图片上传(支持手机拍照)
支持声音输入(chrome支持)
允许自定义的工具条,可以使用所有的bootstrap内容,字体
不使用任何强制的样式
…………………………
其实不止这些,需要大家自己去探索,加油吧!
使用其实很简单的,倒入bootstrap相关CSS,JS,jQuery,还有bootstrap-wysiwyg的JS,如下:
定义相关菜单项目属性和方法:
function initToolbarBootstrapBindings() {
var fOnts= ['Serif', 'Sans', 'Arial', 'Arial Black', 'Courier',
'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande', 'Lucida Sans', 'Tahoma', 'Times',
'Times New Roman', 'Verdana'],
fOntTarget= $('[title=Font]').siblings('.dropdown-menu');
$.each(fonts, function (idx, fontName) {
fontTarget.append($('
'+fontName + ''));
});
$('a[title]').tooltip({container:'body'});
$('.dropdown-menu input').click(function() {return false;})
.change(function () {$(this).parent('.dropdown-menu').siblings('.dropdown-toggle').dropdown('toggle');})
.keydown('esc', function () {this.value='';$(this).change();});
$('[data-role=magic-overlay]').each(function () {
var overlay = $(this), target = $(overlay.data('target'));
overlay.css('opacity', 0).css('position', 'absolute').offset(target.offset()).width(target.outerWidth()).height(target.outerHeight());
});
if ("onwebkitspeechchange" in document.createElement("input")) {
var editorOffset = $('#editor').offset();
$('#voiceBtn').css('position','absolute').offset({top: editorOffset.top, left: editorOffset.left+$('#editor').innerWidth()-35});
} else {
$('#voiceBtn').hide();
}
};
function showErrorAlert (reason, detail) {
var msg='';
if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
else {
console.log("error uploading file", reason, detail);
}
$('
'+
'File upload error '+msg+'
').prependTo('#alerts');
};
initToolbarBootstrapBindings();
$('#editor').wysiwyg({ fileUploadError: showErrorAlert} );
最后是HTML代码:
如果大家还想深入学习,可以点击这里进行学习,再为大家附一个精彩的专题:Bootstrap学习教程
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。