~ted/lazr-js/annoying-debug-message

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/dd/dd-drag.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2010-09-09 14:20:30 UTC
  • mfrom: (182.1.3 yui-3.2)
  • Revision ID: launchpad@pqm.canonical.com-20100909142030-13w6vo0ixfysxc15
[r=beuno] Update lazr-js to yui-3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
4
http://developer.yahoo.com/yui/license.html
5
 
version: 3.1.2
6
 
build: 56
 
5
version: 3.2.0
 
6
build: 2676
7
7
*/
8
8
YUI.add('dd-drag', function(Y) {
9
9
 
27
27
        DRAG_NODE = 'dragNode',
28
28
        OFFSET_HEIGHT = 'offsetHeight',
29
29
        OFFSET_WIDTH = 'offsetWidth',        
30
 
        MOUSE_UP = 'mouseup',
31
 
        MOUSE_DOWN = 'mousedown',
32
 
        DRAG_START = 'dragstart',
33
30
        /**
34
31
        * @event drag:mouseDown
35
32
        * @description Handles the mousedown DOM event, checks to see if you have a valid handle then starts the drag timers.
36
33
        * @preventable _defMouseDownFn
37
 
        * @param {Event.Facade} ev The mousedown event.
 
34
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
35
        * <dl><dt>ev</dt><dd>The original mousedown event.</dd></dl>
38
36
        * @bubbles DDM
39
37
        * @type {Event.Custom}
40
38
        */
42
40
        /**
43
41
        * @event drag:afterMouseDown
44
42
        * @description Fires after the mousedown event has been cleared.
45
 
        * @param {Event.Facade} ev The mousedown event.
 
43
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
44
        * <dl><dt>ev</dt><dd>The original mousedown event.</dd></dl>
46
45
        * @bubbles DDM
47
46
        * @type {Event.Custom}
48
47
        */
50
49
        /**
51
50
        * @event drag:removeHandle
52
51
        * @description Fires after a handle is removed.
 
52
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
53
        * <dl><dt>handle</dt><dd>The handle that was removed.</dd></dl>
53
54
        * @bubbles DDM
54
55
        * @type {Event.Custom}
55
56
        */
57
58
        /**
58
59
        * @event drag:addHandle
59
60
        * @description Fires after a handle is added.
 
61
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
62
        * <dl><dt>handle</dt><dd>The handle that was added.</dd></dl>
60
63
        * @bubbles DDM
61
64
        * @type {Event.Custom}
62
65
        */
64
67
        /**
65
68
        * @event drag:removeInvalid
66
69
        * @description Fires after an invalid selector is removed.
 
70
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
71
        * <dl><dt>handle</dt><dd>The handle that was removed.</dd></dl>
67
72
        * @bubbles DDM
68
73
        * @type {Event.Custom}
69
74
        */
71
76
        /**
72
77
        * @event drag:addInvalid
73
78
        * @description Fires after an invalid selector is added.
 
79
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
80
        * <dl><dt>handle</dt><dd>The handle that was added.</dd></dl>
74
81
        * @bubbles DDM
75
82
        * @type {Event.Custom}
76
83
        */
78
85
        /**
79
86
        * @event drag:start
80
87
        * @description Fires at the start of a drag operation.
 
88
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
89
        * <dl>
 
90
        * <dt>pageX</dt><dd>The original node position X.</dd>
 
91
        * <dt>pageY</dt><dd>The original node position Y.</dd>
 
92
        * <dt>startTime</dt><dd>The startTime of the event. getTime on the current Date object.</dd>
 
93
        * </dl>
81
94
        * @bubbles DDM
82
95
        * @type {Event.Custom}
83
96
        */
85
98
        /**
86
99
        * @event drag:end
87
100
        * @description Fires at the end of a drag operation.
 
101
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
102
        * <dl>
 
103
        * <dt>pageX</dt><dd>The current node position X.</dd>
 
104
        * <dt>pageY</dt><dd>The current node position Y.</dd>
 
105
        * <dt>startTime</dt><dd>The startTime of the event, from the start event.</dd>
 
106
        * <dt>endTime</dt><dd>The endTime of the event. getTime on the current Date object.</dd>
 
107
        * </dl>
88
108
        * @bubbles DDM
89
109
        * @type {Event.Custom}
90
110
        */
92
112
        /**
93
113
        * @event drag:drag
94
114
        * @description Fires every mousemove during a drag operation.
 
115
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
116
        * <dl>
 
117
        * <dt>pageX</dt><dd>The current node position X.</dd>
 
118
        * <dt>pageY</dt><dd>The current node position Y.</dd>
 
119
        * <dt>scroll</dt><dd>Should a scroll action occur.</dd>
 
120
        * <dt>info</dt><dd>Object hash containing calculated XY arrays: start, xy, delta, offset</dd>
 
121
        * </dl>
95
122
        * @bubbles DDM
96
123
        * @type {Event.Custom}
97
124
        */
100
127
        * @event drag:align
101
128
        * @preventable _defAlignFn
102
129
        * @description Fires when this node is aligned.
 
130
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
131
        * <dl>
 
132
        * <dt>pageX</dt><dd>The current node position X.</dd>
 
133
        * <dt>pageY</dt><dd>The current node position Y.</dd>
 
134
        * </dl>
103
135
        * @bubbles DDM
104
136
        * @type {Event.Custom}
105
137
        */
107
139
        /**
108
140
        * @event drag:over
109
141
        * @description Fires when this node is over a Drop Target. (Fired from dd-drop)
 
142
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
143
        * <dl>
 
144
        * <dt>drop</dt><dd>The drop object at the time of the event.</dd>
 
145
        * <dt>drag</dt><dd>The drag object at the time of the event.</dd>
 
146
        * </dl>
110
147
        * @bubbles DDM
111
148
        * @type {Event.Custom}
112
149
        */
113
150
        /**
114
151
        * @event drag:enter
115
152
        * @description Fires when this node enters a Drop Target. (Fired from dd-drop)
 
153
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
154
        * <dl>
 
155
        * <dt>drop</dt><dd>The drop object at the time of the event.</dd>
 
156
        * <dt>drag</dt><dd>The drag object at the time of the event.</dd>
 
157
        * </dl>
116
158
        * @bubbles DDM
117
159
        * @type {Event.Custom}
118
160
        */
119
161
        /**
120
162
        * @event drag:exit
121
163
        * @description Fires when this node exits a Drop Target. (Fired from dd-drop)
 
164
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
165
        * <dl>
 
166
        * <dt>drop</dt><dd>The drop object at the time of the event.</dd>
 
167
        * </dl>
122
168
        * @bubbles DDM
123
169
        * @type {Event.Custom}
124
170
        */
125
171
        /**
126
172
        * @event drag:drophit
127
173
        * @description Fires when this node is dropped on a valid Drop Target. (Fired from dd-ddm-drop)
 
174
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
175
        * <dl>
 
176
        * <dt>drop</dt><dd>The best guess on what was dropped on.</dd>
 
177
        * <dt>drag</dt><dd>The drag object at the time of the event.</dd>
 
178
        * <dt>others</dt><dd>An array of all the other drop targets that was dropped on.</dd>
 
179
        * </dl>
128
180
        * @bubbles DDM
129
181
        * @type {Event.Custom}
130
182
        */
131
183
        /**
132
184
        * @event drag:dropmiss
133
185
        * @description Fires when this node is dropped on an invalid Drop Target. (Fired from dd-ddm-drop)
 
186
        * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
187
        * <dl>
 
188
        * <dt>pageX</dt><dd>The current node position X.</dd>
 
189
        * <dt>pageY</dt><dd>The current node position Y.</dd>
 
190
        * </dl>
134
191
        * @bubbles DDM
135
192
        * @type {Event.Custom}
136
193
        */
146
203
    };
147
204
 
148
205
    Drag.NAME = 'drag';
 
206
    
 
207
    /**
 
208
    * This property defaults to "mousedown", but when drag-gestures is loaded, it is changed to "gesturemovestart"
 
209
    * @static
 
210
    * @property START_EVENT
 
211
    */
 
212
    Drag.START_EVENT = 'mousedown';
149
213
 
150
214
    Drag.ATTRS = {
151
215
        /**
359
423
                this.addTarget(t);
360
424
                return t;
361
425
            }
 
426
        },
 
427
        /**
 
428
        * @attribute haltDown
 
429
        * @description Should the mousedown event be halted. Default: true
 
430
        * @type Boolean
 
431
        */
 
432
        haltDown: {
 
433
            value: true
362
434
        }
363
435
    };
364
436
 
466
538
            });
