From 2b6bcd8d24a6df38142c099046fa466932432ada Mon Sep 17 00:00:00 2001 From: Pablo Zmdl Date: Fri, 21 Jun 2024 17:48:29 +0200 Subject: [PATCH] WIP: Replace inline event handler with standalone JS --- program/actions/mail/show.php | 8 +++----- program/js/mail-action-show.js | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 program/js/mail-action-show.js diff --git a/program/actions/mail/show.php b/program/actions/mail/show.php index efe6a481aa..1a62bcef57 100644 --- a/program/actions/mail/show.php +++ b/program/actions/mail/show.php @@ -221,19 +221,17 @@ public static function message_attachments($attrib) $li_class = $class; if (!self::$PRINT_MODE) { + $rcmail->output->include_script('mail-action-show.js'); $link_attrs = [ 'href' => self::$MESSAGE->get_part_url($attach_prop->mime_id, false), - 'onclick' => sprintf('%s.command(\'load-attachment\',\'%s\',this); return false', - rcmail_output::JS_OBJECT_NAME, $attach_prop->mime_id), - 'onmouseover' => $title ? '' : 'rcube_webmail.long_subject_title_ex(this, 0)', + 'data-mime-id' => $attach_prop->mime_id, 'title' => $title, 'class' => 'filename', ]; if ($mimetype != 'message/rfc822' && empty($attach_prop->size)) { $li_class .= ' no-menu'; - $link_attrs['onclick'] = sprintf('%s.alert_dialog(%s.get_label(\'emptyattachment\')); return false', - rcmail_output::JS_OBJECT_NAME, rcmail_output::JS_OBJECT_NAME); + $link_attrs['data-emptyattachment'] = 'true'; $rcmail->output->add_label('emptyattachment'); } diff --git a/program/js/mail-action-show.js b/program/js/mail-action-show.js new file mode 100644 index 0000000000..cd762127e9 --- /dev/null +++ b/program/js/mail-action-show.js @@ -0,0 +1,20 @@ +rcmail.addEventListener('init', () => { + $('#attachment-list li a.filename').each((_idx, elem) => { + elem.addEventListener('click', (ev) => { + ev.preventDefault(); + if (elem.dataset.emptyattachment) { + rcmail.alert_dialog(rcmail.get_label('emptyattachment')); + } else { + rcmail.command('load-attachment', elem.dataset.mimeId, elem); + } + return false; + }); + + if (!elem.title) { + elem.addEventListener('mouseover', () => { + rcube_webmail.long_subject_title_ex(elem, 0); + }); + } + + }); +});