0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-08 14:40:05 +00:00

Simplify JS that sets the favicon

* look up the favicon DOM element only once
* update the favicon only if title changes, not on every refresh
* details.js: use the base URL when constructing favicon URL
This commit is contained in:
Pēteris Caune 2024-03-26 17:28:47 +02:00
parent ab639e6cfd
commit 9f5cec1c7a
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
2 changed files with 8 additions and 22 deletions

View file

@ -1,5 +1,6 @@
$(function () {
var base = document.getElementById("base-url").getAttribute("href").slice(0, -1);
var favicon = document.querySelector('link[rel="icon"]');
$(".rw .my-checks-name").click(function() {
var code = $(this).closest("tr.checks-row").attr("id");
@ -240,19 +241,10 @@ $(function () {
}
});
if(data.title.includes('down')){
// Get the favicon element
var favicon = document.querySelector('link[rel="icon"]');
//replace the favicon with the down favicon
favicon.href = base + "/static/img/favicon_down.svg";
}
else{
var favicon = document.querySelector('link[rel="icon"]');
favicon.href = base + "/static/img/favicon.svg";
}
if (document.title != data.title) {
document.title = data.title;
var downPostfix = data.title.includes("down") ? "_down" : "";
favicon.href = `${base}/static/img/favicon${downPostfix}.svg`;
}
}
});

View file

@ -1,4 +1,7 @@
$(function () {
var base = document.getElementById("base-url").getAttribute("href").slice(0, -1);
var favicon = document.querySelector('link[rel="icon"]');
$("#edit-name").click(function() {
$('#update-name-modal').modal("show");
$("#update-name-input").focus();
@ -110,19 +113,10 @@ $(function () {
$("#downtimes").html(data.downtimes);
}
if(data.status == "down"){
// Get the favicon element
var favicon = document.querySelector('link[rel="icon"]');
//replace the favicon with the down favicon
favicon.href = "/static/img/favicon_down.svg";
}
else{
var favicon = document.querySelector('link[rel="icon"]');
favicon.href = "/static/img/favicon.svg";
}
if (document.title != data.title) {
document.title = data.title;
var downPostfix = data.status == "down" ? "_down" : "";
favicon.href = `${base}/static/img/favicon${downPostfix}.svg`;
}
}
});