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(o){function e(){i=o.document,a=i[CKEDITOR.env.ie?"getBody":"getDocumentElement"](),m=CKEDITOR.env.quirks?i.getBody():i.getDocumentElement();var e=CKEDITOR.env.quirks?m:m.findOne("body");e&&(e.setStyle("height","auto"),e.setStyle("min-height",CKEDITOR.env.safari?"0%":"auto")),r=CKEDITOR.dom.element.createFromHtml(''+(CKEDITOR.env.webkit?" ":"")+"",i)}function t(){u&&m.setStyle("overflow-y","hidden");var e,t=o.window.getViewPaneSize().height;a.append(r),e=r.getDocumentPosition(i).y+r.$.offsetHeight,r.remove(),e+=g,e=Math.max(e,c),(e=Math.min(e,s))!=t&&n!=e&&(e=o.fire("autoGrow",{currentHeight:t,newHeight:e}).newHeight,t="border-box"===o.container.getComputedStyle("box-sizing"),t=o.container.getSize("width",t),o.resize(t,e,!0),n=e),u||(em.$.clientHeight?m.setStyle("overflow-y","hidden"):m.removeStyle("overflow-y"))}var n,i,a,m,r,d,g=o.config.autoGrow_bottomSpace||0,c=void 0!==o.config.autoGrow_minHeight?o.config.autoGrow_minHeight:200,s=o.config.autoGrow_maxHeight||1/0,u=!o.config.autoGrow_maxHeight;for(d in o.addCommand("autogrow",{exec:t,modes:{wysiwyg:1},readOnly:1,canUndo:!1,editorFocus:!1}),{contentDom:1,key:1,selectionChange:1,insertElement:1,mode:1})o.on(d,function(e){"wysiwyg"==e.editor.mode&&setTimeout(function(){var e=o.getCommand("maximize");!o.window||e&&e.state==CKEDITOR.TRISTATE_ON?n=null:(t(),u||t())},100)});o.on("afterCommandExec",function(e){"maximize"==e.data.name&&"wysiwyg"==e.editor.mode&&(e.data.command.state==CKEDITOR.TRISTATE_ON?m.removeStyle("overflow-y"):t())}),o.on("contentDom",e),e(),o.config.autoGrow_onStartup&&o.editable().isVisible()&&o.execCommand("autogrow")}(e)})}});