mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-09-24 10:49:40 +00:00
Merge "Make sure event handlers are set up even if onready handler is lost"
This commit is contained in:
commit
f7cbc93b86
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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' );
|
||||
|
|
Loading…
Reference in a new issue