Sha256: 6fb38f5a7840da7918cec2ac7530eacbb1cc5f5e9f66df8f84b3f3768fccecf5

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require 'buffer'

module Browser; class Event

class Message < Event
  def self.supported?
    Browser.supports? 'Event.Message'
  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
  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 & 2 rubygems

Version Path
diamonds-0.1.5 lib/diamonds/opal/browser/event/message.rb
opal-browser-0.2.0 opal/browser/event/message.rb