2 Copyright (c) 2003-2013, 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 // DO NOT impose fixed size with single direction resize. (#6308)
\r
48 editor.resize( resizeHorizontal ? width : null, height );
\r
51 function dragEndHandler ( evt )
\r
53 CKEDITOR.document.removeListener( 'mousemove', dragHandler );
\r
54 CKEDITOR.document.removeListener( 'mouseup', dragEndHandler );
\r
56 if ( editor.document )
\r
58 editor.document.removeListener( 'mousemove', dragHandler );
\r
59 editor.document.removeListener( 'mouseup', dragEndHandler );
\r
63 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
\r
66 container = editor.getResizable();
\r
68 startSize = { width : container.$.offsetWidth || 0, height : container.$.offsetHeight || 0 };
\r
69 origin = { x : $event.screenX, y : $event.screenY };
\r
71 config.resize_minWidth > startSize.width && ( config.resize_minWidth = startSize.width );
\r
72 config.resize_minHeight > startSize.height && ( config.resize_minHeight = startSize.height );
\r
74 CKEDITOR.document.on( 'mousemove', dragHandler );
\r
75 CKEDITOR.document.on( 'mouseup', dragEndHandler );
\r
77 if ( editor.document )
\r
79 editor.document.on( 'mousemove', dragHandler );
\r
80 editor.document.on( 'mouseup', dragEndHandler );
\r
84 editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
\r
86 editor.on( 'themeSpace', function( event )
\r
88 if ( event.data.space == 'bottom' )
\r
91 if ( resizeHorizontal && !resizeVertical )
\r
92 direction = ' cke_resizer_horizontal';
\r
93 if ( !resizeHorizontal && resizeVertical )
\r
94 direction = ' cke_resizer_vertical';
\r
98 ' class="cke_resizer' + direction + ' cke_resizer_' + resizeDir + '"' +
\r
99 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
\r
100 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event)"' +
\r
103 // Always sticks the corner of botttom space.
\r
104 resizeDir == 'ltr' && direction == 'ltr' ?
\r
105 event.data.html += resizerHtml :
\r
106 event.data.html = resizerHtml + event.data.html;
\r
108 }, editor, null, 100 );
\r
114 * The minimum editor width, in pixels, when resizing the editor interface by using the resize handle.
\r
115 * Note: It falls back to editor's actual width if it is smaller than the default value.
\r
116 * @name CKEDITOR.config.resize_minWidth
\r
120 * config.resize_minWidth = 500;
\r
124 * The minimum editor height, in pixels, when resizing the editor interface by using the resize handle.
\r
125 * Note: It falls back to editor's actual height if it is smaller than the default value.
\r
126 * @name CKEDITOR.config.resize_minHeight
\r
130 * config.resize_minHeight = 600;
\r
134 * The maximum editor width, in pixels, when resizing the editor interface by using the resize handle.
\r
135 * @name CKEDITOR.config.resize_maxWidth
\r
139 * config.resize_maxWidth = 750;
\r
143 * The maximum editor height, in pixels, when resizing the editor interface by using the resize handle.
\r
144 * @name CKEDITOR.config.resize_maxHeight
\r
148 * config.resize_maxHeight = 600;
\r
152 * Whether to enable the resizing feature. If this feature is disabled, the resize handle will not be visible.
\r
153 * @name CKEDITOR.config.resize_enabled
\r
157 * config.resize_enabled = false;
\r
161 * The dimensions for which the editor resizing is enabled. Possible values
\r
162 * are <code>both</code>, <code>vertical</code>, and <code>horizontal</code>.
\r
163 * @name CKEDITOR.config.resize_dir
\r
168 * config.resize_dir = 'vertical';
\r