mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 14:36:51 +00:00
Convert Cite extention to ES6
Bug: T343220 Change-Id: I769f0bfaa5af14d6ea4861ea738b44c98feb6193
This commit is contained in:
parent
8fe57fcd71
commit
1eb405eb54
|
@ -1,7 +1,12 @@
|
|||
{
|
||||
"root": true,
|
||||
"extends": [
|
||||
"wikimedia/server",
|
||||
"wikimedia/client-es6",
|
||||
"wikimedia/jquery",
|
||||
"wikimedia/mediawiki"
|
||||
]
|
||||
],
|
||||
|
||||
"rules": {
|
||||
"max-len": "off"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"root": true,
|
||||
"extends": [
|
||||
"wikimedia/client",
|
||||
"wikimedia/jquery",
|
||||
"wikimedia/mediawiki"
|
||||
],
|
||||
"rules": {
|
||||
"max-len": "off",
|
||||
"no-var": "off"
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Main JavaScript for the Cite extension. The main purpose of this file
|
||||
* is to add accessibility attributes to the citation links as that can
|
||||
|
@ -6,14 +8,13 @@
|
|||
* @author Marius Hoch <hoo@online.de>
|
||||
*/
|
||||
( function () {
|
||||
'use strict';
|
||||
|
||||
mw.hook( 'wikipage.content' ).add( function ( $content ) {
|
||||
var accessibilityLabelOne = mw.msg( 'cite_references_link_accessibility_label' ),
|
||||
accessibilityLabelMany = mw.msg( 'cite_references_link_many_accessibility_label' );
|
||||
const accessibilityLabelOne = mw.msg( 'cite_references_link_accessibility_label' );
|
||||
const accessibilityLabelMany = mw.msg( 'cite_references_link_many_accessibility_label' );
|
||||
|
||||
$content.find( '.mw-cite-backlink' ).each( function () {
|
||||
var $links = $( this ).find( 'a' );
|
||||
const $links = $( this ).find( 'a' );
|
||||
|
||||
if ( $links.length > 1 ) {
|
||||
// This citation is used multiple times. Let's only set the accessibility label on the first link, the
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* @author Thiemo Kreuz
|
||||
*/
|
||||
( function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Checks if the ID uses a composite format that does not only consist of a sequential number,
|
||||
* as specified in "cite_reference_link_key_with_num".
|
||||
|
@ -12,7 +12,7 @@
|
|||
* @return {boolean}
|
||||
*/
|
||||
function isNamedReference( id ) {
|
||||
var prefix = mw.msg( 'cite_reference_link_prefix' );
|
||||
const prefix = mw.msg( 'cite_reference_link_prefix' );
|
||||
|
||||
// Note: This assumes IDs start with the prefix; this is guaranteed by the parser function
|
||||
return /\D/.test( id.slice( prefix.length ) );
|
||||
|
@ -38,12 +38,12 @@
|
|||
* @return {jQuery}
|
||||
*/
|
||||
function makeUpArrowLink( $backlinkWrapper ) {
|
||||
var textNode = $backlinkWrapper[ 0 ].firstChild,
|
||||
accessibilityLabel = mw.msg( 'cite_references_link_accessibility_back_label' ),
|
||||
$upArrowLink = $( '<a>' )
|
||||
.addClass( 'mw-cite-up-arrow-backlink' )
|
||||
.attr( 'aria-label', accessibilityLabel )
|
||||
.attr( 'title', accessibilityLabel );
|
||||
let textNode = $backlinkWrapper[ 0 ].firstChild;
|
||||
const accessibilityLabel = mw.msg( 'cite_references_link_accessibility_back_label' );
|
||||
const $upArrowLink = $( '<a>' )
|
||||
.addClass( 'mw-cite-up-arrow-backlink' )
|
||||
.attr( 'aria-label', accessibilityLabel )
|
||||
.attr( 'title', accessibilityLabel );
|
||||
|
||||
if ( !textNode ) {
|
||||
return $upArrowLink;
|
||||
|
@ -58,7 +58,7 @@
|
|||
return $upArrowLink;
|
||||
}
|
||||
|
||||
var upArrow = textNode.data.trim();
|
||||
const upArrow = textNode.data.trim();
|
||||
// The text node typically contains "↑ ", and we need to keep the space.
|
||||
textNode.data = textNode.data.replace( upArrow, '' );
|
||||
|
||||
|
@ -80,8 +80,8 @@
|
|||
*/
|
||||
function updateUpArrowLink( $backlink ) {
|
||||
// It's convenient to stop at the class name, but it's not guaranteed to be there.
|
||||
var $backlinkWrapper = $backlink.closest( '.mw-cite-backlink, li' ),
|
||||
$upArrowLink = $backlinkWrapper.find( '.mw-cite-up-arrow-backlink' );
|
||||
const $backlinkWrapper = $backlink.closest( '.mw-cite-backlink, li' );
|
||||
let $upArrowLink = $backlinkWrapper.find( '.mw-cite-up-arrow-backlink' );
|
||||
|
||||
if ( !$upArrowLink.length && $backlinkWrapper.length ) {
|
||||
$upArrowLink = makeUpArrowLink( $backlinkWrapper );
|
||||
|
@ -93,7 +93,7 @@
|
|||
mw.hook( 'wikipage.content' ).add( function ( $content ) {
|
||||
// We are going to use the ID in the code below, so better be sure one is there.
|
||||
$content.find( '.reference[id] > a' ).on( 'click', function () {
|
||||
var id = $( this ).parent().attr( 'id' );
|
||||
const id = $( this ).parent().attr( 'id' );
|
||||
|
||||
$content.find( '.mw-cite-targeted-backlink' ).removeClass( 'mw-cite-targeted-backlink' );
|
||||
|
||||
|
@ -103,7 +103,7 @@
|
|||
}
|
||||
|
||||
// The :not() skips the duplicate link created below. Relevant when double clicking.
|
||||
var $backlink = $content.find( '.references a[href="#' + $.escapeSelector( id ) + '"]:not(.mw-cite-up-arrow-backlink)' )
|
||||
const $backlink = $content.find( '.references a[href="#' + $.escapeSelector( id ) + '"]:not(.mw-cite-up-arrow-backlink)' )
|
||||
.first()
|
||||
.addClass( 'mw-cite-targeted-backlink' );
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* @file Temporary tracking to evaluate the impact of Reference Previews on users' interaction with references.
|
||||
*
|
||||
|
@ -13,11 +15,10 @@
|
|||
|
||||
// EventLogging may not be installed
|
||||
mw.loader.using( 'ext.eventLogging' ).then( function () {
|
||||
'use strict';
|
||||
|
||||
$( function () {
|
||||
var isReferencePreviewsEnabled = mw.config.get( 'wgPopupsReferencePreviews', false ),
|
||||
samplingRate = isReferencePreviewsEnabled ? 1 : 1000;
|
||||
const isReferencePreviewsEnabled = mw.config.get( 'wgPopupsReferencePreviews', false );
|
||||
const samplingRate = isReferencePreviewsEnabled ? 1 : 1000;
|
||||
|
||||
if ( !navigator.sendBeacon ||
|
||||
!mw.config.get( 'wgIsArticle' ) ||
|
||||
|
@ -27,7 +28,7 @@ mw.loader.using( 'ext.eventLogging' ).then( function () {
|
|||
return;
|
||||
}
|
||||
|
||||
var loggingTopic = isReferencePreviewsEnabled ?
|
||||
const loggingTopic = isReferencePreviewsEnabled ?
|
||||
'event.ReferencePreviewsCite' :
|
||||
'event.ReferencePreviewsBaseline';
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
|
@ -36,7 +37,7 @@ mw.loader.using( 'ext.eventLogging' ).then( function () {
|
|||
// Footnote links, references block in VisualEditor, and reference content links.
|
||||
'.reference a[ href*="#" ], .mw-reference-text a, .reference-text a',
|
||||
function () {
|
||||
var isInReferenceBlock = $( this ).parents( '.references' ).length > 0;
|
||||
const isInReferenceBlock = $( this ).parents( '.references' ).length > 0;
|
||||
mw.track( loggingTopic, {
|
||||
action: ( isInReferenceBlock ?
|
||||
'clickedReferenceContentLink' :
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Add Cite-specific functionality to the WikiEditor toolbar.
|
||||
* Adds a button to insert <ref> tags, and adds a help section
|
||||
|
@ -30,7 +32,7 @@ $( function () {
|
|||
} );
|
||||
|
||||
/* Add reference help to the Help section */
|
||||
var parsedRef = function ( number ) {
|
||||
const parsedRef = function ( number ) {
|
||||
return $( '<sup>' )
|
||||
.addClass( 'reference' )
|
||||
.append(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor DataModel Cite-specific Converter tests.
|
||||
*
|
||||
|
@ -8,10 +10,10 @@
|
|||
QUnit.module( 've.dm.Converter (Cite)', ve.test.utils.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'getModelFromDom', function ( assert ) {
|
||||
var cases = ve.dm.citeExample.domToDataCases;
|
||||
const cases = ve.dm.citeExample.domToDataCases;
|
||||
|
||||
for ( var msg in cases ) {
|
||||
var caseItem = ve.copy( cases[ msg ] );
|
||||
for ( const msg in cases ) {
|
||||
const caseItem = ve.copy( cases[ msg ] );
|
||||
caseItem.base = ve.dm.citeExample.baseUri;
|
||||
caseItem.mwConfig = {
|
||||
wgArticlePath: '/wiki/$1'
|
||||
|
@ -27,10 +29,10 @@ QUnit.test( 'getModelFromDom', function ( assert ) {
|
|||
} );
|
||||
|
||||
QUnit.test( 'getDomFromModel', function ( assert ) {
|
||||
var cases = ve.dm.citeExample.domToDataCases;
|
||||
const cases = ve.dm.citeExample.domToDataCases;
|
||||
|
||||
for ( var msg in cases ) {
|
||||
var caseItem = ve.copy( cases[ msg ] );
|
||||
for ( const msg in cases ) {
|
||||
const caseItem = ve.copy( cases[ msg ] );
|
||||
caseItem.base = ve.dm.citeExample.baseUri;
|
||||
caseItem.mwConfig = {
|
||||
wgArticlePath: '/wiki/$1'
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor DataModel Cite-specific InternalList tests.
|
||||
*
|
||||
|
@ -10,44 +12,44 @@ QUnit.module( 've.dm.InternalList (Cite)', ve.test.utils.newMwEnvironment() );
|
|||
/* Tests */
|
||||
|
||||
QUnit.test( 'addNode/removeNode', function ( assert ) {
|
||||
var doc = ve.dm.citeExample.createExampleDocument( 'references' ),
|
||||
newInternalList = new ve.dm.InternalList( doc ),
|
||||
referenceNodes = [
|
||||
doc.getDocumentNode().children[ 0 ].children[ 0 ],
|
||||
doc.getDocumentNode().children[ 1 ].children[ 1 ],
|
||||
doc.getDocumentNode().children[ 1 ].children[ 3 ],
|
||||
doc.getDocumentNode().children[ 1 ].children[ 5 ],
|
||||
doc.getDocumentNode().children[ 2 ].children[ 0 ],
|
||||
doc.getDocumentNode().children[ 2 ].children[ 1 ]
|
||||
],
|
||||
expectedNodes = {
|
||||
'mwReference/': {
|
||||
keyedNodes: {
|
||||
'auto/0': [ referenceNodes[ 0 ] ],
|
||||
'literal/bar': [ referenceNodes[ 1 ], referenceNodes[ 3 ] ],
|
||||
'literal/:3': [ referenceNodes[ 2 ] ],
|
||||
'auto/1': [ referenceNodes[ 4 ] ]
|
||||
},
|
||||
firstNodes: [
|
||||
referenceNodes[ 0 ],
|
||||
referenceNodes[ 1 ],
|
||||
referenceNodes[ 2 ],
|
||||
referenceNodes[ 4 ]
|
||||
],
|
||||
indexOrder: [ 0, 1, 2, 3 ],
|
||||
uniqueListKeys: {},
|
||||
uniqueListKeysInUse: {}
|
||||
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
|
||||
let newInternalList = new ve.dm.InternalList( doc );
|
||||
const referenceNodes = [
|
||||
doc.getDocumentNode().children[ 0 ].children[ 0 ],
|
||||
doc.getDocumentNode().children[ 1 ].children[ 1 ],
|
||||
doc.getDocumentNode().children[ 1 ].children[ 3 ],
|
||||
doc.getDocumentNode().children[ 1 ].children[ 5 ],
|
||||
doc.getDocumentNode().children[ 2 ].children[ 0 ],
|
||||
doc.getDocumentNode().children[ 2 ].children[ 1 ]
|
||||
];
|
||||
const expectedNodes = {
|
||||
'mwReference/': {
|
||||
keyedNodes: {
|
||||
'auto/0': [ referenceNodes[ 0 ] ],
|
||||
'literal/bar': [ referenceNodes[ 1 ], referenceNodes[ 3 ] ],
|
||||
'literal/:3': [ referenceNodes[ 2 ] ],
|
||||
'auto/1': [ referenceNodes[ 4 ] ]
|
||||
},
|
||||
'mwReference/foo': {
|
||||
keyedNodes: {
|
||||
'auto/2': [ referenceNodes[ 5 ] ]
|
||||
},
|
||||
firstNodes: [ undefined, undefined, undefined, undefined, referenceNodes[ 5 ] ],
|
||||
indexOrder: [ 4 ],
|
||||
uniqueListKeys: {},
|
||||
uniqueListKeysInUse: {}
|
||||
}
|
||||
};
|
||||
firstNodes: [
|
||||
referenceNodes[ 0 ],
|
||||
referenceNodes[ 1 ],
|
||||
referenceNodes[ 2 ],
|
||||
referenceNodes[ 4 ]
|
||||
],
|
||||
indexOrder: [ 0, 1, 2, 3 ],
|
||||
uniqueListKeys: {},
|
||||
uniqueListKeysInUse: {}
|
||||
},
|
||||
'mwReference/foo': {
|
||||
keyedNodes: {
|
||||
'auto/2': [ referenceNodes[ 5 ] ]
|
||||
},
|
||||
firstNodes: [ undefined, undefined, undefined, undefined, referenceNodes[ 5 ] ],
|
||||
indexOrder: [ 4 ],
|
||||
uniqueListKeys: {},
|
||||
uniqueListKeysInUse: {}
|
||||
}
|
||||
};
|
||||
|
||||
assert.deepEqualWithNodeTree(
|
||||
doc.internalList.nodes,
|
||||
|
@ -185,11 +187,11 @@ QUnit.test( 'addNode/removeNode', function ( assert ) {
|
|||
} );
|
||||
|
||||
QUnit.test( 'getItemInsertion', function ( assert ) {
|
||||
var doc = ve.dm.citeExample.createExampleDocument( 'references' ),
|
||||
internalList = doc.getInternalList();
|
||||
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
|
||||
const internalList = doc.getInternalList();
|
||||
|
||||
var insertion = internalList.getItemInsertion( 'mwReference/', 'literal/foo', [] );
|
||||
var index = internalList.getItemNodeCount();
|
||||
let insertion = internalList.getItemInsertion( 'mwReference/', 'literal/foo', [] );
|
||||
const index = internalList.getItemNodeCount();
|
||||
assert.strictEqual( insertion.index, index, 'Insertion creates a new reference' );
|
||||
assert.deepEqual(
|
||||
insertion.transaction.getOperations(),
|
||||
|
@ -213,10 +215,10 @@ QUnit.test( 'getItemInsertion', function ( assert ) {
|
|||
} );
|
||||
|
||||
QUnit.test( 'getUniqueListKey', function ( assert ) {
|
||||
var doc = ve.dm.citeExample.createExampleDocument( 'references' ),
|
||||
internalList = doc.getInternalList();
|
||||
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
|
||||
const internalList = doc.getInternalList();
|
||||
|
||||
var generatedName;
|
||||
let generatedName;
|
||||
generatedName = internalList.getUniqueListKey( 'mwReference/', 'auto/0', 'literal/:' );
|
||||
assert.strictEqual( generatedName, 'literal/:0', '0 maps to 0' );
|
||||
generatedName = internalList.getUniqueListKey( 'mwReference/', 'auto/1', 'literal/:' );
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor DataModel Cite-specific Transaction tests.
|
||||
*
|
||||
|
@ -9,7 +11,7 @@ QUnit.module( 've.dm.Transaction (Cite)', ve.test.utils.newMwEnvironment() );
|
|||
|
||||
// FIXME: Duplicates test runner; should be using a data provider
|
||||
QUnit.test( 'newFromDocumentInsertion with references', function ( assert ) {
|
||||
var complexDoc = ve.dm.citeExample.createExampleDocument( 'complexInternalData' ),
|
||||
const complexDoc = ve.dm.citeExample.createExampleDocument( 'complexInternalData' ),
|
||||
withReference = [
|
||||
{ type: 'paragraph' },
|
||||
'B', 'a', 'r',
|
||||
|
@ -69,15 +71,15 @@ QUnit.test( 'newFromDocumentInsertion with references', function ( assert ) {
|
|||
];
|
||||
|
||||
cases.forEach( function ( caseItem ) {
|
||||
var doc = ve.dm.citeExample.createExampleDocument( caseItem.doc );
|
||||
var doc2, removalOps;
|
||||
const doc = ve.dm.citeExample.createExampleDocument( caseItem.doc );
|
||||
let doc2, removalOps;
|
||||
if ( caseItem.newDocData ) {
|
||||
doc2 = new ve.dm.Document( caseItem.newDocData );
|
||||
removalOps = [];
|
||||
} else if ( caseItem.range ) {
|
||||
doc2 = doc.cloneFromRange( caseItem.range );
|
||||
caseItem.modify( doc2 );
|
||||
var removalTx = ve.dm.TransactionBuilder.static.newFromRemoval( doc, caseItem.range, true );
|
||||
const removalTx = ve.dm.TransactionBuilder.static.newFromRemoval( doc, caseItem.range, true );
|
||||
doc.commit( removalTx );
|
||||
removalOps = removalTx.getOperations();
|
||||
}
|
||||
|
@ -86,15 +88,15 @@ QUnit.test( 'newFromDocumentInsertion with references', function ( assert ) {
|
|||
removalOps, caseItem.removalOps, caseItem.msg + ': removal'
|
||||
);
|
||||
|
||||
var tx = ve.dm.TransactionBuilder.static.newFromDocumentInsertion(
|
||||
const tx = ve.dm.TransactionBuilder.static.newFromDocumentInsertion(
|
||||
doc, caseItem.offset, doc2
|
||||
);
|
||||
assert.deepEqualWithDomElements(
|
||||
tx.getOperations(), caseItem.expectedOps, caseItem.msg + ': transaction'
|
||||
);
|
||||
|
||||
var expectedStoreItems = caseItem.expectedStoreItems || [];
|
||||
var actualStoreItems = expectedStoreItems.map( function ( item ) {
|
||||
const expectedStoreItems = caseItem.expectedStoreItems || [];
|
||||
const actualStoreItems = expectedStoreItems.map( function ( item ) {
|
||||
return doc.store.value( OO.getHash( item ) );
|
||||
} );
|
||||
assert.deepEqual( actualStoreItems, expectedStoreItems, caseItem.msg + ': store items' );
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor DataModel Cite-specific example data sets.
|
||||
*
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor Cite-specific DiffElement tests.
|
||||
*
|
||||
|
@ -7,9 +9,9 @@
|
|||
QUnit.module( 've.ui.DiffElement (Cite)' );
|
||||
|
||||
QUnit.test( 'Diffing', function ( assert ) {
|
||||
var spacer = '<div class="ve-ui-diffElement-spacer">⋮</div>',
|
||||
const spacer = '<div class="ve-ui-diffElement-spacer">⋮</div>',
|
||||
ref = function ( text, num ) {
|
||||
var dataMw = {
|
||||
const dataMw = {
|
||||
name: 'ref',
|
||||
body: { html: text }
|
||||
// attrs doesn't get set in preview mode
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor UserInterface MWWikitextStringTransferHandler tests.
|
||||
*
|
||||
|
@ -15,7 +17,7 @@ QUnit.module( 've.ui.MWWikitextStringTransferHandler (Cite)', ve.test.utils.newM
|
|||
/* Tests */
|
||||
|
||||
QUnit.test( 'convert', function ( assert ) {
|
||||
var cases = [
|
||||
const cases = [
|
||||
{
|
||||
msg: 'Simple reference',
|
||||
pasteString: '<ref>Foo</ref>',
|
||||
|
@ -82,7 +84,7 @@ QUnit.test( 'convert', function ( assert ) {
|
|||
}
|
||||
];
|
||||
|
||||
var server = this.server;
|
||||
const server = this.server;
|
||||
cases.forEach( function ( caseItem ) {
|
||||
ve.test.utils.runWikitextStringHandlerTest(
|
||||
assert, server, caseItem.pasteString, caseItem.pasteType,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor ContentEditable MWReferenceNode class.
|
||||
*
|
||||
|
@ -110,12 +112,12 @@ ve.ce.MWReferenceNode.prototype.onAttributeChange = function ( key ) {
|
|||
* @inheritdoc ve.ce.FocusableNode
|
||||
*/
|
||||
ve.ce.MWReferenceNode.prototype.executeCommand = function () {
|
||||
var items = ve.ui.contextItemFactory.getRelatedItems( [ this.model ] );
|
||||
const items = ve.ui.contextItemFactory.getRelatedItems( [ this.model ] );
|
||||
|
||||
if ( items.length ) {
|
||||
var contextItem = ve.ui.contextItemFactory.lookup( items[ 0 ].name );
|
||||
const contextItem = ve.ui.contextItemFactory.lookup( items[ 0 ].name );
|
||||
if ( contextItem ) {
|
||||
var command = this.getRoot().getSurface().getSurface().commandRegistry.lookup( contextItem.static.commandName );
|
||||
const command = this.getRoot().getSurface().getSurface().commandRegistry.lookup( contextItem.static.commandName );
|
||||
if ( command ) {
|
||||
command.execute( this.focusableSurface.getSurface() );
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor ContentEditable MWReferencesListNode class.
|
||||
*
|
||||
|
@ -76,7 +78,7 @@ ve.ce.MWReferencesListNode.static.getDescription = function ( model ) {
|
|||
* @inheritdoc ve.ce.FocusableNode
|
||||
*/
|
||||
ve.ce.MWReferencesListNode.prototype.getExtraHighlightClasses = function () {
|
||||
var extraClasses = ve.ce.FocusableNode.prototype.getExtraHighlightClasses.apply( this, arguments );
|
||||
const extraClasses = ve.ce.FocusableNode.prototype.getExtraHighlightClasses.apply( this, arguments );
|
||||
return extraClasses.concat( [
|
||||
've-ce-mwReferencesListNode-highlight'
|
||||
] );
|
||||
|
@ -173,20 +175,20 @@ ve.ce.MWReferencesListNode.prototype.onListNodeUpdate = function () {
|
|||
* Update the references list.
|
||||
*/
|
||||
ve.ce.MWReferencesListNode.prototype.update = function () {
|
||||
var model = this.getModel();
|
||||
const model = this.getModel();
|
||||
|
||||
// Check the node hasn't been destroyed, as this method is debounced.
|
||||
if ( !model ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var internalList = model.getDocument().internalList;
|
||||
var refGroup = model.getAttribute( 'refGroup' );
|
||||
var listGroup = model.getAttribute( 'listGroup' );
|
||||
var nodes = internalList.getNodeGroup( listGroup );
|
||||
var hasModelReferences = !!( nodes && nodes.indexOrder.length );
|
||||
const internalList = model.getDocument().internalList;
|
||||
const refGroup = model.getAttribute( 'refGroup' );
|
||||
const listGroup = model.getAttribute( 'listGroup' );
|
||||
const nodes = internalList.getNodeGroup( listGroup );
|
||||
const hasModelReferences = !!( nodes && nodes.indexOrder.length );
|
||||
|
||||
var emptyText;
|
||||
let emptyText;
|
||||
if ( refGroup !== '' ) {
|
||||
emptyText = ve.msg( 'cite-ve-referenceslist-isempty', refGroup );
|
||||
} else {
|
||||
|
@ -230,10 +232,10 @@ ve.ce.MWReferencesListNode.prototype.update = function () {
|
|||
this.$element.append( this.$refmsg );
|
||||
} else {
|
||||
nodes.indexOrder.forEach( function ( index ) {
|
||||
var firstNode = nodes.firstNodes[ index ];
|
||||
const firstNode = nodes.firstNodes[ index ];
|
||||
|
||||
var key = internalList.keys[ index ];
|
||||
var keyedNodes = nodes.keyedNodes[ key ];
|
||||
const key = internalList.keys[ index ];
|
||||
let keyedNodes = nodes.keyedNodes[ key ];
|
||||
keyedNodes = keyedNodes.filter( function ( node ) {
|
||||
// Exclude placeholders and references defined inside the references list node
|
||||
return !node.getAttribute( 'placeholder' ) &&
|
||||
|
@ -244,13 +246,13 @@ ve.ce.MWReferencesListNode.prototype.update = function () {
|
|||
return;
|
||||
}
|
||||
|
||||
var $li = $( '<li>' )
|
||||
const $li = $( '<li>' )
|
||||
.append( this.renderBacklinks( keyedNodes, refGroup ), ' ' );
|
||||
|
||||
// Generate reference HTML from first item in key
|
||||
var modelNode = internalList.getItemNode( firstNode.getAttribute( 'listIndex' ) );
|
||||
const modelNode = internalList.getItemNode( firstNode.getAttribute( 'listIndex' ) );
|
||||
if ( modelNode && modelNode.length ) {
|
||||
var refPreview = new ve.ui.MWPreviewElement( modelNode, { useView: true } );
|
||||
const refPreview = new ve.ui.MWPreviewElement( modelNode, { useView: true } );
|
||||
$li.append(
|
||||
$( '<span>' )
|
||||
.addClass( 'reference-text' )
|
||||
|
@ -265,22 +267,22 @@ ve.ce.MWReferencesListNode.prototype.update = function () {
|
|||
}
|
||||
|
||||
if ( this.getRoot() ) {
|
||||
var surface = this.getRoot().getSurface().getSurface();
|
||||
const surface = this.getRoot().getSurface().getSurface();
|
||||
$li.on( 'mousedown', function ( e ) {
|
||||
if ( modelNode && modelNode.length ) {
|
||||
var items = ve.ui.contextItemFactory.getRelatedItems( [ firstNode ] ).filter( function ( item ) {
|
||||
const items = ve.ui.contextItemFactory.getRelatedItems( [ firstNode ] ).filter( function ( item ) {
|
||||
return item.name !== 'mobileActions';
|
||||
} );
|
||||
if ( items.length ) {
|
||||
var contextItem = ve.ui.contextItemFactory.lookup( items[ 0 ].name );
|
||||
const contextItem = ve.ui.contextItemFactory.lookup( items[ 0 ].name );
|
||||
if ( contextItem ) {
|
||||
var command = surface.commandRegistry.lookup( contextItem.static.commandName );
|
||||
const command = surface.commandRegistry.lookup( contextItem.static.commandName );
|
||||
if ( command ) {
|
||||
var fragmentArgs = {
|
||||
const fragmentArgs = {
|
||||
fragment: surface.getModel().getLinearFragment( firstNode.getOuterRange(), true ),
|
||||
selectFragmentOnClose: false
|
||||
};
|
||||
var newArgs = ve.copy( command.args );
|
||||
const newArgs = ve.copy( command.args );
|
||||
if ( command.name === 'reference' ) {
|
||||
newArgs[ 1 ] = fragmentArgs;
|
||||
} else {
|
||||
|
@ -309,7 +311,7 @@ ve.ce.MWReferencesListNode.prototype.update = function () {
|
|||
* Currently used to set responsive layout
|
||||
*/
|
||||
ve.ce.MWReferencesListNode.prototype.updateClasses = function () {
|
||||
var isResponsive = this.getModel().getAttribute( 'isResponsive' );
|
||||
const isResponsive = this.getModel().getAttribute( 'isResponsive' );
|
||||
|
||||
this.$element
|
||||
.toggleClass( 'mw-references-wrap', isResponsive )
|
||||
|
@ -332,8 +334,8 @@ ve.ce.MWReferencesListNode.prototype.renderBacklinks = function ( keyedNodes, re
|
|||
}
|
||||
|
||||
// named reference with multiple usages
|
||||
var $refSpan = $( '<span>' ).attr( 'rel', 'mw:referencedBy' );
|
||||
for ( var i = 0; i < keyedNodes.length; i++ ) {
|
||||
const $refSpan = $( '<span>' ).attr( 'rel', 'mw:referencedBy' );
|
||||
for ( let i = 0; i < keyedNodes.length; i++ ) {
|
||||
$( '<a>' )
|
||||
.attr( 'data-mw-group', refGroup || null )
|
||||
.append( $( '<span>' ).addClass( 'mw-linkback-text' ).text( ( i + 1 ) + ' ' ) )
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor DataModel MWReferenceModel class.
|
||||
*
|
||||
|
@ -42,10 +44,10 @@ OO.mixinClass( ve.dm.MWReferenceModel, OO.EventEmitter );
|
|||
* @return {ve.dm.MWReferenceModel} Reference model
|
||||
*/
|
||||
ve.dm.MWReferenceModel.static.newFromReferenceNode = function ( node ) {
|
||||
var doc = node.getDocument(),
|
||||
internalList = doc.getInternalList(),
|
||||
attr = node.getAttributes(),
|
||||
ref = new ve.dm.MWReferenceModel( doc );
|
||||
const doc = node.getDocument();
|
||||
const internalList = doc.getInternalList();
|
||||
const attr = node.getAttributes();
|
||||
const ref = new ve.dm.MWReferenceModel( doc );
|
||||
|
||||
ref.setExtendsRef( attr.extendsRef );
|
||||
ref.setListKey( attr.listKey );
|
||||
|
@ -85,15 +87,15 @@ ve.dm.MWReferenceModel.prototype.findInternalItem = function ( surfaceModel ) {
|
|||
*/
|
||||
ve.dm.MWReferenceModel.prototype.insertInternalItem = function ( surfaceModel ) {
|
||||
// Create new internal item
|
||||
var doc = surfaceModel.getDocument(),
|
||||
internalList = doc.getInternalList();
|
||||
const doc = surfaceModel.getDocument();
|
||||
const internalList = doc.getInternalList();
|
||||
|
||||
// Fill in data
|
||||
this.setListKey( 'auto/' + internalList.getNextUniqueNumber() );
|
||||
this.setListGroup( 'mwReference/' + this.group );
|
||||
|
||||
// Insert internal reference item into document
|
||||
var item = internalList.getItemInsertion( this.listGroup, this.listKey, [] );
|
||||
const item = internalList.getItemInsertion( this.listGroup, this.listKey, [] );
|
||||
surfaceModel.change( item.transaction );
|
||||
this.setListIndex( item.index );
|
||||
|
||||
|
@ -115,26 +117,26 @@ ve.dm.MWReferenceModel.prototype.insertInternalItem = function ( surfaceModel )
|
|||
* @param {ve.dm.Surface} surfaceModel Surface model of main document
|
||||
*/
|
||||
ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel ) {
|
||||
var doc = surfaceModel.getDocument(),
|
||||
internalList = doc.getInternalList(),
|
||||
listGroup = 'mwReference/' + this.group;
|
||||
const doc = surfaceModel.getDocument();
|
||||
const internalList = doc.getInternalList();
|
||||
const listGroup = 'mwReference/' + this.group;
|
||||
|
||||
// Group/key has changed
|
||||
if ( this.listGroup !== listGroup ) {
|
||||
// Get all reference nodes with the same group and key
|
||||
var group = internalList.getNodeGroup( this.listGroup );
|
||||
var refNodes = group.keyedNodes[ this.listKey ] ?
|
||||
const group = internalList.getNodeGroup( this.listGroup );
|
||||
const refNodes = group.keyedNodes[ this.listKey ] ?
|
||||
group.keyedNodes[ this.listKey ].slice() :
|
||||
[ group.firstNodes[ this.listIndex ] ];
|
||||
// Check for name collision when moving items between groups
|
||||
var keyIndex = internalList.getKeyIndex( this.listGroup, this.listKey );
|
||||
const keyIndex = internalList.getKeyIndex( this.listGroup, this.listKey );
|
||||
if ( keyIndex !== undefined ) {
|
||||
// Resolve name collision by generating a new list key
|
||||
this.listKey = 'auto/' + internalList.getNextUniqueNumber();
|
||||
}
|
||||
// Update the group name of all references nodes with the same group and key
|
||||
var txs = [];
|
||||
for ( var i = 0, len = refNodes.length; i < len; i++ ) {
|
||||
const txs = [];
|
||||
for ( let i = 0, len = refNodes.length; i < len; i++ ) {
|
||||
txs.push( ve.dm.TransactionBuilder.static.newFromAttributeChanges(
|
||||
doc,
|
||||
refNodes[ i ].getOuterRange().start,
|
||||
|
@ -145,7 +147,7 @@ ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel )
|
|||
this.listGroup = listGroup;
|
||||
}
|
||||
// Update internal node content
|
||||
var itemNodeRange = internalList.getItemNode( this.listIndex ).getRange();
|
||||
const itemNodeRange = internalList.getItemNode( this.listIndex ).getRange();
|
||||
surfaceModel.change( ve.dm.TransactionBuilder.static.newFromRemoval( doc, itemNodeRange, true ) );
|
||||
surfaceModel.change(
|
||||
ve.dm.TransactionBuilder.static.newFromDocumentInsertion( doc, itemNodeRange.start, this.getDocument() )
|
||||
|
@ -159,7 +161,7 @@ ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel )
|
|||
* @param {boolean} [placeholder] Reference is a placeholder for staging purposes
|
||||
*/
|
||||
ve.dm.MWReferenceModel.prototype.insertReferenceNode = function ( surfaceFragment, placeholder ) {
|
||||
var attributes = {
|
||||
const attributes = {
|
||||
extendsRef: this.extendsRef,
|
||||
listKey: this.listKey,
|
||||
listGroup: this.listGroup,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor DataModel MWReferenceNode class.
|
||||
*
|
||||
|
@ -64,28 +66,28 @@ ve.dm.MWReferenceNode.static.listKeyRegex = /^(auto|literal)\/([\s\S]*)$/;
|
|||
|
||||
ve.dm.MWReferenceNode.static.toDataElement = function ( domElements, converter ) {
|
||||
function getReflistItemHtml( id ) {
|
||||
var elem = converter.getHtmlDocument().getElementById( id );
|
||||
const elem = converter.getHtmlDocument().getElementById( id );
|
||||
return elem && elem.innerHTML || '';
|
||||
}
|
||||
|
||||
var mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' );
|
||||
var mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
||||
var reflistItemId = mwData.body && mwData.body.id;
|
||||
var body = ( mwData.body && mwData.body.html ) ||
|
||||
const mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' );
|
||||
const mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
||||
const reflistItemId = mwData.body && mwData.body.id;
|
||||
const body = ( mwData.body && mwData.body.html ) ||
|
||||
( reflistItemId && getReflistItemHtml( reflistItemId ) ) ||
|
||||
'';
|
||||
var extendsRef = mw.config.get( 'wgCiteBookReferencing' ) && mwData.attrs && mwData.attrs.extends;
|
||||
var refGroup = mwData.attrs && mwData.attrs.group || '';
|
||||
var listGroup = this.name + '/' + refGroup;
|
||||
var autoKeyed = !mwData.attrs || mwData.attrs.name === undefined;
|
||||
var listKey = autoKeyed ?
|
||||
const extendsRef = mw.config.get( 'wgCiteBookReferencing' ) && mwData.attrs && mwData.attrs.extends;
|
||||
const refGroup = mwData.attrs && mwData.attrs.group || '';
|
||||
const listGroup = this.name + '/' + refGroup;
|
||||
const autoKeyed = !mwData.attrs || mwData.attrs.name === undefined;
|
||||
const listKey = autoKeyed ?
|
||||
'auto/' + converter.internalList.getNextUniqueNumber() :
|
||||
'literal/' + mwData.attrs.name;
|
||||
var queueResult = converter.internalList.queueItemHtml( listGroup, listKey, body );
|
||||
var listIndex = queueResult.index;
|
||||
var contentsUsed = ( body !== '' && queueResult.isNew );
|
||||
const queueResult = converter.internalList.queueItemHtml( listGroup, listKey, body );
|
||||
const listIndex = queueResult.index;
|
||||
const contentsUsed = ( body !== '' && queueResult.isNew );
|
||||
|
||||
var dataElement = {
|
||||
const dataElement = {
|
||||
type: this.name,
|
||||
attributes: {
|
||||
mw: mwData,
|
||||
|
@ -107,33 +109,32 @@ ve.dm.MWReferenceNode.static.toDataElement = function ( domElements, converter )
|
|||
};
|
||||
|
||||
ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, converter ) {
|
||||
var isForClipboard = converter.isForClipboard(),
|
||||
el = doc.createElement( 'sup' );
|
||||
const isForClipboard = converter.isForClipboard();
|
||||
const el = doc.createElement( 'sup' );
|
||||
|
||||
el.setAttribute( 'typeof', 'mw:Extension/ref' );
|
||||
|
||||
var mwData = dataElement.attributes.mw ? ve.copy( dataElement.attributes.mw ) : {};
|
||||
const mwData = dataElement.attributes.mw ? ve.copy( dataElement.attributes.mw ) : {};
|
||||
mwData.name = 'ref';
|
||||
|
||||
if ( isForClipboard || converter.isForParser() ) {
|
||||
var setContents = dataElement.attributes.contentsUsed;
|
||||
let setContents = dataElement.attributes.contentsUsed;
|
||||
|
||||
// This call rebuilds the document tree if it isn't built already (e.g. on a
|
||||
// document slice), so only use when necessary (i.e. not in preview mode)
|
||||
var itemNode = converter.internalList.getItemNode( dataElement.attributes.listIndex );
|
||||
var itemNodeRange = itemNode.getRange();
|
||||
const itemNode = converter.internalList.getItemNode( dataElement.attributes.listIndex );
|
||||
const itemNodeRange = itemNode.getRange();
|
||||
|
||||
var keyedNodes = converter.internalList
|
||||
const keyedNodes = converter.internalList
|
||||
.getNodeGroup( dataElement.attributes.listGroup )
|
||||
.keyedNodes[ dataElement.attributes.listKey ];
|
||||
|
||||
var i, iLen;
|
||||
var contentsAlreadySet = false;
|
||||
let contentsAlreadySet = false;
|
||||
if ( setContents ) {
|
||||
// Check if a previous node has already set the content. If so, we don't overwrite this
|
||||
// node's contents.
|
||||
if ( keyedNodes ) {
|
||||
for ( i = 0, iLen = keyedNodes.length; i < iLen; i++ ) {
|
||||
for ( let i = 0; i < keyedNodes.length; i++ ) {
|
||||
if (
|
||||
ve.compare(
|
||||
this.getInstanceHashObject( keyedNodes[ i ].element ),
|
||||
|
@ -163,7 +164,7 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver
|
|||
setContents = true;
|
||||
// Check no other reference originally defined the contents
|
||||
// As this is keyedNodes[0] we can start at 1
|
||||
for ( i = 1, iLen = keyedNodes.length; i < iLen; i++ ) {
|
||||
for ( let i = 1; i < keyedNodes.length; i++ ) {
|
||||
if ( keyedNodes[ i ].element.attributes.contentsUsed ) {
|
||||
setContents = false;
|
||||
break;
|
||||
|
@ -174,14 +175,14 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver
|
|||
|
||||
// Add reference contents to data-mw.
|
||||
if ( setContents && !contentsAlreadySet ) {
|
||||
var itemNodeWrapper = doc.createElement( 'div' );
|
||||
var originalHtmlWrapper = doc.createElement( 'div' );
|
||||
const itemNodeWrapper = doc.createElement( 'div' );
|
||||
const originalHtmlWrapper = doc.createElement( 'div' );
|
||||
converter.getDomSubtreeFromData(
|
||||
itemNode.getDocument().getFullData( itemNodeRange, 'roundTrip' ),
|
||||
itemNodeWrapper
|
||||
);
|
||||
var itemNodeHtml = itemNodeWrapper.innerHTML; // Returns '' if itemNodeWrapper is empty
|
||||
var originalHtml = ve.getProp( mwData, 'body', 'html' ) ||
|
||||
const itemNodeHtml = itemNodeWrapper.innerHTML; // Returns '' if itemNodeWrapper is empty
|
||||
const originalHtml = ve.getProp( mwData, 'body', 'html' ) ||
|
||||
( ve.getProp( mwData, 'body', 'id' ) !== undefined && itemNode.getAttribute( 'originalHtml' ) ) ||
|
||||
'';
|
||||
originalHtmlWrapper.innerHTML = originalHtml;
|
||||
|
@ -204,8 +205,8 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver
|
|||
}
|
||||
|
||||
// Generate name
|
||||
var name;
|
||||
var listKeyParts = dataElement.attributes.listKey.match( this.listKeyRegex );
|
||||
let name;
|
||||
const listKeyParts = dataElement.attributes.listKey.match( this.listKeyRegex );
|
||||
if ( listKeyParts[ 1 ] === 'auto' ) {
|
||||
// Only render a name if this key was reused
|
||||
if ( keyedNodes.length > 1 ) {
|
||||
|
@ -237,7 +238,7 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver
|
|||
// If mwAttr and originalMw are the same, use originalMw to prevent reserialization,
|
||||
// unless we are writing the clipboard for use in another VE instance
|
||||
// Reserialization has the potential to reorder keys and so change the DOM unnecessarily
|
||||
var originalMw = dataElement.attributes.originalMw;
|
||||
const originalMw = dataElement.attributes.originalMw;
|
||||
if ( converter.isForParser() && originalMw && ve.compare( mwData, JSON.parse( originalMw ) ) ) {
|
||||
el.setAttribute( 'data-mw', originalMw );
|
||||
|
||||
|
@ -249,7 +250,7 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver
|
|||
el.setAttribute( 'data-mw', JSON.stringify( mwData ) );
|
||||
|
||||
// HTML for the external clipboard, it will be ignored by the converter
|
||||
var $link = $( '<a>', doc )
|
||||
const $link = $( '<a>', doc )
|
||||
.css( 'counterReset', 'mw-Ref ' + this.getIndex( dataElement, converter.internalList ) )
|
||||
.attr( 'data-mw-group', this.getGroup( dataElement ) || null );
|
||||
$( el ).addClass( 'mw-ref reference' ).append(
|
||||
|
@ -263,19 +264,18 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver
|
|||
};
|
||||
|
||||
ve.dm.MWReferenceNode.static.remapInternalListIndexes = function ( dataElement, mapping, internalList ) {
|
||||
var listKeyParts;
|
||||
// Remap listIndex
|
||||
dataElement.attributes.listIndex = mapping[ dataElement.attributes.listIndex ];
|
||||
|
||||
// Remap listKey if it was automatically generated
|
||||
listKeyParts = dataElement.attributes.listKey.match( this.listKeyRegex );
|
||||
const listKeyParts = dataElement.attributes.listKey.match( this.listKeyRegex );
|
||||
if ( listKeyParts[ 1 ] === 'auto' ) {
|
||||
dataElement.attributes.listKey = 'auto/' + internalList.getNextUniqueNumber();
|
||||
}
|
||||
};
|
||||
|
||||
ve.dm.MWReferenceNode.static.remapInternalListKeys = function ( dataElement, internalList ) {
|
||||
var suffix = '';
|
||||
let suffix = '';
|
||||
// Try name, name2, name3, ... until unique
|
||||
while ( internalList.keys.indexOf( dataElement.attributes.listKey + suffix ) !== -1 ) {
|
||||
suffix = suffix ? suffix + 1 : 2;
|
||||
|
@ -294,8 +294,8 @@ ve.dm.MWReferenceNode.static.remapInternalListKeys = function ( dataElement, int
|
|||
* @return {number} Index
|
||||
*/
|
||||
ve.dm.MWReferenceNode.static.getIndex = function ( dataElement, internalList ) {
|
||||
var overrideIndex = ve.getProp( dataElement, 'internal', 'overrideIndex' );
|
||||
var attrs = dataElement.attributes;
|
||||
const overrideIndex = ve.getProp( dataElement, 'internal', 'overrideIndex' );
|
||||
const attrs = dataElement.attributes;
|
||||
return overrideIndex || ( internalList.getIndexPosition( attrs.listGroup, attrs.listIndex ) + 1 );
|
||||
};
|
||||
|
||||
|
@ -319,9 +319,9 @@ ve.dm.MWReferenceNode.static.getGroup = function ( dataElement ) {
|
|||
* @return {string} Reference label
|
||||
*/
|
||||
ve.dm.MWReferenceNode.static.getIndexLabel = function ( dataElement, internalList ) {
|
||||
var refGroup = dataElement.attributes.refGroup,
|
||||
index = dataElement.attributes.placeholder ? '…' :
|
||||
ve.dm.MWReferenceNode.static.getIndex( dataElement, internalList );
|
||||
const refGroup = dataElement.attributes.refGroup;
|
||||
const index = dataElement.attributes.placeholder ? '…' :
|
||||
ve.dm.MWReferenceNode.static.getIndex( dataElement, internalList );
|
||||
|
||||
return '[' + ( refGroup ? refGroup + ' ' : '' ) + index + ']';
|
||||
};
|
||||
|
@ -330,7 +330,7 @@ ve.dm.MWReferenceNode.static.getIndexLabel = function ( dataElement, internalLis
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.dm.MWReferenceNode.static.cloneElement = function () {
|
||||
var clone = ve.dm.MWReferenceNode.super.static.cloneElement.apply( this, arguments );
|
||||
const clone = ve.dm.MWReferenceNode.super.static.cloneElement.apply( this, arguments );
|
||||
delete clone.attributes.contentsUsed;
|
||||
delete clone.attributes.mw;
|
||||
delete clone.attributes.originalMw;
|
||||
|
@ -400,7 +400,7 @@ ve.dm.MWReferenceNode.static.describeChange = function ( key, change ) {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.dm.MWReferenceNode.prototype.isEditable = function () {
|
||||
var internalItem = this.getInternalItem();
|
||||
const internalItem = this.getInternalItem();
|
||||
return internalItem && internalItem.getLength() > 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor DataModel MWReferencesListNode class.
|
||||
*
|
||||
|
@ -84,9 +86,9 @@ ve.dm.MWReferencesListNode.static.matchFunction = function ( domElement ) {
|
|||
ve.dm.MWReferencesListNode.static.preserveHtmlAttributes = false;
|
||||
|
||||
ve.dm.MWReferencesListNode.static.toDataElement = function ( domElements, converter ) {
|
||||
var type = domElements[ 0 ].getAttribute( 'typeof' ) || '';
|
||||
const type = domElements[ 0 ].getAttribute( 'typeof' ) || '';
|
||||
|
||||
var refListNode;
|
||||
let refListNode;
|
||||
// We may have matched a mw:Transclusion wrapping a reference list, so pull out the refListNode
|
||||
if ( type.indexOf( 'mw:Extension/references' ) !== -1 ) {
|
||||
refListNode = domElements[ 0 ];
|
||||
|
@ -96,15 +98,15 @@ ve.dm.MWReferencesListNode.static.toDataElement = function ( domElements, conver
|
|||
domElements[ 1 ].querySelector( '[typeof*="mw:Extension/references"]' );
|
||||
}
|
||||
|
||||
var mwDataJSON = refListNode.getAttribute( 'data-mw' );
|
||||
var mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
||||
var refGroup = ve.getProp( mwData, 'attrs', 'group' ) || '';
|
||||
var responsiveAttr = ve.getProp( mwData, 'attrs', 'responsive' );
|
||||
var listGroup = 'mwReference/' + refGroup;
|
||||
var templateGenerated = type.indexOf( 'mw:Transclusion' ) !== -1;
|
||||
var isResponsiveDefault = mw.config.get( 'wgCiteResponsiveReferences' );
|
||||
const mwDataJSON = refListNode.getAttribute( 'data-mw' );
|
||||
const mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
||||
const refGroup = ve.getProp( mwData, 'attrs', 'group' ) || '';
|
||||
const responsiveAttr = ve.getProp( mwData, 'attrs', 'responsive' );
|
||||
const listGroup = 'mwReference/' + refGroup;
|
||||
const templateGenerated = type.indexOf( 'mw:Transclusion' ) !== -1;
|
||||
const isResponsiveDefault = mw.config.get( 'wgCiteResponsiveReferences' );
|
||||
|
||||
var referencesListData = {
|
||||
let referencesListData = {
|
||||
type: this.name,
|
||||
attributes: {
|
||||
mw: mwData,
|
||||
|
@ -118,9 +120,9 @@ ve.dm.MWReferencesListNode.static.toDataElement = function ( domElements, conver
|
|||
if ( mwData.body && mwData.body.html && !templateGenerated ) {
|
||||
// Process the nodes in .body.html as if they were this node's children
|
||||
// Don't process template-generated reflists, that mangles the content (T209493)
|
||||
var contentsDiv = domElements[ 0 ].ownerDocument.createElement( 'div' );
|
||||
const contentsDiv = domElements[ 0 ].ownerDocument.createElement( 'div' );
|
||||
contentsDiv.innerHTML = mwData.body.html;
|
||||
var contentsData = converter.getDataFromDomClean( contentsDiv );
|
||||
const contentsData = converter.getDataFromDomClean( contentsDiv );
|
||||
referencesListData = [ referencesListData ]
|
||||
.concat( contentsData )
|
||||
.concat( [ { type: '/' + this.name } ] );
|
||||
|
@ -129,9 +131,9 @@ ve.dm.MWReferencesListNode.static.toDataElement = function ( domElements, conver
|
|||
};
|
||||
|
||||
ve.dm.MWReferencesListNode.static.toDomElements = function ( data, doc, converter ) {
|
||||
var isForParser = converter.isForParser(),
|
||||
dataElement = data[ 0 ],
|
||||
attrs = dataElement.attributes;
|
||||
const isForParser = converter.isForParser();
|
||||
const dataElement = data[ 0 ];
|
||||
const attrs = dataElement.attributes;
|
||||
|
||||
// If we are sending a template generated ref back to Parsoid, output it as a template.
|
||||
// This works because the dataElement already has mw, originalMw and originalDomIndex properties.
|
||||
|
@ -139,13 +141,13 @@ ve.dm.MWReferencesListNode.static.toDomElements = function ( data, doc, converte
|
|||
return ve.dm.MWTransclusionNode.static.toDomElements.call( this, dataElement, doc, converter );
|
||||
}
|
||||
|
||||
var els;
|
||||
let els;
|
||||
if ( !isForParser ) {
|
||||
// Output needs to be read so re-render
|
||||
var modelNode = ve.dm.nodeFactory.createFromElement( dataElement );
|
||||
const modelNode = ve.dm.nodeFactory.createFromElement( dataElement );
|
||||
// Build from original doc's internal list to get all refs (T186407)
|
||||
modelNode.setDocument( converter.originalDocInternalList.getDocument() );
|
||||
var viewNode = ve.ce.nodeFactory.createFromModel( modelNode );
|
||||
const viewNode = ve.ce.nodeFactory.createFromModel( modelNode );
|
||||
viewNode.modified = true;
|
||||
viewNode.update();
|
||||
els = [ doc.createElement( 'div' ) ];
|
||||
|
@ -159,7 +161,7 @@ ve.dm.MWReferencesListNode.static.toDomElements = function ( data, doc, converte
|
|||
els = [ doc.createElement( 'div' ) ];
|
||||
}
|
||||
|
||||
var mwData = attrs.mw ? ve.copy( attrs.mw ) : {};
|
||||
const mwData = attrs.mw ? ve.copy( attrs.mw ) : {};
|
||||
|
||||
mwData.name = 'references';
|
||||
|
||||
|
@ -169,10 +171,10 @@ ve.dm.MWReferencesListNode.static.toDomElements = function ( data, doc, converte
|
|||
delete mwData.attrs.refGroup;
|
||||
}
|
||||
|
||||
var originalMw = attrs.originalMw;
|
||||
var originalMwData = originalMw && JSON.parse( originalMw );
|
||||
var originalResponsiveAttr = ve.getProp( originalMwData, 'attrs', 'responsive' );
|
||||
var isResponsiveDefault = mw.config.get( 'wgCiteResponsiveReferences' );
|
||||
const originalMw = attrs.originalMw;
|
||||
const originalMwData = originalMw && JSON.parse( originalMw );
|
||||
const originalResponsiveAttr = ve.getProp( originalMwData, 'attrs', 'responsive' );
|
||||
const isResponsiveDefault = mw.config.get( 'wgCiteResponsiveReferences' );
|
||||
|
||||
if ( !(
|
||||
// The original "responsive" attribute hasn't had its meaning changed
|
||||
|
@ -193,8 +195,8 @@ ve.dm.MWReferencesListNode.static.toDomElements = function ( data, doc, converte
|
|||
// the document.
|
||||
// TODO: it would be better to do this without needing to fish through
|
||||
// the converter's linear data. Use the DM tree instead?
|
||||
var nextIndex = converter.documentData.indexOf( data[ data.length - 1 ] ) + 1;
|
||||
var nextElement;
|
||||
let nextIndex = converter.documentData.indexOf( data[ data.length - 1 ] ) + 1;
|
||||
let nextElement;
|
||||
while ( ( nextElement = converter.documentData[ nextIndex ] ) ) {
|
||||
if ( nextElement.type[ 0 ] !== '/' ) {
|
||||
break;
|
||||
|
@ -206,16 +208,16 @@ ve.dm.MWReferencesListNode.static.toDomElements = function ( data, doc, converte
|
|||
}
|
||||
}
|
||||
|
||||
var el = els[ 0 ];
|
||||
const el = els[ 0 ];
|
||||
el.setAttribute( 'typeof', 'mw:Extension/references' );
|
||||
|
||||
var contentsData = data.slice( 1, -1 );
|
||||
const contentsData = data.slice( 1, -1 );
|
||||
if ( contentsData.length > 2 ) {
|
||||
var wrapper = doc.createElement( 'div' );
|
||||
const wrapper = doc.createElement( 'div' );
|
||||
converter.getDomSubtreeFromData( data.slice( 1, -1 ), wrapper );
|
||||
var contentsHtml = wrapper.innerHTML; // Returns '' if wrapper is empty
|
||||
var originalHtml = ve.getProp( mwData, 'body', 'html' ) || '';
|
||||
var originalHtmlWrapper = doc.createElement( 'div' );
|
||||
const contentsHtml = wrapper.innerHTML; // Returns '' if wrapper is empty
|
||||
const originalHtml = ve.getProp( mwData, 'body', 'html' ) || '';
|
||||
const originalHtmlWrapper = doc.createElement( 'div' );
|
||||
originalHtmlWrapper.innerHTML = originalHtml;
|
||||
// Only set body.html if contentsHtml and originalHtml are actually different
|
||||
if ( !originalHtmlWrapper.isEqualNode( wrapper ) ) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor UserInterface MWCitationAction class.
|
||||
*
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor MWCitationContextItem class.
|
||||
*
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*
|
||||
* VisualEditor user interface MWCitationDialog class.
|
||||
*
|
||||
|
@ -40,7 +42,7 @@ ve.ui.MWCitationDialog.static.name = 'cite';
|
|||
* @return {ve.dm.MWReferenceNode|null} Reference node to be edited, null if none exists
|
||||
*/
|
||||
ve.ui.MWCitationDialog.prototype.getReferenceNode = function () {
|
||||
var selectedNode = this.getFragment().getSelectedNode();
|
||||
const selectedNode = this.getFragment().getSelectedNode();
|
||||
|
||||
if ( selectedNode instanceof ve.dm.MWReferenceNode ) {
|
||||
return selectedNode;
|
||||
|
@ -53,12 +55,12 @@ ve.ui.MWCitationDialog.prototype.getReferenceNode = function () {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWCitationDialog.prototype.getSelectedNode = function () {
|
||||
var referenceNode = this.getReferenceNode();
|
||||
const referenceNode = this.getReferenceNode();
|
||||
|
||||
var transclusionNode;
|
||||
let transclusionNode;
|
||||
if ( referenceNode ) {
|
||||
var branches = referenceNode.getInternalItem().getChildren();
|
||||
var leaves = branches &&
|
||||
const branches = referenceNode.getInternalItem().getChildren();
|
||||
const leaves = branches &&
|
||||
branches.length === 1 &&
|
||||
branches[ 0 ].canContainContent() &&
|
||||
branches[ 0 ].getChildren();
|
||||
|
@ -142,23 +144,22 @@ ve.ui.MWCitationDialog.prototype.setApplicableStatus = function () {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWCitationDialog.prototype.getActionProcess = function ( action ) {
|
||||
var dialog = this;
|
||||
const dialog = this;
|
||||
if (
|
||||
this.inDialog !== 'reference' &&
|
||||
( action === 'done' || action === 'insert' )
|
||||
) {
|
||||
return new OO.ui.Process( function () {
|
||||
var deferred = $.Deferred();
|
||||
const deferred = $.Deferred();
|
||||
dialog.checkRequiredParameters().done( function () {
|
||||
var item, refDoc,
|
||||
surfaceModel = dialog.getFragment().getSurface(),
|
||||
doc = surfaceModel.getDocument(),
|
||||
internalList = doc.getInternalList(),
|
||||
obj = dialog.transclusionModel.getPlainObject();
|
||||
const surfaceModel = dialog.getFragment().getSurface();
|
||||
const doc = surfaceModel.getDocument();
|
||||
const internalList = doc.getInternalList();
|
||||
const obj = dialog.transclusionModel.getPlainObject();
|
||||
|
||||
// We had a reference, but no template node (or wrong kind of template node)
|
||||
if ( dialog.referenceModel && !dialog.selectedNode ) {
|
||||
refDoc = dialog.referenceModel.getDocument();
|
||||
const refDoc = dialog.referenceModel.getDocument();
|
||||
// Empty the existing reference, whatever it contained. This allows the dialog to be
|
||||
// used for arbitrary references (to replace their contents with a citation).
|
||||
refDoc.commit(
|
||||
|
@ -174,7 +175,7 @@ ve.ui.MWCitationDialog.prototype.getActionProcess = function ( action ) {
|
|||
dialog.referenceModel.insertReferenceNode( dialog.getFragment() );
|
||||
}
|
||||
|
||||
item = dialog.referenceModel.findInternalItem( surfaceModel );
|
||||
const item = dialog.referenceModel.findInternalItem( surfaceModel );
|
||||
if ( item ) {
|
||||
if ( dialog.selectedNode ) {
|
||||
dialog.transclusionModel.updateTransclusionNode(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor MediaWiki UserInterface citation dialog tool class.
|
||||
*
|
||||
|
@ -25,7 +27,6 @@ ve.ui.MWCitationDialogTool = function VeUiMWCitationDialogTool( toolbar, config
|
|||
OO.inheritClass( ve.ui.MWCitationDialogTool, ve.ui.MWReferenceDialogTool );
|
||||
|
||||
/* Static Properties */
|
||||
|
||||
ve.ui.MWCitationDialogTool.static.group = 'cite';
|
||||
|
||||
/**
|
||||
|
@ -43,15 +44,15 @@ ve.ui.MWCitationDialogTool.static.template = null;
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWCitationDialogTool.static.isCompatibleWith = function ( model ) {
|
||||
var compatible = ve.ui.MWCitationDialogTool.super.static.isCompatibleWith.call( this, model );
|
||||
const compatible = ve.ui.MWCitationDialogTool.super.static.isCompatibleWith.call( this, model );
|
||||
|
||||
if ( compatible && this.template ) {
|
||||
// Check if content of the reference node contains only a template with the same name as
|
||||
// this.template
|
||||
var internalItem = model.getInternalItem();
|
||||
var branches = internalItem.getChildren();
|
||||
const internalItem = model.getInternalItem();
|
||||
const branches = internalItem.getChildren();
|
||||
if ( branches.length === 1 && branches[ 0 ].canContainContent() ) {
|
||||
var leaves = branches[ 0 ].getChildren();
|
||||
const leaves = branches[ 0 ].getChildren();
|
||||
if ( leaves.length === 1 && leaves[ 0 ] instanceof ve.dm.MWTransclusionNode ) {
|
||||
return leaves[ 0 ].isSingleTemplate( this.template );
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor MWCitationNeededContextItem class.
|
||||
*
|
||||
|
@ -48,28 +50,27 @@ ve.ui.MWCitationNeededContextItem.static.label = OO.ui.deferMsg( 'cite-ve-citati
|
|||
/* Methods */
|
||||
|
||||
ve.ui.MWCitationNeededContextItem.prototype.onAddClick = function () {
|
||||
var contextItem = this,
|
||||
surface = this.context.getSurface(),
|
||||
encapsulatedWikitext = this.getCanonicalParam( 'encapsulate' );
|
||||
const contextItem = this;
|
||||
const surface = this.context.getSurface();
|
||||
const encapsulatedWikitext = this.getCanonicalParam( 'encapsulate' );
|
||||
|
||||
var promise;
|
||||
let promise;
|
||||
if ( encapsulatedWikitext ) {
|
||||
this.addButton.setDisabled( true );
|
||||
promise = ve.init.target.parseWikitextFragment( encapsulatedWikitext, false, this.model.getDocument() ).then( function ( response ) {
|
||||
var dmDoc, nodes, range;
|
||||
|
||||
if ( ve.getProp( response, 'visualeditor', 'result' ) !== 'success' ) {
|
||||
return ve.createDeferred().reject().promise();
|
||||
}
|
||||
|
||||
dmDoc = ve.ui.MWWikitextStringTransferHandler.static.createDocumentFromParsoidHtml(
|
||||
const dmDoc = ve.ui.MWWikitextStringTransferHandler.static.createDocumentFromParsoidHtml(
|
||||
response.visualeditor.content,
|
||||
surface.getModel().getDocument()
|
||||
);
|
||||
|
||||
nodes = dmDoc.getDocumentNode().children.filter( function ( node ) {
|
||||
const nodes = dmDoc.getDocumentNode().children.filter( function ( node ) {
|
||||
return !node.isInternal();
|
||||
} );
|
||||
let range;
|
||||
|
||||
// Unwrap single content branch nodes to match internal copy/paste behaviour
|
||||
// (which wouldn't put the open and close tags in the clipboard to begin with).
|
||||
|
@ -92,7 +93,7 @@ ve.ui.MWCitationNeededContextItem.prototype.onAddClick = function () {
|
|||
}
|
||||
|
||||
// TODO: This assumes Citoid is installed...
|
||||
var action = ve.ui.actionFactory.create( 'citoid', surface );
|
||||
const action = ve.ui.actionFactory.create( 'citoid', surface );
|
||||
promise.then( function ( inStaging ) {
|
||||
action.open( true, undefined, inStaging );
|
||||
} );
|
||||
|
@ -103,8 +104,8 @@ ve.ui.MWCitationNeededContextItem.prototype.onAddClick = function () {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWCitationNeededContextItem.prototype.renderBody = function () {
|
||||
var date = this.getCanonicalParam( 'date' ),
|
||||
description = ve.msg( 'cite-ve-citationneeded-description' );
|
||||
const date = this.getCanonicalParam( 'date' );
|
||||
let description = ve.msg( 'cite-ve-citationneeded-description' );
|
||||
|
||||
if ( date ) {
|
||||
description += ve.msg( 'word-separator' ) + ve.msg( 'parentheses', date );
|
||||
|
@ -113,7 +114,7 @@ ve.ui.MWCitationNeededContextItem.prototype.renderBody = function () {
|
|||
this.$body.empty();
|
||||
this.$body.append( $( '<p>' ).addClass( 've-ui-mwCitationNeededContextItem-description' ).text( description ) );
|
||||
|
||||
var reason = this.getCanonicalParam( 'reason' );
|
||||
const reason = this.getCanonicalParam( 'reason' );
|
||||
if ( reason ) {
|
||||
this.$body.append(
|
||||
$( '<p>' ).addClass( 've-ui-mwCitationNeededContextItem-reason' ).append(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor MediaWiki Cite initialisation code.
|
||||
*
|
||||
|
@ -7,12 +9,11 @@
|
|||
|
||||
( function () {
|
||||
function fixTarget( target ) {
|
||||
var toolGroups = target.static.toolbarGroups;
|
||||
const toolGroups = target.static.toolbarGroups;
|
||||
|
||||
var i, iLen;
|
||||
if ( mw.config.get( 'wgCiteVisualEditorOtherGroup' ) ) {
|
||||
for ( i = 0, iLen = toolGroups.length; i < iLen; i++ ) {
|
||||
var toolGroup = toolGroups[ i ];
|
||||
for ( let i = 0; i < toolGroups.length; i++ ) {
|
||||
const toolGroup = toolGroups[ i ];
|
||||
if ( toolGroup.name === 'insert' && ( !toolGroup.demote || toolGroup.demote.indexOf( 'reference' ) === -1 ) ) {
|
||||
toolGroup.demote = toolGroup.demote || [];
|
||||
toolGroup.demote.push( { group: 'cite' }, 'reference', 'reference/existing' );
|
||||
|
@ -20,9 +21,9 @@
|
|||
}
|
||||
} else {
|
||||
// Find the reference placeholder group and replace it
|
||||
for ( i = 0, iLen = toolGroups.length; i < iLen; i++ ) {
|
||||
for ( let i = 0; i < toolGroups.length; i++ ) {
|
||||
if ( toolGroups[ i ].name === 'reference' ) {
|
||||
var group = {
|
||||
const group = {
|
||||
// Change the name so it isn't replaced twice
|
||||
name: 'cite',
|
||||
type: 'list',
|
||||
|
@ -30,7 +31,7 @@
|
|||
include: [ { group: 'cite' }, 'reference', 'reference/existing' ],
|
||||
demote: [ 'reference', 'reference/existing' ]
|
||||
};
|
||||
var label = OO.ui.deferMsg( 'cite-ve-toolbar-group-label' );
|
||||
const label = OO.ui.deferMsg( 'cite-ve-toolbar-group-label' );
|
||||
// Treat mobile targets differently
|
||||
if ( target === ve.init.mw.MobileArticleTarget ) {
|
||||
group.header = label;
|
||||
|
@ -46,7 +47,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
for ( var n in ve.init.mw.targetFactory.registry ) {
|
||||
for ( const n in ve.init.mw.targetFactory.registry ) {
|
||||
fixTarget( ve.init.mw.targetFactory.lookup( n ) );
|
||||
}
|
||||
|
||||
|
@ -71,7 +72,7 @@
|
|||
*
|
||||
*/
|
||||
( function () {
|
||||
var deprecatedIcons = {
|
||||
const deprecatedIcons = {
|
||||
'ref-cite-book': 'book',
|
||||
'ref-cite-journal': 'journal',
|
||||
'ref-cite-news': 'newspaper',
|
||||
|
@ -90,8 +91,8 @@
|
|||
ve.ui.mwCitationTools = ve.ui.mwCitationTools || [];
|
||||
|
||||
ve.ui.mwCitationTools.forEach( function ( item ) {
|
||||
var hasOwn = Object.prototype.hasOwnProperty,
|
||||
data = { template: item.template, title: item.title };
|
||||
const hasOwn = Object.prototype.hasOwnProperty;
|
||||
const data = { template: item.template, title: item.title };
|
||||
|
||||
if ( !item.icon && hasOwn.call( defaultIcons, item.name ) ) {
|
||||
item.icon = defaultIcons[ item.name ];
|
||||
|
@ -102,9 +103,9 @@
|
|||
}
|
||||
|
||||
// Generate citation tool
|
||||
var name = 'cite-' + item.name;
|
||||
const name = 'cite-' + item.name;
|
||||
if ( !ve.ui.toolFactory.lookup( name ) ) {
|
||||
var tool = function GeneratedMWCitationDialogTool() {
|
||||
const tool = function GeneratedMWCitationDialogTool() {
|
||||
ve.ui.MWCitationDialogTool.apply( this, arguments );
|
||||
};
|
||||
OO.inheritClass( tool, ve.ui.MWCitationDialogTool );
|
||||
|
@ -131,7 +132,7 @@
|
|||
|
||||
// Generate citation context item
|
||||
if ( !ve.ui.contextItemFactory.lookup( name ) ) {
|
||||
var contextItem = function GeneratedMWCitationContextItem() {
|
||||
const contextItem = function GeneratedMWCitationContextItem() {
|
||||
// Parent constructor
|
||||
ve.ui.MWCitationContextItem.apply( this, arguments );
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor MWReferenceContextItem class.
|
||||
*
|
||||
|
@ -49,7 +51,7 @@ ve.ui.MWReferenceContextItem.static.commandName = 'reference';
|
|||
* @return {jQuery} DOM rendering of reference
|
||||
*/
|
||||
ve.ui.MWReferenceContextItem.prototype.getRendering = function () {
|
||||
var refNode = this.getReferenceNode();
|
||||
const refNode = this.getReferenceNode();
|
||||
if ( refNode ) {
|
||||
this.view = new ve.ui.MWPreviewElement( refNode );
|
||||
|
||||
|
@ -72,11 +74,11 @@ ve.ui.MWReferenceContextItem.prototype.getRendering = function () {
|
|||
* @return {jQuery|null}
|
||||
*/
|
||||
ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
|
||||
var refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model ),
|
||||
group = this.getFragment().getDocument().getInternalList()
|
||||
.getNodeGroup( refModel.getListGroup() );
|
||||
var nodes = ve.getProp( group, 'keyedNodes', refModel.getListKey() );
|
||||
var usages = nodes && nodes.filter( function ( node ) {
|
||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
||||
const group = this.getFragment().getDocument().getInternalList()
|
||||
.getNodeGroup( refModel.getListGroup() );
|
||||
const nodes = ve.getProp( group, 'keyedNodes', refModel.getListKey() );
|
||||
const usages = nodes && nodes.filter( function ( node ) {
|
||||
return !node.findParent( ve.dm.MWReferencesListNode );
|
||||
} ).length;
|
||||
if ( usages > 1 ) {
|
||||
|
@ -93,7 +95,7 @@ ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
|
|||
* @return {jQuery|null}
|
||||
*/
|
||||
ve.ui.MWReferenceContextItem.prototype.getExtendsWarning = function () {
|
||||
var refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
||||
|
||||
if ( refModel.extendsRef ) {
|
||||
return $( '<div>' )
|
||||
|
@ -112,7 +114,7 @@ ve.ui.MWReferenceContextItem.prototype.getReferenceNode = function () {
|
|||
return null;
|
||||
}
|
||||
if ( !this.referenceNode ) {
|
||||
var refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
||||
this.referenceNode = this.getFragment().getDocument().getInternalList().getItemNode( refModel.getListIndex() );
|
||||
}
|
||||
return this.referenceNode;
|
||||
|
@ -132,12 +134,12 @@ ve.ui.MWReferenceContextItem.prototype.getDescription = function () {
|
|||
* @return {string|null}
|
||||
*/
|
||||
ve.ui.MWReferenceContextItem.prototype.getParentRef = function () {
|
||||
var refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
||||
if ( !refModel.extendsRef ) {
|
||||
return null;
|
||||
}
|
||||
var list = this.getFragment().getDocument().getInternalList();
|
||||
var index = list.keys.indexOf( 'literal/' + refModel.extendsRef );
|
||||
const list = this.getFragment().getDocument().getInternalList();
|
||||
const index = list.keys.indexOf( 'literal/' + refModel.extendsRef );
|
||||
return list.getItemNode( index ).element.attributes.originalHtml;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor UserInterface MediaWiki MWReferenceDialog class.
|
||||
*
|
||||
|
@ -97,7 +99,7 @@ ve.ui.MWReferenceDialog.static.excludeCommands = [
|
|||
* @return {Object} Import rules
|
||||
*/
|
||||
ve.ui.MWReferenceDialog.static.getImportRules = function () {
|
||||
var rules = ve.copy( ve.init.target.constructor.static.importRules );
|
||||
const rules = ve.copy( ve.init.target.constructor.static.importRules );
|
||||
return ve.extendObject(
|
||||
rules,
|
||||
{
|
||||
|
@ -162,7 +164,7 @@ ve.ui.MWReferenceDialog.prototype.isModified = function () {
|
|||
* Handle reference target widget change events
|
||||
*/
|
||||
ve.ui.MWReferenceDialog.prototype.onTargetChange = function () {
|
||||
var hasContent = this.documentHasContent();
|
||||
const hasContent = this.documentHasContent();
|
||||
|
||||
this.actions.setAbilities( {
|
||||
done: this.isModified(),
|
||||
|
@ -195,7 +197,7 @@ ve.ui.MWReferenceDialog.prototype.onReferenceGroupInputChange = function () {
|
|||
* @param {ve.ui.MWReferenceResultWidget} item Chosen item
|
||||
*/
|
||||
ve.ui.MWReferenceDialog.prototype.onSearchResultsChoose = function ( item ) {
|
||||
var ref = item.getData();
|
||||
const ref = item.getData();
|
||||
|
||||
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
|
||||
this.getFragment().removeContent();
|
||||
|
@ -261,10 +263,10 @@ ve.ui.MWReferenceDialog.prototype.useReference = function ( ref ) {
|
|||
this.referenceGroupInput.setValue( this.originalGroup );
|
||||
this.referenceGroupInput.setDisabled( false );
|
||||
|
||||
var group = this.getFragment().getDocument().getInternalList()
|
||||
const group = this.getFragment().getDocument().getInternalList()
|
||||
.getNodeGroup( this.referenceModel.getListGroup() );
|
||||
var nodes = ve.getProp( group, 'keyedNodes', this.referenceModel.getListKey() );
|
||||
var usages = nodes ? nodes.filter( function ( node ) {
|
||||
const nodes = ve.getProp( group, 'keyedNodes', this.referenceModel.getListKey() );
|
||||
const usages = nodes ? nodes.filter( function ( node ) {
|
||||
return !node.findParent( ve.dm.MWReferencesListNode );
|
||||
} ).length : 0;
|
||||
|
||||
|
@ -294,7 +296,7 @@ ve.ui.MWReferenceDialog.prototype.initialize = function () {
|
|||
classes: [ 've-ui-mwReferenceDialog-reuseWarning' ]
|
||||
} );
|
||||
|
||||
var citeCommands = Object.keys( ve.init.target.getSurface().commandRegistry.registry ).filter( function ( command ) {
|
||||
const citeCommands = Object.keys( ve.init.target.getSurface().commandRegistry.registry ).filter( function ( command ) {
|
||||
return command.indexOf( 'cite-' ) !== -1;
|
||||
} );
|
||||
this.referenceTarget = ve.init.target.createTargetWidget(
|
||||
|
@ -353,7 +355,7 @@ ve.ui.MWReferenceDialog.prototype.useExistingReference = function () {
|
|||
ve.ui.MWReferenceDialog.prototype.getActionProcess = function ( action ) {
|
||||
if ( action === 'insert' || action === 'done' ) {
|
||||
return new OO.ui.Process( function () {
|
||||
var surfaceModel = this.getFragment().getSurface();
|
||||
const surfaceModel = this.getFragment().getSurface();
|
||||
|
||||
this.referenceModel.setGroup( this.referenceGroupInput.getValue() );
|
||||
|
||||
|
@ -397,7 +399,7 @@ ve.ui.MWReferenceDialog.prototype.getSetupProcess = function ( data ) {
|
|||
|
||||
this.search.setInternalList( this.getFragment().getDocument().getInternalList() );
|
||||
|
||||
var isReadOnly = this.isReadOnly();
|
||||
const isReadOnly = this.isReadOnly();
|
||||
this.referenceTarget.setReadOnly( isReadOnly );
|
||||
this.referenceGroupInput.setReadOnly( isReadOnly );
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor MediaWiki Reference dialog tool classes.
|
||||
*
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor UserInterface MWReferenceGroupInput class.
|
||||
*
|
||||
|
@ -38,13 +40,13 @@ OO.inheritClass( ve.ui.MWReferenceGroupInputWidget, OO.ui.ComboBoxInputWidget );
|
|||
* @param {ve.dm.InternalList} internalList Internal list with which to populate the menu
|
||||
*/
|
||||
ve.ui.MWReferenceGroupInputWidget.prototype.populateMenu = function ( internalList ) {
|
||||
var items = [ new OO.ui.MenuOptionWidget( {
|
||||
const items = [ new OO.ui.MenuOptionWidget( {
|
||||
data: '',
|
||||
label: this.emptyGroupName,
|
||||
flags: 'emptyGroupPlaceholder'
|
||||
} ) ];
|
||||
for ( var groupName in internalList.getNodeGroups() ) {
|
||||
var match = groupName.match( /^mwReference\/(.+)/ );
|
||||
for ( const groupName in internalList.getNodeGroups() ) {
|
||||
const match = groupName.match( /^mwReference\/(.+)/ );
|
||||
if ( match ) {
|
||||
items.push( new OO.ui.MenuOptionWidget( { data: match[ 1 ], label: match[ 1 ] } ) );
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor UserInterface MWReferenceResultWidget class.
|
||||
*
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor UserInterface MWReferenceSearchWidget class.
|
||||
*
|
||||
|
@ -66,8 +68,8 @@ ve.ui.MWReferenceSearchWidget.prototype.setInternalList = function ( internalLis
|
|||
this.internalList.connect( this, { update: 'onInternalListUpdate' } );
|
||||
this.internalList.getListNode().connect( this, { update: 'onListNodeUpdate' } );
|
||||
|
||||
var groups = internalList.getNodeGroups();
|
||||
for ( var groupName in groups ) {
|
||||
const groups = internalList.getNodeGroups();
|
||||
for ( const groupName in groups ) {
|
||||
if ( groupName.indexOf( 'mwReference/' ) === 0 && groups[ groupName ].indexOrder.length ) {
|
||||
this.indexEmpty = false;
|
||||
return;
|
||||
|
@ -109,41 +111,41 @@ ve.ui.MWReferenceSearchWidget.prototype.onListNodeUpdate = function () {
|
|||
* @method
|
||||
*/
|
||||
ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
|
||||
var groups = this.internalList.getNodeGroups();
|
||||
const groups = this.internalList.getNodeGroups();
|
||||
|
||||
if ( this.built ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.index = [];
|
||||
var groupNames = Object.keys( groups ).sort();
|
||||
const groupNames = Object.keys( groups ).sort();
|
||||
|
||||
for ( var i = 0, iLen = groupNames.length; i < iLen; i++ ) {
|
||||
var groupName = groupNames[ i ];
|
||||
for ( let i = 0; i < groupNames.length; i++ ) {
|
||||
const groupName = groupNames[ i ];
|
||||
if ( groupName.indexOf( 'mwReference/' ) !== 0 ) {
|
||||
continue;
|
||||
}
|
||||
var group = groups[ groupName ];
|
||||
var firstNodes = group.firstNodes;
|
||||
var indexOrder = group.indexOrder;
|
||||
const group = groups[ groupName ];
|
||||
const firstNodes = group.firstNodes;
|
||||
const indexOrder = group.indexOrder;
|
||||
|
||||
var n = 0;
|
||||
for ( var j = 0, jLen = indexOrder.length; j < jLen; j++ ) {
|
||||
var refNode = firstNodes[ indexOrder[ j ] ];
|
||||
let n = 0;
|
||||
for ( let j = 0; j < indexOrder.length; j++ ) {
|
||||
const refNode = firstNodes[ indexOrder[ j ] ];
|
||||
// Exclude placeholder references
|
||||
if ( refNode.getAttribute( 'placeholder' ) ) {
|
||||
continue;
|
||||
}
|
||||
// Only increment counter for real references
|
||||
n++;
|
||||
var refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( refNode );
|
||||
var itemNode = this.internalList.getItemNode( refModel.getListIndex() );
|
||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( refNode );
|
||||
const itemNode = this.internalList.getItemNode( refModel.getListIndex() );
|
||||
|
||||
var refGroup = refModel.getGroup();
|
||||
var citation = ( refGroup && refGroup.length ? refGroup + ' ' : '' ) + n;
|
||||
const refGroup = refModel.getGroup();
|
||||
const citation = ( refGroup && refGroup.length ? refGroup + ' ' : '' ) + n;
|
||||
// Use [\s\S]* instead of .* to catch esoteric whitespace (T263698)
|
||||
var matches = refModel.getListKey().match( /^literal\/([\s\S]*)$/ );
|
||||
var name = matches && matches[ 1 ] || '';
|
||||
const matches = refModel.getListKey().match( /^literal\/([\s\S]*)$/ );
|
||||
const name = matches && matches[ 1 ] || '';
|
||||
|
||||
// TODO: At some point we need to make sure this text is updated in
|
||||
// case the view node is still rendering. This shouldn't happen because
|
||||
|
@ -151,14 +153,13 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
|
|||
// immediately rendered, but we shouldn't trust that on principle to
|
||||
// account for edge cases.
|
||||
|
||||
var $element;
|
||||
let $element;
|
||||
// Make visible text, citation and reference name searchable
|
||||
var text = citation + ' ' + name;
|
||||
let text = citation + ' ' + name;
|
||||
if ( itemNode.length ) {
|
||||
$element = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element;
|
||||
text = $element.text().toLowerCase() + ' ' + text;
|
||||
// Make URLs searchable
|
||||
// eslint-disable-next-line no-loop-func
|
||||
$element.find( 'a[href]' ).each( function () {
|
||||
text += ' ' + this.getAttribute( 'href' );
|
||||
} );
|
||||
|
@ -199,16 +200,16 @@ ve.ui.MWReferenceSearchWidget.prototype.isIndexEmpty = function () {
|
|||
* @method
|
||||
*/
|
||||
ve.ui.MWReferenceSearchWidget.prototype.addResults = function () {
|
||||
var query = this.query.getValue().trim().toLowerCase(),
|
||||
items = [];
|
||||
const query = this.query.getValue().trim().toLowerCase();
|
||||
const items = [];
|
||||
|
||||
for ( var i = 0, len = this.index.length; i < len; i++ ) {
|
||||
var item = this.index[ i ];
|
||||
for ( let i = 0; i < this.index.length; i++ ) {
|
||||
const item = this.index[ i ];
|
||||
if ( item.text.indexOf( query ) >= 0 ) {
|
||||
var $citation = $( '<div>' )
|
||||
const $citation = $( '<div>' )
|
||||
.addClass( 've-ui-mwReferenceSearchWidget-citation' )
|
||||
.text( '[' + item.citation + ']' );
|
||||
var $name = $( '<div>' )
|
||||
const $name = $( '<div>' )
|
||||
.addClass( 've-ui-mwReferenceSearchWidget-name' )
|
||||
.toggleClass( 've-ui-mwReferenceSearchWidget-name-autogenerated', /^:\d+$/.test( item.name ) )
|
||||
.text( item.name );
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor UserInterface MediaWiki ReferencesListCommand class.
|
||||
*
|
||||
|
@ -34,9 +36,9 @@ OO.inheritClass( ve.ui.MWReferencesListCommand, ve.ui.Command );
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWReferencesListCommand.prototype.execute = function ( surface ) {
|
||||
var fragment = surface.getModel().getFragment(),
|
||||
selectedNode = fragment.getSelectedNode(),
|
||||
isReflistNodeSelected = selectedNode && selectedNode instanceof ve.dm.MWReferencesListNode;
|
||||
const fragment = surface.getModel().getFragment();
|
||||
const selectedNode = fragment.getSelectedNode();
|
||||
const isReflistNodeSelected = selectedNode && selectedNode instanceof ve.dm.MWReferencesListNode;
|
||||
|
||||
if ( isReflistNodeSelected ) {
|
||||
return surface.execute( 'window', 'open', 'referencesList' );
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor MWReferencesListContextItem class.
|
||||
*
|
||||
|
@ -65,7 +67,7 @@ ve.ui.MWReferencesListContextItem.prototype.renderBody = function () {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWReferencesListContextItem.prototype.getDescription = function () {
|
||||
var group = this.model.getAttribute( 'refGroup' );
|
||||
const group = this.model.getAttribute( 'refGroup' );
|
||||
|
||||
return group ?
|
||||
ve.msg( 'cite-ve-dialog-referenceslist-contextitem-description-named', group ) :
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor user interface MWReferencesListDialog class.
|
||||
*
|
||||
|
@ -61,13 +63,13 @@ ve.ui.MWReferencesListDialog.prototype.initialize = function () {
|
|||
$overlay: this.$overlay,
|
||||
emptyGroupName: ve.msg( 'cite-ve-dialog-reference-options-group-placeholder' )
|
||||
} );
|
||||
var groupField = new OO.ui.FieldLayout( this.groupInput, {
|
||||
const groupField = new OO.ui.FieldLayout( this.groupInput, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'cite-ve-dialog-reference-options-group-label' )
|
||||
} );
|
||||
|
||||
this.responsiveCheckbox = new OO.ui.CheckboxInputWidget();
|
||||
var responsiveField = new OO.ui.FieldLayout( this.responsiveCheckbox, {
|
||||
const responsiveField = new OO.ui.FieldLayout( this.responsiveCheckbox, {
|
||||
align: 'inline',
|
||||
label: ve.msg( 'cite-ve-dialog-reference-options-responsive-label' )
|
||||
} );
|
||||
|
@ -101,12 +103,12 @@ ve.ui.MWReferencesListDialog.prototype.isModified = function () {
|
|||
return true;
|
||||
}
|
||||
|
||||
var refGroup = this.groupInput.getValue();
|
||||
var listGroup = 'mwReference/' + refGroup;
|
||||
var isResponsive = this.responsiveCheckbox.isSelected();
|
||||
const refGroup = this.groupInput.getValue();
|
||||
const listGroup = 'mwReference/' + refGroup;
|
||||
const isResponsive = this.responsiveCheckbox.isSelected();
|
||||
|
||||
var oldListGroup = this.selectedNode.getAttribute( 'listGroup' );
|
||||
var oldResponsive = this.selectedNode.getAttribute( 'isResponsive' );
|
||||
const oldListGroup = this.selectedNode.getAttribute( 'listGroup' );
|
||||
const oldResponsive = this.selectedNode.getAttribute( 'isResponsive' );
|
||||
|
||||
return listGroup !== oldListGroup || isResponsive !== oldResponsive;
|
||||
};
|
||||
|
@ -119,24 +121,24 @@ ve.ui.MWReferencesListDialog.prototype.getActionProcess = function ( action ) {
|
|||
return new OO.ui.Process( function () {
|
||||
|
||||
// Save changes
|
||||
var refGroup = this.groupInput.getValue();
|
||||
var listGroup = 'mwReference/' + refGroup;
|
||||
var isResponsive = this.responsiveCheckbox.isSelected();
|
||||
const refGroup = this.groupInput.getValue();
|
||||
const listGroup = 'mwReference/' + refGroup;
|
||||
const isResponsive = this.responsiveCheckbox.isSelected();
|
||||
|
||||
if ( this.selectedNode ) {
|
||||
// Edit existing model
|
||||
var surfaceModel = this.getFragment().getSurface();
|
||||
var doc = surfaceModel.getDocument();
|
||||
const surfaceModel = this.getFragment().getSurface();
|
||||
const doc = surfaceModel.getDocument();
|
||||
|
||||
if ( this.isModified() ) {
|
||||
// newFromAttributeChanges doesn't do the smart-replacing
|
||||
// for nested attributes, so make a copy of the mw
|
||||
// attribute so we can disable autoGenerated now we've
|
||||
// changed it.
|
||||
var mwData = ve.copy( this.selectedNode.getAttribute( 'mw' ) ) || {};
|
||||
const mwData = ve.copy( this.selectedNode.getAttribute( 'mw' ) ) || {};
|
||||
delete mwData.autoGenerated;
|
||||
|
||||
var attrChanges = {
|
||||
const attrChanges = {
|
||||
listGroup: listGroup,
|
||||
refGroup: refGroup,
|
||||
isResponsive: isResponsive,
|
||||
|
@ -172,7 +174,7 @@ ve.ui.MWReferencesListDialog.prototype.getSetupProcess = function ( data ) {
|
|||
|
||||
this.responsiveCheckbox.setSelected( this.selectedNode.getAttribute( 'isResponsive' ) );
|
||||
|
||||
var isReadOnly = this.isReadOnly();
|
||||
const isReadOnly = this.isReadOnly();
|
||||
this.groupInput.setReadOnly( isReadOnly );
|
||||
this.responsiveCheckbox.setDisabled( isReadOnly );
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* VisualEditor UserInterface MediaWiki UseExistingReferenceCommand class.
|
||||
*
|
||||
|
@ -36,8 +38,8 @@ ve.ui.MWUseExistingReferenceCommand.prototype.isExecutable = function ( fragment
|
|||
return false;
|
||||
}
|
||||
|
||||
var groups = fragment.getDocument().getInternalList().getNodeGroups();
|
||||
for ( var groupName in groups ) {
|
||||
const groups = fragment.getDocument().getInternalList().getNodeGroups();
|
||||
for ( const groupName in groups ) {
|
||||
if ( groupName.indexOf( 'mwReference/' ) === 0 && groups[ groupName ].indexOrder.length ) {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue