


Detailed explanation of the use of BootStrap's text editor component Summernote
This time I will bring you a detailed explanation of the use of the text editor component Summernote of BootStrap. What are the precautions and the following are practical cases. Let’s take a look.
Summernote is a super simple WYSIWYG online editor based on jquery bootstrap. Summernote is very lightweight, only 30KB in size, and supports Safari, Chrome, Firefox, Opera, and the Internet Explorer 9 (IE8 support coming soon).
Features:
The world's best WYSIWYG online editor
Very easy to install
Open source
Custom initialization options
Support shortcut keys
Suitable for various back-end program languages
Summernote official website address: https://summernote.org/
This is an example from the official website:
nbsp;html> <meta> <title>Summernote</title> <link> <script></script> <script></script> <link> <script></script> <p></p><p>Hello Summernote</p> <script> $(document).ready(function() { $('#summernote').summernote(); }); </script>
Rendering:
The simplest way to initialize components by default:
Add a container
in
:<p>Hello Summernote</p>
Then use Jquery to initialize the component:
$(document).ready(function() { $('#summernote').summernote(); });
We can also define components ourselves, such as customizing the height of the edit box:
$('#summernote').summernote({ height: 300, // 定义编辑框高度 minHeight: null, // 定义编辑框最低的高度 maxHeight: null, // 定义编辑框最高德高度 });
We can also customize the toolbar:
<!--工具栏--> toolbar: [ <!--字体工具--> ['fontname', ['fontname']], //字体系列 ['style', ['bold', 'italic', 'underline', 'clear']], // 字体粗体、字体斜体、字体下划线、字体格式清除 ['font', ['strikethrough', 'superscript', 'subscript']], //字体划线、字体上标、字体下标 ['fontsize', ['fontsize']], //字体大小 ['color', ['color']], //字体颜色 <!--段落工具--> ['style', ['style']],//样式 ['para', ['ul', 'ol', 'paragraph']], //无序列表、有序列表、段落对齐方式 ['height', ['height']], //行高 <!--插入工具--> ['table',['table']], //插入表格 ['hr',['hr']],//插入水平线 ['link',['link']], //插入链接 ['picture',['picture']], //插入图片 ['video',['video']], //插入视频 <!--其它--> ['fullscreen',['fullscreen']], //全屏 ['codeview',['codeview']], //查看html代码 ['undo',['undo']], //撤销 ['redo',['redo']], //取消撤销 ['help',['help']], //帮助 ],
Some other initialization settings:
lang:'zh-CN', //To set Chinese, the Chinese plug-in summernote-zh-CN.js
is required /The dialog box should be placed in the edit box or the Body
dialogsFade: true,//The dialog box display effect
callback functions:
callbacks: { }
callbacks: { onImageUpload: function(file) { //图片默认以二进制的形式存储到数据库,调用此方法将请求后台将图片存储到服务器,返回图片请求地址到前端 //将图片放入Formdate对象中 var formData = new FormData(); //‘picture'为后台获取的文件名,file[0]是要上传的文件 formData.append("picture", file[0]); $.ajax({ type:'post', url:'请求后台地址', cache: false, data:formData, processData: false, contentType: false, dataType:'text', //请求成功后,后台返回图片访问地址字符串,故此以text格式获取,而不是json格式 success: function(picture) { $('#summernote').summernote('insertImage',picture); }, error:function(){ alert("上传失败"); } }); } }
Configuration File
to facilitate future address modifications. At the same time, the virtual access root path should not be stored in the database. Just store the relative location. The virtual access root path is also written in the properties file.Method to get the content of the edit box:
@RequestMapping(value="contentFileUpload",method=RequestMethod.POST) @ResponseBody public String contentFileUpload(MultipartFile picture) { if (picture!=null && picture.getOriginalFilename()!=null && picture.getOriginalFilename().trim().length()>0) { /** * picture上传路径(+时间文件夹) */ //真实的上传根路径 String realUploadPath = 'D:/Program Files (x86)/apache-tomcat-8.5.16/webapps/file'; //虚拟的文件访问根路径 String fictitiousRoot = '/file' //建立以时间命名的文件夹 SimpleDateFormat sdf=new SimpleDateFormat("/yyyy/MM/dd/"); String datePath = sdf.format(new Date()); //最终真实路径 String realuUploadBrandPath = realUploadPath+"/content"+datePath; //最终虚拟访问路径 String fictitiousUploadBrandPath =fictitiousRoot +"/content"+datePath; // 上传文件原始名称 String originFileName = picture.getOriginalFilename(); // 新的文件名称 String newFileName = UUID.randomUUID()+originFileName.substring(originFileName.lastIndexOf(".")); //如果路径文件夹不存在就创建 File dir=new File(realuUploadBrandPath); if(!dir.exists()){ dir.mkdirs(); } // 新文件 File newFile = new File(realuUploadBrandPath+File.separator+newFileName); // 将内存中的文件写入磁盘 try { picture.transferTo(newFile); } catch (IllegalStateException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // 文件虚拟地址 String fictitiousFilePath = fictitiousUploadBrandPath+newFileName; return fictitiousFilePath; } return "false"; }
Operation search component is displayed on the keyboard
Use the static method of the Class class in ES6
The above is the detailed content of Detailed explanation of the use of BootStrap's text editor component Summernote. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use Bootstrap to get the value of the search bar: Determines the ID or name of the search bar. Use JavaScript to get DOM elements. Gets the value of the element. Perform the required actions.

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

Use Bootstrap to implement vertical centering: flexbox method: Use the d-flex, justify-content-center, and align-items-center classes to place elements in the flexbox container. align-items-center class method: For browsers that do not support flexbox, use the align-items-center class, provided that the parent element has a defined height.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
