Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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