Disable link-insert button if target is empty

Set the opening state of the insertion button (in the insert-link
dialog) to disabled, and also disable it whenever the target field
is empty. This makes it unneccessary to show an alert when trying
to insert a blank target so that code is removed.

Bug: T293167
Change-Id: I3541f438fad9b7e0bf23ead2f2e164e84565d254
This commit is contained in:
Sam Wilson 2021-11-26 11:08:54 +08:00
parent 7fbd917c15
commit 79a0d3040e
4 changed files with 21 additions and 16 deletions

View file

@ -118,7 +118,6 @@
"wikieditor-toolbar-tool-link-lookslikeinternal",
"wikieditor-toolbar-tool-link-lookslikeinternal-int",
"wikieditor-toolbar-tool-link-lookslikeinternal-ext",
"wikieditor-toolbar-tool-link-empty",
"wikieditor-toolbar-tool-file",
"wikieditor-toolbar-tool-file-example",
"wikieditor-toolbar-tool-reference",

View file

@ -43,7 +43,6 @@
"wikieditor-toolbar-tool-link-lookslikeinternal": "The URL you specified looks like it was intended as a link to another wiki page.\nDo you want to make it an internal link?",
"wikieditor-toolbar-tool-link-lookslikeinternal-int": "Internal link",
"wikieditor-toolbar-tool-link-lookslikeinternal-ext": "External link",
"wikieditor-toolbar-tool-link-empty": "You did not enter anything to link to.",
"wikieditor-toolbar-tool-file": "Images and media",
"wikieditor-toolbar-tool-file-example": "Example.jpg",
"wikieditor-toolbar-tool-file-title": "Insert file",

View file

@ -73,7 +73,6 @@
"wikieditor-toolbar-tool-link-lookslikeinternal": "Used in the link dialog of the toolbar as hint when clicking the insert button",
"wikieditor-toolbar-tool-link-lookslikeinternal-int": "{{Identical|Internal link}}",
"wikieditor-toolbar-tool-link-lookslikeinternal-ext": "{{Identical|External link}}",
"wikieditor-toolbar-tool-link-empty": "Used in the link dialog of the toolbar as hint after clicking the insert button",
"wikieditor-toolbar-tool-file": "A tooltip on a toolbar button that adds a file (image, audio, or video).\n\nAppears in the same section with the following:\n* {{msg-mw|wikieditor-toolbar-tool-link}}\n* {{msg-mw|wikieditor-toolbar-tool-file}}\n* {{msg-mw|wikieditor-toolbar-tool-reference}}\n* {{msg-mw|templatewizard-dialog-title}} (on wikis where the TemplateWizard extension is installed)",
"wikieditor-toolbar-tool-file-example": "Translate Example, but don't translate .jpg\n{{Identical|Example}}",
"wikieditor-toolbar-tool-file-title": "Title for insert file dialog",

View file

@ -112,25 +112,31 @@
),
init: function () {
/**
* Convenience function for enabling/disabling the main insert button. This is a workaround for
* the fact that the button isn't yet in the DOM when init() is run, so we have to query for it
* in the event handlers.
*
* @param {boolean} enable Whether to enable or disable the button
*/
var setButtonState = function ( enable ) {
// eslint-disable-next-line no-jquery/no-sizzle
$( '.ui-dialog:visible .ui-dialog-buttonpane button' )
.first()
.prop( 'disabled', !enable )
.toggleClass( 'disabled', !enable );
};
// Automatically copy the value of the internal link page title field to the link text field unless the
// user has changed the link text field - this is a convenience thing since most link texts are going to
// be the same as the page title - Also change the internal/external radio button accordingly
// be the same as the page title.
insertLinkTitleInputField.connect( this, {
change: function ( val ) {
insertLinkLinkTypeField.setIsExternal( insertLinkTitleInputField.getField().isExternalLink( val ) );
insertLinkLinkTextField.setValueIfUntouched( val );
// eslint-disable-next-line no-jquery/no-sizzle
$( '.ui-dialog:visible .ui-dialog-buttonpane button' )
.first()
.prop( 'disabled', false )
.removeClass( 'disabled' );
setButtonState( val !== '' );
},
invalid: function () {
// eslint-disable-next-line no-jquery/no-sizzle
$( '.ui-dialog:visible .ui-dialog-buttonpane button' )
.first()
.prop( 'disabled', true )
.addClass( 'disabled' );
setButtonState( false );
}
} );
// Tell the title input field when the internal/external radio changes.
@ -271,8 +277,10 @@
var selection = context.$textarea.textSelection( 'getSelection' );
insertLinkTitleInputField.getField().focus();
// Trigger the change event, so the link status indicator is up to date
insertLinkTitleInputField.getField().$input.trigger( 'change' );
// Trigger the change event, so the link status indicator is up to date.
// It may be triggered again for the selection, below.
insertLinkTitleInputField.getField().emit( 'change', '' );
$( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [ '', '' ] );
if ( selection !== '' ) {
var matches, target, text, isExternal;