Total Complexity | 4 |
Complexity/F | 4 |
Lines of Code | 25 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /** Add one or more listeners to an element |
||
2 | * @param element - DOM element to add listeners to |
||
3 | * @param eventNames - space separated list of event names, e.g. 'click change' |
||
4 | * @param listener - function to attach for each event as a listener |
||
5 | */ |
||
6 | function setEventListener( |
||
7 | element: HTMLElement, |
||
8 | eventNames: "click" | "mouseover" | "submit" | "change", |
||
9 | listener: EventListenerObject | Function | any |
||
10 | ) { |
||
11 | eventNames.split(" ").forEach(function (e) { |
||
12 | //element.addEventListener(e, listener, false); |
||
13 | if (element.attachEvent) { |
||
14 | if (e == "click") { |
||
15 | e = "onclick"; |
||
16 | } |
||
17 | element.attachEvent(e, listener); |
||
18 | } else if (element.addEventListener) { |
||
19 | element.addEventListener(e, listener, false); |
||
20 | } else { |
||
21 | console.error("cannot attach event to FAB wrapper"); |
||
22 | } |
||
23 | }); |
||
24 | } |
||
25 |