Resizer.html
17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-resizer-Resizer'>/**
</span> * Applies drag handles to an element or component to make it resizable. The drag handles are inserted into the element
* (or component's element) and positioned absolute.
*
* Textarea and img elements will be wrapped with an additional div because these elements do not support child nodes.
* The original element can be accessed through the originalTarget property.
*
* Here is the list of valid resize handles:
*
* Value Description
* ------ -------------------
* 'n' north
* 's' south
* 'e' east
* 'w' west
* 'nw' northwest
* 'sw' southwest
* 'se' southeast
* 'ne' northeast
* 'all' all
*
* {@img Ext.resizer.Resizer/Ext.resizer.Resizer.png Ext.resizer.Resizer component}
*
* Here's an example showing the creation of a typical Resizer:
*
* Ext.create('Ext.resizer.Resizer', {
* el: 'elToResize',
* handles: 'all',
* minWidth: 200,
* minHeight: 100,
* maxWidth: 500,
* maxHeight: 400,
* pinned: true
* });
*/
Ext.define('Ext.resizer.Resizer', {
mixins: {
observable: 'Ext.util.Observable'
},
uses: ['Ext.resizer.ResizeTracker', 'Ext.Component'],
alternateClassName: 'Ext.Resizable',
handleCls: Ext.baseCSSPrefix + 'resizable-handle',
pinnedCls: Ext.baseCSSPrefix + 'resizable-pinned',
overCls: Ext.baseCSSPrefix + 'resizable-over',
wrapCls: Ext.baseCSSPrefix + 'resizable-wrap',
<span id='Ext-resizer-Resizer-cfg-dynamic'> /**
</span> * @cfg {Boolean} dynamic
* Specify as true to update the {@link #target} (Element or {@link Ext.Component Component}) dynamically during
* dragging. This is `true` by default, but the {@link Ext.Component Component} class passes `false` when it is
* configured as {@link Ext.Component#resizable}.
*
* If specified as `false`, a proxy element is displayed during the resize operation, and the {@link #target} is
* updated on mouseup.
*/
dynamic: true,
<span id='Ext-resizer-Resizer-cfg-handles'> /**
</span> * @cfg {String} handles
* String consisting of the resize handles to display. Defaults to 's e se' for Elements and fixed position
* Components. Defaults to 8 point resizing for floating Components (such as Windows). Specify either `'all'` or any
* of `'n s e w ne nw se sw'`.
*/
handles: 's e se',
<span id='Ext-resizer-Resizer-cfg-height'> /**
</span> * @cfg {Number} height
* Optional. The height to set target to in pixels
*/
height : null,
<span id='Ext-resizer-Resizer-cfg-width'> /**
</span> * @cfg {Number} width
* Optional. The width to set the target to in pixels
*/
width : null,
<span id='Ext-resizer-Resizer-cfg-heightIncrement'> /**
</span> * @cfg {Number} heightIncrement
* The increment to snap the height resize in pixels.
*/
heightIncrement : 0,
<span id='Ext-resizer-Resizer-cfg-widthIncrement'> /**
</span> * @cfg {Number} widthIncrement
* The increment to snap the width resize in pixels.
*/
widthIncrement : 0,
<span id='Ext-resizer-Resizer-cfg-minHeight'> /**
</span> * @cfg {Number} minHeight
* The minimum height for the element
*/
minHeight : 20,
<span id='Ext-resizer-Resizer-cfg-minWidth'> /**
</span> * @cfg {Number} minWidth
* The minimum width for the element
*/
minWidth : 20,
<span id='Ext-resizer-Resizer-cfg-maxHeight'> /**
</span> * @cfg {Number} maxHeight
* The maximum height for the element
*/
maxHeight : 10000,
<span id='Ext-resizer-Resizer-cfg-maxWidth'> /**
</span> * @cfg {Number} maxWidth
* The maximum width for the element
*/
maxWidth : 10000,
<span id='Ext-resizer-Resizer-cfg-pinned'> /**
</span> * @cfg {Boolean} pinned
* True to ensure that the resize handles are always visible, false indicates resizing by cursor changes only
*/
pinned: false,
<span id='Ext-resizer-Resizer-cfg-preserveRatio'> /**
</span> * @cfg {Boolean} preserveRatio
* True to preserve the original ratio between height and width during resize
*/
preserveRatio: false,
<span id='Ext-resizer-Resizer-cfg-transparent'> /**
</span> * @cfg {Boolean} transparent
* True for transparent handles. This is only applied at config time.
*/
transparent: false,
<span id='Ext-resizer-Resizer-cfg-constrainTo'> /**
</span> * @cfg {Ext.Element/Ext.util.Region} constrainTo
* An element, or a {@link Ext.util.Region Region} into which the resize operation must be constrained.
*/
possiblePositions: {
n: 'north',
s: 'south',
e: 'east',
w: 'west',
se: 'southeast',
sw: 'southwest',
nw: 'northwest',
ne: 'northeast'
},
<span id='Ext-resizer-Resizer-cfg-target'> /**
</span> * @cfg {Ext.Element/Ext.Component} target
* The Element or Component to resize.
*/
<span id='Ext-resizer-Resizer-property-el'> /**
</span> * @property {Ext.Element} el
* Outer element for resizing behavior.
*/
constructor: function(config) {
var me = this,
target,
targetEl,
tag,
handles = me.handles,
handleCls,
possibles,
len,
i = 0,
pos,
handleEls = [],
eastWestStyle, style,
box;
me.addEvents(
<span id='Ext-resizer-Resizer-event-beforeresize'> /**
</span> * @event beforeresize
* Fired before resize is allowed. Return false to cancel resize.
* @param {Ext.resizer.Resizer} this
* @param {Number} width The start width
* @param {Number} height The start height
* @param {Ext.EventObject} e The mousedown event
*/
'beforeresize',
<span id='Ext-resizer-Resizer-event-resizedrag'> /**
</span> * @event resizedrag
* Fires during resizing. Return false to cancel resize.
* @param {Ext.resizer.Resizer} this
* @param {Number} width The new width
* @param {Number} height The new height
* @param {Ext.EventObject} e The mousedown event
*/
'resizedrag',
<span id='Ext-resizer-Resizer-event-resize'> /**
</span> * @event resize
* Fired after a resize.
* @param {Ext.resizer.Resizer} this
* @param {Number} width The new width
* @param {Number} height The new height
* @param {Ext.EventObject} e The mouseup event
*/
'resize'
);
if (Ext.isString(config) || Ext.isElement(config) || config.dom) {
target = config;
config = arguments[1] || {};
config.target = target;
}
// will apply config to this
me.mixins.observable.constructor.call(me, config);
// If target is a Component, ensure that we pull the element out.
// Resizer must examine the underlying Element.
target = me.target;
if (target) {
if (target.isComponent) {
me.el = target.getEl();
if (target.minWidth) {
me.minWidth = target.minWidth;
}
if (target.minHeight) {
me.minHeight = target.minHeight;
}
if (target.maxWidth) {
me.maxWidth = target.maxWidth;
}
if (target.maxHeight) {
me.maxHeight = target.maxHeight;
}
if (target.floating) {
if (!me.hasOwnProperty('handles')) {
me.handles = 'n ne e se s sw w nw';
}
}
} else {
me.el = me.target = Ext.get(target);
}
}
// Backwards compatibility with Ext3.x's Resizable which used el as a config.
else {
me.target = me.el = Ext.get(me.el);
}
// Tags like textarea and img cannot
// have children and therefore must
// be wrapped
tag = me.el.dom.tagName.toUpperCase();
if (tag == 'TEXTAREA' || tag == 'IMG' || tag == 'TABLE') {
<span id='Ext-resizer-Resizer-property-originalTarget'> /**
</span> * @property {Ext.Element/Ext.Component} originalTarget
* Reference to the original resize target if the element of the original resize target was a
* {@link Ext.form.field.Field Field}, or an IMG or a TEXTAREA which must be wrapped in a DIV.
*/
me.originalTarget = me.target;
targetEl = me.el;
box = targetEl.getBox();
me.target = me.el = me.el.wrap({
cls: me.wrapCls,
id: me.el.id + '-rzwrap',
style: targetEl.getStyles('margin-top', 'margin-bottom')
});
// Transfer originalTarget's positioning+sizing+margins
me.el.setPositioning(targetEl.getPositioning());
targetEl.clearPositioning();
me.el.setBox(box);
// Position the wrapped element absolute so that it does not stretch the wrapper
targetEl.setStyle('position', 'absolute');
}
// Position the element, this enables us to absolute position
// the handles within this.el
me.el.position();
if (me.pinned) {
me.el.addCls(me.pinnedCls);
}
<span id='Ext-resizer-Resizer-property-resizeTracker'> /**
</span> * @property {Ext.resizer.ResizeTracker} resizeTracker
*/
me.resizeTracker = new Ext.resizer.ResizeTracker({
disabled: me.disabled,
target: me.target,
constrainTo: me.constrainTo,
overCls: me.overCls,
throttle: me.throttle,
originalTarget: me.originalTarget,
delegate: '.' + me.handleCls,
dynamic: me.dynamic,
preserveRatio: me.preserveRatio,
heightIncrement: me.heightIncrement,
widthIncrement: me.widthIncrement,
minHeight: me.minHeight,
maxHeight: me.maxHeight,
minWidth: me.minWidth,
maxWidth: me.maxWidth
});
// Relay the ResizeTracker's superclass events as our own resize events
me.resizeTracker.on({
mousedown: me.onBeforeResize,
drag: me.onResize,
dragend: me.onResizeEnd,
scope: me
});
if (me.handles == 'all') {
me.handles = 'n s e w ne nw se sw';
}
handles = me.handles = me.handles.split(/ |\s*?[,;]\s*?/);
possibles = me.possiblePositions;
len = handles.length;
handleCls = me.handleCls + ' ' + (me.target.isComponent ? (me.target.baseCls + '-handle ') : '') + me.handleCls + '-';
// Needs heighting on IE6!
eastWestStyle = Ext.isIE6 ? ' style="height:' + me.el.getHeight() + 'px"' : '';
for (; i < len; i++){
// if specified and possible, create
if (handles[i] && possibles[handles[i]]) {
pos = possibles[handles[i]];
if (pos === 'east' || pos === 'west') {
style = eastWestStyle;
} else {
style = '';
}
handleEls.push('<div id="' + me.el.id + '-' + pos + '-handle" class="' + handleCls + pos + ' ' + Ext.baseCSSPrefix + 'unselectable"' + style + '></div>');
}
}
Ext.DomHelper.append(me.el, handleEls.join(''));
// store a reference to each handle elelemtn in this.east, this.west, etc
for (i = 0; i < len; i++){
// if specified and possible, create
if (handles[i] && possibles[handles[i]]) {
pos = possibles[handles[i]];
me[pos] = me.el.getById(me.el.id + '-' + pos + '-handle');
me[pos].region = pos;
me[pos].unselectable();
if (me.transparent) {
me[pos].setOpacity(0);
}
}
}
// Constrain within configured maxima
if (Ext.isNumber(me.width)) {
me.width = Ext.Number.constrain(me.width, me.minWidth, me.maxWidth);
}
if (Ext.isNumber(me.height)) {
me.height = Ext.Number.constrain(me.height, me.minHeight, me.maxHeight);
}
// Size the target (and originalTarget)
if (me.width !== null || me.height !== null) {
if (me.originalTarget) {
me.originalTarget.setWidth(me.width);
me.originalTarget.setHeight(me.height);
}
me.resizeTo(me.width, me.height);
}
me.forceHandlesHeight();
},
disable: function() {
this.resizeTracker.disable();
},
enable: function() {
this.resizeTracker.enable();
},
<span id='Ext-resizer-Resizer-method-onBeforeResize'> /**
</span> * @private Relay the Tracker's mousedown event as beforeresize
* @param tracker The Resizer
* @param e The Event
*/
onBeforeResize: function(tracker, e) {
var box = this.el.getBox();
return this.fireEvent('beforeresize', this, box.width, box.height, e);
},
<span id='Ext-resizer-Resizer-method-onResize'> /**
</span> * @private Relay the Tracker's drag event as resizedrag
* @param tracker The Resizer
* @param e The Event
*/
onResize: function(tracker, e) {
var me = this,
box = me.el.getBox();
me.forceHandlesHeight();
return me.fireEvent('resizedrag', me, box.width, box.height, e);
},
<span id='Ext-resizer-Resizer-method-onResizeEnd'> /**
</span> * @private Relay the Tracker's dragend event as resize
* @param tracker The Resizer
* @param e The Event
*/
onResizeEnd: function(tracker, e) {
var me = this,
box = me.el.getBox();
me.forceHandlesHeight();
return me.fireEvent('resize', me, box.width, box.height, e);
},
<span id='Ext-resizer-Resizer-method-resizeTo'> /**
</span> * Perform a manual resize and fires the 'resize' event.
* @param {Number} width
* @param {Number} height
*/
resizeTo : function(width, height) {
var me = this;
me.target.setSize(width, height);
me.fireEvent('resize', me, width, height, null);
},
<span id='Ext-resizer-Resizer-method-getEl'> /**
</span> * Returns the element that was configured with the el or target config property. If a component was configured with
* the target property then this will return the element of this component.
*
* Textarea and img elements will be wrapped with an additional div because these elements do not support child
* nodes. The original element can be accessed through the originalTarget property.
* @return {Ext.Element} element
*/
getEl : function() {
return this.el;
},
<span id='Ext-resizer-Resizer-method-getTarget'> /**
</span> * Returns the element or component that was configured with the target config property.
*
* Textarea and img elements will be wrapped with an additional div because these elements do not support child
* nodes. The original element can be accessed through the originalTarget property.
* @return {Ext.Element/Ext.Component}
*/
getTarget: function() {
return this.target;
},
destroy: function() {
var i = 0,
handles = this.handles,
len = handles.length,
positions = this.possiblePositions;
for (; i < len; i++) {
this[positions[handles[i]]].remove();
}
},
<span id='Ext-resizer-Resizer-method-forceHandlesHeight'> /**
</span> * @private
* Fix IE6 handle height issue.
*/
forceHandlesHeight : function() {
var me = this,
handle;
if (Ext.isIE6) {
handle = me.east;
if (handle) {
handle.setHeight(me.el.getHeight());
}
handle = me.west;
if (handle) {
handle.setHeight(me.el.getHeight());
}
me.el.repaint();
}
}
});
</pre>
</body>
</html>