From e550968b8c0dd9671683b542d1580d8e52a899f9 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 9 Nov 2023 13:16:05 +0000 Subject: [PATCH] Bug 35012: Apply change to all events We should not just look at Click. Test plan: [1] Apply the example patch for a Blur action in barcode.pl. [2] Check that barcode.pl is active in your framework and that autoBarcode is not disabled. [3] Open the browser dev console. [4] Tab a few times through barcode in the neworderempty form of Acquisition. If you leave the field, the Blur event fires. => Without this patch you will see two console lines (FF may show a little '2' icon at the right side) added. With this patch just one. Signed-off-by: Marcel de Rooy Signed-off-by: Jan Kissig Signed-off-by: Katrin Fischer --- Koha/FrameworkPlugin.pm | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Koha/FrameworkPlugin.pm b/Koha/FrameworkPlugin.pm index 37666c52d8..481bb5b271 100644 --- a/Koha/FrameworkPlugin.pm +++ b/Koha/FrameworkPlugin.pm @@ -329,21 +329,13 @@ sub _add_binding { #click event applies to buttonDot if( $pars =~ /^(e|ev|event)$/i ) { # new style event handler assumed - - if ($ev eq "click"){ - # remove already registered click listeners - $bind= qq| \$("#$ctl").off('click');\n|; - $bind.= qq| \$("#$ctl").$ev(\{id: '$id'\}, $fname);\n|; - } else { - $bind= qq| \$("#$ctl").$ev(\{id: '$id'\}, $fname);\n|; - } - - $script=''; + $bind = qq| \$("#$ctl").off('$ev').on('$ev', \{id: '$id'\}, $fname);\n|; # remove old handler if any + $script = q{}; } elsif( $fname eq 'noclick' ) { # no click: return false, no scroll - $bind= qq| \$("#$ctl").$ev(function () { return false; });\n|; - $script=''; + $bind = qq| \$("#$ctl").$ev(function () { return false; });\n|; + $script = q{}; } else { # add real event handler calling the function found - $bind=qq| \$("#$ctl").$ev(\{id: '$id'\}, ${fname}_handler);\n|; + $bind = qq| \$("#$ctl").off('$ev').on('$ev', \{id: '$id'\}, ${fname}_handler);\n|; $script = $self->_add_handler( $ev, $fname ); } return ( $bind, $script ); -- 2.30.2