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

99 lines
3.9 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 reference = sections('', function(item) { return item.reference; });
nav.side-nav.l-pinned-left.l-layer-4.l-offset-nav
// SEARCH BAR
header.side-nav-search.st-input-wrapper
form.st-input-inner
label(for="search-io" class="is-hidden") 搜索文档
input(type="search" id="search-io" placeholder="搜索文档...")
button(class="mobile-trigger button" aria-label="查看文档菜单" ng-click="appCtrl.toggleDocsMenu($event)" md-button) 文档 <span class="icon icon-arrow-drop-down"></span>
div(class="side-nav-secondary" ng-class="appCtrl.showDocsNav ? 'is-visible' : ''")
.nav-blocks
.nav-title 指南
.nav-primary-link(class="#{qs.class}")
a(href="#{qs.href}" title="#{qs.tooltip}") #{qs.navTitle}
.nav-sub-title 案例: 英雄之旅
.nav-ordered-lists
ol
each item in tutorial
li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}
.nav-blocks
.nav-title 基础知识
.nav-ordered-lists
ol
each item in basics
li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}
.nav-blocks
.nav-title 开发人员指南
.nav-unordered-lists
ul
each item in guide
li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}
.nav-blocks
.nav-title Cookbook
.nav-unordered-lists
ul
each item in cookbook
li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}
.nav-blocks
.nav-title 参考
.nav-unordered-lists
ul
each item in reference
li(class="#{item.class}"): a(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}
script.
// Could put in appCtrl but only needed here and clear here
(function scrollToSelectedLink() {
var sideNav = document.getElementsByClassName('side-nav')[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);
}
})()