@@ -136,49 +136,34 @@ $.widget( "ui.mask", {
136
136
return value ;
137
137
} ,
138
138
_events : function ( ) {
139
- var cancelKeypress ,
140
- lastUnsavedValue ,
141
- that = this ,
142
- elem = that . element ;
143
-
144
- function handlePaste ( ) {
145
- that . currentEvent = event ;
146
- setTimeout ( function ( ) {
147
- var position = that . _parseValue ( ) ;
148
- that . _paint ( ) ;
149
- that . _caret ( that . _seekRight ( position ) ) ;
150
- that . currentEvent = false ;
151
- } , 0 ) ;
152
- }
153
-
154
139
this . _bind ( {
155
140
focus : function ( event ) {
156
- lastUnsavedValue = elem . val ( ) ;
157
- that . _paint ( true ) ;
158
- setTimeout ( function ( ) {
159
- that . _caret ( that . _seekRight ( that . _parseValue ( ) - 1 ) ) ;
141
+ this . lastUnsavedValue = this . element . val ( ) ;
142
+ this . _paint ( true ) ;
143
+ this . _delay ( function ( ) {
144
+ this . _caret ( this . _seekRight ( this . _parseValue ( ) - 1 ) ) ;
160
145
} , 0 ) ;
161
146
} ,
162
147
blur : function ( event ) {
163
148
164
149
// because we are constantly setting the value of the input, the change event
165
150
// never fires - we re-introduce the change event here
166
- that . _parseValue ( ) ;
167
- that . _paint ( false ) ;
168
- if ( elem . val ( ) !== lastUnsavedValue ) {
169
- elem . trigger ( "change" ) ;
151
+ this . _parseValue ( ) ;
152
+ this . _paint ( false ) ;
153
+ if ( this . element . val ( ) !== this . lastUnsavedValue ) {
154
+ this . element . trigger ( "change" ) ;
170
155
}
171
156
return ;
172
157
} ,
173
158
keydown : function ( event ) {
174
159
var bufferObject ,
175
160
key = event . keyCode ,
176
- position = that . _caret ( ) ;
161
+ position = this . _caret ( ) ;
177
162
178
163
switch ( key ) {
179
164
case keyCode . ESCAPE :
180
- elem . val ( lastUnsavedValue ) ;
181
- that . _caret ( 0 , that . _parseValue ( ) ) ;
165
+ this . element . val ( this . lastUnsavedValue ) ;
166
+ this . _caret ( 0 , this . _parseValue ( ) ) ;
182
167
event . preventDefault ( ) ;
183
168
return ;
184
169
@@ -187,31 +172,31 @@ $.widget( "ui.mask", {
187
172
event . preventDefault ( ) ;
188
173
if ( position . begin === position . end ) {
189
174
position . begin = position . end = ( key === keyCode . DELETE ?
190
- that . _seekRight ( position . begin - 1 ) :
191
- that . _seekLeft ( position . begin )
175
+ this . _seekRight ( position . begin - 1 ) :
176
+ this . _seekLeft ( position . begin )
192
177
) ;
193
178
if ( position . begin < 0 ) {
194
- that . _caret ( that . _seekRight ( - 1 ) ) ;
179
+ this . _caret ( this . _seekRight ( - 1 ) ) ;
195
180
return ;
196
181
}
197
182
}
198
- that . _removeValues ( position . begin , position . end ) ;
199
- that . _paint ( ) ;
200
- that . _caret ( position . begin ) ;
183
+ this . _removeValues ( position . begin , position . end ) ;
184
+ this . _paint ( ) ;
185
+ this . _caret ( position . begin ) ;
201
186
return ;
202
187
203
188
case keyCode . RIGHT :
204
189
if ( position . begin === position . end ) {
205
- bufferObject = that . buffer [ position . begin ] ;
190
+ bufferObject = this . buffer [ position . begin ] ;
206
191
if ( bufferObject && bufferObject . length > 1 ) {
207
192
bufferObject . value = this . _validValue ( bufferObject , bufferObject . value ) ;
208
- that . _paint ( ) ;
193
+ this . _paint ( ) ;
209
194
event . preventDefault ( ) ;
210
195
}
211
- position = that . _seekRight ( bufferObject . start + bufferObject . length - 1 ) ;
212
- bufferObject = that . buffer [ position ] ;
196
+ position = this . _seekRight ( bufferObject . start + bufferObject . length - 1 ) ;
197
+ bufferObject = this . buffer [ position ] ;
213
198
if ( bufferObject && bufferObject . length > 1 ) {
214
- that . _caret ( position , position + ( bufferObject && bufferObject . length > 1 ? bufferObject . length : 0 ) ) ;
199
+ this . _caret ( position , position + ( bufferObject && bufferObject . length > 1 ? bufferObject . length : 0 ) ) ;
215
200
event . preventDefault ( ) ;
216
201
}
217
202
}
@@ -221,17 +206,17 @@ $.widget( "ui.mask", {
221
206
keypress : function ( event ) {
222
207
var tempValue ,
223
208
key = event . keyCode ,
224
- position = that . _caret ( ) ,
225
- bufferPosition = that . _seekRight ( position . begin - 1 ) ,
226
- bufferObject = that . buffer [ bufferPosition ] ;
209
+ position = this . _caret ( ) ,
210
+ bufferPosition = this . _seekRight ( position . begin - 1 ) ,
211
+ bufferObject = this . buffer [ bufferPosition ] ;
227
212
228
- that . currentEvent = event ;
213
+ this . currentEvent = event ;
229
214
// ignore keypresses with special keys, or control characters
230
215
if ( event . metaKey || event . altKey || event . ctrlKey || key < 32 ) {
231
216
return ;
232
217
}
233
218
if ( position . begin !== position . end ) {
234
- that . _removeValues ( position . begin , position . end ) ;
219
+ this . _removeValues ( position . begin , position . end ) ;
235
220
}
236
221
if ( bufferObject ) {
237
222
tempValue = String . fromCharCode ( key ) ;
@@ -242,19 +227,28 @@ $.widget( "ui.mask", {
242
227
tempValue = tempValue . substr ( 0 , bufferObject . length ) ;
243
228
}
244
229
if ( this . _validValue ( bufferObject , tempValue ) ) {
245
- that . _shiftRight ( position . begin ) ;
230
+ this . _shiftRight ( position . begin ) ;
246
231
bufferObject . value = tempValue ;
247
- that . _paint ( ) ;
248
- that . _caret ( that . _seekRight ( bufferPosition ) ) ;
232
+ this . _paint ( ) ;
233
+ this . _caret ( this . _seekRight ( bufferPosition ) ) ;
249
234
}
250
235
}
251
236
event . preventDefault ( ) ;
252
- that . currentEvent = false ;
237
+ this . currentEvent = false ;
253
238
} ,
254
- paste : handlePaste ,
255
- input : handlePaste
239
+ paste : "_paste" ,
240
+ input : "_paste"
256
241
} ) ;
257
242
} ,
243
+ _paste : function ( event ) {
244
+ this . currentEvent = event ;
245
+ this . _delay ( function ( ) {
246
+ var position = this . _parseValue ( ) ;
247
+ this . _paint ( ) ;
248
+ this . _caret ( this . _seekRight ( position ) ) ;
249
+ this . currentEvent = false ;
250
+ } , 0 ) ;
251
+ } ,
258
252
_paint : function ( focused ) {
259
253
if ( focused === undefined ) {
260
254
focused = this . element [ 0 ] === document . activeElement ;
@@ -398,7 +392,7 @@ $.widget( "ui.mask", {
398
392
bufferLength = this . buffer . length ;
399
393
400
394
for ( destPosition = begin , bufferPosition = this . _seekRight ( end - 1 ) ;
401
- destPosition < bufferLength ;
395
+ destPosition < bufferLength ;
402
396
destPosition += destObject . length ) {
403
397
destObject = this . buffer [ destPosition ] ;
404
398
bufferObject = this . buffer [ bufferPosition ] ;
0 commit comments