diff --git a/modules/ve-mw/ui/contextitems/ve.ui.MWReferenceContextItem.js b/modules/ve-mw/ui/contextitems/ve.ui.MWReferenceContextItem.js index 2295a1ae8d..635b41177f 100644 --- a/modules/ve-mw/ui/contextitems/ve.ui.MWReferenceContextItem.js +++ b/modules/ve-mw/ui/contextitems/ve.ui.MWReferenceContextItem.js @@ -48,12 +48,9 @@ ve.ui.MWReferenceContextItem.static.commandName = 'reference'; * @return {jQuery} DOM rendering of reference */ ve.ui.MWReferenceContextItem.prototype.getRendering = function () { - var refModel; - if ( this.model.isEditable() ) { - refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model ); - this.view = new ve.ui.PreviewElement( - refModel.getDocument().getInternalList().getItemNode( refModel.getListIndex() ) - ); + var refNode = this.getReferenceNode(); + if ( refNode ) { + this.view = new ve.ui.PreviewElement( refNode ); // The $element property may be rendered into asynchronously, update the context's size when the // rendering is complete if that's the case @@ -67,6 +64,23 @@ ve.ui.MWReferenceContextItem.prototype.getRendering = function () { } }; +/** + * Get the reference node in the containing document (not the internal list document) + * + * @return {ve.dm.Node} Reference node + */ +ve.ui.MWReferenceContextItem.prototype.getReferenceNode = function () { + var refModel; + if ( !this.model.isEditable() ) { + return null; + } + if ( !this.referenceNode ) { + refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model ); + this.referenceNode = this.getFragment().getDocument().getInternalList().getItemNode( refModel.getListIndex() ); + } + return this.referenceNode; +}; + /** * @inheritdoc */