Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal-browser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 634dbf9b637c
Choose a base ref
...
head repository: opal/opal-browser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 114d3aaaa7eb
Choose a head ref
  • 5 commits
  • 5 files changed
  • 1 contributor

Commits on Jan 21, 2014

  1. http: update documentation

    meh committed Jan 21, 2014
    Copy the full SHA
    3feb0a0 View commit details
  2. event_source: add references

    meh committed Jan 21, 2014
    Copy the full SHA
    84c271a View commit details
  3. history: add documentation

    meh committed Jan 21, 2014
    Copy the full SHA
    b3554fb View commit details
  4. location: add references

    meh committed Jan 21, 2014
    Copy the full SHA
    674617d View commit details
  5. navigator: add references

    meh committed Jan 21, 2014
    Copy the full SHA
    114d3aa View commit details
Showing with 75 additions and 23 deletions.
  1. +4 −1 opal/browser/event_source.rb
  2. +39 −7 opal/browser/history.rb
  3. +18 −6 opal/browser/http.rb
  4. +5 −3 opal/browser/location.rb
  5. +9 −6 opal/browser/navigator.rb
5 changes: 4 additions & 1 deletion opal/browser/event_source.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module Browser

# This class wraps `EventSource`.
# An {EventSource} allows you to receive events from a server in real-time,
# similar to long-polling but not exactly.
#
# @see https://developer.mozilla.org/en-US/docs/Web/API/EventSource
class EventSource
def self.supported?
defined? `window.EventSource`
46 changes: 39 additions & 7 deletions opal/browser/history.rb
Original file line number Diff line number Diff line change
@@ -2,50 +2,82 @@

module Browser

# {History} allows manipulation of the session history.
#
# @see https://developer.mozilla.org/en-US/docs/Web/API/History
class History
include Native

# @!attribute [r] length
# @return [Integer] how many items are in the history
alias_native :length

# Go back in the history.
#
# @param number [Integer] how many items to go back
#
# @return [self]
def back(number = 1)
`#@native.go(-number)`

self
end

# Go forward in the history.
#
# @param number [Integer] how many items to go forward
#
# @return [self]
def forward(number = 1)
`#@native.go(number)`

self
end

def push(url, data = nil)
# Push an item in the history.
#
# @param item [String] the item to push in the history
# @param data [Object] additional state to push
#
# @return [self]
def push(item, data = nil)
data = `null` if data.nil?

`#@native.pushState(data, null, url)`
`#@native.pushState(data, null, item)`

self
end

def replace(url, data = nil)
# Replace the current history item with another.
#
# @param item [String] the item to replace with
# @param data [Object] additional state to replace
#
# @return [self]
def replace(item, data = nil)
data = `null` if data.nil?

`#@native.replaceState(data, null, url)`
`#@native.replaceState(data, null, item)`

self
end

# @!attribute [r] current
# @return [String] the current item
def current
$window.location.path
end

# @!attribute [r] state
# @return [Object] the current state
def state
`#@native.state`
end
end

