mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-24 22:25:27 +00:00
33236091f2
This follows up on the work from MF: - I399dd70b5b93fda8c6d1735e3861c5ab2da43bdb - Id59381ddc330de2b8017963d6a25c6567317faf7 Event handlers are added to the history link, talk link, and desktop link to support amc outreach. When eligible, the drawer is shown. When ineligible, logic from the regular handler is executed. Bug: T226069 Depends-On: Id59381ddc330de2b8017963d6a25c6567317faf7 Change-Id: I0cce0bb6f44801c383556f8c26ee865032d86c8a
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
/*
|
|
* 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
|
|
* @return {boolean|undefined}
|
|
*/
|
|
function amcDesktopClickHandler() {
|
|
var
|
|
self = this,
|
|
executeWrappedEvent = function () {
|
|
if ( desktopViewClick() === false ) {
|
|
return false;
|
|
}
|
|
|
|
window.location = self.href;
|
|
},
|
|
amcCampaign = amcOutreach.loadCampaign(),
|
|
onDismiss = function () {
|
|
executeWrappedEvent();
|
|
};
|
|
|
|
if ( amcCampaign.showIfEligible( amcOutreach.ACTIONS.onDesktopLink,
|
|
onDismiss, currentPage.title ) ) {
|
|
// prevent default/stop propagation
|
|
return false;
|
|
}
|
|
|
|
return executeWrappedEvent();
|
|
}
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
$( '#mw-mf-display-toggle' ).on( 'click', amcDesktopClickHandler );
|
|
};
|