NOBUG: Fixed file access permissions
[moodle.git] / lib / yuilib / 3.13.0 / resize-proxy / resize-proxy.js
blobc7dbda67e5439a930bb91d71fe739783526e6b9f
1 /*
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/
6 */
8 YUI.add('resize-proxy', function (Y, NAME) {
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',
21     getCN = Y.ClassNameManager.getClassName,
23     CSS_RESIZE_PROXY = getCN(RESIZE, PROXY);
26 /**
27 Adds a `proxyNode` attribute and resizes it instead of the actual node. __very similar to DDProxy__
29     var resize = new Y.Resize({
30         //Selector of the node to resize
31         node: '#demo'
32     });
33     resize.plug(Y.Plugin.ResizeProxy);
36 @class ResizeProxy
37 @module resize
38 @submodule resize-proxy
39 @constructor
40 @extends Plugin.Base
41 @namespace Plugin
45 function ResizeProxy() {
46     ResizeProxy.superclass.constructor.apply(this, arguments);
49 Y.mix(ResizeProxy, {
50     NAME: RESIZE_PROXY,
52     NS: PROXY,
54     ATTRS: {
55         /**
56          * The Resize proxy element.
57          *
58          * @attribute proxyNode
59          * @default Generated using an internal HTML markup
60          * @type String|Node
61          */
62         proxyNode: {
63             setter: Y.one,
64             valueFn: function() {
65                 return Y.Node.create(this.PROXY_TEMPLATE);
66             }
67         }
68     }
69 });
71 Y.extend(ResizeProxy, Y.Plugin.Base, {
72     /**
73      * Template used to create the resize proxy.
74      *
75      * @property PROXY_TEMPLATE
76      * @type {String}
77      */
78     PROXY_TEMPLATE: '<div class="'+CSS_RESIZE_PROXY+'"></div>',
80     initializer: function() {
81         var instance = this;
83         instance.afterHostEvent('resize:start', instance._afterResizeStart);
84         instance.beforeHostMethod('_resize', instance._beforeHostResize);
85         instance.afterHostMethod('_resizeEnd', instance._afterHostResizeEnd);
86     },
88     destructor: function() {
89         var instance = this;
91         instance.get(PROXY_NODE).remove(true);
92     },
94     _afterHostResizeEnd: function(event) {
95         var instance = this,
96             drag = event.dragEvent.target;
98         // reseting actXY from drag when drag end
99         drag.actXY = [];
101         // if proxy is true, hide it on resize end
102         instance._syncProxyUI();
104         instance.get(PROXY_NODE).hide();
105     },
107     _afterResizeStart: function() {
108         var instance = this;
110         instance._renderProxy();
111     },
113     _beforeHostResize: function(event) {
114         var instance = this,
115             host = this.get(HOST);
117         host._handleResizeAlignEvent(event.dragEvent);
119         // if proxy is true _syncProxyUI instead of _syncUI
120         instance._syncProxyUI();
122         return new Y.Do.Prevent();
123     },
125     /**
126       * Render the <a href="ResizeProxy.html#attr_proxyNode">proxyNode</a> element and
127       * make it sibling of the <a href="Resize.html#attr_node">node</a>.
128       *
129       * @method _renderProxy
130       * @protected
131       */
132     _renderProxy: function() {
133         var instance = this,
134             host = this.get(HOST),
135             proxyNode = instance.get(PROXY_NODE);
137         if (!proxyNode.inDoc()) {
138             host.get(WRAPPER).get(PARENT_NODE).append(
139                 proxyNode.hide()
140             );
141         }
142     },
144     /**
145      * Sync the proxy UI with internal values from
146      * <a href="ResizeProxy.html#property_info">info</a>.
147      *
148      * @method _syncProxyUI
149      * @protected
150      */
151     _syncProxyUI: function() {
152         var instance = this,
153             host = this.get(HOST),
154             info = host.info,
155             activeHandleNode = host.get(ACTIVE_HANDLE_NODE),
156             proxyNode = instance.get(PROXY_NODE),
157             cursor = activeHandleNode.getStyle(CURSOR);
159         proxyNode.show().setStyle(CURSOR, cursor);
161         host.delegate.dd.set(DRAG_CURSOR, cursor);
163         proxyNode.sizeTo(info.offsetWidth, info.offsetHeight);
165         proxyNode.setXY([ info.left, info.top ]);
166     }
169 Y.namespace('Plugin');
170 Y.Plugin.ResizeProxy = ResizeProxy;
173 }, '3.13.0', {"requires": ["plugin", "resize-base"]});