]> git.r.bdr.sh - rbdr/custom_event_support.lua/blobdiff - lib/custom_event.lua
One last try at getting the link right
[rbdr/custom_event_support.lua] / lib / custom_event.lua
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c0341d502138bf4ecb5fcd9a857c4a4d6a911974 100644 (file)
@@ -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;