@@ -4,7 +4,9 @@ Sketch.js v0.0.1
4
4
Copyright 2011 Michael Bleigh and Intridea, Inc.
5
5
Released under the MIT License
6
6
7
- */ ( function ( $ ) {
7
+ */
8
+ var __slice = Array . prototype . slice ;
9
+ ( function ( $ ) {
8
10
var Sketch ;
9
11
$ . sketch = {
10
12
tools : { }
@@ -54,6 +56,9 @@ Released under the MIT License
54
56
} ) ;
55
57
}
56
58
}
59
+ Sketch . prototype . set = function ( key , value ) {
60
+ return this [ key ] = value ;
61
+ } ;
57
62
Sketch . prototype . startPainting = function ( ) {
58
63
this . painting = true ;
59
64
return this . action = {
@@ -111,7 +116,9 @@ Released under the MIT License
111
116
this . context = this . el . getContext ( '2d' ) ;
112
117
sketch = this ;
113
118
$ . each ( this . actions , function ( ) {
114
- return $ . sketch . tools [ this . tool ] . draw . call ( sketch , this ) ;
119
+ if ( this . tool ) {
120
+ return $ . sketch . tools [ this . tool ] . draw . call ( sketch , this ) ;
121
+ }
115
122
} ) ;
116
123
if ( this . painting && this . action ) {
117
124
return $ . sketch . tools [ this . action . tool ] . draw . call ( sketch , this . action ) ;
@@ -148,11 +155,28 @@ Released under the MIT License
148
155
return this . context . stroke ( ) ;
149
156
}
150
157
} ;
151
- return $ . fn . sketch = function ( opts ) {
158
+ return $ . fn . sketch = function ( ) {
159
+ var args , key , sketch ;
160
+ key = arguments [ 0 ] , args = 2 <= arguments . length ? __slice . call ( arguments , 1 ) : [ ] ;
152
161
if ( this . length > 1 ) {
153
- $ . error ( 'Sketch can only be called on one element at a time.' ) ;
162
+ $ . error ( 'Sketch.js can only be called on one element at a time.' ) ;
163
+ }
164
+ sketch = this . data ( 'sketch' ) ;
165
+ if ( typeof key === 'string' && sketch ) {
166
+ if ( sketch [ key ] ) {
167
+ return sketch [ key ] . apply ( sketch , args ) ;
168
+ } else if ( args . length === 1 ) {
169
+ return sketch . set ( key , args [ 0 ] ) ;
170
+ } else if ( args . length === 0 ) {
171
+ return sketch [ key ] ;
172
+ } else {
173
+ return $ . error ( 'Sketch.js did not recognize the given command.' ) ;
174
+ }
175
+ } else if ( sketch ) {
176
+ return sketch ;
177
+ } else {
178
+ this . data ( 'sketch' , new Sketch ( this . get ( 0 ) , key ) ) ;
179
+ return this ;
154
180
}
155
- this . data ( 'sketch' , new Sketch ( this . get ( 0 ) , opts ) ) ;
156
- return this ;
157
181
} ;
158
182
} ) ( jQuery ) ;
0 commit comments