Skip to content

Commit 2d00298

Browse files
Added an extra reference implementation for shorthand event methods
1 parent 33c2955 commit 2d00298

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

pacco.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"browsers": ["ie >= 10"],
33
"components": {
4-
"core/export_esm": false
4+
"core/export_esm": false,
5+
"extra/shorthands": false
56
},
67
"paths": {
78
"tokens": {

src/extra/shorthands.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)