diff --git a/modules/ve/ce/nodes/ve.ce.MWReferenceListNode.js b/modules/ve/ce/nodes/ve.ce.MWReferenceListNode.js index 8166d37284..5e5e0bedd2 100644 --- a/modules/ve/ce/nodes/ve.ce.MWReferenceListNode.js +++ b/modules/ve/ce/nodes/ve.ce.MWReferenceListNode.js @@ -89,6 +89,14 @@ ve.ce.MWReferenceListNode.prototype.update = function () { listGroup = this.model.getAttribute( 'listGroup' ), nodes = internalList.getNodeGroup( listGroup ); + // HACK: detach the children attached in the previous run + while ( this.attachedItems && this.attachedItems.length > 0 ) { + itemNode = this.attachedItems.pop(); + itemNode.setLive( false ); + itemNode.detach( this ); + } + this.attachedItems = this.attachedItems || []; + this.$reflist.empty(); if ( nodes && nodes.keyOrder.length ) { for ( i = 0, iLen = nodes.keyOrder.length; i < iLen; i++ ) { @@ -111,6 +119,9 @@ ve.ce.MWReferenceListNode.prototype.update = function () { itemNode = new ve.ce.InternalItemNode( internalList.getItemNode( keyNodes[0].getAttribute( 'listIndex' ) ) ); + // HACK: ProtectedNode crashes when dealing with an unattached node + this.attachedItems.push( itemNode ); + itemNode.attach( this ); $li.append( $( '' ).html( itemNode.$.show() ) ); this.$reflist.append( $li ); } diff --git a/modules/ve/ce/ve.ce.ProtectedNode.js b/modules/ve/ce/ve.ce.ProtectedNode.js index 081f22e6f8..4f7f9235e7 100644 --- a/modules/ve/ce/ve.ce.ProtectedNode.js +++ b/modules/ve/ce/ve.ce.ProtectedNode.js @@ -17,6 +17,7 @@ ve.ce.ProtectedNode = function VeCeProtectedNode() { // Properties this.$phantoms = $( [] ); this.$shields = $( [] ); + this.isSetup = false; // Events this.connect( this, { @@ -64,10 +65,16 @@ ve.ce.ProtectedNode.static.$phantomTemplate = $( '
' ) * @method */ ve.ce.ProtectedNode.prototype.onProtectedSetup = function () { - var $shield, + var $shield, surfaceModel, node = this, - $shieldTemplate = this.constructor.static.$shieldTemplate, - surfaceModel = this.getRoot().getSurface().getModel(); + $shieldTemplate = this.constructor.static.$shieldTemplate; + + if ( this.isSetup ) { + return; + } + this.isSetup = true; + + surfaceModel = this.getRoot().getSurface().getModel(); // Events this.$.on( 'mouseenter.ve-ce-protectedNode', ve.bind( this.onProtectedMouseEnter, this ) ); @@ -96,7 +103,14 @@ ve.ce.ProtectedNode.prototype.onProtectedSetup = function () { * @method */ ve.ce.ProtectedNode.prototype.onProtectedTeardown = function () { - var surfaceModel = this.getRoot().getSurface().getModel(); + var surfaceModel; + + if ( !this.isSetup ) { + return; + } + this.isSetup = false; + + surfaceModel = this.getRoot().getSurface().getModel(); // Events this.$.off( '.ve-ce-protectedNode' );