|
| 1 | +window.ResizeSensor = require('css-element-queries/src/ResizeSensor'); |
| 2 | +require('sticky-sidebar/dist/sticky-sidebar.js'); |
| 3 | + |
| 4 | +var hljs = require('highlight.js/lib/highlight'); |
| 5 | +hljs.registerLanguage('http', require('highlight.js/lib/languages/http')); |
| 6 | +hljs.registerLanguage('json', require('highlight.js/lib/languages/json')); |
| 7 | + |
| 8 | +$(document).ready(function () { |
| 9 | + var sidebar = new StickySidebar('.sidebar', { |
| 10 | + topSpacing: 22, |
| 11 | + bottomSpacing: 0, |
| 12 | + containerSelector: '.content-wrapper', |
| 13 | + innerWrapperSelector: '.sidebar__inner', |
| 14 | + resizeSensor: true |
| 15 | + }); |
| 16 | + |
| 17 | + $(window).resize(function() { |
| 18 | + sidebar.updateSticky(); |
| 19 | + }); |
| 20 | + |
| 21 | + $('[id^=collapse-]').on('show.bs.collapse', function () { |
| 22 | + var id = $(this).prev().find('a').data('group-id'), |
| 23 | + scrollTop = $(document.getElementById(id)).offset().top - 33; |
| 24 | + |
| 25 | + $('html, body').animate({scrollTop: scrollTop}); |
| 26 | + }); |
| 27 | + |
| 28 | + $('[id^=collapse-]').on('hide.bs.collapse', function (e) { |
| 29 | + var id = $(this).prev().find('a').data('group-id'), |
| 30 | + scrollTop = $(document.getElementById(id)).offset().top - 33; |
| 31 | + |
| 32 | + $('html, body').animate({scrollTop: scrollTop}); |
| 33 | + |
| 34 | + if ($(window).scrollTop() < scrollTop - 1 || $(window).scrollTop() > scrollTop + 1) { |
| 35 | + e.preventDefault(); |
| 36 | + } |
| 37 | + }); |
| 38 | + |
| 39 | + $('.tabs').on('click', 'a', function (e) { |
| 40 | + var id = $(this).attr('href').substring(1), |
| 41 | + scrollTop = $(document.getElementById(id)).offset().top - 33; |
| 42 | + |
| 43 | + $('html, body').animate({scrollTop: scrollTop}); |
| 44 | + |
| 45 | + e.preventDefault(); |
| 46 | + }); |
| 47 | + |
| 48 | + $('.nav-pills').on('click', '.active a', function (e) { |
| 49 | + var that = $(this); |
| 50 | + |
| 51 | + e.preventDefault(); |
| 52 | + |
| 53 | + window.setTimeout(function () { |
| 54 | + that.closest('.nav-pills').next('.tab-content').find('.tab-pane').removeClass('active'); |
| 55 | + that.parent('li').removeClass('active'); |
| 56 | + }, 0); |
| 57 | + }); |
| 58 | + |
| 59 | + $('pre code').each(function (i, block) { |
| 60 | + hljs.highlightBlock(block); |
| 61 | + }); |
| 62 | +}); |
0 commit comments