mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-30 17:14:42 +00:00
Fixed onAfterSplice in es.DocumentViewBranchNode to update the DOM correctly
Fixed issue where events were being listened to from this instead of this.model Added rendering calls after structural changes
This commit is contained in:
parent
521a0644ff
commit
872d2bdb9d
|
@ -25,7 +25,7 @@ es.DocumentViewBranchNode = function( model, $element, horizontal ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Observe and mimic changes on model
|
// Observe and mimic changes on model
|
||||||
this.addListenerMethods( this, {
|
this.model.addListenerMethods( this, {
|
||||||
'afterPush': 'onAfterPush',
|
'afterPush': 'onAfterPush',
|
||||||
'afterUnshift': 'onAfterUnshift',
|
'afterUnshift': 'onAfterUnshift',
|
||||||
'afterPop': 'onAfterPop',
|
'afterPop': 'onAfterPop',
|
||||||
|
@ -55,6 +55,7 @@ es.DocumentViewBranchNode.prototype.onAfterPush = function( childModel ) {
|
||||||
}
|
}
|
||||||
this.emit( 'afterPush', childView );
|
this.emit( 'afterPush', childView );
|
||||||
this.emit( 'update' );
|
this.emit( 'update' );
|
||||||
|
this.renderContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
es.DocumentViewBranchNode.prototype.onAfterUnshift = function( childModel ) {
|
es.DocumentViewBranchNode.prototype.onAfterUnshift = function( childModel ) {
|
||||||
|
@ -68,6 +69,7 @@ es.DocumentViewBranchNode.prototype.onAfterUnshift = function( childModel ) {
|
||||||
this.$.prepend( childView.$ );
|
this.$.prepend( childView.$ );
|
||||||
this.emit( 'afterUnshift', childView );
|
this.emit( 'afterUnshift', childView );
|
||||||
this.emit( 'update' );
|
this.emit( 'update' );
|
||||||
|
this.renderContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
es.DocumentViewBranchNode.prototype.onAfterPop = function() {
|
es.DocumentViewBranchNode.prototype.onAfterPop = function() {
|
||||||
|
@ -80,6 +82,7 @@ es.DocumentViewBranchNode.prototype.onAfterPop = function() {
|
||||||
childView.$.detach();
|
childView.$.detach();
|
||||||
this.emit( 'afterPop' );
|
this.emit( 'afterPop' );
|
||||||
this.emit( 'update' );
|
this.emit( 'update' );
|
||||||
|
this.renderContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
es.DocumentViewBranchNode.prototype.onAfterShift = function() {
|
es.DocumentViewBranchNode.prototype.onAfterShift = function() {
|
||||||
|
@ -92,26 +95,44 @@ es.DocumentViewBranchNode.prototype.onAfterShift = function() {
|
||||||
childView.$.detach();
|
childView.$.detach();
|
||||||
this.emit( 'afterShift' );
|
this.emit( 'afterShift' );
|
||||||
this.emit( 'update' );
|
this.emit( 'update' );
|
||||||
|
this.renderContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
es.DocumentViewBranchNode.prototype.onAfterSplice = function( index, howmany ) {
|
es.DocumentViewBranchNode.prototype.onAfterSplice = function( index, howmany ) {
|
||||||
var args = Array.prototype.slice( arguments, 0 );
|
var i,
|
||||||
this.emit.apply( ['beforeSplice'].concat( args ) );
|
length,
|
||||||
// Update children
|
args = Array.prototype.slice.call( arguments, 0 );
|
||||||
this.splice.apply( this, args );
|
// Convert models to views and attach them to this node
|
||||||
// Update DOM
|
if ( args.length >= 3 ) {
|
||||||
this.$.children()
|
for ( i = 2, length = args.length; i < length; i++ ) {
|
||||||
// Removals
|
args[i] = args[i].createView();
|
||||||
.slice( index, index + howmany )
|
}
|
||||||
.detach()
|
}
|
||||||
.end()
|
this.emit.apply( this, ['beforeSplice'].concat( args ) );
|
||||||
// Insertions
|
var removals = this.children.splice.apply( this.children, args );
|
||||||
.get( index )
|
for ( i = 0, length = removals.length; i < length; i++ ) {
|
||||||
.after( $.map( args.slice( 2 ), function( childView ) {
|
removals[i].detach();
|
||||||
return childView.$;
|
removals[i].removeListener( 'update', this.emitUpdate );
|
||||||
} ) );
|
// Update DOM
|
||||||
this.emit.apply( ['afterSplice'].concat( args ) );
|
removals[i].$.detach();
|
||||||
this.emit( 'update' );
|
}
|
||||||
|
if ( args.length >= 3 ) {
|
||||||
|
var $target;
|
||||||
|
if ( index ) {
|
||||||
|
$target = this.$.children().eq( index );
|
||||||
|
}
|
||||||
|
for ( i = args.length - 1; i >= 2; i-- ) {
|
||||||
|
args[i].attach( this );
|
||||||
|
args[i].on( 'update', this.emitUpdate );
|
||||||
|
if ( index ) {
|
||||||
|
$target.after( args[i].$ );
|
||||||
|
} else {
|
||||||
|
this.$.prepend( args[i].$ );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.emit.apply( this, ['afterSplice'].concat( args ) );
|
||||||
|
this.renderContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
es.DocumentViewBranchNode.prototype.onAfterSort = function() {
|
es.DocumentViewBranchNode.prototype.onAfterSort = function() {
|
||||||
|
@ -131,6 +152,7 @@ es.DocumentViewBranchNode.prototype.onAfterSort = function() {
|
||||||
}
|
}
|
||||||
this.emit( 'afterSort' );
|
this.emit( 'afterSort' );
|
||||||
this.emit( 'update' );
|
this.emit( 'update' );
|
||||||
|
this.renderContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
es.DocumentViewBranchNode.prototype.onAfterReverse = function() {
|
es.DocumentViewBranchNode.prototype.onAfterReverse = function() {
|
||||||
|
@ -143,6 +165,7 @@ es.DocumentViewBranchNode.prototype.onAfterReverse = function() {
|
||||||
} );
|
} );
|
||||||
this.emit( 'afterReverse' );
|
this.emit( 'afterReverse' );
|
||||||
this.emit( 'update' );
|
this.emit( 'update' );
|
||||||
|
this.renderContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue