resize-proxy.js revision 10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85
2801N/AYUI.add('resize-proxy', function(Y) {
2801N/A
2801N/Avar ACTIVE_HANDLE_NODE = 'activeHandleNode',
2801N/A CURSOR = 'cursor',
2801N/A DRAG_CURSOR = 'dragCursor',
2801N/A HOST = 'host',
2801N/A PARENT_NODE = 'parentNode',
2801N/A PROXY = 'proxy',
2801N/A PROXY_NODE = 'proxyNode',
2801N/A RESIZE = 'resize',
2801N/A RESIZE_PROXY = 'resize-proxy',
2801N/A WRAPPER = 'wrapper',
2801N/A
2801N/A getCN = Y.ClassNameManager.getClassName,
2801N/A
2801N/A CSS_RESIZE_PROXY = getCN(RESIZE, PROXY);
2801N/A
2801N/A
2801N/A/**
2801N/AAdds a `proxyNode` attribute and resizes it instead of the actual node. __very similar to DDProxy__
2801N/A
2801N/A var resize = new Y.Resize({
2801N/A //Selector of the node to resize
2801N/A node: '#demo'
2801N/A });
2801N/A resize.plug(Y.Plugin.ResizeProxy);
2801N/A
2801N/A
2801N/A@class ResizeProxy
2801N/A@module resize
2801N/A@submodule resize-proxy
2801N/A@constructor
2801N/A@extends Plugin.Base
2801N/A@namespace Plugin
2801N/A*/
2801N/A
2801N/A
2801N/Afunction ResizeProxy() {
2801N/A ResizeProxy.superclass.constructor.apply(this, arguments);
2801N/A}
2801N/A
2801N/AY.mix(ResizeProxy, {
2801N/A NAME: RESIZE_PROXY,
2801N/A
2801N/A NS: PROXY,
2801N/A
2801N/A ATTRS: {
2801N/A /**
2801N/A * The Resize proxy element.
2801N/A *
2801N/A * @attribute proxyNode
2801N/A * @default Generated using an internal HTML markup
2801N/A * @type String|Node
2801N/A */
2801N/A proxyNode: {
2801N/A setter: Y.one,
2801N/A valueFn: function() {
2801N/A return Y.Node.create(this.PROXY_TEMPLATE);
2801N/A }
2801N/A }
2801N/A }
2801N/A});
2801N/A
2801N/AY.extend(ResizeProxy, Y.Plugin.Base, {
2801N/A /**
2801N/A * Template used to create the resize proxy.
2801N/A *
2801N/A * @property PROXY_TEMPLATE
2801N/A * @type {String}
2801N/A */
2801N/A PROXY_TEMPLATE: '<div class="'+CSS_RESIZE_PROXY+'"></div>',
2801N/A
2801N/A initializer: function() {
2801N/A var instance = this;
2801N/A
2801N/A instance.afterHostEvent('resize:start', instance._afterResizeStart);
2801N/A instance.beforeHostMethod('_resize', instance._beforeHostResize);
2801N/A instance.afterHostMethod('_resizeEnd', instance._afterHostResizeEnd);
2801N/A },
2801N/A
2801N/A destructor: function() {
2801N/A var instance = this;
2801N/A
2801N/A instance.get(PROXY_NODE).remove(true);
2801N/A },
2801N/A
2801N/A _afterHostResizeEnd: function(event) {
2801N/A var instance = this,
2801N/A drag = event.dragEvent.target;
2801N/A
2801N/A // reseting actXY from drag when drag end
2801N/A drag.actXY = [];
2801N/A
2801N/A // if proxy is true, hide it on resize end
2801N/A instance._syncProxyUI();
2801N/A
2801N/A instance.get(PROXY_NODE).hide();
2801N/A },
2801N/A
2801N/A _afterResizeStart: function(event) {
2801N/A var instance = this;
2801N/A
2801N/A instance._renderProxy();
2801N/A },
2801N/A
2801N/A _beforeHostResize: function(event) {
2801N/A var instance = this,
2801N/A host = this.get(HOST);
2801N/A
2801N/A host._handleResizeAlignEvent(event.dragEvent);
2801N/A
2801N/A // if proxy is true _syncProxyUI instead of _syncUI
2801N/A instance._syncProxyUI();
2801N/A
2801N/A return new Y.Do.Prevent();
2801N/A },
2801N/A
2801N/A /**
2801N/A * Render the <a href="ResizeProxy.html#config_proxyNode">proxyNode</a> element and
2801N/A * make it sibling of the <a href="Resize.html#config_node">node</a>.
2801N/A *
2801N/A * @method _renderProxy
2801N/A * @protected
2801N/A */
2801N/A _renderProxy: function() {
2801N/A var instance = this,
2801N/A host = this.get(HOST),
2801N/A proxyNode = instance.get(PROXY_NODE);
2801N/A
2801N/A if (!proxyNode.inDoc()) {
2801N/A host.get(WRAPPER).get(PARENT_NODE).append(
2801N/A proxyNode.hide()
2801N/A );
2801N/A }
2801N/A },
2801N/A
2801N/A /**
2801N/A * Sync the proxy UI with internal values from
2801N/A * <a href="ResizeProxy.html#property_info">info</a>.
2801N/A *
2801N/A * @method _syncProxyUI
2801N/A * @protected
2801N/A */
2801N/A _syncProxyUI: function() {
2801N/A var instance = this,
2801N/A host = this.get(HOST),
2801N/A info = host.info,
2801N/A activeHandleNode = host.get(ACTIVE_HANDLE_NODE),
2801N/A proxyNode = instance.get(PROXY_NODE),
2801N/A cursor = activeHandleNode.getStyle(CURSOR);
2801N/A
2801N/A proxyNode.show().setStyle(CURSOR, cursor);
2801N/A
2801N/A host.delegate.dd.set(DRAG_CURSOR, cursor);
2801N/A
2801N/A proxyNode.sizeTo(info.offsetWidth, info.offsetHeight);
2801N/A
2801N/A proxyNode.setXY([ info.left, info.top ]);
2801N/A }
2801N/A});
2801N/A
2801N/AY.namespace('Plugin');
2801N/AY.Plugin.ResizeProxy = ResizeProxy;
2801N/A
2801N/A
2801N/A}, '@VERSION@' ,{requires:['resize-base', 'plugin'], skinnable:false});
2801N/A