77 *
88 */
99
10- ; ( function ( $ ) {
10+ ; ( function ( $ ) {
1111
1212$ . fn . extend ( {
13- simulate : function ( type , options ) {
13+ simulate : function ( type , options ) {
1414 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 ) ;
1717 } ) ;
1818 }
1919} ) ;
2020
21- $ . simulate = function ( el , type , options ) {
21+ $ . simulate = function ( el , type , options ) {
2222 this . target = el ;
2323 this . options = options ;
2424
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 ] ) ;
2727 } else {
28- this . simulateEvent ( el , type , options ) ;
28+ this . simulateEvent ( el , type , options ) ;
2929 }
30- }
30+ } ;
3131
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 ) ;
3636 return evt ;
3737 } ,
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 ) ;
4343 }
4444 } ,
45- mouseEvent : function ( type , options ) {
45+ mouseEvent : function ( type , options ) {
4646 var evt ;
4747 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 ) ;
5363
54- var relatedTarget = $ ( e . relatedTarget ) [ 0 ] ;
64+ var relatedTarget = $ ( e . relatedTarget ) [ 0 ] ;
5565
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 ,
5969 e . screenX , e . screenY , e . clientX , e . clientY ,
6070 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 ) {
6373 evt = document . createEventObject ( ) ;
64- $ . extend ( evt , e ) ;
74+ $ . extend ( evt , e ) ;
6575 evt . button = { 0 :1 , 1 :4 , 2 :2 } [ evt . button ] || evt . button ;
6676 }
6777 return evt ;
6878 } ,
69- keyboardEvent : function ( type , options ) {
79+ keyboardEvent : function ( type , options ) {
7080 var evt ;
7181
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 ) ;
7693
77- if ( $ . isFunction ( document . createEvent ) ) {
94+ if ( $ . isFunction ( document . createEvent ) ) {
7895 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 ,
8198 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
89111 } ) ;
90112 }
91- } else if ( document . createEventObject ) {
113+ } else if ( document . createEventObject ) {
92114 evt = document . createEventObject ( ) ;
93- $ . extend ( evt , e ) ;
115+ $ . extend ( evt , e ) ;
94116 }
95- if ( $ . browser . msie || $ . browser . opera ) {
117+ if ( $ . browser . msie || $ . browser . opera ) {
96118 evt . keyCode = ( e . charCode > 0 ) ? e . charCode : e . keyCode ;
97119 evt . charCode = undefined ;
98120 }
99121 return evt ;
100122 } ,
101123
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 ) ;
107129 }
108130 return evt ;
109131 } ,
110132
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 ) ;
117144 coord = { clientX : x + 1 , clientY : y + 1 } ;
118- this . simulateEvent ( document , "mousemove" , coord ) ;
145+ this . simulateEvent ( document , "mousemove" , coord ) ;
119146 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 ) ;
124151 } ,
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 ) ;
127156 return {
128157 x : o . left + el . outerWidth ( ) / 2 - d . scrollLeft ( ) ,
129158 y : o . top + el . outerHeight ( ) / 2 - d . scrollTop ( )
130159 } ;
131160 }
132161} ) ;
133162
134- $ . extend ( $ . simulate , {
163+ $ . extend ( $ . simulate , {
135164 defaults : {
136- speed : ' sync'
165+ speed : " sync"
137166 } ,
138167 VK_TAB : 9 ,
139168 VK_ENTER : 13 ,
@@ -148,4 +177,4 @@ $.extend($.simulate, {
148177 VK_DOWN : 40
149178} ) ;
150179
151- } ) ( jQuery ) ;
180+ } ) ( jQuery ) ;
0 commit comments