@telerik/kendo-draggable
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -104,3 +104,3 @@ module.exports = | ||
var Draggable = function () { | ||
function Draggable(element, _ref) { | ||
function Draggable(_ref) { | ||
var _this = this; | ||
@@ -130,3 +130,3 @@ | ||
this._touchend = function (e) { | ||
// the last finger has been lifted, and the user is not performing a gesture. | ||
// the last finger has been lifted, and the user is not doing gesture. | ||
// there might be a better way to handle this. | ||
@@ -166,14 +166,22 @@ if (e.touches.length === 0 && e.changedTouches.length === 1) { | ||
this._element = element; | ||
this._ignoreMouse = false; | ||
bind(element, "mousedown", this._mousedown); | ||
bind(element, "touchstart", this._touchstart); | ||
bind(element, "touchmove", this._touchmove); | ||
bind(element, "touchend", this._touchend); | ||
} | ||
_createClass(Draggable, [{ | ||
key: "destroy", | ||
value: function destroy() { | ||
key: "bindTo", | ||
value: function bindTo(element) { | ||
if (this._element) { | ||
this._unbindFromCurrent(); | ||
} | ||
this._element = element; | ||
bind(element, "mousedown", this._mousedown); | ||
bind(element, "touchstart", this._touchstart); | ||
bind(element, "touchmove", this._touchmove); | ||
bind(element, "touchend", this._touchend); | ||
} | ||
}, { | ||
key: "_unbindFromCurrent", | ||
value: function _unbindFromCurrent() { | ||
unbind(this._element, "mousedown", this._mousedown); | ||
@@ -183,3 +191,7 @@ unbind(this._element, "touchstart", this._touchstart); | ||
unbind(this._element, "touchend", this._touchend); | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy() { | ||
this._unbindFromCurrent(); | ||
this._element = null; | ||
@@ -186,0 +198,0 @@ } |
{ | ||
"name": "@telerik/kendo-draggable", | ||
"description": "A cross-browser/event abstraction that handles mouse and touch drag sequences", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"repository": { | ||
@@ -56,2 +56,2 @@ "type": "git", | ||
} | ||
} | ||
} |
@@ -22,3 +22,3 @@ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) | ||
The draggable class constructor accepts an element and an object with three optional event handler callbacks - `press`, `drag`, and `release`. | ||
The draggable class constructor accepts an object with three optional event handler callbacks - `press`, `drag`, and `release`. | ||
@@ -28,5 +28,3 @@ ```javascript | ||
const element = document.getElementById("my-element"); | ||
const draggable = new Draggable(element, { | ||
const draggable = new Draggable({ | ||
press: function(e) { | ||
@@ -42,7 +40,15 @@ console.log("pressed", e.pageX, e.pageY); | ||
}); | ||
draggable.bindTo(document.getElementById("my-element")); | ||
``` | ||
Since the draggable object persists a reference to the element, it should be destroyed when/if the corresponding element is removed from the document. | ||
The draggable may be re-bound to another element - the event handlers will be automatically unbound from the previous one. | ||
```javascript | ||
draggable.bindTo(document.getElementById("another-element")); | ||
``` | ||
Since the draggable object persists a reference to the currently bound element, it should be destroyed when/if the corresponding element is removed from the document. | ||
```javascript | ||
draggable.destroy(); | ||
@@ -49,0 +55,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11929
159
92