Sha256: e3fcf17f085f1f485678c8954483a8102baba0a3bf602712878465ac16015294

Contents?: true

Size: 819 Bytes

Versions: 8

Compression:

Stored size: 819 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?
      # TODORW:
      # page.params.on('child_changed') do
      #   @page.url.update!
      # end

      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

8 entries across 8 versions & 1 rubygems

Version Path
volt-0.8.7 lib/volt/page/url_tracker.rb
volt-0.8.6 lib/volt/page/url_tracker.rb
volt-0.8.5 lib/volt/page/url_tracker.rb
volt-0.8.4 lib/volt/page/url_tracker.rb
volt-0.8.3 lib/volt/page/url_tracker.rb
volt-0.8.2 lib/volt/page/url_tracker.rb
volt-0.8.1 lib/volt/page/url_tracker.rb
volt-0.8.0 lib/volt/page/url_tracker.rb