2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('resize-base', function(Y) {
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',
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_WRAPPER = getCN(RESIZE, WRAPPER);
137 * A base class for Resize, providing:
139 * <li>Basic Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)</li>
140 * <li>Applies drag handles to an element to make it resizable</li>
141 * <li>Here is the list of valid resize handles:
142 * <code>[ 't', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl' ]</code>. You can
143 * read this list as top, top-right, right, bottom-right, bottom,
144 * bottom-left, left, top-left.</li>
145 * <li>The drag handles are inserted into the element and positioned
146 * absolute. Some elements, such as a textarea or image, don't support
147 * children. To overcome that, set wrap:true in your config and the
148 * element willbe wrapped for you automatically.</li>
153 * <pre><code>var instance = new Y.Resize({
155 * preserveRatio: true,
159 * handles: 't, tr, r, br, b, bl, l, tl'
163 * Check the list of <a href="Resize.html#configattributes">Configuration Attributes</a> available for
167 * @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.
179 * @property Resize.NAME
186 * Static property used to define the default attribute
187 * configuration for the Resize.
189 * @property Resize.ATTRS
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 * The selector or element to resize. Required.
285 * True when the element is being Resized.
287 * @attribute resizing
297 * True to wrap an element with a div if needed (required for textareas
298 * and images, defaults to false) in favor of the handles config option.
299 * The wrapper element type (default div) could be over-riden passing the
300 * <code>wrapper</code> attribute.
313 * Elements that requires a wrapper by default. Normally are elements
314 * which cannot have children elements.
316 * @attribute wrapTypes
317 * @default /canvas|textarea|input|select|button|img/i
323 value: /^canvas|textarea|input|select|button|img|iframe|table|embed$/i
327 * Element to wrap the <code>wrapTypes</code>. This element will house
328 * the handles elements.
332 * @type String | Node
337 valueFn: '_valueWrapper',
343 b: function(instance, dx, dy) {
344 var info = instance.info,
345 originalInfo = instance.originalInfo;
347 info.offsetHeight = originalInfo.offsetHeight + dy;
350 l: function(instance, dx, dy) {
351 var info = instance.info,
352 originalInfo = instance.originalInfo;
354 info.left = originalInfo.left + dx;
355 info.offsetWidth = originalInfo.offsetWidth - dx;
358 r: function(instance, dx, dy) {
359 var info = instance.info,
360 originalInfo = instance.originalInfo;
362 info.offsetWidth = originalInfo.offsetWidth + dx;
365 t: function(instance, dx, dy) {
366 var info = instance.info,
367 originalInfo = instance.originalInfo;
369 info.top = originalInfo.top + dy;
370 info.offsetHeight = originalInfo.offsetHeight - dy;
373 tr: function(instance, dx, dy) {
374 this.t.apply(this, arguments);
375 this.r.apply(this, arguments);
378 bl: function(instance, dx, dy) {
379 this.b.apply(this, arguments);
380 this.l.apply(this, arguments);
383 br: function(instance, dx, dy) {
384 this.b.apply(this, arguments);
385 this.r.apply(this, arguments);
388 tl: function(instance, dx, dy) {
389 this.t.apply(this, arguments);
390 this.l.apply(this, arguments);
394 capitalize: capitalize
402 * Array containing all possible resizable handles.
404 * @property ALL_HANDLES
407 ALL_HANDLES: [ T, TR, R, BR, B, BL, L, TL ],
410 * Regex which matches with the handles that could change the height of
411 * the resizable element.
413 * @property REGEX_CHANGE_HEIGHT
416 REGEX_CHANGE_HEIGHT: /^(t|tr|b|bl|br|tl)$/i,
419 * Regex which matches with the handles that could change the left of
420 * the resizable element.
422 * @property REGEX_CHANGE_LEFT
425 REGEX_CHANGE_LEFT: /^(tl|l|bl)$/i,
428 * Regex which matches with the handles that could change the top of
429 * the resizable element.
431 * @property REGEX_CHANGE_TOP
434 REGEX_CHANGE_TOP: /^(tl|t|tr)$/i,
437 * Regex which matches with the handles that could change the width of
438 * the resizable element.
440 * @property REGEX_CHANGE_WIDTH
443 REGEX_CHANGE_WIDTH: /^(bl|br|l|r|tl|tr)$/i,
446 * Template used to create the resize wrapper node when needed.
448 * @property WRAP_TEMPLATE
451 WRAP_TEMPLATE: '<div class="'+CSS_RESIZE_WRAPPER+'"></div>',
454 * Template used to create each resize handle.
456 * @property HANDLE_TEMPLATE
459 HANDLE_TEMPLATE: '<div class="'+concat(CSS_RESIZE_HANDLE, CSS_RESIZE_HANDLE_PLACEHOLDER)+'">' +
460 '<div class="'+concat(CSS_RESIZE_HANDLE_INNER, CSS_RESIZE_HANDLE_INNER_PLACEHOLDER)+'"> </div>' +
465 * Each box has a content area and optional surrounding padding and
466 * border areas. This property stores the sum of all horizontal
467 * surrounding * information needed to adjust the node height.
469 * @property totalHSurrounding
473 totalHSurrounding: 0,
476 * Each box has a content area and optional surrounding padding and
477 * border areas. This property stores the sum of all vertical
478 * surrounding * information needed to adjust the node height.
480 * @property totalVSurrounding
484 totalVSurrounding: 0,
487 * Stores the <a href="Resize.html#config_node">node</a>
488 * surrounding information retrieved from
489 * <a href="Resize.html#method__getBoxSurroundingInfo">_getBoxSurroundingInfo</a>.
491 * @property nodeSurrounding
495 nodeSurrounding: null,
498 * Stores the <a href="Resize.html#config_wrapper">wrapper</a>
499 * surrounding information retrieved from
500 * <a href="Resize.html#method__getBoxSurroundingInfo">_getBoxSurroundingInfo</a>.
502 * @property wrapperSurrounding
506 wrapperSurrounding: null,
509 * Whether the handle being dragged can change the height.
511 * @property changeHeightHandles
515 changeHeightHandles: false,
518 * Whether the handle being dragged can change the left.
520 * @property changeLeftHandles
524 changeLeftHandles: false,
527 * Whether the handle being dragged can change the top.
529 * @property changeTopHandles
533 changeTopHandles: false,
536 * Whether the handle being dragged can change the width.
538 * @property changeWidthHandles
542 changeWidthHandles: false,
545 * Store DD.Delegate reference for the respective Resize instance.
554 * Stores the current values for the height, width, top and left. You are
555 * able to manipulate these values on resize in order to change the resize
565 * Stores the last values for the height, width, top and left.
574 * Stores the original values for the height, width, top and left, stored
577 * @property originalInfo
584 * Construction logic executed during Resize instantiation. Lifecycle.
586 * @method initializer
589 initializer: function() {
594 * Create the DOM structure for the Resize. Lifecycle.
599 renderUI: function() {
602 instance._renderHandles();
606 * Bind the events on the Resize UI. Lifecycle.
614 instance._createEvents();
616 instance._bindHandle();
620 * Sync the Resize UI.
628 this.get(NODE).addClass(CSS_RESIZE);
630 // hide handles if AUTO_HIDE is true
631 instance._setHideHandlesUI(
632 instance.get(AUTO_HIDE)
637 * Descructor lifecycle implementation for the Resize class. Purges events attached
638 * to the node (and all child nodes) and removes the Resize handles.
643 destructor: function() {
645 node = instance.get(NODE),
646 wrapper = instance.get(WRAPPER),
647 pNode = wrapper.get(PARENT_NODE);
649 // purgeElements on boundingBox
650 Y.Event.purgeElement(wrapper, true);
652 // destroy handles dd and remove them from the dom
653 instance.eachHandle(function(handleEl) {
654 instance.delegate.dd.destroy();
657 handleEl.remove(true);
661 if (instance.get(WRAP)) {
662 instance._copyStyles(wrapper, node);
665 pNode.insertBefore(node, wrapper);
668 wrapper.remove(true);
671 node.removeClass(CSS_RESIZE);
672 node.removeClass(CSS_RESIZE_HIDDEN_HANDLES);
676 * Creates DOM (or manipulates DOM for progressive enhancement)
677 * This method is invoked by initializer(). It's chained automatically for
678 * subclasses if required.
683 renderer: function() {
690 * <p>Loop through each handle which is being used and executes a callback.</p>
692 * <pre><code>instance.eachHandle(
693 * function(handleName, index) { ... }
697 * @param {function} fn Callback function to be executed for each handle.
699 eachHandle: function(fn) {
703 instance.get(HANDLES),
704 function(handle, i) {
705 var handleEl = instance.get(
706 handleAttrName(handle)
709 fn.apply(instance, [handleEl, handle, i]);
715 * Bind the handles DragDrop events to the Resize instance.
720 _bindDD: function() {
723 instance.delegate = new Y.DD.Delegate(
725 bubbleTargets: instance,
726 container: instance.get(WRAPPER),
733 nodes: DOT+CSS_RESIZE_HANDLE,
738 instance.on('drag:drag', instance._handleResizeEvent);
739 instance.on('drag:dropmiss', instance._handleMouseUpEvent);
740 instance.on('drag:end', instance._handleResizeEndEvent);
741 instance.on('drag:start', instance._handleResizeStartEvent);
745 * Bind the events related to the handles (_onHandleMouseEnter, _onHandleMouseLeave).
747 * @method _bindHandle
750 _bindHandle: function() {
752 wrapper = instance.get(WRAPPER);
754 wrapper.on('mouseenter', Y.bind(instance._onWrapperMouseEnter, instance));
755 wrapper.on('mouseleave', Y.bind(instance._onWrapperMouseLeave, instance));
756 wrapper.delegate('mouseenter', Y.bind(instance._onHandleMouseEnter, instance), DOT+CSS_RESIZE_HANDLE);
757 wrapper.delegate('mouseleave', Y.bind(instance._onHandleMouseLeave, instance), DOT+CSS_RESIZE_HANDLE);
761 * Create the custom events used on the Resize.
763 * @method _createEvents
766 _createEvents: function() {
768 // create publish function for kweight optimization
769 publish = function(name, fn) {
770 instance.publish(name, {
780 * Handles the resize start event. Fired when a handle starts to be
783 * @event resize:start
784 * @preventable _defResizeStartFn
785 * @param {Event.Facade} event The resize start event.
787 * @type {Event.Custom}
789 publish(EV_RESIZE_START, this._defResizeStartFn);
792 * Handles the resize event. Fired on each pixel when the handle is
795 * @event resize:resize
796 * @preventable _defResizeFn
797 * @param {Event.Facade} event The resize event.
799 * @type {Event.Custom}
801 publish(EV_RESIZE, this._defResizeFn);
804 * Handles the resize align event.
806 * @event resize:align
807 * @preventable _defResizeAlignFn
808 * @param {Event.Facade} event The resize align event.
810 * @type {Event.Custom}
812 publish(EV_RESIZE_ALIGN, this._defResizeAlignFn);
815 * Handles the resize end event. Fired when a handle stop to be
819 * @preventable _defResizeEndFn
820 * @param {Event.Facade} event The resize end event.
822 * @type {Event.Custom}
824 publish(EV_RESIZE_END, this._defResizeEndFn);
827 * Handles the resize mouseUp event. Fired when a mouseUp event happens on a
830 * @event resize:mouseUp
831 * @preventable _defMouseUpFn
832 * @param {Event.Facade} event The resize mouseUp event.
834 * @type {Event.Custom}
836 publish(EV_MOUSE_UP, this._defMouseUpFn);
840 * Responsible for loop each handle element and append to the wrapper.
842 * @method _renderHandles
845 _renderHandles: function() {
847 wrapper = instance.get(WRAPPER);
849 instance.eachHandle(function(handleEl) {
850 wrapper.append(handleEl);
855 * Creates the handle element based on the handle name and initialize the
858 * @method _buildHandle
859 * @param {String} handle Handle name ('t', 'tr', 'b', ...).
862 _buildHandle: function(handle) {
865 return Y.Node.create(
866 Y.substitute(instance.HANDLE_TEMPLATE, {
873 * Basic resize calculations.
875 * @method _calcResize
878 _calcResize: function() {
880 handle = instance.handle,
881 info = instance.info,
882 originalInfo = instance.originalInfo,
884 dx = info.actXY[0] - originalInfo.actXY[0],
885 dy = info.actXY[1] - originalInfo.actXY[1];
887 if (handle && Y.Resize.RULES[handle]) {
888 Y.Resize.RULES[handle](instance, dx, dy);
895 * Helper method to update the current size value on
896 * <a href="Resize.html#property_info">info</a> to respect the
897 * min/max values and fix the top/left calculations.
900 * @param {String} offset 'offsetHeight' or 'offsetWidth'
901 * @param {number} size Size to restrict the offset
904 _checkSize: function(offset, size) {
906 info = instance.info,
907 originalInfo = instance.originalInfo,
908 axis = (offset == OFFSET_HEIGHT) ? TOP : LEFT;
910 // forcing the offsetHeight/offsetWidth to be the passed size
913 // predicting, based on the original information, the last left valid in case of reach the min/max dimension
914 // this calculation avoid browser event leaks when user interact very fast
915 if (((axis == LEFT) && instance.changeLeftHandles) ||
916 ((axis == TOP) && instance.changeTopHandles)) {
918 info[axis] = originalInfo[axis] + originalInfo[offset] - size;
923 * Copy relevant styles of the <a href="Resize.html#config_node">node</a>
924 * to the <a href="Resize.html#config_wrapper">wrapper</a>.
926 * @method _copyStyles
927 * @param {Node} node Node from.
928 * @param {Node} wrapper Node to.
931 _copyStyles: function(node, wrapper) {
932 var position = node.getStyle(POSITION).toLowerCase(),
933 surrounding = this._getBoxSurroundingInfo(node),
936 // resizable wrapper should be positioned
937 if (position == STATIC) {
943 left: getCompStyle(node, LEFT),
944 top: getCompStyle(node, TOP)
947 Y.mix(wrapperStyle, surrounding.margin);
948 Y.mix(wrapperStyle, surrounding.border);
950 wrapper.setStyles(wrapperStyle);
952 // remove margin and border from the internal node
953 node.setStyles({ border: 0, margin: 0 });
956 node.get(OFFSET_WIDTH) + surrounding.totalHBorder,
957 node.get(OFFSET_HEIGHT) + surrounding.totalVBorder
961 // extract handle name from a string
962 // using Y.cached to memoize the function for performance
963 _extractHandleName: Y.cached(
965 var className = node.get(CLASS_NAME),
967 match = className.match(
969 getCN(RESIZE, HANDLE, '(\\w{1,2})\\b')
973 return match ? match[1] : null;
978 * <p>Generates metadata to the <a href="Resize.html#property_info">info</a>
979 * and <a href="Resize.html#property_originalInfo">originalInfo</a></p>
980 * <pre><code>bottom, actXY, left, top, offsetHeight, offsetWidth, right</code></pre>
984 * @param {EventFacade} event
987 _getInfo: function(node, event) {
989 drag = event.dragEvent.target,
990 nodeXY = node.getXY(),
993 offsetHeight = node.get(OFFSET_HEIGHT),
994 offsetWidth = node.get(OFFSET_WIDTH);
997 // the xy that the node will be set to. Changing this will alter the position as it's dragged.
998 actXY = (drag.actXY.length ? drag.actXY : drag.lastXY);
1003 bottom: (nodeY + offsetHeight),
1005 offsetHeight: offsetHeight,
1006 offsetWidth: offsetWidth,
1007 right: (nodeX + offsetWidth),
1013 * Each box has a content area and optional surrounding margin,
1014 * padding and * border areas. This method get all this information from
1015 * the passed node. For more reference see
1016 * <a href="http://www.w3.org/TR/CSS21/box.html#box-dimensions">
1017 * http://www.w3.org/TR/CSS21/box.html#box-dimensions</a>.
1019 * @method _getBoxSurroundingInfo
1020 * @param {Node} node
1024 _getBoxSurroundingInfo: function(node) {
1032 Y.each([ TOP, RIGHT, BOTTOM, LEFT ], function(dir) {
1033 var paddingProperty = capitalize(PADDING, dir),
1034 marginProperty = capitalize(MARGIN, dir),
1035 borderWidthProperty = capitalize(BORDER, dir, WIDTH),
1036 borderColorProperty = capitalize(BORDER, dir, COLOR),
1037 borderStyleProperty = capitalize(BORDER, dir, STYLE);
1039 info.border[borderColorProperty] = getCompStyle(node, borderColorProperty);
1040 info.border[borderStyleProperty] = getCompStyle(node, borderStyleProperty);
1041 info.border[borderWidthProperty] = getCompStyle(node, borderWidthProperty);
1042 info.margin[marginProperty] = getCompStyle(node, marginProperty);
1043 info.padding[paddingProperty] = getCompStyle(node, paddingProperty);
1047 info.totalHBorder = (toRoundNumber(info.border.borderLeftWidth) + toRoundNumber(info.border.borderRightWidth));
1048 info.totalHPadding = (toRoundNumber(info.padding.paddingLeft) + toRoundNumber(info.padding.paddingRight));
1049 info.totalVBorder = (toRoundNumber(info.border.borderBottomWidth) + toRoundNumber(info.border.borderTopWidth));
1050 info.totalVPadding = (toRoundNumber(info.padding.paddingBottom) + toRoundNumber(info.padding.paddingTop));
1056 * Sync the Resize UI with internal values from
1057 * <a href="Resize.html#property_info">info</a>.
1062 _syncUI: function() {
1063 var instance = this,
1064 info = instance.info,
1065 wrapperSurrounding = instance.wrapperSurrounding,
1066 wrapper = instance.get(WRAPPER),
1067 node = instance.get(NODE);
1069 wrapper.sizeTo(info.offsetWidth, info.offsetHeight);
1071 if (instance.changeLeftHandles || instance.changeTopHandles) {
1072 wrapper.setXY([info.left, info.top]);
1075 // if a wrap node is being used
1076 if (!wrapper.compareTo(node)) {
1077 // the original internal node borders were copied to the wrapper on _copyStyles, to compensate that subtract the borders from the internal node
1079 info.offsetWidth - wrapperSurrounding.totalHBorder,
1080 info.offsetHeight - wrapperSurrounding.totalVBorder
1084 // prevent webkit textarea resize
1086 node.setStyle(RESIZE, NONE);
1091 * Update <code>instance.changeHeightHandles,
1092 * instance.changeLeftHandles, instance.changeTopHandles,
1093 * instance.changeWidthHandles</code> information.
1095 * @method _updateChangeHandleInfo
1098 _updateChangeHandleInfo: function(handle) {
1099 var instance = this;
1101 instance.changeHeightHandles = instance.REGEX_CHANGE_HEIGHT.test(handle);
1102 instance.changeLeftHandles = instance.REGEX_CHANGE_LEFT.test(handle);
1103 instance.changeTopHandles = instance.REGEX_CHANGE_TOP.test(handle);
1104 instance.changeWidthHandles = instance.REGEX_CHANGE_WIDTH.test(handle);
1108 * Update <a href="Resize.html#property_info">info</a> values (bottom, actXY, left, top, offsetHeight, offsetWidth, right).
1110 * @method _updateInfo
1113 _updateInfo: function(event) {
1114 var instance = this;
1116 instance.info = instance._getInfo(instance.get(WRAPPER), event);
1121 * <a href="Resize.html#property_nodeSurrounding">nodeSurrounding</a>,
1122 * <a href="Resize.html#property_nodeSurrounding">wrapperSurrounding</a>,
1123 * <a href="Resize.html#property_nodeSurrounding">totalVSurrounding</a>,
1124 * <a href="Resize.html#property_nodeSurrounding">totalHSurrounding</a>.
1126 * @method _updateSurroundingInfo
1129 _updateSurroundingInfo: function() {
1130 var instance = this,
1131 node = instance.get(NODE),
1132 wrapper = instance.get(WRAPPER),
1133 nodeSurrounding = instance._getBoxSurroundingInfo(node),
1134 wrapperSurrounding = instance._getBoxSurroundingInfo(wrapper);
1136 instance.nodeSurrounding = nodeSurrounding;
1137 instance.wrapperSurrounding = wrapperSurrounding;
1139 instance.totalVSurrounding = (nodeSurrounding.totalVPadding + wrapperSurrounding.totalVBorder);
1140 instance.totalHSurrounding = (nodeSurrounding.totalHPadding + wrapperSurrounding.totalHBorder);
1144 * Set the active state of the handles.
1146 * @method _setActiveHandlesUI
1147 * @param {boolean} val True to activate the handles, false to deactivate.
1150 _setActiveHandlesUI: function(val) {
1151 var instance = this,
1152 activeHandleNode = instance.get(ACTIVE_HANDLE_NODE);
1154 if (activeHandleNode) {
1156 // remove CSS_RESIZE_HANDLE_ACTIVE from all handles before addClass on the active
1157 instance.eachHandle(
1158 function(handleEl) {
1159 handleEl.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1163 activeHandleNode.addClass(CSS_RESIZE_HANDLE_ACTIVE);
1166 activeHandleNode.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1172 * Setter for the handles attribute
1174 * @method _setHandles
1176 * @param {String} val
1178 _setHandles: function(val) {
1179 var instance = this,
1182 // handles attr accepts both array or string
1186 else if (isString(val)) {
1187 // if the handles attr passed in is an ALL string...
1188 if (val.toLowerCase() == ALL) {
1189 handles = instance.ALL_HANDLES;
1191 // otherwise, split the string to extract the handles
1196 var handle = trim(node);
1198 // if its a valid handle, add it to the handles output
1199 if (indexOf(instance.ALL_HANDLES, handle) > -1) {
1200 handles.push(handle);
1211 * Set the visibility of the handles.
1213 * @method _setHideHandlesUI
1214 * @param {boolean} val True to hide the handles, false to show.
1217 _setHideHandlesUI: function(val) {
1218 var instance = this,
1219 wrapper = instance.get(WRAPPER);
1221 if (!instance.get(RESIZING)) {
1223 wrapper.addClass(CSS_RESIZE_HIDDEN_HANDLES);
1226 wrapper.removeClass(CSS_RESIZE_HIDDEN_HANDLES);
1232 * Setter for the wrap attribute
1236 * @param {boolean} val
1238 _setWrap: function(val) {
1239 var instance = this,
1240 node = instance.get(NODE),
1241 nodeName = node.get(NODE_NAME),
1242 typeRegex = instance.get(WRAP_TYPES);
1244 // if nodeName is listed on WRAP_TYPES force use the wrapper
1245 if (typeRegex.test(nodeName)) {
1253 * Default resize:mouseUp handler
1255 * @method _defMouseUpFn
1256 * @param {EventFacade} event The Event object
1259 _defMouseUpFn: function(event) {
1260 var instance = this;
1262 instance.set(RESIZING, false);
1266 * Default resize:resize handler
1268 * @method _defResizeFn
1269 * @param {EventFacade} event The Event object
1272 _defResizeFn: function(event) {
1273 var instance = this;
1275 instance._resize(event);
1279 * Logic method for _defResizeFn. Allow AOP.
1282 * @param {EventFacade} event The Event object
1285 _resize: function(event) {
1286 var instance = this;
1288 instance._handleResizeAlignEvent(event.dragEvent);
1290 // _syncUI of the wrapper, not using proxy
1295 * Default resize:align handler
1297 * @method _defResizeAlignFn
1298 * @param {EventFacade} event The Event object
1301 _defResizeAlignFn: function(event) {
1302 var instance = this;
1304 instance._resizeAlign(event);
1308 * Logic method for _defResizeAlignFn. Allow AOP.
1310 * @method _resizeAlign
1311 * @param {EventFacade} event The Event object
1314 _resizeAlign: function(event) {
1315 var instance = this,
1320 instance.lastInfo = instance.info;
1322 // update the instance.info values
1323 instance._updateInfo(event);
1325 info = instance.info;
1327 // basic resize calculations
1328 instance._calcResize();
1330 // if Y.Plugin.ResizeConstrained is not plugged, check for min dimension
1331 if (!instance.con) {
1332 defMinHeight = (instance.get(DEF_MIN_HEIGHT) + instance.totalVSurrounding);
1333 defMinWidth = (instance.get(DEF_MIN_WIDTH) + instance.totalHSurrounding);
1335 if (info.offsetHeight <= defMinHeight) {
1336 instance._checkSize(OFFSET_HEIGHT, defMinHeight);
1339 if (info.offsetWidth <= defMinWidth) {
1340 instance._checkSize(OFFSET_WIDTH, defMinWidth);
1346 * Default resize:end handler
1348 * @method _defResizeEndFn
1349 * @param {EventFacade} event The Event object
1352 _defResizeEndFn: function(event) {
1353 var instance = this;
1355 instance._resizeEnd(event);
1359 * Logic method for _defResizeEndFn. Allow AOP.
1361 * @method _resizeEnd
1362 * @param {EventFacade} event The Event object
1365 _resizeEnd: function(event) {
1366 var instance = this,
1367 drag = event.dragEvent.target;
1369 // reseting actXY from drag when drag end
1372 // syncUI when resize end
1375 instance._setActiveHandlesUI(false);
1377 instance.set(ACTIVE_HANDLE, null);
1378 instance.set(ACTIVE_HANDLE_NODE, null);
1380 instance.handle = null;
1384 * Default resize:start handler
1386 * @method _defResizeStartFn
1387 * @param {EventFacade} event The Event object
1390 _defResizeStartFn: function(event) {
1391 var instance = this;
1393 instance._resizeStart(event);
1397 * Logic method for _defResizeStartFn. Allow AOP.
1399 * @method _resizeStart
1400 * @param {EventFacade} event The Event object
1403 _resizeStart: function(event) {
1404 var instance = this,
1405 wrapper = instance.get(WRAPPER);
1407 instance.handle = instance.get(ACTIVE_HANDLE);
1409 instance.set(RESIZING, true);
1411 instance._updateSurroundingInfo();
1413 // create an originalInfo information for reference
1414 instance.originalInfo = instance._getInfo(wrapper, event);
1416 instance._updateInfo(event);
1420 * Fires the resize:mouseUp event.
1422 * @method _handleMouseUpEvent
1423 * @param {EventFacade} event resize:mouseUp event facade
1426 _handleMouseUpEvent: function(event) {
1427 this.fire(EV_MOUSE_UP, { dragEvent: event, info: this.info });
1431 * Fires the resize:resize event.
1433 * @method _handleResizeEvent
1434 * @param {EventFacade} event resize:resize event facade
1437 _handleResizeEvent: function(event) {
1438 this.fire(EV_RESIZE, { dragEvent: event, info: this.info });
1442 * Fires the resize:align event.
1444 * @method _handleResizeAlignEvent
1445 * @param {EventFacade} event resize:resize event facade
1448 _handleResizeAlignEvent: function(event) {
1449 this.fire(EV_RESIZE_ALIGN, { dragEvent: event, info: this.info });
1453 * Fires the resize:end event.
1455 * @method _handleResizeEndEvent
1456 * @param {EventFacade} event resize:end event facade
1459 _handleResizeEndEvent: function(event) {
1460 this.fire(EV_RESIZE_END, { dragEvent: event, info: this.info });
1464 * Fires the resize:start event.
1466 * @method _handleResizeStartEvent
1467 * @param {EventFacade} event resize:start event facade
1470 _handleResizeStartEvent: function(event) {
1471 if (!this.get(ACTIVE_HANDLE)) {
1472 //This handles the "touch" case
1473 this._setHandleFromNode(event.target.get('node'));
1475 this.fire(EV_RESIZE_START, { dragEvent: event, info: this.info });
1479 * Mouseenter event handler for the <a href="Resize.html#config_wrapper">wrapper</a>.
1481 * @method _onWrapperMouseEnter
1482 * @param {EventFacade} event
1485 _onWrapperMouseEnter: function(event) {
1486 var instance = this;
1488 if (instance.get(AUTO_HIDE)) {
1489 instance._setHideHandlesUI(false);
1494 * Mouseleave event handler for the <a href="Resize.html#config_wrapper">wrapper</a>.
1496 * @method _onWrapperMouseLeave
1497 * @param {EventFacade} event
1500 _onWrapperMouseLeave: function(event) {
1501 var instance = this;
1503 if (instance.get(AUTO_HIDE)) {
1504 instance._setHideHandlesUI(true);
1509 * Handles setting the activeHandle from a node, used from startDrag (for touch) and mouseenter (for mouse).
1511 * @method _setHandleFromNode
1512 * @param {Node} node
1515 _setHandleFromNode: function(node) {
1516 var instance = this,
1517 handle = instance._extractHandleName(node);
1519 if (!instance.get(RESIZING)) {
1520 instance.set(ACTIVE_HANDLE, handle);
1521 instance.set(ACTIVE_HANDLE_NODE, node);
1523 instance._setActiveHandlesUI(true);
1524 instance._updateChangeHandleInfo(handle);
1529 * Mouseenter event handler for the handles.
1531 * @method _onHandleMouseEnter
1532 * @param {EventFacade} event
1535 _onHandleMouseEnter: function(event) {
1536 this._setHandleFromNode(event.currentTarget);
1540 * Mouseout event handler for the handles.
1542 * @method _onHandleMouseLeave
1543 * @param {EventFacade} event
1546 _onHandleMouseLeave: function(event) {
1547 var instance = this;
1549 if (!instance.get(RESIZING)) {
1550 instance._setActiveHandlesUI(false);
1555 * Default value for the wrapper attribute
1557 * @method _valueWrapper
1561 _valueWrapper: function() {
1562 var instance = this,
1563 node = instance.get(NODE),
1564 pNode = node.get(PARENT_NODE),
1565 // by deafult the wrapper is always the node
1568 // if the node is listed on the wrapTypes or wrap is set to true, create another wrapper
1569 if (instance.get(WRAP)) {
1570 wrapper = Y.Node.create(instance.WRAP_TEMPLATE);
1573 pNode.insertBefore(wrapper, node);
1576 wrapper.append(node);
1578 instance._copyStyles(node, wrapper);
1580 // remove positioning of wrapped node, the WRAPPER take care about positioning
1593 Y.each(Y.Resize.prototype.ALL_HANDLES, function(handle, i) {
1594 // creating ATTRS with the handles elements
1595 Y.Resize.ATTRS[handleAttrName(handle)] = {
1596 setter: function() {
1597 return this._buildHandle(handle);
1605 }, '3.3.0' ,{requires:['base', 'widget', 'substitute', 'event', 'oop', 'dd-drag', 'dd-delegate', 'dd-drop'], skinnable:true});