PageSourceSearch

https://heminit.com/js/src/post-details.js?v=5.1.0

js heminit.com collected 2026-10-03 23:20:27 UTC 4,347 bytes, 147 lines download raw bytes

1/* global NexT: true */
2
3$(document).ready(function () {
4
5  initScrollSpy();
6  NexT.utils.needAffix() && initAffix();
7  initTOCDimension();
8
9  function initScrollSpy () {
10    var tocSelector = '.post-toc';
11    var $tocElement = $(tocSelector);
12    var activeCurrentSelector = '.active-current';
13
14    $tocElement
15      .on('activate.bs.scrollspy', function () {
16        var $currentActiveElement = $(tocSelector + ' .active').last();
17
18        removeCurrentActiveClass();
19        $currentActiveElement.addClass('active-current');
20      })
21      .on('clear.bs.scrollspy', removeCurrentActiveClass);
22
23    $('body').scrollspy({ target: tocSelector });
24
25    function removeCurrentActiveClass () {
26      $(tocSelector + ' ' + activeCurrentSelector)
27        .removeClass(activeCurrentSelector.substring(1));
28    }
29  }
30
31  // Sidebar float
32  function initAffix () {
33    var headerHeight = $('.header-inner').height();
34    var footerOffset = parseInt($('.main').css('padding-bottom'), 10);
35
36    /*jshint camelcase: false */
37    var sidebarTop = (CONFIG.sidebar.offset_float === 0) ?
38      headerHeight + CONFIG.sidebar.offset :
39      headerHeight;
40    /*jshint camelcase: true */
41
42    $('.sidebar-inner').affix({
43      offset: {
44        top: sidebarTop,
45        bottom: footerOffset
46      }
47    });
48
49    $(document)
50      .on('affixed.bs.affix', function () {
51        updateTOCHeight(document.body.clientHeight - 100);
52      });
53  }
54
55  function initTOCDimension () {
56    var updateTOCHeightTimer;
57
58    $(window).on('resize', function () {
59      updateTOCHeightTimer && clearTimeout(updateTOCHeightTimer);
60
61      updateTOCHeightTimer = setTimeout(function () {
62        var tocWrapperHeight = document.body.clientHeight - 100;
63
64        updateTOCHeight(tocWrapperHeight);
65      }, 0);
66    });
67
68    // Initialize TOC Height.
69    updateTOCHeight(document.body.clientHeight - 100);
70
71    // Initialize TOC Width.
72    var scrollbarWidth = NexT.utils.getScrollbarWidth();
73    $('.post-toc').css('width', 'calc(100% + ' + scrollbarWidth + 'px)');
74  }
75
76  function updateTOCHeight (height) {
77    height = height || 'auto';
78    $('.post-toc').css('max-height', height);
79  }
80
81});
82
83$(document).ready(function () {
84  var html = $('html');
85  var TAB_ANIMATE_DURATION = 200;
86  var hasVelocity = $.isFunction(html.velocity);
87
88  $('.sidebar-nav li').on('click', function () {
89    var item = $(this);
90    var activeTabClassName = 'sidebar-nav-active';
91    var activePanelClassName = 'sidebar-panel-active';
92    if (item.hasClass(activeTabClassName)) {
93      return;
94    }
95
96    var currentTarget = $('.' + activePanelClassName);
97    var target = $('.' + item.data('target'));
98
99    hasVelocity ?
100      currentTarget.velocity('transition.slideUpOut', TAB_ANIMATE_DURATION, function () {
101        target
102          .velocity('stop')
103          .velocity('transition.slideDownIn', TAB_ANIMATE_DURATION)
104          .addClass(activePanelClassName);
105      }) :
106      currentTarget.animate({ opacity: 0 }, TAB_ANIMATE_DURATION, function () {
107        currentTarget.hide();
108        target
109          .stop()
110          .css({'opacity': 0, 'display': 'block'})
111          .animate({ opacity: 1 }, TAB_ANIMATE_DURATION, function () {
112            currentTarget.removeClass(activePanelClassName);
113            target.addClass(activePanelClassName);
114          });
115      });
116
117    item.siblings().removeClass(activeTabClassName);
118    item.addClass(activeTabClassName);
119  });
120
121  $('.post-toc a').on('click', function (e) {
122    e.preventDefault();
123    var targetSelector = NexT.utils.escapeSelector(this.getAttribute('href'));
124    var offset = $(targetSelector).offset().top;
125
126    hasVelocity ?
127      html.velocity('stop').velocity('scroll', {
128        offset: offset  + 'px',
129        mobileHA: false
130      }) :
131      $('html, body').stop().animate({
132        scrollTop: offset
133      }, 500);
134  });
135
136  // Expand sidebar on post detail page by default, when post has a toc.
137  var $tocContent = $('.post-toc-content');
138  var isSidebarCouldDisplay = CONFIG.sidebar.display === 'post' ||
139      CONFIG.sidebar.display === 'always';
140  var hasTOC = $tocContent.length > 0 && $tocContent.html().trim().length > 0;
141  if (isSidebarCouldDisplay && hasTOC) {
142    CONFIG.motion ?
143      (NexT.motion.middleWares.sidebar = function () {
144          NexT.utils.displaySidebar();
145      }) : NexT.utils.displaySidebar();
146  }
147});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.