2 Copyright (c) 2003-2010, 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 !config.resize_dir && ( config.resize_dir = 'both' );
\r
13 ( config.resize_maxWidth == undefined ) && ( config.resize_maxWidth = 3000 );
\r
14 ( config.resize_maxHeight == undefined ) && ( config.resize_maxHeight = 3000 );
\r
15 ( config.resize_minWidth == undefined ) && ( config.resize_minWidth = 750 );
\r
16 ( config.resize_minHeight == undefined ) && ( config.resize_minHeight = 250 );
\r
18 if ( config.resize_enabled !== false )
\r
20 var container = null,
\r
23 resizeHorizontal = ( config.resize_dir == 'both' || config.resize_dir == 'horizontal' ) &&
\r
24 ( config.resize_minWidth != config.resize_maxWidth ),
\r
25 resizeVertical = ( config.resize_dir == 'both' || config.resize_dir == 'vertical' ) &&
\r
26 ( config.resize_minHeight != config.resize_maxHeight );
\r
28 function dragHandler( evt )
\r
30 var dx = evt.data.$.screenX - origin.x,
\r
31 dy = evt.data.$.screenY - origin.y,
\r
32 width = startSize.width,
\r
33 height = startSize.height,
\r
34 internalWidth = width + dx * ( editor.lang.dir == 'rtl' ? -1 : 1 ),
\r
35 internalHeight = height + dy;
\r
37 if ( resizeHorizontal )
\r
38 width = Math.max( config.resize_minWidth, Math.min( internalWidth, config.resize_maxWidth ) );
\r
40 if ( resizeVertical )
\r
41 height = Math.max( config.resize_minHeight, Math.min( internalHeight, config.resize_maxHeight ) );
\r
43 editor.resize( width, height );
\r
46 function dragEndHandler ( evt )
\r
48 CKEDITOR.document.removeListener( 'mousemove', dragHandler );
\r
49 CKEDITOR.document.removeListener( 'mouseup', dragEndHandler );
\r
51 if ( editor.document )
\r
53 editor.document.removeListener( 'mousemove', dragHandler );
\r
54 editor.document.removeListener( 'mouseup', dragEndHandler );
\r
58 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
\r
61 container = editor.getResizable();
\r
63 startSize = { width : container.$.offsetWidth || 0, height : container.$.offsetHeight || 0 };
\r
64 origin = { x : $event.screenX, y : $event.screenY };
\r
66 config.resize_minWidth > startSize.width && ( config.resize_minWidth = startSize.width );
\r
67 config.resize_minHeight > startSize.height && ( config.resize_minHeight = startSize.height );
\r
69 CKEDITOR.document.on( 'mousemove', dragHandler );
\r
70 CKEDITOR.document.on( 'mouseup', dragEndHandler );
\r
72 if ( editor.document )
\r
74 editor.document.on( 'mousemove', dragHandler );
\r
75 editor.document.on( 'mouseup', dragEndHandler );
\r
79 editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
\r
81 editor.on( 'themeSpace', function( event )
\r
83 if ( event.data.space == 'bottom' )
\r
86 if ( resizeHorizontal && !resizeVertical )
\r
87 direction = ' cke_resizer_horizontal';
\r
88 if ( !resizeHorizontal && resizeVertical )
\r
89 direction = ' cke_resizer_vertical';
\r
91 event.data.html += '<div class="cke_resizer' + direction + '"' +
\r
92 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
\r
93 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event)"' +
\r
96 }, editor, null, 100 );
\r
102 * The minimum editor width, in pixels, when resizing it with the resize handle.
\r
103 * Note: It fallbacks to editor's actual width if that's smaller than the default value.
\r
104 * @name CKEDITOR.config.resize_minWidth
\r
108 * config.resize_minWidth = 500;
\r
112 * The minimum editor height, in pixels, when resizing it with the resize handle.
\r
113 * Note: It fallbacks to editor's actual height if that's smaller than the default value.
\r
114 * @name CKEDITOR.config.resize_minHeight
\r
118 * config.resize_minHeight = 600;
\r
122 * The maximum editor width, in pixels, when resizing it with the resize handle.
\r
123 * @name CKEDITOR.config.resize_maxWidth
\r
127 * config.resize_maxWidth = 750;
\r
131 * The maximum editor height, in pixels, when resizing it with the resize handle.
\r
132 * @name CKEDITOR.config.resize_maxHeight
\r
136 * config.resize_maxHeight = 600;
\r
140 * Whether to enable the resizing feature. If disabled the resize handler will not be visible.
\r
141 * @name CKEDITOR.config.resize_enabled
\r
145 * config.resize_enabled = false;
\r
149 * The directions to which the editor resizing is enabled. Possible values
\r
150 * are "both", "vertical" and "horizontal".
\r
151 * @name CKEDITOR.config.resize_dir
\r
156 * config.resize_dir = 'vertical';
\r