quill富文本编辑器quill粘贴图片上传服务器
强大的富文本编辑器:quill
github:32k start++,:https://github.com/quilljs/quill
quill粘贴图片上传服务器
<link href="//cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
<div id="editor" style="height: 370px">
<p>Hello World!</p>
</div>
<script src="//cdn.quilljs.com/1.3.6/quill.min.js"></script>
<script>
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{'header': 1}, {'header': 2}], // custom button values
[{'list': 'ordered'}, {'list': 'bullet'}],
[{'script': 'sub'}, {'script': 'super'}], // superscript/subscript
[{'indent': '-1'}, {'indent': '+1'}], // outdent/indent
[{'direction': 'rtl'}], // text direction
[{'size': ['small', false, 'large', 'huge']}], // custom dropdown
[{'header': [1, 2, 3, 4, 5, 6, false]}],
[{'color': []}, {'background': []}], // dropdown with defaults from theme
[{'font': []}],
[{'align': []}],
['image'],
['clean'] // remove formatting button
];
var editor = new Quill('#editor', {
modules: {toolbar: toolbarOptions},
theme: 'snow',
});
// 粘贴图片上传服务器
editor.root.addEventListener("paste", (e) => {
console.log(e)
console.log(this)
const clipboardData = e.clipboardData
// support cut by software & copy image file directly
const isImage = clipboardData.types.length && clipboardData.types.join('').includes('Files');
if (!isImage) {
return;
}
// only support single image paste
const file = clipboardData.files[0];
if (!file || !file.name || !(file.name.toLowerCase().indexOf(".png") !== -1 || file.name.toLowerCase().indexOf(".gif") !== -1
|| file.name.toLowerCase().indexOf(".jpg") !== -1)) {
console.log('粘贴的不是图片')
return;
}
var formData = new FormData;
formData.append('file', file)
// 在此执行上传
$.ajax({
data: formData,
processData: false,//不做处理
contentType: false,//不做处理
sync: false,
url: '/file/up/img',
type: 'post',
success(data) {
console.log(data)
if (data.code==0){
const range = editor.getSelection(true);
editor.insertEmbed(range.index, 'image', data.data);
}else {
layer.msg(data.msg)
}
}
})
})
editor.clipboard.addMatcher('IMG', (node, delta) => {
const Delta = Quill.import('delta')
// 忽略base64插入操作
return new Delta().insert('')
})
</script>
上传图片到服务器返回url处理
完整代码
<link href="//cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
<script src="//cdn.quilljs.com/1.3.6/quill.min.js"></script>
<div id="editor" style="height: 370px">
<p>Hello World!</p>
</div>
<input id="opImg" style="display: none;" type="file" onchange="addImg(this)"
accept="image/gif,image/jpeg,image/jpg,image/png,image/svg">
<script>
var editor,$
function addImg(e) {
const upImg = e.files[0];
console.log(editor)
var formData = new FormData;
formData.append('file', upImg)
$.ajax({
data: formData,
processData: false,//不做处理
contentType: false,//不做处理
sync: false,
url: '/file/up/img',
type: 'post',
success(data) {
console.log(data)
if (data.code == 0) {
const range = editor.getSelection(true);
editor.insertEmbed(range.index, 'image', data.data);
} else {
layer.msg(data.msg)
}
}
})
}
function imageHandler(e) {
// 在此执打开图片选择,行同步上传
/*const range = this.quill.getSelection(true);
this.quill.insertEmbed(range.index, 'image', 'http://localhost:8080/res/images/logo.png');*/
document.getElementById('opImg').click()
}
layui.use(['layer', 'jquery', 'form'], function () {
$ = layui.jquery
var layer = layui.layer
, form = layui.form
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{'header': 1}, {'header': 2}], // custom button values
[{'list': 'ordered'}, {'list': 'bullet'}],
[{'script': 'sub'}, {'script': 'super'}], // superscript/subscript
[{'indent': '-1'}, {'indent': '+1'}], // outdent/indent
[{'direction': 'rtl'}], // text direction
[{'size': ['small', false, 'large', 'huge']}], // custom dropdown
[{'header': [1, 2, 3, 4, 5, 6, false]}],
[{'color': []}, {'background': []}], // dropdown with defaults from theme
[{'font': ['宋体']}],
[{'align': []}],
['image'],
['clean'] // remove formatting button
];
editor = new Quill('#editor', {
modules: {
toolbar: {
container: toolbarOptions,
handlers: {
image: imageHandler
}
}
},
theme: 'snow',
});
editor.root.addEventListener("paste", (e) => {
console.log(e)
console.log(this)
const clipboardData = e.clipboardData
// support cut by software & copy image file directly
const isImage = clipboardData.types.length && clipboardData.types.join('').includes('Files');
if (!isImage) {
return;
}
// only support single image paste
const file = clipboardData.files[0];
if (!file || !file.name || !(file.name.toLowerCase().indexOf(".png") !== -1 || file.name.toLowerCase().indexOf(".gif") !== -1
|| file.name.toLowerCase().indexOf(".jpg") !== -1 || file.name.toLowerCase().indexOf(".jpeg") !== -1)) {
console.log('粘贴的不是图片')
return;
}
console.log(file)
var formData = new FormData;
formData.append('file', file)
// 在此执行上传
$.ajax({
data: formData,
processData: false,//不做处理
contentType: false,//不做处理
sync: false,
url: '/file/up/img',
type: 'post',
success(data) {
console.log(data)
if (data.code == 0) {
const range = editor.getSelection(true);
editor.insertEmbed(range.index, 'image', data.data);
} else {
layer.msg(data.msg)
}
}
})
})
editor.clipboard.addMatcher('IMG', (node, delta) => {
const Delta = Quill.import('delta')
return new Delta().insert('')
})
});
</script>
quill富文本编辑器quill粘贴图片上传服务器的更多相关文章
- Simditor 富文本编辑器多选图片上传、视频连接插入
simditor 是一个基于浏览器的所见即所得的文本编辑器.Simditor 富文本编辑器, 支持多选图片上传, 视频连接插入, HTML代码编辑以及常用富文本按钮,支持的浏览器:IE10.Firef ...
- wangEditor富文本编辑器使用及图片上传
引入js文件 <script type="text/javascript" src="style/js/wangEditor.min.js">< ...
- 富文本编辑器TInyMCE,本地图片上传(Image Upload)
TinyMCE 官网 (类似:百度的富文本web编辑器UEditor) 第一步 下载 TinyMCE,解压后放入工程,在需要的HTML页面引入tinymce.min.js. 第二步 下载tinyMCE ...
- C#中富文本编辑器Simditor带图片上传的全部过程(MVC架构的项目)
描述:最近c#项目中使用富文本编辑器Simditor,记录一下以便以后查看. 注:此项目是MVC架构的. 1.引用文件 项目中引用相应的css和js文件,注意顺序不能打乱,否则富文本编辑器不会正常显示 ...
- c#中富文本编辑器Simditor带图片上传的全部过程(项目不是mvc架构)
描述:最近c#项目中使用富文本编辑器Simditor,记录一下以便以后查看. 注:此项目不是MVC架构的. 1.引用文件 项目中引用相应的css和js文件,注意顺序不能打乱,否则富文本编辑器不会正常显 ...
- 百度富文本编辑器整合fastdfs文件服务器上传
技术:springboot+maven+ueditor 概述 百度富文本整合fastdfs文件服务器上传 详细 代码下载:http://www.demodashi.com/demo/15008.h ...
- 富文本之BootStrap-wysiwyg 带图片上传功能
BootStrap-wysiwyg插件具有良好的编辑功能和展示效果. 一.使用方法在网上有很多,在此记录自己使用过程中的一些问题和解决方式. 相关依赖: bootstrap-wysiwyg.js (核 ...
- 现代富文本编辑器Quill的内容渲染机制
DevUI是一支兼具设计视角和工程视角的团队,服务于华为云DevCloud平台和华为内部数个中后台系统,服务于设计师和前端工程师.官方网站:devui.designNg组件库:ng-devui(欢迎S ...
- 富文本编辑器Quill的使用
我们经常需要使用富文本编辑器从后台管理系统上传文字,图片等用于前台页面的显示,Quill在后台传值的时候需要传两个参数,一个用于后台管理系统编辑器的显示,一个用前台页面的显示,具体代码如下截图: 另Q ...
- Quill 富文本编辑器
Quill 富文本编辑器 https://quilljs.com/ https://github.com/quilljs/quill https://github.com/quilljs/awesom ...
随机推荐
- 拟合优度R2较低怎么办
拟合优度R2较低怎么办 (1)回归分为解释型回归和预测型回归. 预测型回归一般才会更看重2. 解释型回归更多的关注模型整体显著性以及自变量的统计显著性和经济意义显著 性即可. (2)可以对模型进行调整 ...
- 《流畅的Python》 读书笔记 231007(第二章第一部分)
第2章 数据结构 ABC语言是Python的爸爸~ 很多点子在现在看来都很有 Python 风格:序列的泛型操作.内置的元组和映射类型.用缩进来架构的源码.无需变量声明的强类型 不管是哪种数据结构,字 ...
- 基于Java Swing和BouncyCastle的证书生成工具
"Almost no one will remember what he had just not interested." - Nobody "几乎没有人会记得他所丝毫 ...
- 【Unity3D】Cesium加载大地图
1 前言 Cesium 是一个地球可视化平台和工具链,具有数据切片.数据分发.三维可视等功能. Cesium 支持 JS.Unity.Unreal.O3DE.Omniverse 等平台,框架如 ...
- 手撕Vue-查找指令和模板
接着上一篇文章,我们已经实现了提取元素到内存的过程,接下来我们要实现的是查找指令和模板. 大致的思路是这样的: 遍历所有的节点 需要判断当前遍历到的节点是一个元素还是一个文本 如果是一个元素, 我们需 ...
- C#/.NET/.NET Core优秀项目和框架精选(2023年10月更新,项目分类已整理完成欢迎大家踊跃提交PR一起完善让优秀的项目和框架不被埋没)
前言 帮助开发者发现功能强大.性能优越.创新前沿.简单易用的C#/.NET/.NET Core优秀项目和框架,无论你是寻找灵感.学习新技术.改进代码质量,还是想拓展自己的技术视野,都能为你提供有价值的 ...
- 基于GPS定位和人脸识别的作业识别管理系统
一.技术参数 mysql5.5 asp.net jquery 高德地图api 百度人脸识别api 二.功能简介 实现简单的施工项目管理,包括项目地点,工期,名称,编号等 实现作业人员的档案信息管理,包 ...
- umich cv-4-2 经典卷积网络架构
这节课中主要讨论了卷积神经网络的发展历史以及几种经典结构是如何构建的 卷积网络经典结构 AlexNet VGG GoogleNet Residual Network AlexNet 在2012年的时候 ...
- arm架构docker安装nacos
前言 搞了个hk1box,装了armbian系统,想用这个当服务器调试微服务,需要安装nacos.尝试安装非docker版本的nacos,去github下载arm版本的并且放到linux下面,运行的时 ...
- 研读Java代码必须掌握的Eclipse快捷键
1. Ctrl+左键 和F3 这个是大多数人经常用到的,用来查看变量.方法.类的定义 跳到光标所在标识符的定义代码.当按执行流程阅读时,F3实现了大部分导航动作. 2 Ctrl+Shift+G 在工作 ...