Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
79 lines (65 loc) · 1.84 KB
/
Copy pathmain.js
File metadata and controls
79 lines (65 loc) · 1.84 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
---
layout: null
---
$(function() {
var toc = $('.toc-link'),
sidebar = $('#sidebar'),
main = $('#main'),
menu = $('#menu'),
x1, y1;
// run this function after pjax load.
var afterPjax = function() {
// open links in new tab.
$('#main').find('a').filter(function() {
return this.hostname != window.location.hostname;
}).attr('target', '_blank');
// discus comment.
{% if site.disqus_shortname %}
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//{{ site.disqus_shortname }}' + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
{% endif %}
// your scripts
};
afterPjax();
// NProgress
NProgress.configure({ showSpinner: false });
// Pjax
$(document).pjax('#sidebar-avatar, .toc-link', '#main', {
fragment: '#main',
timeout: 3000
});
$(document).on({
'pjax:click': function() {
NProgress.start();
main.removeClass('fadeIn');
},
'pjax:end': function() {
afterPjax();
NProgress.done();
main.scrollTop(0).addClass('fadeIn');
menu.add(sidebar).removeClass('open');
{% if site.google_analytics %}
ga('set', 'location', window.location.href);
ga('send', 'pageview');
{% endif %}
}
});
// Tags Filter
$('#sidebar-tags').on('click', '.sidebar-tag', function() {
var filter = $(this).data('filter');
if (filter === 'all') {
toc.fadeIn(350);
} else {
toc.hide();
$('.toc-link[data-tags~=' + filter + ']').fadeIn(350);
}
$(this).addClass('active').siblings().removeClass('active');
});
// Menu
menu.on('click', function() {
$(this).add(sidebar).toggleClass('open');
});
});