|
68 | 68 | fn.init = function() {
|
69 | 69 | this.calculate_positions();
|
70 | 70 | this.$container.css('position', 'relative');
|
71 |
| - this.enable(); |
| 71 | + this.disabled = false; |
| 72 | + this.events(); |
72 | 73 |
|
73 | 74 | $(window).bind('resize',
|
74 | 75 | throttle($.proxy(this.calculate_positions, this), 200));
|
75 | 76 | };
|
76 | 77 |
|
| 78 | + fn.events = function() { |
| 79 | + this.$container.on('selectstart', this.on_select_start); |
| 80 | + |
| 81 | + this.$container.on(pointer_events.start, this.options.items, $.proxy( |
| 82 | + this.drag_handler, this)); |
| 83 | + |
| 84 | + this.$body.on(pointer_events.end, $.proxy(function(e) { |
| 85 | + this.is_dragging = false; |
| 86 | + if (this.disabled) { return; } |
| 87 | + this.$body.off(pointer_events.move); |
| 88 | + if (this.drag_start) { |
| 89 | + this.on_dragstop(e); |
| 90 | + } |
| 91 | + }, this)); |
| 92 | + }; |
77 | 93 |
|
78 | 94 | fn.get_actual_pos = function($el) {
|
79 | 95 | var pos = $el.position();
|
|
85 | 101 | if (isTouch) {
|
86 | 102 | var oe = e.originalEvent;
|
87 | 103 | e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
|
88 |
| - }; |
| 104 | + } |
89 | 105 |
|
90 | 106 | return {
|
91 | 107 | left: e.clientX,
|
|
144 | 160 | $window.scrollTop(nextScrollTop);
|
145 | 161 | this.scrollOffset = this.scrollOffset + 30;
|
146 | 162 | }
|
147 |
| - }; |
| 163 | + } |
148 | 164 |
|
149 | 165 | if (abs_mouse_top <= mouse_up_zone) {
|
150 | 166 | nextScrollTop = scrollTop - 30;
|
151 | 167 | if (nextScrollTop > 0) {
|
152 | 168 | $window.scrollTop(nextScrollTop);
|
153 | 169 | this.scrollOffset = this.scrollOffset - 30;
|
154 | 170 | }
|
155 |
| - }; |
156 |
| - } |
| 171 | + } |
| 172 | + }; |
157 | 173 |
|
158 | 174 |
|
159 | 175 | fn.calculate_positions = function(e) {
|
160 | 176 | this.window_height = $window.height();
|
161 |
| - } |
| 177 | + }; |
162 | 178 |
|
163 | 179 |
|
164 | 180 | fn.drag_handler = function(e) {
|
165 | 181 | var node = e.target.nodeName;
|
166 |
| - |
167 |
| - if (e.which !== 1 && !isTouch) { |
| 182 | + if (this.disabled || e.which !== 1 && !isTouch) { |
168 | 183 | return;
|
169 | 184 | }
|
170 | 185 |
|
171 | 186 | if (node === 'INPUT' || node === 'TEXTAREA' || node === 'SELECT' ||
|
172 | 187 | node === 'BUTTON') {
|
173 | 188 | return;
|
174 |
| - }; |
| 189 | + } |
175 | 190 |
|
176 | 191 | var self = this;
|
177 | 192 | var first = true;
|
|
199 | 214 | return false;
|
200 | 215 | }
|
201 | 216 |
|
202 |
| - if (self.is_dragging == true) { |
| 217 | + if (self.is_dragging === true) { |
203 | 218 | self.on_dragmove.call(self, mme);
|
204 | 219 | }
|
205 | 220 |
|
|
290 | 305 | };
|
291 | 306 |
|
292 | 307 | fn.on_select_start = function(e) {
|
| 308 | + if (this.disabled) { return; } |
293 | 309 | return false;
|
294 |
| - } |
295 |
| - |
296 |
| - |
297 |
| - fn.enable = function(){ |
298 |
| - this.$container.on('selectstart', this.on_select_start); |
299 |
| - |
300 |
| - this.$container.on(pointer_events.start, this.options.items, $.proxy( |
301 |
| - this.drag_handler, this)); |
302 |
| - |
303 |
| - this.$body.on(pointer_events.end, $.proxy(function(e) { |
304 |
| - this.is_dragging = false; |
305 |
| - this.$body.off(pointer_events.move); |
306 |
| - if (this.drag_start) { |
307 |
| - this.on_dragstop(e); |
308 |
| - } |
309 |
| - }, this)); |
310 | 310 | };
|
311 | 311 |
|
| 312 | + fn.enable = function() { |
| 313 | + this.disabled = false; |
| 314 | + }; |
312 | 315 |
|
313 |
| - fn.disable = function(){ |
314 |
| - this.$container.off(pointer_events.start); |
315 |
| - this.$body.off(pointer_events.end); |
316 |
| - this.$container.off('selectstart', this.on_select_start); |
| 316 | + fn.disable = function() { |
| 317 | + this.disabled = true; |
317 | 318 | };
|
318 | 319 |
|
319 | 320 |
|
|
322 | 323 | $.removeData(this.$container, 'drag');
|
323 | 324 | };
|
324 | 325 |
|
325 |
| - |
326 | 326 | //jQuery adapter
|
327 | 327 | $.fn.drag = function ( options ) {
|
328 | 328 | return this.each(function () {
|
|
0 commit comments