TypeError: $button.trigger is not a function

This error is generating a large amount of logspam.
Add a check to avoid it, and DRY up.

The issue is caused by line 1182 setting dialogaction to false when
a dialog is closed. Presumably references to this data attribute
remain.

Bug: T261529
Change-Id: Ie75f737980dfcbcc4829def1e5a6894262d73b31
This commit is contained in:
jdlrobson 2021-02-10 10:29:40 -08:00 committed by Bartosz Dziewoński
parent 80b3582116
commit 760f023f21

View file

@ -7,6 +7,17 @@
toolbarModule = require( './jquery.wikiEditor.toolbar.js' ),
configData = require( './data.json' );
function triggerButtonClick( element ) {
var $button;
$button = $( element ).data( 'dialogaction' ) || $( element ).find( 'button' ).first();
// Since we're reading from data attribute, make sure we got an element before clicking.
// Note when closing a dialog this can be false leading to TypeError: $button.trigger is not a function
// (T261529)
if ( $button ) {
$button.trigger( 'click' );
}
}
module.exports = {
replaceIcons: function ( $textarea ) {
@ -521,10 +532,8 @@
// Execute the action associated with the first button
// when the user presses Enter
$( this ).closest( '.ui-dialog' ).on( 'keypress', function ( e ) {
var $button;
if ( ( e.keyCode || e.which ) === 13 ) {
$button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button' ).first();
$button.trigger( 'click' );
triggerButtonClick( this );
e.preventDefault();
}
} );
@ -773,11 +782,8 @@
// Execute the action associated with the first button
// when the user presses Enter
$( this ).closest( '.ui-dialog' ).on( 'keypress', function ( e ) {
var $button;
if ( e.which === 13 ) {
$button = $( this ).data( 'dialogaction' ) ||
$( this ).find( 'button' ).first();
$button.trigger( 'click' );
triggerButtonClick( this );
e.preventDefault();
}
} );
@ -944,10 +950,8 @@
// Execute the action associated with the first button
// when the user presses Enter
$( this ).closest( '.ui-dialog' ).on( 'keypress', function ( e ) {
var $button;
if ( ( e.keyCode || e.which ) === 13 ) {
$button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button' ).first();
$button.trigger( 'click' );
triggerButtonClick( this );
e.preventDefault();
}
} );
@ -1143,10 +1147,8 @@
// Execute the action associated with the first button
// when the user presses Enter
$( this ).closest( '.ui-dialog' ).on( 'keypress', function ( e ) {
var $button;
if ( ( e.keyCode || e.which ) === 13 ) {
$button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button' ).first();
$button.trigger( 'click' );
triggerButtonClick( this );
e.preventDefault();
}
} );
@ -1163,11 +1165,9 @@
$textbox
.on( 'keypress.srdialog', function ( e ) {
var $button;
if ( e.which === 13 ) {
// Enter
$button = $dialog.data( 'dialogaction' ) || $dialog.find( 'button' ).first();
$button.trigger( 'click' );
triggerButtonClick( $dialog );
e.preventDefault();
} else if ( e.which === 27 ) {
// Escape