mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-13 06:49:42 +00:00
d69d366469
Change-Id: Ic5504eb2fe8d1d3f22e88abe1dd88790bdfd8b9c
36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
mw.editcheck.ConvertReferenceEditCheck = function MWConvertReferenceEditCheck( /* config */ ) {
|
|
// Parent constructor
|
|
mw.editcheck.ConvertReferenceEditCheck.super.apply( this, arguments );
|
|
};
|
|
|
|
OO.inheritClass( mw.editcheck.ConvertReferenceEditCheck, mw.editcheck.BaseEditCheck );
|
|
|
|
mw.editcheck.ConvertReferenceEditCheck.static.name = 'convertReference';
|
|
|
|
mw.editcheck.ConvertReferenceEditCheck.prototype.onDocumentChange = function ( diff ) {
|
|
const seenIndexes = {};
|
|
return diff.documentModel.getNodesByType( 'mwReference' ).map( ( node ) => {
|
|
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( node );
|
|
const index = refModel.getListIndex();
|
|
if ( seenIndexes[ index ] ) {
|
|
return null;
|
|
}
|
|
seenIndexes[ index ] = true;
|
|
const referenceNode = diff.documentModel.getInternalList().getItemNode( index );
|
|
const href = ve.ui.CitoidReferenceContextItem.static.getConvertibleHref( referenceNode );
|
|
if ( href ) {
|
|
const fragment = diff.surface.getModel().getFragment( new ve.dm.LinearSelection( node.getOuterRange() ) );
|
|
return new mw.editcheck.EditCheckAction( {
|
|
highlight: fragment,
|
|
selection: fragment,
|
|
message: ve.msg( 'citoid-referencecontextitem-convert-message' ),
|
|
check: this
|
|
} );
|
|
} else {
|
|
return null;
|
|
}
|
|
} ).filter( ( obj ) => obj );
|
|
};
|
|
|
|
mw.editcheck.editCheckFactory.register( mw.editcheck.ConvertReferenceEditCheck );
|