1/* global CONFIG */ 2 3document.addEventListener('DOMContentLoaded', () => { 4 'use strict'; 5 6 const doSaveScroll = () => { 7 localStorage.setItem('bookmark' + location.pathname, window.scrollY); 8 }; 9 10 const scrollToMark = () => { 11 let top = localStorage.getItem('bookmark' + location.pathname); 12 top = parseInt(top, 10); 13 // If the page opens with a specific hash, just jump out 14 if (!isNaN(top) && location.hash === '') { 15 // Auto scroll to the position 16 window.anime({ 17 targets : document.scrollingElement, 18 duration : 200, 19 easing : 'linear', 20 scrollTop: top 21 }); 22 } 23 }; 24 // Register everything 25 const init = function(trigger) { 26 // Create a link element 27 const link = document.querySelector('.book-mark-link'); 28 // Scroll event 29 window.addEventListener('scroll', () => link.classList.toggle('book-mark-link-fixed', window.scrollY === 0), { passive: true }); 30 // Register beforeunload event when the trigger is auto 31 if (trigger === 'auto') { 32 // Register beforeunload event 33 window.addEventListener('beforeunload', doSaveScroll); 34 document.addEventListener('pjax:send', doSaveScroll); 35 } 36 // Save the position by clicking the icon 37 link.addEventListener('click', () => { 38 doSaveScroll(); 39 window.anime({ 40 targets : link, 41 duration: 200, 42 easing : 'linear', 43 top : -30, 44 complete: () => { 45 setTimeout(() => { 46 link.style.top = ''; 47 }, 400); 48 } 49 }); 50 }); 51 scrollToMark(); 52 document.addEventListener('pjax:success', scrollToMark); 53 }; 54 55 init(CONFIG.bookmark.save); 56});
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.