Merge branch 'MDL-32509' of git://github.com/danpoltawski/moodle
[moodle.git] / lib / yui / 3.5.0 / build / resize-proxy / resize-proxy-debug.js
blobdd96f94e05e2a5c2206c4c9befdbcb836e6689de
1 /*
2 YUI 3.5.0 (build 5089)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('resize-proxy', function(Y) {
9 var ACTIVE_HANDLE_NODE = 'activeHandleNode',
10         CURSOR = 'cursor',
11         DRAG_CURSOR = 'dragCursor',
12         HOST = 'host',
13         PARENT_NODE = 'parentNode',
14         PROXY = 'proxy',
15         PROXY_NODE = 'proxyNode',
16         RESIZE = 'resize',
17         RESIZE_PROXY = 'resize-proxy',
18         WRAPPER = 'wrapper',
20         getCN = Y.ClassNameManager.getClassName,
22         CSS_RESIZE_PROXY = getCN(RESIZE, PROXY);
25 /**
26 Adds a `proxyNode` attribute and resizes it instead of the actual node. __very similar to DDProxy__
28     var resize = new Y.Resize({
29         //Selector of the node to resize
30         node: '#demo'
31     });
32     resize.plug(Y.Plugin.ResizeProxy);
33     
35 @class ResizeProxy
36 @module resize
37 @submodule resize-proxy
38 @constructor
39 @extends Plugin.Base
40 @namespace Plugin
44 function ResizeProxy() {
45         ResizeProxy.superclass.constructor.apply(this, arguments);
48 Y.mix(ResizeProxy, {
49         NAME: RESIZE_PROXY,
51         NS: PROXY,
53         ATTRS: {
54                 /**
55          * The Resize proxy element.
56          *
57          * @attribute proxyNode
58          * @default Generated using an internal HTML markup
59          * @type String|Node
60          */
61                 proxyNode: {
62                         setter: Y.one,
63                         valueFn: function() {
64                                 return Y.Node.create(this.PROXY_TEMPLATE);
65                         }
66                 }
67         }
68 });
70 Y.extend(ResizeProxy, Y.Plugin.Base, {
71         /**
72      * Template used to create the resize proxy.
73      *
74      * @property PROXY_TEMPLATE
75      * @type {String}
76      */
77         PROXY_TEMPLATE: '<div class="'+CSS_RESIZE_PROXY+'"></div>',
79         initializer: function() {
80                 var instance = this;
82                 instance.afterHostEvent('resize:start', instance._afterResizeStart);
83                 instance.beforeHostMethod('_resize', instance._beforeHostResize);
84                 instance.afterHostMethod('_resizeEnd', instance._afterHostResizeEnd);
85         },
87         destructor: function() {
88                 var instance = this;
90                 instance.get(PROXY_NODE).remove(true);
91         },
93         _afterHostResizeEnd: function(event) {
94                 var instance = this,
95                         drag = event.dragEvent.target;
97                 // reseting actXY from drag when drag end
98                 drag.actXY = [];
100                 // if proxy is true, hide it on resize end
101                 instance._syncProxyUI();
103                 instance.get(PROXY_NODE).hide();
104         },
106         _afterResizeStart: function(event) {
107                 var instance = this;
109                 instance._renderProxy();
110         },
112         _beforeHostResize: function(event) {
113                 var instance = this,
114                         host = this.get(HOST);
116                 host._handleResizeAlignEvent(event.dragEvent);
118                 // if proxy is true _syncProxyUI instead of _syncUI
119                 instance._syncProxyUI();
121                 return new Y.Do.Prevent();
122         },
124     /**
125       * Render the <a href="ResizeProxy.html#config_proxyNode">proxyNode</a> element and
126       * make it sibling of the <a href="Resize.html#config_node">node</a>.
127       *
128       * @method _renderProxy
129       * @protected
130       */
131         _renderProxy: function() {
132                 var instance = this,
133                         host = this.get(HOST),
134                         proxyNode = instance.get(PROXY_NODE);
136                 if (!proxyNode.inDoc()) {
137                         host.get(WRAPPER).get(PARENT_NODE).append(
138                                 proxyNode.hide()
139                         );
140                 }
141         },
143         /**
144      * Sync the proxy UI with internal values from
145      * <a href="ResizeProxy.html#property_info">info</a>.
146      *
147      * @method _syncProxyUI
148      * @protected
149      */
150         _syncProxyUI: function() {
151                 var instance = this,
152                         host = this.get(HOST),
153                         info = host.info,
154                         activeHandleNode = host.get(ACTIVE_HANDLE_NODE),
155                         proxyNode = instance.get(PROXY_NODE),
156                         cursor = activeHandleNode.getStyle(CURSOR);
158                 proxyNode.show().setStyle(CURSOR, cursor);
160                 host.delegate.dd.set(DRAG_CURSOR, cursor);
162                 proxyNode.sizeTo(info.offsetWidth, info.offsetHeight);
164                 proxyNode.setXY([ info.left, info.top ]);
165         }
168 Y.namespace('Plugin');
169 Y.Plugin.ResizeProxy = ResizeProxy;
172 }, '3.5.0' ,{requires:['resize-base', 'plugin'], skinnable:false});