diff --git a/lib/ext.Cite.js b/lib/ext.Cite.js index d24d20f19..939a005b4 100644 --- a/lib/ext.Cite.js +++ b/lib/ext.Cite.js @@ -134,30 +134,32 @@ function RefGroup(group) { this.indexByName = new Map(); } -RefGroup.prototype.add = function(refName, about, skipLinkback) { +RefGroup.prototype.add = function( references, refName, about, skipLinkback ) { var ref; if ( refName && this.indexByName.has( refName ) ) { ref = this.indexByName.get( refName ); } else { - var n = this.refs.length, + var n = references.index, refKey = (1+n) + ''; + // bump index + references.index += 1; + if (refName) { refKey = refName + '-' + refKey; } - ref = { about: about, content: null, group: this.name, - groupIndex: (1+n), // FIXME -- this seems to be wiki-specific + groupIndex: this.refs.length + 1, index: n, key: refKey, linkbacks: [], name: refName, target: 'cite_note-' + refKey }; - this.refs[n] = ref; + this.refs.push( ref ); if (refName) { this.indexByName.set( refName, ref ); } @@ -230,10 +232,10 @@ function getRefGroup(refGroups, groupName, allocIfMissing) { function References(cite) { this.cite = cite; - this.reset(); + this.reset( null, true ); } -References.prototype.reset = function(group) { +References.prototype.reset = function( group, resetIndex ) { if (group) { this.refGroups.set( group, undefined ); } else { @@ -254,6 +256,11 @@ References.prototype.reset = function(group) { * ----------------------------------------------------------------- */ this.nestedRefsHTMLMap = new Map(); } + + // restart reference counter + if ( resetIndex ) { + this.index = 0; + } }; /** @@ -355,7 +362,7 @@ References.prototype.extractRefFromNode = function(node) { about = node.getAttribute("about"), skipLinkback = dp.tmp.skiplinkback, refGroup = getRefGroup(this.refGroups, group, true), - ref = refGroup.add(refName, about, skipLinkback), + ref = refGroup.add(this, refName, about, skipLinkback), nodeType = (node.getAttribute("typeof") || '').replace(/mw:Extension\/ref\/Marker/, ''); // Add ref-index linkback @@ -484,7 +491,7 @@ var Cite = function() { Cite.prototype.resetState = function() { this.ref.reset(); - this.references.reset(); + this.references.reset( null, true ); }; if (typeof module === "object") {