Class: Volt::UrlTracker

Inherits:
Object show all
Defined in:
lib/volt/page/url_tracker.rb

Overview

The URLTracker is responsible for updating the url when a param changes, or updating the url model/params when the browser url changes.

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ UrlTracker

Returns a new instance of UrlTracker.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/volt/page/url_tracker.rb', line 6

def initialize(page)
  @page = page

  if Volt.client?
    that = self

    # Setup popstate on the dom ready event.  Prevents an extra
    # popstate trigger
    `
      window.addEventListener("popstate", function(e) {
        that.$url_updated();
        return true;
      });
    `
  end
end

Instance Method Details

#url_updated(first_call = false) ⇒ Object



23
24
25
26
# File 'lib/volt/page/url_tracker.rb', line 23

def url_updated(first_call = false)
  @page.url.parse(`document.location.href`)
  @page.url.update! unless first_call
end