mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Ensure text version of counter is written to external links when copying
Bug: T137503 Change-Id: Iae791253ea272847984fee5d0586dc302027f1bd
This commit is contained in:
parent
4973740ae3
commit
aeca19c9ea
|
@ -55,8 +55,27 @@ ve.dm.MWNumberedExternalLinkNode.static.toDataElement = function ( domElements )
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
ve.dm.MWNumberedExternalLinkNode.static.toDomElements = function ( dataElement, doc ) {
|
ve.dm.MWNumberedExternalLinkNode.static.toDomElements = function ( dataElement, doc, converter ) {
|
||||||
var domElement = doc.createElement( 'a' );
|
var counter, offset,
|
||||||
|
node = this,
|
||||||
|
domElement = doc.createElement( 'a' );
|
||||||
|
|
||||||
|
// Ensure there is a text version of the counter in the clipboard
|
||||||
|
// as external documents may not have the same stylesheet - and Firefox
|
||||||
|
// discards empty tags on copy.
|
||||||
|
if ( converter.isForClipboard() ) {
|
||||||
|
counter = 1;
|
||||||
|
offset = converter.documentData.indexOf( dataElement );
|
||||||
|
|
||||||
|
if ( offset !== -1 ) {
|
||||||
|
converter.documentData.slice( 0, offset ).forEach( function ( el ) {
|
||||||
|
if ( el.type && el.type === node.name ) {
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
domElement.appendChild( doc.createTextNode( '[' + counter + ']' ) );
|
||||||
|
}
|
||||||
domElement.setAttribute( 'href', dataElement.attributes.href );
|
domElement.setAttribute( 'href', dataElement.attributes.href );
|
||||||
domElement.setAttribute( 'rel', 'mw:ExtLink' );
|
domElement.setAttribute( 'rel', 'mw:ExtLink' );
|
||||||
return [ domElement ];
|
return [ domElement ];
|
||||||
|
|
|
@ -1106,7 +1106,8 @@ ve.dm.mwExample.domToDataCases = {
|
||||||
{ type: '/paragraph' },
|
{ type: '/paragraph' },
|
||||||
{ type: 'internalList' },
|
{ type: 'internalList' },
|
||||||
{ type: '/internalList' }
|
{ type: '/internalList' }
|
||||||
]
|
],
|
||||||
|
clipboardBody: '<p>Foo<a rel="mw:ExtLink" href="http://www.example.com">[1]</a>Bar</p>'
|
||||||
},
|
},
|
||||||
'URL link': {
|
'URL link': {
|
||||||
body: '<p><a rel="mw:ExtLink" href="http://www.mediawiki.org/">mw</a></p>',
|
body: '<p><a rel="mw:ExtLink" href="http://www.mediawiki.org/">mw</a></p>',
|
||||||
|
|
Loading…
Reference in a new issue