Skip to content

Commit

Permalink
v0.10.3, fixes broken touch support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobius1 committed Nov 12, 2017
1 parent d58ba0e commit d844468
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "selectable.js",
"version": "0.10.2",
"version": "0.10.3",
"ignore": [
".gitattributes",
"README.md"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "selectable.js",
"version": "0.10.2",
"version": "0.10.3",
"description": "UI Selectable plugin without the bloat of jQuery and jQuery UI.",
"main": "selectable.min.js",
"scripts": {
Expand Down
69 changes: 34 additions & 35 deletions selectable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version: 0.10.2
* Version: 0.10.3
*
*/
(function(root, factory) {
Expand All @@ -21,7 +21,7 @@
})(typeof global !== 'undefined' ? global : this.window || this.global, function() {
"use strict";

var _version = "0.10.2";
var _version = "0.10.3";

/**
* Check for touch screen
Expand Down Expand Up @@ -343,8 +343,13 @@
}, o.lasso));
}

if (_touch) {
o.toggle = false;
}

this.events = {
start: this.start.bind(this),
touchstart: this.touchstart.bind(this),
drag: this.drag.bind(this),
end: this.end.bind(this),
keyup: this.keyup.bind(this),
Expand Down Expand Up @@ -420,7 +425,7 @@
}

// Mobile
on(this.container, "touchstart", e.start);
on(this.container, "touchstart", e.touchstart);
on(document, "touchend", e.end);
on(document, "touchcancel", e.end);
on(document, "touchmove", e.drag);
Expand Down Expand Up @@ -456,6 +461,17 @@
off(window, 'scroll', e.recalculate);
},

/**
* touchstart event listener
* @param {Object} e Event interface
* @return {Void}
*/
touchstart: function(e) {
off(this.container, "mousedown", this.events.start);

this.start(e);
},

/**
* mousedown / touchstart event listener
* @param {Object} e Event interface
Expand All @@ -478,13 +494,15 @@

if (!node || o.disabled) return false;

var t = e.type === "touchstart";
e.preventDefault();

var touch = e.type === "touchstart";

this.dragging = true;

this.origin = {
x: t ? e.touches[0].clientX : e.pageX,
y: t ? e.touches[0].clientY : e.pageY,
x: touch ? e.touches[0].pageX : e.pageX,
y: touch ? e.touches[0].pageY : e.pageY,
};

if (this.autoscroll) {
Expand All @@ -506,18 +524,6 @@
this.update();
}

// Unselect single item if touched (touchscreens)
if (_touch) {
var item = this.get(node);

if (item.selected) {
// cancel drag
this.dragging = false;
this.unselect(item);
return;
}
}

if (isShiftKey(e)) {

var items = this.items,
Expand Down Expand Up @@ -568,14 +574,10 @@

var unselect = false;

if (o.toggle) {
if (el === node) {
unselect = true;
}
if (touch || o.toggle) {
unselect = el === node;
} else {
if (!_touch && !isCmdKey(e) && !isShiftKey(e)) {
unselect = true;
}
unselect = !isCmdKey(e) && !isShiftKey(e);
}

if (unselect) {
Expand All @@ -593,7 +595,7 @@

this.startEl = node;

this.emit('selectable.start', originalEl);
this.emit('selectable.start', e, originalEl);
},

/**
Expand All @@ -602,12 +604,9 @@
* @return {Void}
*/
drag: function(e) {
if (!this.dragging || isShiftKey(e)) return;

var o = this.config;
if (o.disabled) {
return;
}

if (o.disabled || !this.dragging || isShiftKey(e)) return;

var that = this,
c,
Expand All @@ -617,8 +616,8 @@
this.offset = c = {
x1: this.origin.x,
y1: this.origin.y,
x2: t ? e.touches[0].clientX : e.pageX,
y2: t ? e.touches[0].clientY : e.pageY,
x2: t ? e.touches[0].pageX : e.pageX,
y2: t ? e.touches[0].pageY : e.pageY,
scroll: {
x: 0,
y: 0
Expand Down Expand Up @@ -666,7 +665,7 @@
this.updateHelper(coords);
}

this.emit('selectable.drag', coords);
this.emit('selectable.drag', e, coords);
},

/**
Expand Down Expand Up @@ -743,7 +742,7 @@
}
}, this);

this.emit('selectable.end', selected, unselected);
this.emit('selectable.end', e, selected, unselected);
},

/**
Expand Down
Loading

0 comments on commit d844468

Please sign in to comment.