File: //usr/share/nodejs/turbolinks/src/turbolinks/snapshot.js
// Generated by CoffeeScript 1.12.8
(function() {
require('./head_details');
Turbolinks.Snapshot = (function() {
Snapshot.wrap = function(value) {
if (value instanceof this) {
return value;
} else if (typeof value === "string") {
return this.fromHTMLString(value);
} else {
return this.fromHTMLElement(value);
}
};
Snapshot.fromHTMLString = function(html) {
var htmlElement;
htmlElement = document.createElement("html");
htmlElement.innerHTML = html;
return this.fromHTMLElement(htmlElement);
};
Snapshot.fromHTMLElement = function(htmlElement) {
var bodyElement, headDetails, headElement, ref;
headElement = htmlElement.querySelector("head");
bodyElement = (ref = htmlElement.querySelector("body")) != null ? ref : document.createElement("body");
headDetails = Turbolinks.HeadDetails.fromHeadElement(headElement);
return new this(headDetails, bodyElement);
};
function Snapshot(headDetails1, bodyElement1) {
this.headDetails = headDetails1;
this.bodyElement = bodyElement1;
}
Snapshot.prototype.clone = function() {
return new this.constructor(this.headDetails, this.bodyElement.cloneNode(true));
};
Snapshot.prototype.getRootLocation = function() {
var ref, root;
root = (ref = this.getSetting("root")) != null ? ref : "/";
return new Turbolinks.Location(root);
};
Snapshot.prototype.getCacheControlValue = function() {
return this.getSetting("cache-control");
};
Snapshot.prototype.getElementForAnchor = function(anchor) {
try {
return this.bodyElement.querySelector("[id='" + anchor + "'], a[name='" + anchor + "']");
} catch (error) {}
};
Snapshot.prototype.getPermanentElements = function() {
return this.bodyElement.querySelectorAll("[id][data-turbolinks-permanent]");
};
Snapshot.prototype.getPermanentElementById = function(id) {
return this.bodyElement.querySelector("#" + id + "[data-turbolinks-permanent]");
};
Snapshot.prototype.getPermanentElementsPresentInSnapshot = function(snapshot) {
var element, i, len, ref, results;
ref = this.getPermanentElements();
results = [];
for (i = 0, len = ref.length; i < len; i++) {
element = ref[i];
if (snapshot.getPermanentElementById(element.id)) {
results.push(element);
}
}
return results;
};
Snapshot.prototype.findFirstAutofocusableElement = function() {
return this.bodyElement.querySelector("[autofocus]");
};
Snapshot.prototype.hasAnchor = function(anchor) {
return this.getElementForAnchor(anchor) != null;
};
Snapshot.prototype.isPreviewable = function() {
return this.getCacheControlValue() !== "no-preview";
};
Snapshot.prototype.isCacheable = function() {
return this.getCacheControlValue() !== "no-cache";
};
Snapshot.prototype.isVisitable = function() {
return this.getSetting("visit-control") !== "reload";
};
Snapshot.prototype.getSetting = function(name) {
return this.headDetails.getMetaValue("turbolinks-" + name);
};
return Snapshot;
})();
}).call(this);