Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dom/event: finish the compatibility layer
  • Loading branch information
meh committed Jan 25, 2014
1 parent 7aa164a commit 1e9c8cf
Show file tree
Hide file tree
Showing 27 changed files with 326 additions and 261 deletions.
14 changes: 3 additions & 11 deletions opal/browser/dom/event.rb
Expand Up @@ -131,14 +131,6 @@ def self.class_for(name)
else
Custom
end

if type == Custom
Custom
elsif type.supported?
type
else
Event
end
end

def self.supported?
Expand All @@ -149,7 +141,7 @@ def self.create(name, *args, &block)
name = name_for(name)
klass = class_for(name)

event = klass.new(klass.construct(name, klass.const_get(:Definition).new(&block)))
event = klass.new(klass.construct(name, klass.const_get(:Definition).new(&block)))
event.arguments = args

event
Expand All @@ -165,14 +157,14 @@ def self.construct(name, desc)
var event = document.createEvent("HTMLEvents");
event.initEvent(name, desc.bubbles, desc.cancelable);
return event;
#{return Native(`event`).merge!(desc)};
}
end
elsif Browser.supports? 'Event.createObject'
def self.construct(name, desc)
Native(`document.createEventObject()`) \
.merge!(`{ type: name }`) \
.merge!(desc) \
.merge!(`{ type: name }`) \
.to_n
end
else
Expand Down
12 changes: 2 additions & 10 deletions opal/browser/dom/event/animation.rb
Expand Up @@ -2,7 +2,7 @@ module Browser; module DOM; class Event

class Animation < Event
def self.supported?
not $$[:AnimationEvent].nil?
Browser.supports? 'Event.Animation'
end

class Definition < Definition
Expand All @@ -29,15 +29,7 @@ def self.construct(name, desc)
return event;
}
end
elsif Browser.supports? 'Event.createObject'
def self.construct(name, desc)
Native(`document.createEventObject()`).merge!(desc).to_n
end
else
def self.construct(*)
raise NotImplementedError
end
end
end if supported?

alias_native :name, :animationName
alias_native :elapsed, :elapsedTime
Expand Down
10 changes: 6 additions & 4 deletions opal/browser/dom/event/audio_processing.rb
Expand Up @@ -2,7 +2,7 @@ module Browser; module DOM; class Event

class AudioProcessing < Event
def self.supported?
not $$[:AudioProcessingEvent].nil?
Browser.supports? 'Event.AudioProcessing'
end

class Definition < Definition
Expand All @@ -19,9 +19,11 @@ def output=(value)
end
end

def self.construct(name, desc)
`new AudioProcessingEvent(#{name}, #{desc})`
end
if Browser.supports? 'Event.constructor'
def self.construct(name, desc)
`new AudioProcessingEvent(#{name}, #{desc})`
end
end if supported?

alias_native :time, :playbackTime
alias_native :input, :inputBuffer
Expand Down
10 changes: 6 additions & 4 deletions opal/browser/dom/event/before_unload.rb
Expand Up @@ -2,12 +2,14 @@ module Browser; module DOM; class Event

class BeforeUnload < Event
def self.supported?
not $$[:BeforeUnloadEvent].nil?
Browser.supports? 'Event.BeforeUnload'
end

def self.construct(name, desc)
`new BeforeUnloadEvent(#{name}, #{desc})`
end
if Browser.supports? 'Event.constructor'
def self.construct(name, desc)
`new BeforeUnloadEvent(#{name}, #{desc})`
end
end if supported?
end

end; end; end
10 changes: 6 additions & 4 deletions opal/browser/dom/event/clipboard.rb
Expand Up @@ -2,7 +2,7 @@ module Browser; module DOM; class Event

class Clipboard < Event
def self.supported?
not $$[:ClipboardEvent].nil?
Browser.supports? 'Event.Clipboard'
end

class Definition < Definition
Expand All @@ -15,9 +15,11 @@ def type=(value)
end
end

def self.construct(name, desc)
`new ClipboardEvent(#{name}, #{desc})`
end
if Browser.supports? 'Event.constructor'
def self.construct(name, desc)
`new ClipboardEvent(#{name}, #{desc})`
end
end if supported?

alias_native :data
alias_native :type, :dataType
Expand Down
12 changes: 2 additions & 10 deletions opal/browser/dom/event/close.rb
Expand Up @@ -2,7 +2,7 @@ module Browser; module DOM; class Event

class Close < Event
def self.supported?
not $$[:CloseEvent].nil?
Browser.supports? 'Event.Close'
end

class Definition < Definition
Expand Down Expand Up @@ -37,15 +37,7 @@ def self.construct(name, desc)
return event;
}
end
elsif Browser.supports? 'Event.createObject'
def self.construct(name, desc)
Native(`document.createEventObject()`).merge!(desc).to_n
end
else
def self.construct(*)
raise NotImplementedError
end
end
end if supported?

alias_native :code
alias_native :reason
Expand Down
15 changes: 3 additions & 12 deletions opal/browser/dom/event/composition.rb
Expand Up @@ -2,7 +2,7 @@ module Browser; module DOM; class Event

class Composition < UI
def self.supported?
not $$[:CompositionEvent].nil?
Browser.supports? 'Event.Composition'
end

