NEW_CKEDITOR.plugins.add("autogrow",{init:function(e){e.elementMode!=NEW_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[NEW_CKEDITOR.env.ie?"getBody":"getDocumentElement"](),m=NEW_CKEDITOR.env.quirks?i.getBody():i.getDocumentElement();var t=NEW_CKEDITOR.env.quirks?m:m.findOne("body");t&&(t.setStyle("height","auto"),t.setStyle("min-height",NEW_CKEDITOR.env.safari?"0%":"auto")),d=NEW_CKEDITOR.dom.element.createFromHtml('<span style="margin:0;padding:0;border:0;clear:both;width:1px;height:1px;display:block;">'+(NEW_CKEDITOR.env.webkit?"&nbsp;":"")+"</span>",i)}function o(){u&&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(null,t,!0),n=t),u||(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,u=!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==NEW_CKEDITOR.TRISTATE_ON?n=null:(o(),u||o())}),100)}));e.on("afterCommandExec",(function(e){"maximize"==e.data.name&&"wysiwyg"==e.editor.mode&&(e.data.command.state==NEW_CKEDITOR.TRISTATE_ON?m.removeStyle("overflow-y"):o())})),e.on("contentDom",t),t(),e.config.autoGrow_onStartup&&e.editable().isVisible()&&e.execCommand("autogrow")}(e)}))}});