From f2756b52bf92a5bf69ff7665d188a9cedc18a8a9 Mon Sep 17 00:00:00 2001 From: Stuart Yamartino Date: Sat, 25 Feb 2017 21:34:50 -0500 Subject: [PATCH 01/13] Building out more abstract adapters and added pointer adapter --- License | 2 +- src/adapters/adapter.js | 2 +- src/adapters/adapter_pointer.js | 40 +++++++++++++++++++++++++++++++++ src/config.js | 2 +- src/element.js | 12 ++++++---- src/helpers.js | 11 +++++---- 6 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 src/adapters/adapter_pointer.js diff --git a/License b/License index d96f6fa..12ccebd 100644 --- a/License +++ b/License @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2015 - 2016 Stuart Yamartino. +Copyright (c) 2015 - 2017 Stuart Yamartino. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/adapters/adapter.js b/src/adapters/adapter.js index 5e1f822..7ceb6ab 100644 --- a/src/adapters/adapter.js +++ b/src/adapters/adapter.js @@ -52,7 +52,7 @@ class Adapter{ } bindUnsupportedEvent(){ - this.add(isMobile ? 'touchstart' : 'mousedown', (event) => this.runClosure('unsupported', event)); + this.add(supportsTouch ? 'touchstart' : 'mousedown', (event) => this.runClosure('unsupported', event)); } _startPress(event){ diff --git a/src/adapters/adapter_pointer.js b/src/adapters/adapter_pointer.js new file mode 100644 index 0000000..6b1b4dd --- /dev/null +++ b/src/adapters/adapter_pointer.js @@ -0,0 +1,40 @@ +/* +This adapter is for devices that support pointer events. +*/ + +class AdapterPointer extends Adapter{ + + constructor(el, block, options){ + super(el, block, options); + } + + bindEvents(){ + this.add('pointerdown', this.supportTest.bind(this, 0)); + this.add('pointermove', this.change.bind(this)); + this.add('pointerdown', this.supportTest.bind(this, 0)); + this.add('pointerup', this._endPress.bind(this)); + } + + supportTest(iter, event, runKey = this.runKey){ + if(this.isPressed() === false){ + if(iter <= 6){ + iter++; + setTimeout(this.supportTest.bind(this, iter, event, runKey), 10); + } else { + this.fail(event, runKey); + } + } + } + + change(event){ + if(this.isPressed() && event.pressure > 0){ + this._changePress(event.pressure, event); + this.deepPress(event); + } + } + + returnTouch(event){ + event.pressure >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + } + +} diff --git a/src/config.js b/src/config.js index 7844397..2fb2e49 100644 --- a/src/config.js +++ b/src/config.js @@ -10,7 +10,7 @@ var Config = { // '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 + // 'touch', 'mouse', or 'pointer' will make it run only on that type of device only: null, // this will get the correct config / option settings for the current pressure check diff --git a/src/element.js b/src/element.js index e78b2c7..78a4894 100644 --- a/src/element.js +++ b/src/element.js @@ -7,12 +7,16 @@ class Element{ routeEvents(el, block, options){ var type = Config.get('only', options); - // if on desktop and requesting Force Touch or not requesting 3D Touch - if(isDesktop && (type === 'desktop' || type !== 'mobile')){ + // for devices that support pointer events + if(supportsPointer && (type === 'pointer' || type === null)){ + this.adapter = new AdapterPointer(el, block, options).bindEvents(); + } + // for devices that support Force Touch + else if(supportsMouse && (type === 'mouse' || type === null)){ this.adapter = new AdapterForceTouch(el, block, options).bindEvents(); } - // if on mobile and requesting 3D Touch or not requestion Force Touch - else if(isMobile && (type === 'mobile' || type !== 'desktop')){ + // for devices that support 3D Touch + else if(supportsTouch && (type === 'touch' || type === null)){ this.adapter = new Adapter3DTouch(el, block, options).bindEvents(); } // unsupported if it is requesting a type and your browser is of other type diff --git a/src/helpers.js b/src/helpers.js index ec28c58..06666e9 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -33,13 +33,16 @@ var map = function(x, in_min, in_max, out_min, out_max){ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } -var isDesktop = false; -var isMobile = false; +var supportsMouse = false; +var supportsTouch = false; +var supportsPointer = false; var supportsTouchForceChange = false; + if (typeof window !== 'undefined') { // only attempt to assign these in a browser environment. // on the server, this is a no-op, like the rest of the library - isMobile = 'ontouchstart' in window.document; - isDesktop = !isMobile; + supportsTouch = 'ontouchstart' in window.document; + supportsMouse = 'onmousemove' in window.document && !supportsTouch; + supportsPointer = 'onpointermove' in window.document; supportsTouchForceChange = 'ontouchforcechange' in window.document; } From 613baaba24e2607f9f6735a61aced90a031f26f3 Mon Sep 17 00:00:00 2001 From: Stuart Yamartino Date: Sat, 25 Feb 2017 21:43:16 -0500 Subject: [PATCH 02/13] Wow that actually kinda worked first try --- dist/jquery.pressure.js | 92 +++++++++++++++++++++++++++------ dist/jquery.pressure.min.js | 4 +- dist/pressure.js | 92 +++++++++++++++++++++++++++------ dist/pressure.min.js | 4 +- gulpfile.js | 4 +- src/adapters/adapter_pointer.js | 4 +- 6 files changed, 161 insertions(+), 39 deletions(-) diff --git a/dist/jquery.pressure.js b/dist/jquery.pressure.js index a36b036..1806efd 100644 --- a/dist/jquery.pressure.js +++ b/dist/jquery.pressure.js @@ -1,4 +1,4 @@ -// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2016 +// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 ;(function(root, factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory); @@ -52,18 +52,22 @@ var Element = function () { key: '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 (isDesktop && (type === 'desktop' || type !== 'mobile')) { - this.adapter = new AdapterForceTouch(el, block, options).bindEvents(); + // for devices that support pointer events + if (supportsPointer && (type === 'pointer' || type === null)) { + this.adapter = new AdapterPointer(el, block, options).bindEvents(); } - // if on mobile and requesting 3D Touch or not requestion Force Touch - else if (isMobile && (type === 'mobile' || type !== 'desktop')) { - this.adapter = new Adapter3DTouch(el, block, options).bindEvents(); + // for devices that support Force Touch + else if (supportsMouse && (type === 'mouse' || type === null)) { + this.adapter = new AdapterForceTouch(el, block, options).bindEvents(); } - // unsupported if it is requesting a type and your browser is of other type - else { - this.adapter = new Adapter(el, block).bindUnsupportedEvent(); + // for devices that support 3D Touch + else if (supportsTouch && (type === 'touch' || type === null)) { + this.adapter = new Adapter3DTouch(el, block, options).bindEvents(); } + // unsupported if it is requesting a type and your browser is of other type + else { + this.adapter = new Adapter(el, block).bindUnsupportedEvent(); + } } // prevent the default action of text selection, "peak & pop", and force touch special feature @@ -151,7 +155,7 @@ var Adapter = function () { value: function bindUnsupportedEvent() { var _this = this; - this.add(isMobile ? 'touchstart' : 'mousedown', function (event) { + this.add(supportsTouch ? 'touchstart' : 'mousedown', function (event) { return _this.runClosure('unsupported', event); }); } @@ -392,6 +396,59 @@ var Adapter3DTouch = function (_Adapter2) { return Adapter3DTouch; }(Adapter); +/* +This adapter is for devices that support pointer events. +*/ + +var AdapterPointer = function (_Adapter3) { + _inherits(AdapterPointer, _Adapter3); + + function AdapterPointer(el, block, options) { + _classCallCheck(this, AdapterPointer); + + return _possibleConstructorReturn(this, (AdapterPointer.__proto__ || Object.getPrototypeOf(AdapterPointer)).call(this, el, block, options)); + } + + _createClass(AdapterPointer, [{ + key: 'bindEvents', + value: function bindEvents() { + this.add('pointerdown', this.supportTest.bind(this, 0)); + this.add('pointermove', this.change.bind(this)); + this.add('pointerup', this._endPress.bind(this)); + this.add('pointerleave', this._endPress.bind(this)); + } + }, { + key: 'supportTest', + value: function supportTest(iter, event) { + var runKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.runKey; + + 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(event) { + if (this.isPressed() && event.pressure > 0) { + this._changePress(event.pressure, event); + this.deepPress(event); + } + } + }, { + key: 'deepPress', + value: function deepPress(event) { + event.pressure >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + } + }]); + + return AdapterPointer; +}(Adapter); + // This class holds the states of the the Pressure config @@ -406,7 +463,7 @@ var Config = { // '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 + // 'touch', 'mouse', or 'pointer' will make it run only on that type of device only: null, // this will get the correct config / option settings for the current pressure check @@ -460,14 +517,17 @@ var map = function map(x, in_min, in_max, out_min, out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }; -var isDesktop = false; -var isMobile = false; +var supportsMouse = false; +var supportsTouch = false; +var supportsPointer = false; var supportsTouchForceChange = false; + if (typeof window !== 'undefined') { // only attempt to assign these in a browser environment. // on the server, this is a no-op, like the rest of the library - isMobile = 'ontouchstart' in window.document; - isDesktop = !isMobile; + supportsTouch = 'ontouchstart' in window.document; + supportsMouse = 'onmousemove' in window.document && !supportsTouch; + supportsPointer = 'onpointermove' in window.document; supportsTouchForceChange = 'ontouchforcechange' in window.document; } return void 0; diff --git a/dist/jquery.pressure.min.js b/dist/jquery.pressure.min.js index bb17ed8..2cee5da 100644 --- a/dist/jquery.pressure.min.js +++ b/dist/jquery.pressure.min.js @@ -1,2 +1,2 @@ -// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2016 -!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(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 s(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 n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),c=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),i}(u),l={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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),c=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.supportTest.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),i}(u),a={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])}},d=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i 2 && arguments[2] !== undefined ? arguments[2] : this.runKey; + + 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(event) { + if (this.isPressed() && event.pressure > 0) { + this._changePress(event.pressure, event); + this.deepPress(event); + } + } + }, { + key: 'deepPress', + value: function deepPress(event) { + event.pressure >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + } + }]); + + return AdapterPointer; +}(Adapter); + // This class holds the states of the the Pressure config @@ -411,7 +468,7 @@ var Config = { // '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 + // 'touch', 'mouse', or 'pointer' will make it run only on that type of device only: null, // this will get the correct config / option settings for the current pressure check @@ -465,14 +522,17 @@ var _map = function _map(x, in_min, in_max, out_min, out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }; -var isDesktop = false; -var isMobile = false; +var supportsMouse = false; +var supportsTouch = false; +var supportsPointer = false; var supportsTouchForceChange = false; + if (typeof window !== 'undefined') { // only attempt to assign these in a browser environment. // on the server, this is a no-op, like the rest of the library - isMobile = 'ontouchstart' in window.document; - isDesktop = !isMobile; + supportsTouch = 'ontouchstart' in window.document; + supportsMouse = 'onmousemove' in window.document && !supportsTouch; + supportsPointer = 'onpointermove' in window.document; supportsTouchForceChange = 'ontouchforcechange' in window.document; } return Pressure; diff --git a/dist/pressure.min.js b/dist/pressure.min.js index 6c3b360..543eb85 100644 --- a/dist/pressure.min.js +++ b/dist/pressure.min.js @@ -1,2 +1,2 @@ -// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2016 -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Pressure=t()}(this,function(){"use strict";function e(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 t(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 s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),c=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),o}(u),l={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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),c=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.supportTest.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),o}(u),a={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])}},d=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); } From e6be028271dbbf392b5fe5e7840177703c557b53 Mon Sep 17 00:00:00 2001 From: Stuart Yamartino Date: Sat, 25 Feb 2017 22:07:52 -0500 Subject: [PATCH 03/13] Improved triggering of pointer event pressure on start --- dist/jquery.pressure.js | 9 +++++++-- dist/jquery.pressure.min.js | 2 +- dist/pressure.js | 9 +++++++-- dist/pressure.min.js | 2 +- src/adapters/adapter_pointer.js | 9 +++++++-- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/dist/jquery.pressure.js b/dist/jquery.pressure.js index 1806efd..8d6fe9b 100644 --- a/dist/jquery.pressure.js +++ b/dist/jquery.pressure.js @@ -425,7 +425,12 @@ var AdapterPointer = function (_Adapter3) { if (this.isPressed() === false) { if (iter <= 6) { iter++; - setTimeout(this.supportTest.bind(this, iter, event, runKey), 10); + if (event.pressure === 0 || event.pressure === 0.5) { + setTimeout(this.supportTest.bind(this, iter, event, runKey), 10); + } else { + this._startPress(event); + this._changePress(event.pressure, event); + } } else { this.fail(event, runKey); } @@ -434,7 +439,7 @@ var AdapterPointer = function (_Adapter3) { }, { key: 'change', value: function change(event) { - if (this.isPressed() && event.pressure > 0) { + if (this.isPressed() && event.pressure > 0 && event.pressure !== 0.5) { this._changePress(event.pressure, event); this.deepPress(event); } diff --git a/dist/jquery.pressure.min.js b/dist/jquery.pressure.min.js index 2cee5da..a926184 100644 --- a/dist/jquery.pressure.min.js +++ b/dist/jquery.pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(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 s(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 n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),c=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.supportTest.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),i}(u),a={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])}},d=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),c=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),i}(u),a={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])}},d=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i 0) { + if (this.isPressed() && event.pressure > 0 && event.pressure !== 0.5) { this._changePress(event.pressure, event); this.deepPress(event); } diff --git a/dist/pressure.min.js b/dist/pressure.min.js index 543eb85..239de5e 100644 --- a/dist/pressure.min.js +++ b/dist/pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Pressure=t()}(this,function(){"use strict";function e(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 t(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 s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),c=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.supportTest.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),o}(u),a={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])}},d=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(n){function r(t,n,i){return s(this,r),e(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t,n,i))}return t(r,n),i(r,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),r}(u),c=function(n){function r(t,n,i){return s(this,r),e(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t,n,i))}return t(r,n),i(r,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),r}(u),l=function(n){function r(t,n,i){return s(this,r),e(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t,n,i))}return t(r,n),i(r,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),r}(u),a={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])}},d=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i 0){ + if(this.isPressed() && event.pressure > 0 && event.pressure !== 0.5){ this._changePress(event.pressure, event); this.deepPress(event); } From a6a74a048e657f46c4e4ef223ecac17af4d148cc Mon Sep 17 00:00:00 2001 From: Stuart Yamartino Date: Sat, 25 Feb 2017 22:31:48 -0500 Subject: [PATCH 04/13] Building a polyfill decrement for optional smooth release --- dist/jquery.pressure.js | 28 +++++++++++++++++++++++----- dist/jquery.pressure.min.js | 2 +- dist/pressure.js | 28 +++++++++++++++++++++++----- dist/pressure.min.js | 2 +- src/adapters/adapter.js | 22 ++++++++++++++++++---- src/config.js | 5 ++++- 6 files changed, 70 insertions(+), 17 deletions(-) diff --git a/dist/jquery.pressure.js b/dist/jquery.pressure.js index 8d6fe9b..e018ccc 100644 --- a/dist/jquery.pressure.js +++ b/dist/jquery.pressure.js @@ -203,7 +203,8 @@ var Adapter = function () { }, { key: 'runPolyfill', value: function runPolyfill(event) { - this.increment = 10 / Config.get('polyfillSpeed', this.options); + this.increment = Config.get('polyfillSpeedUp', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedUp', this.options); + this.decrement = Config.get('polyfillSpeedDown', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedDown', this.options); this.setPressed(true); this.runClosure('start', event); this.loopPolyfillForce(0, event); @@ -211,11 +212,25 @@ var Adapter = function () { }, { key: 'loopPolyfillForce', value: function loopPolyfillForce(force, event) { - if (this.isPressed() && this.nativeSupport === false) { + if (this.nativeSupport === false) { + 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); + } else { + this.loopPolyfillForceDown(force, event); + } + } + } + }, { + key: 'loopPolyfillForceDown', + value: function loopPolyfillForceDown(force, event) { + if (this.isPressed() === false && this.nativeSupport === false && force > 0) { + force = force - this.decrement < 0 ? 0 : force - this.increment; 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); + setTimeout(this.loopPolyfillForceDown.bind(this, force, event), 10); } } }]); @@ -463,7 +478,10 @@ var Config = { polyfill: true, // milliseconds it takes to go from 0 to 1 for the polyfill - polyfillSpeed: 1000, + polyfillSpeedUp: 1000, + + // milliseconds it takes to go from 1 to 0 for the polyfill + polyfillSpeedDown: 0, // 'true' prevents the selecting of text and images via css properties preventSelect: true, diff --git a/dist/jquery.pressure.min.js b/dist/jquery.pressure.min.js index a926184..3d4e66f 100644 --- a/dist/jquery.pressure.min.js +++ b/dist/jquery.pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(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 s(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 n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),c=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),i}(u),a={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])}},d=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):this.loopPolyfillForceDown(e,t))}},{key:"loopPolyfillForceDown",value:function(e,t){this.isPressed()===!1&&this.nativeSupport===!1&&e>0&&(e=e-this.decrement<0?0:e-this.increment,this.runClosure("change",e,t),e>=.5?this._startDeepPress(t):this._endDeepPress(),setTimeout(this.loopPolyfillForceDown.bind(this,e,t),10))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),i}(u),c=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),i}(u),a={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + force = force + this.increment > 1 ? 1 : force + this.increment; + setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); + } else { + this.loopPolyfillForceDown(force, event); + } + } + } + }, { + key: 'loopPolyfillForceDown', + value: function loopPolyfillForceDown(force, event) { + if (this.isPressed() === false && this.nativeSupport === false && force > 0) { + force = force - this.decrement < 0 ? 0 : force - this.increment; 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); + setTimeout(this.loopPolyfillForceDown.bind(this, force, event), 10); } } }]); @@ -468,7 +483,10 @@ var Config = { polyfill: true, // milliseconds it takes to go from 0 to 1 for the polyfill - polyfillSpeed: 1000, + polyfillSpeedUp: 1000, + + // milliseconds it takes to go from 1 to 0 for the polyfill + polyfillSpeedDown: 0, // 'true' prevents the selecting of text and images via css properties preventSelect: true, diff --git a/dist/pressure.min.js b/dist/pressure.min.js index 239de5e..9a718ef 100644 --- a/dist/pressure.min.js +++ b/dist/pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Pressure=t()}(this,function(){"use strict";function e(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 t(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 s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(n){function r(t,n,i){return s(this,r),e(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t,n,i))}return t(r,n),i(r,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),r}(u),c=function(n){function r(t,n,i){return s(this,r),e(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t,n,i))}return t(r,n),i(r,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),r}(u),l=function(n){function r(t,n,i){return s(this,r),e(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t,n,i))}return t(r,n),i(r,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),r}(u),a={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])}},d=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):this.loopPolyfillForceDown(e,t))}},{key:"loopPolyfillForceDown",value:function(e,t){this.isPressed()===!1&&this.nativeSupport===!1&&e>0&&(e=e-this.decrement<0?0:e-this.increment,this.runClosure("change",e,t),e>=.5?this._startDeepPress(t):this._endDeepPress(),setTimeout(this.loopPolyfillForceDown.bind(this,e,t),10))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),o}(u),c=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),o}(u),a={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + force = force + this.increment > 1 ? 1 : force + this.increment; + setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); + } else { + this.loopPolyfillForceDown(force, event); + } + } + } + + loopPolyfillForceDown(force, event){ + if(this.isPressed() === false && this.nativeSupport === false && force > 0){ + force = force - this.decrement < 0 ? 0 : force - this.increment; 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); + setTimeout(this.loopPolyfillForceDown.bind(this, force, event), 10); } } diff --git a/src/config.js b/src/config.js index 2fb2e49..0900ace 100644 --- a/src/config.js +++ b/src/config.js @@ -5,7 +5,10 @@ var Config = { polyfill: true, // milliseconds it takes to go from 0 to 1 for the polyfill - polyfillSpeed: 1000, + polyfillSpeedUp: 1000, + + // milliseconds it takes to go from 1 to 0 for the polyfill + polyfillSpeedDown: 0, // 'true' prevents the selecting of text and images via css properties preventSelect: true, From b2e0965ddf7560dde3bb29b2d593dbf9b1d18618 Mon Sep 17 00:00:00 2001 From: Stuart Yamartino Date: Sat, 25 Feb 2017 22:46:45 -0500 Subject: [PATCH 05/13] Updating examples --- examples/example.js | 9 +++++---- examples/index.html | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/example.js b/examples/example.js index 45de8bb..ee03bd7 100644 --- a/examples/example.js +++ b/examples/example.js @@ -41,12 +41,13 @@ var block = { } Pressure.set(document.querySelectorAll('#el1'), block); -Pressure.set($('#el2'), block, {only: 'desktop', polyfill: true, polyfillSpeed: 5000}); -Pressure.set('#el3', block, {only: 'mobile'}); +Pressure.set($('#el2'), block, {only: 'mouse', polyfill: true, polyfillSpeedUp: 5000}); +Pressure.set('#el3', block, {only: 'touch'}); $('#el1-jquery').pressure(block); -$('#el2-jquery').pressure(block, {only: 'desktop'}); -$('#el3-jquery').pressure(block, {only: 'mobile'}); +$('#el2-jquery').pressure(block, {only: 'mouse'}); +$('#el3-jquery').pressure(block, {only: 'touch'}); +$('#el4-jquery').pressure(block, {only: 'pointer'}); $('img').pressure({ change: function(force, event){ diff --git a/examples/index.html b/examples/index.html index 1412f02..a66d4cb 100644 --- a/examples/index.html +++ b/examples/index.html @@ -39,6 +39,8 @@

Change Pressure (target ONLY Force Touch | Mac, Magic Trackpad 2)

0

Change Pressure (target ONLY 3D Touch | iPhone6s, iPhone7, Apple Pencil)

0
+

Change Pressure (target ONLY Pointer Events)

+
0
From 7ae8b2043badbbf0b10e158802a2d83b0ced7139 Mon Sep 17 00:00:00 2001 From: Stuart Yamartino Date: Sat, 25 Feb 2017 23:18:11 -0500 Subject: [PATCH 06/13] Still working on decrementing the polyfill --- dist/jquery.pressure.js | 56 +++++++++++++++++--------------- dist/jquery.pressure.min.js | 2 +- dist/pressure.js | 56 +++++++++++++++++--------------- dist/pressure.min.js | 2 +- src/adapters/adapter.js | 43 ++++++++++++++---------- src/adapters/adapter_3d_touch.js | 2 +- src/adapters/adapter_pointer.js | 6 +--- src/config.js | 2 +- 8 files changed, 88 insertions(+), 81 deletions(-) diff --git a/dist/jquery.pressure.js b/dist/jquery.pressure.js index e018ccc..d7e3458 100644 --- a/dist/jquery.pressure.js +++ b/dist/jquery.pressure.js @@ -103,6 +103,7 @@ var Adapter = function () { this.pressed = false; this.deepPressed = false; this.nativeSupport = false; + this.runningPolyfill = false; this.runKey = Math.random(); } @@ -192,13 +193,20 @@ var Adapter = function () { }, { key: '_endPress', value: function _endPress() { - if (this.isPressed()) { - this._endDeepPress(); - this.setPressed(false); - this.runClosure('end'); + if (this.runningPolyfill === false) { + if (this.isPressed()) { + this._endDeepPress(); + this.setPressed(false); + this.runClosure('end'); + } + this.runKey = Math.random(); + this.nativeSupport = false; } - this.runKey = Math.random(); - this.nativeSupport = false; + } + }, { + key: 'deepPress', + value: function deepPress(force, event) { + force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); } }, { key: 'runPolyfill', @@ -214,25 +222,24 @@ var Adapter = function () { value: function loopPolyfillForce(force, event) { if (this.nativeSupport === false) { if (this.isPressed()) { - this.runClosure('change', force, event); - force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + this.runningPolyfill = true; force = force + this.increment > 1 ? 1 : force + this.increment; + this.runClosure('change', force, event); + this.deepPress(force, event); setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); } else { - this.loopPolyfillForceDown(force, event); + force = force - this.decrement < 0 ? 0 : force - this.decrement; + this.runClosure('change', force, event); + this.deepPress(force, event); + if (force === 0) { + this.runningPolyfill = false; + this._endPress(); + } else { + setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); + } } } } - }, { - key: 'loopPolyfillForceDown', - value: function loopPolyfillForceDown(force, event) { - if (this.isPressed() === false && this.nativeSupport === false && force > 0) { - force = force - this.decrement < 0 ? 0 : force - this.increment; - this.runClosure('change', force, event); - force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); - setTimeout(this.loopPolyfillForceDown.bind(this, force, event), 10); - } - } }]); return Adapter; @@ -403,7 +410,7 @@ var Adapter3DTouch = function (_Adapter2) { }, { key: 'returnTouch', value: function returnTouch(touch, event) { - touch.force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + this.deepPress(touch.force, event); return touch; } }]); @@ -456,14 +463,9 @@ var AdapterPointer = function (_Adapter3) { value: function change(event) { if (this.isPressed() && event.pressure > 0 && event.pressure !== 0.5) { this._changePress(event.pressure, event); - this.deepPress(event); + this.deepPress(event.pressure, event); } } - }, { - key: 'deepPress', - value: function deepPress(event) { - event.pressure >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); - } }]); return AdapterPointer; @@ -481,7 +483,7 @@ var Config = { polyfillSpeedUp: 1000, // milliseconds it takes to go from 1 to 0 for the polyfill - polyfillSpeedDown: 0, + polyfillSpeedDown: 1000, // 'true' prevents the selecting of text and images via css properties preventSelect: true, diff --git a/dist/jquery.pressure.min.js b/dist/jquery.pressure.min.js index 3d4e66f..e11f854 100644 --- a/dist/jquery.pressure.min.js +++ b/dist/jquery.pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(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 s(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 n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):this.loopPolyfillForceDown(e,t))}},{key:"loopPolyfillForceDown",value:function(e,t){this.isPressed()===!1&&this.nativeSupport===!1&&e>0&&(e=e-this.decrement<0?0:e-this.increment,this.runClosure("change",e,t),e>=.5?this._startDeepPress(t):this._endDeepPress(),setTimeout(this.loopPolyfillForceDown.bind(this,e,t),10))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),i}(u),c=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),i}(u),a={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,this.runClosure("change",e,t),this.deepPress(e,t),0===e?(this.runningPolyfill=!1,this._endPress()):setTimeout(this.loopPolyfillForce.bind(this,e,t),10)))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),i}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown: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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); } }, { key: 'runPolyfill', @@ -219,25 +227,24 @@ var Adapter = function () { value: function loopPolyfillForce(force, event) { if (this.nativeSupport === false) { if (this.isPressed()) { - this.runClosure('change', force, event); - force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + this.runningPolyfill = true; force = force + this.increment > 1 ? 1 : force + this.increment; + this.runClosure('change', force, event); + this.deepPress(force, event); setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); } else { - this.loopPolyfillForceDown(force, event); + force = force - this.decrement < 0 ? 0 : force - this.decrement; + this.runClosure('change', force, event); + this.deepPress(force, event); + if (force === 0) { + this.runningPolyfill = false; + this._endPress(); + } else { + setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); + } } } } - }, { - key: 'loopPolyfillForceDown', - value: function loopPolyfillForceDown(force, event) { - if (this.isPressed() === false && this.nativeSupport === false && force > 0) { - force = force - this.decrement < 0 ? 0 : force - this.increment; - this.runClosure('change', force, event); - force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); - setTimeout(this.loopPolyfillForceDown.bind(this, force, event), 10); - } - } }]); return Adapter; @@ -408,7 +415,7 @@ var Adapter3DTouch = function (_Adapter2) { }, { key: 'returnTouch', value: function returnTouch(touch, event) { - touch.force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + this.deepPress(touch.force, event); return touch; } }]); @@ -461,14 +468,9 @@ var AdapterPointer = function (_Adapter3) { value: function change(event) { if (this.isPressed() && event.pressure > 0 && event.pressure !== 0.5) { this._changePress(event.pressure, event); - this.deepPress(event); + this.deepPress(event.pressure, event); } } - }, { - key: 'deepPress', - value: function deepPress(event) { - event.pressure >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); - } }]); return AdapterPointer; @@ -486,7 +488,7 @@ var Config = { polyfillSpeedUp: 1000, // milliseconds it takes to go from 1 to 0 for the polyfill - polyfillSpeedDown: 0, + polyfillSpeedDown: 1000, // 'true' prevents the selecting of text and images via css properties preventSelect: true, diff --git a/dist/pressure.min.js b/dist/pressure.min.js index 9a718ef..29ea9b0 100644 --- a/dist/pressure.min.js +++ b/dist/pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Pressure=t()}(this,function(){"use strict";function e(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 t(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 s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):this.loopPolyfillForceDown(e,t))}},{key:"loopPolyfillForceDown",value:function(e,t){this.isPressed()===!1&&this.nativeSupport===!1&&e>0&&(e=e-this.decrement<0?0:e-this.increment,this.runClosure("change",e,t),e>=.5?this._startDeepPress(t):this._endDeepPress(),setTimeout(this.loopPolyfillForceDown.bind(this,e,t),10))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),o}(u),c=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){this.add("pointerdown",this.supportTest.bind(this,0)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e))}},{key:"deepPress",value:function(e){e.pressure>=.5?this._startDeepPress(e):this._endDeepPress()}}]),o}(u),a={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,this.runClosure("change",e,t),this.deepPress(e,t),0===e?(this.runningPolyfill=!1,this._endPress()):setTimeout(this.loopPolyfillForce.bind(this,e,t),10)))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown: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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); } runPolyfill(event){ @@ -102,23 +109,23 @@ class Adapter{ loopPolyfillForce(force, event){ if(this.nativeSupport === false){ if(this.isPressed()) { - this.runClosure('change', force, event); - force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + this.runningPolyfill = true; force = force + this.increment > 1 ? 1 : force + this.increment; + this.runClosure('change', force, event); + this.deepPress(force, event); setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); } else { - this.loopPolyfillForceDown(force, event); + force = force - this.decrement < 0 ? 0 : force - this.decrement; + this.runClosure('change', force, event); + this.deepPress(force, event); + if(force === 0){ + this.runningPolyfill = false; + this._endPress(); + } else { + setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); + } } } } - loopPolyfillForceDown(force, event){ - if(this.isPressed() === false && this.nativeSupport === false && force > 0){ - force = force - this.decrement < 0 ? 0 : force - this.increment; - this.runClosure('change', force, event); - force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); - setTimeout(this.loopPolyfillForceDown.bind(this, force, event), 10); - } - } - } diff --git a/src/adapters/adapter_3d_touch.js b/src/adapters/adapter_3d_touch.js index 85e715a..6366a9a 100644 --- a/src/adapters/adapter_3d_touch.js +++ b/src/adapters/adapter_3d_touch.js @@ -84,7 +84,7 @@ class Adapter3DTouch extends Adapter{ // return the touch and run a start or end for deep press returnTouch(touch, event){ - touch.force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); + this.deepPress(touch.force, event); return touch; } diff --git a/src/adapters/adapter_pointer.js b/src/adapters/adapter_pointer.js index 4348296..d311349 100644 --- a/src/adapters/adapter_pointer.js +++ b/src/adapters/adapter_pointer.js @@ -34,12 +34,8 @@ class AdapterPointer extends Adapter{ change(event){ if(this.isPressed() && event.pressure > 0 && event.pressure !== 0.5){ this._changePress(event.pressure, event); - this.deepPress(event); + this.deepPress(event.pressure, event); } } - deepPress(event){ - event.pressure >= 0.5 ? this._startDeepPress(event) : this._endDeepPress(); - } - } diff --git a/src/config.js b/src/config.js index 0900ace..6c27641 100644 --- a/src/config.js +++ b/src/config.js @@ -8,7 +8,7 @@ var Config = { polyfillSpeedUp: 1000, // milliseconds it takes to go from 1 to 0 for the polyfill - polyfillSpeedDown: 0, + polyfillSpeedDown: 1000, // 'true' prevents the selecting of text and images via css properties preventSelect: true, From 09402e0d916197dceaf31585d3b50ed702d9aea7 Mon Sep 17 00:00:00 2001 From: Stuart Yamartino Date: Sat, 25 Feb 2017 23:30:24 -0500 Subject: [PATCH 07/13] Pressure polyfill up and down working flawlessly :smile: --- dist/jquery.pressure.js | 13 +++++++++++-- dist/jquery.pressure.min.js | 2 +- dist/pressure.js | 13 +++++++++++-- dist/pressure.min.js | 2 +- src/adapters/adapter.js | 11 ++++++++++- src/config.js | 2 +- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/dist/jquery.pressure.js b/dist/jquery.pressure.js index d7e3458..ba856d2 100644 --- a/dist/jquery.pressure.js +++ b/dist/jquery.pressure.js @@ -201,6 +201,8 @@ var Adapter = function () { } this.runKey = Math.random(); this.nativeSupport = false; + } else { + this.setPressed(false); } } }, { @@ -215,7 +217,9 @@ var Adapter = function () { this.decrement = Config.get('polyfillSpeedDown', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedDown', this.options); this.setPressed(true); this.runClosure('start', event); - this.loopPolyfillForce(0, event); + if (this.runningPolyfill === false) { + this.loopPolyfillForce(0, event); + } } }, { key: 'loopPolyfillForce', @@ -231,8 +235,13 @@ var Adapter = function () { force = force - this.decrement < 0 ? 0 : force - this.decrement; this.runClosure('change', force, event); this.deepPress(force, event); + if (force < 0.5 && this.isDeepPressed()) { + this.setDeepPressed(false); + this.runClosure('endDeepPress'); + } if (force === 0) { this.runningPolyfill = false; + this.setPressed(true); this._endPress(); } else { setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); @@ -483,7 +492,7 @@ var Config = { polyfillSpeedUp: 1000, // milliseconds it takes to go from 1 to 0 for the polyfill - polyfillSpeedDown: 1000, + polyfillSpeedDown: 0, // 'true' prevents the selecting of text and images via css properties preventSelect: true, diff --git a/dist/jquery.pressure.min.js b/dist/jquery.pressure.min.js index e11f854..0dde94e 100644 --- a/dist/jquery.pressure.min.js +++ b/dist/jquery.pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(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 s(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 n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,this.runClosure("change",e,t),this.deepPress(e,t),0===e?(this.runningPolyfill=!1,this._endPress()):setTimeout(this.loopPolyfillForce.bind(this,e,t),10)))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),i}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown: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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,this.runClosure("change",e,t),this.deepPress(e,t),e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):setTimeout(this.loopPolyfillForce.bind(this,e,t),10)))}}]),e}(),h=function(e){function n(e,s,r){return i(this,n),t(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,s,r))}return s(n,e),r(n,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),n}(u),l=function(e){function n(e,s,r){return i(this,n),t(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,s,r))}return s(n,e),r(n,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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,i){i!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,i),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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),n}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var i=document.querySelectorAll(e),n=0;n=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,this.runClosure("change",e,t),this.deepPress(e,t),0===e?(this.runningPolyfill=!1,this._endPress()):setTimeout(this.loopPolyfillForce.bind(this,e,t),10)))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown: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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,this.runClosure("change",e,t),this.deepPress(e,t),e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):setTimeout(this.loopPolyfillForce.bind(this,e,t),10)))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i Date: Sun, 26 Feb 2017 11:40:37 -0500 Subject: [PATCH 08/13] End before giving a change force of 0 on polyfill --- dist/jquery.pressure.js | 4 ++-- dist/jquery.pressure.min.js | 2 +- dist/pressure.js | 4 ++-- dist/pressure.min.js | 2 +- src/adapters/adapter.js | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/jquery.pressure.js b/dist/jquery.pressure.js index ba856d2..882d349 100644 --- a/dist/jquery.pressure.js +++ b/dist/jquery.pressure.js @@ -233,8 +233,6 @@ var Adapter = function () { setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); } else { force = force - this.decrement < 0 ? 0 : force - this.decrement; - this.runClosure('change', force, event); - this.deepPress(force, event); if (force < 0.5 && this.isDeepPressed()) { this.setDeepPressed(false); this.runClosure('endDeepPress'); @@ -244,6 +242,8 @@ var Adapter = function () { this.setPressed(true); this._endPress(); } else { + this.runClosure('change', force, event); + this.deepPress(force, event); setTimeout(this.loopPolyfillForce.bind(this, force, event), 10); } } diff --git a/dist/jquery.pressure.min.js b/dist/jquery.pressure.min.js index 0dde94e..12078e6 100644 --- a/dist/jquery.pressure.min.js +++ b/dist/jquery.pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(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 s(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 n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,this.runClosure("change",e,t),this.deepPress(e,t),e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):setTimeout(this.loopPolyfillForce.bind(this,e,t),10)))}}]),e}(),h=function(e){function n(e,s,r){return i(this,n),t(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,s,r))}return s(n,e),r(n,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),n}(u),l=function(e){function n(e,s,r){return i(this,n),t(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,s,r))}return s(n,e),r(n,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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,i){i!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,i),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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),n}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var i=document.querySelectorAll(e),n=0;n=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(e){function n(e,s,r){return i(this,n),t(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,s,r))}return s(n,e),r(n,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),n}(u),l=function(e){function n(e,s,r){return i(this,n),t(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,s,r))}return s(n,e),r(n,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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,i){i!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,i),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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),n}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var i=document.querySelectorAll(e),n=0;n=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,this.runClosure("change",e,t),this.deepPress(e,t),e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):setTimeout(this.loopPolyfillForce.bind(this,e,t),10)))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i Date: Sun, 26 Feb 2017 12:15:52 -0500 Subject: [PATCH 09/13] Don't need to iterate on pointer pressure events --- dist/jquery.pressure.js | 24 +++++++++--------------- dist/jquery.pressure.min.js | 2 +- dist/pressure.js | 24 +++++++++--------------- dist/pressure.min.js | 2 +- src/adapters/adapter.js | 1 + src/adapters/adapter_pointer.js | 17 ++++++----------- src/config.js | 2 +- 7 files changed, 28 insertions(+), 44 deletions(-) diff --git a/dist/jquery.pressure.js b/dist/jquery.pressure.js index 882d349..31b32a8 100644 --- a/dist/jquery.pressure.js +++ b/dist/jquery.pressure.js @@ -164,6 +164,7 @@ var Adapter = function () { key: '_startPress', value: function _startPress(event) { if (this.isPressed() === false) { + this.runningPolyfill = false; this.setPressed(true); this.runClosure('start', event); } @@ -443,27 +444,20 @@ var AdapterPointer = function (_Adapter3) { _createClass(AdapterPointer, [{ key: 'bindEvents', value: function bindEvents() { - this.add('pointerdown', this.supportTest.bind(this, 0)); + this.add('pointerdown', this.support.bind(this)); this.add('pointermove', this.change.bind(this)); this.add('pointerup', this._endPress.bind(this)); this.add('pointerleave', this._endPress.bind(this)); } }, { - key: 'supportTest', - value: function supportTest(iter, event) { - var runKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.runKey; - + key: 'support', + value: function support(event) { if (this.isPressed() === false) { - if (iter <= 6) { - iter++; - if (event.pressure === 0 || event.pressure === 0.5) { - setTimeout(this.supportTest.bind(this, iter, event, runKey), 10); - } else { - this._startPress(event); - this._changePress(event.pressure, event); - } + if (event.pressure === 0 || event.pressure === 0.5) { + this.fail(event, this.runKey); } else { - this.fail(event, runKey); + this._startPress(event); + this._changePress(event.pressure, event); } } } @@ -492,7 +486,7 @@ var Config = { polyfillSpeedUp: 1000, // milliseconds it takes to go from 1 to 0 for the polyfill - polyfillSpeedDown: 0, + polyfillSpeedDown: 5000, // 'true' prevents the selecting of text and images via css properties preventSelect: true, diff --git a/dist/jquery.pressure.min.js b/dist/jquery.pressure.min.js index 12078e6..b3ec5cd 100644 --- a/dist/jquery.pressure.min.js +++ b/dist/jquery.pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(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 s(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 n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(e){function n(e,s,r){return i(this,n),t(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,s,r))}return s(n,e),r(n,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),n}(u),l=function(e){function n(e,s,r){return i(this,n),t(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,s,r))}return s(n,e),r(n,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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,i){i!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,i),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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),n}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var i=document.querySelectorAll(e),n=0;n=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),i}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:5e3,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i 2 && arguments[2] !== undefined ? arguments[2] : this.runKey; - + key: 'support', + value: function support(event) { if (this.isPressed() === false) { - if (iter <= 6) { - iter++; - if (event.pressure === 0 || event.pressure === 0.5) { - setTimeout(this.supportTest.bind(this, iter, event, runKey), 10); - } else { - this._startPress(event); - this._changePress(event.pressure, event); - } + if (event.pressure === 0 || event.pressure === 0.5) { + this.fail(event, this.runKey); } else { - this.fail(event, runKey); + this._startPress(event); + this._changePress(event.pressure, event); } } } @@ -497,7 +491,7 @@ var Config = { polyfillSpeedUp: 1000, // milliseconds it takes to go from 1 to 0 for the polyfill - polyfillSpeedDown: 0, + polyfillSpeedDown: 5000, // 'true' prevents the selecting of text and images via css properties preventSelect: true, diff --git a/dist/pressure.min.js b/dist/pressure.min.js index 9b4f6bf..a30b281 100644 --- a/dist/pressure.min.js +++ b/dist/pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Pressure=t()}(this,function(){"use strict";function e(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 t(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 s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,0===t.pressure||.5===t.pressure?setTimeout(this.supportTest.bind(this,e,t,s),10):(this._startPress(t),this._changePress(t.pressure,t))):this.fail(t,s))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:5e3,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i Date: Sun, 26 Feb 2017 12:59:46 -0500 Subject: [PATCH 10/13] Version bump to v2.1.0 --- bower.json | 2 +- dist/jquery.pressure.js | 21 ++++++++++----------- dist/jquery.pressure.min.js | 4 ++-- dist/pressure.js | 21 ++++++++++----------- dist/pressure.min.js | 4 ++-- gulpfile.js | 2 +- package.json | 2 +- src/adapters/adapter_3d_touch.js | 12 ++++++------ src/helpers.js | 1 - 9 files changed, 33 insertions(+), 36 deletions(-) diff --git a/bower.json b/bower.json index 4f2944e..c408006 100644 --- a/bower.json +++ b/bower.json @@ -33,5 +33,5 @@ "test", "tests" ], - "version": "2.0.3" + "version": "2.1.0" } diff --git a/dist/jquery.pressure.js b/dist/jquery.pressure.js index 31b32a8..a88375f 100644 --- a/dist/jquery.pressure.js +++ b/dist/jquery.pressure.js @@ -1,4 +1,4 @@ -// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 +// Pressure v2.1.0 | Created By Stuart Yamartino | MIT License | 2015 - 2017 ;(function(root, factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory); @@ -332,10 +332,10 @@ var Adapter3DTouch = function (_Adapter2) { value: function bindEvents() { if (supportsTouchForceChange) { this.add('touchforcechange', this.start.bind(this)); - this.add('touchstart', this.supportTest.bind(this, 0)); + this.add('touchstart', this.support.bind(this, 0)); this.add('touchend', this._endPress.bind(this)); } else { - this.add('touchstart', this.startLegacyTest.bind(this)); + this.add('touchstart', this.startLegacy.bind(this)); this.add('touchend', this._endPress.bind(this)); } } @@ -351,22 +351,22 @@ var Adapter3DTouch = function (_Adapter2) { } } }, { - key: 'supportTest', - value: function supportTest(iter, event) { + key: 'support', + value: function support(iter, event) { var runKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.runKey; if (this.isPressed() === false) { if (iter <= 6) { iter++; - setTimeout(this.supportTest.bind(this, iter, event, runKey), 10); + setTimeout(this.support.bind(this, iter, event, runKey), 10); } else { this.fail(event, runKey); } } } }, { - key: 'startLegacyTest', - value: function startLegacyTest(event) { + key: 'startLegacy', + value: function startLegacy(event) { this.initialForce = event.touches[0].force; this.supportLegacyTest(0, event, this.runKey, this.initialForce); } @@ -376,8 +376,8 @@ var Adapter3DTouch = function (_Adapter2) { // more info from this issue https://github.com/yamartino/pressure/issues/15 }, { - key: 'supportLegacyTest', - value: function supportLegacyTest(iter, event, runKey, force) { + key: 'supportLegacy', + value: function supportLegacy(iter, event, runKey, force) { if (force !== this.initialForce) { this._startPress(event); this.loopForce(event); @@ -549,7 +549,6 @@ var supportsMouse = false; var supportsTouch = false; var supportsPointer = false; var supportsTouchForceChange = false; - if (typeof window !== 'undefined') { // only attempt to assign these in a browser environment. // on the server, this is a no-op, like the rest of the library diff --git a/dist/jquery.pressure.min.js b/dist/jquery.pressure.min.js index b3ec5cd..3e9df9c 100644 --- a/dist/jquery.pressure.min.js +++ b/dist/jquery.pressure.min.js @@ -1,2 +1,2 @@ -// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(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 s(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 n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),i}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:5e3,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),i}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:5e3,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i 2 && arguments[2] !== undefined ? arguments[2] : this.runKey; if (this.isPressed() === false) { if (iter <= 6) { iter++; - setTimeout(this.supportTest.bind(this, iter, event, runKey), 10); + setTimeout(this.support.bind(this, iter, event, runKey), 10); } else { this.fail(event, runKey); } } } }, { - key: 'startLegacyTest', - value: function startLegacyTest(event) { + key: 'startLegacy', + value: function startLegacy(event) { this.initialForce = event.touches[0].force; this.supportLegacyTest(0, event, this.runKey, this.initialForce); } @@ -381,8 +381,8 @@ var Adapter3DTouch = function (_Adapter2) { // more info from this issue https://github.com/yamartino/pressure/issues/15 }, { - key: 'supportLegacyTest', - value: function supportLegacyTest(iter, event, runKey, force) { + key: 'supportLegacy', + value: function supportLegacy(iter, event, runKey, force) { if (force !== this.initialForce) { this._startPress(event); this.loopForce(event); @@ -554,7 +554,6 @@ var supportsMouse = false; var supportsTouch = false; var supportsPointer = false; var supportsTouchForceChange = false; - if (typeof window !== 'undefined') { // only attempt to assign these in a browser environment. // on the server, this is a no-op, like the rest of the library diff --git a/dist/pressure.min.js b/dist/pressure.min.js index a30b281..ed5853f 100644 --- a/dist/pressure.min.js +++ b/dist/pressure.min.js @@ -1,2 +1,2 @@ -// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Pressure=t()}(this,function(){"use strict";function e(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 t(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 s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(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.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(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)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:5e3,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:5e3,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i Date: Sun, 26 Feb 2017 13:10:09 -0500 Subject: [PATCH 11/13] Update readme --- README.md | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5d6f4af..393acf3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 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://pressurejs.com/documentation.html) for installation instructions and more details on pressure.js. +Head over to the [documentation](http://pressurejs.com/documentation.html) for installation instructions, supported devices, and more details on pressure.js. ## Install Download pressure.min.js or pressure.js files from GitHub or install with npm or bower @@ -101,7 +101,7 @@ $('#element').pressure({ With Pressure, the third paramater is an optional object of options that can be passed in. ###Polyfill Support -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. +Using the "polyfill" keyword, you can disable polyfill support for the element. The polyfill is enabled by default and is useful if the device or browser does not support pressure, 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 pressure and see for yourself how it works. ```javascript Pressure.set('#example', { change: function(force, event){ @@ -113,34 +113,54 @@ Pressure.set('#example', { }, {polyfill: false}); ``` -###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). +###Polyfill Speed Up +If you are using the polyfill (on by default), you can see the "polyfillSpeedUp" 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 Pressure.set('#example', { change: function(force, event){ this.innerHTML = force; } -}, {polyfillSpeed: 5000}); +}, {polyfillSpeedUp: 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 on devices that do not support pressure ``` -### Only run on Force Touch trackpads (Desktop) -Set the option only to the type you want it to run on 'desktop' or 'mobile' +###Polyfill Speed Down +If you are using the polyfill (on by default), you can see the "polyfillSpeedDown" speed to determine how fast the polyfill takes to go from 1 to 0 when you let go. The value is an integer in milliseconds and the default is 0 (aka off). +```javascript +Pressure.set('#example', { + change: function(force, event){ + this.innerHTML = force; + } +}, {polyfillSpeedDown: 2000}); +// takes 2 seconds to go from a force value of 1 to 0 +// only on devices that do not support pressure +``` + +### Only run on Force Touch trackpads (mouse) +Set the option only to the type you want it to run on 'mouse', 'touch', or 'pointer'. The names are the types of events that pressure will respond to. +```javascript +Pressure.set('#example',{ + change: function(force, event){ + console.log(force); + }, +}, {only: 'mouse'}); +``` +### Only run on 3D Touch (touch) ```javascript Pressure.set('#example',{ change: function(force, event){ console.log(force); }, -}, {only: 'desktop'}); +}, {only: 'touch'}); ``` -### Only run on 3D Touch (Mobile) +### Only run on Pointer Supported Devices (pointer) ```javascript Pressure.set('#example',{ change: function(force, event){ console.log(force); }, -}, {only: 'mobile'}); +}, {only: 'pointer'}); ``` ### Change the preventSelect option @@ -165,7 +185,8 @@ You can use ```Pressure.config()``` to set default configurations for site wide // These are the default configs set by Pressure Pressure.config({ polyfill: true, - polyfillSpeed: 1000, + polyfillSpeedUp: 1000, + polyfillSpeedDown: 0, preventDefault: true, only: null }); From 21cfb4c21963c56cc4c2a815c2d038ac0b05074a Mon Sep 17 00:00:00 2001 From: Stuart Yamartino Date: Sun, 26 Feb 2017 13:20:48 -0500 Subject: [PATCH 12/13] Wrong config --- dist/jquery.pressure.js | 2 +- dist/jquery.pressure.min.js | 2 +- dist/pressure.js | 2 +- dist/pressure.min.js | 2 +- src/config.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/jquery.pressure.js b/dist/jquery.pressure.js index a88375f..45738c2 100644 --- a/dist/jquery.pressure.js +++ b/dist/jquery.pressure.js @@ -486,7 +486,7 @@ var Config = { polyfillSpeedUp: 1000, // milliseconds it takes to go from 1 to 0 for the polyfill - polyfillSpeedDown: 5000, + polyfillSpeedDown: 0, // 'true' prevents the selecting of text and images via css properties preventSelect: true, diff --git a/dist/jquery.pressure.min.js b/dist/jquery.pressure.min.js index 3e9df9c..af1dab4 100644 --- a/dist/jquery.pressure.min.js +++ b/dist/jquery.pressure.min.js @@ -1,2 +1,2 @@ // Pressure v2.1.0 | Created By Stuart Yamartino | MIT License | 2015 - 2017 -!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(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 s(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 n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),i}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:5e3,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),i}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:5e3,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{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._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(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._changePress(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;t0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,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])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i Date: Sun, 26 Feb 2017 13:22:19 -0500 Subject: [PATCH 13/13] Update speed down example --- examples/example.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example.js b/examples/example.js index ee03bd7..c1c894f 100644 --- a/examples/example.js +++ b/examples/example.js @@ -41,7 +41,7 @@ var block = { } Pressure.set(document.querySelectorAll('#el1'), block); -Pressure.set($('#el2'), block, {only: 'mouse', polyfill: true, polyfillSpeedUp: 5000}); +Pressure.set($('#el2'), block, {only: 'mouse', polyfill: true, polyfillSpeedUp: 5000, polyfillSpeedDown: 2000}); Pressure.set('#el3', block, {only: 'touch'}); $('#el1-jquery').pressure(block);