基于jquery的bootstrap在线文本编辑器插件Summernote (转)

Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器。Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox、Opera、Internet Explorer 9 +(IE8支持即将到来)。
特点:
世界上最好的WYSIWYG在线编辑器
极易安装
开源
自定义初化选项
支持快捷键
适用于各种后端程序言语
使用方法
使用HTML5文档
|
1
2
3
4
|
<!DOCTYPE html><html>...</html> |
引入核心文件,Summernote需要几个JS库的支持,所以得先引入其它库
|
1
2
3
4
5
6
7
8
9
|
<!-- include libries(jQuery, bootstrap, fontawesome) --><script src="//code.jquery.com/jquery-1.9.1.min.js"></script><link href="//netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css"><script src="//netdna.bootstrapcdn.com/bootstrap/3.0.1/js/bootstrap.min.js"></script><link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"><!-- include summernote css/js--><link href="summernote.css" /><script src="summernote.min.js"></script> |
写入html,只需加入一个DIV元素,写上ID
|
1
|
<div id="summernote">Hello Summernote</div> |
写入JS初始化插件
|
1
2
3
|
$(document).ready(function() { $('#summernote').summernote(); }); |
API
初始化Summernote
|
1
|
$('.summernote').summernote(); |
使用参数初始化
设定高度与焦点
|
1
2
3
4
5
6
7
|
$('.summernote').summernote({ height: 300, // set editor height minHeight: null, // set minimum height of editor maxHeight: null, // set maximum height of editor focus: true, // set focus to editable area after initializing summernote}); |
设定高度后,如果内容高度超过设定高度将出现滚动条,如果没有设定高度则一直往下挣开。设定focus为true时,打开页面后焦点定位到编辑器中。
自定义工具栏
|
1
2
3
4
5
6
7
8
9
10
11
12
|
$('.summernote').summernote({ toolbar: [ //[groupname, [button list]] ['style', ['bold', 'italic', 'underline', 'clear']], ['font', ['strikethrough']], ['fontsize', ['fontsize']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['height', ['height']], ]}); |
预设参数
类型
| 方法 | |
|---|---|
| picture | Insert a picture |
| link | Insert a hyperlink |
| video | Insert a video |
| table | Insert a table |
| hr | Insert a horizontal rule |
| style | Format selected block |
| fontname | Set font family |
| fontsize | Set font size |
| color | Set foreground and background color |
| bold | Toggle weight |
| italic | Toggle italic |
| underline | Toggle underline |
| strikethrough | Toggle strikethrough |
| clear | Clearing all styles |
| ul | Make an un-ordered list |
| ol | Make an ordered list |
| paragraph | Set text alignment |
| height | Set height of text |
| fullscreen | Toggle fullscreen editing mode |
| codeview | Toggle wysiwyg and html editing mode |
| undo | Undo |
| redo | Redo |
| help | Show help dialog |
极简模式Air-mode
|
1
2
3
4
5
6
7
8
9
|
$('.summernote').summernote({ airPopover: [ ['color', ['color']], ['font', ['bold', 'underline', 'clear']], ['para', ['ul', 'paragraph']], ['table', ['table']], ['insert', ['link', 'picture']] ]}); |
释放Summernote
|
1
|
$('.summernote').destroy(); |
取值与赋值
|
1
2
3
4
5
6
|
//取值var sHTML = $('.summernote').code();//同一页面多个summernote时,取第二个的值var sHTML = $('.summernote').eq(1).code();//赋值$('.summernote').code(sHTML); |
事件
oninit
|
1
2
3
4
5
|
$('#summernote').summernote({ oninit: function() { console.log('Summernote is launched'); }}); |
onenter
|
1
2
3
4
5
|
$('#summernote').summernote({ onenter: function(e) { console.log('Enter/Return key pressed'); }}); |
onfocus
|
1
2
3
4
5
|
$('#summernote').summernote({ onfocus: function(e) { console.log('Editable area is focused'); }}); |
onblur
|
1
2
3
4
5
|
$('#summernote').summernote({ onblur: function(e) { console.log('Editable area loses focus'); }}); |
onkeyup
|
1
2
3
4
5
|
$('#summernote').summernote({ onkeyup: function(e) { console.log('Key is released:', e.keyCode); }}); |
onkeydown
|
1
2
3
4
5
|
$('#summernote').summernote({ onkeydown: function(e) { console.log('Key is pressed:', e.keyCode); }}); |
onpaste
|
1
2
3
4
5
|
$('#summernote').summernote({ onpaste: function(e) { console.log('Called event paste'); }}); |
onImageUpload
可以重写图片上传句柄
|
1
2
3
4
5
|
$('#summernote').summernote({ onImageUpload: function(files, editor, $editable) { console.log('image upload:', files, editor, $editable); }}); |
onChange
IE9-10: DOMCharacterDataModified, DOMSubtreeModified, DOMNodeInserted
Chrome, FF: input
|
1
2
3
4
5
|
$('#summernote').summernote({ onChange: function(contents, $editable) { console.log('onChange:', contents, $editable); }}); |
支持18国语言,使用时引入你需要的语言文件,lang值设为你需要的语言
|
1
2
3
4
5
6
7
8
|
<!-- include summernote-ko-KR --><script src="lang/summernote-ko-KR.js"></script>$(document).ready(function() { $('#summernote').summernote({ lang: 'ko-KR' // default: 'en-US' });}); |
基于jquery的bootstrap在线文本编辑器插件Summernote (转)的更多相关文章
- 基于jquery的bootstrap在线文本编辑器插件Summernote
Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...
- 基于jquery的bootstrap在线文本编辑器插件Summernote 简单强大
Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...
- Jquery的bootstrap在线文本编辑器插件Summernote
http://www.jqcool.net/demo/201407/bootstrap-summernote/ Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线 ...
- Bootstrap-基于jquery的bootstrap在线文本编辑器插件Summernote
Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...
- 基于JQuery的简单富文本编辑器
利用jQuery实现最简单的编辑器 我试了很多种方法,目前最快捷能够实现及其简单的编辑可以使用 document.execCommand("ForeColor", "fa ...
- 基于jquery、bootstrap的数据验证插件bootstrapValidator使用
实时验证用户名是否存在,密码不能和用户名相同,两次密码需要相同,提交之后需要验证返回值: <form id="defaultForm" role="form&quo ...
- Summernote – 基于 Bootstrap 的文本编辑器
Summernote 是一个简单,灵活,所见即所得(WYSIWYG)的编辑器,基于 jQuery 和 Bootstrap 构建.Summernote 所有主要的操作都支持快捷键,有一个功能强大的 AP ...
- 百度umeditor富文本编辑器插件扩展
富文本编辑器在WEB开发中经常用到,个人比较喜欢用百度出的ueditor这款,ueditor这款本身支持插件扩展的,但是ueditor的mini版本 umeditor 就没有那么方便了,不过找了很多资 ...
- 基于jQuery点击图像居中放大插件Zoom
分享一款基于jQuery点击图像居中放大插件Zoom是一款放大的时候会从原图像的位置以动画方式放大到画面中间,支持点击图像或者按ESC键来关闭效果.效果图如下: 在线预览 源码下载 实现的代码. ...
随机推荐
- SparkSQL的3种Join实现
引言 Join是SQL语句中的常用操作,良好的表结构能够将数据分散在不同的表中,使其符合某种范式,减少表冗余.更新容错等.而建立表和表之间关系的最佳方式就是Join操作. 对于Spark来说有3中Jo ...
- java gc log
java full gc 经常带来延迟, 导致性能问题 如下命令使java虚拟机记录gc的log到文件, 帮助分析定位问题. java -Xloggc:./a.log -jar a.jar // ...
- Angular 学习笔记——$http
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- linux命令之------vmstat使用
在linux命令中,vmstat是个经常用到的分析系统性能的命令之一,主要有两个参数:一个是采样频率,一个是采样的次数.如:vmstat 1 3,意思就是每隔1秒采样1次,总共采样3次. 统计次 ...
- linux服务器性能检测工具nmon使用
今天介绍一款linux系统服务器性能检测的工具-nmon及nmon_analyser (生成性能报告的免费工具),亲测可用. 一.介绍 nmon 工具可以帮助在一个屏幕上显示所有重要的性能优化信息,并 ...
- c#利用委托传递函数参数(1)
本次旨在解决 同参不同名 的函数作为参数传递的情况 情景: 一下两个函数分别多次重复调用了两个同参不同名的函数(实际上总共有3个这样的函数),函数结构基本相同,只有调用的函数名不一样,显然可以整合在一 ...
- CentOs上搭建nginx
目录 CentOs上搭建nginx 1. 在root环境下安装nginx 1.1 常用工具安装 1.2 关闭iptables规则 1.3 关闭SELinux 1.4 安装C/C++环境和PCRE库 1 ...
- POJ 1731 Orders(STL运用)
题目地址:POJ 1731 这题能够直接用STL函数做,非常轻松..next_permutation函数非常给力.. 代码例如以下: #include <algorithm> #inclu ...
- Maven常见异常及解决方法(本篇停更至16-4-12)
本篇文章记录了老猫在学习整合Maven和SSH过程中遇到的问题,有的问题可以解决.有的问题还不能解决. 方法不一定适合全部的环境.但绝对是本人常遇到的常见异常.在这里做一个笔记和记录,也分享给大家,希 ...
- Atitit.swift 的新特性 以及与java的对比 改进方向attilax 总结
Atitit.swift 的新特性 以及与java的对比 改进方向attilax 总结 1. defer关键字1 2. try!形式存在的“不失败”机制3 3. Guard 4 4. swift的新语 ...