@@ -4,12 +4,16 @@ angular.module('angular-ui-scribble',[])
4
4
scope :{ } ,
5
5
template :
6
6
`<div class="scribble">
7
- <div class="scribble-canvas">
8
- <canvas height="300" width="600"></canvas>
7
+ <ul class="scribble-actions">
8
+ <li><button ng-click="clearSignature()">Clear</button></li>
9
+ <li ng-if='mode!="erase"'><button ng-click="setMode('erase')">Erase</button></li>
10
+ <li ng-if='mode=="erase"'><button ng-click="setMode('pen')">Pen</button></li>
11
+ <li><input id="selectBackground" type="file" accept="image/*" capture="camera"></lis>
12
+ </ul>
13
+ <div class="scribble-canvas" height="200" width="350">
14
+ <canvas height="200" width="380" style="z-index:2;"></canvas>
15
+ <canvas id="scribble-background" height="200" width="380" style="z-index:1;"></canvas>
9
16
</div>
10
- <button ng-click="clearSignature()">Clear</button>
11
- <button ng-click="setMode('erase')">Erase</button>
12
- <button ng-click="setMode('pen')">Pen</button>
13
17
</div>` ,
14
18
controller : function ( $scope , $element ) {
15
19
$scope . mode = 'pen' ;
@@ -18,6 +22,8 @@ angular.module('angular-ui-scribble',[])
18
22
var ctx = canvas . getContext ( '2d' ) ;
19
23
signaturePad = new SignaturePad ( canvas ) ;
20
24
25
+ $scope . isMobile = true ;
26
+
21
27
$scope . clearSignature = function ( ) {
22
28
signaturePad . clear ( ) ;
23
29
} ;
@@ -42,6 +48,37 @@ angular.module('angular-ui-scribble',[])
42
48
signaturePad . maxWidth = $scope . oldStroke . maxWidth ;
43
49
}
44
50
} ) ;
51
+
52
+ // Background {{{
53
+
54
+ var selectBackground = document . getElementById ( 'selectBackground' ) ;
55
+ var reader ;
56
+
57
+ selectBackground . addEventListener ( 'change' , function ( e ) {
58
+ var backgroundSrc = selectBackground . files [ 0 ] ;
59
+ reader = new FileReader ( ) ;
60
+
61
+ reader . onload = function ( event ) {
62
+ loadBackground ( event . target . result ) ;
63
+ } ;
64
+
65
+ reader . readAsDataURL ( backgroundSrc ) ;
66
+ } ) ;
67
+
68
+ function loadBackground ( dataUrl ) {
69
+ var background = document . getElementById ( 'scribble-background' ) ;
70
+ var backgroundCtx = background . getContext ( '2d' ) ;
71
+ var image = new Image ( ) ;
72
+ var ratio = window . devicePixelRatio || 1 ;
73
+ var width = background . width ;
74
+ var height = background . height ;
75
+
76
+ image . src = dataUrl ;
77
+ image . onload = function ( ) {
78
+ backgroundCtx . drawImage ( image , 0 , 0 , width , height ) ;
79
+ } ;
80
+ }
81
+ // }}}
45
82
}
46
83
}
47
84
} ) ;
0 commit comments