Skip to content

Commit

Permalink
introduced (non standard) method current to history, in order to acce…
Browse files Browse the repository at this point in the history
…ss current uri from Location in a cleaner way
  • Loading branch information
dstendardi committed Aug 12, 2012
1 parent 2a19ffc commit 3d889af
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/zombie/history.coffee
Expand Up @@ -36,7 +36,11 @@ class History
# History is a stack of Entry objects.
@_stack = []
@_index = 0
@_location = new Location(this, ABOUT_BLANK)
@_location = new Location(this)

Object.defineProperty @, "current",
get: =>
@_stack[@_index]?.url || ABOUT_BLANK

# Apply to window.
_use: (window)->
Expand All @@ -45,8 +49,6 @@ class History
# Add Location/History to window.
Object.defineProperty @_window, "location",
get: =>
if @_stack[@_index]
@_location._url = @_stack[@_index].url
return @_location
set: (url)=>
@_assign @_resolve(url)
Expand Down Expand Up @@ -316,7 +318,7 @@ class History
#
# Represents window.location and document.location.
class Location
constructor: (@_history, @_url)->
constructor: (@_history)->

# ### location.assign(url)
assign: (newUrl)->
Expand All @@ -332,11 +334,11 @@ class Location

# ### location.toString() => String
toString: ->
return URL.format(@_url)
return URL.format(@_history.current)

# ### location.href => String
@prototype.__defineGetter__ "href", ->
return @_url?.href
return @_history.current?.href

# ### location.href = url
@prototype.__defineSetter__ "href", (new_url)->
Expand All @@ -346,9 +348,9 @@ class Location
for prop in ["hash", "host", "hostname", "pathname", "port", "protocol", "search"]
do (prop)=>
@prototype.__defineGetter__ prop, ->
@_url?[prop] || ""
@_history.current?[prop] || ""
@prototype.__defineSetter__ prop, (value)->
newUrl = URL.parse(@_url?.href)
newUrl = URL.parse(@_history.current?.href)
newUrl[prop] = value
@_history._assign URL.format(newUrl)

Expand Down

0 comments on commit 3d889af

Please sign in to comment.