2
YUI 3.10.3 (build 2fb5187)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('resize-base', function (Y, NAME) {
11
* The Resize Utility allows you to make an HTML element resizable.
17
isArray = Lang.isArray,
18
isBoolean = Lang.isBoolean,
19
isNumber = Lang.isNumber,
20
isString = Lang.isString,
24
indexOf = yArray.indexOf,
29
HANDLE_SUB = '{handle}',
33
ACTIVE_HANDLE = 'activeHandle',
34
ACTIVE_HANDLE_NODE = 'activeHandleNode',
36
AUTO_HIDE = 'autoHide',
39
CLASS_NAME = 'className',
41
DEF_MIN_HEIGHT = 'defMinHeight',
42
DEF_MIN_WIDTH = 'defMinWidth',
45
HANDLES_WRAPPER = 'handlesWrapper',
51
NODE_NAME = 'nodeName',
53
OFFSET_HEIGHT = 'offsetHeight',
54
OFFSET_WIDTH = 'offsetWidth',
56
PARENT_NODE = 'parentNode',
57
POSITION = 'position',
58
RELATIVE = 'relative',
60
RESIZING = 'resizing',
68
WRAP_TYPES = 'wrapTypes',
70
EV_MOUSE_UP = 'resize:mouseUp',
71
EV_RESIZE = 'resize:resize',
72
EV_RESIZE_ALIGN = 'resize:align',
73
EV_RESIZE_END = 'resize:end',
74
EV_RESIZE_START = 'resize:start',
86
return Array.prototype.slice.call(arguments).join(SPACE);
89
// round the passed number to get rid of pixel-flickering
90
toRoundNumber = function(num) {
91
return Math.round(parseFloat(num)) || 0;
94
getCompStyle = function(node, val) {
95
return node.getComputedStyle(val);
98
handleAttrName = function(handle) {
99
return HANDLE + handle.toUpperCase();
102
isNode = function(v) {
103
return (v instanceof Y.Node);
106
toInitialCap = Y.cached(
108
return str.substring(0, 1).toUpperCase() + str.substring(1);
112
capitalize = Y.cached(function() {
114
args = yArray(arguments, 0, true);
116
yArray.each(args, function(part, i) {
118
part = toInitialCap(part);
123
return out.join(EMPTY_STR);
126
getCN = Y.ClassNameManager.getClassName,
128
CSS_RESIZE = getCN(RESIZE),
129
CSS_RESIZE_HANDLE = getCN(RESIZE, HANDLE),
130
CSS_RESIZE_HANDLE_ACTIVE = getCN(RESIZE, HANDLE, ACTIVE),
131
CSS_RESIZE_HANDLE_INNER = getCN(RESIZE, HANDLE, INNER),
132
CSS_RESIZE_HANDLE_INNER_PLACEHOLDER = getCN(RESIZE, HANDLE, INNER, HANDLE_SUB),
133
CSS_RESIZE_HANDLE_PLACEHOLDER = getCN(RESIZE, HANDLE, HANDLE_SUB),
134
CSS_RESIZE_HIDDEN_HANDLES = getCN(RESIZE, HIDDEN, HANDLES),
135
CSS_RESIZE_HANDLES_WRAPPER = getCN(RESIZE, HANDLES, WRAPPER),
136
CSS_RESIZE_WRAPPER = getCN(RESIZE, WRAPPER);
139
A base class for Resize, providing:
141
* Basic Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)
142
* Applies drag handles to an element to make it resizable
143
* Here is the list of valid resize handles:
144
`[ 't', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl' ]`. You can
145
read this list as top, top-right, right, bottom-right, bottom,
146
bottom-left, left, top-left.
147
* The drag handles are inserted into the element and positioned
148
absolute. Some elements, such as a textarea or image, don't support
149
children. To overcome that, set wrap:true in your config and the
150
element willbe wrapped for you automatically.
154
var instance = new Y.Resize({
160
handles: 't, tr, r, br, b, bl, l, tl'
163
Check the list of <a href="Resize.html#attrs">Configuration Attributes</a> available for
167
@param config {Object} Object literal specifying widget configuration properties.
173
Resize.superclass.constructor.apply(this, arguments);
178
* Static property provides a string to identify the class.
187
* Static property used to define the default attribute
188
* configuration for the Resize.
196
* Stores the active handle during the resize.
198
* @attribute activeHandle
205
validator: function(v) {
206
return Y.Lang.isString(v) || Y.Lang.isNull(v);
211
* Stores the active handle element during the resize.
213
* @attribute activeHandleNode
224
* False to ensure that the resize handles are always visible, true to
225
* display them only when the user mouses over the resizable borders.
227
* @attribute autoHide
237
* The default minimum height of the element. Only used when
238
* ResizeConstrained is not plugged.
240
* @attribute defMinHeight
250
* The default minimum width of the element. Only used when
251
* ResizeConstrained is not plugged.
253
* @attribute defMinWidth
263
* The handles to use (any combination of): 't', 'b', 'r', 'l', 'bl',
264
* 'br', 'tl', 'tr'. Can use a shortcut of All.
268
* @type Array | String
271
setter: '_setHandles',
276
* Node to wrap the resize handles.
278
* @attribute handlesWrapper
284
valueFn: '_valueHandlesWrapper'
288
* The selector or element to resize. Required.
298
* True when the element is being Resized.
300
* @attribute resizing
310
* True to wrap an element with a div if needed (required for textareas
311
* and images, defaults to false) in favor of the handles config option.
312
* The wrapper element type (default div) could be over-riden passing the
313
* <code>wrapper</code> attribute.
326
* Elements that requires a wrapper by default. Normally are elements
327
* which cannot have children elements.
329
* @attribute wrapTypes
330
* @default /canvas|textarea|input|select|button|img/i
336
value: /^canvas|textarea|input|select|button|img|iframe|table|embed$/i
340
* Element to wrap the <code>wrapTypes</code>. This element will house
341
* the handles elements.
345
* @type String | Node
350
valueFn: '_valueWrapper',
356
b: function(instance, dx, dy) {
357
var info = instance.info,
358
originalInfo = instance.originalInfo;
360
info.offsetHeight = originalInfo.offsetHeight + dy;
363
l: function(instance, dx) {
364
var info = instance.info,
365
originalInfo = instance.originalInfo;
367
info.left = originalInfo.left + dx;
368
info.offsetWidth = originalInfo.offsetWidth - dx;
371
r: function(instance, dx) {
372
var info = instance.info,
373
originalInfo = instance.originalInfo;
375
info.offsetWidth = originalInfo.offsetWidth + dx;
378
t: function(instance, dx, dy) {
379
var info = instance.info,
380
originalInfo = instance.originalInfo;
382
info.top = originalInfo.top + dy;
383
info.offsetHeight = originalInfo.offsetHeight - dy;
387
this.t.apply(this, arguments);
388
this.r.apply(this, arguments);
392
this.b.apply(this, arguments);
393
this.l.apply(this, arguments);
397
this.b.apply(this, arguments);
398
this.r.apply(this, arguments);
402
this.t.apply(this, arguments);
403
this.l.apply(this, arguments);
407
capitalize: capitalize
415
* Array containing all possible resizable handles.
417
* @property ALL_HANDLES
420
ALL_HANDLES: [ T, TR, R, BR, B, BL, L, TL ],
423
* Regex which matches with the handles that could change the height of
424
* the resizable element.
426
* @property REGEX_CHANGE_HEIGHT
429
REGEX_CHANGE_HEIGHT: /^(t|tr|b|bl|br|tl)$/i,
432
* Regex which matches with the handles that could change the left of
433
* the resizable element.
435
* @property REGEX_CHANGE_LEFT
438
REGEX_CHANGE_LEFT: /^(tl|l|bl)$/i,
441
* Regex which matches with the handles that could change the top of
442
* the resizable element.
444
* @property REGEX_CHANGE_TOP
447
REGEX_CHANGE_TOP: /^(tl|t|tr)$/i,
450
* Regex which matches with the handles that could change the width of
451
* the resizable element.
453
* @property REGEX_CHANGE_WIDTH
456
REGEX_CHANGE_WIDTH: /^(bl|br|l|r|tl|tr)$/i,
459
* Template used to create the resize wrapper for the handles.
461
* @property HANDLES_WRAP_TEMPLATE
464
HANDLES_WRAP_TEMPLATE: '<div class="'+CSS_RESIZE_HANDLES_WRAPPER+'"></div>',
467
* Template used to create the resize wrapper node when needed.
469
* @property WRAP_TEMPLATE
472
WRAP_TEMPLATE: '<div class="'+CSS_RESIZE_WRAPPER+'"></div>',
475
* Template used to create each resize handle.
477
* @property HANDLE_TEMPLATE
480
HANDLE_TEMPLATE: '<div class="'+concat(CSS_RESIZE_HANDLE, CSS_RESIZE_HANDLE_PLACEHOLDER)+'">' +
481
'<div class="'+concat(CSS_RESIZE_HANDLE_INNER, CSS_RESIZE_HANDLE_INNER_PLACEHOLDER)+'"> </div>' +
486
* Each box has a content area and optional surrounding padding and
487
* border areas. This property stores the sum of all horizontal
488
* surrounding * information needed to adjust the node height.
490
* @property totalHSurrounding
494
totalHSurrounding: 0,
497
* Each box has a content area and optional surrounding padding and
498
* border areas. This property stores the sum of all vertical
499
* surrounding * information needed to adjust the node height.
501
* @property totalVSurrounding
505
totalVSurrounding: 0,
508
* Stores the <a href="Resize.html#attr_node">node</a>
509
* surrounding information retrieved from
510
* <a href="Resize.html#method__getBoxSurroundingInfo">_getBoxSurroundingInfo</a>.
512
* @property nodeSurrounding
516
nodeSurrounding: null,
519
* Stores the <a href="Resize.html#attr_wrapper">wrapper</a>
520
* surrounding information retrieved from
521
* <a href="Resize.html#method__getBoxSurroundingInfo">_getBoxSurroundingInfo</a>.
523
* @property wrapperSurrounding
527
wrapperSurrounding: null,
530
* Whether the handle being dragged can change the height.
532
* @property changeHeightHandles
536
changeHeightHandles: false,
539
* Whether the handle being dragged can change the left.
541
* @property changeLeftHandles
545
changeLeftHandles: false,
548
* Whether the handle being dragged can change the top.
550
* @property changeTopHandles
554
changeTopHandles: false,
557
* Whether the handle being dragged can change the width.
559
* @property changeWidthHandles
563
changeWidthHandles: false,
566
* Store DD.Delegate reference for the respective Resize instance.
575
* Stores the current values for the height, width, top and left. You are
576
* able to manipulate these values on resize in order to change the resize
586
* Stores the last values for the height, width, top and left.
595
* Stores the original values for the height, width, top and left, stored
598
* @property originalInfo
605
* Construction logic executed during Resize instantiation. Lifecycle.
607
* @method initializer
610
initializer: function() {
611
this._eventHandles = [];
617
* Create the DOM structure for the Resize. Lifecycle.
622
renderUI: function() {
625
instance._renderHandles();
629
* Bind the events on the Resize UI. Lifecycle.
637
instance._createEvents();
639
instance._bindHandle();
643
* Sync the Resize UI.
651
this.get(NODE).addClass(CSS_RESIZE);
653
// hide handles if AUTO_HIDE is true
654
instance._setHideHandlesUI(
655
instance.get(AUTO_HIDE)
660
* Destructor lifecycle implementation for the Resize class.
661
* Detaches all previously attached listeners and removes the Resize handles.
666
destructor: function() {
668
node = instance.get(NODE),
669
wrapper = instance.get(WRAPPER),
670
pNode = wrapper.get(PARENT_NODE);
673
instance._eventHandles,
679
instance._eventHandles.length = 0;
681
// destroy handles dd and remove them from the dom
682
instance.eachHandle(function(handleEl) {
683
instance.delegate.dd.destroy();
686
handleEl.remove(true);
689
instance.delegate.destroy();
692
if (instance.get(WRAP)) {
693
instance._copyStyles(wrapper, node);
696
pNode.insertBefore(node, wrapper);
699
wrapper.remove(true);
702
node.removeClass(CSS_RESIZE);
703
node.removeClass(CSS_RESIZE_HIDDEN_HANDLES);
707
* Creates DOM (or manipulates DOM for progressive enhancement)
708
* This method is invoked by initializer(). It's chained automatically for
709
* subclasses if required.
714
renderer: function() {
721
* <p>Loop through each handle which is being used and executes a callback.</p>
723
* <pre><code>instance.eachHandle(
724
* function(handleName, index) { ... }
728
* @param {function} fn Callback function to be executed for each handle.
730
eachHandle: function(fn) {
734
instance.get(HANDLES),
735
function(handle, i) {
736
var handleEl = instance.get(
737
handleAttrName(handle)
740
fn.apply(instance, [handleEl, handle, i]);
746
* Bind the handles DragDrop events to the Resize instance.
751
_bindDD: function() {
754
instance.delegate = new Y.DD.Delegate(
756
bubbleTargets: instance,
757
container: instance.get(HANDLES_WRAPPER),
764
nodes: DOT+CSS_RESIZE_HANDLE,
769
instance._eventHandles.push(
770
instance.on('drag:drag', instance._handleResizeEvent),
771
instance.on('drag:dropmiss', instance._handleMouseUpEvent),
772
instance.on('drag:end', instance._handleResizeEndEvent),
773
instance.on('drag:start', instance._handleResizeStartEvent)
778
* Bind the events related to the handles (_onHandleMouseEnter, _onHandleMouseLeave).
780
* @method _bindHandle
783
_bindHandle: function() {
785
wrapper = instance.get(WRAPPER);
787
instance._eventHandles.push(
788
wrapper.on('mouseenter', Y.bind(instance._onWrapperMouseEnter, instance)),
789
wrapper.on('mouseleave', Y.bind(instance._onWrapperMouseLeave, instance)),
790
wrapper.delegate('mouseenter', Y.bind(instance._onHandleMouseEnter, instance), DOT+CSS_RESIZE_HANDLE),
791
wrapper.delegate('mouseleave', Y.bind(instance._onHandleMouseLeave, instance), DOT+CSS_RESIZE_HANDLE)
796
* Create the custom events used on the Resize.
798
* @method _createEvents
801
_createEvents: function() {
803
// create publish function for kweight optimization
804
publish = function(name, fn) {
805
instance.publish(name, {
815
* Handles the resize start event. Fired when a handle starts to be
818
* @event resize:start
819
* @preventable _defResizeStartFn
820
* @param {Event.Facade} event The resize start event.
822
* @type {Event.Custom}
824
publish(EV_RESIZE_START, this._defResizeStartFn);
827
* Handles the resize event. Fired on each pixel when the handle is
830
* @event resize:resize
831
* @preventable _defResizeFn
832
* @param {Event.Facade} event The resize event.
834
* @type {Event.Custom}
836
publish(EV_RESIZE, this._defResizeFn);
839
* Handles the resize align event.
841
* @event resize:align
842
* @preventable _defResizeAlignFn
843
* @param {Event.Facade} event The resize align event.
845
* @type {Event.Custom}
847
publish(EV_RESIZE_ALIGN, this._defResizeAlignFn);
850
* Handles the resize end event. Fired when a handle stop to be
854
* @preventable _defResizeEndFn
855
* @param {Event.Facade} event The resize end event.
857
* @type {Event.Custom}
859
publish(EV_RESIZE_END, this._defResizeEndFn);
862
* Handles the resize mouseUp event. Fired when a mouseUp event happens on a
865
* @event resize:mouseUp
866
* @preventable _defMouseUpFn
867
* @param {Event.Facade} event The resize mouseUp event.
869
* @type {Event.Custom}
871
publish(EV_MOUSE_UP, this._defMouseUpFn);
875
* Responsible for loop each handle element and append to the wrapper.
877
* @method _renderHandles
880
_renderHandles: function() {
882
wrapper = instance.get(WRAPPER),
883
handlesWrapper = instance.get(HANDLES_WRAPPER);
885
instance.eachHandle(function(handleEl) {
886
handlesWrapper.append(handleEl);
889
wrapper.append(handlesWrapper);
893
* Creates the handle element based on the handle name and initialize the
896
* @method _buildHandle
897
* @param {String} handle Handle name ('t', 'tr', 'b', ...).
900
_buildHandle: function(handle) {
903
return Y.Node.create(
904
Y.Lang.sub(instance.HANDLE_TEMPLATE, {
911
* Basic resize calculations.
913
* @method _calcResize
916
_calcResize: function() {
918
handle = instance.handle,
919
info = instance.info,
920
originalInfo = instance.originalInfo,
922
dx = info.actXY[0] - originalInfo.actXY[0],
923
dy = info.actXY[1] - originalInfo.actXY[1];
925
if (handle && Y.Resize.RULES[handle]) {
926
Y.Resize.RULES[handle](instance, dx, dy);
933
* Helper method to update the current size value on
934
* <a href="Resize.html#property_info">info</a> to respect the
935
* min/max values and fix the top/left calculations.
938
* @param {String} offset 'offsetHeight' or 'offsetWidth'
939
* @param {number} size Size to restrict the offset
942
_checkSize: function(offset, size) {
944
info = instance.info,
945
originalInfo = instance.originalInfo,
946
axis = (offset === OFFSET_HEIGHT) ? TOP : LEFT;
948
// forcing the offsetHeight/offsetWidth to be the passed size
951
// predicting, based on the original information, the last left valid in case of reach the min/max dimension
952
// this calculation avoid browser event leaks when user interact very fast
953
if (((axis === LEFT) && instance.changeLeftHandles) ||
954
((axis === TOP) && instance.changeTopHandles)) {
956
info[axis] = originalInfo[axis] + originalInfo[offset] - size;
961
* Copy relevant styles of the <a href="Resize.html#attr_node">node</a>
962
* to the <a href="Resize.html#attr_wrapper">wrapper</a>.
964
* @method _copyStyles
965
* @param {Node} node Node from.
966
* @param {Node} wrapper Node to.
969
_copyStyles: function(node, wrapper) {
970
var position = node.getStyle(POSITION).toLowerCase(),
971
surrounding = this._getBoxSurroundingInfo(node),
974
// resizable wrapper should be positioned
975
if (position === STATIC) {
981
left: getCompStyle(node, LEFT),
982
top: getCompStyle(node, TOP)
985
Y.mix(wrapperStyle, surrounding.margin);
986
Y.mix(wrapperStyle, surrounding.border);
988
wrapper.setStyles(wrapperStyle);
990
// remove margin and border from the internal node
991
node.setStyles({ border: 0, margin: 0 });
994
node.get(OFFSET_WIDTH) + surrounding.totalHBorder,
995
node.get(OFFSET_HEIGHT) + surrounding.totalVBorder
999
// extract handle name from a string
1000
// using Y.cached to memoize the function for performance
1001
_extractHandleName: Y.cached(
1003
var className = node.get(CLASS_NAME),
1005
match = className.match(
1007
getCN(RESIZE, HANDLE, '(\\w{1,2})\\b')
1011
return match ? match[1] : null;
1016
* <p>Generates metadata to the <a href="Resize.html#property_info">info</a>
1017
* and <a href="Resize.html#property_originalInfo">originalInfo</a></p>
1018
* <pre><code>bottom, actXY, left, top, offsetHeight, offsetWidth, right</code></pre>
1021
* @param {Node} node
1022
* @param {EventFacade} event
1025
_getInfo: function(node, event) {
1027
drag = event.dragEvent.target,
1028
nodeXY = node.getXY(),
1031
offsetHeight = node.get(OFFSET_HEIGHT),
1032
offsetWidth = node.get(OFFSET_WIDTH);
1035
// the xy that the node will be set to. Changing this will alter the position as it's dragged.
1036
actXY = (drag.actXY.length ? drag.actXY : drag.lastXY);
1041
bottom: (nodeY + offsetHeight),
1043
offsetHeight: offsetHeight,
1044
offsetWidth: offsetWidth,
1045
right: (nodeX + offsetWidth),
1051
* Each box has a content area and optional surrounding margin,
1052
* padding and * border areas. This method get all this information from
1053
* the passed node. For more reference see
1054
* <a href="http://www.w3.org/TR/CSS21/box.html#box-dimensions">
1055
* http://www.w3.org/TR/CSS21/box.html#box-dimensions</a>.
1057
* @method _getBoxSurroundingInfo
1058
* @param {Node} node
1062
_getBoxSurroundingInfo: function(node) {
1070
Y.each([ TOP, RIGHT, BOTTOM, LEFT ], function(dir) {
1071
var paddingProperty = capitalize(PADDING, dir),
1072
marginProperty = capitalize(MARGIN, dir),
1073
borderWidthProperty = capitalize(BORDER, dir, WIDTH),
1074
borderColorProperty = capitalize(BORDER, dir, COLOR),
1075
borderStyleProperty = capitalize(BORDER, dir, STYLE);
1077
info.border[borderColorProperty] = getCompStyle(node, borderColorProperty);
1078
info.border[borderStyleProperty] = getCompStyle(node, borderStyleProperty);
1079
info.border[borderWidthProperty] = getCompStyle(node, borderWidthProperty);
1080
info.margin[marginProperty] = getCompStyle(node, marginProperty);
1081
info.padding[paddingProperty] = getCompStyle(node, paddingProperty);
1085
info.totalHBorder = (toRoundNumber(info.border.borderLeftWidth) + toRoundNumber(info.border.borderRightWidth));
1086
info.totalHPadding = (toRoundNumber(info.padding.paddingLeft) + toRoundNumber(info.padding.paddingRight));
1087
info.totalVBorder = (toRoundNumber(info.border.borderBottomWidth) + toRoundNumber(info.border.borderTopWidth));
1088
info.totalVPadding = (toRoundNumber(info.padding.paddingBottom) + toRoundNumber(info.padding.paddingTop));
1094
* Sync the Resize UI with internal values from
1095
* <a href="Resize.html#property_info">info</a>.
1100
_syncUI: function() {
1101
var instance = this,
1102
info = instance.info,
1103
wrapperSurrounding = instance.wrapperSurrounding,
1104
wrapper = instance.get(WRAPPER),
1105
node = instance.get(NODE);
1107
wrapper.sizeTo(info.offsetWidth, info.offsetHeight);
1109
if (instance.changeLeftHandles || instance.changeTopHandles) {
1110
wrapper.setXY([info.left, info.top]);
1113
// if a wrap node is being used
1114
if (!wrapper.compareTo(node)) {
1115
// the original internal node borders were copied to the wrapper on
1116
// _copyStyles, to compensate that subtract the borders from the internal node
1118
info.offsetWidth - wrapperSurrounding.totalHBorder,
1119
info.offsetHeight - wrapperSurrounding.totalVBorder
1123
// prevent webkit textarea resize
1125
node.setStyle(RESIZE, NONE);
1130
* Update <code>instance.changeHeightHandles,
1131
* instance.changeLeftHandles, instance.changeTopHandles,
1132
* instance.changeWidthHandles</code> information.
1134
* @method _updateChangeHandleInfo
1137
_updateChangeHandleInfo: function(handle) {
1138
var instance = this;
1140
instance.changeHeightHandles = instance.REGEX_CHANGE_HEIGHT.test(handle);
1141
instance.changeLeftHandles = instance.REGEX_CHANGE_LEFT.test(handle);
1142
instance.changeTopHandles = instance.REGEX_CHANGE_TOP.test(handle);
1143
instance.changeWidthHandles = instance.REGEX_CHANGE_WIDTH.test(handle);
1147
* Update <a href="Resize.html#property_info">info</a> values (bottom, actXY, left, top, offsetHeight, offsetWidth, right).
1149
* @method _updateInfo
1152
_updateInfo: function(event) {
1153
var instance = this;
1155
instance.info = instance._getInfo(instance.get(WRAPPER), event);
1160
* <a href="Resize.html#property_nodeSurrounding">nodeSurrounding</a>,
1161
* <a href="Resize.html#property_nodeSurrounding">wrapperSurrounding</a>,
1162
* <a href="Resize.html#property_nodeSurrounding">totalVSurrounding</a>,
1163
* <a href="Resize.html#property_nodeSurrounding">totalHSurrounding</a>.
1165
* @method _updateSurroundingInfo
1168
_updateSurroundingInfo: function() {
1169
var instance = this,
1170
node = instance.get(NODE),
1171
wrapper = instance.get(WRAPPER),
1172
nodeSurrounding = instance._getBoxSurroundingInfo(node),
1173
wrapperSurrounding = instance._getBoxSurroundingInfo(wrapper);
1175
instance.nodeSurrounding = nodeSurrounding;
1176
instance.wrapperSurrounding = wrapperSurrounding;
1178
instance.totalVSurrounding = (nodeSurrounding.totalVPadding + wrapperSurrounding.totalVBorder);
1179
instance.totalHSurrounding = (nodeSurrounding.totalHPadding + wrapperSurrounding.totalHBorder);
1183
* Set the active state of the handles.
1185
* @method _setActiveHandlesUI
1186
* @param {boolean} val True to activate the handles, false to deactivate.
1189
_setActiveHandlesUI: function(val) {
1190
var instance = this,
1191
activeHandleNode = instance.get(ACTIVE_HANDLE_NODE);
1193
if (activeHandleNode) {
1195
// remove CSS_RESIZE_HANDLE_ACTIVE from all handles before addClass on the active
1196
instance.eachHandle(
1197
function(handleEl) {
1198
handleEl.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1202
activeHandleNode.addClass(CSS_RESIZE_HANDLE_ACTIVE);
1205
activeHandleNode.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1211
* Setter for the handles attribute
1213
* @method _setHandles
1215
* @param {String} val
1217
_setHandles: function(val) {
1218
var instance = this,
1221
// handles attr accepts both array or string
1225
else if (isString(val)) {
1226
// if the handles attr passed in is an ALL string...
1227
if (val.toLowerCase() === ALL) {
1228
handles = instance.ALL_HANDLES;
1230
// otherwise, split the string to extract the handles
1235
var handle = trim(node);
1237
// if its a valid handle, add it to the handles output
1238
if (indexOf(instance.ALL_HANDLES, handle) > -1) {
1239
handles.push(handle);
1250
* Set the visibility of the handles.
1252
* @method _setHideHandlesUI
1253
* @param {boolean} val True to hide the handles, false to show.
1256
_setHideHandlesUI: function(val) {
1257
var instance = this,
1258
wrapper = instance.get(WRAPPER);
1260
if (!instance.get(RESIZING)) {
1262
wrapper.addClass(CSS_RESIZE_HIDDEN_HANDLES);
1265
wrapper.removeClass(CSS_RESIZE_HIDDEN_HANDLES);
1271
* Setter for the wrap attribute
1275
* @param {boolean} val
1277
_setWrap: function(val) {
1278
var instance = this,
1279
node = instance.get(NODE),
1280
nodeName = node.get(NODE_NAME),
1281
typeRegex = instance.get(WRAP_TYPES);
1283
// if nodeName is listed on WRAP_TYPES force use the wrapper
1284
if (typeRegex.test(nodeName)) {
1292
* Default resize:mouseUp handler
1294
* @method _defMouseUpFn
1295
* @param {EventFacade} event The Event object
1298
_defMouseUpFn: function() {
1299
var instance = this;
1301
instance.set(RESIZING, false);
1305
* Default resize:resize handler
1307
* @method _defResizeFn
1308
* @param {EventFacade} event The Event object
1311
_defResizeFn: function(event) {
1312
var instance = this;
1314
instance._resize(event);
1318
* Logic method for _defResizeFn. Allow AOP.
1321
* @param {EventFacade} event The Event object
1324
_resize: function(event) {
1325
var instance = this;
1327
instance._handleResizeAlignEvent(event.dragEvent);
1329
// _syncUI of the wrapper, not using proxy
1334
* Default resize:align handler
1336
* @method _defResizeAlignFn
1337
* @param {EventFacade} event The Event object
1340
_defResizeAlignFn: function(event) {
1341
var instance = this;
1343
instance._resizeAlign(event);
1347
* Logic method for _defResizeAlignFn. Allow AOP.
1349
* @method _resizeAlign
1350
* @param {EventFacade} event The Event object
1353
_resizeAlign: function(event) {
1354
var instance = this,
1359
instance.lastInfo = instance.info;
1361
// update the instance.info values
1362
instance._updateInfo(event);
1364
info = instance.info;
1366
// basic resize calculations
1367
instance._calcResize();
1369
// if Y.Plugin.ResizeConstrained is not plugged, check for min dimension
1370
if (!instance.con) {
1371
defMinHeight = (instance.get(DEF_MIN_HEIGHT) + instance.totalVSurrounding);
1372
defMinWidth = (instance.get(DEF_MIN_WIDTH) + instance.totalHSurrounding);
1374
if (info.offsetHeight <= defMinHeight) {
1375
instance._checkSize(OFFSET_HEIGHT, defMinHeight);
1378
if (info.offsetWidth <= defMinWidth) {
1379
instance._checkSize(OFFSET_WIDTH, defMinWidth);
1385
* Default resize:end handler
1387
* @method _defResizeEndFn
1388
* @param {EventFacade} event The Event object
1391
_defResizeEndFn: function(event) {
1392
var instance = this;
1394
instance._resizeEnd(event);
1398
* Logic method for _defResizeEndFn. Allow AOP.
1400
* @method _resizeEnd
1401
* @param {EventFacade} event The Event object
1404
_resizeEnd: function(event) {
1405
var instance = this,
1406
drag = event.dragEvent.target;
1408
// reseting actXY from drag when drag end
1411
// syncUI when resize end
1414
instance._setActiveHandlesUI(false);
1416
instance.set(ACTIVE_HANDLE, null);
1417
instance.set(ACTIVE_HANDLE_NODE, null);
1419
instance.handle = null;
1423
* Default resize:start handler
1425
* @method _defResizeStartFn
1426
* @param {EventFacade} event The Event object
1429
_defResizeStartFn: function(event) {
1430
var instance = this;
1432
instance._resizeStart(event);
1436
* Logic method for _defResizeStartFn. Allow AOP.
1438
* @method _resizeStart
1439
* @param {EventFacade} event The Event object
1442
_resizeStart: function(event) {
1443
var instance = this,
1444
wrapper = instance.get(WRAPPER);
1446
instance.handle = instance.get(ACTIVE_HANDLE);
1448
instance.set(RESIZING, true);
1450
instance._updateSurroundingInfo();
1452
// create an originalInfo information for reference
1453
instance.originalInfo = instance._getInfo(wrapper, event);
1455
instance._updateInfo(event);
1459
* Fires the resize:mouseUp event.
1461
* @method _handleMouseUpEvent
1462
* @param {EventFacade} event resize:mouseUp event facade
1465
_handleMouseUpEvent: function(event) {
1466
this.fire(EV_MOUSE_UP, { dragEvent: event, info: this.info });
1470
* Fires the resize:resize event.
1472
* @method _handleResizeEvent
1473
* @param {EventFacade} event resize:resize event facade
1476
_handleResizeEvent: function(event) {
1477
this.fire(EV_RESIZE, { dragEvent: event, info: this.info });
1481
* Fires the resize:align event.
1483
* @method _handleResizeAlignEvent
1484
* @param {EventFacade} event resize:resize event facade
1487
_handleResizeAlignEvent: function(event) {
1488
this.fire(EV_RESIZE_ALIGN, { dragEvent: event, info: this.info });
1492
* Fires the resize:end event.
1494
* @method _handleResizeEndEvent
1495
* @param {EventFacade} event resize:end event facade
1498
_handleResizeEndEvent: function(event) {
1499
this.fire(EV_RESIZE_END, { dragEvent: event, info: this.info });
1503
* Fires the resize:start event.
1505
* @method _handleResizeStartEvent
1506
* @param {EventFacade} event resize:start event facade
1509
_handleResizeStartEvent: function(event) {
1510
if (!this.get(ACTIVE_HANDLE)) {
1511
//This handles the "touch" case
1512
this._setHandleFromNode(event.target.get('node'));
1514
this.fire(EV_RESIZE_START, { dragEvent: event, info: this.info });
1518
* Mouseenter event handler for the <a href="Resize.html#attr_wrapper">wrapper</a>.
1520
* @method _onWrapperMouseEnter
1521
* @param {EventFacade} event
1524
_onWrapperMouseEnter: function() {
1525
var instance = this;
1527
if (instance.get(AUTO_HIDE)) {
1528
instance._setHideHandlesUI(false);
1533
* Mouseleave event handler for the <a href="Resize.html#attr_wrapper">wrapper</a>.
1535
* @method _onWrapperMouseLeave
1536
* @param {EventFacade} event
1539
_onWrapperMouseLeave: function() {
1540
var instance = this;
1542
if (instance.get(AUTO_HIDE)) {
1543
instance._setHideHandlesUI(true);
1548
* Handles setting the activeHandle from a node, used from startDrag (for touch) and mouseenter (for mouse).
1550
* @method _setHandleFromNode
1551
* @param {Node} node
1554
_setHandleFromNode: function(node) {
1555
var instance = this,
1556
handle = instance._extractHandleName(node);
1558
if (!instance.get(RESIZING)) {
1559
instance.set(ACTIVE_HANDLE, handle);
1560
instance.set(ACTIVE_HANDLE_NODE, node);
1562
instance._setActiveHandlesUI(true);
1563
instance._updateChangeHandleInfo(handle);
1568
* Mouseenter event handler for the handles.
1570
* @method _onHandleMouseEnter
1571
* @param {EventFacade} event
1574
_onHandleMouseEnter: function(event) {
1575
this._setHandleFromNode(event.currentTarget);
1579
* Mouseout event handler for the handles.
1581
* @method _onHandleMouseLeave
1582
* @param {EventFacade} event
1585
_onHandleMouseLeave: function() {
1586
var instance = this;
1588
if (!instance.get(RESIZING)) {
1589
instance._setActiveHandlesUI(false);
1594
* Default value for the wrapper handles node attribute
1596
* @method _valueHandlesWrapper
1600
_valueHandlesWrapper: function() {
1601
return Y.Node.create(this.HANDLES_WRAP_TEMPLATE);
1605
* Default value for the wrapper attribute
1607
* @method _valueWrapper
1611
_valueWrapper: function() {
1612
var instance = this,
1613
node = instance.get(NODE),
1614
pNode = node.get(PARENT_NODE),
1615
// by deafult the wrapper is always the node
1618
// if the node is listed on the wrapTypes or wrap is set to true, create another wrapper
1619
if (instance.get(WRAP)) {
1620
wrapper = Y.Node.create(instance.WRAP_TEMPLATE);
1623
pNode.insertBefore(wrapper, node);
1626
wrapper.append(node);
1628
instance._copyStyles(node, wrapper);
1630
// remove positioning of wrapped node, the WRAPPER take care about positioning
1643
Y.each(Y.Resize.prototype.ALL_HANDLES, function(handle) {
1644
// creating ATTRS with the handles elements
1645
Y.Resize.ATTRS[handleAttrName(handle)] = {
1646
setter: function() {
1647
return this._buildHandle(handle);
1655
}, '3.10.3', {"requires": ["base", "widget", "event", "oop", "dd-drag", "dd-delegate", "dd-drop"], "skinnable": true});