Skip to content

Fix ESLint Test #1890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 64 additions & 71 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -1,122 +1,115 @@
$(function(){
var doc = $(document);
$(function () {
const doc = $(document)

// top link
$('#top').click(function(e){
$('html, body').animate({scrollTop : 0}, 500);
return false;
});
$('#top').click(function (e) {
$('html, body').animate({ scrollTop: 0 }, 500)
return false
})

// scrolling links
var added;
doc.scroll(function(e){
let added
doc.scroll(function (e) {
if (doc.scrollTop() > 5) {
if (added) return;
added = true;
$('body').addClass('scroll');
if (added) return
added = true
$('body').addClass('scroll')
} else {
$('body').removeClass('scroll');
added = false;
$('body').removeClass('scroll')
added = false
}
})

// menu bar

var headings = $('h2, h3').map(function(i, el){
const 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;
function closest () {
let h
const top = $(window).scrollTop()
let i = headings.length
while (i--) {
h = headings[i];
if (top >= h.top) return h;
h = headings[i]
if (top >= h.top) return h
}
}

var currentApiPrefix;
var parentMenuSelector;
var lastApiPrefix;
let currentApiPrefix
let parentMenuSelector
let lastApiPrefix

if (document.readyState !== 'loading') {
const languageElement = document.getElementById('languageData');
const languagesData = languageElement ? JSON.parse(languageElement.dataset.languages) : [];
const languageElement = document.getElementById('languageData')
const languagesData = languageElement ? JSON.parse(languageElement.dataset.languages) : []

const langDisplay = document.getElementById('current-lang');
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';
}
const currentLanguage = window.location.pathname.split('/')[1]
const matchedLang = languagesData.find(lang => lang.code === currentLanguage)
langDisplay.textContent = matchedLang ? matchedLang.name : 'English'
}
}

$(document).scroll(function() {
var h = closest();
if (!h) return;
$(document).scroll(function () {
const h = closest()
if (!h) return

currentApiPrefix = h.id.split('.')[0];
parentMenuSelector = '#'+ currentApiPrefix + '-menu';
currentApiPrefix = h.id.split('.')[0]
parentMenuSelector = '#' + currentApiPrefix + '-menu'

$(parentMenuSelector).addClass('active');
$(parentMenuSelector).addClass('active')

if (lastApiPrefix && (lastApiPrefix != currentApiPrefix)) {
$('#'+ lastApiPrefix + '-menu').removeClass('active');
if (lastApiPrefix && (lastApiPrefix !== currentApiPrefix)) {
$('#' + lastApiPrefix + '-menu').removeClass('active')
}

$('#menu li a').removeClass('active');
$('#menu li a').removeClass('active')

var a = $('a[href="#' + h.id + '"]');
a.addClass('active');
const a = $('a[href="#' + h.id + '"]')
a.addClass('active')

lastApiPrefix = currentApiPrefix.split('.')[0];
lastApiPrefix = currentApiPrefix.split('.')[0]
})

// i18n notice
if (readCookie('i18nClose')) {
$('#i18n-notice-box').hide();
$("#i18n-notice-box").addClass("hidden");
}
else {
$('#i18n-notice-box').hide()
$('#i18n-notice-box').addClass('hidden')
} else {
$('#close-i18n-notice-box').on('click', function () {
$('#i18n-notice-box').hide();
$("#i18n-notice-box").addClass("hidden");
createCookie('i18nClose', 1);
$('#i18n-notice-box').hide()
$('#i18n-notice-box').addClass('hidden')
createCookie('i18nClose', 1)
})
}
})



function createCookie(name, value, days) {
var expires;
function createCookie (name, value, days) {
let expires

if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
const date = new Date()
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))
expires = '; expires=' + date.toGMTString()
} else {
expires = "";
expires = ''
}
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
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));
function readCookie (name) {
const nameEQ = encodeURIComponent(name) + '='
const ca = document.cookie.split(';')
for (let i = 0; i < ca.length; i++) {
let 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;
return null
}

function eraseCookie(name) {
createCookie(name, "", -1);
}
68 changes: 34 additions & 34 deletions js/copycode.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
const codeBlocks = document.querySelectorAll("pre:has(code)");
const codeBlocks = document.querySelectorAll('pre:has(code)')

codeBlocks.forEach((block) => {
// Only add button if browser supports Clipboard API
if (!navigator.clipboard) return;
if (!navigator.clipboard) return

const button = createCopyButton();
block.appendChild(button);
block.setAttribute("tabindex", 0); // Add keyboard a11y for <pre></pre>
const button = createCopyButton()
block.appendChild(button)
block.setAttribute('tabindex', 0) // Add keyboard a11y for <pre></pre>

button.addEventListener("click", async () => {
await copyCode(block, button);
});
});
button.addEventListener('click', async () => {
await copyCode(block, button)
})
})

function createCopyButton() {
const button = document.createElement("button");
function createCopyButton () {
const button = document.createElement('button')
setButtonAttributes(button, {
type: "button", // button doesn't act as a submit button
title: "copy code",
"aria-label": "click to copy code",
});
return button;
type: 'button', // button doesn't act as a submit button
title: 'copy code',
'aria-label': 'click to copy code'
})
return button
}

function setButtonAttributes(button, attributes) {
function setButtonAttributes (button, attributes) {
for (const [key, value] of Object.entries(attributes)) {
button.setAttribute(key, value);
button.setAttribute(key, value)
}
}

async function copyCode(block, button) {
const code = block.querySelector("code");
let text = code.innerText;
async function copyCode (block, button) {
const code = block.querySelector('code')
let text = code.innerText
// remove "$" and space if exists at the beginning of the code
text = text.replace(/^\$\s?/,"");
text = text.replace(/^\$\s?/, '')

try {
await navigator.clipboard.writeText(text);
updateButtonState(button, "copied", "code is copied!");
await navigator.clipboard.writeText(text)
updateButtonState(button, 'copied', 'code is copied!')
} catch {
updateButtonState(button, "failed", "failed!");
updateButtonState(button, 'failed', 'failed!')
}
}

function updateButtonState(button, statusClass, ariaLabel) {
button.setAttribute("aria-live", "polite");
button.setAttribute("aria-label", ariaLabel);
button.classList.add(statusClass);
function updateButtonState (button, statusClass, ariaLabel) {
button.setAttribute('aria-live', 'polite')
button.setAttribute('aria-label', ariaLabel)
button.classList.add(statusClass)

// Clear any existing timer
if (button.dataset.timerId) clearTimeout(Number(button.dataset.timerId));
if (button.dataset.timerId) clearTimeout(Number(button.dataset.timerId))
const timer = setTimeout(() => {
button.classList.remove(statusClass);
button.setAttribute("aria-label", "click to copy code");
}, 1000);
button.classList.remove(statusClass)
button.setAttribute('aria-label', 'click to copy code')
}, 1000)

button.dataset.timerId = timer;
button.dataset.timerId = timer
}
Loading
Loading