3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('resize-base', function(Y) {
10
* The Resize Utility allows you to make an HTML element resizable.
16
isArray = Lang.isArray,
17
isBoolean = Lang.isBoolean,
18
isNumber = Lang.isNumber,
19
isString = Lang.isString,
23
indexOf = YArray.indexOf,
28
HANDLE_SUB = '{handle}',
32
ACTIVE_HANDLE = 'activeHandle',
33
ACTIVE_HANDLE_NODE = 'activeHandleNode',
35
AUTO_HIDE = 'autoHide',
38
CLASS_NAME = 'className',
40
DEF_MIN_HEIGHT = 'defMinHeight',
41
DEF_MIN_WIDTH = 'defMinWidth',
44
HANDLES_WRAPPER = 'handlesWrapper',
50
NODE_NAME = 'nodeName',
52
OFFSET_HEIGHT = 'offsetHeight',
53
OFFSET_WIDTH = 'offsetWidth',
55
PARENT_NODE = 'parentNode',
56
POSITION = 'position',
57
RELATIVE = 'relative',
59
RESIZING = 'resizing',
67
WRAP_TYPES = 'wrapTypes',
69
EV_MOUSE_UP = 'resize:mouseUp',
70
EV_RESIZE = 'resize:resize',
71
EV_RESIZE_ALIGN = 'resize:align',
72
EV_RESIZE_END = 'resize:end',
73
EV_RESIZE_START = 'resize:start',
85
return Array.prototype.slice.call(arguments).join(SPACE);
88
// round the passed number to get rid of pixel-flickering
89
toRoundNumber = function(num) {
90
return Math.round(parseFloat(num)) || 0;
93
getCompStyle = function(node, val) {
94
return node.getComputedStyle(val);
97
handleAttrName = function(handle) {
98
return HANDLE + handle.toUpperCase();
101
isNode = function(v) {
102
return (v instanceof Y.Node);
105
toInitialCap = Y.cached(
107
return str.substring(0, 1).toUpperCase() + str.substring(1);
111
capitalize = Y.cached(function() {
113
args = YArray(arguments, 0, true);
115
YArray.each(args, function(part, i) {
117
part = toInitialCap(part);
122
return out.join(EMPTY_STR);
125
getCN = Y.ClassNameManager.getClassName,
127
CSS_RESIZE = getCN(RESIZE),
128
CSS_RESIZE_HANDLE = getCN(RESIZE, HANDLE),
129
CSS_RESIZE_HANDLE_ACTIVE = getCN(RESIZE, HANDLE, ACTIVE),
130
CSS_RESIZE_HANDLE_INNER = getCN(RESIZE, HANDLE, INNER),
131
CSS_RESIZE_HANDLE_INNER_PLACEHOLDER = getCN(RESIZE, HANDLE, INNER, HANDLE_SUB),
132
CSS_RESIZE_HANDLE_PLACEHOLDER = getCN(RESIZE, HANDLE, HANDLE_SUB),
133
CSS_RESIZE_HIDDEN_HANDLES = getCN(RESIZE, HIDDEN, HANDLES),
134
CSS_RESIZE_HANDLES_WRAPPER = getCN(RESIZE, HANDLES, WRAPPER),
135
CSS_RESIZE_WRAPPER = getCN(RESIZE, WRAPPER);
138
A base class for Resize, providing:
140
* Basic Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)
141
* Applies drag handles to an element to make it resizable
142
* Here is the list of valid resize handles:
143
`[ 't', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl' ]`. You can
144
read this list as top, top-right, right, bottom-right, bottom,
145
bottom-left, left, top-left.
146
* The drag handles are inserted into the element and positioned
147
absolute. Some elements, such as a textarea or image, don't support
148
children. To overcome that, set wrap:true in your config and the
149
element willbe wrapped for you automatically.
153
var instance = new Y.Resize({
159
handles: 't, tr, r, br, b, bl, l, tl'
162
Check the list of <a href="Resize.html#configattributes">Configuration Attributes</a> available for
166
@param config {Object} Object literal specifying widget configuration properties.
172
Resize.superclass.constructor.apply(this, arguments);
177
* Static property provides a string to identify the class.
186
* Static property used to define the default attribute
187
* configuration for the Resize.
195
* Stores the active handle during the resize.
197
* @attribute activeHandle
204
validator: function(v) {
205
return Y.Lang.isString(v) || Y.Lang.isNull(v);
210
* Stores the active handle element during the resize.
212
* @attribute activeHandleNode
223
* False to ensure that the resize handles are always visible, true to
224
* display them only when the user mouses over the resizable borders.
226
* @attribute autoHide
236
* The default minimum height of the element. Only used when
237
* ResizeConstrained is not plugged.
239
* @attribute defMinHeight
249
* The default minimum width of the element. Only used when
250
* ResizeConstrained is not plugged.
252
* @attribute defMinWidth
262
* The handles to use (any combination of): 't', 'b', 'r', 'l', 'bl',
263
* 'br', 'tl', 'tr'. Can use a shortcut of All.
267
* @type Array | String
270
setter: '_setHandles',
275
* Node to wrap the resize handles.
277
* @attribute handlesWrapper
283
valueFn: '_valueHandlesWrapper'
287
* The selector or element to resize. Required.
297
* True when the element is being Resized.
299
* @attribute resizing
309
* True to wrap an element with a div if needed (required for textareas
310
* and images, defaults to false) in favor of the handles config option.
311
* The wrapper element type (default div) could be over-riden passing the
312
* <code>wrapper</code> attribute.
325
* Elements that requires a wrapper by default. Normally are elements
326
* which cannot have children elements.
328
* @attribute wrapTypes
329
* @default /canvas|textarea|input|select|button|img/i
335
value: /^canvas|textarea|input|select|button|img|iframe|table|embed$/i
339
* Element to wrap the <code>wrapTypes</code>. This element will house
340
* the handles elements.
344
* @type String | Node
349
valueFn: '_valueWrapper',
355
b: function(instance, dx, dy) {
356
var info = instance.info,
357
originalInfo = instance.originalInfo;
359
info.offsetHeight = originalInfo.offsetHeight + dy;
362
l: function(instance, dx, dy) {
363
var info = instance.info,
364
originalInfo = instance.originalInfo;
366
info.left = originalInfo.left + dx;
367
info.offsetWidth = originalInfo.offsetWidth - dx;
370
r: function(instance, dx, dy) {
371
var info = instance.info,
372
originalInfo = instance.originalInfo;
374
info.offsetWidth = originalInfo.offsetWidth + dx;
377
t: function(instance, dx, dy) {
378
var info = instance.info,
379
originalInfo = instance.originalInfo;
381
info.top = originalInfo.top + dy;
382
info.offsetHeight = originalInfo.offsetHeight - dy;
385
tr: function(instance, dx, dy) {
386
this.t.apply(this, arguments);
387
this.r.apply(this, arguments);
390
bl: function(instance, dx, dy) {
391
this.b.apply(this, arguments);
392
this.l.apply(this, arguments);
395
br: function(instance, dx, dy) {
396
this.b.apply(this, arguments);
397
this.r.apply(this, arguments);
400
tl: function(instance, dx, dy) {
401
this.t.apply(this, arguments);
402
this.l.apply(this, arguments);
406
capitalize: capitalize
414
* Array containing all possible resizable handles.
416
* @property ALL_HANDLES
419
ALL_HANDLES: [ T, TR, R, BR, B, BL, L, TL ],
422
* Regex which matches with the handles that could change the height of
423
* the resizable element.
425
* @property REGEX_CHANGE_HEIGHT
428
REGEX_CHANGE_HEIGHT: /^(t|tr|b|bl|br|tl)$/i,
431
* Regex which matches with the handles that could change the left of
432
* the resizable element.
434
* @property REGEX_CHANGE_LEFT
437
REGEX_CHANGE_LEFT: /^(tl|l|bl)$/i,
440
* Regex which matches with the handles that could change the top of
441
* the resizable element.
443
* @property REGEX_CHANGE_TOP
446
REGEX_CHANGE_TOP: /^(tl|t|tr)$/i,
449
* Regex which matches with the handles that could change the width of
450
* the resizable element.
452
* @property REGEX_CHANGE_WIDTH
455
REGEX_CHANGE_WIDTH: /^(bl|br|l|r|tl|tr)$/i,
458
* Template used to create the resize wrapper for the handles.
460
* @property HANDLES_WRAP_TEMPLATE
463
HANDLES_WRAP_TEMPLATE: '<div class="'+CSS_RESIZE_HANDLES_WRAPPER+'"></div>',
466
* Template used to create the resize wrapper node when needed.
468
* @property WRAP_TEMPLATE
471
WRAP_TEMPLATE: '<div class="'+CSS_RESIZE_WRAPPER+'"></div>',
474
* Template used to create each resize handle.
476
* @property HANDLE_TEMPLATE
479
HANDLE_TEMPLATE: '<div class="'+concat(CSS_RESIZE_HANDLE, CSS_RESIZE_HANDLE_PLACEHOLDER)+'">' +
480
'<div class="'+concat(CSS_RESIZE_HANDLE_INNER, CSS_RESIZE_HANDLE_INNER_PLACEHOLDER)+'"> </div>' +
485
* Each box has a content area and optional surrounding padding and
486
* border areas. This property stores the sum of all horizontal
487
* surrounding * information needed to adjust the node height.
489
* @property totalHSurrounding
493
totalHSurrounding: 0,
496
* Each box has a content area and optional surrounding padding and
497
* border areas. This property stores the sum of all vertical
498
* surrounding * information needed to adjust the node height.
500
* @property totalVSurrounding
504
totalVSurrounding: 0,
507
* Stores the <a href="Resize.html#config_node">node</a>
508
* surrounding information retrieved from
509
* <a href="Resize.html#method__getBoxSurroundingInfo">_getBoxSurroundingInfo</a>.
511
* @property nodeSurrounding
515
nodeSurrounding: null,
518
* Stores the <a href="Resize.html#config_wrapper">wrapper</a>
519
* surrounding information retrieved from
520
* <a href="Resize.html#method__getBoxSurroundingInfo">_getBoxSurroundingInfo</a>.
522
* @property wrapperSurrounding
526
wrapperSurrounding: null,
529
* Whether the handle being dragged can change the height.
531
* @property changeHeightHandles
535
changeHeightHandles: false,
538
* Whether the handle being dragged can change the left.
540
* @property changeLeftHandles
544
changeLeftHandles: false,
547
* Whether the handle being dragged can change the top.
549
* @property changeTopHandles
553
changeTopHandles: false,
556
* Whether the handle being dragged can change the width.
558
* @property changeWidthHandles
562
changeWidthHandles: false,
565
* Store DD.Delegate reference for the respective Resize instance.
574
* Stores the current values for the height, width, top and left. You are
575
* able to manipulate these values on resize in order to change the resize
585
* Stores the last values for the height, width, top and left.
594
* Stores the original values for the height, width, top and left, stored
597
* @property originalInfo
604
* Construction logic executed during Resize instantiation. Lifecycle.
606
* @method initializer
609
initializer: function() {
614
* Create the DOM structure for the Resize. Lifecycle.
619
renderUI: function() {
622
instance._renderHandles();
626
* Bind the events on the Resize UI. Lifecycle.
634
instance._createEvents();
636
instance._bindHandle();
640
* Sync the Resize UI.
648
this.get(NODE).addClass(CSS_RESIZE);
650
// hide handles if AUTO_HIDE is true
651
instance._setHideHandlesUI(
652
instance.get(AUTO_HIDE)
657
* Descructor lifecycle implementation for the Resize class. Purges events attached
658
* to the node (and all child nodes) and removes the Resize handles.
663
destructor: function() {
665
node = instance.get(NODE),
666
wrapper = instance.get(WRAPPER),
667
pNode = wrapper.get(PARENT_NODE);
669
// purgeElements on boundingBox
670
Y.Event.purgeElement(wrapper, true);
672
// destroy handles dd and remove them from the dom
673
instance.eachHandle(function(handleEl) {
674
instance.delegate.dd.destroy();
677
handleEl.remove(true);
681
if (instance.get(WRAP)) {
682
instance._copyStyles(wrapper, node);
685
pNode.insertBefore(node, wrapper);
688
wrapper.remove(true);
691
node.removeClass(CSS_RESIZE);
692
node.removeClass(CSS_RESIZE_HIDDEN_HANDLES);
696
* Creates DOM (or manipulates DOM for progressive enhancement)
697
* This method is invoked by initializer(). It's chained automatically for
698
* subclasses if required.
703
renderer: function() {
710
* <p>Loop through each handle which is being used and executes a callback.</p>
712
* <pre><code>instance.eachHandle(
713
* function(handleName, index) { ... }
717
* @param {function} fn Callback function to be executed for each handle.
719
eachHandle: function(fn) {
723
instance.get(HANDLES),
724
function(handle, i) {
725
var handleEl = instance.get(
726
handleAttrName(handle)
729
fn.apply(instance, [handleEl, handle, i]);
735
* Bind the handles DragDrop events to the Resize instance.
740
_bindDD: function() {
743
instance.delegate = new Y.DD.Delegate(
745
bubbleTargets: instance,
746
container: instance.get(HANDLES_WRAPPER),
753
nodes: DOT+CSS_RESIZE_HANDLE,
758
instance.on('drag:drag', instance._handleResizeEvent);
759
instance.on('drag:dropmiss', instance._handleMouseUpEvent);
760
instance.on('drag:end', instance._handleResizeEndEvent);
761
instance.on('drag:start', instance._handleResizeStartEvent);
765
* Bind the events related to the handles (_onHandleMouseEnter, _onHandleMouseLeave).
767
* @method _bindHandle
770
_bindHandle: function() {
772
wrapper = instance.get(WRAPPER);
774
wrapper.on('mouseenter', Y.bind(instance._onWrapperMouseEnter, instance));
775
wrapper.on('mouseleave', Y.bind(instance._onWrapperMouseLeave, instance));
776
wrapper.delegate('mouseenter', Y.bind(instance._onHandleMouseEnter, instance), DOT+CSS_RESIZE_HANDLE);
777
wrapper.delegate('mouseleave', Y.bind(instance._onHandleMouseLeave, instance), DOT+CSS_RESIZE_HANDLE);
781
* Create the custom events used on the Resize.
783
* @method _createEvents
786
_createEvents: function() {
788
// create publish function for kweight optimization
789
publish = function(name, fn) {
790
instance.publish(name, {
800
* Handles the resize start event. Fired when a handle starts to be
803
* @event resize:start
804
* @preventable _defResizeStartFn
805
* @param {Event.Facade} event The resize start event.
807
* @type {Event.Custom}
809
publish(EV_RESIZE_START, this._defResizeStartFn);
812
* Handles the resize event. Fired on each pixel when the handle is
815
* @event resize:resize
816
* @preventable _defResizeFn
817
* @param {Event.Facade} event The resize event.
819
* @type {Event.Custom}
821
publish(EV_RESIZE, this._defResizeFn);
824
* Handles the resize align event.
826
* @event resize:align
827
* @preventable _defResizeAlignFn
828
* @param {Event.Facade} event The resize align event.
830
* @type {Event.Custom}
832
publish(EV_RESIZE_ALIGN, this._defResizeAlignFn);
835
* Handles the resize end event. Fired when a handle stop to be
839
* @preventable _defResizeEndFn
840
* @param {Event.Facade} event The resize end event.
842
* @type {Event.Custom}
844
publish(EV_RESIZE_END, this._defResizeEndFn);
847
* Handles the resize mouseUp event. Fired when a mouseUp event happens on a
850
* @event resize:mouseUp
851
* @preventable _defMouseUpFn
852
* @param {Event.Facade} event The resize mouseUp event.
854
* @type {Event.Custom}
856
publish(EV_MOUSE_UP, this._defMouseUpFn);
860
* Responsible for loop each handle element and append to the wrapper.
862
* @method _renderHandles
865
_renderHandles: function() {
867
wrapper = instance.get(WRAPPER),
868
handlesWrapper = instance.get(HANDLES_WRAPPER);
870
instance.eachHandle(function(handleEl) {
871
handlesWrapper.append(handleEl);
874
wrapper.append(handlesWrapper);
878
* Creates the handle element based on the handle name and initialize the
881
* @method _buildHandle
882
* @param {String} handle Handle name ('t', 'tr', 'b', ...).
885
_buildHandle: function(handle) {
888
return Y.Node.create(
889
Y.substitute(instance.HANDLE_TEMPLATE, {
896
* Basic resize calculations.
898
* @method _calcResize
901
_calcResize: function() {
903
handle = instance.handle,
904
info = instance.info,
905
originalInfo = instance.originalInfo,
907
dx = info.actXY[0] - originalInfo.actXY[0],
908
dy = info.actXY[1] - originalInfo.actXY[1];
910
if (handle && Y.Resize.RULES[handle]) {
911
Y.Resize.RULES[handle](instance, dx, dy);
918
* Helper method to update the current size value on
919
* <a href="Resize.html#property_info">info</a> to respect the
920
* min/max values and fix the top/left calculations.
923
* @param {String} offset 'offsetHeight' or 'offsetWidth'
924
* @param {number} size Size to restrict the offset
927
_checkSize: function(offset, size) {
929
info = instance.info,
930
originalInfo = instance.originalInfo,
931
axis = (offset == OFFSET_HEIGHT) ? TOP : LEFT;
933
// forcing the offsetHeight/offsetWidth to be the passed size
936
// predicting, based on the original information, the last left valid in case of reach the min/max dimension
937
// this calculation avoid browser event leaks when user interact very fast
938
if (((axis == LEFT) && instance.changeLeftHandles) ||
939
((axis == TOP) && instance.changeTopHandles)) {
941
info[axis] = originalInfo[axis] + originalInfo[offset] - size;
946
* Copy relevant styles of the <a href="Resize.html#config_node">node</a>
947
* to the <a href="Resize.html#config_wrapper">wrapper</a>.
949
* @method _copyStyles
950
* @param {Node} node Node from.
951
* @param {Node} wrapper Node to.
954
_copyStyles: function(node, wrapper) {
955
var position = node.getStyle(POSITION).toLowerCase(),
956
surrounding = this._getBoxSurroundingInfo(node),
959
// resizable wrapper should be positioned
960
if (position == STATIC) {
966
left: getCompStyle(node, LEFT),
967
top: getCompStyle(node, TOP)
970
Y.mix(wrapperStyle, surrounding.margin);
971
Y.mix(wrapperStyle, surrounding.border);
973
wrapper.setStyles(wrapperStyle);
975
// remove margin and border from the internal node
976
node.setStyles({ border: 0, margin: 0 });
979
node.get(OFFSET_WIDTH) + surrounding.totalHBorder,
980
node.get(OFFSET_HEIGHT) + surrounding.totalVBorder
984
// extract handle name from a string
985
// using Y.cached to memoize the function for performance
986
_extractHandleName: Y.cached(
988
var className = node.get(CLASS_NAME),
990
match = className.match(
992
getCN(RESIZE, HANDLE, '(\\w{1,2})\\b')
996
return match ? match[1] : null;
1001
* <p>Generates metadata to the <a href="Resize.html#property_info">info</a>
1002
* and <a href="Resize.html#property_originalInfo">originalInfo</a></p>
1003
* <pre><code>bottom, actXY, left, top, offsetHeight, offsetWidth, right</code></pre>
1006
* @param {Node} node
1007
* @param {EventFacade} event
1010
_getInfo: function(node, event) {
1012
drag = event.dragEvent.target,
1013
nodeXY = node.getXY(),
1016
offsetHeight = node.get(OFFSET_HEIGHT),
1017
offsetWidth = node.get(OFFSET_WIDTH);
1020
// the xy that the node will be set to. Changing this will alter the position as it's dragged.
1021
actXY = (drag.actXY.length ? drag.actXY : drag.lastXY);
1026
bottom: (nodeY + offsetHeight),
1028
offsetHeight: offsetHeight,
1029
offsetWidth: offsetWidth,
1030
right: (nodeX + offsetWidth),
1036
* Each box has a content area and optional surrounding margin,
1037
* padding and * border areas. This method get all this information from
1038
* the passed node. For more reference see
1039
* <a href="http://www.w3.org/TR/CSS21/box.html#box-dimensions">
1040
* http://www.w3.org/TR/CSS21/box.html#box-dimensions</a>.
1042
* @method _getBoxSurroundingInfo
1043
* @param {Node} node
1047
_getBoxSurroundingInfo: function(node) {
1055
Y.each([ TOP, RIGHT, BOTTOM, LEFT ], function(dir) {
1056
var paddingProperty = capitalize(PADDING, dir),
1057
marginProperty = capitalize(MARGIN, dir),
1058
borderWidthProperty = capitalize(BORDER, dir, WIDTH),
1059
borderColorProperty = capitalize(BORDER, dir, COLOR),
1060
borderStyleProperty = capitalize(BORDER, dir, STYLE);
1062
info.border[borderColorProperty] = getCompStyle(node, borderColorProperty);
1063
info.border[borderStyleProperty] = getCompStyle(node, borderStyleProperty);
1064
info.border[borderWidthProperty] = getCompStyle(node, borderWidthProperty);
1065
info.margin[marginProperty] = getCompStyle(node, marginProperty);
1066
info.padding[paddingProperty] = getCompStyle(node, paddingProperty);
1070
info.totalHBorder = (toRoundNumber(info.border.borderLeftWidth) + toRoundNumber(info.border.borderRightWidth));
1071
info.totalHPadding = (toRoundNumber(info.padding.paddingLeft) + toRoundNumber(info.padding.paddingRight));
1072
info.totalVBorder = (toRoundNumber(info.border.borderBottomWidth) + toRoundNumber(info.border.borderTopWidth));
1073
info.totalVPadding = (toRoundNumber(info.padding.paddingBottom) + toRoundNumber(info.padding.paddingTop));
1079
* Sync the Resize UI with internal values from
1080
* <a href="Resize.html#property_info">info</a>.
1085
_syncUI: function() {
1086
var instance = this,
1087
info = instance.info,
1088
wrapperSurrounding = instance.wrapperSurrounding,
1089
wrapper = instance.get(WRAPPER),
1090
node = instance.get(NODE);
1092
wrapper.sizeTo(info.offsetWidth, info.offsetHeight);
1094
if (instance.changeLeftHandles || instance.changeTopHandles) {
1095
wrapper.setXY([info.left, info.top]);
1098
// if a wrap node is being used
1099
if (!wrapper.compareTo(node)) {
1100
// the original internal node borders were copied to the wrapper on _copyStyles, to compensate that subtract the borders from the internal node
1102
info.offsetWidth - wrapperSurrounding.totalHBorder,
1103
info.offsetHeight - wrapperSurrounding.totalVBorder
1107
// prevent webkit textarea resize
1109
node.setStyle(RESIZE, NONE);
1114
* Update <code>instance.changeHeightHandles,
1115
* instance.changeLeftHandles, instance.changeTopHandles,
1116
* instance.changeWidthHandles</code> information.
1118
* @method _updateChangeHandleInfo
1121
_updateChangeHandleInfo: function(handle) {
1122
var instance = this;
1124
instance.changeHeightHandles = instance.REGEX_CHANGE_HEIGHT.test(handle);
1125
instance.changeLeftHandles = instance.REGEX_CHANGE_LEFT.test(handle);
1126
instance.changeTopHandles = instance.REGEX_CHANGE_TOP.test(handle);
1127
instance.changeWidthHandles = instance.REGEX_CHANGE_WIDTH.test(handle);
1131
* Update <a href="Resize.html#property_info">info</a> values (bottom, actXY, left, top, offsetHeight, offsetWidth, right).
1133
* @method _updateInfo
1136
_updateInfo: function(event) {
1137
var instance = this;
1139
instance.info = instance._getInfo(instance.get(WRAPPER), event);
1144
* <a href="Resize.html#property_nodeSurrounding">nodeSurrounding</a>,
1145
* <a href="Resize.html#property_nodeSurrounding">wrapperSurrounding</a>,
1146
* <a href="Resize.html#property_nodeSurrounding">totalVSurrounding</a>,
1147
* <a href="Resize.html#property_nodeSurrounding">totalHSurrounding</a>.
1149
* @method _updateSurroundingInfo
1152
_updateSurroundingInfo: function() {
1153
var instance = this,
1154
node = instance.get(NODE),
1155
wrapper = instance.get(WRAPPER),
1156
nodeSurrounding = instance._getBoxSurroundingInfo(node),
1157
wrapperSurrounding = instance._getBoxSurroundingInfo(wrapper);
1159
instance.nodeSurrounding = nodeSurrounding;
1160
instance.wrapperSurrounding = wrapperSurrounding;
1162
instance.totalVSurrounding = (nodeSurrounding.totalVPadding + wrapperSurrounding.totalVBorder);
1163
instance.totalHSurrounding = (nodeSurrounding.totalHPadding + wrapperSurrounding.totalHBorder);
1167
* Set the active state of the handles.
1169
* @method _setActiveHandlesUI
1170
* @param {boolean} val True to activate the handles, false to deactivate.
1173
_setActiveHandlesUI: function(val) {
1174
var instance = this,
1175
activeHandleNode = instance.get(ACTIVE_HANDLE_NODE);
1177
if (activeHandleNode) {
1179
// remove CSS_RESIZE_HANDLE_ACTIVE from all handles before addClass on the active
1180
instance.eachHandle(
1181
function(handleEl) {
1182
handleEl.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1186
activeHandleNode.addClass(CSS_RESIZE_HANDLE_ACTIVE);
1189
activeHandleNode.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1195
* Setter for the handles attribute
1197
* @method _setHandles
1199
* @param {String} val
1201
_setHandles: function(val) {
1202
var instance = this,
1205
// handles attr accepts both array or string
1209
else if (isString(val)) {
1210
// if the handles attr passed in is an ALL string...
1211
if (val.toLowerCase() == ALL) {
1212
handles = instance.ALL_HANDLES;
1214
// otherwise, split the string to extract the handles
1219
var handle = trim(node);
1221
// if its a valid handle, add it to the handles output
1222
if (indexOf(instance.ALL_HANDLES, handle) > -1) {
1223
handles.push(handle);
1234
* Set the visibility of the handles.
1236
* @method _setHideHandlesUI
1237
* @param {boolean} val True to hide the handles, false to show.
1240
_setHideHandlesUI: function(val) {
1241
var instance = this,
1242
wrapper = instance.get(WRAPPER);
1244
if (!instance.get(RESIZING)) {
1246
wrapper.addClass(CSS_RESIZE_HIDDEN_HANDLES);
1249
wrapper.removeClass(CSS_RESIZE_HIDDEN_HANDLES);
1255
* Setter for the wrap attribute
1259
* @param {boolean} val
1261
_setWrap: function(val) {
1262
var instance = this,
1263
node = instance.get(NODE),
1264
nodeName = node.get(NODE_NAME),
1265
typeRegex = instance.get(WRAP_TYPES);
1267
// if nodeName is listed on WRAP_TYPES force use the wrapper
1268
if (typeRegex.test(nodeName)) {
1276
* Default resize:mouseUp handler
1278
* @method _defMouseUpFn
1279
* @param {EventFacade} event The Event object
1282
_defMouseUpFn: function(event) {
1283
var instance = this;
1285
instance.set(RESIZING, false);
1289
* Default resize:resize handler
1291
* @method _defResizeFn
1292
* @param {EventFacade} event The Event object
1295
_defResizeFn: function(event) {
1296
var instance = this;
1298
instance._resize(event);
1302
* Logic method for _defResizeFn. Allow AOP.
1305
* @param {EventFacade} event The Event object
1308
_resize: function(event) {
1309
var instance = this;
1311
instance._handleResizeAlignEvent(event.dragEvent);
1313
// _syncUI of the wrapper, not using proxy
1318
* Default resize:align handler
1320
* @method _defResizeAlignFn
1321
* @param {EventFacade} event The Event object
1324
_defResizeAlignFn: function(event) {
1325
var instance = this;
1327
instance._resizeAlign(event);
1331
* Logic method for _defResizeAlignFn. Allow AOP.
1333
* @method _resizeAlign
1334
* @param {EventFacade} event The Event object
1337
_resizeAlign: function(event) {
1338
var instance = this,
1343
instance.lastInfo = instance.info;
1345
// update the instance.info values
1346
instance._updateInfo(event);
1348
info = instance.info;
1350
// basic resize calculations
1351
instance._calcResize();
1353
// if Y.Plugin.ResizeConstrained is not plugged, check for min dimension
1354
if (!instance.con) {
1355
defMinHeight = (instance.get(DEF_MIN_HEIGHT) + instance.totalVSurrounding);
1356
defMinWidth = (instance.get(DEF_MIN_WIDTH) + instance.totalHSurrounding);
1358
if (info.offsetHeight <= defMinHeight) {
1359
instance._checkSize(OFFSET_HEIGHT, defMinHeight);
1362
if (info.offsetWidth <= defMinWidth) {
1363
instance._checkSize(OFFSET_WIDTH, defMinWidth);
1369
* Default resize:end handler
1371
* @method _defResizeEndFn
1372
* @param {EventFacade} event The Event object
1375
_defResizeEndFn: function(event) {
1376
var instance = this;
1378
instance._resizeEnd(event);
1382
* Logic method for _defResizeEndFn. Allow AOP.
1384
* @method _resizeEnd
1385
* @param {EventFacade} event The Event object
1388
_resizeEnd: function(event) {
1389
var instance = this,
1390
drag = event.dragEvent.target;
1392
// reseting actXY from drag when drag end
1395
// syncUI when resize end
1398
instance._setActiveHandlesUI(false);
1400
instance.set(ACTIVE_HANDLE, null);
1401
instance.set(ACTIVE_HANDLE_NODE, null);
1403
instance.handle = null;
1407
* Default resize:start handler
1409
* @method _defResizeStartFn
1410
* @param {EventFacade} event The Event object
1413
_defResizeStartFn: function(event) {
1414
var instance = this;
1416
instance._resizeStart(event);
1420
* Logic method for _defResizeStartFn. Allow AOP.
1422
* @method _resizeStart
1423
* @param {EventFacade} event The Event object
1426
_resizeStart: function(event) {
1427
var instance = this,
1428
wrapper = instance.get(WRAPPER);
1430
instance.handle = instance.get(ACTIVE_HANDLE);
1432
instance.set(RESIZING, true);
1434
instance._updateSurroundingInfo();
1436
// create an originalInfo information for reference
1437
instance.originalInfo = instance._getInfo(wrapper, event);
1439
instance._updateInfo(event);
1443
* Fires the resize:mouseUp event.
1445
* @method _handleMouseUpEvent
1446
* @param {EventFacade} event resize:mouseUp event facade
1449
_handleMouseUpEvent: function(event) {
1450
this.fire(EV_MOUSE_UP, { dragEvent: event, info: this.info });
1454
* Fires the resize:resize event.
1456
* @method _handleResizeEvent
1457
* @param {EventFacade} event resize:resize event facade
1460
_handleResizeEvent: function(event) {
1461
this.fire(EV_RESIZE, { dragEvent: event, info: this.info });
1465
* Fires the resize:align event.
1467
* @method _handleResizeAlignEvent
1468
* @param {EventFacade} event resize:resize event facade
1471
_handleResizeAlignEvent: function(event) {
1472
this.fire(EV_RESIZE_ALIGN, { dragEvent: event, info: this.info });
1476
* Fires the resize:end event.
1478
* @method _handleResizeEndEvent
1479
* @param {EventFacade} event resize:end event facade
1482
_handleResizeEndEvent: function(event) {
1483
this.fire(EV_RESIZE_END, { dragEvent: event, info: this.info });
1487
* Fires the resize:start event.
1489
* @method _handleResizeStartEvent
1490
* @param {EventFacade} event resize:start event facade
1493
_handleResizeStartEvent: function(event) {
1494
if (!this.get(ACTIVE_HANDLE)) {
1495
//This handles the "touch" case
1496
this._setHandleFromNode(event.target.get('node'));
1498
this.fire(EV_RESIZE_START, { dragEvent: event, info: this.info });
1502
* Mouseenter event handler for the <a href="Resize.html#config_wrapper">wrapper</a>.
1504
* @method _onWrapperMouseEnter
1505
* @param {EventFacade} event
1508
_onWrapperMouseEnter: function(event) {
1509
var instance = this;
1511
if (instance.get(AUTO_HIDE)) {
1512
instance._setHideHandlesUI(false);
1517
* Mouseleave event handler for the <a href="Resize.html#config_wrapper">wrapper</a>.
1519
* @method _onWrapperMouseLeave
1520
* @param {EventFacade} event
1523
_onWrapperMouseLeave: function(event) {
1524
var instance = this;
1526
if (instance.get(AUTO_HIDE)) {
1527
instance._setHideHandlesUI(true);
1532
* Handles setting the activeHandle from a node, used from startDrag (for touch) and mouseenter (for mouse).
1534
* @method _setHandleFromNode
1535
* @param {Node} node
1538
_setHandleFromNode: function(node) {
1539
var instance = this,
1540
handle = instance._extractHandleName(node);
1542
if (!instance.get(RESIZING)) {
1543
instance.set(ACTIVE_HANDLE, handle);
1544
instance.set(ACTIVE_HANDLE_NODE, node);
1546
instance._setActiveHandlesUI(true);
1547
instance._updateChangeHandleInfo(handle);
1552
* Mouseenter event handler for the handles.
1554
* @method _onHandleMouseEnter
1555
* @param {EventFacade} event
1558
_onHandleMouseEnter: function(event) {
1559
this._setHandleFromNode(event.currentTarget);
1563
* Mouseout event handler for the handles.
1565
* @method _onHandleMouseLeave
1566
* @param {EventFacade} event
1569
_onHandleMouseLeave: function(event) {
1570
var instance = this;
1572
if (!instance.get(RESIZING)) {
1573
instance._setActiveHandlesUI(false);
1578
* Default value for the wrapper handles node attribute
1580
* @method _valueHandlesWrapper
1584
_valueHandlesWrapper: function() {
1585
return Y.Node.create(this.HANDLES_WRAP_TEMPLATE);
1589
* Default value for the wrapper attribute
1591
* @method _valueWrapper
1595
_valueWrapper: function() {
1596
var instance = this,
1597
node = instance.get(NODE),
1598
pNode = node.get(PARENT_NODE),
1599
// by deafult the wrapper is always the node
1602
// if the node is listed on the wrapTypes or wrap is set to true, create another wrapper
1603
if (instance.get(WRAP)) {
1604
wrapper = Y.Node.create(instance.WRAP_TEMPLATE);
1607
pNode.insertBefore(wrapper, node);
1610
wrapper.append(node);
1612
instance._copyStyles(node, wrapper);
1614
// remove positioning of wrapped node, the WRAPPER take care about positioning
1627
Y.each(Y.Resize.prototype.ALL_HANDLES, function(handle, i) {
1628
// creating ATTRS with the handles elements
1629
Y.Resize.ATTRS[handleAttrName(handle)] = {
1630
setter: function() {
1631
return this._buildHandle(handle);
1639
}, '3.5.1' ,{requires:['base', 'widget', 'substitute', 'event', 'oop', 'dd-drag', 'dd-delegate', 'dd-drop'], skinnable:true});