Unbind confirm dialog handlers after either of the events fires once

We weren't unbinding these handlers at all, and so the 'ok' or 'cancel'
handlers could run multiple times for one button click, and even worse,
you could get in a situation where clicking 'ok' in one confirm dialog
would also run the 'ok' handler for the other one. This happens because
the ConfirmDialog instance is recycled by the WindowSet.

The way the unbinding is done is ugly; we should either consolidate the
'ok' and 'cancel' events so we can use .once(), or come up with some other
way to automatically unbind the handlers.

Bug: 65557
Change-Id: Iabf0c0d0229add09cc775358fc5a4e5ae783db04
This commit is contained in:
Roan Kattouw 2014-05-20 19:11:45 -07:00
parent 3871ba5a06
commit 293609e5d8

View file

@ -292,7 +292,17 @@ ve.init.mw.ViewPageTarget.prototype.deactivate = function ( override ) {
'cancelLabel': ve.msg( 'visualeditor-viewpage-savewarning-keep' ), 'cancelLabel': ve.msg( 'visualeditor-viewpage-savewarning-keep' ),
'cancelFlags': [] 'cancelFlags': []
} ); } );
confirmDialog.connect( this, { 'ok': 'cancel' } ); confirmDialog.connect( this, {
'ok': function () {
// Prevent future confirm dialogs from executing this handler (bug 65557)
confirmDialog.disconnect( this );
this.cancel();
},
'cancel': function () {
// Prevent future confirm dialogs from executing this handler (bug 65557)
confirmDialog.disconnect( this );
}
} );
} }
} }
}; };
@ -906,6 +916,8 @@ ve.init.mw.ViewPageTarget.prototype.editSource = function () {
} ); } );
confirmDialog.connect( this, { confirmDialog.connect( this, {
'ok': function () { 'ok': function () {
// Prevent future confirm dialogs from executing this handler (bug 65557)
confirmDialog.disconnect( this );
// Get Wikitext from the DOM // Get Wikitext from the DOM
this.serialize( this.serialize(
this.docToSave || ve.dm.converter.getDomFromModel( this.surface.getModel().getDocument() ), this.docToSave || ve.dm.converter.getDomFromModel( this.surface.getModel().getDocument() ),
@ -913,6 +925,9 @@ ve.init.mw.ViewPageTarget.prototype.editSource = function () {
); );
}, },
'cancel': function () { 'cancel': function () {
// Prevent future confirm dialogs from executing this handler (bug 65557)
confirmDialog.disconnect( this );
// Undo the opacity change
this.$document.css( 'opacity', 1 ); this.$document.css( 'opacity', 1 );
} }
} ); } );