2 YUI 3.13.0 (build 508226d)
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);
929 Y.log('Handle rule not found: ' + handle, 'warn', 'resize');
934 * Helper method to update the current size value on
935 * <a href="Resize.html#property_info">info</a> to respect the
936 * min/max values and fix the top/left calculations.
939 * @param {String} offset 'offsetHeight' or 'offsetWidth'
940 * @param {number} size Size to restrict the offset
943 _checkSize: function(offset, size) {
945 info = instance.info,
946 originalInfo = instance.originalInfo,
947 axis = (offset === OFFSET_HEIGHT) ? TOP : LEFT;
949 // forcing the offsetHeight/offsetWidth to be the passed size
952 // predicting, based on the original information, the last left valid in case of reach the min/max dimension
953 // this calculation avoid browser event leaks when user interact very fast
954 if (((axis === LEFT) && instance.changeLeftHandles) ||
955 ((axis === TOP) && instance.changeTopHandles)) {
957 info[axis] = originalInfo[axis] + originalInfo[offset] - size;
962 * Copy relevant styles of the <a href="Resize.html#attr_node">node</a>
963 * to the <a href="Resize.html#attr_wrapper">wrapper</a>.
965 * @method _copyStyles
966 * @param {Node} node Node from.
967 * @param {Node} wrapper Node to.
970 _copyStyles: function(node, wrapper) {
971 var position = node.getStyle(POSITION).toLowerCase(),
972 surrounding = this._getBoxSurroundingInfo(node),
975 // resizable wrapper should be positioned
976 if (position === STATIC) {
982 left: getCompStyle(node, LEFT),
983 top: getCompStyle(node, TOP)
986 Y.mix(wrapperStyle, surrounding.margin);
987 Y.mix(wrapperStyle, surrounding.border);
989 wrapper.setStyles(wrapperStyle);
991 // remove margin and border from the internal node
992 node.setStyles({ border: 0, margin: 0 });
995 node.get(OFFSET_WIDTH) + surrounding.totalHBorder,
996 node.get(OFFSET_HEIGHT) + surrounding.totalVBorder
1000 // extract handle name from a string
1001 // using Y.cached to memoize the function for performance
1002 _extractHandleName: Y.cached(
1004 var className = node.get(CLASS_NAME),
1006 match = className.match(
1008 getCN(RESIZE, HANDLE, '(\\w{1,2})\\b')
1012 return match ? match[1] : null;
1017 * <p>Generates metadata to the <a href="Resize.html#property_info">info</a>
1018 * and <a href="Resize.html#property_originalInfo">originalInfo</a></p>
1019 * <pre><code>bottom, actXY, left, top, offsetHeight, offsetWidth, right</code></pre>
1022 * @param {Node} node
1023 * @param {EventFacade} event
1026 _getInfo: function(node, event) {
1028 drag = event.dragEvent.target,
1029 nodeXY = node.getXY(),
1032 offsetHeight = node.get(OFFSET_HEIGHT),
1033 offsetWidth = node.get(OFFSET_WIDTH);
1036 // the xy that the node will be set to. Changing this will alter the position as it's dragged.
1037 actXY = (drag.actXY.length ? drag.actXY : drag.lastXY);
1042 bottom: (nodeY + offsetHeight),
1044 offsetHeight: offsetHeight,
1045 offsetWidth: offsetWidth,
1046 right: (nodeX + offsetWidth),
1052 * Each box has a content area and optional surrounding margin,
1053 * padding and * border areas. This method get all this information from
1054 * the passed node. For more reference see
1055 * <a href="http://www.w3.org/TR/CSS21/box.html#box-dimensions">
1056 * http://www.w3.org/TR/CSS21/box.html#box-dimensions</a>.
1058 * @method _getBoxSurroundingInfo
1059 * @param {Node} node
1063 _getBoxSurroundingInfo: function(node) {
1071 Y.each([ TOP, RIGHT, BOTTOM, LEFT ], function(dir) {
1072 var paddingProperty = capitalize(PADDING, dir),
1073 marginProperty = capitalize(MARGIN, dir),
1074 borderWidthProperty = capitalize(BORDER, dir, WIDTH),
1075 borderColorProperty = capitalize(BORDER, dir, COLOR),
1076 borderStyleProperty = capitalize(BORDER, dir, STYLE);
1078 info.border[borderColorProperty] = getCompStyle(node, borderColorProperty);
1079 info.border[borderStyleProperty] = getCompStyle(node, borderStyleProperty);
1080 info.border[borderWidthProperty] = getCompStyle(node, borderWidthProperty);
1081 info.margin[marginProperty] = getCompStyle(node, marginProperty);
1082 info.padding[paddingProperty] = getCompStyle(node, paddingProperty);
1086 info.totalHBorder = (toRoundNumber(info.border.borderLeftWidth) + toRoundNumber(info.border.borderRightWidth));
1087 info.totalHPadding = (toRoundNumber(info.padding.paddingLeft) + toRoundNumber(info.padding.paddingRight));
1088 info.totalVBorder = (toRoundNumber(info.border.borderBottomWidth) + toRoundNumber(info.border.borderTopWidth));
1089 info.totalVPadding = (toRoundNumber(info.padding.paddingBottom) + toRoundNumber(info.padding.paddingTop));
1095 * Sync the Resize UI with internal values from
1096 * <a href="Resize.html#property_info">info</a>.
1101 _syncUI: function() {
1102 var instance = this,
1103 info = instance.info,
1104 wrapperSurrounding = instance.wrapperSurrounding,
1105 wrapper = instance.get(WRAPPER),
1106 node = instance.get(NODE);
1108 wrapper.sizeTo(info.offsetWidth, info.offsetHeight);
1110 if (instance.changeLeftHandles || instance.changeTopHandles) {
1111 wrapper.setXY([info.left, info.top]);
1114 // if a wrap node is being used
1115 if (!wrapper.compareTo(node)) {
1116 // the original internal node borders were copied to the wrapper on
1117 // _copyStyles, to compensate that subtract the borders from the internal node
1119 info.offsetWidth - wrapperSurrounding.totalHBorder,
1120 info.offsetHeight - wrapperSurrounding.totalVBorder
1124 // prevent webkit textarea resize
1126 node.setStyle(RESIZE, NONE);
1131 * Update <code>instance.changeHeightHandles,
1132 * instance.changeLeftHandles, instance.changeTopHandles,
1133 * instance.changeWidthHandles</code> information.
1135 * @method _updateChangeHandleInfo
1138 _updateChangeHandleInfo: function(handle) {
1139 var instance = this;
1141 instance.changeHeightHandles = instance.REGEX_CHANGE_HEIGHT.test(handle);
1142 instance.changeLeftHandles = instance.REGEX_CHANGE_LEFT.test(handle);
1143 instance.changeTopHandles = instance.REGEX_CHANGE_TOP.test(handle);
1144 instance.changeWidthHandles = instance.REGEX_CHANGE_WIDTH.test(handle);
1148 * Update <a href="Resize.html#property_info">info</a> values (bottom, actXY, left, top, offsetHeight, offsetWidth, right).
1150 * @method _updateInfo
1153 _updateInfo: function(event) {
1154 var instance = this;
1156 instance.info = instance._getInfo(instance.get(WRAPPER), event);
1161 * <a href="Resize.html#property_nodeSurrounding">nodeSurrounding</a>,
1162 * <a href="Resize.html#property_nodeSurrounding">wrapperSurrounding</a>,
1163 * <a href="Resize.html#property_nodeSurrounding">totalVSurrounding</a>,
1164 * <a href="Resize.html#property_nodeSurrounding">totalHSurrounding</a>.
1166 * @method _updateSurroundingInfo
1169 _updateSurroundingInfo: function() {
1170 var instance = this,
1171 node = instance.get(NODE),
1172 wrapper = instance.get(WRAPPER),
1173 nodeSurrounding = instance._getBoxSurroundingInfo(node),
1174 wrapperSurrounding = instance._getBoxSurroundingInfo(wrapper);
1176 instance.nodeSurrounding = nodeSurrounding;
1177 instance.wrapperSurrounding = wrapperSurrounding;
1179 instance.totalVSurrounding = (nodeSurrounding.totalVPadding + wrapperSurrounding.totalVBorder);
1180 instance.totalHSurrounding = (nodeSurrounding.totalHPadding + wrapperSurrounding.totalHBorder);
1184 * Set the active state of the handles.
1186 * @method _setActiveHandlesUI
1187 * @param {boolean} val True to activate the handles, false to deactivate.
1190 _setActiveHandlesUI: function(val) {
1191 var instance = this,
1192 activeHandleNode = instance.get(ACTIVE_HANDLE_NODE);
1194 if (activeHandleNode) {
1196 // remove CSS_RESIZE_HANDLE_ACTIVE from all handles before addClass on the active
1197 instance.eachHandle(
1198 function(handleEl) {
1199 handleEl.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1203 activeHandleNode.addClass(CSS_RESIZE_HANDLE_ACTIVE);
1206 activeHandleNode.removeClass(CSS_RESIZE_HANDLE_ACTIVE);
1212 * Setter for the handles attribute
1214 * @method _setHandles
1216 * @param {String} val
1218 _setHandles: function(val) {
1219 var instance = this,
1222 // handles attr accepts both array or string
1226 else if (isString(val)) {
1227 // if the handles attr passed in is an ALL string...
1228 if (val.toLowerCase() === ALL) {
1229 handles = instance.ALL_HANDLES;
1231 // otherwise, split the string to extract the handles
1236 var handle = trim(node);
1238 // if its a valid handle, add it to the handles output
1239 if (indexOf(instance.ALL_HANDLES, handle) > -1) {
1240 handles.push(handle);
1251 * Set the visibility of the handles.
1253 * @method _setHideHandlesUI
1254 * @param {boolean} val True to hide the handles, false to show.
1257 _setHideHandlesUI: function(val) {
1258 var instance = this,
1259 wrapper = instance.get(WRAPPER);
1261 if (!instance.get(RESIZING)) {
1263 wrapper.addClass(CSS_RESIZE_HIDDEN_HANDLES);
1266 wrapper.removeClass(CSS_RESIZE_HIDDEN_HANDLES);
1272 * Setter for the wrap attribute
1276 * @param {boolean} val
1278 _setWrap: function(val) {
1279 var instance = this,
1280 node = instance.get(NODE),
1281 nodeName = node.get(NODE_NAME),
1282 typeRegex = instance.get(WRAP_TYPES);
1284 // if nodeName is listed on WRAP_TYPES force use the wrapper
1285 if (typeRegex.test(nodeName)) {
1293 * Default resize:mouseUp handler
1295 * @method _defMouseUpFn
1296 * @param {EventFacade} event The Event object
1299 _defMouseUpFn: function() {
1300 var instance = this;
1302 instance.set(RESIZING, false);
1306 * Default resize:resize handler
1308 * @method _defResizeFn
1309 * @param {EventFacade} event The Event object
1312 _defResizeFn: function(event) {
1313 var instance = this;
1315 instance._resize(event);
1319 * Logic method for _defResizeFn. Allow AOP.
1322 * @param {EventFacade} event The Event object
1325 _resize: function(event) {
1326 var instance = this;
1328 instance._handleResizeAlignEvent(event.dragEvent);
1330 // _syncUI of the wrapper, not using proxy
1335 * Default resize:align handler
1337 * @method _defResizeAlignFn
1338 * @param {EventFacade} event The Event object
1341 _defResizeAlignFn: function(event) {
1342 var instance = this;
1344 instance._resizeAlign(event);
1348 * Logic method for _defResizeAlignFn. Allow AOP.
1350 * @method _resizeAlign
1351 * @param {EventFacade} event The Event object
1354 _resizeAlign: function(event) {
1355 var instance = this,
1360 instance.lastInfo = instance.info;
1362 // update the instance.info values
1363 instance._updateInfo(event);
1365 info = instance.info;
1367 // basic resize calculations
1368 instance._calcResize();
1370 // if Y.Plugin.ResizeConstrained is not plugged, check for min dimension
1371 if (!instance.con) {
1372 defMinHeight = (instance.get(DEF_MIN_HEIGHT) + instance.totalVSurrounding);
1373 defMinWidth = (instance.get(DEF_MIN_WIDTH) + instance.totalHSurrounding);
1375 if (info.offsetHeight <= defMinHeight) {
1376 instance._checkSize(OFFSET_HEIGHT, defMinHeight);
1379 if (info.offsetWidth <= defMinWidth) {
1380 instance._checkSize(OFFSET_WIDTH, defMinWidth);
1386 * Default resize:end handler
1388 * @method _defResizeEndFn
1389 * @param {EventFacade} event The Event object
1392 _defResizeEndFn: function(event) {
1393 var instance = this;
1395 instance._resizeEnd(event);
1399 * Logic method for _defResizeEndFn. Allow AOP.
1401 * @method _resizeEnd
1402 * @param {EventFacade} event The Event object
1405 _resizeEnd: function(event) {
1406 var instance = this,
1407 drag = event.dragEvent.target;
1409 // reseting actXY from drag when drag end
1412 // syncUI when resize end
1415 instance._setActiveHandlesUI(false);
1417 instance.set(ACTIVE_HANDLE, null);
1418 instance.set(ACTIVE_HANDLE_NODE, null);
1420 instance.handle = null;
1424 * Default resize:start handler
1426 * @method _defResizeStartFn
1427 * @param {EventFacade} event The Event object
1430 _defResizeStartFn: function(event) {
1431 var instance = this;
1433 instance._resizeStart(event);
1437 * Logic method for _defResizeStartFn. Allow AOP.
1439 * @method _resizeStart
1440 * @param {EventFacade} event The Event object
1443 _resizeStart: function(event) {
1444 var instance = this,
1445 wrapper = instance.get(WRAPPER);
1447 instance.handle = instance.get(ACTIVE_HANDLE);
1449 instance.set(RESIZING, true);
1451 instance._updateSurroundingInfo();
1453 // create an originalInfo information for reference
1454 instance.originalInfo = instance._getInfo(wrapper, event);
1456 instance._updateInfo(event);
1460 * Fires the resize:mouseUp event.
1462 * @method _handleMouseUpEvent
1463 * @param {EventFacade} event resize:mouseUp event facade
1466 _handleMouseUpEvent: function(event) {
1467 this.fire(EV_MOUSE_UP, { dragEvent: event, info: this.info });
1471 * Fires the resize:resize event.
1473 * @method _handleResizeEvent
1474 * @param {EventFacade} event resize:resize event facade
1477 _handleResizeEvent: function(event) {
1478 this.fire(EV_RESIZE, { dragEvent: event, info: this.info });
1482 * Fires the resize:align event.
1484 * @method _handleResizeAlignEvent
1485 * @param {EventFacade} event resize:resize event facade
1488 _handleResizeAlignEvent: function(event) {
1489 this.fire(EV_RESIZE_ALIGN, { dragEvent: event, info: this.info });
1493 * Fires the resize:end event.
1495 * @method _handleResizeEndEvent
1496 * @param {EventFacade} event resize:end event facade
1499 _handleResizeEndEvent: function(event) {
1500 this.fire(EV_RESIZE_END, { dragEvent: event, info: this.info });
1504 * Fires the resize:start event.
1506 * @method _handleResizeStartEvent
1507 * @param {EventFacade} event resize:start event facade
1510 _handleResizeStartEvent: function(event) {
1511 if (!this.get(ACTIVE_HANDLE)) {
1512 //This handles the "touch" case
1513 this._setHandleFromNode(event.target.get('node'));
1515 this.fire(EV_RESIZE_START, { dragEvent: event, info: this.info });
1519 * Mouseenter event handler for the <a href="Resize.html#attr_wrapper">wrapper</a>.
1521 * @method _onWrapperMouseEnter
1522 * @param {EventFacade} event
1525 _onWrapperMouseEnter: function() {
1526 var instance = this;
1528 if (instance.get(AUTO_HIDE)) {
1529 instance._setHideHandlesUI(false);
1534 * Mouseleave event handler for the <a href="Resize.html#attr_wrapper">wrapper</a>.
1536 * @method _onWrapperMouseLeave
1537 * @param {EventFacade} event
1540 _onWrapperMouseLeave: function() {
1541 var instance = this;
1543 if (instance.get(AUTO_HIDE)) {
1544 instance._setHideHandlesUI(true);
1549 * Handles setting the activeHandle from a node, used from startDrag (for touch) and mouseenter (for mouse).
1551 * @method _setHandleFromNode
1552 * @param {Node} node
1555 _setHandleFromNode: function(node) {
1556 var instance = this,
1557 handle = instance._extractHandleName(node);
1559 if (!instance.get(RESIZING)) {
1560 instance.set(ACTIVE_HANDLE, handle);
1561 instance.set(ACTIVE_HANDLE_NODE, node);
1563 instance._setActiveHandlesUI(true);
1564 instance._updateChangeHandleInfo(handle);
1569 * Mouseenter event handler for the handles.
1571 * @method _onHandleMouseEnter
1572 * @param {EventFacade} event
1575 _onHandleMouseEnter: function(event) {
1576 this._setHandleFromNode(event.currentTarget);
1580 * Mouseout event handler for the handles.
1582 * @method _onHandleMouseLeave
1583 * @param {EventFacade} event
1586 _onHandleMouseLeave: function() {
1587 var instance = this;
1589 if (!instance.get(RESIZING)) {
1590 instance._setActiveHandlesUI(false);
1595 * Default value for the wrapper handles node attribute
1597 * @method _valueHandlesWrapper
1601 _valueHandlesWrapper: function() {
1602 return Y.Node.create(this.HANDLES_WRAP_TEMPLATE);
1606 * Default value for the wrapper attribute
1608 * @method _valueWrapper
1612 _valueWrapper: function() {
1613 var instance = this,
1614 node = instance.get(NODE),
1615 pNode = node.get(PARENT_NODE),
1616 // by deafult the wrapper is always the node
1619 // if the node is listed on the wrapTypes or wrap is set to true, create another wrapper
1620 if (instance.get(WRAP)) {
1621 wrapper = Y.Node.create(instance.WRAP_TEMPLATE);
1624 pNode.insertBefore(wrapper, node);
1627 wrapper.append(node);
1629 instance._copyStyles(node, wrapper);
1631 // remove positioning of wrapped node, the WRAPPER take care about positioning
1644 Y.each(Y.Resize.prototype.ALL_HANDLES, function(handle) {
1645 // creating ATTRS with the handles elements
1646 Y.Resize.ATTRS[handleAttrName(handle)] = {
1647 setter: function() {
1648 return this._buildHandle(handle);
1656 }, '3.13.0', {"requires": ["base", "widget", "event", "oop", "dd-drag", "dd-delegate", "dd-drop"], "skinnable": true});