Skip to content

Commit

Permalink
WIP: Replace inline event handler with standalone JS
Browse files Browse the repository at this point in the history
  • Loading branch information
pabzm committed Jun 21, 2024
1 parent 50035fb commit 2b6bcd8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 3 additions & 5 deletions program/actions/mail/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
20 changes: 20 additions & 0 deletions program/js/mail-action-show.js
Original file line number Diff line number Diff line change
@@ -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);
});
}

});
});

0 comments on commit 2b6bcd8

Please sign in to comment.