Skip to content
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

Assorted JS tweaks #1617

Merged
merged 1 commit into from
Mar 14, 2023
Merged
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
6 changes: 3 additions & 3 deletions build/build-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

'use strict'

const fs = require('fs').promises
const path = require('path')
const fs = require('node:fs').promises
const path = require('node:path')
const picocolors = require('picocolors')

const iconsDir = path.join(__dirname, '../icons/')
Expand Down Expand Up @@ -53,7 +53,7 @@ tags:

const filesLength = files.length

console.log(picocolors.green('\nSuccess, %s page%s prepared!'), filesLength, filesLength !== 1 ? 's' : '')
console.log(picocolors.green('\nSuccess, %s page%s prepared!'), filesLength, filesLength === 1 ? '' : 's')
console.timeEnd(timeLabel)
} catch (error) {
console.error(error)
Expand Down
8 changes: 4 additions & 4 deletions build/build-svgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

'use strict'

const fs = require('fs').promises
const path = require('path')
const process = require('process')
const fs = require('node:fs').promises
const path = require('node:path')
const process = require('node:process')
const picocolors = require('picocolors')
const { loadConfig, optimize } = require('svgo')

Expand Down Expand Up @@ -46,7 +46,7 @@ async function processFile(file, config) {

const filesLength = files.length

console.log(picocolors.green('\nSuccess, prepared %s icon%s!'), filesLength, filesLength !== 1 ? 's' : '')
console.log(picocolors.green('\nSuccess, prepared %s icon%s!'), filesLength, filesLength === 1 ? '' : 's')
console.timeEnd(timeLabel)
} catch (error) {
console.error(error)
Expand Down
2 changes: 1 addition & 1 deletion build/vnu-jar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict'

const { execFile, spawn } = require('child_process')
const { execFile, spawn } = require('node:child_process')
const vnu = require('vnu-jar')

execFile('java', ['-version'], (error, stdout, stderr) => {
Expand Down
36 changes: 18 additions & 18 deletions docs/assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
(function () {
'use strict'

var btnHtml = '<div class="bd-clipboard"><button type="button" class="btn-clipboard" title="Copy to clipboard"><i class="bi bi-clipboard" aria-hidden="true"></i></button></div>';
const btnHtml = '<div class="bd-clipboard"><button type="button" class="btn-clipboard" title="Copy to clipboard"><i class="bi bi-clipboard" aria-hidden="true"></i></button></div>'

[].slice.call(document.querySelectorAll('div.highlight'))
.forEach(function (element) {
Array.prototype.slice.call(document.querySelectorAll('div.highlight'))
.forEach(element => {
element.insertAdjacentHTML('beforebegin', btnHtml)
})

var clipboard = new ClipboardJS('.btn-clipboard', {
target: function (trigger) {
const clipboard = new ClipboardJS('.btn-clipboard', {
target(trigger) {
return trigger.parentNode.nextElementSibling
}
})

clipboard.on('success', function (event) {
var icon = event.trigger.querySelector('.bi')
var originalTitle = event.trigger.title
clipboard.on('success', event => {
const icon = event.trigger.querySelector('.bi')
const originalTitle = event.trigger.title

event.clearSelection()
icon.classList.replace('bi-clipboard', 'bi-check2')
event.trigger.title = 'Copied!'

setTimeout(function () {
setTimeout(() => {
icon.classList.replace('bi-check2', 'bi-clipboard')
event.trigger.title = originalTitle
}, 2000)
})

clipboard.on('error', function () {
var modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
var errorElement = document.getElementById('copy-error-callout')
clipboard.on('error', () => {
const modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
const fallbackMsg = `Press ${modifierKey}C to copy`
const errorElement = document.getElementById('copy-error-callout')

if (!errorElement) {
return
Expand All @@ -45,19 +45,19 @@
errorElement.insertAdjacentHTML('afterbegin', fallbackMsg)
})

var searchInput = document.getElementById('search')
const searchInput = document.getElementById('search')
if (searchInput) {
searchInput.addEventListener('keydown', function (event) {
searchInput.addEventListener('keydown', event => {
if (event.key === 'Enter') {
event.preventDefault()
}
})
}

// Disable empty links in docs
[].slice.call(document.querySelectorAll('[href="#"]'))
.forEach(function (link) {
link.addEventListener('click', function (event) {
Array.prototype.slice.call(document.querySelectorAll('[href="#"]'))
.forEach(link => {
link.addEventListener('click', event => {
event.preventDefault()
})
})
Expand Down
2 changes: 1 addition & 1 deletion svgo.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const path = require('path')
const path = require('node:path')

module.exports = {
multipass: true,
Expand Down