2017-10-18 21:03:51 +00:00
|
|
|
( function ( M ) {
|
|
|
|
|
|
|
|
var msg = mw.msg,
|
2017-11-15 22:37:37 +00:00
|
|
|
MAX_PRINT_TIMEOUT = 3000,
|
2017-10-18 21:03:51 +00:00
|
|
|
Icon = M.require( 'mobile.startup/Icon' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A download icon for triggering print functionality
|
|
|
|
* @class DownloadIcon
|
|
|
|
* @extends Icon
|
|
|
|
*
|
2017-11-15 22:37:37 +00:00
|
|
|
* @param {Skin} skin
|
2017-10-18 21:03:51 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
2017-11-15 22:37:37 +00:00
|
|
|
function DownloadIcon( skin ) {
|
2017-10-18 21:03:51 +00:00
|
|
|
var options = {};
|
2017-11-15 22:37:37 +00:00
|
|
|
this.skin = skin;
|
2017-10-18 21:03:51 +00:00
|
|
|
options.tagName = 'li';
|
|
|
|
options.title = msg( 'minerva-download' );
|
|
|
|
options.name = 'download';
|
|
|
|
Icon.call( this, options );
|
|
|
|
}
|
|
|
|
|
|
|
|
OO.mfExtend( DownloadIcon, Icon, {
|
2017-11-15 22:37:37 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-10-18 21:03:51 +00:00
|
|
|
onClick: function () {
|
2017-11-15 22:37:37 +00:00
|
|
|
var self = this,
|
|
|
|
hideSpinner = this.hideSpinner.bind( this );
|
|
|
|
|
|
|
|
function doPrint() {
|
|
|
|
self.timeout = clearTimeout( self.timeout );
|
|
|
|
hideSpinner();
|
|
|
|
window.print();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2017-10-18 21:03:51 +00:00
|
|
|
},
|
|
|
|
events: {
|
|
|
|
click: 'onClick'
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
M.define( 'skins.minerva.scripts/DownloadIcon', DownloadIcon );
|
|
|
|
}( mw.mobileFrontend ) );
|