mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-04 18:48:15 +00:00
9826055afc
Looks like window.print may block so keep the spinner until it's finished execution. This may or may not fix the larger issue being discussed in the bug but is harmless so why not. Bug: T181261 Change-Id: I927d4bc8c96d74c14463f71b7ce6dec62618a485
74 lines
1.7 KiB
JavaScript
74 lines
1.7 KiB
JavaScript
( function ( M ) {
|
|
|
|
var msg = mw.msg,
|
|
MAX_PRINT_TIMEOUT = 3000,
|
|
Icon = M.require( 'mobile.startup/Icon' );
|
|
|
|
/**
|
|
* A download icon for triggering print functionality
|
|
* @class DownloadIcon
|
|
* @extends Icon
|
|
*
|
|
* @param {Skin} skin
|
|
* @constructor
|
|
*/
|
|
function DownloadIcon( skin ) {
|
|
var options = {};
|
|
this.skin = skin;
|
|
options.tagName = 'li';
|
|
options.title = msg( 'minerva-download' );
|
|
options.name = 'download';
|
|
Icon.call( this, options );
|
|
}
|
|
|
|
OO.mfExtend( DownloadIcon, Icon, {
|
|
/**
|
|
* Replace download icon with a spinner
|
|
*/
|
|
showSpinner: function () {
|
|
this.options.name = 'spinner';
|
|
this.render();
|
|
},
|
|
/**
|
|
* Restore download icon from spinner state
|
|
*/
|
|
hideSpinner: function () {
|
|
this.options.name = 'download';
|
|
this.render();
|
|
},
|
|
isTemplateMode: false,
|
|
/**
|
|
* onClick handler for button that invokes print function
|
|
*/
|
|
onClick: function () {
|
|
var self = this,
|
|
hideSpinner = this.hideSpinner.bind( this );
|
|
|
|
function doPrint() {
|
|
self.timeout = clearTimeout( self.timeout );
|
|
window.print();
|
|
hideSpinner();
|
|
}
|
|
|
|
// The click handler may be invoked multiple times so if a pending print is occurring
|
|
// do nothing.
|
|
if ( !this.timeout ) {
|
|
this.showSpinner();
|
|
// If all image downloads are taking longer to load then the MAX_PRINT_TIMEOUT
|
|
// abort the spinner and print regardless.
|
|
this.timeout = setTimeout( doPrint, MAX_PRINT_TIMEOUT );
|
|
this.skin.loadImagesList().always( function () {
|
|
if ( self.timeout ) {
|
|
doPrint();
|
|
}
|
|
} );
|
|
}
|
|
},
|
|
events: {
|
|
click: 'onClick'
|
|
}
|
|
} );
|
|
|
|
M.define( 'skins.minerva.scripts/DownloadIcon', DownloadIcon );
|
|
}( mw.mobileFrontend ) );
|