|
36 | 36 | var $window = $(window);
|
37 | 37 | var dir_map = { x : 'left', y : 'top' };
|
38 | 38 | var isTouch = !!('ontouchstart' in window);
|
39 |
| - var pointer_events = { |
40 |
| - start: 'touchstart.gridster-draggable mousedown.gridster-draggable', |
41 |
| - move: 'touchmove.gridster-draggable mousemove.gridster-draggable', |
42 |
| - end: 'touchend.gridster-draggable mouseup.gridster-draggable' |
43 |
| - }; |
44 | 39 |
|
45 | 40 | var capitalize = function(str) {
|
46 | 41 | return str.charAt(0).toUpperCase() + str.slice(1);
|
47 | 42 | };
|
48 | 43 |
|
| 44 | + var idCounter = 0; |
| 45 | + var uniqId = function() { |
| 46 | + return ++idCounter + ''; |
| 47 | + } |
| 48 | + |
49 | 49 | /**
|
50 | 50 | * Basic drag implementation for DOM elements inside a container.
|
51 | 51 | * Provide start/stop/drag callbacks.
|
|
82 | 82 | this.$dragitems = $(this.options.items, this.$container);
|
83 | 83 | this.is_dragging = false;
|
84 | 84 | this.player_min_left = 0 + this.options.offset_left;
|
| 85 | + this.id = uniqId(); |
| 86 | + this.ns = '.gridster-draggable-' + this.id; |
85 | 87 | this.init();
|
86 | 88 | }
|
87 | 89 |
|
|
96 | 98 | this.disabled = false;
|
97 | 99 | this.events();
|
98 | 100 |
|
99 |
| - $(window).bind('resize.gridster-draggable', |
| 101 | + $(window).bind(this.nsEvent('resize'), |
100 | 102 | throttle($.proxy(this.calculate_dimensions, this), 200));
|
101 | 103 | };
|
102 | 104 |
|
| 105 | + fn.nsEvent = function(ev) { |
| 106 | + return (ev || '') + this.ns; |
| 107 | + }; |
| 108 | + |
103 | 109 | fn.events = function() {
|
104 |
| - this.$container.on('selectstart.gridster-draggable', |
| 110 | + this.pointer_events = { |
| 111 | + start: this.nsEvent('touchstart') + ' ' + this.nsEvent('mousedown'), |
| 112 | + move: this.nsEvent('touchmove') + ' ' + this.nsEvent('mousemove'), |
| 113 | + end: this.nsEvent('touchend') + ' ' + this.nsEvent('mouseup'), |
| 114 | + }; |
| 115 | + |
| 116 | + this.$container.on(this.nsEvent('selectstart'), |
105 | 117 | $.proxy(this.on_select_start, this));
|
106 | 118 |
|
107 |
| - this.$container.on(pointer_events.start, this.options.items, |
| 119 | + this.$container.on(this.pointer_events.start, this.options.items, |
108 | 120 | $.proxy(this.drag_handler, this));
|
109 | 121 |
|
110 |
| - this.$document.on(pointer_events.end, $.proxy(function(e) { |
| 122 | + this.$document.on(this.pointer_events.end, $.proxy(function(e) { |
111 | 123 | this.is_dragging = false;
|
112 | 124 | if (this.disabled) { return; }
|
113 |
| - this.$document.off(pointer_events.move); |
| 125 | + this.$document.off(this.pointer_events.move); |
114 | 126 | if (this.drag_start) {
|
115 | 127 | this.on_dragstop(e);
|
116 | 128 | }
|
|
265 | 277 | this.mouse_init_pos = this.get_mouse_pos(e);
|
266 | 278 | this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
|
267 | 279 |
|
268 |
| - this.$document.on(pointer_events.move, function(mme) { |
| 280 | + this.$document.on(this.pointer_events.move, function(mme) { |
269 | 281 | var mouse_actual_pos = self.get_mouse_pos(mme);
|
270 | 282 | var diff_x = Math.abs(
|
271 | 283 | mouse_actual_pos.left - self.mouse_init_pos.left);
|
|
391 | 403 | fn.destroy = function() {
|
392 | 404 | this.disable();
|
393 | 405 |
|
394 |
| - this.$container.off('.gridster-draggable'); |
395 |
| - this.$document.off('.gridster-draggable'); |
396 |
| - $(window).off('.gridster-draggable'); |
| 406 | + this.$container.off(this.ns); |
| 407 | + this.$document.off(this.ns); |
| 408 | + $(window).off(this.ns); |
397 | 409 |
|
398 | 410 | $.removeData(this.$container, 'drag');
|
399 | 411 | };
|
|
0 commit comments