/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/static/javascript/yui/build/dd/dd-ddm-base-debug.js

  • Committer: Martin Albisetti
  • Date: 2008-10-20 21:18:06 UTC
  • mfrom: (229.1.3 add-yui-3)
  • Revision ID: martin.albisetti@canonical.com-20081020211806-rzs0ya40gz9wcpoz
Added yui library to the tree. Welcome to the future. (Paul Hummer)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
 
3
Code licensed under the BSD License:
 
4
http://developer.yahoo.net/yui/license.txt
 
5
version: 3.0.0pr1
 
6
*/
 
7
YUI.add('dd-ddm-base', function(Y) {
 
8
 
 
9
    /**
 
10
     * Provides the base Drag Drop Manger required for making a Node draggable.
 
11
     * @module dd
 
12
     * @submodule dd-ddm-base
 
13
     */     
 
14
     /**
 
15
     * Provides the base Drag Drop Manger required for making a Node draggable.
 
16
     * @class DDM
 
17
     * @extends Base
 
18
     * @constructor
 
19
     */
 
20
    
 
21
    var DDMBase = function() {
 
22
        //debugger;
 
23
        DDMBase.superclass.constructor.apply(this, arguments);
 
24
    };
 
25
 
 
26
    DDMBase.NAME = 'DragDropMgr';
 
27
 
 
28
    DDMBase.ATTRS = {
 
29
        /**
 
30
        * @attribute clickPixelThresh
 
31
        * @description The number of pixels to move to start a drag operation, default is 3.
 
32
        * @type Number
 
33
        */
 
34
        clickPixelThresh: {
 
35
            value: 3
 
36
        },
 
37
        /**
 
38
        * @attribute clickTimeThresh
 
39
        * @description The number of milliseconds a mousedown has to pass to start a drag operation, default is 1000.
 
40
        * @type Number
 
41
        */        
 
42
        clickTimeThresh: {
 
43
            value: 1000
 
44
        },
 
45
        /**
 
46
        * @attribute dragMode
 
47
        * @description This attribute only works if the dd-drop module is active. It will set the dragMode (point, intersect, strict) of all future Drag instances. 
 
48
        * @type String
 
49
        */        
 
50
        dragMode: {
 
51
            value: 'point',
 
52
            set: function(mode) {
 
53
                this._setDragMode(mode);
 
54
            }           
 
55
        }
 
56
 
 
57
    };
 
58
 
 
59
    Y.extend(DDMBase, Y.Base, {
 
60
        /**
 
61
        * @private
 
62
        * @method _setDragMode
 
63
        * @description Handler for dragMode attribute setter.
 
64
        * @param String/Number The Number value or the String for the DragMode to default all future drag instances to.
 
65
        * @return Number The Mode to be set
 
66
        */
 
67
        _setDragMode: function(mode) {
 
68
            if (mode === null) {
 
69
                mode = Y.DD.DDM.get('dragMode');
 
70
            }
 
71
            switch (mode) {
 
72
                case 1:
 
73
                case 'intersect':
 
74
                    return 1;
 
75
                case 2:
 
76
                case 'strict':
 
77
                    return 2;
 
78
                case 0:
 
79
                case 'point':
 
80
                    return 0;
 
81
            }
 
82
            return 0;       
 
83
        },
 
84
        /**
 
85
        * @property CSS_PREFIX
 
86
        * @description The PREFIX to attach to all DD CSS class names
 
87
        * @type {String}
 
88
        */
 
89
        CSS_PREFIX: 'yui-dd',
 
90
        _activateTargets: function() {},        
 
91
        /**
 
92
        * @private
 
93
        * @property _drags
 
94
        * @description Holder for all registered drag elements.
 
95
        * @type {Array}
 
96
        */
 
97
        _drags: [],
 
98
        /**
 
99
        * @property activeDrag
 
100
        * @description A reference to the currently active draggable object.
 
101
        * @type {Drag}
 
102
        */
 
103
        activeDrag: false,
 
104
        /**
 
105
        * @private
 
106
        * @method _regDrag
 
107
        * @description Adds a reference to the drag object to the DDM._drags array, called in the constructor of Drag.
 
108
        * @param {Drag} d The Drag object
 
109
        */
 
110
        _regDrag: function(d) {
 
111
            this._drags[this._drags.length] = d;
 
112
        },
 
113
        /**
 
114
        * @private
 
115
        * @method _unregDrag
 
116
        * @description Remove this drag object from the DDM._drags array.
 
117
        * @param {Drag} d The drag object.
 
118
        */
 
119
        _unregDrag: function(d) {
 
120
            var tmp = [];
 
121
            Y.each(this._drags, function(n, i) {
 
122
                if (n !== d) {
 
123
                    tmp[tmp.length] = n;
 
124
                }
 
125
            });
 
126
            this._drags = tmp;
 
127
        },
 
128
        /**
 
129
        * @private
 
130
        * @method _init
 
131
        * @description DDM's init method
 
132
        */
 
133
        initializer: function() {
 
134
            Y.Node.get('document').on('mousemove', this._move, this, true);
 
135
            Y.Node.get('document').on('mouseup', this._end, this, true);
 
136
            //Y.Event.Target.apply(this);
 
137
        },
 
138
        /**
 
139
        * @private
 
140
        * @method _start
 
141
        * @description Internal method used by Drag to signal the start of a drag operation
 
142
        * @param {Number} x The x position of the drag element
 
143
        * @param {Number} y The y position of the drag element
 
144
        * @param {Number} w The width of the drag element
 
145
        * @param {Number} h The height of the drag element
 
146
        */
 
147
        _start: function(x, y, w, h) {
 
148
            this._startDrag.apply(this, arguments);
 
149
        },
 
150
        /**
 
151
        * @private
 
152
        * @method _startDrag
 
153
        * @description Factory method to be overwritten by other DDM's
 
154
        * @param {Number} x The x position of the drag element
 
155
        * @param {Number} y The y position of the drag element
 
156
        * @param {Number} w The width of the drag element
 
157
        * @param {Number} h The height of the drag element
 
158
        */
 
159
        _startDrag: function() {},
 
160
        /**
 
161
        * @private
 
162
        * @method _endDrag
 
163
        * @description Factory method to be overwritten by other DDM's
 
164
        */
 
165
        _endDrag: function() {},
 
166
        _dropMove: function() {},
 
167
        /**
 
168
        * @private
 
169
        * @method _end
 
170
        * @description Internal method used by Drag to signal the end of a drag operation
 
171
        */
 
172
        _end: function() {
 
173
            //@TODO - Here we can get a (click - drag - click - release) interaction instead of a (mousedown - drag - mouseup - release) interaction
 
174
            //Add as a config option??
 
175
            if (this.activeDrag) {
 
176
                this._endDrag();
 
177
                this.activeDrag.end.call(this.activeDrag);
 
178
                this.activeDrag = null;
 
179
            }
 
180
        },
 
181
        /**
 
182
        * @method stopDrag
 
183
        * @description Method will forcefully stop a drag operation. For example calling this from inside an ESC keypress handler will stop this drag.
 
184
        * @return {Self}
 
185
        * @chainable
 
186
        */       
 
187
        stopDrag: function() {
 
188
            if (this.activeDrag) {
 
189
                this._end();
 
190
            }
 
191
            return this;
 
192
        },
 
193
        /**
 
194
        * @private
 
195
        * @method _move
 
196
        * @description Internal listener for the mousemove DOM event to pass to the Drag's move method.
 
197
        * @param {Event} ev The Dom mousemove Event
 
198
        */
 
199
        _move: function(ev) {
 
200
            if (this.activeDrag) {
 
201
                this.activeDrag._move.apply(this.activeDrag, arguments);
 
202
                this._dropMove();
 
203
            }
 
204
        },
 
205
        /**
 
206
        * @method setXY
 
207
        * @description A simple method to set the top and left position from offsets instead of page coordinates
 
208
        * @param {Object} node The node to set the position of 
 
209
        * @param {Array} xy The Array of left/top position to be set.
 
210
        */
 
211
        setXY: function(node, xy) {
 
212
            var t = parseInt(node.getStyle('top'), 10),
 
213
            l = parseInt(node.getStyle('left'), 10),
 
214
            pos = node.getStyle('position');
 
215
 
 
216
            if (pos === 'static') {
 
217
                node.setStyle('position', 'relative');
 
218
            }
 
219
 
 
220
            // in case of 'auto'
 
221
            if (isNaN(t)) { t = 0; }
 
222
            if (isNaN(l)) { l = 0; }
 
223
            
 
224
            node.setStyle('top', (xy[1] + t) + 'px');
 
225
            node.setStyle('left', (xy[0] + l) + 'px');
 
226
            
 
227
        },
 
228
        /**
 
229
        * //TODO Private, rename??...
 
230
        * @private
 
231
        * @method cssSizestoObject
 
232
        * @description Helper method to use to set the gutter from the attribute setter.
 
233
        * @param {String} gutter CSS style string for gutter: '5 0' (sets top and bottom to 5px, left and right to 0px), '1 2 3 4' (top 1px, right 2px, bottom 3px, left 4px)
 
234
        * @return {Object} The gutter Object Literal.
 
235
        */
 
236
        cssSizestoObject: function(gutter) {
 
237
            var p = gutter.split(' '),
 
238
            g = {
 
239
                top: 0,
 
240
                bottom: 0,
 
241
                right: 0,
 
242
                left: 0
 
243
            };
 
244
            if (p.length) {
 
245
                g.top = parseInt(p[0], 10);
 
246
                if (p[1]) {
 
247
                    g.right = parseInt(p[1], 10);
 
248
                } else {
 
249
                    g.right = g.top;
 
250
                }
 
251
                if (p[2]) {
 
252
                    g.bottom = parseInt(p[2], 10);
 
253
                } else {
 
254
                    g.bottom = g.top;
 
255
                }
 
256
                if (p[3]) {
 
257
                    g.left = parseInt(p[3], 10);
 
258
                } else if (p[1]) {
 
259
                    g.left = g.right;
 
260
                } else {
 
261
                    g.left = g.top;
 
262
                }
 
263
            }
 
264
            return g;
 
265
        },
 
266
        /**
 
267
        * @method getDrag
 
268
        * @description Get a valid Drag instance back from a Node or a selector string, false otherwise
 
269
        * @param {String/Object} node The Node instance or Selector string to check for a valid Drag Object
 
270
        * @return {Object}
 
271
        */
 
272
        getDrag: function(node) {
 
273
            var drag = false,
 
274
                n = Y.Node.get(node);
 
275
            if (n instanceof Y.Node) {
 
276
                Y.each(this._drags, function(v, k) {
 
277
                    if (n.compareTo(v.get('node'))) {
 
278
                        drag = v;
 
279
                    }
 
280
                });
 
281
            }
 
282
            return drag;
 
283
        }
 
284
    });
 
285
 
 
286
    Y.namespace('DD');
 
287
    Y.DD.DDM = new DDMBase();
 
288
 
 
289
 
 
290
 
 
291
}, '3.0.0pr1' ,{requires:['node', 'base'], skinnable:false});