mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-16 18:58:45 +00:00
9c2ba25ca2
The Drawer API was changed in Ib123efe6af1b167706a73c71c860c85e7f439cc5 to have clients in charge of appending drawers to the DOM. To reflect and make AMC outreach drawer work with these changes, the amcOutreach.js code in MF was refactored in I8aa3f2c1fe1f638810a20a5e77eb5f2e2f6addd1 to make the showIfEligible method return the drawer instead of calling show on it. This work refactors Minerva to make use of both of these changes. Additional changes: * Removes amcOutreach click handler for talk button. Talk button is a tab everywhere except main page (I think) now so this code is just confusing. Bug: T242491 Depends-On: I8aa3f2c1fe1f638810a20a5e77eb5f2e2f6addd1 Change-Id: I01afe765cbcb5e79e419a3e42b3125f513e1f87e
91 lines
2.1 KiB
JavaScript
91 lines
2.1 KiB
JavaScript
var drawers = require( './drawers.js' );
|
|
|
|
/*
|
|
* Warn people if they're trying to switch to desktop but have cookies disabled.
|
|
*/
|
|
module.exports = function ( amcOutreach, currentPage ) {
|
|
/**
|
|
* Checks whether cookies are enabled
|
|
* @method
|
|
* @ignore
|
|
* @return {boolean} Whether cookies are enabled
|
|
*/
|
|
function cookiesEnabled() {
|
|
// If session cookie already set, return true
|
|
if ( $.cookie( 'mf_testcookie' ) === 'test_value' ) {
|
|
return true;
|
|
// Otherwise try to set mf_testcookie and return true if it was set
|
|
} else {
|
|
$.cookie( 'mf_testcookie', 'test_value', {
|
|
path: '/'
|
|
} );
|
|
return $.cookie( 'mf_testcookie' ) === 'test_value';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* An event handler for the toggle to desktop link.
|
|
* If cookies are enabled it will redirect you to desktop site as described in
|
|
* the link href associated with the handler.
|
|
* If cookies are not enabled, show a toast and die.
|
|
* @method
|
|
* @ignore
|
|
* @return {boolean|undefined}
|
|
*/
|
|
function desktopViewClick() {
|
|
if ( !cookiesEnabled() ) {
|
|
mw.notify(
|
|
mw.msg( 'mobile-frontend-cookies-required' ),
|
|
{ type: 'error' }
|
|
);
|
|
// Prevent default action
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @method
|
|
* @ignore
|
|
* @param {JQuery.Event} ev
|
|
* @return {boolean|undefined}
|
|
*/
|
|
function amcDesktopClickHandler( ev ) {
|
|
var
|
|
self = this,
|
|
executeWrappedEvent = function () {
|
|
if ( desktopViewClick() === false ) {
|
|
return false;
|
|
}
|
|
|
|
window.location = self.href;
|
|
},
|
|
amcCampaign = amcOutreach.loadCampaign(),
|
|
onDismiss = function () {
|
|
executeWrappedEvent();
|
|
},
|
|
drawer = amcCampaign.showIfEligible(
|
|
amcOutreach.ACTIONS.onDesktopLink,
|
|
onDismiss,
|
|
currentPage.title
|
|
);
|
|
|
|
if ( drawer ) {
|
|
ev.preventDefault();
|
|
// stopPropagation is needed to prevent drawer from immediately closing
|
|
// when shown (drawers.js adds a click event to window when drawer is
|
|
// shown
|
|
ev.stopPropagation();
|
|
|
|
drawers.displayDrawer( drawer, {} );
|
|
drawers.lockScroll();
|
|
|
|
return;
|
|
}
|
|
|
|
return executeWrappedEvent();
|
|
}
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
$( '#mw-mf-display-toggle' ).on( 'click', amcDesktopClickHandler );
|
|
};
|