angular-cn/public/docs/_includes/_side-nav.jade

150 lines
6.5 KiB
Plaintext

// Include this file ONLY when current.path[2] is defined
- var base = '/docs/' + current.path[1] + '/' + current.path[2] + '/';
- var dir = current.path[4] ? current.path[3] + '/' : '';
- var cur = current.path[4] || current.path[3];
- cur = cur === 'index' ? '' : cur + '.html';
- cur = base + dir + cur;
- var sections = function(dir, selector) {
- var secondaryPath = public.docs[current.path[1]][current.path[2]]
- var data = dir ? secondaryPath[dir] && secondaryPath[dir]._data : secondaryPath._data;
- if (!data) return [];
- var section = [];
- var selector = selector || function() { return true; };
- var prefix = base + (dir ? dir + '/' : '');
- for (prop in data) {
- var item = data[prop];
- item.slug = prop;
- if (prop[0] !== '_' && !item.hide && selector(item)) {
- var file = pro
- var ext = prop.lastIndexOf('/') === prop.length-1 ? '' : '.html';
- var file = prop === 'index' ? '' : prop + ext;
- var href = prefix + file;
- item.class = cur === href ? 'is-selected' : '';
- item.file = file;
- item.href = href;
- item.navTitle = item.navTitle || item.title;
- item.tooltip = item.description || item.intro || item.title || '';
- section.push(item);
- }
- }
- return section;
- }
- var tutorial = sections('tutorial');
- var cookbook = sections('cookbook');
- var basics = sections('guide', function(item) { return item.basics; });
- var guide = sections('guide', function(item) { return !item.basics; });
- var qs = sections('', function(item) { return item.slug === 'quickstart'; })[0] || {};
- var cliqs = sections('', function(item) { return item.slug === 'cli-quickstart'; })[0] || {};
- var reference = sections('', function(item) { return item.reference; });
- var anyItemSelected = function(items) {
- var selectedCount = items.filter(function(item) { return !!item.class; }).length;
- return selectedCount > 0 ? 'is-selected' : '';
- }
- var isQuickstartSelected = function() {
- var splitted = cur.split('/');
- var bit = splitted[splitted.length - 1].replace('.html', '');
- return bit === 'quickstart' ? 'is-selected' : '';
-}
- var isCLIQuickstartSelected = function() {
- var split = cur.split('/');
- var bit = split[split.length - 1].replace('.html', '');
- return bit === 'cli-quickstart' ? 'is-selected' : '';
-}
- var isApiReferenceSelected = function() {
- var splitted = cur.split('/');
- var bit = splitted[splitted.length - 2];
- return bit === 'api' ? 'is-selected' : '';
-}
- var isCollapsed = function(titleStyle) {
- return titleStyle === 'is-selected' ? '' : 'is-hidden';
- }
- var language = current.path[1] || 'ts'
- if (language !== 'ts' || language !== 'js' || language !== 'dart') { language = 'ts'; }
nav(class="sidenav l-pinned-left l-layer-4 l-offset-nav" data-swiftype-index="false" ng-class="appCtrl.showDocsNav ? 'is-visible' : ''")
// SEARCH BAR
header.sidenav-search.st-input-wrapper
.st-input-inner
label(for="search-io" class="is-hidden") Search Docs
input(type="text" class="st-default-search-input" placeholder="SEARCH DOCS...")
button(class="mobile-trigger button" aria-label="View Docs Menu" ng-click="appCtrl.toggleDocsMenu($event)" md-button) Docs <span class="icon icon-arrow-drop-down"></span>
ul(class="sidenav-links")
li.sidenav-section.no-border
a(class="nav-title" href="/docs/#{current.path[1]}/latest/") Docs Home
// CORE DOCUMENTATION
li.sidenav-section-divider
h3 Core Documentation
li.sidenav-section
a(class="nav-title #{isQuickstartSelected(cur)}" href="#{qs.href}" title="#{qs.tooltip}") Quickstart
li.sidenav-section
a(class="nav-title #{isCLIQuickstartSelected(cur)}" href="#{cliqs.href}" title="#{cliqs.tooltip}") CLI Quickstart
li.sidenav-section
a(class="nav-title is-parent #{anyItemSelected(basics)}" href="#{basics[0].href}" title="#{basics[0].tooltip}") Guide
img(class="inline-arrow-down-svg" src="/resources/images/icons/ic_keyboard_arrow_down_black_24px.svg")
.nav-ordered-lists(class="#{isCollapsed(anyItemSelected(basics))}")
ul
each item, index in basics
li(class="nav-list-item #{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{index + 1}. #{item.navTitle}
li.sidenav-section.no-border
a(class="nav-title #{isApiReferenceSelected()}" href="#{reference[0].href}" title="#{reference[0].tooltip}") API Reference
// ADVANCED DOCUMENATION
li.sidenav-section-divider
h3 Additional Documentation
li.sidenav-section
a(class="nav-title is-parent #{anyItemSelected(tutorial)}" href="#{tutorial[0].href}" title="#{tutorial[0].tooltip}") Tutorial
img(class="inline-arrow-down-svg" src="/resources/images/icons/ic_keyboard_arrow_down_black_24px.svg")
.nav-ordered-lists(class="#{isCollapsed(anyItemSelected(tutorial))}")
ul
each item, index in tutorial
li(class="nav-list-item #{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{index + 1}. #{item.navTitle}
li.sidenav-section
a(class="nav-title is-parent #{anyItemSelected(guide)}" href="#{guide[0].href}" title="#{guide[0].tooltip}") Advanced
img(class="inline-arrow-down-svg" src="/resources/images/icons/ic_keyboard_arrow_down_black_24px.svg")
.nav-unordered-lists(class="#{isCollapsed(anyItemSelected(guide))}")
ul
each item in guide
li(class="nav-list-item #{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}
li.sidenav-section
a(class="nav-title is-parent #{anyItemSelected(cookbook)}" href="#{cookbook[0].href}" title="#{cookbook[0].tooltip}") Cookbook
img(class="inline-arrow-down-svg" src="/resources/images/icons/ic_keyboard_arrow_down_black_24px.svg")
.nav-unordered-lists(class="#{isCollapsed(anyItemSelected(cookbook))}")
ul
each item in cookbook
li(class="nav-list-item #{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}
if current.path[0] == "docs"
!= partial("../../_includes/_version-dropdown")
script.
// Could put in appCtrl but only needed here and clear here
(function scrollToSelectedLink() {
var sideNav = document.getElementsByClassName('sidenav')[0];
var link = sideNav.getElementsByClassName('is-selected')[0];
if(link && link.offsetTop > window.innerHeight){
sideNav.scrollTop = link.offsetTop - (window.innerHeight/2);
//alert("offsetTop: " + link.offsetTop + " side-nav top is " + sideNav.scrollTop);
}
})()