UNPKG

5.11 kBJavaScriptView Raw
1function getSearchTerm()
2{
3 var sPageURL = window.location.search.substring(1);
4 var sURLVariables = sPageURL.split('&');
5 for (var i = 0; i < sURLVariables.length; i++)
6 {
7 var sParameterName = sURLVariables[i].split('=');
8 if (sParameterName[0] == 'q')
9 {
10 return sParameterName[1];
11 }
12 }
13}
14
15$(document).ready(function() {
16
17 var search_term = getSearchTerm(),
18 $search_modal = $('#mkdocs_search_modal'),
19 $keyboard_modal = $('#mkdocs_keyboard_modal');
20
21 if(search_term){
22 $search_modal.modal();
23 }
24
25 // make sure search input gets autofocus everytime modal opens.
26 $search_modal.on('shown.bs.modal', function () {
27 $search_modal.find('#mkdocs-search-query').focus();
28 });
29
30 // Close search modal when result is selected
31 // The links get added later so listen to parent
32 $('#mkdocs-search-results').click(function(e) {
33 if ($(e.target).is('a')) {
34 $search_modal.modal('hide');
35 }
36 });
37
38 // Populate keyboard modal with proper Keys
39 $keyboard_modal.find('.help.shortcut kbd')[0].innerHTML = keyCodes[shortcuts.help];
40 $keyboard_modal.find('.prev.shortcut kbd')[0].innerHTML = keyCodes[shortcuts.previous];
41 $keyboard_modal.find('.next.shortcut kbd')[0].innerHTML = keyCodes[shortcuts.next];
42 $keyboard_modal.find('.search.shortcut kbd')[0].innerHTML = keyCodes[shortcuts.search];
43
44 // Keyboard navigation
45 document.addEventListener("keydown", function(e) {
46 if ($(e.target).is(':input')) return true;
47 var key = e.which || e.keyCode || window.event && window.event.keyCode;
48 var page;
49 switch (key) {
50 case shortcuts.next:
51 page = $('[role="navigation"] a:contains(Next):first').prop('href');
52 break;
53 case shortcuts.previous:
54 page = $('[role="navigation"] a:contains(Previous):first').prop('href');
55 break;
56 case shortcuts.search:
57 e.preventDefault();
58 $keyboard_modal.modal('hide');
59 $search_modal.modal('show');
60 $search_modal.find('#mkdocs-search-query').focus();
61 break;
62 case shortcuts.help:
63 $search_modal.modal('hide');
64 $keyboard_modal.modal('show');
65 break;
66 default: break;
67 }
68 if (page) {
69 $keyboard_modal.modal('hide');
70 window.location.href = page;
71 }
72 });
73
74 $('table').addClass('table table-striped table-hover');
75
76 // Improve the scrollspy behaviour when users click on a TOC item.
77 $(".bs-sidenav a").on("click", function() {
78 var clicked = this;
79 setTimeout(function() {
80 var active = $('.nav li.active a');
81 active = active[active.length - 1];
82 if (clicked !== active) {
83 $(active).parent().removeClass("active");
84 $(clicked).parent().addClass("active");
85 }
86 }, 50);
87 });
88
89});
90
91
92$('body').scrollspy({
93 target: '.bs-sidebar',
94 offset: 100
95});
96
97/* Prevent disabled links from causing a page reload */
98$("li.disabled a").click(function() {
99 event.preventDefault();
100});
101
102// See https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
103// We only list common keys below. Obscure keys are omited and their use is discouraged.
104var keyCodes = {
105 8: 'backspace',
106 9: 'tab',
107 13: 'enter',
108 16: 'shift',
109 17: 'ctrl',
110 18: 'alt',
111 19: 'pause/break',
112 20: 'caps lock',
113 27: 'escape',
114 32: 'spacebar',
115 33: 'page up',
116 34: 'page down',
117 35: 'end',
118 36: 'home',
119 37: '&larr;',
120 38: '&uarr;',
121 39: '&rarr;',
122 40: '&darr;',
123 45: 'insert',
124 46: 'delete',
125 48: '0',
126 49: '1',
127 50: '2',
128 51: '3',
129 52: '4',
130 53: '5',
131 54: '6',
132 55: '7',
133 56: '8',
134 57: '9',
135 65: 'a',
136 66: 'b',
137 67: 'c',
138 68: 'd',
139 69: 'e',
140 70: 'f',
141 71: 'g',
142 72: 'h',
143 73: 'i',
144 74: 'j',
145 75: 'k',
146 76: 'l',
147 77: 'm',
148 78: 'n',
149 79: 'o',
150 80: 'p',
151 81: 'q',
152 82: 'r',
153 83: 's',
154 84: 't',
155 85: 'u',
156 86: 'v',
157 87: 'w',
158 88: 'x',
159 89: 'y',
160 90: 'z',
161 91: 'Left Windows Key / Left ⌘',
162 92: 'Right Windows Key',
163 93: 'Windows Menu / Right ⌘',
164 96: 'numpad 0',
165 97: 'numpad 1',
166 98: 'numpad 2',
167 99: 'numpad 3',
168 100: 'numpad 4',
169 101: 'numpad 5',
170 102: 'numpad 6',
171 103: 'numpad 7',
172 104: 'numpad 8',
173 105: 'numpad 9',
174 106: 'multiply',
175 107: 'add',
176 109: 'subtract',
177 110: 'decimal point',
178 111: 'divide',
179 112: 'f1',
180 113: 'f2',
181 114: 'f3',
182 115: 'f4',
183 116: 'f5',
184 117: 'f6',
185 118: 'f7',
186 119: 'f8',
187 120: 'f9',
188 121: 'f10',
189 122: 'f11',
190 123: 'f12',
191 124: 'f13',
192 125: 'f14',
193 126: 'f15',
194 127: 'f16',
195 128: 'f17',
196 129: 'f18',
197 130: 'f19',
198 131: 'f20',
199 132: 'f21',
200 133: 'f22',
201 134: 'f23',
202 135: 'f24',
203 144: 'num lock',
204 145: 'scroll lock',
205 186: '&semi;',
206 187: '&equals;',
207 188: '&comma;',
208 189: '&hyphen;',
209 190: '&period;',
210 191: '&quest;',
211 192: '&grave;',
212 219: '&lsqb;',
213 220: '&bsol;',
214 221: '&rsqb;',
215 222: '&apos;',
216};