You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
996 B
JavaScript
43 lines
996 B
JavaScript
'use strict';
|
|
|
|
var debounce = require("debounce");
|
|
var defaultValue = require("default-value");
|
|
|
|
var selectable = require("./selectable");
|
|
|
|
module.exports = function ($) {
|
|
selectable($);
|
|
|
|
$.fn.draggable = function () {
|
|
var _this = this;
|
|
|
|
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
|
|
|
var debounceInterval = defaultValue(options.debounce, 10);
|
|
|
|
this.on("mousedown", function (event) {
|
|
var startX = event.pageX;
|
|
var startY = event.pageY;
|
|
|
|
var moveHandler = debounce(function (event) {
|
|
_this.trigger("draggable:move", [{
|
|
offsetX: event.pageX - startX,
|
|
offsetY: event.pageY - startY
|
|
}]);
|
|
}, debounceInterval);
|
|
|
|
$(document).on("mousemove", moveHandler);
|
|
|
|
$(document).one("mouseup", function (event) {
|
|
$(document).off("mousemove", moveHandler);
|
|
$(document).enableSelection();
|
|
|
|
_this.trigger("draggable:end");
|
|
});
|
|
|
|
$(document).disableSelection();
|
|
|
|
_this.trigger("draggable:start");
|
|
});
|
|
};
|
|
}; |