X-Git-Url: https://git.r.bdr.sh/rbdr/custom_event_support.lua/blobdiff_plain/b4238901d280e4db010d8426d05459b19e714722..676ef49de6412859ef2c807d64827554774d51f1:/lib/custom_event.lua diff --git a/lib/custom_event.lua b/lib/custom_event.lua index e69de29..c0341d5 100644 --- a/lib/custom_event.lua +++ b/lib/custom_event.lua @@ -0,0 +1,39 @@ +local CustomEvent = class('CustomEvent') + +function CustomEvent:initialize(event_type, data) + -- defaults + self.bubbles = true + self.cancelable = true + self.current_target = nil + self.timestamp = 0 + self.target = nil + self.type = '' + self.is_propagation_stopped = false + self.is_default_prevented = false + self.is_immediate_propagation_stopped = false + self.are_immediate_handlers_prevented = false + + -- init + self.type = event_type + for k, v in pairs(data) do + self[k] = v + end +end + +function CustomEvent:stop_propagation() + self.is_propagation_stopped = true +end + +function CustomEvent:prevent_default() + self.is_default_prevented = true +end + +function CustomEvent:stop_immediate_propagation() + self.is_immediate_propagation_stopped = true +end + +function CustomEvent:prevent_immediate_handlers() + self.are_immediate_handlers_prevented = true +end + +return CustomEvent;