Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4125845
mobileRedirect.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
mobileRedirect.js
View Options
const
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
(
mw
.
cookie
.
get
(
'mf_testcookie'
)
===
'test_value'
)
{
return
true
;
// Otherwise try to set mf_testcookie and return true if it was set
}
else
{
mw
.
cookie
.
set
(
'mf_testcookie'
,
'test_value'
,
{
path
:
'/'
}
);
return
mw
.
cookie
.
get
(
'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
)
{
const
self
=
this
;
const
executeWrappedEvent
=
function
()
{
if
(
desktopViewClick
()
===
false
)
{
return
false
;
}
window
.
location
=
self
.
href
;
};
const
amcCampaign
=
amcOutreach
.
loadCampaign
();
const
onDismiss
=
function
()
{
executeWrappedEvent
();
};
const
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
);
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 19, 07:42 (2 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
3b/ac/4a7c7ad5b98733a52d693d1f6abe
Default Alt Text
mobileRedirect.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment