mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fixed disable method, it didn't work well for multiple instances.
Previously, disabling gridster caused all the instances of Gridster running on the pages was disabled. Because Draggable class uses event delegation from the body to manage drag events.
This commit is contained in:
@ -68,12 +68,28 @@
|
|||||||
fn.init = function() {
|
fn.init = function() {
|
||||||
this.calculate_positions();
|
this.calculate_positions();
|
||||||
this.$container.css('position', 'relative');
|
this.$container.css('position', 'relative');
|
||||||
this.enable();
|
this.disabled = false;
|
||||||
|
this.events();
|
||||||
|
|
||||||
$(window).bind('resize',
|
$(window).bind('resize',
|
||||||
throttle($.proxy(this.calculate_positions, this), 200));
|
throttle($.proxy(this.calculate_positions, this), 200));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fn.events = function() {
|
||||||
|
this.$container.on('selectstart', this.on_select_start);
|
||||||
|
|
||||||
|
this.$container.on(pointer_events.start, this.options.items, $.proxy(
|
||||||
|
this.drag_handler, this));
|
||||||
|
|
||||||
|
this.$body.on(pointer_events.end, $.proxy(function(e) {
|
||||||
|
this.is_dragging = false;
|
||||||
|
if (this.disabled) { return; }
|
||||||
|
this.$body.off(pointer_events.move);
|
||||||
|
if (this.drag_start) {
|
||||||
|
this.on_dragstop(e);
|
||||||
|
}
|
||||||
|
}, this));
|
||||||
|
};
|
||||||
|
|
||||||
fn.get_actual_pos = function($el) {
|
fn.get_actual_pos = function($el) {
|
||||||
var pos = $el.position();
|
var pos = $el.position();
|
||||||
@ -85,7 +101,7 @@
|
|||||||
if (isTouch) {
|
if (isTouch) {
|
||||||
var oe = e.originalEvent;
|
var oe = e.originalEvent;
|
||||||
e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
|
e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
|
||||||
};
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
left: e.clientX,
|
left: e.clientX,
|
||||||
@ -144,7 +160,7 @@
|
|||||||
$window.scrollTop(nextScrollTop);
|
$window.scrollTop(nextScrollTop);
|
||||||
this.scrollOffset = this.scrollOffset + 30;
|
this.scrollOffset = this.scrollOffset + 30;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
if (abs_mouse_top <= mouse_up_zone) {
|
if (abs_mouse_top <= mouse_up_zone) {
|
||||||
nextScrollTop = scrollTop - 30;
|
nextScrollTop = scrollTop - 30;
|
||||||
@ -152,26 +168,25 @@
|
|||||||
$window.scrollTop(nextScrollTop);
|
$window.scrollTop(nextScrollTop);
|
||||||
this.scrollOffset = this.scrollOffset - 30;
|
this.scrollOffset = this.scrollOffset - 30;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
fn.calculate_positions = function(e) {
|
fn.calculate_positions = function(e) {
|
||||||
this.window_height = $window.height();
|
this.window_height = $window.height();
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
fn.drag_handler = function(e) {
|
fn.drag_handler = function(e) {
|
||||||
var node = e.target.nodeName;
|
var node = e.target.nodeName;
|
||||||
|
if (this.disabled || e.which !== 1 && !isTouch) {
|
||||||
if (e.which !== 1 && !isTouch) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node === 'INPUT' || node === 'TEXTAREA' || node === 'SELECT' ||
|
if (node === 'INPUT' || node === 'TEXTAREA' || node === 'SELECT' ||
|
||||||
node === 'BUTTON') {
|
node === 'BUTTON') {
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var first = true;
|
var first = true;
|
||||||
@ -199,7 +214,7 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.is_dragging == true) {
|
if (self.is_dragging === true) {
|
||||||
self.on_dragmove.call(self, mme);
|
self.on_dragmove.call(self, mme);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,30 +305,16 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
fn.on_select_start = function(e) {
|
fn.on_select_start = function(e) {
|
||||||
|
if (this.disabled) { return; }
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fn.enable = function(){
|
|
||||||
this.$container.on('selectstart', this.on_select_start);
|
|
||||||
|
|
||||||
this.$container.on(pointer_events.start, this.options.items, $.proxy(
|
|
||||||
this.drag_handler, this));
|
|
||||||
|
|
||||||
this.$body.on(pointer_events.end, $.proxy(function(e) {
|
|
||||||
this.is_dragging = false;
|
|
||||||
this.$body.off(pointer_events.move);
|
|
||||||
if (this.drag_start) {
|
|
||||||
this.on_dragstop(e);
|
|
||||||
}
|
|
||||||
}, this));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fn.enable = function() {
|
||||||
|
this.disabled = false;
|
||||||
|
};
|
||||||
|
|
||||||
fn.disable = function() {
|
fn.disable = function() {
|
||||||
this.$container.off(pointer_events.start);
|
this.disabled = true;
|
||||||
this.$body.off(pointer_events.end);
|
|
||||||
this.$container.off('selectstart', this.on_select_start);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -322,7 +323,6 @@
|
|||||||
$.removeData(this.$container, 'drag');
|
$.removeData(this.$container, 'drag');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//jQuery adapter
|
//jQuery adapter
|
||||||
$.fn.drag = function ( options ) {
|
$.fn.drag = function ( options ) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
|
Reference in New Issue
Block a user