base.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. function getSearchTerm() {
  2. var sPageURL = window.location.search.substring(1);
  3. var sURLVariables = sPageURL.split('&');
  4. for (var i = 0; i < sURLVariables.length; i++) {
  5. var sParameterName = sURLVariables[i].split('=');
  6. if (sParameterName[0] == 'q') {
  7. return sParameterName[1];
  8. }
  9. }
  10. }
  11. function applyTopPadding() {
  12. // Update various absolute positions to match where the main container
  13. // starts. This is necessary for handling multi-line nav headers, since
  14. // that pushes the main container down.
  15. var offset = $('body > .container').offset();
  16. $('html').css('scroll-padding-top', offset.top + 'px');
  17. $('.bs-sidebar.affix').css('top', offset.top + 'px');
  18. }
  19. $(document).ready(function() {
  20. applyTopPadding();
  21. var search_term = getSearchTerm(),
  22. $search_modal = $('#mkdocs_search_modal'),
  23. $keyboard_modal = $('#mkdocs_keyboard_modal');
  24. if (search_term) {
  25. $search_modal.modal();
  26. }
  27. // make sure search input gets autofocus every time modal opens.
  28. $search_modal.on('shown.bs.modal', function() {
  29. $search_modal.find('#mkdocs-search-query').focus();
  30. });
  31. // Close search modal when result is selected
  32. // The links get added later so listen to parent
  33. $('#mkdocs-search-results').click(function(e) {
  34. if ($(e.target).is('a')) {
  35. $search_modal.modal('hide');
  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. // Keyboard navigation
  44. document.addEventListener("keydown", function(e) {
  45. if ($(e.target).is(':input')) return true;
  46. var key = e.which || e.keyCode || window.event && window.event.keyCode;
  47. var page;
  48. switch (key) {
  49. case shortcuts.next:
  50. page = $('.navbar a[rel="next"]:first').prop('href');
  51. break;
  52. case shortcuts.previous:
  53. page = $('.navbar a[rel="prev"]:first').prop('href');
  54. break;
  55. case shortcuts.search:
  56. e.preventDefault();
  57. $keyboard_modal.modal('hide');
  58. $search_modal.modal('show');
  59. $search_modal.find('#mkdocs-search-query').focus();
  60. break;
  61. case shortcuts.help:
  62. $search_modal.modal('hide');
  63. $keyboard_modal.modal('show');
  64. break;
  65. default: break;
  66. }
  67. if (page) {
  68. $keyboard_modal.modal('hide');
  69. window.location.href = page;
  70. }
  71. });
  72. $('table').addClass('table table-striped table-hover');
  73. // Improve the scrollspy behaviour when users click on a TOC item.
  74. $(".bs-sidenav a").on("click", function() {
  75. var clicked = this;
  76. setTimeout(function() {
  77. var active = $('.nav li.active a');
  78. active = active[active.length - 1];
  79. if (clicked !== active) {
  80. $(active).parent().removeClass("active");
  81. $(clicked).parent().addClass("active");
  82. }
  83. }, 50);
  84. });
  85. function showInnerDropdown(item) {
  86. var popup = $(item).next('.dropdown-menu');
  87. popup.addClass('show');
  88. $(item).addClass('open');
  89. // First, close any sibling dropdowns.
  90. var container = $(item).parent().parent();
  91. container.find('> .dropdown-submenu > a').each(function(i, el) {
  92. if (el !== item) {
  93. hideInnerDropdown(el);
  94. }
  95. });
  96. var popupMargin = 10;
  97. var maxBottom = $(window).height() - popupMargin;
  98. var bounds = item.getBoundingClientRect();
  99. popup.css('left', bounds.right + 'px');
  100. if (bounds.top + popup.height() > maxBottom &&
  101. bounds.top > $(window).height() / 2) {
  102. popup.css({
  103. 'top': (bounds.bottom - popup.height()) + 'px',
  104. 'max-height': (bounds.bottom - popupMargin) + 'px',
  105. });
  106. } else {
  107. popup.css({
  108. 'top': bounds.top + 'px',
  109. 'max-height': (maxBottom - bounds.top) + 'px',
  110. });
  111. }
  112. }
  113. function hideInnerDropdown(item) {
  114. var popup = $(item).next('.dropdown-menu');
  115. popup.removeClass('show');
  116. $(item).removeClass('open');
  117. popup.scrollTop(0);
  118. popup.find('.dropdown-menu').scrollTop(0).removeClass('show');
  119. popup.find('.dropdown-submenu > a').removeClass('open');
  120. }
  121. $('.dropdown-submenu > a').on('click', function(e) {
  122. if ($(this).next('.dropdown-menu').hasClass('show')) {
  123. hideInnerDropdown(this);
  124. } else {
  125. showInnerDropdown(this);
  126. }
  127. e.stopPropagation();
  128. e.preventDefault();
  129. });
  130. $('.dropdown-menu').parent().on('hide.bs.dropdown', function(e) {
  131. $(this).find('.dropdown-menu').scrollTop(0);
  132. $(this).find('.dropdown-submenu > a').removeClass('open');
  133. $(this).find('.dropdown-menu .dropdown-menu').removeClass('show');
  134. });
  135. });
  136. $(window).on('resize', applyTopPadding);
  137. $('body').scrollspy({
  138. target: '.bs-sidebar',
  139. offset: 100
  140. });
  141. /* Prevent disabled links from causing a page reload */
  142. $("li.disabled a").click(function() {
  143. event.preventDefault();
  144. });
  145. // See https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
  146. // We only list common keys below. Obscure keys are omitted and their use is discouraged.
  147. var keyCodes = {
  148. 8: 'backspace',
  149. 9: 'tab',
  150. 13: 'enter',
  151. 16: 'shift',
  152. 17: 'ctrl',
  153. 18: 'alt',
  154. 19: 'pause/break',
  155. 20: 'caps lock',
  156. 27: 'escape',
  157. 32: 'spacebar',
  158. 33: 'page up',
  159. 34: 'page down',
  160. 35: 'end',
  161. 36: 'home',
  162. 37: '&larr;',
  163. 38: '&uarr;',
  164. 39: '&rarr;',
  165. 40: '&darr;',
  166. 45: 'insert',
  167. 46: 'delete',
  168. 48: '0',
  169. 49: '1',
  170. 50: '2',
  171. 51: '3',
  172. 52: '4',
  173. 53: '5',
  174. 54: '6',
  175. 55: '7',
  176. 56: '8',
  177. 57: '9',
  178. 65: 'a',
  179. 66: 'b',
  180. 67: 'c',
  181. 68: 'd',
  182. 69: 'e',
  183. 70: 'f',
  184. 71: 'g',
  185. 72: 'h',
  186. 73: 'i',
  187. 74: 'j',
  188. 75: 'k',
  189. 76: 'l',
  190. 77: 'm',
  191. 78: 'n',
  192. 79: 'o',
  193. 80: 'p',
  194. 81: 'q',
  195. 82: 'r',
  196. 83: 's',
  197. 84: 't',
  198. 85: 'u',
  199. 86: 'v',
  200. 87: 'w',
  201. 88: 'x',
  202. 89: 'y',
  203. 90: 'z',
  204. 91: 'Left Windows Key / Left ⌘',
  205. 92: 'Right Windows Key',
  206. 93: 'Windows Menu / Right ⌘',
  207. 96: 'numpad 0',
  208. 97: 'numpad 1',
  209. 98: 'numpad 2',
  210. 99: 'numpad 3',
  211. 100: 'numpad 4',
  212. 101: 'numpad 5',
  213. 102: 'numpad 6',
  214. 103: 'numpad 7',
  215. 104: 'numpad 8',
  216. 105: 'numpad 9',
  217. 106: 'multiply',
  218. 107: 'add',
  219. 109: 'subtract',
  220. 110: 'decimal point',
  221. 111: 'divide',
  222. 112: 'f1',
  223. 113: 'f2',
  224. 114: 'f3',
  225. 115: 'f4',
  226. 116: 'f5',
  227. 117: 'f6',
  228. 118: 'f7',
  229. 119: 'f8',
  230. 120: 'f9',
  231. 121: 'f10',
  232. 122: 'f11',
  233. 123: 'f12',
  234. 124: 'f13',
  235. 125: 'f14',
  236. 126: 'f15',
  237. 127: 'f16',
  238. 128: 'f17',
  239. 129: 'f18',
  240. 130: 'f19',
  241. 131: 'f20',
  242. 132: 'f21',
  243. 133: 'f22',
  244. 134: 'f23',
  245. 135: 'f24',
  246. 144: 'num lock',
  247. 145: 'scroll lock',
  248. 186: '&semi;',
  249. 187: '&equals;',
  250. 188: '&comma;',
  251. 189: '&hyphen;',
  252. 190: '&period;',
  253. 191: '&quest;',
  254. 192: '&grave;',
  255. 219: '&lsqb;',
  256. 220: '&bsol;',
  257. 221: '&rsqb;',
  258. 222: '&apos;',
  259. };