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