1 Star 0 Fork 296

cgb-lowcode/ueditor-plus

forked from ModStartLib/ueditor-plus 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
customPluginDemo.html 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
MZ 提交于 2023-11-01 11:03 +08:00 . build
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title></title>
<script type="text/javascript" charset="utf-8" src="../ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="editor_api.js"></script>
<script>var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?f84f35a44b5cc5c0b10c3fabdf0f322b";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();</script>
<link rel="stylesheet" href="./style.css"/>
</head>
<body class="demo-editor-page">
<div>
<h1>UEditor自定义插件</h1>
<!--style给定宽度可以影响编辑器的最终宽度-->
<script type="text/plain" id="myEditor">
<p><img src="http://ueditor.baidu.com/website/images/banner-dl.png" alt=""></p>
<p>插件描述选中图片在其上单击会改变图片的边框</p>
</script>
<script type="text/javascript">
//创建一个在选中的图片单击时添加边框的插件,其实质就是在baidu.editor.plugins塞进一个闭包
UE.plugins["addborder"] = function () {
var me = this;
//创建一个改变图片边框的命令
me.commands["addborder"] = {
execCommand: function () {
//获取当前选区
var range = me.selection.getRange();
//选区没闭合的情况下操作
if (!range.collapsed) {
//图片判断
var img = range.getClosedNode();
if (img && img.tagName == "IMG") {
//点击切换图片边框
img.style.border = img.style.borderWidth == "5px" ? "1px" : "5px solid red";
}
}
}
};
//注册一个触发命令的事件,同学们可以在任意地放绑定触发此命令的事件
me.addListener('click', function () {
setTimeout(function () {
me.execCommand("addborder");
})
});
};
var editor_a = UE.getEditor('myEditor');
</script>
</div>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cgb-lowcode/ueditor-plus.git
git@gitee.com:cgb-lowcode/ueditor-plus.git
cgb-lowcode
ueditor-plus
ueditor-plus
master

搜索帮助