From 7f55741b1b05b4a2bc20c411fa4762529eaa4b58 Mon Sep 17 00:00:00 2001 From: daria <95225431+dariiing@users.noreply.github.com> Date: Tue, 10 Jun 2025 11:12:54 +0300 Subject: [PATCH] clean code --- www/common/sframe-common-mailbox.js | 13 +++++-------- www/notifications/inner.js | 16 ++++++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index 3f8b238f9..d84ea457a 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -88,15 +88,11 @@ define([ role: 'button' }); Common.displayAvatar($(avatar), userData.avatar, userData.displayName || userData.name); - $(avatar).keydown(function (e) { - if (e.which === 13 || e.which === 32) { - $(avatar).click(); - } - }); - $(avatar).click(function (e) { + const handler = function (e) { e.stopPropagation(); Common.openURL(Hash.hashToHref(userData.profile, 'profile')); - }); + }; + Util.onClickEnter($(avatar), handler, { space: true }); } else if (userData && userData.supportTeam) { avatar = h('span.cp-avatar-image', h('img', { src:'/customize/CryptPad_logo.svg' })); } @@ -128,7 +124,8 @@ define([ $(notif).find('.cp-notification-content p').html(data.content.getFormatText()); }, 60000); } - $(notif).find('.cp-notification-content').attr('aria-label', data.content.getFormatText().replace(/<[^>]*>/g, '')); // removes html tags from the text + const label = $(notif).find('.cp-notification-content p').text(); + $(notif).find('.cp-notification-content').attr('aria-label', label); } $(notif).mouseenter((e) => { diff --git a/www/notifications/inner.js b/www/notifications/inner.js index 43a7a8e65..dfde1dd67 100644 --- a/www/notifications/inner.js +++ b/www/notifications/inner.js @@ -14,6 +14,7 @@ define([ '/common/common-interface.js', '/common/common-ui-elements.js', '/common/notifications.js', + '/common/common-util.js', 'css!/components/bootstrap/dist/css/bootstrap.min.css', 'css!/components/components-font-awesome/css/font-awesome.min.css', @@ -29,7 +30,8 @@ define([ Messages, UI, UIElements, - Notifications + Notifications, + Util, ) { var APP = {}; @@ -160,19 +162,17 @@ define([ $('.cp-app-notification-archived[data-hash="' + data.hash + '"]').css('display', 'flex'); } }); - - $(dismissAll).keydown(function (e) { - if (e.keyCode === 13 || e.keyCode === 32) { - $(dismissAll).click(); + const handler = function (e) { + if (!notifsData) { + return; } - }); - $(dismissAll).click(function () { notifsData.forEach(function (data) { if (data.content.isDismissible) { data.content.dismissHandler(); } }); - }); + }; + Util.onClickEnter($(dismissAll), handler, { space: true }); return $div; };