Pmiazga has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/403968 )
Change subject: Show Download button only on Android >= 5 & Chrome >= 41 ...................................................................... Show Download button only on Android >= 5 & Chrome >= 41 Changes: - moved DownloadButtton checks & initialization to separate function - introduced supportedNamespaces variable for better readability - reorganized huge if(){} statement to set of smaller if's with nice comments why this configuration is not supported - introduced getAndroidVersion and getChromeVersion helper functions - added check to not allow Android < 5 or Chrome < 41 Bug: T182059 Change-Id: Ib5064459ee56aed68179389f37b4bc3b5c2c4492 --- M resources/skins.minerva.scripts/init.js 1 file changed, 47 insertions(+), 22 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/skins/MinervaNeue refs/changes/68/403968/1 diff --git a/resources/skins.minerva.scripts/init.js b/resources/skins.minerva.scripts/init.js index 327399f..1912b81 100644 --- a/resources/skins.minerva.scripts/init.js +++ b/resources/skins.minerva.scripts/init.js @@ -205,6 +205,15 @@ $tagline.text( msg ); } } + function getAndroidVersion() { + var match = navigator.userAgent.toLowerCase().match( /android\s(\d\.]*)/ ); + return match ? parseInt( match[1] ) : false; + } + + function getChromeVersion() { + var match = navigator.userAgent.toLowerCase().match( /chrom(e|ium)\/(\d+)\./ ); + return match ? parseInt( match[2] ) : false; + } /** * Initialisation function for registration date on user page @@ -220,6 +229,43 @@ } ); } + /** + * Initialize and inject the download button + * + * There are many restrictions when we can show the download button, this function should handle + * all device/os/operating system related checks and if device supports printing it will inject + * the Download icon + */ + function appendDownloadButton() { + var androidVersion = getAndroidVersion(), + chromeVersion = getChromeVersion(), + supportedNamespaces = config.get( 'wgMinervaDownloadNamespaces', [ 0 ] ); + + // Download button is restricted to certain namespaces T181152. + // Defaults to 0, in case cached JS has been served. + if ( supportedNamespaces.indexOf( config.get( 'wgNamespaceNumber' ) ) === -1 || page.isMainPage() ) { + // namespace is not supported or it's a main page + return; + } + if ( browser.isIos() || window.chrome === undefined ) { + // we support only chrome/chromium on desktop/android + return; + } + if ( androidVersion && androidVersion < 5 || + chromeVersion && chromeVersion < 41 ) { + // we do not support android version older than 5 or Chrome older than version 541 + return; + } + // Because the page actions are floated to the right, their order in the + // DOM is reversed in the display. The watchstar is last in the DOM and + // left-most in the display. Since we want the download button to be to + // the left of the watchstar, we put it after it in the DOM. + new DownloadIcon( skin ).$el.insertAfter( '#ca-watch' ); + track( 'minerva.downloadAsPDF', { + action: 'buttonVisible' + } ); + } + $( function () { // Update anything else that needs enhancing (e.g. watchlist) initModifiedInfo(); @@ -227,28 +273,7 @@ initHistoryLink( $( '.last-modifier-tagline a' ) ); M.on( 'resize', loadTabletModules ); loadTabletModules(); - - if ( - // Download button is restricted to certain namespaces T181152. - // Defaults to 0, in case cached JS has been served. - config.get( 'wgMinervaDownloadNamespaces', [ 0 ] ) - .indexOf( config.get( 'wgNamespaceNumber' ) ) > -1 && - !page.isMainPage() && - // The iOS print dialog does not provide pdf functionality (see T177215) - !browser.isIos() && - // Currently restricted to Chrome (T179529) until we have good fallbacks for browsers - // which do not provide print functionality - window.chrome !== undefined - ) { - // Because the page actions are floated to the right, their order in the - // DOM is reversed in the display. The watchstar is last in the DOM and - // left-most in the display. Since we want the download button to be to - // the left of the watchstar, we put it after it in the DOM. - new DownloadIcon( skin ).$el.insertAfter( '#ca-watch' ); - track( 'minerva.downloadAsPDF', { - action: 'buttonVisible' - } ); - } + appendDownloadButton(); } ); M.define( 'skins.minerva.scripts/overlayManager', overlayManager ); -- To view, visit https://gerrit.wikimedia.org/r/403968 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib5064459ee56aed68179389f37b4bc3b5c2c4492 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/skins/MinervaNeue Gerrit-Branch: master Gerrit-Owner: Pmiazga <pmia...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits