为wangEditor扩展,增加全屏 查看源码功能

wangEditor 全屏 & 预览 & 查看源码

使用方法

引入wangEditor-fullscreen-plugin.css和wangEditor-fullscreen-plugin.js两个文件。

在wangEditor的create方法调用后,再调用插件的初始化方法,如:
	var E = window.wangEditor;
    var editor = new E('#editor');
    editor.create();
    E.fullscreen.init('#editor');

代码:
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;
}
 
.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;
}
/**
 * @todo 全屏
 */
window.wangEditor.fullscreen = {
	// editor create之后调用
	init: function(editorSelector){
		$(editorSelector + " .w-e-toolbar").append('<div class="w-e-menu"><a class="_wangEditor_btn_fullscreen" href="###" οnclick="window.wangEditor.fullscreen.toggleFullscreen(\'' + editorSelector + '\')">全屏</a></div>');
	},
	toggleFullscreen: function(editorSelector){
		$(editorSelector).toggleClass('fullscreen-editor');
		if($(editorSelector + ' ._wangEditor_btn_fullscreen').text() == '全屏'){
			$(editorSelector + ' ._wangEditor_btn_fullscreen').text('退出全屏');
		}else{
			$(editorSelector + ' ._wangEditor_btn_fullscreen').text('全屏');
		}
	}
};
 
/**
 * @todo 查看源码
 */
window.wangEditor.viewsource = {
    init: function(editorSelector) {
    	$(editorSelector + " .w-e-toolbar").append('<div class="w-e-menu"><a class="_wangEditor_btn_viewsource" href="###" οnclick="window.wangEditor.viewsource.toggleViewsource(\'' + editorSelector + '\')">源码</a></div>');
    },
    toggleViewsource: function(editorSelector) {
    	editorHtml = editor.txt.html();
		if($(editorSelector + ' ._wangEditor_btn_viewsource').text() == '源码'){
			editorHtml = editorHtml.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/ /g, "&nbsp;");
			$(editorSelector + ' ._wangEditor_btn_viewsource').text('返回');
		}else{
			editorHtml = editor.txt.text().replace(/&lt;/ig, "<").replace(/&gt;/ig, ">").replace(/&nbsp;/ig, " ");
			$(editorSelector + ' ._wangEditor_btn_viewsource').text('源码');
		}
        editor.txt.html(editorHtml);
        editor.change && editor.change();	//更新编辑器的内容
    }
};

页面调用:

    var E = window.wangEditor; 
    var editor = new E('#contentDiv'); 
    editor.create(); 
    E.fullscreen.init('#contentDiv');
    E.viewsource.init('#contentDiv');
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hello.鑫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值