mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-09-24 18:59:45 +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' );
|
mw.mmv.actionLogger.log( 'enlarge' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.ensureEventHandlersAreSetUp();
|
||||||
|
|
||||||
this.loadViewer().then( function ( viewer ) {
|
this.loadViewer().then( function ( viewer ) {
|
||||||
viewer.loadImageByTitle( title, true );
|
viewer.loadImageByTitle( title, true );
|
||||||
} );
|
} );
|
||||||
|
@ -395,6 +397,9 @@
|
||||||
MMVB.setupEventHandlers = function () {
|
MMVB.setupEventHandlers = function () {
|
||||||
var self = this;
|
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 () {
|
$( window ).on( this.browserHistory && this.browserHistory.pushState ? 'popstate.mmvb' : 'hashchange', function () {
|
||||||
self.hash();
|
self.hash();
|
||||||
} );
|
} );
|
||||||
|
@ -415,6 +420,19 @@
|
||||||
MMVB.cleanupEventHandlers = function () {
|
MMVB.cleanupEventHandlers = function () {
|
||||||
$( window ).off( 'hashchange popstate.mmvb' );
|
$( window ).off( 'hashchange popstate.mmvb' );
|
||||||
$( document ).off( 'mmv-hash' );
|
$( 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 ) {
|
function createBootstrap( viewer ) {
|
||||||
var bootstrap = new mw.mmv.MultimediaViewerBootstrap();
|
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 }; };
|
bootstrap.getViewer = function() { return viewer ? viewer : { initWithThumbs : $.noop }; };
|
||||||
|
|
||||||
return bootstrap;
|
return bootstrap;
|
||||||
|
@ -101,6 +106,7 @@
|
||||||
this.sandbox.stub( mw.loader, 'using' )
|
this.sandbox.stub( mw.loader, 'using' )
|
||||||
.callsArgWith( 2, new Error( 'loading failed', ['mmv'] ) )
|
.callsArgWith( 2, new Error( 'loading failed', ['mmv'] ) )
|
||||||
.withArgs( 'mediawiki.notification' ).returns( $.Deferred().reject() ); // needed for mw.notify
|
.withArgs( 'mediawiki.notification' ).returns( $.Deferred().reject() ); // needed for mw.notify
|
||||||
|
bootstrap.ensureEventHandlersAreSetUp = $.noop;
|
||||||
|
|
||||||
event = new $.Event( 'click', { button: 0, which: 1 } );
|
event = new $.Event( 'click', { button: 0, which: 1 } );
|
||||||
returnValue = bootstrap.click( {}, event, 'foo' );
|
returnValue = bootstrap.click( {}, event, 'foo' );
|
||||||
|
|
Loading…
Reference in a new issue