mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-16 10:50:52 +00:00
c5d09c0288
Changes: * MinervaUI will now prefix any icons with `minerva` * Update definitions in skin.json, retaining selectors for cached HTML for icons that are rendered via PHP. * In I9021c53c2c04bdd7ce395eed33d89986acbfea6d watch and watched and arrow are moved to MobileFrontend so are removed from the RL module skins.minerva.icons.images.scripts as they are not used directly in this repo. user and anonymous are no longer used so also removed. * Presentation of userpage now belongs to MobileFrontend. Icons are styles were moved there in depends on. They are retained in skin.json to support cached HTML as user pages are subject to cache. They can be removed in a week. * In code review we noticed the anonymous icon was badly named. We rename to login. No caching implications. * Main menu icons are now prefixed with minerva rather than mf to reflect where they come from. Depends-On: I9021c53c2c04bdd7ce395eed33d89986acbfea6d Bug: T182162 Change-Id: I93264024f4915fc910c792b1905b89cdc6b8b546
133 lines
3.5 KiB
JavaScript
133 lines
3.5 KiB
JavaScript
( function ( M, track ) {
|
|
var msg = mw.msg,
|
|
MAX_PRINT_TIMEOUT = 3000,
|
|
GLYPH = 'download',
|
|
Icon = M.require( 'mobile.startup/Icon' ),
|
|
browser = M.require( 'mobile.startup/Browser' ).getSingleton();
|
|
|
|
/**
|
|
* Helper function to retreive the Android version
|
|
* @ignore
|
|
* @param {String} userAgent User Agent
|
|
* @return {Integer}
|
|
*/
|
|
function getAndroidVersion( userAgent ) {
|
|
var match = userAgent.toLowerCase().match( /android\s(\d\.]*)/ );
|
|
return match ? parseInt( match[1] ) : false;
|
|
}
|
|
|
|
/**
|
|
* Helper function to retrieve the Chrome/Chromium version
|
|
* @ignore
|
|
* @param {String} userAgent User Agent
|
|
* @return {Integer}
|
|
*/
|
|
function getChromeVersion( userAgent ) {
|
|
var match = userAgent.toLowerCase().match( /chrom(e|ium)\/(\d+)\./ );
|
|
return match ? parseInt( match[2] ) : false;
|
|
}
|
|
|
|
/**
|
|
* A download icon for triggering print functionality
|
|
* @class DownloadIcon
|
|
* @extends Icon
|
|
*
|
|
* @param {Skin} skin
|
|
* @param {Number[]} [supportedNamespaces]
|
|
* @constructor
|
|
*/
|
|
function DownloadIcon( skin, supportedNamespaces ) {
|
|
var options = {};
|
|
this.skin = skin;
|
|
this.supportedNamespaces = supportedNamespaces || [ 0 ];
|
|
options.tagName = 'li';
|
|
options.glyphPrefix = 'minerva';
|
|
options.title = msg( 'minerva-download' );
|
|
options.name = GLYPH;
|
|
Icon.call( this, options );
|
|
}
|
|
|
|
OO.mfExtend( DownloadIcon, Icon, {
|
|
/**
|
|
* Checks whether DownloadIcon is available for given user agent
|
|
* @param {string} userAgent User agent
|
|
* @return {Boolean}
|
|
*/
|
|
isAvailable: function ( userAgent ) {
|
|
var androidVersion = getAndroidVersion( userAgent ),
|
|
chromeVersion = getChromeVersion( userAgent ),
|
|
page = this.skin.page;
|
|
|
|
// Download button is restricted to certain namespaces T181152.
|
|
// Defaults to 0, in case cached JS has been served.
|
|
if ( this.supportedNamespaces.indexOf( page.getNamespaceId() ) === -1 ||
|
|
page.isMainPage() ) {
|
|
// namespace is not supported or it's a main page
|
|
return false;
|
|
}
|
|
|
|
if ( browser.isIos() || chromeVersion === false ) {
|
|
// we support only chrome/chromium on desktop/android
|
|
return false;
|
|
}
|
|
if ( ( androidVersion && androidVersion < 5 ) || chromeVersion < 41 ) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
/**
|
|
* 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 = GLYPH;
|
|
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 );
|
|
track( 'minerva.downloadAsPDF', {
|
|
action: 'callPrint'
|
|
} );
|
|
window.print();
|
|
hideSpinner();
|
|
}
|
|
// The click handler may be invoked multiple times so if a pending print is occurring
|
|
// do nothing.
|
|
if ( !this.timeout ) {
|
|
track( 'minerva.downloadAsPDF', {
|
|
action: 'fetchImages'
|
|
} );
|
|
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, mw.track ) );
|