class Definition < UI::Definition
Expand All @@ -24,21 +24,12 @@ def self.construct(name, desc)
%x{
var event = document.createEvent("CompositionEvent");
event.initCompositionEvent(name, desc.bubbles, desc.cancelable,
window, desc.data, desc.locale);
desc.view || window, desc.data, desc.locale);
return event;
}
end
elsif Browser.supports? 'Event.createObject'
def self.construct(name, desc)
Native(`document.createEventObject()`).merge!(desc).to_n
end
else
def self.construct(*)
raise NotImplementedError
end
end

end if supported?

alias_native :data
alias_native :locale
Expand Down
15 changes: 11 additions & 4 deletions opal/browser/dom/event/custom.rb
Expand Up @@ -4,7 +4,7 @@ module Browser; module DOM; class Event

class Custom < Event
def self.supported?
not $$[:CustomEvent].nil?
Browser.supports? 'Event.Custom'
end

class Definition < Definition
Expand All @@ -17,7 +17,10 @@ def method_missing(name, value)

if Browser.supports? 'Event.constructor'
def self.construct(name, desc)
`new CustomEvent(name, desc)`
`new CustomEvent(name, {
bubbles: desc.bubbles,
cancelable: desc.cancelable,
detail: desc })`
end
elsif Browser.supports? 'Event.create'
def self.construct(name, desc)
Expand All @@ -37,8 +40,12 @@ def self.construct(name, desc)
detail: desc }`).to_n
end
else
def self.construct(*)
raise NotImplementedError
def self.construct(name, desc)
Native(desc).merge!(`{
type: name,
bubbles: desc.bubbles,
cancelable: desc.cancelable,
detail: desc }`).to_n
end
end

Expand Down
10 changes: 6 additions & 4 deletions opal/browser/dom/event/device_light.rb
Expand Up @@ -2,7 +2,7 @@ module Browser; module DOM; class Event

class DeviceLight < Event
def self.supported?
not $$[:DeviceLightEvent].nil?
Browser.supports? 'Event.DeviceLight'
end

class Definition < Definition
Expand All @@ -11,9 +11,11 @@ def value=(value)
end
end

def self.construct(name, desc)
`new DeviceLightEvent(#{name}, #{desc})`
end
if Browser.supports? 'Event.constructor'
def self.construct(name, desc)
`new DeviceLightEvent(#{name}, #{desc})`
end
end if supported?

alias_native :value
end
Expand Down
13 changes: 2 additions & 11 deletions opal/browser/dom/event/device_motion.rb
Expand Up @@ -2,7 +2,7 @@ module Browser; module DOM; class Event

class DeviceMotion < Event
def self.supported?
not $$[:DeviceMotionEvent].nil?
Browser.supports? 'Event.DeviceMotion'
end

Acceleration = Struct.new(:x, :y, :z)
Expand Down Expand Up @@ -40,16 +40,7 @@ def self.construct(name, desc)
return event;
}
end
elsif Browser.supports? 'Event.createObject'
def self.construct(name, desc)
Native(`document.createEventObject()`).merge!(desc).to_n
end
else
def self.construct(*)
raise NotImplementedError
end
end

end if supported?

alias_native :acceleration
alias_native :acceleration_with_gravity, :accelerationIncludingGravity
Expand Down
20 changes: 16 additions & 4 deletions opal/browser/dom/event/device_orientation.rb
Expand Up @@ -2,7 +2,7 @@ module Browser; module DOM; class Event

class DeviceOrientation < Event
def self.supported?
not $$[:DeviceOrientationEvent].nil?
Browser.supports? 'Event.DeviceOrientation'
end

class Definition < Definition
Expand All @@ -23,9 +23,21 @@ def gamma=(value)
end
end

def self.construct(name, desc)
`new DeviceOrientationEvent(#{name}, #{desc})`
end
if Browser.supports? 'Event.constructor'
def self.construct(name, desc)
`new DeviceOrientationEvent(#{name}, #{desc})`
end
elsif Browser.supports? 'Event.create'
def self.construct(name, desc)
%x{
var event = document.createEvent("DeviceOrientationEvent");
event.initDeviceOrientationEvent(name, desc.bubbles, desc.cancelable,
desc.alpha, desc.beta, desc.gamma, desc.absolute);
return event;
}
end
end if supported?

alias_native :absolute
alias_native :alpha
Expand Down
10 changes: 6 additions & 4 deletions opal/browser/dom/event/device_proximity.rb
Expand Up @@ -2,7 +2,7 @@ module Browser; module DOM; class Event

class DeviceProximity < Event
def self.supported?
not $$[:DeviceProximityEvent].nil?
Browser.supports? 'Event.DeviceProximity'
end

class Definition < Definition
Expand All @@ -19,9 +19,11 @@ def max=(value)
end
end

def self.construct(name, desc)
`new DeviceProximityEvent(#{name}, #{desc})`
end
if Browser.supports? 'Event.constructor'
def self.construct(name, desc)
`new DeviceProximityEvent(#{name}, #{desc})`
end
end if supported?

alias_native :value
alias_native :min
Expand Down

0 comments on commit 1e9c8cf

Please sign in to comment.