]> git.immae.eu Git - perso/Immae/Projets/packagist/ludivine-ckeditor-component.git/blame - sources/plugins/resize/plugin.js
Update to 4.7.3
[perso/Immae/Projets/packagist/ludivine-ckeditor-component.git] / sources / plugins / resize / plugin.js
CommitLineData
c63493c8
IB
1/**\r
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.\r
3 * For licensing, see LICENSE.md or http://ckeditor.com/license\r
4 */\r
5\r
6CKEDITOR.plugins.add( 'resize', {\r
7 init: function( editor ) {\r
8 function dragHandler( evt ) {\r
9 var dx = evt.data.$.screenX - origin.x,\r
10 dy = evt.data.$.screenY - origin.y,\r
11 width = startSize.width,\r
12 height = startSize.height,\r
13 internalWidth = width + dx * ( resizeDir == 'rtl' ? -1 : 1 ),\r
14 internalHeight = height + dy;\r
15\r
16 if ( resizeHorizontal )\r
17 width = Math.max( config.resize_minWidth, Math.min( internalWidth, config.resize_maxWidth ) );\r
18\r
19 if ( resizeVertical )\r
20 height = Math.max( config.resize_minHeight, Math.min( internalHeight, config.resize_maxHeight ) );\r
21\r
1794320d 22 // DO NOT impose fixed size with single direction resize. (http://dev.ckeditor.com/ticket/6308)\r
c63493c8
IB
23 editor.resize( resizeHorizontal ? width : null, height );\r
24 }\r
25\r
26 function dragEndHandler() {\r
27 CKEDITOR.document.removeListener( 'mousemove', dragHandler );\r
28 CKEDITOR.document.removeListener( 'mouseup', dragEndHandler );\r
29\r
30 if ( editor.document ) {\r
31 editor.document.removeListener( 'mousemove', dragHandler );\r
32 editor.document.removeListener( 'mouseup', dragEndHandler );\r
33 }\r
34 }\r
35\r
36 var config = editor.config;\r
37 var spaceId = editor.ui.spaceId( 'resizer' );\r
38\r
39 // Resize in the same direction of chrome,\r
1794320d 40 // which is identical to dir of editor element. (http://dev.ckeditor.com/ticket/6614)\r
c63493c8
IB
41 var resizeDir = editor.element ? editor.element.getDirection( 1 ) : 'ltr';\r
42\r
43 !config.resize_dir && ( config.resize_dir = 'vertical' );\r
44 ( config.resize_maxWidth === undefined ) && ( config.resize_maxWidth = 3000 );\r
45 ( config.resize_maxHeight === undefined ) && ( config.resize_maxHeight = 3000 );\r
46 ( config.resize_minWidth === undefined ) && ( config.resize_minWidth = 750 );\r
47 ( config.resize_minHeight === undefined ) && ( config.resize_minHeight = 250 );\r
48\r
49 if ( config.resize_enabled !== false ) {\r
50 var container = null,\r
51 origin, startSize,\r
52 resizeHorizontal = ( config.resize_dir == 'both' || config.resize_dir == 'horizontal' ) && ( config.resize_minWidth != config.resize_maxWidth ),\r
53 resizeVertical = ( config.resize_dir == 'both' || config.resize_dir == 'vertical' ) && ( config.resize_minHeight != config.resize_maxHeight );\r
54\r
55 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event ) {\r
56 if ( !container )\r
57 container = editor.getResizable();\r
58\r
59 startSize = { width: container.$.offsetWidth || 0, height: container.$.offsetHeight || 0 };\r
60 origin = { x: $event.screenX, y: $event.screenY };\r
61\r
62 config.resize_minWidth > startSize.width && ( config.resize_minWidth = startSize.width );\r
63 config.resize_minHeight > startSize.height && ( config.resize_minHeight = startSize.height );\r
64\r
65 CKEDITOR.document.on( 'mousemove', dragHandler );\r
66 CKEDITOR.document.on( 'mouseup', dragEndHandler );\r
67\r
68 if ( editor.document ) {\r
69 editor.document.on( 'mousemove', dragHandler );\r
70 editor.document.on( 'mouseup', dragEndHandler );\r
71 }\r
72\r
73 $event.preventDefault && $event.preventDefault();\r
74 } );\r
75\r
76 editor.on( 'destroy', function() {\r
77 CKEDITOR.tools.removeFunction( mouseDownFn );\r
78 } );\r
79\r
80 editor.on( 'uiSpace', function( event ) {\r
81 if ( event.data.space == 'bottom' ) {\r
82 var direction = '';\r
83 if ( resizeHorizontal && !resizeVertical )\r
84 direction = ' cke_resizer_horizontal';\r
85 if ( !resizeHorizontal && resizeVertical )\r
86 direction = ' cke_resizer_vertical';\r
87\r
88 var resizerHtml =\r
89 '<span' +\r
90 ' id="' + spaceId + '"' +\r
91 ' class="cke_resizer' + direction + ' cke_resizer_' + resizeDir + '"' +\r
92 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.common.resize ) + '"' +\r
93 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event)"' +\r
94 '>' +\r
95 // BLACK LOWER RIGHT TRIANGLE (ltr)\r
96 // BLACK LOWER LEFT TRIANGLE (rtl)\r
97 ( resizeDir == 'ltr' ? '\u25E2' : '\u25E3' ) +\r
98 '</span>';\r
99\r
100 // Always sticks the corner of botttom space.\r
101 resizeDir == 'ltr' && direction == 'ltr' ? event.data.html += resizerHtml : event.data.html = resizerHtml + event.data.html;\r
102 }\r
103 }, editor, null, 100 );\r
104\r
105 // Toggle the visibility of the resizer when an editor is being maximized or minimized.\r
106 editor.on( 'maximize', function( event ) {\r
107 editor.ui.space( 'resizer' )[ event.data == CKEDITOR.TRISTATE_ON ? 'hide' : 'show' ]();\r
108 } );\r
109 }\r
110 }\r
111} );\r
112\r
113/**\r
114 * The minimum editor width, in pixels, when resizing the editor interface by using the resize handle.\r
115 * Note: It falls back to editor's actual width if it is smaller than the default value.\r
116 *\r
117 * Read more in the [documentation](#!/guide/dev_resize)\r
118 * and see the [SDK sample](http://sdk.ckeditor.com/samples/resize.html).\r
119 *\r
120 * config.resize_minWidth = 500;\r
121 *\r
122 * @cfg {Number} [resize_minWidth=750]\r
123 * @member CKEDITOR.config\r
124 */\r
125\r
126/**\r
127 * The minimum editor height, in pixels, when resizing the editor interface by using the resize handle.\r
128 * Note: It falls back to editor's actual height if it is smaller than the default value.\r
129 *\r
130 * Read more in the [documentation](#!/guide/dev_resize)\r
131 * and see the [SDK sample](http://sdk.ckeditor.com/samples/resize.html).\r
132 *\r
133 * config.resize_minHeight = 600;\r
134 *\r
135 * @cfg {Number} [resize_minHeight=250]\r
136 * @member CKEDITOR.config\r
137 */\r
138\r
139/**\r
140 * The maximum editor width, in pixels, when resizing the editor interface by using the resize handle.\r
141 *\r
142 * Read more in the [documentation](#!/guide/dev_resize)\r
143 * and see the [SDK sample](http://sdk.ckeditor.com/samples/resize.html).\r
144 *\r
145 * config.resize_maxWidth = 750;\r
146 *\r
147 * @cfg {Number} [resize_maxWidth=3000]\r
148 * @member CKEDITOR.config\r
149 */\r
150\r
151/**\r
152 * The maximum editor height, in pixels, when resizing the editor interface by using the resize handle.\r
153 *\r
154 * Read more in the [documentation](#!/guide/dev_resize)\r
155 * and see the [SDK sample](http://sdk.ckeditor.com/samples/resize.html).\r
156 *\r
157 * config.resize_maxHeight = 600;\r
158 *\r
159 * @cfg {Number} [resize_maxHeight=3000]\r
160 * @member CKEDITOR.config\r
161 */\r
162\r
163/**\r
164 * Whether to enable the resizing feature. If this feature is disabled, the resize handle will not be visible.\r
165 *\r
166 * Read more in the [documentation](#!/guide/dev_resize)\r
167 * and see the [SDK sample](http://sdk.ckeditor.com/samples/resize.html).\r
168 *\r
169 * config.resize_enabled = false;\r
170 *\r
171 * @cfg {Boolean} [resize_enabled=true]\r
172 * @member CKEDITOR.config\r
173 */\r
174\r
175/**\r
176 * The dimensions for which the editor resizing is enabled. Possible values\r
177 * are `both`, `vertical`, and `horizontal`.\r
178 *\r
179 * Read more in the [documentation](#!/guide/dev_resize)\r
180 * and see the [SDK sample](http://sdk.ckeditor.com/samples/resize.html).\r
181 *\r
182 * config.resize_dir = 'both';\r
183 *\r
184 * @since 3.3\r
185 * @cfg {String} [resize_dir='vertical']\r
186 * @member CKEDITOR.config\r
187 */\r