~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.9.1/build/dd-proxy/dd-proxy.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
 
YUI.add('dd-proxy', function (Y, NAME) {
3
 
 
4
 
 
5
 
    /**
6
 
     * Plugin for dd-drag for creating a proxy drag node, instead of dragging the original node.
7
 
     * @module dd
8
 
     * @submodule dd-proxy
9
 
     */
10
 
    /**
11
 
     * Plugin for dd-drag for creating a proxy drag node, instead of dragging the original node.
12
 
     * @class DDProxy
13
 
     * @extends Base
14
 
     * @constructor
15
 
     * @namespace Plugin
16
 
     */
17
 
    var DDM = Y.DD.DDM,
18
 
        NODE = 'node',
19
 
        DRAG_NODE = 'dragNode',
20
 
        HOST = 'host',
21
 
        TRUE = true, proto,
22
 
        P = function() {
23
 
            P.superclass.constructor.apply(this, arguments);
24
 
        };
25
 
 
26
 
    P.NAME = 'DDProxy';
27
 
    /**
28
 
    * The Proxy instance will be placed on the Drag instance under the proxy namespace.
29
 
    * @property NS
30
 
    * @default con
31
 
    * @readonly
32
 
    * @protected
33
 
    * @static
34
 
    * @type {String}
35
 
    */
36
 
    P.NS = 'proxy';
37
 
 
38
 
    P.ATTRS = {
39
 
        host: {
40
 
        },
41
 
        /**
42
 
        * Move the original node at the end of the drag. Default: true
43
 
        * @attribute moveOnEnd
44
 
        * @type Boolean
45
 
        */
46
 
        moveOnEnd: {
47
 
            value: TRUE
48
 
        },
49
 
        /**
50
 
        * Hide the drag node at the end of the drag. Default: true
51
 
        * @attribute hideOnEnd
52
 
        * @type Boolean
53
 
        */
54
 
        hideOnEnd: {
55
 
            value: TRUE
56
 
        },
57
 
        /**
58
 
        * Make the Proxy node assume the size of the original node. Default: true
59
 
        * @attribute resizeFrame
60
 
        * @type Boolean
61
 
        */
62
 
        resizeFrame: {
63
 
            value: TRUE
64
 
        },
65
 
        /**
66
 
        * Make the Proxy node appear in the same place as the original node. Default: true
67
 
        * @attribute positionProxy
68
 
        * @type Boolean
69
 
        */
70
 
        positionProxy: {
71
 
            value: TRUE
72
 
        },
73
 
        /**
74
 
        * The default border style for the border of the proxy. Default: 1px solid #808080
75
 
        * @attribute borderStyle
76
 
        * @type Boolean
77
 
        */
78
 
        borderStyle: {
79
 
            value: '1px solid #808080'
80
 
        },
81
 
        /**
82
 
        * Should the node be cloned into the proxy for you. Default: false
83
 
        * @attribute cloneNode
84
 
        * @type Boolean
85
 
        */
86
 
        cloneNode: {
87
 
            value: false
88
 
        }
89
 
    };
90
 
 
91
 
    proto = {
92
 
        /**
93
 
        * Holds the event handles for setting the proxy
94
 
        * @private
95
 
        * @property _hands
96
 
        */
97
 
        _hands: null,
98
 
        /**
99
 
        * Handler for the proxy config attribute
100
 
        * @private
101
 
        * @method _init
102
 
        */
103
 
        _init: function() {
104
 
            if (!DDM._proxy) {
105
 
                DDM._createFrame();
106
 
                Y.on('domready', Y.bind(this._init, this));
107
 
                return;
108
 
            }
109
 
            if (!this._hands) {
110
 
                this._hands = [];
111
 
            }
112
 
            var h, h1, host = this.get(HOST), dnode = host.get(DRAG_NODE);
113
 
            if (dnode.compareTo(host.get(NODE))) {
114
 
                if (DDM._proxy) {
115
 
                    host.set(DRAG_NODE, DDM._proxy);
116
 
                }
117
 
            }
118
 
            Y.Array.each(this._hands, function(v) {
119
 
                v.detach();
120
 
            });
121
 
            h = DDM.on('ddm:start', Y.bind(function() {
122
 
                if (DDM.activeDrag === host) {
123
 
                    DDM._setFrame(host);
124
 
                }
125
 
            }, this));
126
 
            h1 = DDM.on('ddm:end', Y.bind(function() {
127
 
                if (host.get('dragging')) {
128
 
                    if (this.get('moveOnEnd')) {
129
 
                        host.get(NODE).setXY(host.lastXY);
130
 
                    }
131
 
                    if (this.get('hideOnEnd')) {
132
 
                        host.get(DRAG_NODE).setStyle('display', 'none');
133
 
                    }
134
 
                    if (this.get('cloneNode')) {
135
 
                        host.get(DRAG_NODE).remove();
136
 
                        host.set(DRAG_NODE, DDM._proxy);
137
 
                    }
138
 
                }
139
 
            }, this));
140
 
            this._hands = [h, h1];
141
 
        },
142
 
        initializer: function() {
143
 
            this._init();
144
 
        },
145
 
        destructor: function() {
146
 
            var host = this.get(HOST);
147
 
            Y.Array.each(this._hands, function(v) {
148
 
                v.detach();
149
 
            });
150
 
            host.set(DRAG_NODE, host.get(NODE));
151
 
        },
152
 
        clone: function() {
153
 
            var host = this.get(HOST),
154
 
                n = host.get(NODE),
155
 
                c = n.cloneNode(true);
156
 
 
157
 
            delete c._yuid;
158
 
            c.setAttribute('id', Y.guid());
159
 
            c.setStyle('position', 'absolute');
160
 
            n.get('parentNode').appendChild(c);
161
 
            host.set(DRAG_NODE, c);
162
 
            return c;
163
 
        }
164
 
    };
165
 
 
166
 
    Y.namespace('Plugin');
167
 
    Y.extend(P, Y.Base, proto);
168
 
    Y.Plugin.DDProxy = P;
169
 
 
170
 
    //Add a couple of methods to the DDM
171
 
    Y.mix(DDM, {
172
 
        /**
173
 
        * Create the proxy element if it doesn't already exist and set the DD.DDM._proxy value
174
 
        * @private
175
 
        * @for DDM
176
 
        * @namespace DD
177
 
        * @method _createFrame
178
 
        */
179
 
        _createFrame: function() {
180
 
            if (!DDM._proxy) {
181
 
                DDM._proxy = TRUE;
182
 
 
183
 
                var p = Y.Node.create('<div></div>'),
184
 
                b = Y.one('body');
185
 
 
186
 
                p.setStyles({
187
 
                    position: 'absolute',
188
 
                    display: 'none',
189
 
                    zIndex: '999',
190
 
                    top: '-999px',
191
 
                    left: '-999px'
192
 
                });
193
 
 
194
 
                b.prepend(p);
195
 
                p.set('id', Y.guid());
196
 
                p.addClass(DDM.CSS_PREFIX + '-proxy');
197
 
                DDM._proxy = p;
198
 
            }
199
 
        },
200
 
        /**
201
 
        * If resizeProxy is set to true (default) it will resize the proxy element to match the size of the Drag Element.
202
 
        * If positionProxy is set to true (default) it will position the proxy element in the same location as the Drag Element.
203
 
        * @private
204
 
        * @for DDM
205
 
        * @namespace DD
206
 
        * @method _setFrame
207
 
        */
208
 
        _setFrame: function(drag) {
209
 
            var n = drag.get(NODE), d = drag.get(DRAG_NODE), ah, cur = 'auto';
210
 
 
211
 
            ah = DDM.activeDrag.get('activeHandle');
212
 
            if (ah) {
213
 
                cur = ah.getStyle('cursor');
214
 
            }
215
 
            if (cur === 'auto') {
216
 
                cur = DDM.get('dragCursor');
217
 
            }
218
 
 
219
 
            d.setStyles({
220
 
                visibility: 'hidden',
221
 
                display: 'block',
222
 
                cursor: cur,
223
 
                border: drag.proxy.get('borderStyle')
224
 
            });
225
 
 
226
 
            if (drag.proxy.get('cloneNode')) {
227
 
                d = drag.proxy.clone();
228
 
            }
229
 
 
230
 
            if (drag.proxy.get('resizeFrame')) {
231
 
                d.setStyles({
232
 
                    height: n.get('offsetHeight') + 'px',
233
 
                    width: n.get('offsetWidth') + 'px'
234
 
                });
235
 
            }
236
 
 
237
 
            if (drag.proxy.get('positionProxy')) {
238
 
                d.setXY(drag.nodeXY);
239
 
            }
240
 
            d.setStyle('visibility', 'visible');
241
 
        }
242
 
    });
243
 
 
244
 
    //Create the frame when DOM is ready
245
 
    //Y.on('domready', Y.bind(DDM._createFrame, DDM));
246
 
 
247
 
 
248
 
 
249
 
 
250
 
}, '3.9.1', {"requires": ["dd-drag"]});