diff --git a/CHANGELOG.md b/CHANGELOG.md index e05d34f..12573d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ ## 0.3.4 +* Element#children= +* Support more methods on Media +* Event::Custom to support non-enumerable properties * DOM::Element::Form: #valid?, #request_submit, #ajax_submit * Compatibility for Opal-RSpec 1.0 diff --git a/opal/browser/dom/element.rb b/opal/browser/dom/element.rb index a219167..7eb0173 100644 --- a/opal/browser/dom/element.rb +++ b/opal/browser/dom/element.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + # Requires are moved to the bottom of this file. module Browser; module DOM @@ -367,6 +369,8 @@ def inner_dom=(node) self << node end + alias children= inner_dom= + # @!attribute inner_html # @return [String] the inner HTML of the element def inner_html diff --git a/opal/browser/dom/element/attributes.rb b/opal/browser/dom/element/attributes.rb index 34756c7..18c64a2 100644 --- a/opal/browser/dom/element/attributes.rb +++ b/opal/browser/dom/element/attributes.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Attributes diff --git a/opal/browser/dom/element/button.rb b/opal/browser/dom/element/button.rb index c04b036..37fa859 100644 --- a/opal/browser/dom/element/button.rb +++ b/opal/browser/dom/element/button.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Button < Element diff --git a/opal/browser/dom/element/custom.rb b/opal/browser/dom/element/custom.rb index 747b621..94f9305 100644 --- a/opal/browser/dom/element/custom.rb +++ b/opal/browser/dom/element/custom.rb @@ -1,5 +1,6 @@ # use_strict: true # helpers: truthy +# backtick_javascript: true module Browser; module DOM; class Element < Node @@ -174,4 +175,4 @@ def detached_once include Mixin end -end; end; end \ No newline at end of file +end; end; end diff --git a/opal/browser/dom/element/data.rb b/opal/browser/dom/element/data.rb index fea87b0..e142ab3 100644 --- a/opal/browser/dom/element/data.rb +++ b/opal/browser/dom/element/data.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Data diff --git a/opal/browser/dom/element/editable.rb b/opal/browser/dom/element/editable.rb index 0f536bc..99f5308 100644 --- a/opal/browser/dom/element/editable.rb +++ b/opal/browser/dom/element/editable.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM class Element < Node diff --git a/opal/browser/dom/element/form.rb b/opal/browser/dom/element/form.rb index 27e7cd5..c1986d0 100644 --- a/opal/browser/dom/element/form.rb +++ b/opal/browser/dom/element/form.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Form < Element diff --git a/opal/browser/dom/element/iframe.rb b/opal/browser/dom/element/iframe.rb index 949e4ff..91789f4 100644 --- a/opal/browser/dom/element/iframe.rb +++ b/opal/browser/dom/element/iframe.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Iframe < Element diff --git a/opal/browser/dom/element/image.rb b/opal/browser/dom/element/image.rb index 6dd23fe..d47d745 100644 --- a/opal/browser/dom/element/image.rb +++ b/opal/browser/dom/element/image.rb @@ -1,23 +1,14 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Image < Element def_selector "img" - def complete? - `#@native.complete` - end - - def cross? - `#@native.crossOrigin` - end - - def height - `#@native.naturalHeight` - end - - def width - `#@native.naturalWidth` - end + alias_native :complete?, :complete + alias_native :cross?, :crossOrigin + alias_native :height, :naturalHeight + alias_native :width, :naturalWidth end Img = Image diff --git a/opal/browser/dom/element/input.rb b/opal/browser/dom/element/input.rb index d11c811..106f677 100644 --- a/opal/browser/dom/element/input.rb +++ b/opal/browser/dom/element/input.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Input < Element @@ -14,21 +16,11 @@ def value } end - def value=(value) - `#@native.value = #{value}` - end - - def name_ - `#@native.name` - end - - def type - `#@native.type` - end - - def checked? - `#@native.checked` - end + alias_native :value= + alias_native :name_, :name + alias_native :type + alias_native :checked?, :checked + alias_native :enabled?, :enabled def check! `#@native.checked = 'checked'` @@ -38,10 +30,6 @@ def uncheck! `#@native.checked = ''` end - def enabled? - `#@native.enabled` - end - def disable! `#@native.disabled = 'disabled'` end diff --git a/opal/browser/dom/element/media.rb b/opal/browser/dom/element/media.rb index 4d2078a..a1aa4ba 100644 --- a/opal/browser/dom/element/media.rb +++ b/opal/browser/dom/element/media.rb @@ -1,9 +1,10 @@ module Browser; module DOM; class Element < Node class Media < Element - def play - `#@native.play()` - end + alias_native :play + alias_native :pause + alias_native :time, :currentTime + alias_native :time=, :currentTime end class Video < Media diff --git a/opal/browser/dom/element/offset.rb b/opal/browser/dom/element/offset.rb index 0089817..3d7688d 100644 --- a/opal/browser/dom/element/offset.rb +++ b/opal/browser/dom/element/offset.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Offset diff --git a/opal/browser/dom/element/scroll.rb b/opal/browser/dom/element/scroll.rb index b7e8c15..de02820 100644 --- a/opal/browser/dom/element/scroll.rb +++ b/opal/browser/dom/element/scroll.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node # @todo Consider using the new interfaces which allow for optional diff --git a/opal/browser/dom/element/select.rb b/opal/browser/dom/element/select.rb index c90657b..dc23960 100644 --- a/opal/browser/dom/element/select.rb +++ b/opal/browser/dom/element/select.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Select < Element @@ -14,9 +16,7 @@ def value } end - def value= value - `#@native.value = #{value.to_n}` - end + alias_native :value= def labels NodeSet[Native::Array.new(`#@native.labels`)] @@ -30,10 +30,7 @@ def option DOM(`#@native.options[#@native.selectedIndex]`) end - def index - `#@native.selectedIndex` - end - + alias_native :index, :selectedIndex alias_native :multiple?, :multiple alias_native :required?, :required alias_native :length diff --git a/opal/browser/dom/element/size.rb b/opal/browser/dom/element/size.rb index fb96225..6ca8fc9 100644 --- a/opal/browser/dom/element/size.rb +++ b/opal/browser/dom/element/size.rb @@ -1,6 +1,8 @@ module Browser; module DOM; class Element < Node class Size + include Native::Wrapper + attr_reader :element # @private @@ -12,9 +14,7 @@ def initialize(element, *inc) # @!attribute width # @return [Integer] the element width - def width - `#@native.offsetWidth` - end + alias_native :width, :offsetWidth def width=(value) @element.style[:width] = value @@ -22,9 +22,7 @@ def width=(value) # @!attribute height # @return [Integer] the element height - def height - `#@native.offsetHeight` - end + alias_native :height, :offsetHeight def height=(value) @element.style[:height] = value @@ -32,15 +30,11 @@ def height=(value) # @!attribute client_width # @return [Integer] the content-box width of an element - def client_width - `#@native.clientWidth` - end + alias_native :client_width, :clientWidth # @!attribute client_height # @return [Integer] the content-box height of an element - def client_height - `#@native.clientHeight` - end + alias_native :client_height, :clientHeight end end; end; end diff --git a/opal/browser/dom/element/template.rb b/opal/browser/dom/element/template.rb index 2448663..e6ecf89 100644 --- a/opal/browser/dom/element/template.rb +++ b/opal/browser/dom/element/template.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Template < Element diff --git a/opal/browser/dom/element/textarea.rb b/opal/browser/dom/element/textarea.rb index 5700718..338e8f6 100644 --- a/opal/browser/dom/element/textarea.rb +++ b/opal/browser/dom/element/textarea.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; module DOM; class Element < Node class Textarea < Element @@ -14,9 +16,7 @@ def value } end - def value=(value) - `#@native.value = #{value}` - end + alias_native :value= def clear `#@native.value = ''` diff --git a/opal/browser/event/animation.rb b/opal/browser/event/animation.rb index e6b3c3d..c4a158b 100644 --- a/opal/browser/event/animation.rb +++ b/opal/browser/event/animation.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Animation < Event @@ -8,13 +10,9 @@ def self.supported? end class Definition < Definition - def animation=(value) - `#@native.animationName = #{value}` - end - - def elapsed=(value) - `#@native.elapsedTime = #{value}` - end + alias_native :name=, :animationName= + alias_native :animation=, :animationName= + alias_native :elapsed=, :elapsedTime= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/audio_processing.rb b/opal/browser/event/audio_processing.rb index a712040..71aa7bd 100644 --- a/opal/browser/event/audio_processing.rb +++ b/opal/browser/event/audio_processing.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class AudioProcessing < Event @@ -8,17 +10,9 @@ def self.supported? end class Definition < Definition - def time=(value) - `#@native.playbackTime = #{value}` - end - - def input=(value) - `#@native.inputBuffer = #{value}` - end - - def output=(value) - `#@native.outputBuffer = #{value}` - end + alias_native :time=, :playbackTime= + alias_native :input=, :inputBuffer= + alias_native :output=, :outputBuffer= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/base.rb b/opal/browser/event/base.rb index c812845..e8f3036 100644 --- a/opal/browser/event/base.rb +++ b/opal/browser/event/base.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser class Event @@ -16,14 +18,10 @@ def self.new(&block) end # Set the event as bubbling. - def bubbles=(value) - `#@native.bubbles = #{value}` - end + alias_native :bubbles= # Set the event as cancelable. - def cancelable=(value) - `#@native.cancelable = #{value}` - end + alias_native :cancelable= end module Target diff --git a/opal/browser/event/before_unload.rb b/opal/browser/event/before_unload.rb index 07bf528..5df430b 100644 --- a/opal/browser/event/before_unload.rb +++ b/opal/browser/event/before_unload.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class BeforeUnload < Event diff --git a/opal/browser/event/clipboard.rb b/opal/browser/event/clipboard.rb index 018763b..572f85d 100644 --- a/opal/browser/event/clipboard.rb +++ b/opal/browser/event/clipboard.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Clipboard < Event @@ -8,13 +10,8 @@ def self.supported? end class Definition < Definition - def data=(value) - `#@native.data = #{value}` - end - - def type=(value) - `#@native.dataType = #{value}` - end + alias_native :data= + alias_native :type=, :dataType= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/close.rb b/opal/browser/event/close.rb index e181736..ead48a1 100644 --- a/opal/browser/event/close.rb +++ b/opal/browser/event/close.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Close < Event @@ -8,13 +10,8 @@ def self.supported? end class Definition < Definition - def code=(value) - `#@native.code = #{value}` - end - - def reason=(value) - `#@native.reason = #{value}` - end + alias_native :code= + alias_native :reason= def clean!(value) `#@native.wasClean = true` diff --git a/opal/browser/event/composition.rb b/opal/browser/event/composition.rb index 88d3131..e992283 100644 --- a/opal/browser/event/composition.rb +++ b/opal/browser/event/composition.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Composition < UI @@ -8,13 +10,8 @@ def self.supported? end class Definition < UI::Definition - def data=(value) - `#@native.data = #{value}` - end - - def locale=(value) - `#@native.locale = #{value}` - end + alias_native :data= + alias_native :locale= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/custom.rb b/opal/browser/event/custom.rb index c052a87..a47cf30 100644 --- a/opal/browser/event/custom.rb +++ b/opal/browser/event/custom.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + require 'ostruct' module Browser; class Event @@ -11,6 +13,8 @@ class Definition < Definition def method_missing(name, value) if name.end_with? ?= `#@native[#{name[0 .. -2]}] = value` + else + super end end end @@ -51,12 +55,10 @@ def self.construct(name, desc) def initialize(event, callback = nil) super(event, callback) - - @detail = Hash.new(`#{event}.detail`) end def method_missing(id, *) - return @detail[id] if @detail.has_key?(id) + `if (#@native.detail != null && Object.hasOwn(#@native.detail, id)) return #@native.detail[id]` super end diff --git a/opal/browser/event/data_transfer.rb b/opal/browser/event/data_transfer.rb index dba122e..555ec59 100644 --- a/opal/browser/event/data_transfer.rb +++ b/opal/browser/event/data_transfer.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + require 'browser/blob' module Browser; class Event @@ -92,4 +94,4 @@ def to_file end end -end; end \ No newline at end of file +end; end diff --git a/opal/browser/event/device_light.rb b/opal/browser/event/device_light.rb index 402e2cb..252a14b 100644 --- a/opal/browser/event/device_light.rb +++ b/opal/browser/event/device_light.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class DeviceLight < Event @@ -8,9 +10,7 @@ def self.supported? end class Definition < Definition - def value=(value) - `#@native.value = #{value}` - end + alias_native :value end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/device_motion.rb b/opal/browser/event/device_motion.rb index 0f188d4..fccf39f 100644 --- a/opal/browser/event/device_motion.rb +++ b/opal/browser/event/device_motion.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class DeviceMotion < Event @@ -10,21 +12,10 @@ def self.supported? Acceleration = Struct.new(:x, :y, :z) class Definition < Definition - def acceleration=(value) - `#@native.acceleration = #{value.to_n}` - end - - def acceleration_with_gravity=(value) - `#@native.accelerationIncludingGravity = #{value.to_n}` - end - - def rotation=(value) - `#@native.rotationRate = #{value}` - end - - def interval=(value) - `#@native.interval = #{value}` - end + alias_native :acceleration= + alias_native :acceleration_with_gravity=, :accelerationIncludingGravity= + alias_native :rotation=, :rotationRate= + alias_native :interval= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/device_orientation.rb b/opal/browser/event/device_orientation.rb index 37e1465..099bff4 100644 --- a/opal/browser/event/device_orientation.rb +++ b/opal/browser/event/device_orientation.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class DeviceOrientation < Event @@ -8,21 +10,10 @@ def self.supported? end class Definition < Definition - def absolute=(value) - `#@native.absolute = #{value}` - end - - def alpha=(value) - `#@native.alpha = #{value}` - end - - def beta=(value) - `#@native.beta = #{value}` - end - - def gamma=(value) - `#@native.gamma = #{value}` - end + alias_native :absolute= + alias_native :alpha= + alias_native :beta= + alias_native :gamma= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/device_proximity.rb b/opal/browser/event/device_proximity.rb index 420f03c..11909c4 100644 --- a/opal/browser/event/device_proximity.rb +++ b/opal/browser/event/device_proximity.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class DeviceProximity < Event @@ -8,17 +10,9 @@ def self.supported? end class Definition < Definition - def value=(value) - `#@native.value = #{value}` - end - - def min=(value) - `#@native.min = #{value}` - end - - def max=(value) - `#@native.max = #{value}` - end + alias_native :value= + alias_native :min= + alias_native :max= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/drag.rb b/opal/browser/event/drag.rb index bf46ec8..f6ec233 100644 --- a/opal/browser/event/drag.rb +++ b/opal/browser/event/drag.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Drag < Event @@ -12,25 +14,15 @@ class Definition < Definition class Client include Native::Wrapper - def x=(value) - `#@native.clientX = #{value}` - end - - def y=(value) - `#@native.clientY = #{value}` - end + alias_native :x=, :clientX + alias_native :y=, :clientY end class Screen include Native::Wrapper - def x=(value) - `#@native.screenX = #{value}` - end - - def y=(value) - `#@native.screenY = #{value}` - end + alias_native :x=, :screenX + alias_native :y=, :screenY end def alt! diff --git a/opal/browser/event/focus.rb b/opal/browser/event/focus.rb index 9493abb..18186b3 100644 --- a/opal/browser/event/focus.rb +++ b/opal/browser/event/focus.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Focus < UI @@ -8,13 +10,8 @@ def self.supported? end class Definition < UI::Definition - def view=(value) - `#@native.view = #{Native.convert(value)}` - end - - def related=(elem) - `#@native.relatedTarget = #{Native.convert(elem)}` - end + alias_native :view= + alias_native :related=, :relatedTarget end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/gamepad.rb b/opal/browser/event/gamepad.rb index 1e70f5f..06c85af 100644 --- a/opal/browser/event/gamepad.rb +++ b/opal/browser/event/gamepad.rb @@ -1,6 +1,8 @@ +# backtick_javascript: true + module Browser; class Event -class Gamepad < Event + class Gamepad < Event handles 'gamepadconnected', 'gamepaddisconnected' def self.supported? diff --git a/opal/browser/event/hash_change.rb b/opal/browser/event/hash_change.rb index f00d91c..d60a096 100644 --- a/opal/browser/event/hash_change.rb +++ b/opal/browser/event/hash_change.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class HashChange < Event @@ -8,13 +10,8 @@ def self.supported? end class Definition < Definition - def old=(value) - `#@native.oldURL = #{value}` - end - - def new=(value) - `#@native.newURL = #{value}` - end + alias_native :old=, :oldURL= + alias_native :new=, :newURL= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/keyboard.rb b/opal/browser/event/keyboard.rb index 58a5428..4205091 100644 --- a/opal/browser/event/keyboard.rb +++ b/opal/browser/event/keyboard.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Keyboard < UI diff --git a/opal/browser/event/message.rb b/opal/browser/event/message.rb index 7571aaf..27fb046 100644 --- a/opal/browser/event/message.rb +++ b/opal/browser/event/message.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + require 'buffer' module Browser; class Event @@ -10,17 +12,9 @@ def self.supported? end class Definition < Definition - def data=(value) - `#@native.data = value` - end - - def origin=(value) - `#@native.origin = value` - end - - def source=(value) - `#@native.source = #{Native.convert(value)}` - end + alias_native :data= + alias_native :origin= + alias_native :source= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/mouse.rb b/opal/browser/event/mouse.rb index 5a5fab1..a628fd0 100644 --- a/opal/browser/event/mouse.rb +++ b/opal/browser/event/mouse.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Mouse < UI @@ -13,82 +15,51 @@ class Definition < UI::Definition class Client include Native::Wrapper - def x=(value) - `#@native.clientX = #{value}` - end - - def y=(value) - `#@native.clientY = #{value}` - end + alias_native :x=, :clientX= + alias_native :y=, :clientY= end class Layer include Native::Wrapper - def x=(value) - `#@native.layerX = #{value}` - end - - def y=(value) - `#@native.layerY = #{value}` - end + alias_native :x=, :layerX= + alias_native :y=, :layerY= end class Offset include Native::Wrapper - def x=(value) - `#@native.offsetX = #{value}` - end - - def y=(value) - `#@native.offsetY= #{value}` - end + alias_native :x=, :offsetX= + alias_native :y=, :offsetY= end class Page include Native::Wrapper - def x=(value) - `#@native.pageX = #{value}` - end - - def y=(value) - `#@native.pageY = #{value}` - end + alias_native :x=, :pageX= + alias_native :y=, :pageY= end class Screen include Native::Wrapper - def x=(value) - `#@native.screenX = #{value}` - end - - def y=(value) - `#@native.screenY = #{value}` - end + alias_native :x=, :screenX= + alias_native :y=, :screenY= end class Ancestor include Native::Wrapper - def x=(value) - `#@native.x = #{value}` - end - - def y=(value) - `#@native.y = #{value}` - end - end - - def x=(value) - `#@native.screenX = #{value}` + alias_native :x= + alias_native :y= end - def y=(value) - `#@native.screenY = #{value}` - end + alias_native :x=, :screenX= + alias_native :y=, :screenY= + alias_native :button= + alias_native :related=, :relatedTarget= + alias_native :from=, :fromElement= + alias_native :to=, :toElement= def alt! `#@native.altKey = true` @@ -102,10 +73,6 @@ def meta! `#@native.metaKey = true` end - def button=(value) - `#@native.button = #{value}` - end - def client Client.new(@native) end @@ -129,18 +96,6 @@ def screen def ancestor Ancestor.new(@native) end - - def related=(elem) - `#@native.relatedTarget = #{Native.try_convert(elem)}` - end - - def from=(elem) - `#@native.fromElement = #{Native.try_convert(elem)}` - end - - def to=(elem) - `#@native.toElement = #{Native.try_convert(elem)}` - end end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/page_transition.rb b/opal/browser/event/page_transition.rb index 3835412..69cdd2c 100644 --- a/opal/browser/event/page_transition.rb +++ b/opal/browser/event/page_transition.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class PageTransition < Event @@ -8,9 +10,7 @@ def self.supported? end class Definition < Definition - def persisted=(value) - `#@native.persisted = #{value}` - end + alias_native :persisted= end if Browser.supports? 'Event.PageTransition' diff --git a/opal/browser/event/pop_state.rb b/opal/browser/event/pop_state.rb index 2ffc200..249b636 100644 --- a/opal/browser/event/pop_state.rb +++ b/opal/browser/event/pop_state.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class PopState < Event @@ -9,7 +11,7 @@ def self.supported? class Definition < Definition def state=(value) - `#@native.state = #{value}` + alias_native :state= end end diff --git a/opal/browser/event/progress.rb b/opal/browser/event/progress.rb index 6fe513a..9f5e053 100644 --- a/opal/browser/event/progress.rb +++ b/opal/browser/event/progress.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Progress < Event @@ -8,17 +10,9 @@ def self.supported? end class Definition < Definition - def computable=(value) - `#@native.computableLength = #{value}` - end - - def loaded=(value) - `#@native.loaded = #{value}` - end - - def total=(value) - `#@native.total = #{value}` - end + alias_native :computable=, :computableLength= + alias_native :loaded= + alias_native :total= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/sensor.rb b/opal/browser/event/sensor.rb index 1dc0a97..5a1ff38 100644 --- a/opal/browser/event/sensor.rb +++ b/opal/browser/event/sensor.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Sensor < Event diff --git a/opal/browser/event/storage.rb b/opal/browser/event/storage.rb index e02b258..8beaac7 100644 --- a/opal/browser/event/storage.rb +++ b/opal/browser/event/storage.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Storage < Event @@ -8,25 +10,11 @@ def self.supported? end class Definition < Definition - def key=(value) - `#@native.key = #{value}` - end - - def new=(value) - `#@native.newValue = #{value}` - end - - def old=(value) - `#@native.oldValue = #{value}` - end - - def area=(value) - `#@native.storageArea = #{value}` - end - - def url=(value) - `#@native.url = #{value}` - end + alias_native :key= + alias_native :new=, :newValue= + alias_native :old=, :oldValue= + alias_native :area=, :storageArea= + alias_native :url= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/touch.rb b/opal/browser/event/touch.rb index eb51436..1022b82 100644 --- a/opal/browser/event/touch.rb +++ b/opal/browser/event/touch.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Touch < Event diff --git a/opal/browser/event/ui.rb b/opal/browser/event/ui.rb index 34a53d7..8ce7d66 100644 --- a/opal/browser/event/ui.rb +++ b/opal/browser/event/ui.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class UI < Event @@ -6,13 +8,8 @@ def self.supported? end class Definition < Definition - def detail=(value) - `#@native.detail = #{value}` - end - - def view=(value) - `#@native.view = #{value}` - end + alias_native :detail= + alias_native :view= end if Browser.supports? 'Event.constructor' diff --git a/opal/browser/event/wheel.rb b/opal/browser/event/wheel.rb index 7290ccc..9876525 100644 --- a/opal/browser/event/wheel.rb +++ b/opal/browser/event/wheel.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + module Browser; class Event class Wheel < UI @@ -8,17 +10,9 @@ def self.supported? end class Definition < Definition - def x=(value) - `#@native.deltaX = #{value}` - end - - def y=(value) - `#@native.deltaY = #{value}` - end - - def z=(value) - `#@native.deltaZ = #{value}` - end + alias_native :x=, :deltaX= + alias_native :y=, :deltaY= + alias_native :z=, :deltaZ= def mode=(value) value = case value diff --git a/opal/browser/version.rb b/opal/browser/version.rb index def5c48..e427ec4 100644 --- a/opal/browser/version.rb +++ b/opal/browser/version.rb @@ -1,3 +1,3 @@ module Browser - VERSION = '0.3.3' + VERSION = '0.3.4' end diff --git a/spec/event_spec.rb b/spec/event_spec.rb index 3401f07..cec9fef 100644 --- a/spec/event_spec.rb +++ b/spec/event_spec.rb @@ -1,3 +1,5 @@ +# backtick_javascript: true + require 'spec_helper' require 'browser/event' @@ -153,4 +155,45 @@ expect(count).to eq(3) end end + + describe "#trigger" do + it "can set properties of custom events" do + elem = $document["event-spec"] + + count = 0 + cb = elem.on :abcabc do |e| + count += e.thing + end + + elem.trigger :abcabc do |e| + e.thing = 6 + end + + expect(count).to eq(6) + + cb.off + end + + it "works with non-enumerable properties" do + elem = $document["event-spec"] + + count = 0 + cb = elem.on :abcabcd do |e| + count += e.thing + end + + elem.trigger :abcabcd do |e| + %x{ + Object.defineProperty(e.native, "thing", { + value: 6, + enumerable: false + }); + } + end + + expect(count).to eq(6) + + cb.off + end + end end