MediaWiki:Gadget-FDVEDiagramLink.js: Difference between revisions

Warn loudly if the VE classes are missing instead of failing silently
Remove the dead "Change which diagram is shown" link: the transclusion dialog is empty for a parser function, so it was a false affordance
Line 159: Line 159:


FDDiagramContextItem.prototype.renderBody = function () {
FDDiagramContextItem.prototype.renderBody = function () {
var item = this,
var page = diagramPageFromModel( this.model ),
page = diagramPageFromModel( this.model ),
url = this.getDiagramEditUrl(),
url = this.getDiagramEditUrl(),
$edit, $change;
$edit;


if ( !page || !url ) {
if ( !page || !url ) {
Line 178: Line 177:
ve.setAttributeSafe( $edit[ 0 ], 'href', url, '#' );
ve.setAttributeSafe( $edit[ 0 ], 'href', url, '#' );


// Overriding onEditButtonClick costs the normal route to changing which
// Deliberately the only control here. There was also a "Change which
// diagram is embedded, so offer it explicitly.
// diagram is shown" link that fell through to the stock transclusion
$change = $( '<a>' )
// dialog, but that dialog is empty for this node: #display_diagram is a
.addClass( 'fd-ve-diagramContextItem-change' )
// parser function, so the diagram page is part of the target string
.attr( 'href', '#' )
// rather than a parameter, and VE sources its parameter list from
.text( 'Change which diagram is shown' )
// TemplateData, which a parser function has none of. It looked
.on( 'click', function ( e ) {
// actionable and was not. To point an article at a different diagram,
e.preventDefault();
// edit the page source - it is one obvious line of wikitext.
ve.ui.MWTransclusionContextItem.prototype.onEditButtonClick.call( item );
this.$body.empty().append( $( '<div>' ).append( $edit ) );
} );
 
this.$body.empty().append(
$( '<div>' ).append( $edit ),
$( '<div>' ).append( $change )
);
};
};