-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.html
64 lines (49 loc) · 1.87 KB
/
test.html
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
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="build/build.js" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var DOM = require("dom-events");
// Create a custom class that mixes in EventTarget.
function Custom() {
DOM.EventTarget(this);
}
Custom.prototype = {
constructor: Custom,
__proto__: DOM.EventTarget.prototype,
handleEvent: function(event)
{
console.log(event.type, "handleEvent");
},
specificEventHandler: function(event)
{
console.log(event.type, "specific scoped function");
}
}
// Test the API.
var eventTarget = new Custom;
function handleEvent(event)
{
console.log(event.type, "simple function");
event.stopPropagation();
event.preventDefault();
}
function cancelledHandleEvent(event)
{
console.log(event.type, "this function shouldn't be called");
}
eventTarget.addEventListener("foo", eventTarget);
eventTarget.addEventListener("foo", eventTarget.specificEventHandler, eventTarget);
eventTarget.addEventListener("foo", handleEvent);
eventTarget.addEventListener("foo", cancelledHandleEvent);
console.log("event default action was was prevented?", eventTarget.dispatchEvent(new DOM.Event("foo")));
eventTarget.removeEventListener("foo", eventTarget);
eventTarget.removeEventListener("foo", eventTarget.specificEventHandler, eventTarget);
eventTarget.removeEventListener("foo", handleEvent);
eventTarget.removeEventListener("foo", cancelledHandleEvent);
eventTarget.dispatchEvent(new DOM.Event("foo"));
</script>
</head>
<body>
</body>
</html>