JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4b
[ckeditor.git] / _source / plugins / autogrow / plugin.js
diff --git a/_source/plugins/autogrow/plugin.js b/_source/plugins/autogrow/plugin.js
new file mode 100644 (file)
index 0000000..cd3fc3d
--- /dev/null
@@ -0,0 +1,79 @@
+/*\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+/**\r
+ * @file AutoGrow plugin\r
+ */\r
+(function(){\r
+       var resizeEditor = function( editor )\r
+       {\r
+               var doc = editor.document,\r
+                       currentHeight = editor.window.getViewPaneSize().height,\r
+                       newHeight;\r
+\r
+               // We can not use documentElement to calculate the height for IE (#6061).\r
+               if ( CKEDITOR.env.ie )\r
+                       newHeight = doc.getBody().$.scrollHeight + 24;\r
+               else\r
+                       newHeight = doc.getDocumentElement().$.offsetHeight;\r
+\r
+               var min = editor.config.autoGrow_minHeight,\r
+                       max = editor.config.autoGrow_maxHeight;\r
+               ( min == undefined ) && ( editor.config.autoGrow_minHeight = min = 200 );\r
+               if ( min )\r
+                       newHeight = Math.max( newHeight, min );\r
+               if ( max )\r
+                       newHeight = Math.min( newHeight, max );\r
+\r
+               if ( newHeight != currentHeight )\r
+               {\r
+                       newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;\r
+                       editor.resize( editor.container.getStyle( 'width' ), newHeight, true );\r
+               }\r
+       };\r
+       CKEDITOR.plugins.add( 'autogrow',\r
+       {\r
+               init : function( editor )\r
+               {\r
+                       for ( var eventName in { contentDom:1, key:1, selectionChange:1, insertElement:1 } )\r
+                       {\r
+                               editor.on( eventName, function( evt )\r
+                               {\r
+                                       // Some time is required for insertHtml, and it gives other events better performance as well.\r
+                                       if ( evt.editor.mode == 'wysiwyg' )\r
+                                               setTimeout( function(){ resizeEditor( evt.editor ); }, 100 );\r
+                               });\r
+                       }\r
+               }\r
+       });\r
+})();\r
+/**\r
+ * The minimum height to which the editor can reach using AutoGrow.\r
+ * @name CKEDITOR.config.autoGrow_minHeight\r
+ * @type Number\r
+ * @default 200\r
+ * @since 3.4\r
+ * @example\r
+ * config.autoGrow_minHeight = 300;\r
+ */\r
+\r
+/**\r
+ * The maximum height to which the editor can reach using AutoGrow. Zero means unlimited.\r
+ * @name CKEDITOR.config.autoGrow_maxHeight\r
+ * @type Number\r
+ * @default 0\r
+ * @since 3.4\r
+ * @example\r
+ * config.autoGrow_maxHeight = 400;\r
+ */\r
+\r
+/**\r
+ * Fired when the AutoGrow plugin is about to change the size of the editor.\r
+ * @name CKEDITOR#autogrow\r
+ * @event\r
+ * @param {Number} data.currentHeight The current height of the editor (before the resizing).\r
+ * @param {Number} data.newHeight The new height of the editor (after the resizing). It can be changed\r
+ *                             to determine another height to be used instead.\r
+ */\r