Merge "Don't show placeholder references in lists"

This commit is contained in:
jenkins-bot 2015-05-06 23:17:28 +00:00 committed by Gerrit Code Review
commit f1a6e87bc5
3 changed files with 31 additions and 12 deletions

View file

@ -143,7 +143,7 @@ ve.ce.MWReferencesListNode.prototype.onListNodeUpdate = function () {
* Update the references list.
*/
ve.ce.MWReferencesListNode.prototype.update = function () {
var i, j, iLen, jLen, index, firstNode, key, keyedNodes, $li, modelNode, viewNode,
var i, j, n, iLen, jLen, index, firstNode, key, keyedNodes, $li, modelNode, viewNode,
internalList = this.model.getDocument().internalList,
refGroup = this.model.getAttribute( 'refGroup' ),
listGroup = this.model.getAttribute( 'listGroup' ),
@ -160,15 +160,20 @@ ve.ce.MWReferencesListNode.prototype.update = function () {
}
this.$element.append( this.$refmsg );
} else {
n = 0;
for ( i = 0, iLen = nodes.indexOrder.length; i < iLen; i++ ) {
index = nodes.indexOrder[i];
firstNode = nodes.firstNodes[index];
key = internalList.keys[index];
keyedNodes = nodes.keyedNodes[key];
// Exclude references defined inside the references list node
/*jshint loopfunc:true */
keyedNodes = keyedNodes.filter( function ( node ) {
// Exclude placeholder references
if ( node.getAttribute( 'placeholder' ) ) {
return false;
}
// Exclude references defined inside the references list node
while ( ( node = node.parent ) && node !== null ) {
if ( node instanceof ve.dm.MWReferencesListNode ) {
return false;
@ -180,6 +185,8 @@ ve.ce.MWReferencesListNode.prototype.update = function () {
if ( !keyedNodes.length ) {
continue;
}
// Only increment counter for non-empty groups
n++;
$li = $( '<li>' );
@ -187,7 +194,7 @@ ve.ce.MWReferencesListNode.prototype.update = function () {
for ( j = 0, jLen = keyedNodes.length; j < jLen; j++ ) {
$li.append(
$( '<sup>' ).append(
$( '<a>' ).text( ( i + 1 ) + '.' + j )
$( '<a>' ).text( n + '.' + j )
)
).append( ' ' );
}

View file

@ -158,18 +158,23 @@ ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel )
* Insert reference at the end of a surface fragment.
*
* @param {ve.dm.SurfaceFragment} surfaceModel Surface fragment to insert at
* @param {boolean} [placeholder] Reference is a placeholder for staging purposes
*/
ve.dm.MWReferenceModel.prototype.insertReferenceNode = function ( surfaceFragment ) {
ve.dm.MWReferenceModel.prototype.insertReferenceNode = function ( surfaceFragment, placeholder ) {
var attributes = {
listKey: this.listKey,
listGroup: this.listGroup,
listIndex: this.listIndex,
refGroup: this.group
};
if ( placeholder ) {
attributes.placeholder = true;
}
surfaceFragment
.insertContent( [
{
type: 'mwReference',
attributes: {
listKey: this.listKey,
listGroup: this.listGroup,
listIndex: this.listIndex,
refGroup: this.group
}
attributes: attributes
},
{ type: '/mwReference' }
] );

View file

@ -150,7 +150,7 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
return;
}
var i, iLen, j, jLen, refModel, group, groupName, groupNames, view, text, firstNodes, indexOrder,
var n, i, iLen, j, jLen, refModel, group, groupName, groupNames, view, text, firstNodes, indexOrder,
refGroup, refNode, matches, name, citation,
groups = this.internalList.getNodeGroups();
@ -170,15 +170,22 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
firstNodes = group.firstNodes;
indexOrder = group.indexOrder;
n = 0;
for ( j = 0, jLen = indexOrder.length; j < jLen; j++ ) {
refNode = firstNodes[indexOrder[j]];
// Exclude placeholder references
if ( refNode.getAttribute( 'placeholder' ) ) {
continue;
}
// Only increment counter for real references
n++;
refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( refNode );
view = new ve.ui.PreviewWidget(
refModel.getDocument().getInternalList().getItemNode( refModel.getListIndex() )
);
refGroup = refModel.getGroup();
citation = ( refGroup && refGroup.length ? refGroup + ' ' : '' ) + ( j + 1 );
citation = ( refGroup && refGroup.length ? refGroup + ' ' : '' ) + n;
matches = refModel.getListKey().match( /^literal\/(.*)$/ );
name = matches && matches[1] || '';
// Hide previously auto-generated reference names