forked from TheThingsNetwork/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
104 lines (81 loc) · 2.39 KB
/
main.js
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
97
98
99
100
101
102
103
104
require('tocbot');
require('ttn-stylebook/dist/js/bootstrap');
var AnchorJS = require('anchor-js');
$(function() {
var contentOffset = 100;
var smoothScrollOptions = {
selector: 'a',
easing: 'easeInOutCubic',
offset: contentOffset,
speed: 300,
updateURL: true
};
if ($('.layout-guide').length) {
/**
* Anchor-JS
*/
var anchors = new AnchorJS();
anchors.add('.js-toc-content h1, .js-toc-content h2');
/**
* TocBot Sidebar
*/
tocbot.init({
headingSelector: 'h1, h2',
activeLinkClass: 'active',
extraListClasses: 'nav',
headingsOffset: contentOffset,
smoothScrollOptions: smoothScrollOptions
});
$('.guide-sidebar').affix({
offset: {
top: contentOffset
}
});
// enable smooth scroll, including the offset set through tocbot
$('.anchorjs-link').attr('data-scroll', 'data-scroll');
/**
* ClipboardJS
*/
$('.highlighter-rouge .highlight').before('<span class="btn-clipboard">Copy</span>');
var Clipboard = require('clipboard');
var clipboard = new Clipboard('.btn-clipboard', {
target: function(trigger) {
return trigger.nextElementSibling;
}
});
clipboard.on('success', function(e) {
$(e.trigger).attr('title', 'Copied!').tooltip('show').on('shown.bs.tooltip', function() {
setTimeout(function() {
$(e.trigger).removeAttr('title').tooltip('destroy');
}, 500);
});
e.clearSelection();
});
clipboard.on('error', function(e) {
$(e.trigger).attr('title', 'Press Ctrl/⌘ + C to copy!').tooltip('show').on('shown.bs.tooltip', function() {
setTimeout(function() {
$(e.trigger).removeAttr('title').tooltip('destroy');
}, 500);
});
});
} else {
// so that front-page content scroll to below navbar as well
var smoothScroll = require('tocbot/node_modules/smooth-scroll');
smoothScroll.init(smoothScrollOptions);
}
/**
* Tooltips
*/
$('[data-toggle="tooltip"]').tooltip();
/**
* Disabled links
*/
$('a[disabled][href]').attr('href', 'javascript:void(0)');
/**
* External links (http://stackoverflow.com/a/13147238)
*/
for (var c = document.getElementsByTagName('a'), a = 0; a < c.length; a++) {
var b = c[a];
b.getAttribute('href') && b.hostname !== location.hostname && (b.target = '_blank');
}
});