De-duplicate and fix updating of file link in media dialog

Bug: T198565
Change-Id: I7d06d3316b317fb85edb9461080f5f2e5cd439fe
This commit is contained in:
Ed Sanders 2018-07-03 17:59:43 +01:00
parent dd794ddd40
commit 6bf9210abe

View file

@ -897,18 +897,7 @@ ve.ui.MWMediaDialog.prototype.confirmSelectedImage = function () {
}, },
info info
); );
// Update filename this.updateFilenameFieldset();
this.filenameFieldset.setLabel(
$( '<span>' ).append(
document.createTextNode( this.imageModel.getFilename() + ' ' ),
$( '<a>' )
.addClass( 'visualeditor-dialog-media-content-description-link' )
.attr( 'href', ve.resolveUrl( title, this.getFragment().getDocument().getHtmlDocument() ) )
.attr( 'target', '_blank' )
.attr( 'rel', 'noopener' )
.text( ve.msg( 'visualeditor-dialog-media-content-description-link' ) )
)
);
} }
// Cache // Cache
@ -927,6 +916,23 @@ ve.ui.MWMediaDialog.prototype.confirmSelectedImage = function () {
} }
}; };
/**
* Update the filename fieldset (link to media page)
*/
ve.ui.MWMediaDialog.prototype.updateFilenameFieldset = function () {
this.filenameFieldset.setLabel(
$( '<span>' ).append(
document.createTextNode( this.imageModel.getFilename() + ' ' ),
$( '<a>' )
.addClass( 'visualeditor-dialog-media-content-description-link' )
.attr( 'href', ve.resolveUrl( this.imageModel.getResourceName(), this.getFragment().getDocument().getHtmlDocument() ) )
.attr( 'target', '_blank' )
.attr( 'rel', 'noopener' )
.text( ve.msg( 'visualeditor-dialog-media-content-description-link' ) )
)
);
};
/** /**
* Handle image model alignment change * Handle image model alignment change
* *
@ -1207,17 +1213,7 @@ ve.ui.MWMediaDialog.prototype.attachImageModel = function () {
this.isSettingUpModel = true; this.isSettingUpModel = true;
// Filename // Filename
this.filenameFieldset.setLabel( this.updateFilenameFieldset();
$( '<span>' ).append(
document.createTextNode( this.imageModel.getFilename() + ' ' ),
$( '<a>' )
.addClass( 'visualeditor-dialog-media-content-description-link' )
.attr( 'href', ve.resolveUrl( this.imageModel.getResourceName(), this.getFragment().getDocument().getHtmlDocument() ) )
.attr( 'target', '_blank' )
.attr( 'rel', 'noopener' )
.text( ve.msg( 'visualeditor-dialog-media-content-description-link' ) )
)
);
// Size widget // Size widget
this.sizeErrorLabel.toggle( false ); this.sizeErrorLabel.toggle( false );