 #########
 # Earl
+# The MIT License (MIT)
+# Copyright (c) Travis Kriplean, Consider.it LLC
 # 
 # Hire Earl to handle the browser history & location bar. 
 #

# Enables history aware link. Wraps basic dom.A.

if hist_aware

  window.dom = window.dom || {}

  dom.A = ->
    props = @props
    if @props.href
      href = @props.href


    # enough to deal with the mightly Webkit browser's imposition of 
    # a remembered scroll position for a return visitor upon initial 
    # page load!
    if Earl.seek_to_hash && !@int

      @int = setInterval -> 
        Earl.seek_to_hash = false
        el = document.getElementById("#{loc.hash}") or document.querySelector("[name='#{loc.hash}']")
        if el
          window.scrollTo 0, getCoords(el).top - 50

          if loc.query_params.c 
            delete loc.query_params.c 
            delete loc.hash
            save loc

          clearInterval @int 
          @int = null

      , 50

  monitor()


url_from_browser_location = -> 
  # location.search returns the query parameters
