]> git.r.bdr.sh - rbdr/custom_event_support.lua/blob - lib/custom_event.lua
c0341d502138bf4ecb5fcd9a857c4a4d6a911974
[rbdr/custom_event_support.lua] / lib / custom_event.lua
1 local CustomEvent = class('CustomEvent')
2
3 function 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
21 end
22
23 function CustomEvent:stop_propagation()
24 self.is_propagation_stopped = true
25 end
26
27 function CustomEvent:prevent_default()
28 self.is_default_prevented = true
29 end
30
31 function CustomEvent:stop_immediate_propagation()
32 self.is_immediate_propagation_stopped = true
33 end
34
35 function CustomEvent:prevent_immediate_handlers()
36 self.are_immediate_handlers_prevented = true
37 end
38
39 return CustomEvent;