[2862] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2010, 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( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
|
---|
| 59 |
|
---|
| 60 | editor.on( 'themeSpace', function( event )
|
---|
| 61 | {
|
---|
| 62 | if ( event.data.space == 'bottom' )
|
---|
| 63 | {
|
---|
| 64 | event.data.html += '<div class="cke_resizer"' +
|
---|
| 65 | ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
|
---|
| 66 | ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event)"' +
|
---|
| 67 | '></div>';
|
---|
| 68 | }
|
---|
| 69 | }, editor, null, 100 );
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | } );
|
---|
| 73 |
|
---|
| 74 | /**
|
---|
| 75 | * The minimum editor width, in pixels, when resizing it with the resize handle.
|
---|
| 76 | * @type Number
|
---|
| 77 | * @default 750
|
---|
| 78 | * @example
|
---|
| 79 | * config.resize_minWidth = 500;
|
---|
| 80 | */
|
---|
| 81 | CKEDITOR.config.resize_minWidth = 750;
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
| 84 | * The minimum editor height, in pixels, when resizing it with the resize handle.
|
---|
| 85 | * @type Number
|
---|
| 86 | * @default 250
|
---|
| 87 | * @example
|
---|
| 88 | * config.resize_minHeight = 600;
|
---|
| 89 | */
|
---|
| 90 | CKEDITOR.config.resize_minHeight = 250;
|
---|
| 91 |
|
---|
| 92 | /**
|
---|
| 93 | * The maximum editor width, in pixels, when resizing it with the resize handle.
|
---|
| 94 | * @type Number
|
---|
| 95 | * @default 3000
|
---|
| 96 | * @example
|
---|
| 97 | * config.resize_maxWidth = 750;
|
---|
| 98 | */
|
---|
| 99 | CKEDITOR.config.resize_maxWidth = 3000;
|
---|
| 100 |
|
---|
| 101 | /**
|
---|
| 102 | * The maximum editor height, in pixels, when resizing it with the resize handle.
|
---|
| 103 | * @type Number
|
---|
| 104 | * @default 3000
|
---|
| 105 | * @example
|
---|
| 106 | * config.resize_maxHeight = 600;
|
---|
| 107 | */
|
---|
| 108 | CKEDITOR.config.resize_maxHeight = 3000;
|
---|
| 109 |
|
---|
| 110 | /**
|
---|
| 111 | * Whether to enable the resizing feature. If disabed the resize handler will not be visible.
|
---|
| 112 | * @type Boolean
|
---|
| 113 | * @default true
|
---|
| 114 | * @example
|
---|
| 115 | * config.resize_enabled = false;
|
---|
| 116 | */
|
---|
| 117 | CKEDITOR.config.resize_enabled = true;
|
---|