MCPcopy
hub / github.com/fabiospampinato/cash / on

Function on

src/events/on.ts:34–167  ·  view source on GitHub ↗
( this: Cash, eventFullName: Record<string, EventCallback> | string, selector?: any, data?: any, callback?: EventCallback, _one?: boolean )

Source from the content-addressed store, hash-verified

32function on ( this: Cash, eventFullName: string, data: any, callback: EventCallback ): Cash;
33function on ( this: Cash, eventFullName: string, selector: string | null | undefined, data: any, callback: EventCallback, _one?: boolean ): Cash;
34function on ( this: Cash, eventFullName: Record<string, EventCallback> | string, selector?: any, data?: any, callback?: EventCallback, _one?: boolean ) {
35
36 if ( !isString ( eventFullName ) ) {
37
38 for ( const key in eventFullName ) {
39
40 this.on ( key, selector, data, eventFullName[key], _one );
41
42 }
43
44 return this;
45
46 }
47
48 if ( !isString ( selector ) ) {
49
50 if ( isUndefined ( selector ) || isNull ( selector ) ) {
51
52 selector = '';
53
54 } else if ( isUndefined ( data ) ) {
55
56 data = selector;
57 selector = '';
58
59 } else {
60
61 callback = data;
62 data = selector;
63 selector = '';
64
65 }
66
67 }
68
69 if ( !isFunction ( callback ) ) {
70
71 callback = data;
72 data = undefined;
73
74 }
75
76 if ( !callback ) return this;
77
78 each ( getSplitValues ( eventFullName ), ( i, eventFullName ) => {
79
80 const [nameOriginal, namespaces] = parseEventName ( eventFullName );
81 const name = getEventNameBubbling ( nameOriginal );
82 const isEventHover = ( nameOriginal in eventsHover );
83 const isEventFocus = ( nameOriginal in eventsFocus );
84
85 if ( !name ) return;
86
87 this.each ( ( i, ele ) => {
88
89 if ( !isElement ( ele ) && !isDocument ( ele ) && !isWindow ( ele ) ) return;
90
91 const finalCallback = function ( event: Event ) {

Callers

nothing calls this directly

Calls 14

isStringFunction · 0.85
isUndefinedFunction · 0.85
isNullFunction · 0.85
isFunctionFunction · 0.85
eachFunction · 0.85
getSplitValuesFunction · 0.85
parseEventNameFunction · 0.85
getEventNameBubblingFunction · 0.85
isElementFunction · 0.85
isDocumentFunction · 0.85
isWindowFunction · 0.85
addEventFunction · 0.85

Tested by

no test coverage detected