Skip to content
This repository has been archived by the owner on Nov 18, 2019. It is now read-only.

Add mouseleave event binding #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ angular.module('signature').directive('signaturePad', ['$interval', '$timeout',
return {
restrict: 'EA',
replace: true,
template: '<div class="signature" style="width: 100%; max-width:{{width}}px; height: 100%; max-height:{{height}}px;"><canvas style="display: block; margin: 0 auto;" ng-mouseup="onMouseup()" ng-mousedown="notifyDrawing({ drawing: true })"></canvas></div>',
template: '<div class="signature" style="width: 100%; max-width:{{width}}px; height: 100%; max-height:{{height}}px;"><canvas style="display: block; margin: 0 auto;" ng-mouseup="onMouseup()" ng-mouseleave="onMouseleave($event)" ng-mousedown="notifyDrawing({ drawing: true })"></canvas></div>',
scope: {
accept: '=?',
clear: '=?',
Expand All @@ -36,6 +36,17 @@ angular.module('signature').directive('signaturePad', ['$interval', '$timeout',
};

$scope.onMouseup = function () {
$scope.endDrawing();
};

$scope.onMouseleave = function (event) {
// left button depressed
if (event.buttons & 1 === 1) {
$scope.endDrawing();
}
};

$scope.endDrawing = function () {
$scope.updateModel();

// notify that drawing has ended
Expand Down Expand Up @@ -98,7 +109,7 @@ angular.module('signature').directive('signaturePad', ['$interval', '$timeout',
scope.$watch('disabled', function (val) {
val ? scope.signaturePad.off() : scope.signaturePad.on();
});

var calculateScale = function() {
var scaleWidth = Math.min(parent.clientWidth / width, 1);
var scaleHeight = Math.min(parent.clientHeight / height, 1);
Expand Down