]> git.r.bdr.sh - rbdr/custom_event_support.lua/blame - lib/custom_event.lua
One last try at getting the link right
[rbdr/custom_event_support.lua] / lib / custom_event.lua
CommitLineData
676ef49d
BB
1local CustomEvent = class('CustomEvent')
2
3function CustomEvent:initialize(event_type, data)
4 -- defaults
5 self.bubbles = true
6 self.cancelable = true
7 self.current_target = nil
8 self.timestamp = 0
9 self.target = nil
10 self.type = ''
11 self.is_propagation_stopped = false
12 self.is_default_prevented = false
13 self.is_immediate_propagation_stopped = false
14 self.are_immediate_handlers_prevented = false
15
16 -- init
17 self.type = event_type
18 for k, v in pairs(data) do
19 self[k] = v
20 end
21end
22
23function CustomEvent:stop_propagation()
24 self.is_propagation_stopped = true
25end
26
27function CustomEvent:prevent_default()
28 self.is_default_prevented = true
29end
30
31function CustomEvent:stop_immediate_propagation()
32 self.is_immediate_propagation_stopped = true
33end
34
35function CustomEvent:prevent_immediate_handlers()
36 self.are_immediate_handlers_prevented = true
37end
38
39return CustomEvent;