Skip to content

Commit

Permalink
Re-add lost preventDefault
Browse files Browse the repository at this point in the history
If the last argument to a data-on* attribute is an object (associative
array in PHP), it is used as options, which allow to specify if
preventDefault() should be called on the event.
This is relevant for some parts of the code and got lost in previous
changes.
  • Loading branch information
pabzm committed Sep 5, 2024
1 parent 6e2e1a1 commit a927b13
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'href' => '#',
'id' => "ruleadv{$id}",
'title' => $adv_title,
'data-onclick' => ['rule_adv_switch', $id, '__THIS__'],
'data-onclick' => ['rule_adv_switch', $id, '__THIS__', ['preventDefault' => true]],
'class' => 'show',
],
html::span(['class' => 'inner'], $adv_title)
Expand All @@ -2140,7 +2140,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'href' => '#',
'id' => "ruleadv{$id}",
'title' => $adv_title,
'data-onclick' => ['rule_adv_switch', $id, '__THIS__'],
'data-onclick' => ['rule_adv_switch', $id, '__THIS__', ['preventDefault' => true]],
'class' => 'advanced show',
],
html::span(['class' => 'inner'], $adv_title)
Expand All @@ -2150,7 +2150,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'href' => '#',
'id' => "ruleadd{$id}",
'title' => $add_title,
'data-onclick' => ['managesieve_ruleadd', $id],
'data-onclick' => ['managesieve_ruleadd', $id, ['preventDefault' => true]],
'class' => 'button create add',
],
html::span(['class' => 'inner'], $add_title)
Expand All @@ -2159,7 +2159,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'href' => '#',
'id' => "ruledel{$id}",
'title' => $del_title,
'data-onclick' => ['managesieve_ruledel', $id],
'data-onclick' => ['managesieve_ruledel', $id, ['preventDefault' => true]],
'class' => 'button delete del ' . $rows_num < 2 ? 'disabled' : '',
],
html::span(['class' => 'inner'], $del_title)
Expand Down
2 changes: 1 addition & 1 deletion plugins/newmail_notifier/newmail_notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function prefs_list($args)
$field_id = '_' . $key;
$input = new html_checkbox(['name' => $field_id, 'id' => $field_id, 'value' => 1]);
$content = $input->show($this->rc->config->get($key))
. ' ' . html::a(['href' => '#', 'data-onclick' => ['newmail_notifier_test_' . $type]],
. ' ' . html::a(['href' => '#', 'data-onclick' => ['newmail_notifier_test_' . $type, ['preventDefault' => true]]],
$this->gettext('test'));

$args['blocks']['new_message']['options'][$key] = [
Expand Down
2 changes: 1 addition & 1 deletion program/actions/mail/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ public static function message_body($attrib)
$supported = in_array($mimetype, self::$CLIENT_MIMETYPES);
$show_link_attr = [
'href' => self::$MESSAGE->get_part_url($attach_prop->mime_id, false),
'data-onclick' => ['command', 'load-attachment', $attach_prop->mime_id, '__THIS__'],
'data-onclick' => ['command', 'load-attachment', $attach_prop->mime_id, '__THIS__', ['preventDefault' => true]],
];
$download_link_attr = [
'href' => $show_link_attr['href'] . '&_download=1',
Expand Down
2 changes: 1 addition & 1 deletion program/include/rcmail_output_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ public function search_form($attrib)
if (empty($attrib['form']) && empty($attrib['no-form'])) {
$out = $this->form_tag([
'name' => !empty($attrib['form-name']) ? $attrib['form-name'] : 'rcmqsearchform',
'data-onsubmit' => ['command', !empty($attrib['command']) ? $attrib['command'] : 'search'],
'data-onsubmit' => ['command', !empty($attrib['command']) ? $attrib['command'] : 'search', ['preventDefault' => true]],
// 'style' => "display:inline"
], $out);
}
Expand Down
12 changes: 10 additions & 2 deletions program/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10849,15 +10849,23 @@ function rcube_webmail() {
}
return arg;
});
var preventDefault = false;
if (typeof eventArgs.at(-1) === 'object') {
options = eventArgs.pop();
var preventDefault = Boolean(options.preventDefault);
}
elem.addEventListener(eventName, (ev) => {
// Inject a reference to the event object, if required.
var localEventArgs = eventArgs.map(function (arg) {
var localEventArgs = eventArgs.map((arg) => {
if (arg === '__EVENT__') {
return ev;
}
return arg;
});
this[methodName](...localEventArgs);
if (preventDefault) {
ev.preventDefault();
}
return this[methodName](...localEventArgs);
});
};

Expand Down

0 comments on commit a927b13

Please sign in to comment.