This repository was archived by the owner on Nov 1, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathdocumentation.js
More file actions
96 lines (86 loc) · 3.2 KB
/
documentation.js
File metadata and controls
96 lines (86 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Init sidebar
$(function() {
var activeItem,
helpList = $('#js-sidebar .js-topic'),
firstOccurance = true,
styleTOC = function() {
var pathRegEx = /\/\/[^\/]+([A-Za-z0-9-_./]+)/g,
docUrl = pathRegEx.exec(window.location.toString())
if (docUrl){
$('#js-sidebar .js-topic a').each(function(){
if ($(this).parent('li').hasClass('disable'))
$(this).parent('li').removeClass('disable')
var url = $(this).attr('href').toString()
var cleanDocUrl = docUrl[1]
if(url.indexOf(cleanDocUrl) >= 0 && url.length == cleanDocUrl.length){
$(this).parent('li').addClass('disable')
var parentTopic = $(this).parentsUntil('div.sidebar-module > ul').last()
parentTopic.addClass('js-current')
parentTopic.find('.js-expand-btn').toggleClass('collapsed expanded')
}
});
}
}
// bind every href with a hash; take a look at v3/search/ for example
$('#js-sidebar .js-accordion-list .js-topic a[href*=#]').bind("click", function(e) {
if (window.location.toString().indexOf($(e.target).attr('href')) == -1)
setTimeout(styleTOC, 0); // trigger the window.location change, then stylize
});
// hide list items at startup
if($('body.api') && window.location){
styleTOC();
}
$('#js-sidebar .js-topic').each(function(){
if(($(this).find('.disable').length == 0 || firstOccurance == false) &&
$(this).hasClass('js-current') != true){
$(this).find('.js-guides').children().hide()
} else {
activeItem = $(this).index()
firstOccurance = false
}
})
// Toggle style list. Expanded items stay
// expanded when new items are clicked.
$('#js-sidebar .js-toggle-list .js-expand-btn').click(function(){
var clickedTopic = $(this).parents('.js-topic'),
topicGuides = clickedTopic.find('.js-guides li')
$(this).toggleClass('collapsed expanded')
topicGuides.slideToggle(100)
return false
})
// Accordion style list. Expanded items
// collapse when new items are clicked.
$('#js-sidebar .js-accordion-list .js-topic h3 a').click(function(){
var clickedTopic = $(this).parents('.js-topic'),
topicGuides = clickedTopic.find('.js-guides li')
if(activeItem != clickedTopic.index()){
if(helpList.eq(activeItem)){
helpList.eq(activeItem).find('.js-guides li').slideToggle(100)
}
activeItem = clickedTopic.index()
topicGuides.slideToggle(100)
} else {
activeItem = undefined
topicGuides.slideToggle(100)
}
return false
})
// Grab API status
$.getJSON('https://status.github.com/api/status.json?callback=?', function(data) {
if(data) {
var link = $("<a>")
.attr("href", "https://status.github.com")
.addClass(data.status)
.attr("title", "API Status: " + data.status + ". Click for details.")
.text("API Status: " + data.status);
$('.api-status').html(link);
}
});
// Earth animation
if ($('.dev-program').length) {
setTimeout(function() {
$('.earth').fadeOut();
$('.earth-short-loop').show();
}, 19 * 1000); // Let first loop run through 19 seconds
}
});