Sha256: f225f3b2b3187d506b2b2531ce15e5532b2cf070ca9eac5ef140333471d3e711

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

# backtick_javascript: true

require 'buffer'

module Browser; class Event

class Message < Event
  handles 'message'

  def self.supported?
    Browser.supports? 'Event.Message'
  end

  class Definition < Definition
    alias_native :data=
    alias_native :origin=
    alias_native :source=
  end

  if Browser.supports? 'Event.constructor'
    def self.construct(name, desc)
      `new MessageEvent(#{name}, #{desc})`
    end
  elsif Browser.supports? 'Event.create'
    def self.construct(name, desc)
      %x{
        var event = document.createEvent("MessageEvent");
            event.initMessageEvent(name, desc.bubbles, desc.cancelable,
              desc.data, desc.origin, "", desc.source || window);

        return event;
      }
    end
  end if supported?

  def data
    %x{
      if (window.ArrayBuffer && #@native.data instanceof ArrayBuffer) {
        return #{Buffer.new(`#@native.data`)};
      }
      else if (window.Blob && #@native.data instanceof Blob) {
        return #{Blob.new(`#@native.data`)};
      }
      else {
        return #@native.data;
      }
    }
  end

  alias_native :origin

  def source
    %x{
      var source = #@native.source;

      if (window.Window && source instanceof window.Window) {
        return #{Window.new(`source`)};
      }
      else {
        return nil;
      }
    }
  end
end

end; end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opal-browser-0.3.5 opal/browser/event/message.rb
opal-browser-0.3.4 opal/browser/event/message.rb