2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
6 CKEDITOR.plugins.add( 'resize',
8 init : function( editor )
10 var config = editor.config;
12 // Resize in the same direction of chrome,
13 // which is identical to dir of editor element. (#6614)
14 var resizeDir = editor.element.getDirection( 1 );
16 !config.resize_dir && ( config.resize_dir = 'both' );
17 ( config.resize_maxWidth == undefined ) && ( config.resize_maxWidth = 3000 );
18 ( config.resize_maxHeight == undefined ) && ( config.resize_maxHeight = 3000 );
19 ( config.resize_minWidth == undefined ) && ( config.resize_minWidth = 750 );
20 ( config.resize_minHeight == undefined ) && ( config.resize_minHeight = 250 );
22 if ( config.resize_enabled !== false )
27 resizeHorizontal = ( config.resize_dir == 'both' || config.resize_dir == 'horizontal' ) &&
28 ( config.resize_minWidth != config.resize_maxWidth ),
29 resizeVertical = ( config.resize_dir == 'both' || config.resize_dir == 'vertical' ) &&
30 ( config.resize_minHeight != config.resize_maxHeight );
32 function dragHandler( evt )
34 var dx = evt.data.$.screenX - origin.x,
35 dy = evt.data.$.screenY - origin.y,
36 width = startSize.width,
37 height = startSize.height,
38 internalWidth = width + dx * ( resizeDir == 'rtl' ? -1 : 1 ),
39 internalHeight = height + dy;
41 if ( resizeHorizontal )
42 width = Math.max( config.resize_minWidth, Math.min( internalWidth, config.resize_maxWidth ) );
45 height = Math.max( config.resize_minHeight, Math.min( internalHeight, config.resize_maxHeight ) );
47 editor.resize( width, height );
50 function dragEndHandler ( evt )
52 CKEDITOR.document.removeListener( 'mousemove', dragHandler );
53 CKEDITOR.document.removeListener( 'mouseup', dragEndHandler );
55 if ( editor.document )
57 editor.document.removeListener( 'mousemove', dragHandler );
58 editor.document.removeListener( 'mouseup', dragEndHandler );
62 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
65 container = editor.getResizable();
67 startSize = { width : container.$.offsetWidth || 0, height : container.$.offsetHeight || 0 };
68 origin = { x : $event.screenX, y : $event.screenY };
70 config.resize_minWidth > startSize.width && ( config.resize_minWidth = startSize.width );
71 config.resize_minHeight > startSize.height && ( config.resize_minHeight = startSize.height );
73 CKEDITOR.document.on( 'mousemove', dragHandler );
74 CKEDITOR.document.on( 'mouseup', dragEndHandler );
76 if ( editor.document )
78 editor.document.on( 'mousemove', dragHandler );
79 editor.document.on( 'mouseup', dragEndHandler );
83 editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
85 editor.on( 'themeSpace', function( event )
87 if ( event.data.space == 'bottom' )
90 if ( resizeHorizontal && !resizeVertical )
91 direction = ' cke_resizer_horizontal';
92 if ( !resizeHorizontal && resizeVertical )
93 direction = ' cke_resizer_vertical';
97 ' class="cke_resizer' + direction + ' cke_resizer_' + resizeDir + '"' +
98 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
99 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event)"' +
102 // Always sticks the corner of botttom space.
103 resizeDir == 'ltr' && direction == 'ltr' ?
104 event.data.html += resizerHtml :
105 event.data.html = resizerHtml + event.data.html;
107 }, editor, null, 100 );
113 * The minimum editor width, in pixels, when resizing the editor interface by using the resize handle.
114 * Note: It falls back to editor's actual width if it is smaller than the default value.
115 * @name CKEDITOR.config.resize_minWidth
119 * config.resize_minWidth = 500;
123 * The minimum editor height, in pixels, when resizing the editor interface by using the resize handle.
124 * Note: It falls back to editor's actual height if it is smaller than the default value.
125 * @name CKEDITOR.config.resize_minHeight
129 * config.resize_minHeight = 600;
133 * The maximum editor width, in pixels, when resizing the editor interface by using the resize handle.
134 * @name CKEDITOR.config.resize_maxWidth
138 * config.resize_maxWidth = 750;
142 * The maximum editor height, in pixels, when resizing the editor interface by using the resize handle.
143 * @name CKEDITOR.config.resize_maxHeight
147 * config.resize_maxHeight = 600;
151 * Whether to enable the resizing feature. If this feature is disabled, the resize handle will not be visible.
152 * @name CKEDITOR.config.resize_enabled
156 * config.resize_enabled = false;
160 * The dimensions for which the editor resizing is enabled. Possible values
161 * are <code>both</code>, <code>vertical</code>, and <code>horizontal</code>.
162 * @name CKEDITOR.config.resize_dir
167 * config.resize_dir = 'vertical';