opds-web-client
Version:
67 lines (66 loc) • 2.53 kB
JavaScript
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var React = require("react");
var CatalogLink_1 = require("./CatalogLink");
var Breadcrumbs = (function (_super) {
__extends(Breadcrumbs, _super);
function Breadcrumbs() {
return _super.apply(this, arguments) || this;
}
Breadcrumbs.prototype.render = function () {
var _this = this;
return (React.createElement("ol", { className: "breadcrumb", "aria-label": "breadcrumbs", role: "navigation" }, this.props.links && this.props.links.map(function (link, i) {
return React.createElement("li", { key: link.url },
React.createElement(CatalogLink_1.default, { collectionUrl: link.url, bookUrl: null }, i === _this.props.links.length - 1 ? React.createElement("strong", null, link.text) : link.text));
})));
};
return Breadcrumbs;
}(React.Component));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Breadcrumbs;
function defaultComputeBreadcrumbs(collection, history) {
var links = history ? history.slice(0) : [];
if (collection) {
links.push({
url: collection.url,
text: collection.title
});
}
return links;
}
exports.defaultComputeBreadcrumbs = defaultComputeBreadcrumbs;
function hierarchyComputeBreadcrumbs(collection, history, comparator) {
var links = [];
if (!collection) {
return [];
}
if (!comparator) {
comparator = function (url1, url2) { return (url1 === url2); };
}
var catalogRootLink = collection.catalogRootLink, parentLink = collection.parentLink;
if (catalogRootLink && !comparator(catalogRootLink.url, collection.url)) {
links.push({
text: catalogRootLink.text || "Catalog",
url: catalogRootLink.url
});
}
if (parentLink && parentLink.url && parentLink.text &&
(!catalogRootLink || !comparator(parentLink.url, catalogRootLink.url)) &&
!comparator(parentLink.url, collection.url)) {
links.push({
text: parentLink.text,
url: parentLink.url
});
}
links.push({
url: collection.url,
text: collection.title
});
return links;
}
exports.hierarchyComputeBreadcrumbs = hierarchyComputeBreadcrumbs;
;
;