PageSourceSearch

https://thoughtful-ark.pages.dev/assets/js/theme.js

js thoughtful-ark.pages.dev collected 2026-10-03 05:58:04 UTC 4,086 bytes, 136 lines download raw bytes

1 // alertbar later
2    $(document).scroll(function () {
3        var y = $(this).scrollTop();
4        if (y > 280) {
5            $('.alertbar').fadeIn();
6        } else {
7            $('.alertbar').fadeOut();
8        }
9    });
10
11
12// Hide Header on on scroll down
13    var didScroll;
14    var lastScrollTop = 0;
15    var delta = 5;
16    var navbarHeight = $('nav').outerHeight();
17
18    $(window).scroll(function(event){
19        didScroll = true;
20    });
21
22    setInterval(function() {
23        if (didScroll) {
24            hasScrolled();
25            didScroll = false;
26        }
27    }, 250);
28
29    function hasScrolled() {
30        var st = $(this).scrollTop();
31        
32        // Make sure they scroll more than delta
33        if(Math.abs(lastScrollTop - st) <= delta)
34            return;
35
36        // If they scrolled down and are past the navbar, add class .nav-up.
37        // This is necessary so you never see what is "behind" the navbar.
38        if (st > lastScrollTop && st > navbarHeight){
39            // Scroll Down            
40            $('nav').removeClass('nav-down').addClass('nav-up'); 
41            $('.nav-up').css('top', - $('nav').outerHeight() + 'px');
42           
43        } else {
44            // Scroll Up
45            if(st + $(window).height() < $(document).height()) {               
46                $('nav').removeClass('nav-up').addClass('nav-down');
47                $('.nav-up, .nav-down').css('top', '0px');             
48            }
49        }
50
51        lastScrollTop = st;
52    }
53    
54    
55    $('.site-content').css('margin-top', $('header').outerHeight() + 'px');
56
57
58function loadSearch(){
59    // Create a new Index
60    idx = lunr(function(){
61        this.field('id')
62        this.field('title', { boost: 10 })
63        this.field('summary')
64    })
65 
66    // Send a request to get the content json file
67    $.getJSON('/content.json', function(data){
68 
69        // Put the data into the window global so it can be used later
70        window.searchData = data
71 
72        // Loop through each entry and add it to the index
73        $.each(data, function(index, entry){
74            idx.add($.extend({"id": index}, entry))
75        })
76    })
77 
78    // When search is pressed on the menu toggle the search box
79    $('#search').on('click', function(){
80        $('.searchForm').toggleClass('show')
81    })
82 
83    // When the search form is submitted
84    $('#searchForm').on('submit', function(e){
85        // Stop the default action
86        e.preventDefault()
87 
88        // Find the results from lunr
89        results = idx.search($('#searchField').val())
90 
91        // Empty #content and put a list in for the results
92        $('#content').html('<h1>Search Results (' + results.length + ')</h1>')
93        $('#content').append('<ul id="searchResults"></ul>')
94 
95        // Loop through results
96        $.each(results, function(index, result){
97            // Get the entry from the window global
98            entry = window.searchData[result.ref]
99 
100            // Append the entry to the list.
101            $('#searchResults').append('<li><a href="' + entry.url + '">' + entry.title + '</li>')
102        })
103    })
104}
105
106
107
108// Smooth on external page
109$(function() {
110  setTimeout(function() {
111    if (location.hash) {
112      /* we need to scroll to the top of the window first, because the browser will always jump to the anchor first before JavaScript is ready, thanks Stack Overflow: http://stackoverflow.com/a/3659116 */
113      window.scrollTo(0, 0);
114      target = location.hash.split('#');
115      smoothScrollTo($('#'+target[1]));
116    }
117  }, 1);
118
119  // taken from: https://css-tricks.com/snippets/jquery/smooth-scrolling/
120  $('a[href*=\\#]:not([href=\\#])').click(function() {
121    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
122      smoothScrollTo($(this.hash));
123      return false;
124    }
125  });
126
127  function smoothScrollTo(target) {
128    target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
129
130    if (target.length) {
131      $('html,body').animate({
132        scrollTop: target.offset().top
133      }, 1000);
134    }
135  }
136});

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.