File: //usr/share/nodejs/turbolinks/src/turbolinks/location.js
// Generated by CoffeeScript 1.12.8
(function() {
Turbolinks.Location = (function() {
var addTrailingSlash, getPrefixURL, stringEndsWith, stringStartsWith;
Location.wrap = function(value) {
if (value instanceof this) {
return value;
} else {
return new this(value);
}
};
function Location(url) {
var anchorLength, linkWithAnchor;
if (url == null) {
url = "";
}
linkWithAnchor = document.createElement("a");
linkWithAnchor.href = url.toString();
this.absoluteURL = linkWithAnchor.href;
anchorLength = linkWithAnchor.hash.length;
if (anchorLength < 2) {
this.requestURL = this.absoluteURL;
} else {
this.requestURL = this.absoluteURL.slice(0, -anchorLength);
this.anchor = linkWithAnchor.hash.slice(1);
}
}
Location.prototype.getOrigin = function() {
return this.absoluteURL.split("/", 3).join("/");
};
Location.prototype.getPath = function() {
var ref, ref1;
return (ref = (ref1 = this.requestURL.match(/\/\/[^\/]*(\/[^?;]*)/)) != null ? ref1[1] : void 0) != null ? ref : "/";
};
Location.prototype.getPathComponents = function() {
return this.getPath().split("/").slice(1);
};
Location.prototype.getLastPathComponent = function() {
return this.getPathComponents().slice(-1)[0];
};
Location.prototype.getExtension = function() {
var ref, ref1;
return (ref = (ref1 = this.getLastPathComponent().match(/\.[^.]*$/)) != null ? ref1[0] : void 0) != null ? ref : "";
};
Location.prototype.isHTML = function() {
return this.getExtension().match(/^(?:|\.(?:htm|html|xhtml))$/);
};
Location.prototype.isPrefixedBy = function(location) {
var prefixURL;
prefixURL = getPrefixURL(location);
return this.isEqualTo(location) || stringStartsWith(this.absoluteURL, prefixURL);
};
Location.prototype.isEqualTo = function(location) {
return this.absoluteURL === (location != null ? location.absoluteURL : void 0);
};
Location.prototype.toCacheKey = function() {
return this.requestURL;
};
Location.prototype.toJSON = function() {
return this.absoluteURL;
};
Location.prototype.toString = function() {
return this.absoluteURL;
};
Location.prototype.valueOf = function() {
return this.absoluteURL;
};
getPrefixURL = function(location) {
return addTrailingSlash(location.getOrigin() + location.getPath());
};
addTrailingSlash = function(url) {
if (stringEndsWith(url, "/")) {
return url;
} else {
return url + "/";
}
};
stringStartsWith = function(string, prefix) {
return string.slice(0, prefix.length) === prefix;
};
stringEndsWith = function(string, suffix) {
return string.slice(-suffix.length) === suffix;
};
return Location;
})();
}).call(this);