|
1 | 1 | $(function () {
|
2 |
| - const doc = $(document) |
| 2 | + const doc = $(document); |
3 | 3 |
|
4 | 4 | // top link
|
5 | 5 | $('#top').click(function (e) {
|
6 |
| - $('html, body').animate({ scrollTop: 0 }, 500) |
7 |
| - return false |
8 |
| - }) |
| 6 | + $('html, body').animate({ scrollTop: 0 }, 500); |
| 7 | + return false; |
| 8 | + }); |
9 | 9 |
|
10 | 10 | // scrolling links
|
11 |
| - let added |
| 11 | + let added; |
12 | 12 | doc.scroll(function (e) {
|
13 | 13 | if (doc.scrollTop() > 5) {
|
14 |
| - if (added) return |
15 |
| - added = true |
16 |
| - $('body').addClass('scroll') |
| 14 | + if (added) return; |
| 15 | + added = true; |
| 16 | + $('body').addClass('scroll'); |
17 | 17 | } else {
|
18 |
| - $('body').removeClass('scroll') |
19 |
| - added = false |
| 18 | + $('body').removeClass('scroll'); |
| 19 | + added = false; |
20 | 20 | }
|
21 |
| - }) |
| 21 | + }); |
22 | 22 |
|
23 | 23 | // menu bar
|
24 | 24 |
|
25 | 25 | const headings = $('h2, h3').map(function (i, el) {
|
26 | 26 | return {
|
27 | 27 | top: $(el).offset().top - 200,
|
28 | 28 | id: el.id
|
29 |
| - } |
30 |
| - }) |
| 29 | + }; |
| 30 | + }); |
31 | 31 |
|
32 | 32 | function closest () {
|
33 |
| - let h |
34 |
| - const top = $(window).scrollTop() |
35 |
| - let i = headings.length |
| 33 | + let h; |
| 34 | + const top = $(window).scrollTop(); |
| 35 | + let i = headings.length; |
36 | 36 | while (i--) {
|
37 |
| - h = headings[i] |
38 |
| - if (top >= h.top) return h |
| 37 | + h = headings[i]; |
| 38 | + if (top >= h.top) return h; |
39 | 39 | }
|
40 | 40 | }
|
41 | 41 |
|
42 |
| - let currentApiPrefix |
43 |
| - let parentMenuSelector |
44 |
| - let lastApiPrefix |
| 42 | + let currentApiPrefix; |
| 43 | + let parentMenuSelector; |
| 44 | + let lastApiPrefix; |
45 | 45 |
|
46 | 46 | if (document.readyState !== 'loading') {
|
47 |
| - const languageElement = document.getElementById('languageData') |
48 |
| - const languagesData = languageElement ? JSON.parse(languageElement.dataset.languages) : [] |
| 47 | + const languageElement = document.getElementById('languageData'); |
| 48 | + const languagesData = languageElement ? JSON.parse(languageElement.dataset.languages) : []; |
49 | 49 |
|
50 |
| - const langDisplay = document.getElementById('current-lang') |
| 50 | + const langDisplay = document.getElementById('current-lang'); |
51 | 51 |
|
52 | 52 | if (langDisplay) {
|
53 |
| - const currentLanguage = window.location.pathname.split('/')[1] |
54 |
| - const matchedLang = languagesData.find(lang => lang.code === currentLanguage) |
55 |
| - langDisplay.textContent = matchedLang ? matchedLang.name : 'English' |
| 53 | + const currentLanguage = window.location.pathname.split('/')[1]; |
| 54 | + const matchedLang = languagesData.find(lang => lang.code === currentLanguage); |
| 55 | + langDisplay.textContent = matchedLang ? matchedLang.name : 'English'; |
56 | 56 | }
|
57 | 57 | }
|
58 | 58 |
|
59 | 59 | $(document).scroll(function () {
|
60 |
| - const h = closest() |
61 |
| - if (!h) return |
| 60 | + const h = closest(); |
| 61 | + if (!h) return; |
62 | 62 |
|
63 |
| - currentApiPrefix = h.id.split('.')[0] |
64 |
| - parentMenuSelector = '#' + currentApiPrefix + '-menu' |
| 63 | + currentApiPrefix = h.id.split('.')[0]; |
| 64 | + parentMenuSelector = '#' + currentApiPrefix + '-menu'; |
65 | 65 |
|
66 |
| - $(parentMenuSelector).addClass('active') |
| 66 | + $(parentMenuSelector).addClass('active'); |
67 | 67 |
|
68 | 68 | if (lastApiPrefix && (lastApiPrefix !== currentApiPrefix)) {
|
69 |
| - $('#' + lastApiPrefix + '-menu').removeClass('active') |
| 69 | + $('#' + lastApiPrefix + '-menu').removeClass('active'); |
70 | 70 | }
|
71 | 71 |
|
72 |
| - $('#menu li a').removeClass('active') |
| 72 | + $('#menu li a').removeClass('active'); |
73 | 73 |
|
74 |
| - const a = $('a[href="#' + h.id + '"]') |
75 |
| - a.addClass('active') |
| 74 | + const a = $('a[href="#' + h.id + '"]'); |
| 75 | + a.addClass('active'); |
76 | 76 |
|
77 |
| - lastApiPrefix = currentApiPrefix.split('.')[0] |
78 |
| - }) |
| 77 | + lastApiPrefix = currentApiPrefix.split('.')[0]; |
| 78 | + }); |
79 | 79 |
|
80 | 80 | // i18n notice
|
81 | 81 | if (readCookie('i18nClose')) {
|
82 |
| - $('#i18n-notice-box').hide() |
83 |
| - $('#i18n-notice-box').addClass('hidden') |
| 82 | + $('#i18n-notice-box').hide(); |
| 83 | + $('#i18n-notice-box').addClass('hidden'); |
84 | 84 | } else {
|
85 | 85 | $('#close-i18n-notice-box').on('click', function () {
|
86 |
| - $('#i18n-notice-box').hide() |
87 |
| - $('#i18n-notice-box').addClass('hidden') |
88 |
| - createCookie('i18nClose', 1) |
89 |
| - }) |
| 86 | + $('#i18n-notice-box').hide(); |
| 87 | + $('#i18n-notice-box').addClass('hidden'); |
| 88 | + createCookie('i18nClose', 1); |
| 89 | + }); |
90 | 90 | }
|
91 |
| -}) |
| 91 | +}); |
92 | 92 |
|
93 | 93 | function createCookie (name, value, days) {
|
94 |
| - let expires |
| 94 | + let expires; |
95 | 95 |
|
96 | 96 | if (days) {
|
97 |
| - const date = new Date() |
98 |
| - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)) |
99 |
| - expires = '; expires=' + date.toGMTString() |
| 97 | + const date = new Date(); |
| 98 | + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); |
| 99 | + expires = '; expires=' + date.toGMTString(); |
100 | 100 | } else {
|
101 |
| - expires = '' |
| 101 | + expires = ''; |
102 | 102 | }
|
103 |
| - document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + expires + '; path=/' |
| 103 | + document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + expires + '; path=/'; |
104 | 104 | }
|
105 | 105 |
|
106 | 106 | function readCookie (name) {
|
107 |
| - const nameEQ = encodeURIComponent(name) + '=' |
108 |
| - const ca = document.cookie.split(';') |
| 107 | + const nameEQ = encodeURIComponent(name) + '='; |
| 108 | + const ca = document.cookie.split(';'); |
109 | 109 | for (let i = 0; i < ca.length; i++) {
|
110 |
| - let c = ca[i] |
111 |
| - while (c.charAt(0) === ' ') c = c.substring(1, c.length) |
112 |
| - if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length)) |
| 110 | + let c = ca[i]; |
| 111 | + while (c.charAt(0) === ' ') c = c.substring(1, c.length); |
| 112 | + if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length)); |
113 | 113 | }
|
114 |
| - return null |
| 114 | + return null; |
115 | 115 | }
|
0 commit comments