7
7
*
8
8
*/
9
9
10
- ; ( function ( $ ) {
10
+ ; ( function ( $ ) {
11
11
12
12
$ . fn . extend ( {
13
- simulate : function ( type , options ) {
13
+ simulate : function ( type , options ) {
14
14
return this . each ( function ( ) {
15
- var opt = $ . extend ( { } , $ . simulate . defaults , options || { } ) ;
16
- new $ . simulate ( this , type , opt ) ;
15
+ var opt = $ . extend ( { } , $ . simulate . defaults , options ) ;
16
+ new $ . simulate ( this , type , opt ) ;
17
17
} ) ;
18
18
}
19
19
} ) ;
20
20
21
- $ . simulate = function ( el , type , options ) {
21
+ $ . simulate = function ( el , type , options ) {
22
22
this . target = el ;
23
23
this . options = options ;
24
24
25
- if ( / ^ d r a g $ / . test ( type ) ) {
26
- this [ type ] . apply ( this , [ this . target , options ] ) ;
25
+ if ( type === "drag" ) {
26
+ this [ type ] . apply ( this , [ this . target , options ] ) ;
27
27
} else {
28
- this . simulateEvent ( el , type , options ) ;
28
+ this . simulateEvent ( el , type , options ) ;
29
29
}
30
- }
30
+ } ;
31
31
32
- $ . extend ( $ . simulate . prototype , {
33
- simulateEvent : function ( el , type , options ) {
34
- var evt = this . createEvent ( type , options ) ;
35
- this . dispatchEvent ( el , type , evt , options ) ;
32
+ $ . extend ( $ . simulate . prototype , {
33
+ simulateEvent : function ( el , type , options ) {
34
+ var evt = this . createEvent ( type , options ) ;
35
+ this . dispatchEvent ( el , type , evt , options ) ;
36
36
return evt ;
37
37
} ,
38
- createEvent : function ( type , options ) {
39
- if ( / ^ m o u s e ( o v e r | o u t | d o w n | u p | m o v e ) | ( d b l ) ? c l i c k $ / . test ( type ) ) {
40
- return this . mouseEvent ( type , options ) ;
41
- } else if ( / ^ k e y ( u p | d o w n | p r e s s ) $ / . test ( type ) ) {
42
- return this . keyboardEvent ( type , options ) ;
38
+ createEvent : function ( type , options ) {
39
+ if ( / ^ m o u s e ( o v e r | o u t | d o w n | u p | m o v e ) | ( d b l ) ? c l i c k $ / . test ( type ) ) {
40
+ return this . mouseEvent ( type , options ) ;
41
+ } else if ( / ^ k e y ( u p | d o w n | p r e s s ) $ / . test ( type ) ) {
42
+ return this . keyboardEvent ( type , options ) ;
43
43
}
44
44
} ,
45
- mouseEvent : function ( type , options ) {
45
+ mouseEvent : function ( type , options ) {
46
46
var evt ;
47
47
var e = $ . extend ( {
48
- bubbles : true , cancelable : ( type != "mousemove" ) , view : window , detail : 0 ,
49
- screenX : 0 , screenY : 0 , clientX : 0 , clientY : 0 ,
50
- ctrlKey : false , altKey : false , shiftKey : false , metaKey : false ,
51
- button : 0 , relatedTarget : undefined
52
- } , options ) ;
48
+ bubbles : true ,
49
+ cancelable : ( type !== "mousemove" ) ,
50
+ view : window ,
51
+ detail : 0 ,
52
+ screenX : 0 ,
53
+ screenY : 0 ,
54
+ clientX : 0 ,
55
+ clientY : 0 ,
56
+ ctrlKey : false ,
57
+ altKey : false ,
58
+ shiftKey : false ,
59
+ metaKey : false ,
60
+ button : 0 ,
61
+ relatedTarget : undefined
62
+ } , options ) ;
53
63
54
- var relatedTarget = $ ( e . relatedTarget ) [ 0 ] ;
64
+ var relatedTarget = $ ( e . relatedTarget ) [ 0 ] ;
55
65
56
- if ( $ . isFunction ( document . createEvent ) ) {
57
- evt = document . createEvent ( "MouseEvents" ) ;
58
- evt . initMouseEvent ( type , e . bubbles , e . cancelable , e . view , e . detail ,
66
+ if ( $ . isFunction ( document . createEvent ) ) {
67
+ evt = document . createEvent ( "MouseEvents" ) ;
68
+ evt . initMouseEvent ( type , e . bubbles , e . cancelable , e . view , e . detail ,
59
69
e . screenX , e . screenY , e . clientX , e . clientY ,
60
70
e . ctrlKey , e . altKey , e . shiftKey , e . metaKey ,
61
- e . button , e . relatedTarget || document . body . parentNode ) ;
62
- } else if ( document . createEventObject ) {
71
+ e . button , e . relatedTarget || document . body . parentNode ) ;
72
+ } else if ( document . createEventObject ) {
63
73
evt = document . createEventObject ( ) ;
64
- $ . extend ( evt , e ) ;
74
+ $ . extend ( evt , e ) ;
65
75
evt . button = { 0 :1 , 1 :4 , 2 :2 } [ evt . button ] || evt . button ;
66
76
}
67
77
return evt ;
68
78
} ,
69
- keyboardEvent : function ( type , options ) {
79
+ keyboardEvent : function ( type , options ) {
70
80
var evt ;
71
81
72
- var e = $ . extend ( { bubbles : true , cancelable : true , view : window ,
73
- ctrlKey : false , altKey : false , shiftKey : false , metaKey : false ,
74
- keyCode : 0 , charCode : 0
75
- } , options ) ;
82
+ var e = $ . extend ( {
83
+ bubbles : true ,
84
+ cancelable : true ,
85
+ view : window ,
86
+ ctrlKey : false ,
87
+ altKey : false ,
88
+ shiftKey : false ,
89
+ metaKey : false ,
90
+ keyCode : 0 ,
91
+ charCode : 0
92
+ } , options ) ;
76
93
77
- if ( $ . isFunction ( document . createEvent ) ) {
94
+ if ( $ . isFunction ( document . createEvent ) ) {
78
95
try {
79
- evt = document . createEvent ( "KeyEvents" ) ;
80
- evt . initKeyEvent ( type , e . bubbles , e . cancelable , e . view ,
96
+ evt = document . createEvent ( "KeyEvents" ) ;
97
+ evt . initKeyEvent ( type , e . bubbles , e . cancelable , e . view ,
81
98
e . ctrlKey , e . altKey , e . shiftKey , e . metaKey ,
82
- e . keyCode , e . charCode ) ;
83
- } catch ( err ) {
84
- evt = document . createEvent ( "Events" ) ;
85
- evt . initEvent ( type , e . bubbles , e . cancelable ) ;
86
- $ . extend ( evt , { view : e . view ,
87
- ctrlKey : e . ctrlKey , altKey : e . altKey , shiftKey : e . shiftKey , metaKey : e . metaKey ,
88
- keyCode : e . keyCode , charCode : e . charCode
99
+ e . keyCode , e . charCode ) ;
100
+ } catch ( err ) {
101
+ evt = document . createEvent ( "Events" ) ;
102
+ evt . initEvent ( type , e . bubbles , e . cancelable ) ;
103
+ $ . extend ( evt , {
104
+ view : e . view ,
105
+ ctrlKey : e . ctrlKey ,
106
+ altKey : e . altKey ,
107
+ shiftKey : e . shiftKey ,
108
+ metaKey : e . metaKey ,
109
+ keyCode : e . keyCode ,
110
+ charCode : e . charCode
89
111
} ) ;
90
112
}
91
- } else if ( document . createEventObject ) {
113
+ } else if ( document . createEventObject ) {
92
114
evt = document . createEventObject ( ) ;
93
- $ . extend ( evt , e ) ;
115
+ $ . extend ( evt , e ) ;
94
116
}
95
- if ( $ . browser . msie || $ . browser . opera ) {
117
+ if ( $ . browser . msie || $ . browser . opera ) {
96
118
evt . keyCode = ( e . charCode > 0 ) ? e . charCode : e . keyCode ;
97
119
evt . charCode = undefined ;
98
120
}
99
121
return evt ;
100
122
} ,
101
123
102
- dispatchEvent : function ( el , type , evt ) {
103
- if ( el . dispatchEvent ) {
104
- el . dispatchEvent ( evt ) ;
105
- } else if ( el . fireEvent ) {
106
- el . fireEvent ( 'on' + type , evt ) ;
124
+ dispatchEvent : function ( el , type , evt ) {
125
+ if ( el . dispatchEvent ) {
126
+ el . dispatchEvent ( evt ) ;
127
+ } else if ( el . fireEvent ) {
128
+ el . fireEvent ( "on" + type , evt ) ;
107
129
}
108
130
return evt ;
109
131
} ,
110
132
111
- drag : function ( el ) {
112
- var self = this , center = this . findCenter ( this . target ) ,
113
- options = this . options , x = Math . floor ( center . x ) , y = Math . floor ( center . y ) ,
114
- dx = options . dx || 0 , dy = options . dy || 0 , target = this . target ;
115
- var coord = { clientX : x , clientY : y } ;
116
- this . simulateEvent ( target , "mousedown" , coord ) ;
133
+ drag : function ( el ) {
134
+ var self = this ,
135
+ center = this . findCenter ( this . target ) ,
136
+ options = this . options ,
137
+ x = Math . floor ( center . x ) ,
138
+ y = Math . floor ( center . y ) ,
139
+ dx = options . dx || 0 ,
140
+ dy = options . dy || 0 ,
141
+ target = this . target ,
142
+ coord = { clientX : x , clientY : y } ;
143
+ this . simulateEvent ( target , "mousedown" , coord ) ;
117
144
coord = { clientX : x + 1 , clientY : y + 1 } ;
118
- this . simulateEvent ( document , "mousemove" , coord ) ;
145
+ this . simulateEvent ( document , "mousemove" , coord ) ;
119
146
coord = { clientX : x + dx , clientY : y + dy } ;
120
- this . simulateEvent ( document , "mousemove" , coord ) ;
121
- this . simulateEvent ( document , "mousemove" , coord ) ;
122
- this . simulateEvent ( target , "mouseup" , coord ) ;
123
- this . simulateEvent ( target , "click" , coord ) ;
147
+ this . simulateEvent ( document , "mousemove" , coord ) ;
148
+ this . simulateEvent ( document , "mousemove" , coord ) ;
149
+ this . simulateEvent ( target , "mouseup" , coord ) ;
150
+ this . simulateEvent ( target , "click" , coord ) ;
124
151
} ,
125
- findCenter : function ( el ) {
126
- var el = $ ( this . target ) , o = el . offset ( ) , d = $ ( document ) ;
152
+ findCenter : function ( el ) {
153
+ var el = $ ( this . target ) ,
154
+ o = el . offset ( ) ,
155
+ d = $ ( document ) ;
127
156
return {
128
157
x : o . left + el . outerWidth ( ) / 2 - d . scrollLeft ( ) ,
129
158
y : o . top + el . outerHeight ( ) / 2 - d . scrollTop ( )
130
159
} ;
131
160
}
132
161
} ) ;
133
162
134
- $ . extend ( $ . simulate , {
163
+ $ . extend ( $ . simulate , {
135
164
defaults : {
136
- speed : ' sync'
165
+ speed : " sync"
137
166
} ,
138
167
VK_TAB : 9 ,
139
168
VK_ENTER : 13 ,
@@ -148,4 +177,4 @@ $.extend($.simulate, {
148
177
VK_DOWN : 40
149
178
} ) ;
150
179
151
- } ) ( jQuery ) ;
180
+ } ) ( jQuery ) ;
0 commit comments