Skip to content

Commit

Permalink
Merge pull request #51 from stuyam/dev-v2.0.1
Browse files Browse the repository at this point in the history
Cancel the polyfill if at any point force is detected
  • Loading branch information
stuyam authored Oct 24, 2016
2 parents a188d91 + d23aaad commit d8b5126
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
"test",
"tests"
],
"version": "2.0.0"
"version": "2.0.1"
}
18 changes: 13 additions & 5 deletions dist/jquery.pressure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Pressure v2.0.0 | Created By Stuart Yamartino | MIT License | 2015 - 2016
// Pressure v2.0.1 | Created By Stuart Yamartino | MIT License | 2015 - 2016
;(function(window, document, $) {
"use strict";

Expand Down Expand Up @@ -120,6 +120,7 @@ var Adapter = function () {
this.options = options;
this.pressed = false;
this.deepPressed = false;
this.nativeSupport = false;
this.runKey = Math.random();
}

Expand Down Expand Up @@ -192,6 +193,12 @@ var Adapter = function () {
this.runClosure('startDeepPress', event);
}
}
}, {
key: "_changePress",
value: function _changePress(force, event) {
this.nativeSupport = true;
this.runClosure('change', force, event);
}
}, {
key: "_endDeepPress",
value: function _endDeepPress() {
Expand All @@ -209,6 +216,7 @@ var Adapter = function () {
this.runClosure('end');
}
this.runKey = Math.random();
this.nativeSupport = false;
}
}, {
key: "runPolyfill",
Expand All @@ -221,7 +229,7 @@ var Adapter = function () {
}, {
key: "loopPolyfillForce",
value: function loopPolyfillForce(force, event) {
if (this.isPressed()) {
if (this.isPressed() && this.nativeSupport === false) {
this.runClosure('change', force, event);
force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
force = force + this.increment > 1 ? 1 : force + this.increment;
Expand Down Expand Up @@ -268,7 +276,7 @@ var AdapterForceTouch = function (_Adapter) {
key: "change",
value: function change(event) {
if (this.isPressed() && event.webkitForce > 0) {
this.runClosure('change', this.normalizeForce(event.webkitForce), event);
this._changePress(this.normalizeForce(event.webkitForce), event);
}
}

Expand Down Expand Up @@ -322,7 +330,7 @@ var Adapter3DTouch = function (_Adapter2) {
value: function start(event) {
if (event.touches.length > 0) {
this._startPress(event);
this.runClosure('change', this.selectTouch(event).force, event);
this._changePress(this.selectTouch(event).force, event);
}
}
}, {
Expand Down Expand Up @@ -369,7 +377,7 @@ var Adapter3DTouch = function (_Adapter2) {
if (this.isPressed()) {
this.touch = this.selectTouch(event);
setTimeout(this.loopForce.bind(this, event), 10);
this.runClosure('change', this.touch.force, event);
this._changePress(this.touch.force, event);
}
}

Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.pressure.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d8b5126

Please sign in to comment.