Skip to content

Commit

Permalink
Release 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
szimek committed Jun 4, 2015
1 parent bdd38e2 commit 4cd5a24
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 58 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ file_put_contents( "signature.png",$decoded_image);
```

## Changelog
### 1.4.0
* Add `off` method that unbinds all event handlers. [Rob-ot](https://github.com/Rob-ot)

### 1.3.6
* Fix support for Browserify. [chevett](https://github.com/chevett)

Expand Down
94 changes: 57 additions & 37 deletions example/js/signature_pad.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}(this, function () {

/*!
* Signature Pad v1.3.5
* Signature Pad v1.4.0
* https://github.com/szimek/signature_pad
*
* Copyright 2015 Szymon Nowak
Expand Down Expand Up @@ -53,6 +53,48 @@ var SignaturePad = (function (document) {
this._ctx = canvas.getContext("2d");
this.clear();

// we need add these inline so they are available to unbind while still having
// access to 'self' we could use _.bind but it's not worth adding a dependency
this._handleMouseDown = function (event) {
if (event.which === 1) {
self._mouseButtonDown = true;
self._strokeBegin(event);
}
};

this._handleMouseMove = function (event) {
if (self._mouseButtonDown) {
self._strokeUpdate(event);
}
};

this._handleMouseUp = function (event) {
if (event.which === 1 && self._mouseButtonDown) {
self._mouseButtonDown = false;
self._strokeEnd(event);
}
};

this._handleTouchStart = function (event) {
var touch = event.changedTouches[0];
self._strokeBegin(touch);
};

this._handleTouchMove = function (event) {
// Prevent scrolling.
event.preventDefault();

var touch = event.changedTouches[0];
self._strokeUpdate(touch);
};

this._handleTouchEnd = function (event) {
var wasCanvasTouched = event.target === self._canvas;
if (wasCanvasTouched) {
self._strokeEnd(event);
}
};

this._handleMouseEvents();
this._handleTouchEvents();
};
Expand Down Expand Up @@ -126,25 +168,9 @@ var SignaturePad = (function (document) {
var self = this;
this._mouseButtonDown = false;

this._canvas.addEventListener("mousedown", function (event) {
if (event.which === 1) {
self._mouseButtonDown = true;
self._strokeBegin(event);
}
});

this._canvas.addEventListener("mousemove", function (event) {
if (self._mouseButtonDown) {
self._strokeUpdate(event);
}
});

document.addEventListener("mouseup", function (event) {
if (event.which === 1 && self._mouseButtonDown) {
self._mouseButtonDown = false;
self._strokeEnd(event);
}
});
this._canvas.addEventListener("mousedown", this._handleMouseDown);
this._canvas.addEventListener("mousemove", this._handleMouseMove);
document.addEventListener("mouseup", this._handleMouseUp);
};

SignaturePad.prototype._handleTouchEvents = function () {
Expand All @@ -153,25 +179,19 @@ var SignaturePad = (function (document) {
// Pass touch events to canvas element on mobile IE.
this._canvas.style.msTouchAction = 'none';

this._canvas.addEventListener("touchstart", function (event) {
var touch = event.changedTouches[0];
self._strokeBegin(touch);
});

this._canvas.addEventListener("touchmove", function (event) {
// Prevent scrolling.
event.preventDefault();
this._canvas.addEventListener("touchstart", this._handleTouchStart);
this._canvas.addEventListener("touchmove", this._handleTouchMove);
document.addEventListener("touchend", this._handleTouchEnd);
};

var touch = event.changedTouches[0];
self._strokeUpdate(touch);
});
SignaturePad.prototype.off = function () {
this._canvas.removeEventListener("mousedown", this._handleMouseDown);
this._canvas.removeEventListener("mousemove", this._handleMouseMove);
document.removeEventListener("mouseup", this._handleMouseUp);

document.addEventListener("touchend", function (event) {
var wasCanvasTouched = event.target === self._canvas;
if (wasCanvasTouched) {
self._strokeEnd(event);
}
});
this._canvas.removeEventListener("touchstart", this._handleTouchStart);
this._canvas.removeEventListener("touchmove", this._handleTouchMove);
document.removeEventListener("touchend", this._handleTouchEnd);
};

SignaturePad.prototype.isEmpty = function () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "signature_pad",
"description": "Library for drawing smooth signatures.",
"version": "1.3.6",
"version": "1.4.0",
"homepage": "https://github.com/szimek/signature_pad",
"author": {
"name": "Szymon Nowak",
Expand Down
34 changes: 17 additions & 17 deletions signature_pad.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
}
}(this, function () {

/*!
* Signature Pad v1.3.6
* https://github.com/szimek/signature_pad
*
* Copyright 2015 Szymon Nowak
* Released under the MIT license
*
* The main idea and some parts of the code (e.g. drawing variable width Bézier curve) are taken from:
* http://corner.squareup.com/2012/07/smoother-signatures.html
*
* Implementation of interpolation using cubic Bézier curves is taken from:
* http://benknowscode.wordpress.com/2012/09/14/path-interpolation-using-cubic-bezier-and-control-point-estimation-in-javascript
*
* Algorithm for approximated length of a Bézier curve is taken from:
* http://www.lemoda.net/maths/bezier-length/index.html
*
*/
/*!
* Signature Pad v1.4.0
* https://github.com/szimek/signature_pad
*
* Copyright 2015 Szymon Nowak
* Released under the MIT license
*
* The main idea and some parts of the code (e.g. drawing variable width Bézier curve) are taken from:
* http://corner.squareup.com/2012/07/smoother-signatures.html
*
* Implementation of interpolation using cubic Bézier curves is taken from:
* http://benknowscode.wordpress.com/2012/09/14/path-interpolation-using-cubic-bezier-and-control-point-estimation-in-javascript
*
* Algorithm for approximated length of a Bézier curve is taken from:
* http://www.lemoda.net/maths/bezier-length/index.html
*
*/
var SignaturePad = (function (document) {
"use strict";

Expand Down
6 changes: 3 additions & 3 deletions signature_pad.min.js

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

0 comments on commit 4cd5a24

Please sign in to comment.