This repository has been archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events-handlings.js
66 lines (59 loc) · 2.41 KB
/
events-handlings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
define(["template!views/modules/_default.html"], template => {
var module,
handleButtonClickEvent = event => {
let msg = event.target.id + " button clicked and handled in static private function"
module.panel.html(module.panel.html() + "> " + msg + "<br />");
console.log(msg);
}
const moduleClass = class {
constructor() {
module = this;
}
render({params, element}) {
return template({
header:
"Event handlings",
firstLine:
"Demonstration of different element event handling tehniques.",
secondLine:
"",
viewLocation:
"/app/views/modules/view-events.js",
routeDefintion:
'"/view-events": {\n' +
' view: "views/modules/view-events",\n' +
' data: {\n' +
' title: "View events",\n' +
' category: "modules"\n' +
' },\n' +
'}',
closingLine: String.html`These are two buttons to be clicked here:
<span>
<button id="button1">button1 click here!</button>
<button id="button2">button2 click here!</button>
<button id="button3">button3 click here!</button>
</span>
<br /><br />
<div class="panel panel-default">
<div class="panel-heading">output:</div>
<div class="panel-body"></div>
</div>
`
});
}
rendered({params, element}) {
this.panel = element.find(".panel-body");
element.find("#button1").on("click", (e) => {
this.handleButtonClickEvent(e);
});
element.find("#button2").on("click", (e) => this.handleButtonClickEvent(e));
element.find("#button3").on("click", handleButtonClickEvent);
}
handleButtonClickEvent(event) {
let msg = event.target.id + " button clicked and handled in instance method"
this.panel.html(this.panel.html() + "> " + msg + "<br />");
console.log(msg);
}
}
return moduleClass;
});