mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
Disable inserting/changing references when surface widget is empty
This listens to change events on the surface and checks to see if there is more than just an empty paragraph node. Bug: 53345 Change-Id: Ic8fa84d7cdcbffd154178939d0ec8c2c4f86c415
This commit is contained in:
parent
92c7be9b31
commit
f50102f521
|
@ -342,6 +342,9 @@ ve.ui.MWReferenceDialog.prototype.useReference = function ( ref ) {
|
|||
}
|
||||
);
|
||||
|
||||
// Event handlers
|
||||
this.referenceSurface.getSurface().getModel().connect( this, { 'change': 'onSurfaceChange' } );
|
||||
|
||||
// Initialization
|
||||
this.referenceGroupInput.setValue( refGroup );
|
||||
this.contentFieldset.$.append( this.referenceSurface.$ );
|
||||
|
@ -350,6 +353,18 @@ ve.ui.MWReferenceDialog.prototype.useReference = function ( ref ) {
|
|||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle reference surface change events
|
||||
*/
|
||||
ve.ui.MWReferenceDialog.prototype.onSurfaceChange = function () {
|
||||
var data = this.referenceSurface.getContent(),
|
||||
// TODO: Check for other types of empty, e.g. only whitespace?
|
||||
disabled = data.length <= 2;
|
||||
|
||||
this.insertButton.setDisabled( disabled );
|
||||
this.applyButton.setDisabled( disabled );
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ui.dialogFactory.register( 'mwReference', ve.ui.MWReferenceDialog );
|
||||
|
|
|
@ -59,11 +59,11 @@ ve.ui.Widget.prototype.isDisabled = function () {
|
|||
* This should probably change the widgets's appearance and prevent it from being used.
|
||||
*
|
||||
* @method
|
||||
* @param {boolean} state Disable button
|
||||
* @param {boolean} disabled Disable button
|
||||
* @chainable
|
||||
*/
|
||||
ve.ui.Widget.prototype.setDisabled = function ( state ) {
|
||||
this.disabled = !!state;
|
||||
ve.ui.Widget.prototype.setDisabled = function ( disabled ) {
|
||||
this.disabled = !!disabled;
|
||||
if ( this.disabled ) {
|
||||
this.$.addClass( 've-ui-widget-disabled' );
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue