turbolinks
Version:
Turbolinks makes navigating your web application faster
66 lines (47 loc) • 1.83 kB
text/coffeescript
#= require ./head_details
class Turbolinks.Snapshot
: (value) ->
if value instanceof this
value
else if typeof value == "string"
else
: (html) ->
htmlElement = document.createElement("html")
htmlElement.innerHTML = html
: (htmlElement) ->
headElement = htmlElement.querySelector("head")
bodyElement = htmlElement.querySelector("body") ? document.createElement("body")
headDetails = Turbolinks.HeadDetails.fromHeadElement(headElement)
new this headDetails, bodyElement
constructor: ( , ) ->
clone: ->
new , .cloneNode(true)
getRootLocation: ->
root = ? "/"
new Turbolinks.Location root
getCacheControlValue: ->
getElementForAnchor: (anchor) ->
try .querySelector("[id='#{anchor}'], a[name='#{anchor}']")
getPermanentElements: ->
.querySelectorAll("[id][data-turbolinks-permanent]")
getPermanentElementById: (id) ->
.querySelector("##{id}[data-turbolinks-permanent]")
getPermanentElementsPresentInSnapshot: (snapshot) ->
element for element in when snapshot.getPermanentElementById(element.id)
findFirstAutofocusableElement: ->
.querySelector("[autofocus]")
hasAnchor: (anchor) ->
?
isPreviewable: ->
isnt "no-preview"
isCacheable: ->
isnt "no-cache"
isVisitable: ->
isnt "reload"
# Private
getSetting: (name) ->
.getMetaValue("turbolinks-#{name}")