1 /*
  2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
  3 For licensing, see LICENSE.html or http://ckeditor.com/license
  4 */
  5
  6 CKEDITOR.plugins.add( 'resize',
  7 {
  8 	init : function( editor )
  9 	{
 10 		var config = editor.config;
 11
 12 		if ( config.resize_enabled )
 13 		{
 14 			var container = null;
 15 			var origin, startSize;
 16
 17 			function dragHandler( evt )
 18 			{
 19 				var dx = evt.data.$.screenX - origin.x;
 20 				var dy = evt.data.$.screenY - origin.y;
 21 				var internalWidth = startSize.width + dx * ( editor.lang.dir == 'rtl' ? -1 : 1 );
 22 				var internalHeight = startSize.height + dy;
 23
 24 				editor.resize( Math.max( config.resize_minWidth, Math.min( internalWidth, config.resize_maxWidth ) ),
 25 						Math.max( config.resize_minHeight, Math.min( internalHeight, config.resize_maxHeight ) ) );
 26 			}
 27
 28 			function dragEndHandler ( evt )
 29 			{
 30 				CKEDITOR.document.removeListener( 'mousemove', dragHandler );
 31 				CKEDITOR.document.removeListener( 'mouseup', dragEndHandler );
 32
 33 				if ( editor.document )
 34 				{
 35 					editor.document.removeListener( 'mousemove', dragHandler );
 36 					editor.document.removeListener( 'mouseup', dragEndHandler );
 37 				}
 38 			}
 39
 40 			var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
 41 				{
 42 					if ( !container )
 43 						container = editor.getResizable();
 44
 45 					startSize = { width : container.$.offsetWidth || 0, height : container.$.offsetHeight || 0 };
 46 					origin = { x : $event.screenX, y : $event.screenY };
 47
 48 					CKEDITOR.document.on( 'mousemove', dragHandler );
 49 					CKEDITOR.document.on( 'mouseup', dragEndHandler );
 50
 51 					if ( editor.document )
 52 					{
 53 						editor.document.on( 'mousemove', dragHandler );
 54 						editor.document.on( 'mouseup', dragEndHandler );
 55 					}
 56 				} );
 57
 58 			editor.on( 'themeSpace', function( event )
 59 				{
 60 					if ( event.data.space == 'bottom' )
 61 					{
 62 						event.data.html += '<div class="cke_resizer"' +
 63 							' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
 64 							' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event)"' +
 65 							'></div>';
 66 					}
 67 				}, editor, null, 100 );
 68 		}
 69 	}
 70 } );
 71
 72 CKEDITOR.config.resize_minWidth = 750;
 73 CKEDITOR.config.resize_minHeight = 250;
 74 CKEDITOR.config.resize_maxWidth = 3000;
 75 CKEDITOR.config.resize_maxHeight = 3000;
 76 CKEDITOR.config.resize_enabled = true;
 77