Merge "Make sure event handlers are set up even if onready handler is lost"

This commit is contained in:
jenkins-bot 2014-09-15 08:19:01 +00:00 committed by Gerrit Code Review
commit f7cbc93b86
2 changed files with 24 additions and 0 deletions

View file

@ -307,6 +307,8 @@
mw.mmv.actionLogger.log( 'enlarge' );
}
this.ensureEventHandlersAreSetUp();
this.loadViewer().then( function ( viewer ) {
viewer.loadImageByTitle( title, true );
} );
@ -395,6 +397,9 @@
MMVB.setupEventHandlers = function () {
var self = this;
/** @property {boolean} eventHandlersHaveBeenSetUp tracks domready event handler state */
this.eventHandlersHaveBeenSetUp = true;
$( window ).on( this.browserHistory && this.browserHistory.pushState ? 'popstate.mmvb' : 'hashchange', function () {
self.hash();
} );
@ -415,6 +420,19 @@
MMVB.cleanupEventHandlers = function () {
$( window ).off( 'hashchange popstate.mmvb' );
$( document ).off( 'mmv-hash' );
this.eventHandlersHaveBeenSetUp = false;
};
/**
* Makes sure event handlers are set up properly via MultimediaViewerBootstrap.setupEventHandlers().
* Called before loading the main mmv module. At this point, event handers for MultimediaViewerBootstrap
* should have been set up, but due to bug 70756 it cannot be guaranteed.
*/
MMVB.ensureEventHandlersAreSetUp = function () {
if ( !this.eventHandlersHaveBeenSetUp ) {
this.setupEventHandlers();
this.eventHandlersHaveBeenSetUp = true;
}
};
/**

View file

@ -38,6 +38,11 @@
function createBootstrap( viewer ) {
var bootstrap = new mw.mmv.MultimediaViewerBootstrap();
// MultimediaViewerBootstrap.ensureEventHandlersAreSetUp() is a weird workaround for gadget bugs.
// MediaViewer should work without it, and so should the tests.
bootstrap.ensureEventHandlersAreSetUp = $.noop;
bootstrap.getViewer = function() { return viewer ? viewer : { initWithThumbs : $.noop }; };
return bootstrap;
@ -101,6 +106,7 @@
this.sandbox.stub( mw.loader, 'using' )
.callsArgWith( 2, new Error( 'loading failed', ['mmv'] ) )
.withArgs( 'mediawiki.notification' ).returns( $.Deferred().reject() ); // needed for mw.notify
bootstrap.ensureEventHandlersAreSetUp = $.noop;
event = new $.Event( 'click', { button: 0, which: 1 } );
returnValue = bootstrap.click( {}, event, 'foo' );