|
| 1 | + |
| 2 | +// @require core/cash.ts |
| 3 | +// @require core/each.ts |
| 4 | +// @require events/on.ts |
| 5 | +// @require events/trigger.ts |
| 6 | + |
| 7 | +type shorthandEventName = 'blur' | 'focus' | 'focusin' | 'focusout' | 'resize' | 'scroll' | 'click' | 'dblclick' | 'mousedown' | 'mouseup' | 'mousemove' | 'mouseover' | 'mouseout' | 'mouseenter' | 'mouseleave' | 'change' | 'select' | 'submit' | 'keydown' | 'keypress' | 'keyup' | 'contextmenu'; |
| 8 | + |
| 9 | +interface Cash { |
| 10 | + blur ( handler?: Function ): Cash; |
| 11 | + focus ( handler?: Function ): Cash; |
| 12 | + focusin ( handler?: Function ): Cash; |
| 13 | + focusout ( handler?: Function ): Cash; |
| 14 | + resize ( handler?: Function ): Cash; |
| 15 | + scroll ( handler?: Function ): Cash; |
| 16 | + click ( handler?: Function ): Cash; |
| 17 | + dblclick ( handler?: Function ): Cash; |
| 18 | + mousedown ( handler?: Function ): Cash; |
| 19 | + mouseup ( handler?: Function ): Cash; |
| 20 | + mousemove ( handler?: Function ): Cash; |
| 21 | + mouseover ( handler?: Function ): Cash; |
| 22 | + mouseout ( handler?: Function ): Cash; |
| 23 | + mouseenter ( handler?: Function ): Cash; |
| 24 | + mouseleave ( handler?: Function ): Cash; |
| 25 | + change ( handler?: Function ): Cash; |
| 26 | + select ( handler?: Function ): Cash; |
| 27 | + submit ( handler?: Function ): Cash; |
| 28 | + keydown ( handler?: Function ): Cash; |
| 29 | + keypress ( handler?: Function ): Cash; |
| 30 | + keyup ( handler?: Function ): Cash; |
| 31 | + contextmenu ( handler?: Function ): Cash; |
| 32 | +} |
| 33 | + |
| 34 | +cash.each ( 'blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu'.split ( ' ' ), ( i, event: shorthandEventName ) => { |
| 35 | + |
| 36 | + cash.fn[event] = function ( this: Cash, callback?: Function ) { |
| 37 | + |
| 38 | + if ( callback ) return this.on ( event, callback ); |
| 39 | + |
| 40 | + return this.trigger ( event ); |
| 41 | + |
| 42 | + }; |
| 43 | + |
| 44 | +}); |
0 commit comments