monkeytype/src/js/dom-util.js
2021-03-12 19:17:39 +00:00

79 lines
1.8 KiB
JavaScript

export function showBackgroundLoader() {
$("#backgroundLoader").stop(true, true).fadeIn(125);
}
export function hideBackgroundLoader() {
$("#backgroundLoader").stop(true, true).fadeOut(125);
}
export function accountIconLoading(truefalse) {
if (truefalse) {
$("#top #menu .account .icon").html(
'<i class="fas fa-fw fa-spin fa-circle-notch"></i>'
);
$("#top #menu .account").css("opacity", 1).css("pointer-events", "none");
} else {
$("#top #menu .account .icon").html('<i class="fas fa-fw fa-user"></i>');
$("#top #menu .account").css("opacity", 1).css("pointer-events", "auto");
}
}
export function swapElements(
el1,
el2,
totalDuration,
callback = function () {
return;
}
) {
if (
(el1.hasClass("hidden") && !el2.hasClass("hidden")) ||
(!el1.hasClass("hidden") && el2.hasClass("hidden"))
) {
//one of them is hidden and the other is visible
if (el1.hasClass("hidden")) {
callback();
return false;
}
$(el1)
.removeClass("hidden")
.css("opacity", 1)
.animate(
{
opacity: 0,
},
totalDuration / 2,
() => {
$(el1).addClass("hidden");
$(el2)
.removeClass("hidden")
.css("opacity", 0)
.animate(
{
opacity: 1,
},
totalDuration / 2,
() => {
callback();
}
);
}
);
} else if (el1.hasClass("hidden") && el2.hasClass("hidden")) {
//both are hidden, only fade in the second
$(el2)
.removeClass("hidden")
.css("opacity", 0)
.animate(
{
opacity: 1,
},
totalDuration,
() => {
callback();
}
);
} else {
callback();
}
}