文章详情

虽然 wangEditor 没有内置全屏功能,但是你可以通过简单的代码来搞定,作者已经做了一个demo来示范。通过运行 demo(文档一开始就介绍了)即可看到该示例页面,直接查看页面源代码即可。

如果需要预览和查看源码的功能,也需要跟全屏功能一样,自己定义按钮。点击按钮时通过editor.txt.html()获取编辑器内容,然后自定义实现预览和查看源码功能。通过editor.txt.html(value)可以更新源码,这样就可以做到修改源码了。

CSS样式:wangEditor-fullscreen-plugin.css

@CHARSET "UTF-8";
.w-e-toolbar {
flex-wrap: wrap;
-webkit-box-lines: multiple;
}
.w-e-toolbar .w-e-menu:hover{
z-index: 10002!important;
}
.w-e-menu a {
text-decoration: none;
}
.btn_viewSource .icon {
background-image: url("dm.png");
width: 10px;
height: 10px;
}
.fullscreen-editor {
position: fixed !important;
width: 100% !important;
height: 100% !important;
left: 0px !important;
top: 0px !important;
background-color: white;
z-index: 9999;
}
.fullscreen-editor .w-e-text-container {
width: 100% !important;
height: 95% !important;
}

JS样式:wangEditor-fullscreen-plugin.js

/**
* wangEditor扩展,增加全屏 查看源码功能
* 使用方法:
* E.fullscreen.init(editor);
* E.viewSource.init(editor);
*/
window.wangEditor.fullscreen = {
init: function(editor) {
id = editor.id;
if(!this.pluginsEditors){
this.pluginsEditors = {}
}
if(this.pluginsEditors[id]){
editor = this.pluginsEditors[id];
} else {
this.pluginsEditors[id]=editor;
}
editor.isFullScreen = false;
toolbar = editor.$toolbarElem[0];
$(toolbar).append('<div class="w-e-menu btn_fullscreen" onclick="window.wangEditor.fullscreen.run(\''+id+'\')">全屏</div>');
},
run: function(id) {
editor = this.pluginsEditors[id];
editor.isFullScreen = editor.isFullScreen;
container = $(editor.toolbarSelector);
container.toggleClass('fullscreen-editor');
container.find('.btn_fullscreen').text(this.isFullScreen ? '退出全屏': '全屏');
}
};
window.wangEditor.viewSource = {
init: function(editor) {
id = editor.id;
if(!this.pluginsEditors){
this.pluginsEditors = {}
}
if(this.pluginsEditors[id]){
editor = this.pluginsEditors[id];
} else {
this.pluginsEditors[id]=editor;
}
editor.isHTML = false;
toolbar = editor.$toolbarElem[0];
$(toolbar).append("<div class='w-e-menu btn_viewSource' title='查看源码' onclick='window.wangEditor.viewSource.run(\""+id+"\")'><img src='dm.png' width='25' height='25'></div>");
},
run: function(id) {
editor = this.pluginsEditors[id];
editor.isHTML = !editor.isHTML;
_source = editor.txt.html();
toolbar = editor.$toolbarElem[0];
if (editor.isHTML) {
_source = _source.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/ /g, "&nbsp;");
$(toolbar).find('.w-e-menu').css({ "display": "none" });
$(toolbar).find('.btn_viewSource').css({ "display": "" });
} else {
_source = editor.txt.text().replace(/&lt;/ig, "<").replace(/&gt;/ig, ">").replace(/&nbsp;/ig, " ");
$(toolbar).find('.w-e-menu').css({ "display": "" });
editor.change && editor.change();
}
editor.txt.html(_source);
}
};

最后在后面增加下面代码即可

E.fullscreen.init(editor);
E.viewSource.init(editor);

版权:版权申明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 70068002@qq.com 举报,一经查实,本站将立刻删除。

转载请注明出处:https://www.stntk.com/2519.html

相关推荐
JS前端模拟Excel条件格式实现数据条效果
需求背景 最近业务中遇到一个有意思的需求,是要在现有的表格中实现类似 Excel 中的数据条的效果,在数据比较多的时候单纯看表格里的数字会比…
头像
前端开发 2024-05-26
962
js 实现汉字简体和繁体之间的互相转换
简体字 简体字(Simplified Chinese,简体中文),是中国大陆地区目前在用的字体,由官方公布的简体字,主要由传承字以及1950…
头像
前端开发 2024-05-26
746
如何使用nginx配置代理多个前端资源?
背景 两套不同的前端使用同一个后端服务,前端使用的Nginx代理的dist包 前端 vue+elementui 后端 Python+flas…
头像
前端开发 2024-05-26
612
jquery实现ul列表中点击li选择radio
如何利用jquery实现ul列表中点击li选择radio呢? 1、HTML代码 <ul class="list-group"> …
头像
前端开发 2024-05-26
1,165
vue3.2+ts实现在方法中可调用的拟态框弹窗(类el-MessageBox)
公司UI设计的拟态框弹窗跟Element Plus UI的布局不太一致。导致不能够直接修改样式得到想到样式。直接上图。 这个需求最主要的是要…
头像
前端开发 2024-05-26
1,166
前端如何实现网页变灰功能?
今天来从前端的角度看看网页置灰是如何实现的,以及相关使用技巧! 实现思路 先来看看一些主流网站是如何实现置灰的: BiliBili: 京东 …
头像
前端开发 2024-05-26
871
发表评论
暂无评论

还没有评论呢,快来抢沙发~

点击联系客服

在线时间:8:00-16:00

客服电话

400-888-8888

客服邮箱

70068002@qq.com

扫描二维码

关注微信公众号