Sha256: 7f439be5cb80fec1328c846521328743994d1b33cca4f370b5a578ac66e9d106

Contents?: true

Size: 1.56 KB

Versions: 15

Compression:

Stored size: 1.56 KB

Contents

class Turbolinks.Location
  @wrap: (value) ->
    if value instanceof this
      value
    else
      new this value

  constructor: (url = "") ->
    linkWithAnchor = document.createElement("a")
    linkWithAnchor.href = url.toString()

    @absoluteURL = linkWithAnchor.href

    anchorLength = linkWithAnchor.hash.length
    if anchorLength < 2
      @requestURL = @absoluteURL
    else
      @requestURL = @absoluteURL.slice(0, -anchorLength)
      @anchor = linkWithAnchor.hash.slice(1)

  getOrigin: ->
    @absoluteURL.split("/", 3).join("/")

  getPath: ->
    @requestURL.match(/\/\/[^/]*(\/[^?;]*)/)?[1] ? "/"

  getPathComponents: ->
    @getPath().split("/").slice(1)

  getLastPathComponent: ->
    @getPathComponents().slice(-1)[0]

  getExtension: ->
    @getLastPathComponent().match(/\.[^.]*$/)?[0] ? ""

  isHTML: ->
    @getExtension().match(/^(?:|\.(?:htm|html|xhtml))$/)

  isPrefixedBy: (location) ->
    prefixURL = getPrefixURL(location)
    @isEqualTo(location) or stringStartsWith(@absoluteURL, prefixURL)

  isEqualTo: (location) ->
    @absoluteURL is location?.absoluteURL

  toCacheKey: ->
    @requestURL

  toJSON: ->
    @absoluteURL

  toString: ->
    @absoluteURL

  valueOf: ->
    @absoluteURL

  # 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

Version data entries

15 entries across 14 versions & 6 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/turbolinks/src/turbolinks/location.coffee
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/turbolinks/src/turbolinks/location.coffee
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/turbolinks/src/turbolinks/location.coffee
ruby2js-4.0.4 lib/tasks/testrails/node_modules/turbolinks/src/turbolinks/location.coffee
ruby2js-4.0.3 lib/tasks/testrails/node_modules/turbolinks/src/turbolinks/location.coffee
jester-data-8.0.0 node_modules/turbolinks/src/turbolinks/location.coffee
ezii-os-5.2.1 node_modules/turbolinks/src/turbolinks/location.coffee
ezii-os-2.0.1 node_modules/turbolinks/src/turbolinks/location.coffee
ezii-os-1.1.0 node_modules/turbolinks/src/turbolinks/location.coffee
ezii-os-1.0.0 node_modules/turbolinks/src/turbolinks/location.coffee
ezii-os-0.0.0.1.0 node_modules/turbolinks/src/turbolinks/location.coffee
ezii-os-0.0.0.0.1 node_modules/turbolinks/src/turbolinks/location.coffee
rails_auth-1.0.6 test/dummy/node_modules/turbolinks/src/turbolinks/location.coffee
rails_auth-1.0.5 test/dummy/node_modules/turbolinks/src/turbolinks/location.coffee
rails_auth-1.0.4 test/dummy/node_modules/turbolinks/src/turbolinks/location.coffee