ckeditor5 全屏功能

RT 在ckeditor4的时候 我们可以在配置中添加一个属性 ‘maximize’ 就可以有个全屏或者缩小成默认的的按钮.
但是在ckeditor5的时候,这个功能被废弃了,笔者也找了一大堆资料
在这里插入图片描述
前两个都是开发者关于这个问题的解答
在这里插入图片描述
在这里插入图片描述
在此使用的时候,也会遇到在一个编辑器里使用多种文本模式报错的问题,详情解决方法可以看我上一篇文章 这里不再过多赘述.

准备工作

1.下载一份源码

git clone -b stable https://github.com/ckeditor/ckeditor5-build-classic.git
npm i

2.在src下新建一个文件 名字随便取

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ImageFullBig from '../icons/fullscreen-big.svg';
import ImageFullCancel from '../icons/fullscreen-cancel.svg';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import '../css/style.css';

export default class FullScreen extends Plugin {
	init() {
		const editor = this.editor;
		editor.ui.componentFactory.add( 'fullScreen', locale => {
			const view = new ButtonView( locale );
			let etat = 0; //
			view.set( {
				label: '全屏',
				icon: ImageFullBig,
				tooltip: true
			} );
			view.on( 'execute', () => {
				if ( etat == 1 ) {
					
					editor.sourceElement.nextElementSibling.removeAttribute( 'id' );
					document.body.removeAttribute( 'id' );
					view.set( {
						label: '全屏',
						icon: ImageFullBig,
						tooltip: true
					} );
					etat = 0;
				} else {
					editor.sourceElement.nextElementSibling.setAttribute( 'id', 'fullscreeneditor' );
					document.body.setAttribute( 'id', 'fullscreenoverlay' );
					view.set( {
						label: '默认',
						icon: ImageFullCancel,
						tooltip: true
					} );
					etat = 1;
				}
			} );

			return view;
		} );
	}
}


将这份代码复制进去 注意 上面引用的包不用继续下载 不然会报错 他在npm中已经有了
都完成 就可以npm打包了
上面的css以及图标我已经传入gitee里了
点击跳转gitee

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值