Class: Ruta::History
- Inherits:
-
Object
- Object
- Ruta::History
- Defined in:
- lib/ruta/history.rb
Class Method Summary collapse
-
.back(by = 1) ⇒ Object
move browser backwards.
-
.current(item) ⇒ Object
get current ‘item` from locaction.
-
.forward(by = 1) ⇒ Object
move browser forward.
-
.listen_for_on_before_load ⇒ Object
will turn on a listener for when the page move away from the current page(refresh or back), will present user with dialogue box.
-
.listen_for_pop ⇒ Object
will turn on a listener for when the forward and backward buttons on the browser are pressed.
-
.navigate_to_remote(path) ⇒ Object
navigate browser to remote path.
-
.push(context, url, data, title = "") ⇒ Object
push new url to history.
-
.replace(url, data, title = nil) ⇒ Object
replace current url in history.
-
.stop_listening_for_on_before_load ⇒ Object
will stop listening for when the page move away from the current page(refresh or back), will present user with dialogue box.
-
.stop_listening_for_pop ⇒ Object
will stop listening for when forward and backward buttons on the browser are pressed.
Class Method Details
.back(by = 1) ⇒ Object
move browser backwards
36 37 38 |
# File 'lib/ruta/history.rb', line 36 def back(by=1) `history.go(#{-by.to_i})` end |
.current(item) ⇒ Object
get current ‘item` from locaction
current items supported are:
* query
* fragment
* path
* url
* uri
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ruta/history.rb', line 56 def current item case item when :query `location.query` when :fragment ` location.fragment` when :path `location.pathname` when :url `location.href` when :uri `location.uri` end end |
.forward(by = 1) ⇒ Object
move browser forward
29 30 31 |
# File 'lib/ruta/history.rb', line 29 def forward(by=1) `history.go(#{by.to_i})` end |
.listen_for_on_before_load ⇒ Object
will turn on a listener for when the page move away from the current page(refresh or back), will present user with dialogue box
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ruta/history.rb', line 93 def listen_for_on_before_load `window.onbeforeunload = function (evt) { var message = 'Are you sure you want to leave?'; if (typeof evt == 'undefined') { evt = window.event; } if (evt) { evt.returnValue = message; } return message; }` end |
.listen_for_pop ⇒ Object
will turn on a listener for when the forward and backward buttons on the browser are pressed
73 74 75 76 77 78 79 |
# File 'lib/ruta/history.rb', line 73 def listen_for_pop `window.onpopstate = function(event) { #{ Router.find_and_execute(current :path) } }` end |
.navigate_to_remote(path) ⇒ Object
navigate browser to remote path
43 44 45 |
# File 'lib/ruta/history.rb', line 43 def navigate_to_remote path `location.href = #{path}` end |
.push(context, url, data, title = "") ⇒ Object
push new url to history
12 13 14 15 |
# File 'lib/ruta/history.rb', line 12 def push(context,url,data,title="") url = Ruta.config.context_prefix ? "/#{context}#{url}" : url `history.pushState(#{data.to_n}, #{title}, #{url})` end |
.replace(url, data, title = nil) ⇒ Object
replace current url in history
22 23 24 |
# File 'lib/ruta/history.rb', line 22 def replace(url,data,title=nil) `history.replaceState(#{data.to_n}, #{title}, #{url})` end |
.stop_listening_for_on_before_load ⇒ Object
will stop listening for when the page move away from the current page(refresh or back), will present user with dialogue box
87 88 89 |
# File 'lib/ruta/history.rb', line 87 def stop_listening_for_on_before_load `window.onbeforeunload = nil` end |
.stop_listening_for_pop ⇒ Object
will stop listening for when forward and backward buttons on the browser are pressed
82 83 84 |
# File 'lib/ruta/history.rb', line 82 def stop_listening_for_pop `window.onpopstate = nil` end |