Skip to content

Commit d6191a3

Browse files
authored
Merge pull request rpmsoftware#13 from rpmsoftware/issue-11-update-signature-pad-2-1-0
Update signaturePad.js to v2.1.0
2 parents 39d31c6 + cee279e commit d6191a3

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

injectedJavaScript/signaturePad.js

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Signature Pad v1.6.0-beta.9
2+
* Signature Pad v2.1.0
33
* https://github.com/szimek/signature_pad
44
*
55
* Copyright 2017 Szymon Nowak
@@ -73,13 +73,56 @@ Bezier.prototype._point = function (t, start, c1, c2, end) {
7373
return start * (1.0 - t) * (1.0 - t) * (1.0 - t) + 3.0 * c1 * (1.0 - t) * (1.0 - t) * t + 3.0 * c2 * (1.0 - t) * t * t + end * t * t * t;
7474
};
7575
76+
/* eslint-disable */
77+
78+
/* http://stackoverflow.com/a/27078401/815507 */
79+
function throttle(func, wait, options) {
80+
var context, args, result;
81+
var timeout = null;
82+
var previous = 0;
83+
if (!options) options = {};
84+
var later = function later() {
85+
previous = options.leading === false ? 0 : Date.now();
86+
timeout = null;
87+
result = func.apply(context, args);
88+
if (!timeout) context = args = null;
89+
};
90+
return function () {
91+
var now = Date.now();
92+
if (!previous && options.leading === false) previous = now;
93+
var remaining = wait - (now - previous);
94+
context = this;
95+
args = arguments;
96+
if (remaining <= 0 || remaining > wait) {
97+
if (timeout) {
98+
clearTimeout(timeout);
99+
timeout = null;
100+
}
101+
previous = now;
102+
result = func.apply(context, args);
103+
if (!timeout) context = args = null;
104+
} else if (!timeout && options.trailing !== false) {
105+
timeout = setTimeout(later, remaining);
106+
}
107+
return result;
108+
};
109+
}
110+
76111
function SignaturePad(canvas, options) {
77112
var self = this;
78113
var opts = options || {};
79114
80115
this.velocityFilterWeight = opts.velocityFilterWeight || 0.7;
81116
this.minWidth = opts.minWidth || 0.5;
82117
this.maxWidth = opts.maxWidth || 2.5;
118+
this.throttle = opts.throttle || 16; /* in milliseconds */
119+
120+
if (this.throttle) {
121+
this._strokeMoveUpdate = throttle(SignaturePad.prototype._strokeUpdate, this.throttle);
122+
} else {
123+
this._strokeMoveUpdate = SignaturePad.prototype._strokeUpdate;
124+
}
125+
83126
this.dotSize = opts.dotSize || function () {
84127
return (this.minWidth + this.maxWidth) / 2;
85128
};
@@ -103,7 +146,7 @@ function SignaturePad(canvas, options) {
103146
104147
this._handleMouseMove = function (event) {
105148
if (self._mouseButtonDown) {
106-
self._strokeUpdate(event);
149+
self._strokeMoveUpdate(event);
107150
}
108151
};
109152
@@ -126,7 +169,7 @@ function SignaturePad(canvas, options) {
126169
event.preventDefault();
127170
128171
var touch = event.targetTouches[0];
129-
self._strokeUpdate(touch);
172+
self._strokeMoveUpdate(touch);
130173
};
131174
132175
this._handleTouchEnd = function (event) {

0 commit comments

Comments
 (0)