mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-01 01:56:20 +00:00
MWReferencesListNode: Guard against run-after-teardown
Change-Id: Icea7580d04d7093ab2b27b2d757e625d7559b94c
This commit is contained in:
parent
b929001479
commit
e8dd5fed93
|
@ -36,7 +36,7 @@ ve.ce.MWReferencesListNode = function VeCeMWReferencesListNode() {
|
||||||
.addClass( 've-ce-mwReferencesListNode-muted' );
|
.addClass( 've-ce-mwReferencesListNode-muted' );
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
this.model.connect( this, { attributeChange: 'onAttributeChange' } );
|
this.getModel().connect( this, { attributeChange: 'onAttributeChange' } );
|
||||||
|
|
||||||
this.updateDebounced = ve.debounce( this.update.bind( this ) );
|
this.updateDebounced = ve.debounce( this.update.bind( this ) );
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ ve.ce.MWReferencesListNode.static.getDescription = function ( model ) {
|
||||||
* @method
|
* @method
|
||||||
*/
|
*/
|
||||||
ve.ce.MWReferencesListNode.prototype.onSetup = function () {
|
ve.ce.MWReferencesListNode.prototype.onSetup = function () {
|
||||||
this.internalList = this.model.getDocument().getInternalList();
|
this.internalList = this.getModel().getDocument().getInternalList();
|
||||||
this.listNode = this.internalList.getListNode();
|
this.listNode = this.internalList.getListNode();
|
||||||
|
|
||||||
this.internalList.connect( this, { update: 'onInternalListUpdate' } );
|
this.internalList.connect( this, { update: 'onInternalListUpdate' } );
|
||||||
|
@ -111,7 +111,7 @@ ve.ce.MWReferencesListNode.prototype.onTeardown = function () {
|
||||||
*/
|
*/
|
||||||
ve.ce.MWReferencesListNode.prototype.onInternalListUpdate = function ( groupsChanged ) {
|
ve.ce.MWReferencesListNode.prototype.onInternalListUpdate = function ( groupsChanged ) {
|
||||||
// Only update if this group has been changed
|
// Only update if this group has been changed
|
||||||
if ( groupsChanged.indexOf( this.model.getAttribute( 'listGroup' ) ) !== -1 ) {
|
if ( groupsChanged.indexOf( this.getModel().getAttribute( 'listGroup' ) ) !== -1 ) {
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
this.updateDebounced();
|
this.updateDebounced();
|
||||||
}
|
}
|
||||||
|
@ -155,18 +155,25 @@ ve.ce.MWReferencesListNode.prototype.onListNodeUpdate = function () {
|
||||||
*/
|
*/
|
||||||
ve.ce.MWReferencesListNode.prototype.update = function () {
|
ve.ce.MWReferencesListNode.prototype.update = function () {
|
||||||
var i, j, iLen, jLen, index, firstNode, key, keyedNodes, modelNode, viewNode,
|
var i, j, iLen, jLen, index, firstNode, key, keyedNodes, modelNode, viewNode,
|
||||||
$li, $refSpan, $link,
|
$li, $refSpan, $link, internalList, refGroup, listGroup, nodes,
|
||||||
internalList = this.model.getDocument().internalList,
|
model = this.getModel();
|
||||||
refGroup = this.model.getAttribute( 'refGroup' ),
|
|
||||||
listGroup = this.model.getAttribute( 'listGroup' ),
|
// Check the node hasn't been destroyed, as this method is debounced.
|
||||||
|
if ( !model ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
internalList = model.getDocument().internalList;
|
||||||
|
refGroup = model.getAttribute( 'refGroup' );
|
||||||
|
listGroup = model.getAttribute( 'listGroup' );
|
||||||
nodes = internalList.getNodeGroup( listGroup );
|
nodes = internalList.getNodeGroup( listGroup );
|
||||||
|
|
||||||
// Just use Parsoid-provided DOM for first rendering
|
// Just use Parsoid-provided DOM for first rendering
|
||||||
// NB: Technically this.modified could be reset to false if this
|
// NB: Technically this.modified could be reset to false if this
|
||||||
// node is re-attached, but that is an unlikely edge case.
|
// node is re-attached, but that is an unlikely edge case.
|
||||||
if ( !this.modified && this.model.getElement().originalDomElementsIndex ) {
|
if ( !this.modified && model.getElement().originalDomElementsIndex ) {
|
||||||
this.$originalRefList = $( this.model.getStore().value(
|
this.$originalRefList = $( model.getStore().value(
|
||||||
this.model.getElement().originalDomElementsIndex
|
model.getElement().originalDomElementsIndex
|
||||||
) );
|
) );
|
||||||
this.$element.append( this.$originalRefList );
|
this.$element.append( this.$originalRefList );
|
||||||
return;
|
return;
|
||||||
|
@ -302,7 +309,7 @@ ve.ce.MWReferencesListNode.prototype.update = function () {
|
||||||
* Currently used to set responsive layout
|
* Currently used to set responsive layout
|
||||||
*/
|
*/
|
||||||
ve.ce.MWReferencesListNode.prototype.updateClasses = function () {
|
ve.ce.MWReferencesListNode.prototype.updateClasses = function () {
|
||||||
var isResponsive = this.model.getAttribute( 'isResponsive' );
|
var isResponsive = this.getModel().getAttribute( 'isResponsive' );
|
||||||
|
|
||||||
this.$element
|
this.$element
|
||||||
.toggleClass( 'mw-references-wrap', isResponsive )
|
.toggleClass( 'mw-references-wrap', isResponsive )
|
||||||
|
|
Loading…
Reference in a new issue