JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / plugins / resize / plugin.js
diff --git a/_source/plugins/resize/plugin.js b/_source/plugins/resize/plugin.js
new file mode 100644 (file)
index 0000000..6ef729f
--- /dev/null
@@ -0,0 +1,115 @@
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+CKEDITOR.plugins.add( 'resize',\r
+{\r
+       init : function( editor )\r
+       {\r
+               var config = editor.config;\r
+\r
+               if ( config.resize_enabled )\r
+               {\r
+                       var container = null;\r
+                       var origin, startSize;\r
+\r
+                       function dragHandler( evt )\r
+                       {\r
+                               var dx = evt.data.$.screenX - origin.x;\r
+                               var dy = evt.data.$.screenY - origin.y;\r
+                               var internalWidth = startSize.width + dx * ( editor.lang.dir == 'rtl' ? -1 : 1 );\r
+                               var internalHeight = startSize.height + dy;\r
+\r
+                               editor.resize( Math.max( config.resize_minWidth, Math.min( internalWidth, config.resize_maxWidth ) ),\r
+                                               Math.max( config.resize_minHeight, Math.min( internalHeight, config.resize_maxHeight ) ) );\r
+                       }\r
+\r
+                       function dragEndHandler ( evt )\r
+                       {\r
+                               CKEDITOR.document.removeListener( 'mousemove', dragHandler );\r
+                               CKEDITOR.document.removeListener( 'mouseup', dragEndHandler );\r
+\r
+                               if ( editor.document )\r
+                               {\r
+                                       editor.document.removeListener( 'mousemove', dragHandler );\r
+                                       editor.document.removeListener( 'mouseup', dragEndHandler );\r
+                               }\r
+                       }\r
+\r
+                       var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )\r
+                               {\r
+                                       if ( !container )\r
+                                               container = editor.getResizable();\r
+\r
+                                       startSize = { width : container.$.offsetWidth || 0, height : container.$.offsetHeight || 0 };\r
+                                       origin = { x : $event.screenX, y : $event.screenY };\r
+\r
+                                       CKEDITOR.document.on( 'mousemove', dragHandler );\r
+                                       CKEDITOR.document.on( 'mouseup', dragEndHandler );\r
+\r
+                                       if ( editor.document )\r
+                                       {\r
+                                               editor.document.on( 'mousemove', dragHandler );\r
+                                               editor.document.on( 'mouseup', dragEndHandler );\r
+                                       }\r
+                               } );\r
+\r
+                       editor.on( 'themeSpace', function( event )\r
+                               {\r
+                                       if ( event.data.space == 'bottom' )\r
+                                       {\r
+                                               event.data.html += '<div class="cke_resizer"' +\r
+                                                       ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +\r
+                                                       ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event)"' +\r
+                                                       '></div>';\r
+                                       }\r
+                               }, editor, null, 100 );\r
+               }\r
+       }\r
+} );\r
+\r
+/**\r
+ * The minimum editor width, in pixels, when resizing it with the resize handle.\r
+ * @type Number\r
+ * @default 750\r
+ * @example\r
+ * config.resize_minWidth = 500;\r
+ */\r
+CKEDITOR.config.resize_minWidth = 750;\r
+\r
+/**\r
+ * The minimum editor height, in pixels, when resizing it with the resize handle.\r
+ * @type Number\r
+ * @default 250\r
+ * @example\r
+ * config.resize_minHeight = 600;\r
+ */\r
+CKEDITOR.config.resize_minHeight = 250;\r
+\r
+/**\r
+ * The maximum editor width, in pixels, when resizing it with the resize handle.\r
+ * @type Number\r
+ * @default 3000\r
+ * @example\r
+ * config.resize_maxWidth = 750;\r
+ */\r
+CKEDITOR.config.resize_maxWidth = 3000;\r
+\r
+/**\r
+ * The maximum editor height, in pixels, when resizing it with the resize handle.\r
+ * @type Number\r
+ * @default 3000\r
+ * @example\r
+ * config.resize_maxHeight = 600;\r
+ */\r
+CKEDITOR.config.resize_maxHeight = 3000;\r
+\r
+/**\r
+ * Whether to enable the resizing feature. If disabed the resize handler will not be visible.\r
+ * @type Boolean\r
+ * @default true\r
+ * @example\r
+ * config.resize_enabled = false;\r
+ */\r
+CKEDITOR.config.resize_enabled = true;\r