forked from TheThingsNetwork/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_page.js
89 lines (73 loc) · 1.96 KB
/
_page.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
require('./_toc.js');
require('stylebook/dist/js/bootstrap');
var Clipboard = require('clipboard');
var AnchorJS = require('anchor-js');
$(function () {
/**
* TOC
*/
$('.page-toc').toc({
title: '',
listType: 'ul',
headers: '.page-content h2, .page-content h3, .page-content h4',
minimumHeaders: 1
});
/**
* ClipboardJS
*/
$('.highlighter-rouge .highlight').before('<span class="btn-clipboard">Copy</span>');
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);
});
});
/**
* Lightbox
*/
$('#lightbox .modal-dialog').click(function () {
$('#lightbox').modal('hide');
});
$('.page-content :not(a) img').click(function () {
var src = this.getAttribute('src');
if (window.innerWidth >= 768) {
$('#lightbox a').attr('href', src);
$('#lightbox img').attr('src', src);
$('#lightbox').modal('show');
} else {
window.open(src);
}
});
/**
* Anchors
*/
var anchors = new AnchorJS();
anchors.add('.page-content h2, .page-content h3, .page-content h4');
/**
* Affix
*/
$('.page-affix').affix({
offset: {
top: $('.page-side-nav').parent().offset().top - 30,
bottom: 30
}
}).on('affix-top.bs.affix', function() {
$(this).width('auto');
}).on('affix.bs.affix', function() {
$(this).width($(this).parent().width());
});
});