所见即所得的富文本编辑器bootstrap

网友投稿 373 2023-07-16


所见即所得的富文本编辑器bootstrap

本文教大家如何使用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($('

});

$('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+'

};

initToolbarBootstrapBindings();

$('#editor').wysiwyghttp://({ fileUploadError: showErrorAlert} );

最后是HTML代码:

 

输入内容…

如果大家还想深入学习,可以点击这里进行学习,再为大家附一个精彩的专题:Bootstrap学习教程


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Bootstrap布局方式详解
下一篇:Java中Finally关键字
相关文章

 发表评论

暂时没有评论,来抢沙发吧~