mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
Fix motd close button for community ads (#7752)
Fixes a subtle breakage from the bootstrap migration: The motd close button works for update/motds but not community ads. This PR cleans up the duplicate code and subsequent deviation.
This commit is contained in:
@@ -26,17 +26,21 @@ import $ from 'jquery';
|
|||||||
|
|
||||||
import {Ad, Motd} from './motd.interfaces.js';
|
import {Ad, Motd} from './motd.interfaces.js';
|
||||||
|
|
||||||
function ensureShownMessage(message: string, motdNode: JQuery) {
|
function setupMotd(motdNode: JQuery, onHide: () => void) {
|
||||||
motdNode.find('.content').html(message);
|
|
||||||
motdNode.removeClass('d-none');
|
|
||||||
motdNode
|
motdNode
|
||||||
.find('.btn-close')
|
.find('.btn-close')
|
||||||
.on('click', () => {
|
.on('click', () => {
|
||||||
motdNode.addClass('d-none');
|
motdNode.addClass('d-none');
|
||||||
|
onHide();
|
||||||
})
|
})
|
||||||
.prop('title', 'Hide message');
|
.prop('title', 'Hide message');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ensureShownMessage(message: string, motdNode: JQuery) {
|
||||||
|
motdNode.find('.content').html(message);
|
||||||
|
motdNode.removeClass('d-none');
|
||||||
|
}
|
||||||
|
|
||||||
export function isValidAd(ad: Ad, subLang: string): boolean {
|
export function isValidAd(ad: Ad, subLang: string): boolean {
|
||||||
if (!subLang || ad.filter.length === 0 || ad.filter.includes(subLang)) {
|
if (!subLang || ad.filter.length === 0 || ad.filter.includes(subLang)) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@@ -59,6 +63,7 @@ export function isValidAd(ad: Ad, subLang: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleMotd(motd: Motd, motdNode: JQuery, subLang: string, adsEnabled: boolean, onHide: () => void) {
|
function handleMotd(motd: Motd, motdNode: JQuery, subLang: string, adsEnabled: boolean, onHide: () => void) {
|
||||||
|
setupMotd(motdNode, onHide);
|
||||||
if (motd.update) {
|
if (motd.update) {
|
||||||
ensureShownMessage(motd.update, motdNode);
|
ensureShownMessage(motd.update, motdNode);
|
||||||
} else if (motd.motd) {
|
} else if (motd.motd) {
|
||||||
@@ -68,12 +73,7 @@ function handleMotd(motd: Motd, motdNode: JQuery, subLang: string, adsEnabled: b
|
|||||||
|
|
||||||
if (applicableAds != null && applicableAds.length > 0) {
|
if (applicableAds != null && applicableAds.length > 0) {
|
||||||
const randomAd = applicableAds[Math.floor(Math.random() * applicableAds.length)];
|
const randomAd = applicableAds[Math.floor(Math.random() * applicableAds.length)];
|
||||||
motdNode.find('.content').html(randomAd.html);
|
ensureShownMessage(randomAd.html, motdNode);
|
||||||
motdNode.find('.close').on('click', () => {
|
|
||||||
motdNode.addClass('d-none');
|
|
||||||
onHide();
|
|
||||||
});
|
|
||||||
motdNode.removeClass('d-none');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user