UNPKG

2.58 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8Object.defineProperty(exports, "__esModule", { value: true });
9const components_1 = require("../components");
10const events_1 = require("../events");
11let NavigationPlugin = class NavigationPlugin extends components_1.RendererComponent {
12 initialize() {
13 this.listenTo(this.owner, {
14 [events_1.RendererEvent.BEGIN]: this.onBeginRenderer,
15 [events_1.PageEvent.BEGIN]: this.onBeginPage
16 });
17 }
18 onBeginRenderer(event) {
19 this.navigation = this.owner.theme.getNavigation(event.project);
20 }
21 onBeginPage(page) {
22 const currentItems = [];
23 (function updateItem(item) {
24 item.isCurrent = false;
25 item.isInPath = false;
26 item.isVisible = item.isGlobals;
27 if (item.url === page.url || (item.dedicatedUrls && item.dedicatedUrls.includes(page.url))) {
28 currentItems.push(item);
29 }
30 if (item.children) {
31 item.children.forEach((child) => updateItem(child));
32 }
33 })(this.navigation);
34 currentItems.forEach((item) => {
35 item.isCurrent = true;
36 let depth = item.isGlobals ? -1 : 0;
37 let count = 1;
38 while (item) {
39 item.isInPath = true;
40 item.isVisible = true;
41 count += 1;
42 depth += 1;
43 if (item.children) {
44 count += item.children.length;
45 if (depth < 2 || count < 30) {
46 item.children.forEach((child) => {
47 child.isVisible = true;
48 });
49 }
50 }
51 item = item.parent;
52 }
53 });
54 page.navigation = this.navigation;
55 }
56};
57NavigationPlugin = __decorate([
58 components_1.Component({ name: 'navigation' })
59], NavigationPlugin);
60exports.NavigationPlugin = NavigationPlugin;
61//# sourceMappingURL=NavigationPlugin.js.map
\No newline at end of file