Favicon Switcher - Flatpikr

This commit is contained in:
Fred Tempez 2021-12-01 16:07:42 +01:00
parent 272de57267
commit 400278071e
3 changed files with 67 additions and 53 deletions

View File

@ -5,6 +5,8 @@ Mises à jour :
- jQuery v3.6.0 - jQuery v3.6.0
- Lity v2.4.1 - Lity v2.4.1
- Lightbox v2.10.1 - Lightbox v2.10.1
- Faltpickr v4.6.9
- FavIcon Switcher v1.2.2
- Corrections : - Corrections :
- Configuration, restauration d'une archive du site : - Configuration, restauration d'une archive du site :
- la validation du formulaire sans avoir sélectionné de fichier de sauvegarde provoque le crash du site. - la validation du formulaire sans avoir sélectionné de fichier de sauvegarde provoque le crash du site.

View File

@ -1,56 +1,67 @@
// FavIcon Switcher V1.2.2
;(function(mod){ ;(function(mod){
function collectLinks() { function collectLinks() {
return Array.prototype.slice.apply( return Array.prototype.slice.apply(
document.head.querySelectorAll('link[rel*="icon"]') document.head.querySelectorAll('link[rel*="icon"]')
) )
}
function applyLink(source, target) {
target.setAttribute('type', source.getAttribute('type'))
target.setAttribute('href', source.getAttribute('href'))
}
// eslint-disable-next-line no-unused-vars
function initSwitcher(delay) {
// Exit if media queries aren't supported
if (typeof window.matchMedia !== 'function') {
return function noop() {}
} }
function applyLink(source, target) { var links = collectLinks()
target.setAttribute('type', source.getAttribute('type')) var current = document.createElement('link')
target.setAttribute('href', source.getAttribute('href')) var prevMatch
}
current.setAttribute('rel', 'shortcut icon')
// eslint-disable-next-line no-unused-vars document.head.appendChild(current)
function initSwitcher(delay) {
// Exit if media queries aren't supported function faviconApplyLoop() {
if (typeof window.matchMedia !== 'function') { var matched
return function noop() {}
}
var links = collectLinks()
var current = document.createElement('link')
var prevMatch
current.setAttribute('rel', 'shortcut icon')
document.head.appendChild(current)
function faviconApplyLoop() {
links.forEach(function(link) {
if (window.matchMedia(link.media).matches) {
if (link.media !== prevMatch) {
prevMatch = link.media
applyLink(link, current)
}
}
})
}
var intervalId = setInterval(faviconApplyLoop, delay || 300)
function unsubscribe() {
clearInterval(intervalId)
links.forEach(function(link) {
document.head.appendChild(link)
})
}
faviconApplyLoop()
links.forEach(function(link) { links.forEach(function(link) {
document.head.removeChild(link) if (window.matchMedia(link.media).matches) {
matched = link
}
}) })
return unsubscribe if (! matched) {
return
}
if (matched.media !== prevMatch) {
prevMatch = matched.media
applyLink(matched, current)
}
} }
initSwitcher() var intervalId = setInterval(faviconApplyLoop, delay || 300)
})()
function unsubscribe() {
clearInterval(intervalId)
links.forEach(function(link) {
document.head.appendChild(link)
})
}
faviconApplyLoop()
links.forEach(function(link) {
document.head.removeChild(link)
})
return unsubscribe
}
initSwitcher()
})()

File diff suppressed because one or more lines are too long