1
YUI.add('resize-base', function (Y, NAME) {
4
* The Resize Utility allows you to make an HTML element resizable.
10
isArray = Lang.isArray,
11
isBoolean = Lang.isBoolean,
12
isNumber = Lang.isNumber,
13
isString = Lang.isString,
17
indexOf = yArray.indexOf,
22
HANDLE_SUB = '{handle}',
26
ACTIVE_HANDLE = 'activeHandle',
27
ACTIVE_HANDLE_NODE = 'activeHandleNode',
29
AUTO_HIDE = 'autoHide',
32
CLASS_NAME = 'className',
34
DEF_MIN_HEIGHT = 'defMinHeight',
35
DEF_MIN_WIDTH = 'defMinWidth',
38
HANDLES_WRAPPER = 'handlesWrapper',
44
NODE_NAME = 'nodeName',
46
OFFSET_HEIGHT = 'offsetHeight',
47
OFFSET_WIDTH = 'offsetWidth',
49
PARENT_NODE = 'parentNode',
50
POSITION = 'position',
51
RELATIVE = 'relative',
53
RESIZING = 'resizing',
61
WRAP_TYPES = 'wrapTypes',
63
EV_MOUSE_UP = 'resize:mouseUp',
64
EV_RESIZE = 'resize:resize',
65
EV_RESIZE_ALIGN = 'resize:align',
66
EV_RESIZE_END = 'resize:end',
67
EV_RESIZE_START = 'resize:start',
79
return Array.prototype.slice.call(arguments).join(SPACE);
82
// round the passed number to get rid of pixel-flickering
83
toRoundNumber = function(num) {
84
return Math.round(parseFloat(num)) || 0;
87
getCompStyle = function(node, val) {
88
return node.getComputedStyle(val);
91
handleAttrName = function(handle) {
92
return HANDLE + handle.toUpperCase();
95
isNode = function(v) {
96
return (v instanceof Y.Node);
99
toInitialCap = Y.cached(
101
return str.substring(0, 1).toUpperCase() + str.substring(1);
105
capitalize = Y.cached(function() {
107
args = yArray(arguments, 0, true);
109
yArray.each(args, function(part, i) {
111
part = toInitialCap(part);
116
return out.join(EMPTY_STR);
119
getCN = Y.ClassNameManager.getClassName,
121
CSS_RESIZE = getCN(RESIZE),
122
CSS_RESIZE_HANDLE = getCN(RESIZE, HANDLE),
123
CSS_RESIZE_HANDLE_ACTIVE = getCN(RESIZE, HANDLE, ACTIVE),
124
CSS_RESIZE_HANDLE_INNER = getCN(RESIZE, HANDLE, INNER),
125
CSS_RESIZE_HANDLE_INNER_PLACEHOLDER = getCN(RESIZE, HANDLE, INNER, HANDLE_SUB),
126
CSS_RESIZE_HANDLE_PLACEHOLDER = getCN(RESIZE, HANDLE, HANDLE_SUB),
127
CSS_RESIZE_HIDDEN_HANDLES = getCN(RESIZE, HIDDEN, HANDLES),
128
CSS_RESIZE_HANDLES_WRAPPER = getCN(RESIZE, HANDLES, WRAPPER),
129
CSS_RESIZE_WRAPPER = getCN(RESIZE, WRAPPER);
132
A base class for Resize, providing:
134
* Basic Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)
135
* Applies drag handles to an element to make it resizable
136
* Here is the list of valid resize handles:
137
`[ 't', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl' ]`. You can
138
read this list as top, top-right, right, bottom-right, bottom,
139
bottom-left, left, top-left.
140
* The drag handles are inserted into the element and positioned
141
absolute. Some elements, such as a textarea or image, don't support
142
children. To overcome that, set wrap:true in your config and the
143
element willbe wrapped for you automatically.
147
var instance = new Y.Resize({
153
handles: 't, tr, r, br, b, bl, l, tl'
156
Check the list of <a href="Resize.html#attrs">Configuration Attributes</a> available for
160
@param config {Object} Object literal specifying widget configuration properties.
166
Resize.superclass.constructor.apply(this, arguments);
171
* Static property provides a string to identify the class.
180
* Static property used to define the default attribute
181
* configuration for the Resize.
189
* Stores the active handle during the resize.
191
* @attribute activeHandle
198
validator: function(v) {
199
return Y.Lang.isString(v) || Y.Lang.isNull(v);
204
* Stores the active handle element during the resize.
206
* @attribute activeHandleNode
217
* False to ensure that the resize handles are always visible, true to
218
* display them only when the user mouses over the resizable borders.
220
* @attribute autoHide
230
* The default minimum height of the element. Only used when
231
* ResizeConstrained is not plugged.
233
* @attribute defMinHeight
243
* The default minimum width of the element. Only used when
244
* ResizeConstrained is not plugged.
246
* @attribute defMinWidth
256
* The handles to use (any combination of): 't', 'b', 'r', 'l', 'bl',
257
* 'br', 'tl', 'tr'. Can use a shortcut of All.
261
* @type Array | String
264
setter: '_setHandles',
269
* Node to wrap the resize handles.
271
* @attribute handlesWrapper
277
valueFn: '_valueHandlesWrapper'
281
* The selector or element to resize. Required.
291
* True when the element is being Resized.
293
* @attribute resizing
303
* True to wrap an element with a div if needed (required for textareas
304
* and images, defaults to false) in favor of the handles config option.
305
* The wrapper element type (default div) could be over-riden passing the
306
* <code>wrapper</code> attribute.
319
* Elements that requires a wrapper by default. Normally are elements
320
* which cannot have children elements.
322
* @attribute wrapTypes
323
* @default /canvas|textarea|input|select|button|img/i
329
value: /^canvas|textarea|input|select|button|img|iframe|table|embed$/i
333
* Element to wrap the <code>wrapTypes</code>. This element will house
334
* the handles elements.
338
* @type String | Node
343
valueFn: '_valueWrapper',
349
b: function(instance, dx, dy) {
350
var info = instance.info,
351
originalInfo = instance.originalInfo;
353
info.offsetHeight = originalInfo.offsetHeight + dy;
356
l: function(instance, dx) {
357
var info = instance.info,
358
originalInfo = instance.originalInfo;
360
info.left = originalInfo.left + dx;
361
info.offsetWidth = originalInfo.offsetWidth - dx;
364
r: function(instance, dx) {
365
var info = instance.info,
366
originalInfo = instance.originalInfo;
368
info.offsetWidth = originalInfo.offsetWidth + dx;
371
t: function(instance, dx, dy) {
372
var info = instance.info,
373
originalInfo = instance.originalInfo;
375
info.top = originalInfo.top + dy;
376
info.offsetHeight = originalInfo.offsetHeight - dy;
380
this.t.apply(this, arguments);
381
this.r.apply(this, arguments);
385
this.b.apply(this, arguments);
386
this.l.apply(this, arguments);
390
this.b.apply(this, arguments);
391
this.r.apply(this, arguments);
395
this.t.apply(this, arguments);
396
this.l.apply(this, arguments);
400
capitalize: capitalize
408
* Array containing all possible resizable handles.
410
* @property ALL_HANDLES
413
ALL_HANDLES: [ T, TR, R, BR, B, BL, L, TL ],
416
* Regex which matches with the handles that could change the height of
417
* the resizable element.
419
* @property REGEX_CHANGE_HEIGHT
422
REGEX_CHANGE_HEIGHT: /^(t|tr|b|bl|br|tl)$/i,
425
* Regex which matches with the handles that could change the left of
426
* the resizable element.
428
* @property REGEX_CHANGE_LEFT
431
REGEX_CHANGE_LEFT: /^(tl|l|bl)$/i,
434
* Regex which matches with the handles that could change the top of
435
* the resizable element.
437
* @property REGEX_CHANGE_TOP
440
REGEX_CHANGE_TOP: /^(tl|t|tr)$/i,
443
* Regex which matches with the handles that could change the width of
444
* the resizable element.
446
* @property REGEX_CHANGE_WIDTH
449
REGEX_CHANGE_WIDTH: /^(bl|br|l|r|tl|tr)$/i,
452
* Template used to create the resize wrapper for the handles.
454
* @property HANDLES_WRAP_TEMPLATE
457
HANDLES_WRAP_TEMPLATE: '<div class="'+CSS_RESIZE_HANDLES_WRAPPER+'"></div>',
460
* Template used to create the resize wrapper node when needed.
462
* @property WRAP_TEMPLATE
465
WRAP_TEMPLATE: '<div class="'+CSS_RESIZE_WRAPPER+'"></div>',
468
* Template used to create each resize handle.
470
* @property HANDLE_TEMPLATE
473
HANDLE_TEMPLATE: '<div class="'+concat(CSS_RESIZE_HANDLE, CSS_RESIZE_HANDLE_PLACEHOLDER)+'">' +
474
'<div class="'+concat(CSS_RESIZE_HANDLE_INNER, CSS_RESIZE_HANDLE_INNER_PLACEHOLDER)+'"> </div>' +
479
* Each box has a content area and optional surrounding padding and
480
* border areas. This property stores the sum of all horizontal
481
* surrounding * information needed to adjust the node height.
483
* @property totalHSurrounding
487
totalHSurrounding: 0,
490
* Each box has a content area and optional surrounding padding and
491
* border areas. This property stores the sum of all vertical
492
* surrounding * information needed to adjust the node height.
494
* @property totalVSurrounding
498
totalVSurrounding: 0,
501
* Stores the <a href="Resize.html#attr_node">node</a>
502
* surrounding information retrieved from
503
* <a href="Resize.html#method__getBoxSurroundingInfo">_getBoxSurroundingInfo</a>.
505
* @property nodeSurrounding
509
nodeSurrounding: null,
512
* Stores the <a href="Resize.html#attr_wrapper">wrapper</a>
513
* surrounding information retrieved from
514
* <a href="Resize.html#method__getBoxSurroundingInfo">_getBoxSurroundingInfo</a>.
516
* @property wrapperSurrounding
520
wrapperSurrounding: null,
523
* Whether the handle being dragged can change the height.
525
* @property changeHeightHandles
529
changeHeightHandles: false,
532
* Whether the handle being dragged can change the left.
534
* @property changeLeftHandles
538
changeLeftHandles: false,
541
* Whether the handle being dragged can change the top.
543
* @property changeTopHandles
547
changeTopHandles: false,
550
* Whether the handle being dragged can change the width.
552
* @property changeWidthHandles
556
changeWidthHandles: false,
559
* Store DD.Delegate reference for the respective Resize instance.
568
* Stores the current values for the height, width, top and left. You are
569
* able to manipulate these values on resize in order to change the resize
579
* Stores the last values for the height, width, top and left.
588
* Stores the original values for the height, width, top and left, stored
591
* @property originalInfo
598
* Construction logic executed during Resize instantiation. Lifecycle.
600
* @method initializer
603
initializer: function() {
604
this._eventHandles = [];
610
* Create the DOM structure for the Resize. Lifecycle.
615
renderUI: function() {
618
instance._renderHandles();
622
* Bind the events on the Resize UI. Lifecycle.
630
instance._createEvents();
632
instance._bindHandle();
636
* Sync the Resize UI.
644
this.get(NODE).addClass(CSS_RESIZE);
646
// hide handles if AUTO_HIDE is true
647
instance._setHideHandlesUI(
648
instance.get(AUTO_HIDE)
653
* Destructor lifecycle implementation for the Resize class.
654
* Detaches all previously attached listeners and removes the Resize handles.
659
destructor: function() {
661
node = instance.get(NODE),
662
wrapper = instance.get(WRAPPER),
663
pNode = wrapper.get(PARENT_NODE);
666
instance._eventHandles,
672
instance._eventHandles.length = 0;
674
// destroy handles dd and remove them from the dom
675
instance.eachHandle(function(handleEl) {
676
instance.delegate.dd.destroy();
679
handleEl.remove(true);
682
instance.delegate.destroy();
685
if (instance.get(WRAP)) {
686
instance._copyStyles(wrapper, node);
689
pNode.insertBefore(node, wrapper);
692
wrapper.remove(true);
695
node.removeClass(CSS_RESIZE);
696
node.removeClass(CSS_RESIZE_HIDDEN_HANDLES);
700
* Creates DOM (or manipulates DOM for progressive enhancement)
701
* This method is invoked by initializer(). It's chained automatically for
702
* subclasses if required.
707
renderer: function() {
714
* <p>Loop through each handle which is being used and executes a callback.</p>
716
* <pre><code>instance.eachHandle(
717
* function(handleName, index) { ... }
721
* @param {function} fn Callback function to be executed for each handle.
723
eachHandle: function(fn) {
727
instance.get(HANDLES),
728
function(handle, i) {
729
var handleEl = instance.get(
730
handleAttrName(handle)
733
fn.apply(instance, [handleEl, handle, i]);
739
* Bind the handles DragDrop events to the Resize instance.
744
_bindDD: function() {
747
instance.delegate = new Y.DD.Delegate(
749
bubbleTargets: instance,
750
container: instance.get(HANDLES_WRAPPER),
757
nodes: DOT+CSS_RESIZE_HANDLE,
762
instance._eventHandles.push(
763
instance.on('drag:drag', instance._handleResizeEvent),
764
instance.on('drag:dropmiss', instance._handleMouseUpEvent),
765
instance.on('drag:end', instance._handleResizeEndEvent),
766
instance.on('drag:start', instance._handleResizeStartEvent)
771
* Bind the events related to the handles (_onHandleMouseEnter, _onHandleMouseLeave).
773
* @method _bindHandle
776
_bindHandle: function() {
778
wrapper = instance.get(WRAPPER);
780
instance._eventHandles.push(
781
wrapper.on('mouseenter', Y.bind(instance._onWrapperMouseEnter, instance)),
782
wrapper.on('mouseleave', Y.bind(instance._onWrapperMouseLeave, instance)),
783
wrapper.delegate('mouseenter', Y.bind(instance._onHandleMouseEnter, instance), DOT+CSS_RESIZE_HANDLE),
784
wrapper.delegate('mouseleave', Y.bind(instance._onHandleMouseLeave, instance), DOT+CSS_RESIZE_HANDLE)
789
* Create the custom events used on the Resize.
791
* @method _createEvents
794
_createEvents: function() {
796
// create publish function for kweight optimization
797
publish = function(name, fn) {
798
instance.publish(name, {
808
* Handles the resize start event. Fired when a handle starts to be
811
* @event resize:start
812
* @preventable _defResizeStartFn
813
* @param {EventFacade} event The resize start event.
816
publish(EV_RESIZE_START, this._defResizeStartFn);
819
* Handles the resize event. Fired on each pixel when the handle is
822
* @event resize:resize
823
* @preventable _defResizeFn
824
* @param {EventFacade} event The resize event.
827
publish(EV_RESIZE, this._defResizeFn);
830
* Handles the resize align event.
832
* @event resize:align
833
* @preventable _defResizeAlignFn
834
* @param {EventFacade} event The resize align event.
837
publish(EV_RESIZE_ALIGN, this._defResizeAlignFn);
840
* Handles the resize end event. Fired when a handle stop to be
844
* @preventable _defResizeEndFn
845
* @param {EventFacade} event The resize end event.
848
publish(EV_RESIZE_END, this._defResizeEndFn);
851
* Handles the resize mouseUp event. Fired when a mouseUp event happens on a
854
* @event resize:mouseUp
855
* @preventable _defMouseUpFn
856
* @param {EventFacade} event The resize mouseUp event.
859
publish(EV_MOUSE_UP, this._defMouseUpFn);
863
* Responsible for loop each handle element and append to the wrapper.
865
* @method _renderHandles
868
_renderHandles: function() {
870
wrapper = instance.get(WRAPPER),
871
handlesWrapper = instance.get(HANDLES_WRAPPER);
873
instance.eachHandle(function(handleEl) {
874
handlesWrapper.append(handleEl);
877
wrapper.append(handlesWrapper);
881
* Creates the handle element based on the handle name and initialize the
884
* @method _buildHandle
885
* @param {String} handle Handle name ('t', 'tr', 'b', ...).
888
_buildHandle: function(handle) {
891
return Y.Node.create(
892
Y.Lang.sub(instance.HANDLE_TEMPLATE, {
899
* Basic resize calculations.
901
* @method _calcResize
904
_calcResize: function() {
906
handle = instance.handle,
907
info = instance.info,
908
originalInfo = instance.originalInfo,
910
dx = info.actXY[0] - originalInfo.actXY[0],
911
dy = info.actXY[1] - originalInfo.actXY[1];
913
if (handle && Y.Resize.RULES[handle]) {
914
Y.Resize.RULES[handle](instance, dx, dy);
917
Y.log('Handle rule not found: ' + handle, 'warn', 'resize');
922
* Helper method to update the current size value on
923
* <a href="Resize.html#property_info">info</a> to respect the
924
* min/max values and fix the top/left calculations.
927
* @param {String} offset 'offsetHeight' or 'offsetWidth'
928
* @param {number} size Size to restrict the offset
931
_checkSize: function(offset, size) {
933
info = instance.info,
934
originalInfo = instance.originalInfo,
935
axis = (offset === OFFSET_HEIGHT) ? TOP : LEFT;
937
// forcing the offsetHeight/offsetWidth to be the passed size
940
// predicting, based on the original information, the last left valid in case of reach the min/max dimension
941
// this calculation avoid browser event leaks when user interact very fast
942
if (((axis === LEFT) && instance.changeLeftHandles) ||
943
((axis === TOP) && instance.changeTopHandles)) {
945
info[axis] = originalInfo[axis] + originalInfo[offset] - size;
950
* Copy relevant styles of the <a href="Resize.html#attr_node">node</a>
951
* to the <a href="Resize.html#attr_wrapper">wrapper</a>.
953
* @method _copyStyles
954
* @param {Node} node Node from.
955
* @param {Node} wrapper Node to.
958
_copyStyles: function(node, wrapper) {
959
var position = node.getStyle(POSITION).toLowerCase(),
960
surrounding = this._getBoxSurroundingInfo(node),
963
// resizable wrapper should be positioned
964
if (position === STATIC) {
970
left: getCompStyle(node, LEFT),
971
top: getCompStyle(node, TOP)
974
Y.mix(wrapperStyle, surrounding.margin);
975
Y.mix(wrapperStyle, surrounding.border);
977
wrapper.setStyles(wrapperStyle);
979
// remove margin and border from the internal node
980
node.setStyles({ border: 0, margin: 0 });
983
node.get(OFFSET_WIDTH) + surrounding.totalHBorder,
984
node.get(OFFSET_HEIGHT) + surrounding.totalVBorder
988
// extract handle name from a string
989
// using Y.cached to memoize the function for performance
990
_extractHandleName: Y.cached(
992
var className = node.get(CLASS_NAME),
994
match = className.match(
996
getCN(RESIZE, HANDLE, '(\\w{1,2})\\b')
1000
return match ? match[1] : null;
1005
* <p>Generates metadata to the <a href="Resize.html#property_info">info</a>
1006
* and <a href="Resize.html#property_originalInfo">originalInfo</a></p>
1007
* <pre><code>bottom, actXY, left, top, offsetHeight, offsetWidth, right</code></pre>
1010
* @param {Node} node
1011
* @param {EventFacade} event
1014
_getInfo: function(node, event) {
1016
drag = event.dragEvent.target,
1017
nodeXY = node.getXY(),
1020
offsetHeight = node.get(OFFSET_HEIGHT),
1021
offsetWidth = node.get(OFFSET_WIDTH);
1024
// the xy that the node will be set to. Changing this will alter the position as it's dragged.
1025
actXY = (drag.actXY.length ? drag.actXY : drag.lastXY);
1030
bottom: (nodeY + offsetHeight),
1032
offsetHeight: offsetHeight,
1033
offsetWidth: offsetWidth,
1034
right: (nodeX + offsetWidth),
1040
* Each box has a content area and optional surrounding margin,
1041
* padding and * border areas. This method get all this information from
1042
* the passed node. For more reference see
1043
* <a href="http://www.w3.org/TR/CSS21/box.html#box-dimensions">
1044
* http://www.w3.org/TR/CSS21/box.html#box-dimensions</a>.
1046
* @method _getBoxSurroundingInfo
1047
* @param {Node} node
1051
_getBoxSurroundingInfo: function(node) {
1059
Y.each([ TOP, RIGHT, BOTTOM, LEFT ], function(dir) {
1060
var paddingProperty = capitalize(PADDING, dir),
1061
marginProperty = capitalize(MARGIN, dir),
1062
borderWidthProperty = capitalize(BORDER, dir, WIDTH),
1063
borderColorProperty = capitalize(BORDER, dir, COLOR),
1064
borderStyleProperty = capitalize(BORDER, dir, STYLE);
1066
info.border[borderColorProperty] = getCompStyle(node, borderColorProperty);
1067
info.border[borderStyleProperty] = getCompStyle(node, borderStyleProperty);
1068
info.border[borderWidthProperty] = getCompStyle(node, borderWidthProperty);
1069
info.margin[marginProperty] = getCompStyle(node, marginProperty);
1070
info.padding[paddingProperty] = getCompStyle(node, paddingProperty);
1074
info.totalHBorder = (toRoundNumber(info.border.borderLeftWidth) + toRoundNumber(info.border.borderRightWidth));
1075
info.totalHPadding = (toRoundNumber(info.padding.paddingLeft) + toRoundNumber(info.padding.paddingRight));
1076
info.totalVBorder = (toRoundNumber(info.border.borderBottomWidth) + toRoundNumber(info.border.borderTopWidth));
1077
info.totalVPadding = (toRoundNumber(info.padding.paddingBottom) + toRoundNumber(info.padding.paddingTop));
1083
* Sync the Resize UI with internal values from
1084
* <a href="Resize.html#property_info">info</a>.
1089
_syncUI: function() {
1090
var instance = this,
1091
info = instance.info,
1092
wrapperSurrounding = instance.wrapperSurrounding,
1093
wrapper = instance.get(WRAPPER),
1094
node = instance.get(NODE);
1096
wrapper.sizeTo(info.offsetWidth, info.offsetHeight);
1098
if (instance.changeLeftHandles || instance.changeTopHandles) {
1099
wrapper.setXY([info.left, info.top]);
1102
// if a wrap node is being used
1103
if (!wrapper.compareTo(node)) {
1104
// the original internal node borders were copied to the wrapper on
1105
// _copyStyles, to compensate that subtract the borders from the internal node
1107
info.offsetWidth - wrapperSurrounding.totalHBorder,
1108
info.offsetHeight - wrapperSurrounding.totalVBorder
1112
// prevent webkit textarea resize
1114
node.setStyle(RESIZE, NONE);
1119
* Update <code>instance.changeHeightHandles,
1120
* instance.changeLeftHandles, instance.changeTopHandles,
1121
* instance.changeWidthHandles</code> information.
1123
* @method _updateChangeHandleInfo
1126
_updateChangeHandleInfo: function(handle) {
1127
var instance = this;
1129
instance.changeHeightHandles = instance.REGEX_CHANGE_HEIGHT.test(handle);
1130
instance.changeLeftHandles = instance.REGEX_CHANGE_LEFT.test(handle);
1131
instance.changeTopHandles = instance.REGEX_CHANGE_TOP.test(handle);
1132
instance.changeWidthHandles = instance.REGEX_CHANGE_WIDTH.test(handle);
1136
* Update <a href="Resize.html#property_info">info</a> values (bottom, actXY, left, top, offsetHeight, offsetWidth, right).
1138
* @method _updateInfo
1141
_updateInfo: function(event) {
1142
var instance = this;
1144
instance.info = instance._getInfo(instance.get(WRAPPER), event);
1149
* <a href="Resize.html#property_nodeSurrounding">nodeSurrounding</a>,
1150
* <a href="Resize.html#property_nodeSurrounding">wrapperSurrounding</a>,
1151
* <a href="Resize.html#property_nodeSurrounding">totalVSurrounding</a>,
1152
* <a href="Resize.html#property_nodeSurrounding">totalHSurrounding</a>.
1154
* @method _updateSurroundingInfo
1157
_updateSurroundingInfo: function() {
1158
var instance = this,
1159
node = instance.get(NODE),
1160
wrapper = instance.get(WRAPPER),
1161
nodeSurrounding = instance._getBoxSurroundingInfo(node),
1162
wrapperSurrounding = instance._getBoxSurroundingInfo(wrapper);
1164
instance.nodeSurrounding = nodeSurrounding;
1165
instance.wrapperSurrounding = wrapperSurrounding;
1167
instance.totalVSurrounding = (nodeSurrounding.totalVPadding + wrapperSurrounding.totalVBorder);
1168
instance.totalHSurrounding = (nodeSurrounding.totalHPadding + wrapperSurrounding.totalHBorder);
1172
* Set the active state of the handles.
1174
* @method _setActiveHandlesUI
1175
* @param {boolean} val True to activate the handles, false to deactivate.
1178
_setActiveHandlesUI: function(val) {
1179
var instance = this,
1180
activeHandleNode = instance.get(ACTIVE_HANDLE_NODE);
1182
if (activeHandleNode) {
1184
// remove CSS_RESIZE_HANDLE_ACTIVE from all handles before addClass on the active
1185
instance.eachHandle(
1186
function(handleEl) {
1187
handleEl.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1191
activeHandleNode.addClass(CSS_RESIZE_HANDLE_ACTIVE);
1194
activeHandleNode.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1200
* Setter for the handles attribute
1202
* @method _setHandles
1204
* @param {String} val
1206
_setHandles: function(val) {
1207
var instance = this,
1210
// handles attr accepts both array or string
1214
else if (isString(val)) {
1215
// if the handles attr passed in is an ALL string...
1216
if (val.toLowerCase() === ALL) {
1217
handles = instance.ALL_HANDLES;
1219
// otherwise, split the string to extract the handles
1224
var handle = trim(node);
1226
// if its a valid handle, add it to the handles output
1227
if (indexOf(instance.ALL_HANDLES, handle) > -1) {
1228
handles.push(handle);
1239
* Set the visibility of the handles.
1241
* @method _setHideHandlesUI
1242
* @param {boolean} val True to hide the handles, false to show.
1245
_setHideHandlesUI: function(val) {
1246
var instance = this,
1247
wrapper = instance.get(WRAPPER);
1249
if (!instance.get(RESIZING)) {
1251
wrapper.addClass(CSS_RESIZE_HIDDEN_HANDLES);
1254
wrapper.removeClass(CSS_RESIZE_HIDDEN_HANDLES);
1260
* Setter for the wrap attribute
1264
* @param {boolean} val
1266
_setWrap: function(val) {
1267
var instance = this,
1268
node = instance.get(NODE),
1269
nodeName = node.get(NODE_NAME),
1270
typeRegex = instance.get(WRAP_TYPES);
1272
// if nodeName is listed on WRAP_TYPES force use the wrapper
1273
if (typeRegex.test(nodeName)) {
1281
* Default resize:mouseUp handler
1283
* @method _defMouseUpFn
1284
* @param {EventFacade} event The Event object
1287
_defMouseUpFn: function() {
1288
var instance = this;
1290
instance.set(RESIZING, false);
1294
* Default resize:resize handler
1296
* @method _defResizeFn
1297
* @param {EventFacade} event The Event object
1300
_defResizeFn: function(event) {
1301
var instance = this;
1303
instance._resize(event);
1307
* Logic method for _defResizeFn. Allow AOP.
1310
* @param {EventFacade} event The Event object
1313
_resize: function(event) {
1314
var instance = this;
1316
instance._handleResizeAlignEvent(event.dragEvent);
1318
// _syncUI of the wrapper, not using proxy
1323
* Default resize:align handler
1325
* @method _defResizeAlignFn
1326
* @param {EventFacade} event The Event object
1329
_defResizeAlignFn: function(event) {
1330
var instance = this;
1332
instance._resizeAlign(event);
1336
* Logic method for _defResizeAlignFn. Allow AOP.
1338
* @method _resizeAlign
1339
* @param {EventFacade} event The Event object
1342
_resizeAlign: function(event) {
1343
var instance = this,
1348
instance.lastInfo = instance.info;
1350
// update the instance.info values
1351
instance._updateInfo(event);
1353
info = instance.info;
1355
// basic resize calculations
1356
instance._calcResize();
1358
// if Y.Plugin.ResizeConstrained is not plugged, check for min dimension
1359
if (!instance.con) {
1360
defMinHeight = (instance.get(DEF_MIN_HEIGHT) + instance.totalVSurrounding);
1361
defMinWidth = (instance.get(DEF_MIN_WIDTH) + instance.totalHSurrounding);
1363
if (info.offsetHeight <= defMinHeight) {
1364
instance._checkSize(OFFSET_HEIGHT, defMinHeight);
1367
if (info.offsetWidth <= defMinWidth) {
1368
instance._checkSize(OFFSET_WIDTH, defMinWidth);
1374
* Default resize:end handler
1376
* @method _defResizeEndFn
1377
* @param {EventFacade} event The Event object
1380
_defResizeEndFn: function(event) {
1381
var instance = this;
1383
instance._resizeEnd(event);
1387
* Logic method for _defResizeEndFn. Allow AOP.
1389
* @method _resizeEnd
1390
* @param {EventFacade} event The Event object
1393
_resizeEnd: function(event) {
1394
var instance = this,
1395
drag = event.dragEvent.target;
1397
// reseting actXY from drag when drag end
1400
// syncUI when resize end
1403
instance._setActiveHandlesUI(false);
1405
instance.set(ACTIVE_HANDLE, null);
1406
instance.set(ACTIVE_HANDLE_NODE, null);
1408
instance.handle = null;
1412
* Default resize:start handler
1414
* @method _defResizeStartFn
1415
* @param {EventFacade} event The Event object
1418
_defResizeStartFn: function(event) {
1419
var instance = this;
1421
instance._resizeStart(event);
1425
* Logic method for _defResizeStartFn. Allow AOP.
1427
* @method _resizeStart
1428
* @param {EventFacade} event The Event object
1431
_resizeStart: function(event) {
1432
var instance = this,
1433
wrapper = instance.get(WRAPPER);
1435
instance.handle = instance.get(ACTIVE_HANDLE);
1437
instance.set(RESIZING, true);
1439
instance._updateSurroundingInfo();
1441
// create an originalInfo information for reference
1442
instance.originalInfo = instance._getInfo(wrapper, event);
1444
instance._updateInfo(event);
1448
* Fires the resize:mouseUp event.
1450
* @method _handleMouseUpEvent
1451
* @param {EventFacade} event resize:mouseUp event facade
1454
_handleMouseUpEvent: function(event) {
1455
this.fire(EV_MOUSE_UP, { dragEvent: event, info: this.info });
1459
* Fires the resize:resize event.
1461
* @method _handleResizeEvent
1462
* @param {EventFacade} event resize:resize event facade
1465
_handleResizeEvent: function(event) {
1466
this.fire(EV_RESIZE, { dragEvent: event, info: this.info });
1470
* Fires the resize:align event.
1472
* @method _handleResizeAlignEvent
1473
* @param {EventFacade} event resize:resize event facade
1476
_handleResizeAlignEvent: function(event) {
1477
this.fire(EV_RESIZE_ALIGN, { dragEvent: event, info: this.info });
1481
* Fires the resize:end event.
1483
* @method _handleResizeEndEvent
1484
* @param {EventFacade} event resize:end event facade
1487
_handleResizeEndEvent: function(event) {
1488
this.fire(EV_RESIZE_END, { dragEvent: event, info: this.info });
1492
* Fires the resize:start event.
1494
* @method _handleResizeStartEvent
1495
* @param {EventFacade} event resize:start event facade
1498
_handleResizeStartEvent: function(event) {
1499
if (!this.get(ACTIVE_HANDLE)) {
1500
//This handles the "touch" case
1501
this._setHandleFromNode(event.target.get('node'));
1503
this.fire(EV_RESIZE_START, { dragEvent: event, info: this.info });
1507
* Mouseenter event handler for the <a href="Resize.html#attr_wrapper">wrapper</a>.
1509
* @method _onWrapperMouseEnter
1510
* @param {EventFacade} event
1513
_onWrapperMouseEnter: function() {
1514
var instance = this;
1516
if (instance.get(AUTO_HIDE)) {
1517
instance._setHideHandlesUI(false);
1522
* Mouseleave event handler for the <a href="Resize.html#attr_wrapper">wrapper</a>.
1524
* @method _onWrapperMouseLeave
1525
* @param {EventFacade} event
1528
_onWrapperMouseLeave: function() {
1529
var instance = this;
1531
if (instance.get(AUTO_HIDE)) {
1532
instance._setHideHandlesUI(true);
1537
* Handles setting the activeHandle from a node, used from startDrag (for touch) and mouseenter (for mouse).
1539
* @method _setHandleFromNode
1540
* @param {Node} node
1543
_setHandleFromNode: function(node) {
1544
var instance = this,
1545
handle = instance._extractHandleName(node);
1547
if (!instance.get(RESIZING)) {
1548
instance.set(ACTIVE_HANDLE, handle);
1549
instance.set(ACTIVE_HANDLE_NODE, node);
1551
instance._setActiveHandlesUI(true);
1552
instance._updateChangeHandleInfo(handle);
1557
* Mouseenter event handler for the handles.
1559
* @method _onHandleMouseEnter
1560
* @param {EventFacade} event
1563
_onHandleMouseEnter: function(event) {
1564
this._setHandleFromNode(event.currentTarget);
1568
* Mouseout event handler for the handles.
1570
* @method _onHandleMouseLeave
1571
* @param {EventFacade} event
1574
_onHandleMouseLeave: function() {
1575
var instance = this;
1577
if (!instance.get(RESIZING)) {
1578
instance._setActiveHandlesUI(false);
1583
* Default value for the wrapper handles node attribute
1585
* @method _valueHandlesWrapper
1589
_valueHandlesWrapper: function() {
1590
return Y.Node.create(this.HANDLES_WRAP_TEMPLATE);
1594
* Default value for the wrapper attribute
1596
* @method _valueWrapper
1600
_valueWrapper: function() {
1601
var instance = this,
1602
node = instance.get(NODE),
1603
pNode = node.get(PARENT_NODE),
1604
// by deafult the wrapper is always the node
1607
// if the node is listed on the wrapTypes or wrap is set to true, create another wrapper
1608
if (instance.get(WRAP)) {
1609
wrapper = Y.Node.create(instance.WRAP_TEMPLATE);
1612
pNode.insertBefore(wrapper, node);
1615
wrapper.append(node);
1617
instance._copyStyles(node, wrapper);
1619
// remove positioning of wrapped node, the WRAPPER take care about positioning
1632
Y.each(Y.Resize.prototype.ALL_HANDLES, function(handle) {
1633
// creating ATTRS with the handles elements
1634
Y.Resize.ATTRS[handleAttrName(handle)] = {
1635
setter: function() {
1636
return this._buildHandle(handle);
1644
}, '@VERSION@', {"requires": ["base", "widget", "event", "oop", "dd-drag", "dd-delegate", "dd-drop"], "skinnable": true});