Class: GlimR::Event

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/glimr/event.rb

Overview

Implements the <a href=“www.w3.org/TR/DOM-Level-2-Events”>W3C DOM Event model</a> event interface.

Much like the ECMAScript API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, params = {:bubbles => true, :cancelable => false}) ⇒ Event

Creates a new event of the given type, sets params to param hash. By default, the event bubbles and is not cancelable.



17
18
19
20
21
22
23
24
25
26
# File 'lib/glimr/event.rb', line 17

def initialize(type, params={:bubbles => true, :cancelable => false})
  params = params.clone
  params[:bubbles] = true if params[:bubbles].nil?
  params[:cancelable] = false if params[:cancelable].nil?
  params[:time] ||= Time.now.to_f
  super(params)
  @type = type.to_sym
  @params = params
  @phase = :capture
end

Instance Attribute Details

#cancelledObject (readonly)

Returns the value of attribute cancelled.



12
13
14
# File 'lib/glimr/event.rb', line 12

def cancelled
  @cancelled
end

#paramsObject

Returns the value of attribute params.



13
14
15
# File 'lib/glimr/event.rb', line 13

def params
  @params
end

#phaseObject

Returns the value of attribute phase.



13
14
15
# File 'lib/glimr/event.rb', line 13

def phase
  @phase
end

#stoppedObject (readonly)

Returns the value of attribute stopped.



12
13
14
# File 'lib/glimr/event.rb', line 12

def stopped
  @stopped
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/glimr/event.rb', line 12

def type
  @type
end

Instance Method Details

#prevent_defaultObject

Cancels the event’s possible default behaviour.



34
35
36
# File 'lib/glimr/event.rb', line 34

def prevent_default
  @cancelled = true if cancelable
end

#stop_propagationObject

Stops the handling of the event.



29
30
31
# File 'lib/glimr/event.rb', line 29

def stop_propagation
  @stopped = true
end