diff --git a/public/scripts/backgrounds.js b/public/scripts/backgrounds.js index 683e9c4ee..4ec8bf1f6 100644 --- a/public/scripts/backgrounds.js +++ b/public/scripts/backgrounds.js @@ -96,8 +96,13 @@ function highlightLockedBackground() { }); } +/** + * Locks the background for the current chat + * @param {Event} e Click event + * @returns {string} Empty string + */ function onLockBackgroundClick(e) { - e.stopPropagation(); + e?.stopPropagation(); const chatName = getCurrentChatId(); @@ -114,8 +119,13 @@ function onLockBackgroundClick(e) { return ''; } +/** + * Locks the background for the current chat + * @param {Event} e Click event + * @returns {string} Empty string + */ function onUnlockBackgroundClick(e) { - e.stopPropagation(); + e?.stopPropagation(); removeBackgroundMetadata(); unsetCustomBackground(); highlightLockedBackground(); @@ -513,12 +523,12 @@ export function initBackgrounds() { $('#add_bg_button').on('change', onBackgroundUploadSelected); $('#bg-filter').on('input', onBackgroundFilterInput); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'lockbg', - callback: onLockBackgroundClick, + callback: () => onLockBackgroundClick(new CustomEvent('click')), aliases: ['bglock'], helpString: 'Locks a background for the currently selected chat', })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'unlockbg', - callback: onUnlockBackgroundClick, + callback: () => onUnlockBackgroundClick(new CustomEvent('click')), aliases: ['bgunlock'], helpString: 'Unlocks a background for the currently selected chat', }));