]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/resize/resize-proxy.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / resize / resize-proxy.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('resize-proxy', function(Y) {
9
10 var ACTIVE_HANDLE_NODE = 'activeHandleNode',
11         CURSOR = 'cursor',
12         DRAG_CURSOR = 'dragCursor',
13         HOST = 'host',
14         PARENT_NODE = 'parentNode',
15         PROXY = 'proxy',
16         PROXY_NODE = 'proxyNode',
17         RESIZE = 'resize',
18         RESIZE_PROXY = 'resize-proxy',
19         WRAPPER = 'wrapper',
20
21         getCN = Y.ClassNameManager.getClassName,
22
23         CSS_RESIZE_PROXY = getCN(RESIZE, PROXY);
24
25 function ResizeProxy() {
26         ResizeProxy.superclass.constructor.apply(this, arguments);
27 }
28
29 Y.mix(ResizeProxy, {
30         NAME: RESIZE_PROXY,
31
32         NS: PROXY,
33
34         ATTRS: {
35                 /**
36          * The Resize proxy element.
37          *
38          * @attribute proxyNode
39          * @default Generated using an internal HTML markup
40          * @type String | Node
41          */
42                 proxyNode: {
43                         setter: Y.one,
44                         valueFn: function() {
45                                 return Y.Node.create(this.PROXY_TEMPLATE);
46                         }
47                 }
48         }
49 });
50
51 Y.extend(ResizeProxy, Y.Plugin.Base, {
52         /**
53      * Template used to create the resize proxy.
54      *
55      * @property PROXY_TEMPLATE
56      * @type {String}
57      */
58         PROXY_TEMPLATE: '<div class="'+CSS_RESIZE_PROXY+'"></div>',
59
60         initializer: function() {
61                 var instance = this;
62
63                 instance.afterHostEvent('resize:start', instance._afterResizeStart);
64                 instance.beforeHostMethod('_resize', instance._beforeHostResize);
65                 instance.afterHostMethod('_resizeEnd', instance._afterHostResizeEnd);
66         },
67
68         destructor: function() {
69                 var instance = this;
70
71                 instance.get(PROXY_NODE).remove(true);
72         },
73
74         _afterHostResizeEnd: function(event) {
75                 var instance = this,
76                         drag = event.dragEvent.target;
77
78                 // reseting actXY from drag when drag end
79                 drag.actXY = [];
80
81                 // if proxy is true, hide it on resize end
82                 instance._syncProxyUI();
83
84                 instance.get(PROXY_NODE).hide();
85         },
86
87         _afterResizeStart: function(event) {
88                 var instance = this;
89
90                 instance._renderProxy();
91         },
92
93         _beforeHostResize: function(event) {
94                 var instance = this,
95                         host = this.get(HOST);
96
97                 host._handleResizeAlignEvent(event.dragEvent);
98
99                 // if proxy is true _syncProxyUI instead of _syncUI
100                 instance._syncProxyUI();
101
102                 return new Y.Do.Prevent();
103         },
104
105     /**
106       * Render the <a href="ResizeProxy.html#config_proxyNode">proxyNode</a> element and
107       * make it sibling of the <a href="Resize.html#config_node">node</a>.
108       *
109       * @method _renderProxy
110       * @protected
111       */
112         _renderProxy: function() {
113                 var instance = this,
114                         host = this.get(HOST),
115                         proxyNode = instance.get(PROXY_NODE);
116
117                 if (!proxyNode.inDoc()) {
118                         host.get(WRAPPER).get(PARENT_NODE).append(
119                                 proxyNode.hide()
120                         );
121                 }
122         },
123
124         /**
125      * Sync the proxy UI with internal values from
126      * <a href="ResizeProxy.html#property_info">info</a>.
127      *
128      * @method _syncProxyUI
129      * @protected
130      */
131         _syncProxyUI: function() {
132                 var instance = this,
133                         host = this.get(HOST),
134                         info = host.info,
135                         activeHandleNode = host.get(ACTIVE_HANDLE_NODE),
136                         proxyNode = instance.get(PROXY_NODE),
137                         cursor = activeHandleNode.getStyle(CURSOR);
138
139                 proxyNode.show().setStyle(CURSOR, cursor);
140
141                 host.delegate.dd.set(DRAG_CURSOR, cursor);
142
143                 proxyNode.sizeTo(info.offsetWidth, info.offsetHeight);
144
145                 proxyNode.setXY([ info.left, info.top ]);
146         }
147 });
148
149 Y.namespace('Plugin');
150 Y.Plugin.ResizeProxy = ResizeProxy;
151
152
153 }, '3.3.0' ,{requires:['resize-base', 'plugin'], skinnable:false});