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