mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-16 18:58:45 +00:00
72df451bd3
Help with readability by using module.exports and require rather than the MobileFrontend provided mw.mobileFrontend module manager (and avoid adopting webpack at this time) Replace usages of mw.mobileFrontend.require with local require and module.exports (compatible with RL or Node implementation) Changes: * Notifications modules are merged into skins.minerva.scripts and initialised via a client side check. * new file overlayManager for exporting an overlayManager singleton rather than being hidden inside resources/skins.minerva.scripts/init.js * All M.define/M.requires swapped out for require where possible The `define` method is now forbidden in the repo. Bug: T212944 Change-Id: I44790dd3fc6fe42bb502d79c39c4081c223bf2b1
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
/*
|
|
* Warn people if they're trying to switch to desktop but have cookies disabled.
|
|
*/
|
|
module.exports = function () {
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
$( '#mw-mf-display-toggle' ).on( 'click', desktopViewClick );
|
|
};
|