JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
780f319388b09d898b7c323c02c80d5bf2d7d58c
[ckeditor.git] / _source / plugins / resize / plugin.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 CKEDITOR.plugins.add( 'resize',\r
7 {\r
8         init : function( editor )\r
9         {\r
10                 var config = editor.config;\r
11 \r
12                 if ( config.resize_enabled )\r
13                 {\r
14                         var container = null;\r
15                         var origin, startSize;\r
16 \r
17                         function dragHandler( evt )\r
18                         {\r
19                                 var dx = evt.data.$.screenX - origin.x;\r
20                                 var dy = evt.data.$.screenY - origin.y;\r
21                                 var internalWidth = startSize.width + dx * ( editor.lang.dir == 'rtl' ? -1 : 1 );\r
22                                 var internalHeight = startSize.height + dy;\r
23 \r
24                                 editor.resize( Math.max( config.resize_minWidth, Math.min( internalWidth, config.resize_maxWidth ) ),\r
25                                                 Math.max( config.resize_minHeight, Math.min( internalHeight, config.resize_maxHeight ) ) );\r
26                         }\r
27 \r
28                         function dragEndHandler ( evt )\r
29                         {\r
30                                 CKEDITOR.document.removeListener( 'mousemove', dragHandler );\r
31                                 CKEDITOR.document.removeListener( 'mouseup', dragEndHandler );\r
32 \r
33                                 if ( editor.document )\r
34                                 {\r
35                                         editor.document.removeListener( 'mousemove', dragHandler );\r
36                                         editor.document.removeListener( 'mouseup', dragEndHandler );\r
37                                 }\r
38                         }\r
39 \r
40                         var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )\r
41                                 {\r
42                                         if ( !container )\r
43                                                 container = editor.getResizable();\r
44 \r
45                                         startSize = { width : container.$.offsetWidth || 0, height : container.$.offsetHeight || 0 };\r
46                                         origin = { x : $event.screenX, y : $event.screenY };\r
47 \r
48                                         CKEDITOR.document.on( 'mousemove', dragHandler );\r
49                                         CKEDITOR.document.on( 'mouseup', dragEndHandler );\r
50 \r
51                                         if ( editor.document )\r
52                                         {\r
53                                                 editor.document.on( 'mousemove', dragHandler );\r
54                                                 editor.document.on( 'mouseup', dragEndHandler );\r
55                                         }\r
56                                 });\r
57 \r
58                         editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );\r
59 \r
60                         editor.on( 'themeSpace', function( event )\r
61                                 {\r
62                                         if ( event.data.space == 'bottom' )\r
63                                         {\r
64                                                 event.data.html += '<div class="cke_resizer"' +\r
65                                                         ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +\r
66                                                         ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event)"' +\r
67                                                         '></div>';\r
68                                         }\r
69                                 }, editor, null, 100 );\r
70                 }\r
71         }\r
72 } );\r
73 \r
74 /**\r
75  * The minimum editor width, in pixels, when resizing it with the resize handle.\r
76  * @type Number\r
77  * @default 750\r
78  * @example\r
79  * config.resize_minWidth = 500;\r
80  */\r
81 CKEDITOR.config.resize_minWidth = 750;\r
82 \r
83 /**\r
84  * The minimum editor height, in pixels, when resizing it with the resize handle.\r
85  * @type Number\r
86  * @default 250\r
87  * @example\r
88  * config.resize_minHeight = 600;\r
89  */\r
90 CKEDITOR.config.resize_minHeight = 250;\r
91 \r
92 /**\r
93  * The maximum editor width, in pixels, when resizing it with the resize handle.\r
94  * @type Number\r
95  * @default 3000\r
96  * @example\r
97  * config.resize_maxWidth = 750;\r
98  */\r
99 CKEDITOR.config.resize_maxWidth = 3000;\r
100 \r
101 /**\r
102  * The maximum editor height, in pixels, when resizing it with the resize handle.\r
103  * @type Number\r
104  * @default 3000\r
105  * @example\r
106  * config.resize_maxHeight = 600;\r
107  */\r
108 CKEDITOR.config.resize_maxHeight = 3000;\r
109 \r
110 /**\r
111  * Whether to enable the resizing feature. If disabed the resize handler will not be visible.\r
112  * @type Boolean\r
113  * @default true\r
114  * @example\r
115  * config.resize_enabled = false;\r
116  */\r
117 CKEDITOR.config.resize_enabled = true;\r