Socket
Socket
Sign inDemoInstall

pressure

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pressure - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

.github/ISSUE_TEMPLATE.md

10

bower.json
{
"name": "pressure",
"description": "Pressure is a JavaScript library for handling both Force Touch and 3D Touch through a single API",
"description": "Pressure is a lightweight JavaScript library for both Force Touch and 3D Touch through a single API.",
"main": "dist/pressure.min.js",

@@ -17,3 +17,7 @@ "authors": [

"iphone6s",
"iphone6splus"
"iphone6splus",
"iphone7",
"iphone7plus",
"magic-trackpad",
"apple-pencil"
],

@@ -29,3 +33,3 @@ "homepage": "https://github.com/yamartino/pressure",

],
"version": "1.0.1"
"version": "2.0.0"
}

@@ -1,2 +0,2 @@

// Pressure v1.0.1 | Created By Stuart Yamartino | MIT License | 2015-Present
// Pressure v2.0.0 | Created By Stuart Yamartino | MIT License | 2015 - 2016
;(function(window, document, $) {

@@ -27,3 +27,3 @@ "use strict";

}, $.pressureMap = function (x, in_min, in_max, out_min, out_max) {
return map(x, in_min, in_max, out_min, out_max);
return map.apply(null, arguments);
};

@@ -67,10 +67,7 @@ } else {

var Element = function () {
function Element(element, block, options) {
function Element(el, block, options) {
_classCallCheck(this, Element);
this.element = element;
this.block = block;
this.type = Config.get('only', options);
this.options = options;
this.routeEvents();
this.routeEvents(el, block, options);
this.preventSelect(el, options);
}

@@ -80,24 +77,31 @@

key: "routeEvents",
value: function routeEvents() {
value: function routeEvents(el, block, options) {
var type = Config.get('only', options);
// if on desktop and requesting Force Touch or not requesting 3D Touch
if (Support.mobile === false && (this.type === 'force' || this.type !== '3d')) {
new AdapterForceTouch(this);
if (isDesktop && (type === 'desktop' || type !== 'mobile')) {
this.adapter = new AdapterForceTouch(el, block, options).bindEvents();
}
// if on mobile and requesting 3D Touch or not requestion Force Touch
else if (Support.mobile === true && (this.type === '3d' || this.type !== 'force')) {
new Adapter3DTouch(this);
else if (isMobile && (type === 'mobile' || type !== 'desktop')) {
this.adapter = new Adapter3DTouch(el, block, options).bindEvents();
}
// if it is requesting a type and your browser is of other type
// unsupported if it is requesting a type and your browser is of other type
else {
this.instantFail();
this.adapter = new Adapter(el, block).bindUnsupportedEvent();
}
}
// prevent the default action of text selection, "peak & pop", and force touch special feature
}, {
key: "instantFail",
value: function instantFail() {
var _this = this;
this.element.addEventListener(Support.mobile ? 'touchstart' : 'mousedown', function () {
return runClosure(_this.block, 'unsupported', _this.element);
}, false);
key: "preventSelect",
value: function preventSelect(el, options) {
if (Config.get('preventSelect', options)) {
el.style.webkitTouchCallout = "none";
el.style.webkitUserSelect = "none";
el.style.khtmlUserSelect = "none";
el.style.MozUserSelect = "none";
el.style.msUserSelect = "none";
el.style.userSelect = "none";
}
}

@@ -109,24 +113,19 @@ }]);

/*
This is the base adapter from which all the other adapters extend.
*/
var Adapter = function () {
function Adapter(element) {
function Adapter(el, block, options) {
_classCallCheck(this, Adapter);
this.element = element;
this.el = element.element;
this.block = element.block;
this.el = el;
this.block = block;
this.options = options;
this.pressed = false;
this.deepPressed = false;
this.runKey = Math.random();
}
_createClass(Adapter, [{
key: "add",
value: function add(event, set) {
this.el.addEventListener(event, set, false);
}
}, {
key: "remove",
value: function remove(event, set) {
this.el.removeEventListener(event, set);
}
}, {
key: "setPressed",

@@ -142,301 +141,140 @@ value: function setPressed(boolean) {

}, {
key: "failOrPolyfill",
value: function failOrPolyfill(event) {
Support.didFail();
// is the polyfill option set
if (Config.get('polyfill', this.element.options) === true) {
this.polyfill = new AdapterPolyfill(this.element, event);
} else {
runClosure(this.block, 'unsupported', this.el);
}
key: "isPressed",
value: function isPressed() {
return this.pressed;
}
// prevent the default action of text selection, "peak & pop", and force touch special feature
}, {
key: "preventDefault",
value: function preventDefault(event) {
if (Config.get('preventDefault', this.element.options) === true) {
event.preventDefault();
this.el.style.webkitTouchCallout = "none";
this.el.style.userSelect = "none";
this.el.style.webkitUserSelect = "none";
this.el.style.MozUserSelect = "none";
}
key: "isDeepPressed",
value: function isDeepPressed() {
return this.deepPressed;
}
}]);
return Adapter;
}();
var Adapter3DTouch = function (_Adapter) {
_inherits(Adapter3DTouch, _Adapter);
function Adapter3DTouch(element) {
_classCallCheck(this, Adapter3DTouch);
var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(Adapter3DTouch).call(this, element));
_this2.$support();
_this2.$start();
_this2.$change();
_this2.$end();
return _this2;
}
_createClass(Adapter3DTouch, [{
key: "$support",
value: function $support() {
this.supportMethod = this.middleMan.bind(this);
this.add('touchstart', this.supportMethod);
}, {
key: "add",
value: function add(event, set) {
this.el.addEventListener(event, set, false);
}
}, {
key: "middleMan",
value: function middleMan(event) {
this.setPressed(true);
this.forceValueTest = event.touches[0].force;
this.supportCallback(0, event);
key: "runClosure",
value: function runClosure(method) {
if (method in this.block) {
// call the closure method and apply nth arguments if they exist
this.block[method].apply(this.el, Array.prototype.slice.call(arguments, 1));
}
}
}, {
key: "supportCallback",
value: function supportCallback(iter, event) {
// this checks up to 10 times on a touch to see if the touch can read a force value or not to check "support"
if (Support.hasRun === false && !(this.polyfill instanceof AdapterPolyfill)) {
// if the force value has changed it means the device supports pressure
// more info from this issue https://github.com/yamartino/pressure/issues/15
if (event.touches[0].force !== this.forceValueTest) {
this.preventDefault(event);
Support.didSucceed('3d');
this.remove('touchstart', this.supportMethod);
runClosure(this.block, 'start', this.el, event);
this.changeLogic(event);
} else if (iter <= 10 && this.pressed) {
iter += 1;
setTimeout(this.supportCallback.bind(this), 10, iter, event);
} else if (this.pressed) {
this.failOrPolyfill(event);
key: "fail",
value: function fail(event, runKey) {
if (Config.get('polyfill', this.options)) {
if (this.runKey === runKey) {
this.runPolyfill(event);
}
} else if (Support.forPressure || this.polyfill instanceof AdapterPolyfill) {
this.remove('touchstart', this.supportMethod);
} else {
this.failOrPolyfill(event);
this.runClosure('unsupported', event);
}
}
}, {
key: "$start",
value: function $start() {
var _this3 = this;
key: "bindUnsupportedEvent",
value: function bindUnsupportedEvent() {
var _this = this;
// call 'start' when the touch goes down
this.add('touchstart', function (event) {
if (Support.forPressure) {
_this3.setPressed(true);
_this3.preventDefault(event);
runClosure(_this3.block, 'start', _this3.el, event);
}
this.add(isMobile ? 'touchstart' : 'mousedown', function (event) {
return _this.runClosure('unsupported', event);
});
}
}, {
key: "$change",
value: function $change() {
this.add('touchstart', this.changeLogic.bind(this));
}
}, {
key: "changeLogic",
value: function changeLogic(event) {
if (Support.forPressure && this.pressed) {
key: "_startPress",
value: function _startPress(event) {
if (this.isPressed() === false) {
this.setPressed(true);
this.runForce(event);
this.runClosure('start', event);
}
}
}, {
key: "$end",
value: function $end() {
var _this4 = this;
// call 'end' when the touch goes up
this.add('touchend', function () {
if (Support.forPressure) {
_this4.endDeepPress();
_this4.setPressed(false);
runClosure(_this4.block, 'end', _this4.el);
}
});
key: "_startDeepPress",
value: function _startDeepPress(event) {
if (this.isPressed() && this.isDeepPressed() === false) {
this.setDeepPressed(true);
this.runClosure('startDeepPress', event);
}
}
}, {
key: "startDeepPress",
value: function startDeepPress(event) {
if (this.deepPressed === false) {
runClosure(this.block, 'startDeepPress', this.el, event);
key: "_endDeepPress",
value: function _endDeepPress() {
if (this.isPressed() && this.isDeepPressed()) {
this.setDeepPressed(false);
this.runClosure('endDeepPress');
}
this.setDeepPressed(true);
}
}, {
key: "endDeepPress",
value: function endDeepPress() {
if (this.deepPressed === true) {
runClosure(this.block, 'endDeepPress', this.el);
key: "_endPress",
value: function _endPress() {
if (this.isPressed()) {
this._endDeepPress();
this.setPressed(false);
this.runClosure('end');
}
this.setDeepPressed(false);
this.runKey = Math.random();
}
}, {
key: "runForce",
value: function runForce(event) {
if (this.pressed) {
this.touch = this.selectTouch(event);
setTimeout(this.runForce.bind(this), 10, event);
runClosure(this.block, 'change', this.el, this.touch.force, event);
}
key: "runPolyfill",
value: function runPolyfill(event) {
this.increment = 10 / Config.get('polyfillSpeed', this.options);
this.setPressed(true);
this.runClosure('start', event);
this.loopPolyfillForce(0, event);
}
// link up the touch point to the correct element, this is to support multitouch
}, {
key: "selectTouch",
value: function selectTouch(event) {
if (event.touches.length === 1) {
return this.returnTouch(event.touches[0], event);
} else {
for (var i = 0; i < event.touches.length; i++) {
// if the target press is on this element
if (event.touches[i].target === this.el) {
return this.returnTouch(event.touches[i], event);
}
}
key: "loopPolyfillForce",
value: function loopPolyfillForce(force, event) {
if (this.isPressed()) {
this.runClosure('change', force, event);
force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
force = force + this.increment > 1 ? 1 : force + this.increment;
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
}
}
}]);
// return the touch and run a start or end for deep press
return Adapter;
}();
}, {
key: "returnTouch",
value: function returnTouch(touch, event) {
touch.force >= 0.5 ? this.startDeepPress(event) : this.endDeepPress();
return touch;
}
}]);
/*
This adapter is for Macs with Force Touch trackpads.
*/
return Adapter3DTouch;
}(Adapter);
var AdapterForceTouch = function (_Adapter) {
_inherits(AdapterForceTouch, _Adapter);
var AdapterForceTouch = function (_Adapter2) {
_inherits(AdapterForceTouch, _Adapter2);
function AdapterForceTouch(element) {
function AdapterForceTouch(el, block, options) {
_classCallCheck(this, AdapterForceTouch);
var _this5 = _possibleConstructorReturn(this, Object.getPrototypeOf(AdapterForceTouch).call(this, element));
_this5.$support();
_this5.$start();
_this5.$change();
_this5.$startDeepPress();
_this5.$endDeepPress();
_this5.$end();
return _this5;
return _possibleConstructorReturn(this, Object.getPrototypeOf(AdapterForceTouch).call(this, el, block, options));
}
// Support check methods
_createClass(AdapterForceTouch, [{
key: "$support",
value: function $support() {
this.add('webkitmouseforcewillbegin', this.forceTouchEnabled);
this.add('mousedown', this.supportCallback.bind(this));
key: "bindEvents",
value: function bindEvents() {
this.add('webkitmouseforcewillbegin', this._startPress.bind(this));
this.add('mousedown', this.support.bind(this));
this.add('webkitmouseforcechanged', this.change.bind(this));
this.add('webkitmouseforcedown', this._startDeepPress.bind(this));
this.add('webkitmouseforceup', this._endDeepPress.bind(this));
this.add('mouseleave', this._endPress.bind(this));
this.add('mouseup', this._endPress.bind(this));
}
}, {
key: "forceTouchEnabled",
value: function forceTouchEnabled(event) {
event.preventDefault();
Support.didSucceed('force');
key: "support",
value: function support(event) {
if (this.isPressed() === false) {
this.fail(event, this.runKey);
}
}
}, {
key: "supportCallback",
value: function supportCallback(event) {
if (Support.forPressure === true || this.polyfill instanceof AdapterPolyfill) {
this.remove('webkitmouseforcewillbegin', this.forceTouchEnabled);
this.preventDefault(event);
} else {
this.failOrPolyfill(event);
key: "change",
value: function change(event) {
if (this.isPressed() && event.webkitForce > 0) {
this.runClosure('change', this.normalizeForce(event.webkitForce), event);
}
}
}, {
key: "$start",
value: function $start() {
var _this6 = this;
// call 'start' when the mouse goes down
this.add('mousedown', function (event) {
if (Support.forPressure) {
_this6.setPressed(true);
runClosure(_this6.block, 'start', _this6.el, event);
}
});
}
}, {
key: "$change",
value: function $change() {
var _this7 = this;
this.add('webkitmouseforcechanged', function (event) {
if (Support.forPressure && event.webkitForce !== 0 && _this7.pressed) {
runClosure(_this7.block, 'change', _this7.el, _this7.normalizeForce(event.webkitForce), event);
}
});
}
}, {
key: "$end",
value: function $end() {
var _this8 = this;
// call 'end' when the mouse goes up or leaves the element
this.add('mouseup', function () {
if (Support.forPressure) {
_this8.setPressed(false);
runClosure(_this8.block, 'end', _this8.el);
}
});
this.add('mouseleave', function () {
if (Support.forPressure) {
if (_this8.pressed) {
runClosure(_this8.block, 'end', _this8.el);
}
_this8.setPressed(false);
}
});
}
}, {
key: "$startDeepPress",
value: function $startDeepPress() {
var _this9 = this;
this.add('webkitmouseforcedown', function (event) {
if (Support.forPressure) {
_this9.setDeepPressed(true);
runClosure(_this9.block, 'startDeepPress', _this9.el, event);
}
});
}
}, {
key: "$endDeepPress",
value: function $endDeepPress() {
var _this10 = this;
this.add('webkitmouseforceup', function () {
if (Support.forPressure) {
_this10.setDeepPressed(false);
runClosure(_this10.block, 'endDeepPress', _this10.el);
}
});
this.add('mouseleave', function () {
if (Support.forPressure) {
if (_this10.deepPressed) {
runClosure(_this10.block, 'endDeepPress', _this10.el);
}
_this10.setDeepPressed(false);
}
});
}
// make the force the standard 0 to 1 scale and not the 1 to 3 scale

@@ -450,3 +288,3 @@

// if the force value is above 0.999 set the force to 1
// if the force value is above 0.995 set the force to 1

@@ -456,3 +294,3 @@ }, {

value: function reachOne(force) {
return force > 0.999 ? 1 : force;
return force > 0.995 ? 1 : force;
}

@@ -464,105 +302,111 @@ }]);

var AdapterPolyfill = function (_Adapter3) {
_inherits(AdapterPolyfill, _Adapter3);
/*
This adapter is more mobile devices that support 3D Touch.
*/
function AdapterPolyfill(element, firstEvent) {
_classCallCheck(this, AdapterPolyfill);
var Adapter3DTouch = function (_Adapter2) {
_inherits(Adapter3DTouch, _Adapter2);
var _this11 = _possibleConstructorReturn(this, Object.getPrototypeOf(AdapterPolyfill).call(this, element));
function Adapter3DTouch(el, block, options) {
_classCallCheck(this, Adapter3DTouch);
_this11.$start();
_this11.$change();
_this11.$end();
_this11.force = 0;
_this11.increment = 0.01;
_this11.firstRun(firstEvent);
return _this11;
return _possibleConstructorReturn(this, Object.getPrototypeOf(Adapter3DTouch).call(this, el, block, options));
}
_createClass(AdapterPolyfill, [{
key: "firstRun",
value: function firstRun(event) {
this.preventDefault(event);
this.startLogic(event);
this.changeLogic(event);
_createClass(Adapter3DTouch, [{
key: "bindEvents",
value: function bindEvents() {
if (supportsTouchForceChange) {
this.add('touchforcechange', this.start.bind(this));
this.add('touchstart', this.supportTest.bind(this, 0));
this.add('touchend', this._endPress.bind(this));
} else {
this.add('touchstart', this.startLegacyTest.bind(this));
this.add('touchend', this._endPress.bind(this));
}
}
}, {
key: "$start",
value: function $start() {
var _this12 = this;
// call 'start' when the touch goes down
this.add(Support.mobile ? 'touchstart' : 'mousedown', function (event) {
_this12.startLogic(event);
});
key: "start",
value: function start(event) {
if (event.touches.length > 0) {
this._startPress(event);
this.runClosure('change', this.selectTouch(event).force, event);
}
}
}, {
key: "startLogic",
value: function startLogic(event) {
this.setPressed(true);
runClosure(this.block, 'start', this.el, event);
key: "supportTest",
value: function supportTest(iter, event) {
var runKey = arguments.length <= 2 || arguments[2] === undefined ? this.runKey : arguments[2];
if (this.isPressed() === false) {
if (iter <= 6) {
iter++;
setTimeout(this.supportTest.bind(this, iter, event, runKey), 10);
} else {
this.fail(event, runKey);
}
}
}
}, {
key: "$change",
value: function $change() {
this.add(Support.mobile ? 'touchstart' : 'mousedown', this.changeLogic.bind(this));
key: "startLegacyTest",
value: function startLegacyTest(event) {
this.initialForce = event.touches[0].force;
this.supportLegacyTest(0, event, this.runKey, this.initialForce);
}
// this checks up to 6 times on a touch to see if the touch can read a force value
// if the force value has changed it means the device supports pressure
// more info from this issue https://github.com/yamartino/pressure/issues/15
}, {
key: "changeLogic",
value: function changeLogic(event) {
if (this.pressed) {
this.setPressed(true);
this.runForce(event);
key: "supportLegacyTest",
value: function supportLegacyTest(iter, event, runKey, force) {
if (force !== this.initialForce) {
this._startPress(event);
this.loopForce(event);
} else if (iter <= 6) {
iter++;
setTimeout(this.supportLegacyTest.bind(this, iter, event, runKey, force), 10);
} else {
this.fail(event, runKey);
}
}
}, {
key: "$end",
value: function $end() {
var _this13 = this;
// call 'end' when the mouse goes up or leaves the element
this.add(Support.mobile ? 'touchend' : 'mouseup', function () {
_this13.endDeepPress();
_this13.setPressed(false);
runClosure(_this13.block, 'end', _this13.el);
_this13.force = 0;
});
this.add('mouseleave', function () {
_this13.endDeepPress();
if (_this13.pressed) {
runClosure(_this13.block, 'end', _this13.el);
}
_this13.setPressed(false);
_this13.force = 0;
});
}
}, {
key: "startDeepPress",
value: function startDeepPress(event) {
if (this.deepPressed === false) {
runClosure(this.block, 'startDeepPress', this.el, event);
key: "loopForce",
value: function loopForce(event) {
if (this.isPressed()) {
this.touch = this.selectTouch(event);
setTimeout(this.loopForce.bind(this, event), 10);
this.runClosure('change', this.touch.force, event);
}
this.setDeepPressed(true);
}
// link up the touch point to the correct element, this is to support multitouch
}, {
key: "endDeepPress",
value: function endDeepPress() {
if (this.deepPressed === true) {
runClosure(this.block, 'endDeepPress', this.el);
key: "selectTouch",
value: function selectTouch(event) {
if (event.touches.length === 1) {
return this.returnTouch(event.touches[0], event);
} else {
for (var i = 0; i < event.touches.length; i++) {
// if the target press is on this element
if (event.touches[i].target === this.el) {
return this.returnTouch(event.touches[i], event);
}
}
}
this.setDeepPressed(false);
}
// return the touch and run a start or end for deep press
}, {
key: "runForce",
value: function runForce(event) {
if (this.pressed) {
runClosure(this.block, 'change', this.el, this.force, event);
this.force >= 0.5 ? this.startDeepPress(event) : this.endDeepPress();
this.force = this.force + this.increment > 1 ? 1 : this.force + this.increment;
setTimeout(this.runForce.bind(this), 10, event);
}
key: "returnTouch",
value: function returnTouch(touch, event) {
touch.force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
return touch;
}
}]);
return AdapterPolyfill;
return Adapter3DTouch;
}(Adapter);

@@ -575,8 +419,14 @@

preventDefault: true,
// 'false' will make polyfill not run when pressure is not supported and the 'unsupported' method will be called
polyfill: true,
// milliseconds it takes to go from 0 to 1 for the polyfill
polyfillSpeed: 1000,
// 'true' prevents the selecting of text and images via css properties
preventSelect: true,
// 'mobile' or 'desktop' will make it run only on that type of device
only: null,
polyfill: false,
// this will get the correct config / option settings for the current pressure check

@@ -598,30 +448,4 @@ get: function get(option, options) {

// This class holds the states of the the Pressure support the user has
var Support = {
//------------------- Helpers -------------------//
// if the support has already been checked
hasRun: false,
// if the device has support for pressure or not
forPressure: false,
// the type of support the device has "force" or "3d"
type: false,
// Check if the device is mobile or desktop
mobile: 'ontouchstart' in document,
didFail: function didFail() {
this.hasRun = true;
this.forPressure = false;
},
didSucceed: function didSucceed(type) {
this.hasRun = true;
this.forPressure = true;
this.type = type;
}
};
//------------------- Helpers Section -------------------//
// accepts jQuery object, node list, string selector, then called a setup for each element

@@ -654,10 +478,2 @@ var loopPressureElements = function loopPressureElements(selector, closure) {

// run the closure if the property exists in the object
var runClosure = function runClosure(closure, method, element) {
if (closure.hasOwnProperty(method)) {
// call the closure method and apply nth arguments if they exist
closure[method].apply(element || this, Array.prototype.slice.call(arguments, 3));
}
};
// the map method allows for interpolating a value from one range of values to another

@@ -668,2 +484,11 @@ // example from the Arduino documentation: https://www.arduino.cc/en/Reference/Map

};
// check if device is desktop device
var isDesktop = 'ontouchstart' in document === false;
// check if device is regular mobile device
var isMobile = 'ontouchstart' in document === true;
// check if device is an Apple iOS 10+ device
var supportsTouchForceChange = 'ontouchforcechange' in document;
}(typeof window !== "undefined" ? window : false, typeof window !== "undefined" ? window.document : false, typeof jQuery !== "undefined" ? jQuery : false));

@@ -1,2 +0,2 @@

// Pressure v1.0.1 | Created By Stuart Yamartino | MIT License | 2015-Present
!function(e,t,s){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};if(s===!1)throw new Error("Pressure jQuery requires jQuery is loaded before your jquery.pressure.min.js file");if(s.fn.pressure=function(e,t){return v(this,e,t),this},s.pressureConfig=function(e){p.set(e)},s.pressureMap=function(e,t,s,n,r){return k(e,t,s,n,r)},e===!1)return void console.warn("Pressure requires a window with a document");if("undefined"!=typeof Pressure)if("function"==typeof define&&define.amd){var c=Pressure;define(["pressure"],function(e){return e})}else if("object"===("undefined"==typeof module?"undefined":u(module))&&module.exports){var c=Pressure;module.exports=c}else e.Pressure=Pressure;var l=function(){function e(t,s,n){i(this,e),this.element=t,this.block=s,this.type=p.get("only",n),this.options=n,this.routeEvents()}return o(e,[{key:"routeEvents",value:function(){y.mobile!==!1||"force"!==this.type&&"3d"===this.type?y.mobile!==!0||"3d"!==this.type&&"force"===this.type?this.instantFail():new a(this):new f(this)}},{key:"instantFail",value:function(){var e=this;this.element.addEventListener(y.mobile?"touchstart":"mousedown",function(){return P(e.block,"unsupported",e.element)},!1)}}]),e}(),h=function(){function e(t){i(this,e),this.element=t,this.el=t.element,this.block=t.block,this.pressed=!1,this.deepPressed=!1}return o(e,[{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"remove",value:function(e,t){this.el.removeEventListener(e,t)}},{key:"setPressed",value:function(e){this.pressed=e}},{key:"setDeepPressed",value:function(e){this.deepPressed=e}},{key:"failOrPolyfill",value:function(e){y.didFail(),p.get("polyfill",this.element.options)===!0?this.polyfill=new d(this.element,e):P(this.block,"unsupported",this.el)}},{key:"preventDefault",value:function(e){p.get("preventDefault",this.element.options)===!0&&(e.preventDefault(),this.el.style.webkitTouchCallout="none",this.el.style.userSelect="none",this.el.style.webkitUserSelect="none",this.el.style.MozUserSelect="none")}}]),e}(),a=function(e){function t(e){i(this,t);var s=n(this,Object.getPrototypeOf(t).call(this,e));return s.$support(),s.$start(),s.$change(),s.$end(),s}return r(t,e),o(t,[{key:"$support",value:function(){this.supportMethod=this.middleMan.bind(this),this.add("touchstart",this.supportMethod)}},{key:"middleMan",value:function(e){this.setPressed(!0),this.forceValueTest=e.touches[0].force,this.supportCallback(0,e)}},{key:"supportCallback",value:function(e,t){y.hasRun!==!1||this.polyfill instanceof d?y.forPressure||this.polyfill instanceof d?this.remove("touchstart",this.supportMethod):this.failOrPolyfill(t):t.touches[0].force!==this.forceValueTest?(this.preventDefault(t),y.didSucceed("3d"),this.remove("touchstart",this.supportMethod),P(this.block,"start",this.el,t),this.changeLogic(t)):10>=e&&this.pressed?(e+=1,setTimeout(this.supportCallback.bind(this),10,e,t)):this.pressed&&this.failOrPolyfill(t)}},{key:"$start",value:function(){var e=this;this.add("touchstart",function(t){y.forPressure&&(e.setPressed(!0),e.preventDefault(t),P(e.block,"start",e.el,t))})}},{key:"$change",value:function(){this.add("touchstart",this.changeLogic.bind(this))}},{key:"changeLogic",value:function(e){y.forPressure&&this.pressed&&(this.setPressed(!0),this.runForce(e))}},{key:"$end",value:function(){var e=this;this.add("touchend",function(){y.forPressure&&(e.endDeepPress(),e.setPressed(!1),P(e.block,"end",e.el))})}},{key:"startDeepPress",value:function(e){this.deepPressed===!1&&P(this.block,"startDeepPress",this.el,e),this.setDeepPressed(!0)}},{key:"endDeepPress",value:function(){this.deepPressed===!0&&P(this.block,"endDeepPress",this.el),this.setDeepPressed(!1)}},{key:"runForce",value:function(e){this.pressed&&(this.touch=this.selectTouch(e),setTimeout(this.runForce.bind(this),10,e),P(this.block,"change",this.el,this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return this.returnTouch(e.touches[t],e)}},{key:"returnTouch",value:function(e,t){return e.force>=.5?this.startDeepPress(t):this.endDeepPress(),e}}]),t}(h),f=function(e){function t(e){i(this,t);var s=n(this,Object.getPrototypeOf(t).call(this,e));return s.$support(),s.$start(),s.$change(),s.$startDeepPress(),s.$endDeepPress(),s.$end(),s}return r(t,e),o(t,[{key:"$support",value:function(){this.add("webkitmouseforcewillbegin",this.forceTouchEnabled),this.add("mousedown",this.supportCallback.bind(this))}},{key:"forceTouchEnabled",value:function(e){e.preventDefault(),y.didSucceed("force")}},{key:"supportCallback",value:function(e){y.forPressure===!0||this.polyfill instanceof d?(this.remove("webkitmouseforcewillbegin",this.forceTouchEnabled),this.preventDefault(e)):this.failOrPolyfill(e)}},{key:"$start",value:function(){var e=this;this.add("mousedown",function(t){y.forPressure&&(e.setPressed(!0),P(e.block,"start",e.el,t))})}},{key:"$change",value:function(){var e=this;this.add("webkitmouseforcechanged",function(t){y.forPressure&&0!==t.webkitForce&&e.pressed&&P(e.block,"change",e.el,e.normalizeForce(t.webkitForce),t)})}},{key:"$end",value:function(){var e=this;this.add("mouseup",function(){y.forPressure&&(e.setPressed(!1),P(e.block,"end",e.el))}),this.add("mouseleave",function(){y.forPressure&&(e.pressed&&P(e.block,"end",e.el),e.setPressed(!1))})}},{key:"$startDeepPress",value:function(){var e=this;this.add("webkitmouseforcedown",function(t){y.forPressure&&(e.setDeepPressed(!0),P(e.block,"startDeepPress",e.el,t))})}},{key:"$endDeepPress",value:function(){var e=this;this.add("webkitmouseforceup",function(){y.forPressure&&(e.setDeepPressed(!1),P(e.block,"endDeepPress",e.el))}),this.add("mouseleave",function(){y.forPressure&&(e.deepPressed&&P(e.block,"endDeepPress",e.el),e.setDeepPressed(!1))})}},{key:"normalizeForce",value:function(e){return this.reachOne(k(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.999?1:e}}]),t}(h),d=function(e){function t(e,s){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this,e));return r.$start(),r.$change(),r.$end(),r.force=0,r.increment=.01,r.firstRun(s),r}return r(t,e),o(t,[{key:"firstRun",value:function(e){this.preventDefault(e),this.startLogic(e),this.changeLogic(e)}},{key:"$start",value:function(){var e=this;this.add(y.mobile?"touchstart":"mousedown",function(t){e.startLogic(t)})}},{key:"startLogic",value:function(e){this.setPressed(!0),P(this.block,"start",this.el,e)}},{key:"$change",value:function(){this.add(y.mobile?"touchstart":"mousedown",this.changeLogic.bind(this))}},{key:"changeLogic",value:function(e){this.pressed&&(this.setPressed(!0),this.runForce(e))}},{key:"$end",value:function(){var e=this;this.add(y.mobile?"touchend":"mouseup",function(){e.endDeepPress(),e.setPressed(!1),P(e.block,"end",e.el),e.force=0}),this.add("mouseleave",function(){e.endDeepPress(),e.pressed&&P(e.block,"end",e.el),e.setPressed(!1),e.force=0})}},{key:"startDeepPress",value:function(e){this.deepPressed===!1&&P(this.block,"startDeepPress",this.el,e),this.setDeepPressed(!0)}},{key:"endDeepPress",value:function(){this.deepPressed===!0&&P(this.block,"endDeepPress",this.el),this.setDeepPressed(!1)}},{key:"runForce",value:function(e){this.pressed&&(P(this.block,"change",this.el,this.force,e),this.force>=.5?this.startDeepPress(e):this.endDeepPress(),this.force=this.force+this.increment>1?1:this.force+this.increment,setTimeout(this.runForce.bind(this),10,e))}}]),t}(h),p={preventDefault:!0,only:null,polyfill:!1,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},y={hasRun:!1,forPressure:!1,type:!1,mobile:"ontouchstart"in t,didFail:function(){this.hasRun=!0,this.forPressure=!1},didSucceed:function(e){this.hasRun=!0,this.forPressure=!0,this.type=e}},v=function(e,s){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if("string"==typeof e||e instanceof String)for(var r=t.querySelectorAll(e),i=0;i<r.length;i++)new l(r[i],s,n);else if(b(e))new l(e,s,n);else for(var i=0;i<e.length;i++)new l(e[i],s,n)},b=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":u(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":u(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},P=function(e,t,s){e.hasOwnProperty(t)&&e[t].apply(s||this,Array.prototype.slice.call(arguments,3))},k=function(e,t,s,n,r){return(e-t)*(r-n)/(s-t)+n}}("undefined"!=typeof window?window:!1,"undefined"!=typeof window?window.document:!1,"undefined"!=typeof jQuery?jQuery:!1);
// Pressure v2.0.0 | Created By Stuart Yamartino | MIT License | 2015 - 2016
!function(e,t,s){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};if(s===!1)throw new Error("Pressure jQuery requires jQuery is loaded before your jquery.pressure.min.js file");if(s.fn.pressure=function(e,t){return p(this,e,t),this},s.pressureConfig=function(e){f.set(e)},s.pressureMap=function(e,t,s,n,i){return b.apply(null,arguments)},e===!1)return void console.warn("Pressure requires a window with a document");if("undefined"!=typeof Pressure)if("function"==typeof define&&define.amd){var h=Pressure;define(["pressure"],function(e){return e})}else if("object"===("undefined"==typeof module?"undefined":u(module))&&module.exports){var h=Pressure;module.exports=h}else e.Pressure=Pressure;var l=function(){function e(t,s,n){r(this,e),this.routeEvents(t,s,n),this.preventSelect(t,n)}return o(e,[{key:"routeEvents",value:function(e,t,s){var n=f.get("only",s);!P||"desktop"!==n&&"mobile"===n?!v||"mobile"!==n&&"desktop"===n?this.adapter=new c(e,t).bindUnsupportedEvent():this.adapter=new d(e,t,s).bindEvents():this.adapter=new a(e,t,s).bindEvents()}},{key:"preventSelect",value:function(e,t){f.get("preventSelect",t)&&(e.style.webkitTouchCallout="none",e.style.webkitUserSelect="none",e.style.khtmlUserSelect="none",e.style.MozUserSelect="none",e.style.msUserSelect="none",e.style.userSelect="none")}}]),e}(),c=function(){function e(t,s,n){r(this,e),this.el=t,this.block=s,this.options=n,this.pressed=!1,this.deepPressed=!1,this.runKey=Math.random()}return o(e,[{key:"setPressed",value:function(e){this.pressed=e}},{key:"setDeepPressed",value:function(e){this.deepPressed=e}},{key:"isPressed",value:function(){return this.pressed}},{key:"isDeepPressed",value:function(){return this.deepPressed}},{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"runClosure",value:function(e){e in this.block&&this.block[e].apply(this.el,Array.prototype.slice.call(arguments,1))}},{key:"fail",value:function(e,t){f.get("polyfill",this.options)?this.runKey===t&&this.runPolyfill(e):this.runClosure("unsupported",e)}},{key:"bindUnsupportedEvent",value:function(){var e=this;this.add(v?"touchstart":"mousedown",function(t){return e.runClosure("unsupported",t)})}},{key:"_startPress",value:function(e){this.isPressed()===!1&&(this.setPressed(!0),this.runClosure("start",e))}},{key:"_startDeepPress",value:function(e){this.isPressed()&&this.isDeepPressed()===!1&&(this.setDeepPressed(!0),this.runClosure("startDeepPress",e))}},{key:"_endDeepPress",value:function(){this.isPressed()&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress"))}},{key:"_endPress",value:function(){this.isPressed()&&(this._endDeepPress(),this.setPressed(!1),this.runClosure("end")),this.runKey=Math.random()}},{key:"runPolyfill",value:function(e){this.increment=10/f.get("polyfillSpeed",this.options),this.setPressed(!0),this.runClosure("start",e),this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.isPressed()&&(this.runClosure("change",e,t),e>=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),a=function(e){function t(e,s,i){return r(this,t),n(this,Object.getPrototypeOf(t).call(this,e,s,i))}return i(t,e),o(t,[{key:"bindEvents",value:function(){this.add("webkitmouseforcewillbegin",this._startPress.bind(this)),this.add("mousedown",this.support.bind(this)),this.add("webkitmouseforcechanged",this.change.bind(this)),this.add("webkitmouseforcedown",this._startDeepPress.bind(this)),this.add("webkitmouseforceup",this._endDeepPress.bind(this)),this.add("mouseleave",this._endPress.bind(this)),this.add("mouseup",this._endPress.bind(this))}},{key:"support",value:function(e){this.isPressed()===!1&&this.fail(e,this.runKey)}},{key:"change",value:function(e){this.isPressed()&&e.webkitForce>0&&this.runClosure("change",this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(b(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),t}(c),d=function(e){function t(e,s,i){return r(this,t),n(this,Object.getPrototypeOf(t).call(this,e,s,i))}return i(t,e),o(t,[{key:"bindEvents",value:function(){m?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.supportTest.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacyTest.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.runClosure("change",this.selectTouch(e).force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length<=2||void 0===arguments[2]?this.runKey:arguments[2];this.isPressed()===!1&&(6>=e?(e++,setTimeout(this.supportTest.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacyTest",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacyTest",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):6>=e?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,n),10)):this.fail(t,s)}},{key:"loopForce",value:function(e){this.isPressed()&&(this.touch=this.selectTouch(e),setTimeout(this.loopForce.bind(this,e),10),this.runClosure("change",this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return this.returnTouch(e.touches[t],e)}},{key:"returnTouch",value:function(e,t){return e.force>=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),t}(c),f={polyfill:!0,polyfillSpeed:1e3,preventSelect:!0,only:null,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},p=function(e,s){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if("string"==typeof e||e instanceof String)for(var i=t.querySelectorAll(e),r=0;r<i.length;r++)new l(i[r],s,n);else if(y(e))new l(e,s,n);else for(var r=0;r<e.length;r++)new l(e[r],s,n)},y=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":u(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":u(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},b=function(e,t,s,n,i){return(e-t)*(i-n)/(s-t)+n},P="ontouchstart"in t==!1,v="ontouchstart"in t==!0,m="ontouchforcechange"in t}("undefined"!=typeof window?window:!1,"undefined"!=typeof window?window.document:!1,"undefined"!=typeof jQuery?jQuery:!1);

@@ -1,2 +0,2 @@

// Pressure v1.0.1 | Created By Stuart Yamartino | MIT License | 2015-Present
// Pressure v2.0.0 | Created By Stuart Yamartino | MIT License | 2015 - 2016
;(function(window, document) {

@@ -20,3 +20,3 @@ "use strict";

// targets any device with Force of 3D Touch
// targets any device with Force or 3D Touch

@@ -37,3 +37,3 @@ set: function set(selector, closure, options) {

map: function map(x, in_min, in_max, out_min, out_max) {
return _map(x, in_min, in_max, out_min, out_max);
return _map.apply(null, arguments);
}

@@ -75,10 +75,7 @@ };

var Element = function () {
function Element(element, block, options) {
function Element(el, block, options) {
_classCallCheck(this, Element);
this.element = element;
this.block = block;
this.type = Config.get('only', options);
this.options = options;
this.routeEvents();
this.routeEvents(el, block, options);
this.preventSelect(el, options);
}

@@ -88,24 +85,31 @@

key: "routeEvents",
value: function routeEvents() {
value: function routeEvents(el, block, options) {
var type = Config.get('only', options);
// if on desktop and requesting Force Touch or not requesting 3D Touch
if (Support.mobile === false && (this.type === 'force' || this.type !== '3d')) {
new AdapterForceTouch(this);
if (isDesktop && (type === 'desktop' || type !== 'mobile')) {
this.adapter = new AdapterForceTouch(el, block, options).bindEvents();
}
// if on mobile and requesting 3D Touch or not requestion Force Touch
else if (Support.mobile === true && (this.type === '3d' || this.type !== 'force')) {
new Adapter3DTouch(this);
else if (isMobile && (type === 'mobile' || type !== 'desktop')) {
this.adapter = new Adapter3DTouch(el, block, options).bindEvents();
}
// if it is requesting a type and your browser is of other type
// unsupported if it is requesting a type and your browser is of other type
else {
this.instantFail();
this.adapter = new Adapter(el, block).bindUnsupportedEvent();
}
}
// prevent the default action of text selection, "peak & pop", and force touch special feature
}, {
key: "instantFail",
value: function instantFail() {
var _this = this;
this.element.addEventListener(Support.mobile ? 'touchstart' : 'mousedown', function () {
return runClosure(_this.block, 'unsupported', _this.element);
}, false);
key: "preventSelect",
value: function preventSelect(el, options) {
if (Config.get('preventSelect', options)) {
el.style.webkitTouchCallout = "none";
el.style.webkitUserSelect = "none";
el.style.khtmlUserSelect = "none";
el.style.MozUserSelect = "none";
el.style.msUserSelect = "none";
el.style.userSelect = "none";
}
}

@@ -117,24 +121,19 @@ }]);

/*
This is the base adapter from which all the other adapters extend.
*/
var Adapter = function () {
function Adapter(element) {
function Adapter(el, block, options) {
_classCallCheck(this, Adapter);
this.element = element;
this.el = element.element;
this.block = element.block;
this.el = el;
this.block = block;
this.options = options;
this.pressed = false;
this.deepPressed = false;
this.runKey = Math.random();
}
_createClass(Adapter, [{
key: "add",
value: function add(event, set) {
this.el.addEventListener(event, set, false);
}
}, {
key: "remove",
value: function remove(event, set) {
this.el.removeEventListener(event, set);
}
}, {
key: "setPressed",

@@ -150,301 +149,140 @@ value: function setPressed(boolean) {

}, {
key: "failOrPolyfill",
value: function failOrPolyfill(event) {
Support.didFail();
// is the polyfill option set
if (Config.get('polyfill', this.element.options) === true) {
this.polyfill = new AdapterPolyfill(this.element, event);
} else {
runClosure(this.block, 'unsupported', this.el);
}
key: "isPressed",
value: function isPressed() {
return this.pressed;
}
// prevent the default action of text selection, "peak & pop", and force touch special feature
}, {
key: "preventDefault",
value: function preventDefault(event) {
if (Config.get('preventDefault', this.element.options) === true) {
event.preventDefault();
this.el.style.webkitTouchCallout = "none";
this.el.style.userSelect = "none";
this.el.style.webkitUserSelect = "none";
this.el.style.MozUserSelect = "none";
}
key: "isDeepPressed",
value: function isDeepPressed() {
return this.deepPressed;
}
}]);
return Adapter;
}();
var Adapter3DTouch = function (_Adapter) {
_inherits(Adapter3DTouch, _Adapter);
function Adapter3DTouch(element) {
_classCallCheck(this, Adapter3DTouch);
var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(Adapter3DTouch).call(this, element));
_this2.$support();
_this2.$start();
_this2.$change();
_this2.$end();
return _this2;
}
_createClass(Adapter3DTouch, [{
key: "$support",
value: function $support() {
this.supportMethod = this.middleMan.bind(this);
this.add('touchstart', this.supportMethod);
}, {
key: "add",
value: function add(event, set) {
this.el.addEventListener(event, set, false);
}
}, {
key: "middleMan",
value: function middleMan(event) {
this.setPressed(true);
this.forceValueTest = event.touches[0].force;
this.supportCallback(0, event);
key: "runClosure",
value: function runClosure(method) {
if (method in this.block) {
// call the closure method and apply nth arguments if they exist
this.block[method].apply(this.el, Array.prototype.slice.call(arguments, 1));
}
}
}, {
key: "supportCallback",
value: function supportCallback(iter, event) {
// this checks up to 10 times on a touch to see if the touch can read a force value or not to check "support"
if (Support.hasRun === false && !(this.polyfill instanceof AdapterPolyfill)) {
// if the force value has changed it means the device supports pressure
// more info from this issue https://github.com/yamartino/pressure/issues/15
if (event.touches[0].force !== this.forceValueTest) {
this.preventDefault(event);
Support.didSucceed('3d');
this.remove('touchstart', this.supportMethod);
runClosure(this.block, 'start', this.el, event);
this.changeLogic(event);
} else if (iter <= 10 && this.pressed) {
iter += 1;
setTimeout(this.supportCallback.bind(this), 10, iter, event);
} else if (this.pressed) {
this.failOrPolyfill(event);
key: "fail",
value: function fail(event, runKey) {
if (Config.get('polyfill', this.options)) {
if (this.runKey === runKey) {
this.runPolyfill(event);
}
} else if (Support.forPressure || this.polyfill instanceof AdapterPolyfill) {
this.remove('touchstart', this.supportMethod);
} else {
this.failOrPolyfill(event);
this.runClosure('unsupported', event);
}
}
}, {
key: "$start",
value: function $start() {
var _this3 = this;
key: "bindUnsupportedEvent",
value: function bindUnsupportedEvent() {
var _this = this;
// call 'start' when the touch goes down
this.add('touchstart', function (event) {
if (Support.forPressure) {
_this3.setPressed(true);
_this3.preventDefault(event);
runClosure(_this3.block, 'start', _this3.el, event);
}
this.add(isMobile ? 'touchstart' : 'mousedown', function (event) {
return _this.runClosure('unsupported', event);
});
}
}, {
key: "$change",
value: function $change() {
this.add('touchstart', this.changeLogic.bind(this));
}
}, {
key: "changeLogic",
value: function changeLogic(event) {
if (Support.forPressure && this.pressed) {
key: "_startPress",
value: function _startPress(event) {
if (this.isPressed() === false) {
this.setPressed(true);
this.runForce(event);
this.runClosure('start', event);
}
}
}, {
key: "$end",
value: function $end() {
var _this4 = this;
// call 'end' when the touch goes up
this.add('touchend', function () {
if (Support.forPressure) {
_this4.endDeepPress();
_this4.setPressed(false);
runClosure(_this4.block, 'end', _this4.el);
}
});
key: "_startDeepPress",
value: function _startDeepPress(event) {
if (this.isPressed() && this.isDeepPressed() === false) {
this.setDeepPressed(true);
this.runClosure('startDeepPress', event);
}
}
}, {
key: "startDeepPress",
value: function startDeepPress(event) {
if (this.deepPressed === false) {
runClosure(this.block, 'startDeepPress', this.el, event);
key: "_endDeepPress",
value: function _endDeepPress() {
if (this.isPressed() && this.isDeepPressed()) {
this.setDeepPressed(false);
this.runClosure('endDeepPress');
}
this.setDeepPressed(true);
}
}, {
key: "endDeepPress",
value: function endDeepPress() {
if (this.deepPressed === true) {
runClosure(this.block, 'endDeepPress', this.el);
key: "_endPress",
value: function _endPress() {
if (this.isPressed()) {
this._endDeepPress();
this.setPressed(false);
this.runClosure('end');
}
this.setDeepPressed(false);
this.runKey = Math.random();
}
}, {
key: "runForce",
value: function runForce(event) {
if (this.pressed) {
this.touch = this.selectTouch(event);
setTimeout(this.runForce.bind(this), 10, event);
runClosure(this.block, 'change', this.el, this.touch.force, event);
}
key: "runPolyfill",
value: function runPolyfill(event) {
this.increment = 10 / Config.get('polyfillSpeed', this.options);
this.setPressed(true);
this.runClosure('start', event);
this.loopPolyfillForce(0, event);
}
// link up the touch point to the correct element, this is to support multitouch
}, {
key: "selectTouch",
value: function selectTouch(event) {
if (event.touches.length === 1) {
return this.returnTouch(event.touches[0], event);
} else {
for (var i = 0; i < event.touches.length; i++) {
// if the target press is on this element
if (event.touches[i].target === this.el) {
return this.returnTouch(event.touches[i], event);
}
}
key: "loopPolyfillForce",
value: function loopPolyfillForce(force, event) {
if (this.isPressed()) {
this.runClosure('change', force, event);
force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
force = force + this.increment > 1 ? 1 : force + this.increment;
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
}
}
}]);
// return the touch and run a start or end for deep press
return Adapter;
}();
}, {
key: "returnTouch",
value: function returnTouch(touch, event) {
touch.force >= 0.5 ? this.startDeepPress(event) : this.endDeepPress();
return touch;
}
}]);
/*
This adapter is for Macs with Force Touch trackpads.
*/
return Adapter3DTouch;
}(Adapter);
var AdapterForceTouch = function (_Adapter) {
_inherits(AdapterForceTouch, _Adapter);
var AdapterForceTouch = function (_Adapter2) {
_inherits(AdapterForceTouch, _Adapter2);
function AdapterForceTouch(element) {
function AdapterForceTouch(el, block, options) {
_classCallCheck(this, AdapterForceTouch);
var _this5 = _possibleConstructorReturn(this, Object.getPrototypeOf(AdapterForceTouch).call(this, element));
_this5.$support();
_this5.$start();
_this5.$change();
_this5.$startDeepPress();
_this5.$endDeepPress();
_this5.$end();
return _this5;
return _possibleConstructorReturn(this, Object.getPrototypeOf(AdapterForceTouch).call(this, el, block, options));
}
// Support check methods
_createClass(AdapterForceTouch, [{
key: "$support",
value: function $support() {
this.add('webkitmouseforcewillbegin', this.forceTouchEnabled);
this.add('mousedown', this.supportCallback.bind(this));
key: "bindEvents",
value: function bindEvents() {
this.add('webkitmouseforcewillbegin', this._startPress.bind(this));
this.add('mousedown', this.support.bind(this));
this.add('webkitmouseforcechanged', this.change.bind(this));
this.add('webkitmouseforcedown', this._startDeepPress.bind(this));
this.add('webkitmouseforceup', this._endDeepPress.bind(this));
this.add('mouseleave', this._endPress.bind(this));
this.add('mouseup', this._endPress.bind(this));
}
}, {
key: "forceTouchEnabled",
value: function forceTouchEnabled(event) {
event.preventDefault();
Support.didSucceed('force');
key: "support",
value: function support(event) {
if (this.isPressed() === false) {
this.fail(event, this.runKey);
}
}
}, {
key: "supportCallback",
value: function supportCallback(event) {
if (Support.forPressure === true || this.polyfill instanceof AdapterPolyfill) {
this.remove('webkitmouseforcewillbegin', this.forceTouchEnabled);
this.preventDefault(event);
} else {
this.failOrPolyfill(event);
key: "change",
value: function change(event) {
if (this.isPressed() && event.webkitForce > 0) {
this.runClosure('change', this.normalizeForce(event.webkitForce), event);
}
}
}, {
key: "$start",
value: function $start() {
var _this6 = this;
// call 'start' when the mouse goes down
this.add('mousedown', function (event) {
if (Support.forPressure) {
_this6.setPressed(true);
runClosure(_this6.block, 'start', _this6.el, event);
}
});
}
}, {
key: "$change",
value: function $change() {
var _this7 = this;
this.add('webkitmouseforcechanged', function (event) {
if (Support.forPressure && event.webkitForce !== 0 && _this7.pressed) {
runClosure(_this7.block, 'change', _this7.el, _this7.normalizeForce(event.webkitForce), event);
}
});
}
}, {
key: "$end",
value: function $end() {
var _this8 = this;
// call 'end' when the mouse goes up or leaves the element
this.add('mouseup', function () {
if (Support.forPressure) {
_this8.setPressed(false);
runClosure(_this8.block, 'end', _this8.el);
}
});
this.add('mouseleave', function () {
if (Support.forPressure) {
if (_this8.pressed) {
runClosure(_this8.block, 'end', _this8.el);
}
_this8.setPressed(false);
}
});
}
}, {
key: "$startDeepPress",
value: function $startDeepPress() {
var _this9 = this;
this.add('webkitmouseforcedown', function (event) {
if (Support.forPressure) {
_this9.setDeepPressed(true);
runClosure(_this9.block, 'startDeepPress', _this9.el, event);
}
});
}
}, {
key: "$endDeepPress",
value: function $endDeepPress() {
var _this10 = this;
this.add('webkitmouseforceup', function () {
if (Support.forPressure) {
_this10.setDeepPressed(false);
runClosure(_this10.block, 'endDeepPress', _this10.el);
}
});
this.add('mouseleave', function () {
if (Support.forPressure) {
if (_this10.deepPressed) {
runClosure(_this10.block, 'endDeepPress', _this10.el);
}
_this10.setDeepPressed(false);
}
});
}
// make the force the standard 0 to 1 scale and not the 1 to 3 scale

@@ -458,3 +296,3 @@

// if the force value is above 0.999 set the force to 1
// if the force value is above 0.995 set the force to 1

@@ -464,3 +302,3 @@ }, {

value: function reachOne(force) {
return force > 0.999 ? 1 : force;
return force > 0.995 ? 1 : force;
}

@@ -472,105 +310,111 @@ }]);

var AdapterPolyfill = function (_Adapter3) {
_inherits(AdapterPolyfill, _Adapter3);
/*
This adapter is more mobile devices that support 3D Touch.
*/
function AdapterPolyfill(element, firstEvent) {
_classCallCheck(this, AdapterPolyfill);
var Adapter3DTouch = function (_Adapter2) {
_inherits(Adapter3DTouch, _Adapter2);
var _this11 = _possibleConstructorReturn(this, Object.getPrototypeOf(AdapterPolyfill).call(this, element));
function Adapter3DTouch(el, block, options) {
_classCallCheck(this, Adapter3DTouch);
_this11.$start();
_this11.$change();
_this11.$end();
_this11.force = 0;
_this11.increment = 0.01;
_this11.firstRun(firstEvent);
return _this11;
return _possibleConstructorReturn(this, Object.getPrototypeOf(Adapter3DTouch).call(this, el, block, options));
}
_createClass(AdapterPolyfill, [{
key: "firstRun",
value: function firstRun(event) {
this.preventDefault(event);
this.startLogic(event);
this.changeLogic(event);
_createClass(Adapter3DTouch, [{
key: "bindEvents",
value: function bindEvents() {
if (supportsTouchForceChange) {
this.add('touchforcechange', this.start.bind(this));
this.add('touchstart', this.supportTest.bind(this, 0));
this.add('touchend', this._endPress.bind(this));
} else {
this.add('touchstart', this.startLegacyTest.bind(this));
this.add('touchend', this._endPress.bind(this));
}
}
}, {
key: "$start",
value: function $start() {
var _this12 = this;
// call 'start' when the touch goes down
this.add(Support.mobile ? 'touchstart' : 'mousedown', function (event) {
_this12.startLogic(event);
});
key: "start",
value: function start(event) {
if (event.touches.length > 0) {
this._startPress(event);
this.runClosure('change', this.selectTouch(event).force, event);
}
}
}, {
key: "startLogic",
value: function startLogic(event) {
this.setPressed(true);
runClosure(this.block, 'start', this.el, event);
key: "supportTest",
value: function supportTest(iter, event) {
var runKey = arguments.length <= 2 || arguments[2] === undefined ? this.runKey : arguments[2];
if (this.isPressed() === false) {
if (iter <= 6) {
iter++;
setTimeout(this.supportTest.bind(this, iter, event, runKey), 10);
} else {
this.fail(event, runKey);
}
}
}
}, {
key: "$change",
value: function $change() {
this.add(Support.mobile ? 'touchstart' : 'mousedown', this.changeLogic.bind(this));
key: "startLegacyTest",
value: function startLegacyTest(event) {
this.initialForce = event.touches[0].force;
this.supportLegacyTest(0, event, this.runKey, this.initialForce);
}
// this checks up to 6 times on a touch to see if the touch can read a force value
// if the force value has changed it means the device supports pressure
// more info from this issue https://github.com/yamartino/pressure/issues/15
}, {
key: "changeLogic",
value: function changeLogic(event) {
if (this.pressed) {
this.setPressed(true);
this.runForce(event);
key: "supportLegacyTest",
value: function supportLegacyTest(iter, event, runKey, force) {
if (force !== this.initialForce) {
this._startPress(event);
this.loopForce(event);
} else if (iter <= 6) {
iter++;
setTimeout(this.supportLegacyTest.bind(this, iter, event, runKey, force), 10);
} else {
this.fail(event, runKey);
}
}
}, {
key: "$end",
value: function $end() {
var _this13 = this;
// call 'end' when the mouse goes up or leaves the element
this.add(Support.mobile ? 'touchend' : 'mouseup', function () {
_this13.endDeepPress();
_this13.setPressed(false);
runClosure(_this13.block, 'end', _this13.el);
_this13.force = 0;
});
this.add('mouseleave', function () {
_this13.endDeepPress();
if (_this13.pressed) {
runClosure(_this13.block, 'end', _this13.el);
}
_this13.setPressed(false);
_this13.force = 0;
});
}
}, {
key: "startDeepPress",
value: function startDeepPress(event) {
if (this.deepPressed === false) {
runClosure(this.block, 'startDeepPress', this.el, event);
key: "loopForce",
value: function loopForce(event) {
if (this.isPressed()) {
this.touch = this.selectTouch(event);
setTimeout(this.loopForce.bind(this, event), 10);
this.runClosure('change', this.touch.force, event);
}
this.setDeepPressed(true);
}
// link up the touch point to the correct element, this is to support multitouch
}, {
key: "endDeepPress",
value: function endDeepPress() {
if (this.deepPressed === true) {
runClosure(this.block, 'endDeepPress', this.el);
key: "selectTouch",
value: function selectTouch(event) {
if (event.touches.length === 1) {
return this.returnTouch(event.touches[0], event);
} else {
for (var i = 0; i < event.touches.length; i++) {
// if the target press is on this element
if (event.touches[i].target === this.el) {
return this.returnTouch(event.touches[i], event);
}
}
}
this.setDeepPressed(false);
}
// return the touch and run a start or end for deep press
}, {
key: "runForce",
value: function runForce(event) {
if (this.pressed) {
runClosure(this.block, 'change', this.el, this.force, event);
this.force >= 0.5 ? this.startDeepPress(event) : this.endDeepPress();
this.force = this.force + this.increment > 1 ? 1 : this.force + this.increment;
setTimeout(this.runForce.bind(this), 10, event);
}
key: "returnTouch",
value: function returnTouch(touch, event) {
touch.force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
return touch;
}
}]);
return AdapterPolyfill;
return Adapter3DTouch;
}(Adapter);

@@ -583,8 +427,14 @@

preventDefault: true,
// 'false' will make polyfill not run when pressure is not supported and the 'unsupported' method will be called
polyfill: true,
// milliseconds it takes to go from 0 to 1 for the polyfill
polyfillSpeed: 1000,
// 'true' prevents the selecting of text and images via css properties
preventSelect: true,
// 'mobile' or 'desktop' will make it run only on that type of device
only: null,
polyfill: false,
// this will get the correct config / option settings for the current pressure check

@@ -606,30 +456,4 @@ get: function get(option, options) {

// This class holds the states of the the Pressure support the user has
var Support = {
//------------------- Helpers -------------------//
// if the support has already been checked
hasRun: false,
// if the device has support for pressure or not
forPressure: false,
// the type of support the device has "force" or "3d"
type: false,
// Check if the device is mobile or desktop
mobile: 'ontouchstart' in document,
didFail: function didFail() {
this.hasRun = true;
this.forPressure = false;
},
didSucceed: function didSucceed(type) {
this.hasRun = true;
this.forPressure = true;
this.type = type;
}
};
//------------------- Helpers Section -------------------//
// accepts jQuery object, node list, string selector, then called a setup for each element

@@ -662,10 +486,2 @@ var loopPressureElements = function loopPressureElements(selector, closure) {

// run the closure if the property exists in the object
var runClosure = function runClosure(closure, method, element) {
if (closure.hasOwnProperty(method)) {
// call the closure method and apply nth arguments if they exist
closure[method].apply(element || this, Array.prototype.slice.call(arguments, 3));
}
};
// the map method allows for interpolating a value from one range of values to another

@@ -676,2 +492,11 @@ // example from the Arduino documentation: https://www.arduino.cc/en/Reference/Map

};
// check if device is desktop device
var isDesktop = 'ontouchstart' in document === false;
// check if device is regular mobile device
var isMobile = 'ontouchstart' in document === true;
// check if device is an Apple iOS 10+ device
var supportsTouchForceChange = 'ontouchforcechange' in document;
}(typeof window !== "undefined" ? window : false, typeof window !== "undefined" ? window.document : false));

@@ -1,2 +0,2 @@

// Pressure v1.0.1 | Created By Stuart Yamartino | MIT License | 2015-Present
!function(e,t){"use strict";function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},u={set:function(e,t,s){v(e,t,s)},config:function(e){p.set(e)},map:function(e,t,s,n,i){return k(e,t,s,n,i)}};if(e===!1)return void console.warn("Pressure requires a window with a document");if("undefined"!=typeof u)if("function"==typeof define&&define.amd){var c=u;define(["pressure"],function(e){return e})}else if("object"===("undefined"==typeof module?"undefined":r(module))&&module.exports){var c=u;module.exports=c}else e.Pressure=u;var l=function(){function e(t,s,n){i(this,e),this.element=t,this.block=s,this.type=p.get("only",n),this.options=n,this.routeEvents()}return o(e,[{key:"routeEvents",value:function(){y.mobile!==!1||"force"!==this.type&&"3d"===this.type?y.mobile!==!0||"3d"!==this.type&&"force"===this.type?this.instantFail():new a(this):new f(this)}},{key:"instantFail",value:function(){var e=this;this.element.addEventListener(y.mobile?"touchstart":"mousedown",function(){return P(e.block,"unsupported",e.element)},!1)}}]),e}(),h=function(){function e(t){i(this,e),this.element=t,this.el=t.element,this.block=t.block,this.pressed=!1,this.deepPressed=!1}return o(e,[{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"remove",value:function(e,t){this.el.removeEventListener(e,t)}},{key:"setPressed",value:function(e){this.pressed=e}},{key:"setDeepPressed",value:function(e){this.deepPressed=e}},{key:"failOrPolyfill",value:function(e){y.didFail(),p.get("polyfill",this.element.options)===!0?this.polyfill=new d(this.element,e):P(this.block,"unsupported",this.el)}},{key:"preventDefault",value:function(e){p.get("preventDefault",this.element.options)===!0&&(e.preventDefault(),this.el.style.webkitTouchCallout="none",this.el.style.userSelect="none",this.el.style.webkitUserSelect="none",this.el.style.MozUserSelect="none")}}]),e}(),a=function(e){function t(e){i(this,t);var n=s(this,Object.getPrototypeOf(t).call(this,e));return n.$support(),n.$start(),n.$change(),n.$end(),n}return n(t,e),o(t,[{key:"$support",value:function(){this.supportMethod=this.middleMan.bind(this),this.add("touchstart",this.supportMethod)}},{key:"middleMan",value:function(e){this.setPressed(!0),this.forceValueTest=e.touches[0].force,this.supportCallback(0,e)}},{key:"supportCallback",value:function(e,t){y.hasRun!==!1||this.polyfill instanceof d?y.forPressure||this.polyfill instanceof d?this.remove("touchstart",this.supportMethod):this.failOrPolyfill(t):t.touches[0].force!==this.forceValueTest?(this.preventDefault(t),y.didSucceed("3d"),this.remove("touchstart",this.supportMethod),P(this.block,"start",this.el,t),this.changeLogic(t)):10>=e&&this.pressed?(e+=1,setTimeout(this.supportCallback.bind(this),10,e,t)):this.pressed&&this.failOrPolyfill(t)}},{key:"$start",value:function(){var e=this;this.add("touchstart",function(t){y.forPressure&&(e.setPressed(!0),e.preventDefault(t),P(e.block,"start",e.el,t))})}},{key:"$change",value:function(){this.add("touchstart",this.changeLogic.bind(this))}},{key:"changeLogic",value:function(e){y.forPressure&&this.pressed&&(this.setPressed(!0),this.runForce(e))}},{key:"$end",value:function(){var e=this;this.add("touchend",function(){y.forPressure&&(e.endDeepPress(),e.setPressed(!1),P(e.block,"end",e.el))})}},{key:"startDeepPress",value:function(e){this.deepPressed===!1&&P(this.block,"startDeepPress",this.el,e),this.setDeepPressed(!0)}},{key:"endDeepPress",value:function(){this.deepPressed===!0&&P(this.block,"endDeepPress",this.el),this.setDeepPressed(!1)}},{key:"runForce",value:function(e){this.pressed&&(this.touch=this.selectTouch(e),setTimeout(this.runForce.bind(this),10,e),P(this.block,"change",this.el,this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return this.returnTouch(e.touches[t],e)}},{key:"returnTouch",value:function(e,t){return e.force>=.5?this.startDeepPress(t):this.endDeepPress(),e}}]),t}(h),f=function(e){function t(e){i(this,t);var n=s(this,Object.getPrototypeOf(t).call(this,e));return n.$support(),n.$start(),n.$change(),n.$startDeepPress(),n.$endDeepPress(),n.$end(),n}return n(t,e),o(t,[{key:"$support",value:function(){this.add("webkitmouseforcewillbegin",this.forceTouchEnabled),this.add("mousedown",this.supportCallback.bind(this))}},{key:"forceTouchEnabled",value:function(e){e.preventDefault(),y.didSucceed("force")}},{key:"supportCallback",value:function(e){y.forPressure===!0||this.polyfill instanceof d?(this.remove("webkitmouseforcewillbegin",this.forceTouchEnabled),this.preventDefault(e)):this.failOrPolyfill(e)}},{key:"$start",value:function(){var e=this;this.add("mousedown",function(t){y.forPressure&&(e.setPressed(!0),P(e.block,"start",e.el,t))})}},{key:"$change",value:function(){var e=this;this.add("webkitmouseforcechanged",function(t){y.forPressure&&0!==t.webkitForce&&e.pressed&&P(e.block,"change",e.el,e.normalizeForce(t.webkitForce),t)})}},{key:"$end",value:function(){var e=this;this.add("mouseup",function(){y.forPressure&&(e.setPressed(!1),P(e.block,"end",e.el))}),this.add("mouseleave",function(){y.forPressure&&(e.pressed&&P(e.block,"end",e.el),e.setPressed(!1))})}},{key:"$startDeepPress",value:function(){var e=this;this.add("webkitmouseforcedown",function(t){y.forPressure&&(e.setDeepPressed(!0),P(e.block,"startDeepPress",e.el,t))})}},{key:"$endDeepPress",value:function(){var e=this;this.add("webkitmouseforceup",function(){y.forPressure&&(e.setDeepPressed(!1),P(e.block,"endDeepPress",e.el))}),this.add("mouseleave",function(){y.forPressure&&(e.deepPressed&&P(e.block,"endDeepPress",e.el),e.setDeepPressed(!1))})}},{key:"normalizeForce",value:function(e){return this.reachOne(k(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.999?1:e}}]),t}(h),d=function(e){function t(e,n){i(this,t);var o=s(this,Object.getPrototypeOf(t).call(this,e));return o.$start(),o.$change(),o.$end(),o.force=0,o.increment=.01,o.firstRun(n),o}return n(t,e),o(t,[{key:"firstRun",value:function(e){this.preventDefault(e),this.startLogic(e),this.changeLogic(e)}},{key:"$start",value:function(){var e=this;this.add(y.mobile?"touchstart":"mousedown",function(t){e.startLogic(t)})}},{key:"startLogic",value:function(e){this.setPressed(!0),P(this.block,"start",this.el,e)}},{key:"$change",value:function(){this.add(y.mobile?"touchstart":"mousedown",this.changeLogic.bind(this))}},{key:"changeLogic",value:function(e){this.pressed&&(this.setPressed(!0),this.runForce(e))}},{key:"$end",value:function(){var e=this;this.add(y.mobile?"touchend":"mouseup",function(){e.endDeepPress(),e.setPressed(!1),P(e.block,"end",e.el),e.force=0}),this.add("mouseleave",function(){e.endDeepPress(),e.pressed&&P(e.block,"end",e.el),e.setPressed(!1),e.force=0})}},{key:"startDeepPress",value:function(e){this.deepPressed===!1&&P(this.block,"startDeepPress",this.el,e),this.setDeepPressed(!0)}},{key:"endDeepPress",value:function(){this.deepPressed===!0&&P(this.block,"endDeepPress",this.el),this.setDeepPressed(!1)}},{key:"runForce",value:function(e){this.pressed&&(P(this.block,"change",this.el,this.force,e),this.force>=.5?this.startDeepPress(e):this.endDeepPress(),this.force=this.force+this.increment>1?1:this.force+this.increment,setTimeout(this.runForce.bind(this),10,e))}}]),t}(h),p={preventDefault:!0,only:null,polyfill:!1,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},y={hasRun:!1,forPressure:!1,type:!1,mobile:"ontouchstart"in t,didFail:function(){this.hasRun=!0,this.forPressure=!1},didSucceed:function(e){this.hasRun=!0,this.forPressure=!0,this.type=e}},v=function(e,s){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if("string"==typeof e||e instanceof String)for(var i=t.querySelectorAll(e),o=0;o<i.length;o++)new l(i[o],s,n);else if(b(e))new l(e,s,n);else for(var o=0;o<e.length;o++)new l(e[o],s,n)},b=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":r(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":r(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},P=function(e,t,s){e.hasOwnProperty(t)&&e[t].apply(s||this,Array.prototype.slice.call(arguments,3))},k=function(e,t,s,n,i){return(e-t)*(i-n)/(s-t)+n}}("undefined"!=typeof window?window:!1,"undefined"!=typeof window?window.document:!1);
// Pressure v2.0.0 | Created By Stuart Yamartino | MIT License | 2015 - 2016
!function(e,t){"use strict";function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},u={set:function(e,t,s){p(e,t,s)},config:function(e){f.set(e)},map:function(e,t,s,n,i){return b.apply(null,arguments)}};if(e===!1)return void console.warn("Pressure requires a window with a document");if("undefined"!=typeof u)if("function"==typeof define&&define.amd){var h=u;define(["pressure"],function(e){return e})}else if("object"===("undefined"==typeof module?"undefined":o(module))&&module.exports){var h=u;module.exports=h}else e.Pressure=u;var l=function(){function e(t,s,n){i(this,e),this.routeEvents(t,s,n),this.preventSelect(t,n)}return r(e,[{key:"routeEvents",value:function(e,t,s){var n=f.get("only",s);!v||"desktop"!==n&&"mobile"===n?!P||"mobile"!==n&&"desktop"===n?this.adapter=new c(e,t).bindUnsupportedEvent():this.adapter=new d(e,t,s).bindEvents():this.adapter=new a(e,t,s).bindEvents()}},{key:"preventSelect",value:function(e,t){f.get("preventSelect",t)&&(e.style.webkitTouchCallout="none",e.style.webkitUserSelect="none",e.style.khtmlUserSelect="none",e.style.MozUserSelect="none",e.style.msUserSelect="none",e.style.userSelect="none")}}]),e}(),c=function(){function e(t,s,n){i(this,e),this.el=t,this.block=s,this.options=n,this.pressed=!1,this.deepPressed=!1,this.runKey=Math.random()}return r(e,[{key:"setPressed",value:function(e){this.pressed=e}},{key:"setDeepPressed",value:function(e){this.deepPressed=e}},{key:"isPressed",value:function(){return this.pressed}},{key:"isDeepPressed",value:function(){return this.deepPressed}},{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"runClosure",value:function(e){e in this.block&&this.block[e].apply(this.el,Array.prototype.slice.call(arguments,1))}},{key:"fail",value:function(e,t){f.get("polyfill",this.options)?this.runKey===t&&this.runPolyfill(e):this.runClosure("unsupported",e)}},{key:"bindUnsupportedEvent",value:function(){var e=this;this.add(P?"touchstart":"mousedown",function(t){return e.runClosure("unsupported",t)})}},{key:"_startPress",value:function(e){this.isPressed()===!1&&(this.setPressed(!0),this.runClosure("start",e))}},{key:"_startDeepPress",value:function(e){this.isPressed()&&this.isDeepPressed()===!1&&(this.setDeepPressed(!0),this.runClosure("startDeepPress",e))}},{key:"_endDeepPress",value:function(){this.isPressed()&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress"))}},{key:"_endPress",value:function(){this.isPressed()&&(this._endDeepPress(),this.setPressed(!1),this.runClosure("end")),this.runKey=Math.random()}},{key:"runPolyfill",value:function(e){this.increment=10/f.get("polyfillSpeed",this.options),this.setPressed(!0),this.runClosure("start",e),this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.isPressed()&&(this.runClosure("change",e,t),e>=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),a=function(e){function t(e,n,r){return i(this,t),s(this,Object.getPrototypeOf(t).call(this,e,n,r))}return n(t,e),r(t,[{key:"bindEvents",value:function(){this.add("webkitmouseforcewillbegin",this._startPress.bind(this)),this.add("mousedown",this.support.bind(this)),this.add("webkitmouseforcechanged",this.change.bind(this)),this.add("webkitmouseforcedown",this._startDeepPress.bind(this)),this.add("webkitmouseforceup",this._endDeepPress.bind(this)),this.add("mouseleave",this._endPress.bind(this)),this.add("mouseup",this._endPress.bind(this))}},{key:"support",value:function(e){this.isPressed()===!1&&this.fail(e,this.runKey)}},{key:"change",value:function(e){this.isPressed()&&e.webkitForce>0&&this.runClosure("change",this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(b(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),t}(c),d=function(e){function t(e,n,r){return i(this,t),s(this,Object.getPrototypeOf(t).call(this,e,n,r))}return n(t,e),r(t,[{key:"bindEvents",value:function(){m?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.supportTest.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacyTest.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.runClosure("change",this.selectTouch(e).force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length<=2||void 0===arguments[2]?this.runKey:arguments[2];this.isPressed()===!1&&(6>=e?(e++,setTimeout(this.supportTest.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacyTest",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacyTest",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):6>=e?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,n),10)):this.fail(t,s)}},{key:"loopForce",value:function(e){this.isPressed()&&(this.touch=this.selectTouch(e),setTimeout(this.loopForce.bind(this,e),10),this.runClosure("change",this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return this.returnTouch(e.touches[t],e)}},{key:"returnTouch",value:function(e,t){return e.force>=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),t}(c),f={polyfill:!0,polyfillSpeed:1e3,preventSelect:!0,only:null,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},p=function(e,s){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if("string"==typeof e||e instanceof String)for(var i=t.querySelectorAll(e),r=0;r<i.length;r++)new l(i[r],s,n);else if(y(e))new l(e,s,n);else for(var r=0;r<e.length;r++)new l(e[r],s,n)},y=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":o(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":o(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},b=function(e,t,s,n,i){return(e-t)*(i-n)/(s-t)+n},v="ontouchstart"in t==!1,P="ontouchstart"in t==!0,m="ontouchforcechange"in t}("undefined"!=typeof window?window:!1,"undefined"!=typeof window?window.document:!1);

@@ -5,8 +5,4 @@ // Example of change method with a failure closure

Pressure.config({
polyfill: true
});
$.pressureConfig({
preventDefault: false
polyfill: false
});

@@ -20,3 +16,4 @@

change: function(force, event){
this.style.width = $.pressureMap(force, 0, 1, 200, 300) + 'px';
// event.preventDefault();
this.style.width = Pressure.map(force, 0, 1, 200, 300) + 'px';
this.innerHTML = force;

@@ -28,2 +25,3 @@ console.log('change', force);

console.log('start deep press', event);
this.style.backgroundColor = '#FF0040';
},

@@ -33,2 +31,3 @@

console.log('end deep press');
this.style.backgroundColor = '#0080FF';
},

@@ -48,14 +47,14 @@

Pressure.set(document.querySelectorAll('#el1'), block, {polyfill: true});
Pressure.set($('#el2'), block, {only: 'force'});
Pressure.set('#el3', block, {only: '3d', polyfill: true});
Pressure.set(document.querySelectorAll('#el1'), block);
Pressure.set($('#el2'), block, {only: 'desktop', polyfill: true, polyfillSpeed: 5000});
Pressure.set('#el3', block, {only: 'mobile'});
$('#el1-jquery').pressure(block);
$('#el2-jquery').pressure(block, {only: 'force', preventDefault: false});
$('#el3-jquery').pressure(block, {only: '3d'});
$('#el2-jquery').pressure(block, {only: 'desktop'});
$('#el3-jquery').pressure(block, {only: 'mobile'});
// $('h3').pressure({
// start: function(){
// console.log('preventDefault text');
// }
// }, {preventDefault: false});
$('img').pressure({
change: function(force, event){
console.log(force);
}
});

@@ -10,3 +10,3 @@ // include plug-ins

var HEADER_COMMENT = '// Pressure v1.0.1 | Created By Stuart Yamartino | MIT License | 2015-Present\n';
var HEADER_COMMENT = '// Pressure v2.0.0 | Created By Stuart Yamartino | MIT License | 2015 - 2016\n';
var DESTINATION = '.';

@@ -20,8 +20,6 @@

'./src/element.js',
'./src/adapter.js',
'./src/adapter_3d_touch.js',
'./src/adapter_force_touch.js',
'./src/adapter_polyfill.js',
'./src/adapters/adapter.js',
'./src/adapters/adapter_force_touch.js',
'./src/adapters/adapter_3d_touch.js',
'./src/config.js',
'./src/support.js',
'./src/helpers.js',

@@ -55,8 +53,6 @@ ])

'./src/element.js',
'./src/adapter.js',
'./src/adapter_3d_touch.js',
'./src/adapter_force_touch.js',
'./src/adapter_polyfill.js',
'./src/adapters/adapter.js',
'./src/adapters/adapter_force_touch.js',
'./src/adapters/adapter_3d_touch.js',
'./src/config.js',
'./src/support.js',
'./src/helpers.js',

@@ -86,3 +82,3 @@ ])

gulp.task('watch', function() {
gulp.watch('src/*', ['pressure', 'jquery-pressure']);
gulp.watch(['src/*', 'src/adapters/*'], ['pressure', 'jquery-pressure']);
});
{
"name": "pressure",
"version": "1.0.1",
"description": "Pressure is a JavaScript library for handling both Force Touch and 3D Touch through a single API",
"version": "2.0.0",
"description": "Pressure is a lightweight JavaScript library for both Force Touch and 3D Touch through a single API.",
"main": "dist/pressure.min.js",

@@ -32,3 +32,7 @@ "dependencies": {},

"iphone6s",
"iphone6splus"
"iphone6splus",
"iphone7",
"iphone7plus",
"magic-trackpad",
"apple-pencil"
],

@@ -35,0 +39,0 @@ "author": "Stuart Yamartino",

@@ -1,2 +0,2 @@

# pressure.js
# Pressure.js

@@ -6,10 +6,10 @@ [![Join the chat at https://gitter.im/yamartino/pressure](https://badges.gitter.im/yamartino/pressure.svg)](https://gitter.im/yamartino/pressure?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

![Pressure Example](http://yamartino.github.io/pressure/pressure.gif)
![Pressure Example](http://pressurejs.com/img/pressure.gif)
Pressure is a JavaScript library that makes dealing with Apple's Force Touch and 3D Touch simple. Force Touch for new Macs and 3D Touch for the new iPhone 6s and 6s Plus, all bundled under one roof with a simple API that makes working with them painless.
Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web, bundled under one library with a simple API that makes working with them painless.
Head over to the [documentation](http://yamartino.github.com/pressure) website for installation instructions and how to use pressure.js
Head over to the [documentation](http://pressurejs.com/documentation.html) for installation instructions and more details on pressure.js.
## Install
download pressure.min.js or pressure.js files from GitHub or install with npm or bower
Download pressure.min.js or pressure.js files from GitHub or install with npm or bower
#### npm

@@ -67,2 +67,3 @@ ```

unsupported: function(){
// NOTE: this is only called if the polyfill option is disabled!
// this is called once there is a touch on the element and the device or browser does not support Force or 3D touch

@@ -95,2 +96,3 @@ }

unsupported: function(){
// NOTE: this is only called if the polyfill option is disabled!
// this is called once there is a touch on the element and the device or browser does not support Force or 3D touch

@@ -102,39 +104,55 @@ }

## Options
With Pressure, the third paramater is an optional object of options that can be passed in.
###Polyfill Support
With Pressure, the third paramater is an optional object of options that can be passed in. Using the "polyfill" keyword, you can enable polyfill support for the element. What this means is that if the device or browser does not support force or 3D touch, it will fall back to using time. For example instead of force from 0 to 1, it counts up from 0 to 1 over the course of one second, as long as you are holding the element. Try some of the examples on the [main page](http://pressurejs.com) on a devices that does not support force or 3D touch and see for yourself how it works.
Using the "polyfill" keyword, you can disable polyfill support for the element. The polyfill is enabled by defauly and is useful if the device or browser does not support force or 3D touch, it will fall back to using time. For example instead of force from 0 to 1, it counts up from 0 to 1 over the course of one second, as long as you are holding the element. Try some of the examples on the main page on a devices that does not support force or 3D touch and see for yourself how it works.
```javascript
Pressure.set('#polyfill-example', {
Pressure.set('#example', {
change: function(force, event){
this.innerHTML = force;
},
unsupported: function(){
alert("Oh no, this device does not support pressure.");
}
}, {polyfill: true});
}, {polyfill: false});
```
### Only run on Force Touch trackpads (Mac)
Set the option only to the type you want it to run on 'force' or '3d'
###Polyfill Speed
If you are using the polyfill (on by default), you can see the "polyfillSpeed" speed to determine how fast the polyfill takes to go from 0 to 1. The value is an integer in milliseconds and the default is 1000 (1 second).
```javascript
$('#element').pressure({
Pressure.set('#example', {
change: function(force, event){
this.innerHTML = force;
}
}, {polyfillSpeed: 5000});
// takes 5 seconds to go from a force value of 0 to 1
// only on devices that do not support force touch or 3d touch
```
### Only run on Force Touch trackpads (Desktop)
Set the option only to the type you want it to run on 'desktop' or 'mobile'
```javascript
Pressure.set('#example',{
change: function(force, event){
console.log(force);
},
}, {only: 'force'});
}, {only: 'desktop'});
```
### Only run on 3D Touch (iPhone 6s)
### Only run on 3D Touch (Mobile)
```javascript
$('#element').pressure({
Pressure.set('#example',{
change: function(force, event){
console.log(force);
},
}, {only: '3d'});
}, {only: 'mobile'});
```
### Change the preventDefault option
### Change the preventSelect option
The preventDefault option in "true" by default and it prevents the default actions that happen on 3D "peel and pop" actions and the Force "define word" actions as well as other defaults. To allow the defaults to run set preventDefault to "false"
```javascript
$('#element').pressure({
Pressure.set('#example',{
change: function(force, event){
console.log(force);
},
}, {preventDefault: false});
}, {preventSelect: false});
```

@@ -153,3 +171,4 @@

Pressure.config({
polyfill: false,
polyfill: true,
polyfillSpeed: 1000,
preventDefault: true,

@@ -156,0 +175,0 @@ only: null

// This class holds the states of the the Pressure config
var Config = {
preventDefault: true,
// 'false' will make polyfill not run when pressure is not supported and the 'unsupported' method will be called
polyfill: true,
// milliseconds it takes to go from 0 to 1 for the polyfill
polyfillSpeed: 1000,
// 'true' prevents the selecting of text and images via css properties
preventSelect: true,
// 'mobile' or 'desktop' will make it run only on that type of device
only: null,
polyfill: false,
// this will get the correct config / option settings for the current pressure check

@@ -11,0 +17,0 @@ get(option, options){

class Element{
constructor(element, block, options){
this.element = element;
this.block = block;
this.type = Config.get('only', options);
this.options = options;
this.routeEvents();
constructor(el, block, options){
this.routeEvents(el, block, options);
this.preventSelect(el, options);
}
routeEvents(){
routeEvents(el, block, options){
var type = Config.get('only', options);
// if on desktop and requesting Force Touch or not requesting 3D Touch
if(Support.mobile === false && (this.type === 'force' || this.type !== '3d')){
new AdapterForceTouch(this);
if(isDesktop && (type === 'desktop' || type !== 'mobile')){
this.adapter = new AdapterForceTouch(el, block, options).bindEvents();
}
// if on mobile and requesting 3D Touch or not requestion Force Touch
else if(Support.mobile === true && (this.type === '3d' || this.type !== 'force')){
new Adapter3DTouch(this);
else if(isMobile && (type === 'mobile' || type !== 'desktop')){
this.adapter = new Adapter3DTouch(el, block, options).bindEvents();
}
// if it is requesting a type and your browser is of other type
// unsupported if it is requesting a type and your browser is of other type
else{
this.instantFail();
this.adapter = new Adapter(el, block).bindUnsupportedEvent();
}
}
instantFail(){
this.element.addEventListener(Support.mobile ? 'touchstart' : 'mousedown', () => runClosure(this.block, 'unsupported', this.element), false);
// prevent the default action of text selection, "peak & pop", and force touch special feature
preventSelect(el, options){
if(Config.get('preventSelect', options)){
el.style.webkitTouchCallout = "none";
el.style.webkitUserSelect = "none";
el.style.khtmlUserSelect = "none";
el.style.MozUserSelect = "none";
el.style.msUserSelect = "none";
el.style.userSelect = "none";
}
}
}

@@ -1,2 +0,2 @@

//------------------- Helpers Section -------------------//
//------------------- Helpers -------------------//

@@ -30,10 +30,2 @@ // accepts jQuery object, node list, string selector, then called a setup for each element

// run the closure if the property exists in the object
var runClosure = function(closure, method, element){
if(closure.hasOwnProperty(method)){
// call the closure method and apply nth arguments if they exist
closure[method].apply(element || this, Array.prototype.slice.call(arguments, 3));
}
}
// the map method allows for interpolating a value from one range of values to another

@@ -44,1 +36,10 @@ // example from the Arduino documentation: https://www.arduino.cc/en/Reference/Map

}
// check if device is desktop device
var isDesktop = 'ontouchstart' in document === false;
// check if device is regular mobile device
var isMobile = 'ontouchstart' in document === true;
// check if device is an Apple iOS 10+ device
var supportsTouchForceChange = 'ontouchforcechange' in document;

@@ -15,3 +15,3 @@ //--------------------- Public jQuery API Section ---------------------//

$.pressureMap = function(x, in_min, in_max, out_min, out_max) {
return map(x, in_min, in_max, out_min, out_max);
return map.apply(null, arguments);
};

@@ -18,0 +18,0 @@

@@ -6,3 +6,3 @@ //--------------------- Public API Section ---------------------//

// targets any device with Force of 3D Touch
// targets any device with Force or 3D Touch
set(selector, closure, options){

@@ -20,5 +20,5 @@ loopPressureElements(selector, closure, options);

map(x, in_min, in_max, out_min, out_max){
return map(x, in_min, in_max, out_min, out_max);
return map.apply(null, arguments);
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc