plugin.js 1.85 KB
Newer Older
Julien Jorry committed
1
CKEDITOR.plugins.add("autogrow",{init:function(e){e.elementMode!=CKEDITOR.ELEMENT_MODE_INLINE&&e.on("instanceReady",(function(){e.editable().isInline()?e.ui.space("contents").setStyle("height","auto"):function(e){function t(){i=e.document,a=i[CKEDITOR.env.ie?"getBody":"getDocumentElement"](),m=CKEDITOR.env.quirks?i.getBody():i.getDocumentElement();var t=CKEDITOR.env.quirks?m:m.findOne("body");t&&(t.setStyle("height","auto"),t.setStyle("min-height",CKEDITOR.env.safari?"0%":"auto")),d=CKEDITOR.dom.element.createFromHtml('<span style="margin:0;padding:0;border:0;clear:both;width:1px;height:1px;display:block;">'+(CKEDITOR.env.webkit?"&nbsp;":"")+"</span>",i)}function o(){s&&m.setStyle("overflow-y","hidden");var t,o=e.window.getViewPaneSize().height;a.append(d),t=d.getDocumentPosition(i).y+d.$.offsetHeight,d.remove(),t+=g,t=Math.max(t,c),(t=Math.min(t,l))!=o&&n!=t&&(t=e.fire("autoGrow",{currentHeight:o,newHeight:t}).newHeight,e.resize(e.container.getStyle("width"),t,!0),n=t),s||(t<l&&m.$.scrollHeight>m.$.clientHeight?m.setStyle("overflow-y","hidden"):m.removeStyle("overflow-y"))}var n,i,a,m,d,r,g=e.config.autoGrow_bottomSpace||0,c=void 0!==e.config.autoGrow_minHeight?e.config.autoGrow_minHeight:200,l=e.config.autoGrow_maxHeight||1/0,s=!e.config.autoGrow_maxHeight;for(r in e.addCommand("autogrow",{exec:o,modes:{wysiwyg:1},readOnly:1,canUndo:!1,editorFocus:!1}),{contentDom:1,key:1,selectionChange:1,insertElement:1,mode:1})e.on(r,(function(t){"wysiwyg"==t.editor.mode&&setTimeout((function(){var t=e.getCommand("maximize");!e.window||t&&t.state==CKEDITOR.TRISTATE_ON?n=null:(o(),s||o())}),100)}));e.on("afterCommandExec",(function(e){"maximize"==e.data.name&&"wysiwyg"==e.editor.mode&&(e.data.command.state==CKEDITOR.TRISTATE_ON?m.removeStyle("overflow-y"):o())})),e.on("contentDom",t),t(),e.config.autoGrow_onStartup&&e.editable().isVisible()&&e.execCommand("autogrow")}(e)}))}});