turbolinks
Version:
Turbolinks makes navigating your web application faster
71 lines (50 loc) • 1.6 kB
text/coffeescript
class Turbolinks.Location
if value instanceof this
value
else
new this value
constructor: (url = "") ->
linkWithAnchor = document.createElement("a")
linkWithAnchor.href = url.toString()
anchorLength = linkWithAnchor.hash.length
if anchorLength < 2
else
getOrigin: ->
getPath: ->
getPathComponents: ->
getLastPathComponent: ->
getExtension: ->
isHTML: ->
isPrefixedBy: (location) ->
prefixURL = getPrefixURL(location)
isEqualTo: (location) ->
toCacheKey: ->
toJSON: ->
toString: ->
valueOf: ->
# Private
getPrefixURL = (location) ->
addTrailingSlash(location.getOrigin() + location.getPath())
addTrailingSlash = (url) ->
if stringEndsWith(url, "/") then url else url + "/"
stringStartsWith = (string, prefix) ->
string.slice(0, prefix.length) is prefix
stringEndsWith = (string, suffix) ->
string.slice(-suffix.length) is suffix