Files
expressjs.com/js/app.js
Sebastian Beltran 68b4840949 remove prism (#1746)
2025-02-05 18:23:03 -05:00

126 lines
2.9 KiB
JavaScript

$(function(){
var doc = $(document);
// top link
$('#top').click(function(e){
$('html, body').animate({scrollTop : 0}, 500);
return false;
});
// scrolling links
var added;
doc.scroll(function(e){
if (doc.scrollTop() > 5) {
if (added) return;
added = true;
$('body').addClass('scroll');
} else {
$('body').removeClass('scroll');
added = false;
}
})
// menu bar
var headings = $('h2, h3').map(function(i, el){
return {
top: $(el).offset().top - 200,
id: el.id
}
});
function closest() {
var h;
var top = $(window).scrollTop();
var i = headings.length;
while (i--) {
h = headings[i];
if (top >= h.top) return h;
}
}
var currentApiPrefix;
var parentMenuSelector;
var lastApiPrefix;
if (document.readyState !== 'loading') {
const languageElement = document.getElementById('languageData');
const languagesData = languageElement ? JSON.parse(languageElement.dataset.languages) : [];
const langDisplay = document.getElementById('current-lang');
if (langDisplay) {
const currentLanguage = window.location.pathname.split('/')[1];
const matchedLang = languagesData.find(lang => lang.code === currentLanguage);
langDisplay.textContent = matchedLang ? matchedLang.name : 'English';
}
}
$(window).bind('load resize', function() {
$('#menu').css('height', ($(this).height() - 150) + 'px');
});
$(document).scroll(function() {
var h = closest();
if (!h) return;
currentApiPrefix = h.id.split('.')[0];
parentMenuSelector = '#'+ currentApiPrefix + '-menu';
$(parentMenuSelector).addClass('active');
if (lastApiPrefix && (lastApiPrefix != currentApiPrefix)) {
$('#'+ lastApiPrefix + '-menu').removeClass('active');
}
$('#menu li a').removeClass('active');
var a = $('a[href="#' + h.id + '"]');
a.addClass('active');
lastApiPrefix = currentApiPrefix.split('.')[0];
})
// i18n notice
if (readCookie('i18nClose')) {
$('#i18n-notice-box').hide()
}
else {
$('#close-i18n-notice-box').on('click', function () {
$('#i18n-notice-box').hide()
createCookie('i18nClose', 1);
})
}
})
function createCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
} else {
expires = "";
}
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = encodeURIComponent(name) + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}