467
539
            
468
540
            this.publish(EV_END, {
 
541
                defaultFn: this._defEndFn,
469
542
                preventedFn: this._prevEndFn,
470
543
                queuable: false,
471
544
                emitFacade: true,
681
754
        */
682
755
        _defMouseDownFn: function(e) {
683
756
            var ev = e.ev;
 
757
 
684
758
            this._dragThreshMet = false;
685
759
            this._ev_md = ev;
686
760
            
689
763
            }
690
764
            if (this.validClick(ev)) {
691
765
                this._fixIEMouseDown();
692
 
                ev.halt();
 
766
                if (this.get('haltDown')) {
 
767
                    ev.halt();
 
768
                } else {
 
769
                    ev.preventDefault();
 
770
                }
 
771
                
693
772
                this._setStartPosition([ev.pageX, ev.pageY]);
694
773
 
695
774
                DDM.activeDrag = this;
790
869
        * @description The method passed to setTimeout to determine if the clickTimeThreshold was met.
791
870
        */
792
871
        _timeoutCheck: function() {
793
 
            if (!this.get('lock') && !this._dragThreshMet) {
 
872
            if (!this.get('lock') && !this._dragThreshMet && this._ev_md) {
794
873
                this._fromTimeout = this._dragThreshMet = true;
795
874
                this.start();
796
875
                this._alignNode([this._ev_md.pageX, this._ev_md.pageY], true);
901
980
            this._dragThreshMet = false;
902
981
            var node = this.get(NODE);
903
982
            node.addClass(DDM.CSS_PREFIX + '-draggable');
904
 
            node.on(MOUSE_DOWN, Y.bind(this._handleMouseDownEvent, this));
905
 
            node.on(MOUSE_UP, Y.bind(this._handleMouseUp, this));
906
 
            node.on(DRAG_START, Y.bind(this._fixDragStart, this));
 
983
 
 
984
            node.addClass(DDM.CSS_PREFIX + '-draggable');
 
985
            node.on(Drag.START_EVENT, Y.bind(this._handleMouseDownEvent, this));
 
986
            node.on('mouseup', Y.bind(this._handleMouseUp, this));
 
987
            node.on('dragstart', Y.bind(this._fixDragStart, this));
907
988
        },
908
989
        /**
909
990
        * @private
968
1049
            if (this._clickTimeout) {
969
1050
                this._clickTimeout.cancel();
970
1051
            }
971
 
            this._dragThreshMet = false;
972
 
            this._fromTimeout = false;
 
1052
            this._dragThreshMet = this._fromTimeout = false;
 
1053
            this._ev_md = null;
 
1054
 
973
1055
            if (!this.get('lock') && this.get(DRAGGING)) {
974
1056
                this.fire(EV_END, {
975
1057
                    pageX: this.lastXY[0],
986
1068
        },
987
1069
        /**
988
1070
        * @private
 
1071
        * @method _defEndFn
 
1072
        * @description Handler for fixing the selection in IE
 
1073
        */
 
1074
        _defEndFn: function(e) {
 
1075
            this._fixIEMouseUp();
 
1076
        },
 
1077
        /**
 
1078
        * @private
989
1079
        * @method _prevEndFn
990
1080
        * @description Handler for preventing the drag:end event. It will reset the node back to it's start position
991
1081
        */
992
1082
        _prevEndFn: function(e) {
 
1083
            this._fixIEMouseUp();
993
1084
            //Bug #1852577
994
1085
            this.get(DRAG_NODE).setXY(this.nodeXY);
995
1086
        },
1139
1230
 
1140
1231
 
1141
1232
 
1142
 
}, '3.1.2' ,{requires:['dd-ddm-base'], skinnable:false});
 
1233
}, '3.2.0' ,{skinnable:false, requires:['dd-ddm-base']});