resize-base-debug.js revision b451f8781c6f461e76013de8c464ba9c26c37161
/**
* The Resize Utility allows you to make an HTML element resizable.
*
* @module resize
*/
DOT = '.',
COMMA = ',',
SPACE = ' ',
ACTIVE = 'active',
ACTIVE_HANDLE = 'activeHandle',
ACTIVE_HANDLE_EL = 'activeHandleEl',
ALL = 'all',
AUTO_HIDE = 'autoHide',
BOTTOM = 'bottom',
CLASS_NAME = 'className',
CURSOR = 'cursor',
DRAG_CURSOR = 'dragCursor',
HANDLE = 'handle',
HANDLES = 'handles',
HIDDEN = 'hidden',
INNER = 'inner',
LEFT = 'left',
MARGIN = 'margin',
NODE = 'node',
NODE_NAME = 'nodeName',
NONE = 'none',
OFFSET_HEIGHT = 'offsetHeight',
OFFSET_WIDTH = 'offsetWidth',
PARENT_NODE = 'parentNode',
POSITION = 'position',
PROXY = 'proxy',
PROXY_EL = 'proxyEl',
RELATIVE = 'relative',
RESIZE = 'resize',
RESIZING = 'resizing',
RIGHT = 'right',
STATIC = 'static',
TOP = 'top',
WRAP = 'wrap',
WRAPPER = 'wrapper',
WRAP_TYPES = 'wrapTypes',
EV_MOUSE_UP = 'resize:mouseUp',
EV_RESIZE = 'resize:resize',
EV_RESIZE_ALIGN = 'resize:align',
EV_RESIZE_END = 'resize:end',
EV_RESIZE_START = 'resize:start',
T = 't',
TR = 'tr',
R = 'r',
BR = 'br',
B = 'b',
BL = 'bl',
L = 'l',
TL = 'tl',
isNode = function(v) {
return (v instanceof Y.Node);
},
handleAttrName = function(handle) {
},
concat = function() {
},
toInitialCap = Y.cached(
function(str) {
}
),
'<div class="'+concat(CSS_RESIZE_HANDLE_INNER, CSS_RESIZE_HANDLE_INNER_PLACEHOLDER)+'"> </div>' +
'</div>',
/**
* A base class for Resize, providing:
* <ul>
* <li>Basic Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)</li>
* <li>Applies drag handles to an element to make it resizable</li>
* <li>Here is the list of valid resize handles:
* <code>[ 't', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl' ]</code>. You can
* read this list as top, top-right, right, bottom-right, bottom,
* bottom-left, left, top-left.</li>
* <li>The drag handles are inserted into the element and positioned
* absolute. Some elements, such as a textarea or image, don't support
* children. To overcome that, set wrap:true in your config and the
* element willbe wrapped for you automatically.</li>
* </ul>
*
* Quick Example:
*
* <pre><code>var instance = new Y.Resize({
* node: '#resize1',
* proxy: true,
* preserveRatio: true,
* wrap: true,
* maxHeight: 170,
* maxWidth: 400,
* handles: 't, tr, r, br, b, bl, l, tl'
* });
* </code></pre>
*
* Check the list of <a href="Resize.html#configattributes">Configuration Attributes</a> available for
* Resize.
*
* @class Resize
* @param config {Object} Object literal specifying widget configuration properties.
* @constructor
* @extends Base
*/
function Resize() {
}
/**
* Static property provides a string to identify the class.
*
* @property Resize.NAME
* @type String
* @static
*/
/**
* Static property used to define the default attribute
* configuration for the Resize.
*
* @property Resize.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* Stores the active handle during the resize.
*
* @attribute activeHandle
* @default null
* @private
* @type String
*/
activeHandle: {
value: null,
},
/**
* Stores the active handle element during the resize.
*
* @attribute activeHandleEl
* @default null
* @private
* @type Node
*/
value: null,
},
/**
* False to ensure that the resize handles are always visible, true to
* display them only when the user mouses over the resizable borders.
*
* @attribute autoHide
* @default false
* @type boolean
*/
autoHide: {
value: false,
},
/**
* The handles to use (any combination of): 't', 'b', 'r', 'l', 'bl',
* 'br', 'tl', 'tr'. Can use a shortcut of All.
*
* @attribute handles
* @default all
* @type Array | String
*/
handles: {
setter: '_setHandles',
},
/**
* The selector or element to resize. Required.
*
* @attribute node
* @type Node
*/
node: {
},
/**
* Resize a proxy element instead of the real element.
*
* @attribute proxy
* @default false
* @type boolean
*/
proxy: {
value: false,
},
/**
* The Resize proxy element.
*
* @attribute proxyEl
* @default Generated using an internal HTML markup
* @type String | Node
*/
proxyEl: {
valueFn: function() {
}
},
/**
* True when the element is being Resized.
*
* @attribute resizing
* @default false
* @type boolean
*/
resizing: {
value: false,
},
/**
* True to wrap an element with a div if needed (required for textareas
* and images, defaults to false) in favor of the handles config option.
* The wrapper element type (default div) could be over-riden passing the
* <code>wrapper</code> attribute.
*
* @attribute wrap
* @default false
* @type boolean
*/
wrap: {
setter: '_setWrap',
value: false,
},
/**
* Elements that requires a wrapper by default. Normally are elements
* which cannot have children elements.
*
* @attribute wrapTypes
* @default /canvas|textarea|input|select|button|img/i
* @readOnly
* @type Regex
*/
wrapTypes: {
readOnly: true,
},
/**
* Element to wrap the <code>wrapTypes</code>. This element will house
* the handles elements.
*
* @attribute wrapper
* @default div
* @type String | Node
* @writeOnce
*/
wrapper: {
setter: '_setWrapper',
value: null,
writeOnce: true
}
}
});
Y.Base,
{
/**
* Whether the handle being dragged can change the height.
*
* @property changeHeightHandles
* @default false
* @type boolean
*/
changeHeightHandles: false,
/**
* Whether the handle being dragged can change the left.
*
* @property changeLeftHandles
* @default false
* @type boolean
*/
changeLeftHandles: false,
/**
* Whether the handle being dragged can change the top.
*
* @property changeTopHandles
* @default false
* @type boolean
*/
changeTopHandles: false,
/**
* Whether the handle being dragged can change the width.
*
* @property changeWidthHandles
* @default false
* @type boolean
*/
changeWidthHandles: false,
/**
* Store DD.Delegate reference for the respective Resize instance.
*
* @property delegate
* @default null
* @type Object
*/
delegate: null,
/**
* Stores the current values for the height, width, top and left. You are
* able to manipulate these values on resize in order to change the resize
* behavior.
*
* @property info
* @type Object
* @protected
*/
info: null,
/**
* Stores the last values for the height, width, top and left.
*
* @property lastInfo
* @type Object
* @protected
*/
lastInfo: null,
/**
* Stores the original values for the height, width, top and left, stored
* on resize start.
*
* @property originalInfo
* @type Object
* @protected
*/
originalInfo: null,
/**
* Construction logic executed during Resize instantiation. Lifecycle.
*
* @method initializer
* @protected
*/
initializer: function() {
var instance = this;
instance.originalInfo = {};
},
/**
* Create the DOM structure for the Resize. Lifecycle.
*
* @method renderUI
* @protected
*/
renderUI: function() {
var instance = this;
},
/**
* Bind the events on the Resize UI. Lifecycle.
*
* @method bindUI
* @protected
*/
bindUI: function() {
var instance = this;
},
/**
* Sync the Resize UI.
*
* @method syncUI
* @protected
*/
syncUI: function() {
var instance = this;
// hide handles if AUTO_HIDE is true
);
},
/**
* Descructor lifecycle implementation for the Resize class. Purges events attached
* to the node (and all child nodes) and removes the Resize handles.
*
* @method destructor
* @protected
*/
destructor: function() {
var instance = this,
// purgeElements on boundingBox
// destroy handles dd and remove them from the dom
// remove handle
});
// unwrap node
});
if (pNode) {
}
// wrapper.placeBefore(node);
}
},
/**
* Creates DOM (or manipulates DOM for progressive enhancement)
* This method is invoked by initializer(). It's chained automatically for
* subclasses if required.
*
* @method renderer
* @protected
*/
renderer: function() {
this.renderUI();
this.bindUI();
this.syncUI();
},
/**
* <p>Loop through each handle which is being used and executes a callback.</p>
* <p>Example:</p>
* <pre><code>instance.eachHandle(
* function(handleName, index) { ... }
* );</code></pre>
*
* @method eachHandle
* @param {function} fn Callback function to be executed for each handle.
*/
eachHandle: function(fn) {
var instance = this;
Y.each(
function(handle, i) {
);
}
);
},
/**
* Bind the handles DragDrop events to the Resize instance.
*
* @method _bindDD
* @private
*/
_bindDD: function() {
var instance = this;
{
dragConfig: {
clickPixelThresh: 0,
clickTimeThresh: 0,
useShim: true,
move: false
},
target: false
}
);
},
/**
* Bind the events related to the handles (_onHandleMouseEnter, _onHandleMouseLeave).
*
* @method _bindHandle
* @private
*/
_bindHandle: function() {
var instance = this,
wrapper.delegate('mouseenter', Y.bind(instance._onHandleMouseEnter, instance), DOT+CSS_RESIZE_HANDLE);
wrapper.delegate('mouseleave', Y.bind(instance._onHandleMouseLeave, instance), DOT+CSS_RESIZE_HANDLE);
},
/**
* Create the custom events used on the Resize.
*
* @method _createEvents
* @private
*/
_createEvents: function() {
var instance = this,
// create publish function for kweight optimization
queuable: false,
emitFacade: true,
bubbles: true,
});
};
/**
* Handles the resize start event. Fired when a handle starts to be
* dragged.
*
* @event resize:start
* @preventable _defResizeStartFn
* @param {Event.Facade} event The resize start event.
* @bubbles Resize
* @type {Event.Custom}
*/
/**
* Handles the resize event. Fired on each pixel when the handle is
* being dragged.
*
* @event resize:resize
* @preventable _defResizeFn
* @param {Event.Facade} event The resize event.
* @bubbles Resize
* @type {Event.Custom}
*/
/**
* Handles the resize align event.
*
* @event resize:align
* @preventable _defResizeAlignFn
* @param {Event.Facade} event The resize align event.
* @bubbles Resize
* @type {Event.Custom}
*/
/**
* Handles the resize end event. Fired when a handle stop to be
* dragged.
*
* @event resize:end
* @preventable _defResizeEndFn
* @param {Event.Facade} event The resize end event.
* @bubbles Resize
* @type {Event.Custom}
*/
/**
* Handles the resize mouseUp event. Fired when a mouseUp event happens on a
* handle.
*
* @event resize:mouseUp
* @preventable _defMouseUpFn
* @param {Event.Facade} event The resize mouseUp event.
* @bubbles Resize
* @type {Event.Custom}
*/
},
/**
* Responsible for loop each handle element and append to the wrapper.
*
* @method _renderHandles
* @protected
*/
_renderHandles: function() {
var instance = this,
});
},
/**
* Render the <a href="Resize.html#config_proxyEl">proxyEl</a> element and
* make it sibling of the <a href="Resize.html#config_node">node</a>.
*
* @method _renderProxy
* @protected
*/
_renderProxy: function() {
var instance = this,
);
},
/**
* Creates the handle element based on the handle name and initialize the
* DragDrop on it.
*
* @method _buildHandle
* @param {String} handle Handle name ('t', 'tr', 'b', ...).
* @protected
*/
_buildHandle: function(handle) {
Y.substitute(TPL_HANDLE, {
})
);
},
/**
* Helper method to update the current size value on
* <a href="Resize.html#property_info">info</a> to respect the
*
* @method _checkSize
* @param {String} offset 'offsetHeight' or 'offsetWidth'
* @param {number} size Size to restrict the offset
* @protected
*/
var instance = this,
// forcing the offsetHeight/offsetWidth to be the passed size
// predicting, based on the original information, the last left valid in case of reach the min/max dimension
// this calculation avoid browser event leaks when user interact very fast with their mouse
}
},
/**
* Copy relevant styles of the <a href="Resize.html#config_node">node</a>
* to the <a href="Resize.html#config_wrapper">wrapper</a>.
*
* @method _copyStyles
* @param {Node} node Node from.
* @param {Node} wrapper Node to.
* @protected
*/
nodeStyle = {},
// resizable wrapper should be positioned
}
// copy margin, padding, position styles from the node to wrapper
wrapperStyle = {
};
// store margin(Top,Right,Bottom,Left) from the nodes involved
// apply margin from node to the wrapper
});
// force remove margin from the internal node
);
);
},
// extract handle name from a string
// using Y.cached to memoize the function for performance
function(node) {
new RegExp(
)
);
}
),
/**
* <p>Generates metadata to the <a href="Resize.html#property_info">info</a>
* and <a href="Resize.html#property_originalInfo">originalInfo</a></p>
* <pre><code>bottom, actXY, left, top, offsetHeight, offsetWidth, right</code></pre>
*
* @method _getInfo
* @param {Node} node
* @param {EventFacade} event
* @private
*/
var actXY,
if (event) {
// the xy that the node will be set to. Changing this will alter the position as it's dragged.
}
return {
};
},
/**
* Basic resize calculations.
*
* @method _resize
* @protected
*/
_resize: function() {
var instance = this,
rules = {
t: function() {
},
r: function() {
},
l: function() {
},
b: function() {
},
tr: function() {
this.t();
this.r();
},
br: function() {
this.b();
this.r();
},
tl: function() {
this.t();
this.l();
},
bl: function() {
this.b();
this.l();
}
};
},
/**
* Set offsetWidth and offsetHeight of the passed node.
*
* @method _setOffset
* @param {Node} node Node
* @param {number} offsetWidth
* @param {number} offsetHeight
* @protected
*/
},
/**
* Sync the Resize UI with internal values from
* <a href="Resize.html#property_info">info</a>.
*
* @method _syncUI
* @protected
*/
_syncUI: function() {
var instance = this,
}
// if wrapper is different from node
}
// prevent webkit textarea resize
}
},
/**
* Sync the proxy UI with internal values from
* <a href="Resize.html#property_info">info</a>.
*
* @method _syncProxyUI
* @protected
*/
_syncProxyUI: function() {
var instance = this,
},
/**
* Update <code>instance.changeHeightHandles,
* instance.changeLeftHandles, instance.changeTopHandles,
* instance.changeWidthHandles</code> information.
*
* @method _updateChangeHandleInfo
* @private
*/
_updateChangeHandleInfo: function(handle) {
var instance = this;
},
/**
* Update <a href="Resize.html#property_info">info</a> values (bottom, actXY, left, top, offsetHeight, offsetWidth, right).
*
* @method _updateInfo
* @private
*/
_updateInfo: function(event) {
var instance = this;
},
/**
* Set the active state of the handles.
*
* @method _setActiveHandlesUI
* @param {boolean} val True to activate the handles, false to deactivate.
* @protected
*/
_setActiveHandlesUI: function(val) {
var instance = this,
if (activeHandleEl) {
if (val) {
// remove CSS_RESIZE_HANDLE_ACTIVE from all handles before addClass on the active
function(handleEl) {
}
);
}
else {
}
}
},
/**
* Setter for the handles attribute
*
* @method _setHandles
* @protected
* @param {String} val
*/
_setHandles: function(val) {
var handles = [];
// handles attr accepts both array or string
}
// if the handles attr passed in is an ALL string...
}
// otherwise, split the string to extract the handles
else {
Y.each(
function(node, i) {
// if its a valid handle, add it to the handles output
}
}
);
}
}
return handles;
},
/**
* Set the visibility of the handles.
*
* @method _setHideHandlesUI
* @param {boolean} val True to hide the handles, false to show.
* @protected
*/
_setHideHandlesUI: function(val) {
var instance = this,
if (val) {
}
else {
}
}
},
/**
* Setter for the wrap attribute
*
* @method _setWrap
* @protected
* @param {boolean} val
*/
var instance = this,
// if nodeName is listed on WRAP_TYPES force use the wrapper
val = true;
}
return val;
},
/**
* Setter for the wrapper attribute
*
* @method _setWrapper
* @protected
* @readOnly
*/
_setWrapper: function() {
var instance = this,
// by deafult the wrapper is always the node
// if the node is listed on the wrapTypes or wrap is set to true, create another wrapper
if (pNode) {
}
// node.placeBefore(wrapper);
// remove positioning of wrapped node, the WRAPPER take care about positioning
left: 0,
top: 0
});
}
return wrapper;
},
/**
* Default resize:mouseUp handler
*
* @method _defMouseUpFn
* @param {EventFacade} event The Event object
* @protected
*/
_defMouseUpFn: function(event) {
var instance = this;
},
/**
* Default resize:resize handler
*
* @method _defResizeFn
* @param {EventFacade} event The Event object
* @protected
*/
_defResizeFn: function(event) {
var instance = this;
// if proxy is true _syncProxyUI instead of _syncUI
}
else {
// _syncUI of the wrapper, not using proxy
}
},
/**
* Default resize:align handler
*
* @method _defResizeAlignFn
* @param {EventFacade} event The Event object
* @protected
*/
_defResizeAlignFn: function(event) {
// update the instance.info values
// basic resize calculations
// if Y.Plugin.ResizeConstrained is not plugged, check for min dimension
}
}
}
},
/**
* Default resize:end handler
*
* @method _defResizeEndFn
* @param {EventFacade} event The Event object
* @protected
*/
_defResizeEndFn: function(event) {
var instance = this,
// reseting actXY from drag when drag end
// if proxy is true, hide it on resize end
}
// syncUI when resize end
instance._setActiveHandlesUI(false);
},
/**
* Default resize:start handler
*
* @method _defResizeStartFn
* @param {EventFacade} event The Event object
* @protected
*/
_defResizeStartFn: function(event) {
var instance = this;
// create an originalInfo information for reference
},
/**
* Fires the resize:mouseUp event.
*
* @method _handleMouseUpEvent
* @param {EventFacade} event resize:mouseUp event facade
* @protected
*/
_handleMouseUpEvent: function(event) {
},
/**
* Fires the resize:resize event.
*
* @method _handleResizeEvent
* @param {EventFacade} event resize:resize event facade
* @protected
*/
_handleResizeEvent: function(event) {
},
/**
* Fires the resize:align event.
*
* @method _handleResizeAlignEvent
* @param {EventFacade} event resize:resize event facade
* @protected
*/
_handleResizeAlignEvent: function(event) {
},
/**
* Fires the resize:end event.
*
* @method _handleResizeEndEvent
* @param {EventFacade} event resize:end event facade
* @protected
*/
_handleResizeEndEvent: function(event) {
},
/**
* Fires the resize:start event.
*
* @method _handleResizeStartEvent
* @param {EventFacade} event resize:start event facade
* @protected
*/
_handleResizeStartEvent: function(event) {
},
/**
* Mouseenter event handler for the <a href="Resize.html#config_wrapper">wrapper</a>.
*
* @method _onWrapperMouseEnter
* @param {EventFacade} event
* @protected
*/
_onWrapperMouseEnter: function(event) {
var instance = this;
instance._setHideHandlesUI(false);
}
},
/**
* Mouseleave event handler for the <a href="Resize.html#config_wrapper">wrapper</a>.
*
* @method _onWrapperMouseLeave
* @param {EventFacade} event
* @protected
*/
_onWrapperMouseLeave: function(event) {
var instance = this;
instance._setHideHandlesUI(true);
}
},
/**
* Mouseover event handler for the handles.
*
* @method _onHandleMouseEnter
* @param {EventFacade} event
* @protected
*/
_onHandleMouseEnter: function(event) {
var instance = this,
instance._setActiveHandlesUI(true);
}
},
/**
* Mouseout event handler for the handles.
*
* @method _onHandleMouseLeave
* @param {EventFacade} event
* @protected
*/
_onHandleMouseLeave: function(event) {
var instance = this;
instance._setActiveHandlesUI(false);
}
}
}
);
// creating ATTRS with the handles elements
setter: function() {
return this._buildHandle(handle);
},
value: null,
writeOnce: true
};
});
}, '@VERSION@' ,{skinnable:true, requires:['base', 'widget', 'substitute', 'event', 'oop', 'dd-drag', 'dd-delegate', 'dd-drop']});