Class: Browser::History

Inherits:
Object show all
Includes:
Native
Defined in:
lib/roda/component/history.rb

Overview

History allows manipulation of the session history.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#currentString (readonly)

Returns the current item.

Returns:

  • (String)

    the current item



68
69
70
# File 'lib/roda/component/history.rb', line 68

def current
  $window.location.path
end

#lengthInteger (readonly)

Returns how many items are in the history.

Returns:

  • (Integer)

    how many items are in the history



26
# File 'lib/roda/component/history.rb', line 26

alias_native :length

Instance Method Details

#back(number = 1) ⇒ Object

Go back in the history.

Parameters:

  • number (Integer) (defaults to: 1)

    how many items to go back



31
32
33
# File 'lib/roda/component/history.rb', line 31

def back(number = 1)
  `History.go(-number)`
end

#change(&block) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/roda/component/history.rb', line 72

def change &block
  %x{
    History.Adapter.bind(window,'statechange',function(e){
      var state = History.getState();
      state = #{Native(`state`)}
      return #{block.call(`state`)}
    });
  }
end

#forward(number = 1) ⇒ Object

Go forward in the history.

Parameters:

  • number (Integer) (defaults to: 1)

    how many items to go forward



38
39
40
# File 'lib/roda/component/history.rb', line 38

def forward(number = 1)
  `History.go(number)`
end

#get_stateObject



62
63
64
# File 'lib/roda/component/history.rb', line 62

def get_state
  Native(`History.getState()`)
end

#push(item, data = nil) ⇒ Object

Push an item in the history.

Parameters:

  • item (String)

    the item to push in the history

  • data (Object) (defaults to: nil)

    additional state to push



46
47
48
49
50
# File 'lib/roda/component/history.rb', line 46

def push(item, data = nil)
  data = `null` if data.nil?

  `History.pushState(jQuery.parseJSON(data.$to_json()), null, item)`
end

#replace(item, data = nil) ⇒ Object

Replace the current history item with another.

Parameters:

  • item (String)

    the item to replace with

  • data (Object) (defaults to: nil)

    additional state to replace



56
57
58
59
60
# File 'lib/roda/component/history.rb', line 56

def replace(item, data = nil)
  data = `null` if data.nil?

  `History.replaceState(data, null, item)`
end