From 8ce71820455a327c2bad8cd2f56588ce43261323 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 13 Dec 2013 16:51:07 +0000 Subject: [PATCH] Move index label generation to the model Also make available as a static method so it can be used by the converter. We will need this for generated HTML for the external clipboard. Change-Id: Ief843ac10cd6c6e4b25e09a007625d363792adff --- .../ve-mw/ce/nodes/ve.ce.MWReferenceNode.js | 7 +----- .../ve-mw/dm/nodes/ve.dm.MWReferenceNode.js | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWReferenceNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWReferenceNode.js index c038d2a2b1..08ac3fc660 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWReferenceNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWReferenceNode.js @@ -92,12 +92,7 @@ ve.ce.MWReferenceNode.prototype.onInternalListUpdate = function ( groupsChanged * @method */ ve.ce.MWReferenceNode.prototype.update = function () { - var listIndex = this.model.getAttribute( 'listIndex' ), - listGroup = this.model.getAttribute( 'listGroup' ), - refGroup = this.model.getAttribute( 'refGroup' ), - position = this.internalList.getIndexPosition( listGroup, listIndex ); - - this.$link.text( '[' + ( refGroup ? refGroup + ' ' : '' ) + ( position + 1 ) + ']' ); + this.$link.text( this.model.getIndexLabel() ); }; /** */ diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWReferenceNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWReferenceNode.js index 6ce194e6b1..da0b7bb0bb 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWReferenceNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWReferenceNode.js @@ -215,6 +215,22 @@ ve.dm.MWReferenceNode.static.remapInternalListKeys = function ( dataElement, int } }; +/** + * Gets the index label for the reference + * @static + * @param {Object} dataElement Element data + * @param {ve.dm.InternalList} internalList Internal list + * @returns {string} Reference label + */ +ve.dm.MWReferenceNode.static.getIndexLabel = function ( dataElement, internalList ) { + var listIndex = dataElement.attributes.listIndex, + listGroup = dataElement.attributes.listGroup, + refGroup = dataElement.attributes.refGroup, + position = internalList.getIndexPosition( listGroup, listIndex ); + + return '[' + ( refGroup ? refGroup + ' ' : '' ) + ( position + 1 ) + ']'; +}; + /* Methods */ /** @@ -236,6 +252,15 @@ ve.dm.MWReferenceNode.prototype.getInternalItem = function () { return this.getDocument().getInternalList().getItemNode( this.getAttribute( 'listIndex' ) ); }; +/** + * Gets the index label for the reference + * @method + * @returns {string} Reference label + */ +ve.dm.MWReferenceNode.prototype.getIndexLabel = function () { + return this.constructor.static.getIndexLabel( this.element, this.getDocument().getInternalList() ); +}; + /** * Handle the node being attached to the root * @method