Class: Browser::History

Inherits:
Object show all
Includes:
Native
Defined in:
lib/wedge/plugins/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



76
77
78
# File 'lib/wedge/plugins/history.rb', line 76

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



35
# File 'lib/wedge/plugins/history.rb', line 35

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



40
41
42
# File 'lib/wedge/plugins/history.rb', line 40

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

#change(&block) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/wedge/plugins/history.rb', line 80

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



47
48
49
# File 'lib/wedge/plugins/history.rb', line 47

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

#get_stateObject



70
71
72
# File 'lib/wedge/plugins/history.rb', line 70

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

#push(item, data = {}) ⇒ Object

Push an item in the history.

Parameters:

  • item (String)

    the item to push in the history

  • data (Object) (defaults to: {})

    additional state to push



55
56
57
58
# File 'lib/wedge/plugins/history.rb', line 55

def push(item, data = {})

  `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



64
65
66
67
68
# File 'lib/wedge/plugins/history.rb', line 64

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

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