为用户设置CKEditor大小

时间:2014-05-05 02:25:08

标签: ckeditor

是否有回调或我可以使用的任何内容,以便当用户调整CKEditor大小时,我可以将新大小保存在cookie中,并在下次打开屏幕时重置编辑器大小。

到目前为止我找到的所有建议都是配置中的设置,而不是用户。

1 个答案:

答案 0 :(得分:1)

一般来说,有一种方法editor.resize(),它允许调整编辑器的大小(即使用cookie中的维度)。

问题仍然是:当用户重新调整UI大小时,如何保存尺寸?有editor#resize事件被触发,但由于未知原因,它没有传递任何有关尺寸的信息,这使得它变得毫无用处。

所以现在,我建议覆盖editor.resize(),当用户与缩放器进行交互时调用var width, height, savedWidth, savedHeight; var defaultResize = CKEDITOR.editor.prototype.resize; CKEDITOR.editor.prototype.resize = function( w, h ) { // Intercept dimensions when user resizes the UI. width = w; height = h; defaultResize.apply( this, arguments ); }; var editor = CKEDITOR.replace( 'editor', { toolbarGroups: [ { name: 'basicstyles' } ], resize_dir: 'both', on: { resize: function( evt ) { console.log( 'Editor was resized!' ); console.log( '...but editor#resize does not pass dimensions in evt.data so it is useless :(' ); } } } ); function save() { savedWidth = width; savedHeight = height; console.log( 'saving', savedWidth, savedHeight ); } function restore() { editor.resize( savedWidth, savedHeight ); console.log( 'restoring', savedWidth, savedHeight ); } 。然后,可以使用相同的方法恢复截取的维度:

{{1}}

JSFiddle

相关问题