Sha256: d02fe2ce76b77b20188c2d7b8ba49538b6ffd7161bf6e3bd0f945eeb890dc11b

Contents?: true

Size: 826 Bytes

Versions: 55

Compression:

Stored size: 826 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?
      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

55 entries across 55 versions & 1 rubygems

Version Path
volt-0.6.5 lib/volt/page/url_tracker.rb
volt-0.6.4 lib/volt/page/url_tracker.rb
volt-0.6.3 lib/volt/page/url_tracker.rb
volt-0.6.2 lib/volt/page/url_tracker.rb
volt-0.6.1 lib/volt/page/url_tracker.rb
volt-0.6.0 lib/volt/page/url_tracker.rb
volt-0.5.18 lib/volt/page/url_tracker.rb
volt-0.5.17 lib/volt/page/url_tracker.rb
volt-0.5.16 lib/volt/page/url_tracker.rb
volt-0.5.15 lib/volt/page/url_tracker.rb
volt-0.5.14 lib/volt/page/url_tracker.rb
volt-0.5.13 lib/volt/page/url_tracker.rb
volt-0.5.12 lib/volt/page/url_tracker.rb
volt-0.5.11 lib/volt/page/url_tracker.rb
volt-0.5.10 lib/volt/page/url_tracker.rb
volt-0.5.9 lib/volt/page/url_tracker.rb
volt-0.5.8 lib/volt/page/url_tracker.rb
volt-0.5.7 lib/volt/page/url_tracker.rb
volt-0.5.6 lib/volt/page/url_tracker.rb
volt-0.5.4 lib/volt/page/url_tracker.rb