Sha256: 77d2094fffffa8960aac4bf09839a0c81c30c59be33e0756288f49de99c2e98e

Contents?: true

Size: 719 Bytes

Versions: 6

Compression:

Stored size: 719 Bytes

Contents

# The URLTracker is responsible for updating the url when
# a param changes, or updating the url model/params when
# the browser url changes.
class UrlTracker
  def initialize(page)
    @page = page

    if Volt.client?
      that = self

      # Setup popstate on the dom ready event.  Prevents an extra
      # popstate trigger
      %x{
        var first = true;
        window.addEventListener("popstate", function(e) {
          if (first === false) {
            that.$url_updated();
          }

          first = false;

          return true;
        });
      }
    end
  end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
volt-0.8.14 lib/volt/page/url_tracker.rb
volt-0.8.13 lib/volt/page/url_tracker.rb
volt-0.8.11 lib/volt/page/url_tracker.rb
volt-0.8.10 lib/volt/page/url_tracker.rb
volt-0.8.9 lib/volt/page/url_tracker.rb
volt-0.8.8 lib/volt/page/url_tracker.rb