/*
 Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
 For licensing, see LICENSE.html or http://ckeditor.com/license
*/
(function(){function i(a){var a=a.document,c=a.getBody(),d=a.getDocumentElement();return"BackCompat"==a.$.compatMode?c:d}var h=function(a,c){if(a.window){var d=a.getCommand("maximize");if(!(d&&d.state==CKEDITOR.TRISTATE_ON)){var d=i(a),f=a.window.getViewPaneSize().height,b;b=d.getStyle("overflow-y");var g=d.getDocument(),e=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>",g);g[CKEDITOR.env.ie?
"getBody":"getDocumentElement"]().append(e);g=e.getDocumentPosition(g).y+e.$.offsetHeight;e.remove();d.setStyle("overflow-y",b);b=g+(a.config.autoGrow_bottomSpace||0);e=a.config.autoGrow_maxHeight||Infinity;b=Math.max(b,void 0!=a.config.autoGrow_minHeight?a.config.autoGrow_minHeight:200);b=Math.min(b,e);b!=f&&c!=b&&(b=a.fire("autoGrow",{currentHeight:f,newHeight:b}).newHeight,a.resize(a.container.getStyle("width"),b,!0),c=b);d.$.scrollHeight>d.$.clientHeight&&b<e?d.setStyle("overflow-y","hidden"):
d.removeStyle("overflow-y");return c}}};CKEDITOR.plugins.add("autogrow",{init:function(a){if(a.elementMode!=CKEDITOR.ELEMENT_MODE_INLINE)a.on("instanceReady",function(){var c;if(a.editable().isInline())a.ui.space("contents").setStyle("height","auto");else{a.addCommand("autogrow",{exec:function(a){c=h(a,c)},modes:{wysiwyg:1},readOnly:1,canUndo:!1,editorFocus:!1});var d={contentDom:1,key:1,selectionChange:1,insertElement:1,mode:1},f;for(f in d)a.on(f,function(a){"wysiwyg"==a.editor.mode&&setTimeout(function(){c=
h(a.editor,c);c=h(a.editor,c)},100)});a.on("afterCommandExec",function(b){"maximize"==b.data.name&&"wysiwyg"==b.editor.mode&&(b.data.command.state==CKEDITOR.TRISTATE_ON?i(a).removeStyle("overflow"):c=h(a,c))});a.config.autoGrow_onStartup&&a.execCommand("autogrow")}})}})})();