class Window
# Get the {History} object for this window.
#
# @return [History]
# @!attribute [r] history
# @return [History] the history for this window
def history
History.new(`#@native.history`) if `#@native.history`
end
24 changes: 18 additions & 6 deletions opal/browser/http.rb
Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@ module HTTP
# @param method [Symbol] the HTTP method to use
# @param url [String] the URL to request
# @param data [String, Hash] the data to send
# @return [Response] the response
#
# @return [Promise] a promise that will be resolved with the response
def self.send(method, url, data = nil, &block)
Promise.new.tap {|promise|
Request.new(&block).tap {|req|
@@ -32,15 +33,17 @@ def self.send(method, url, data = nil, &block)
# Send an asynchronous GET request.
#
# @param url [String] the URL to request
# @return [Response] the response
#
# @return [Promise] a promise that will be resolved with the response
def self.get(url, &block)
send(:get, url, &block)
end

# Send an asynchronous HEAD request.
#
# @param url [String] the URL to request
# @return [Response] the response
#
# @return [Promise] a promise that will be resolved with the response
def self.head(url, &block)
send(:head, url, &block)
end
@@ -49,7 +52,8 @@ def self.head(url, &block)
#
# @param url [String] the URL to request
# @param data [String, Hash] the data to send
# @return [Response] the response
#
# @return [Promise] a promise that will be resolved with the response
def self.post(url, data = nil, &block)
send(:post, url, data, &block)
end
@@ -58,7 +62,8 @@ def self.post(url, data = nil, &block)
#
# @param url [String] the URL to request
# @param data [String, Hash] the data to send
# @return [Response] the response
#
# @return [Promise] a promise that will be resolved with the response
def self.put(url, data = nil, &block)
send(:put, url, data, &block)
end
@@ -67,7 +72,8 @@ def self.put(url, data = nil, &block)
#
# @param url [String] the URL to request
# @param data [String, Hash] the data to send
# @return [Response] the response
#
# @return [Promise] a promise that will be resolved with the response
def self.delete(url, data = nil, &block)
send(:delete, url, data, &block)
end
@@ -77,6 +83,7 @@ def self.delete(url, data = nil, &block)
# @param method [Symbol] the HTTP method to use
# @param url [String] the URL to request
# @param data [String, Hash] the data to send
#
# @return [Response] the response
def self.send!(method, url, data = nil, &block)
Request.new(&block).open(method, url, false).send(data)
@@ -85,6 +92,7 @@ def self.send!(method, url, data = nil, &block)
# Send a synchronous GET request.
#
# @param url [String] the URL to request
#
# @return [Response] the response
def self.get!(url, &block)
send!(:get, url, &block)
@@ -93,6 +101,7 @@ def self.get!(url, &block)
# Send a synchronous HEAD request.
#
# @param url [String] the URL to request
#
# @return [Response] the response
def self.head!(url, &block)
send!(:head, url, &block)
@@ -102,6 +111,7 @@ def self.head!(url, &block)
#
# @param url [String] the URL to request
# @param data [String, Hash] the data to send
#
# @return [Response] the response
def self.post!(url, data = nil, &block)
send!(:post, url, data, &block)
@@ -111,6 +121,7 @@ def self.post!(url, data = nil, &block)
#
# @param url [String] the URL to request
# @param data [String, Hash] the data to send
#
# @return [Response] the response
def self.put!(url, data = nil, &block)
send!(:put, url, data, &block)
@@ -120,6 +131,7 @@ def self.put!(url, data = nil, &block)
#
# @param url [String] the URL to request
# @param data [String, Hash] the data to send
#
# @return [Response] the response
def self.delete!(url, data = nil, &block)
send!(:delete, url, data, &block)
8 changes: 5 additions & 3 deletions opal/browser/location.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Browser

# Allows manipulation of a location, usually from {Window} and {DOM::Document}.
#
# @see https://developer.mozilla.org/en-US/docs/Web/API/Location
class Location
include Native

@@ -66,9 +69,8 @@ def to_s
end

class Window
# Get the {Location} object for this window.
#
# @return [Location]
# @!attribute [r] location
# @return [Location] the location for the window
def location
Location.new(`#@native.location`) if `#@native.location`
end
15 changes: 9 additions & 6 deletions opal/browser/navigator.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module Browser

# Class that represents the browser attributes.
# Representation of the navigator application.
#
# @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator
class Navigator
include Native

Version = Struct.new(:major, :minor, :build)
Product = Struct.new(:name, :version)
Vendor = Struct.new(:name, :version)

# Class that represents a MIME type.
# Representation of a MIME type.
class MimeType
include Native

@@ -33,7 +35,9 @@ def extensions
alias_native :type
end

# Class to represent a browser plugin.
# Representation of a navigator plugin.
#
# @see https://developer.mozilla.org/en-US/docs/Web/API/Plugin
class Plugin < Native::Array
def initialize(plugin)
super plugin do |m|
@@ -140,9 +144,8 @@ def java?
end

class Window
# Get the {Navigator} object for this window.
#
# @return [Navigator]
# @!attribute [r] navigator
# @return [Navigator] the navigator
def navigator
Navigator.new(`#@native.navigator`) if `#@native.navigator`
end