| 1 |
const drawers = require( './drawers.js' ); |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
module.exports = function ( amcOutreach, currentPage ) { |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
function cookiesEnabled() { |
| 15 |
|
| 16 |
if ( mw.cookie.get( 'mf_testcookie' ) === 'test_value' ) { |
| 17 |
return true; |
| 18 |
|
| 19 |
} else { |
| 20 |
mw.cookie.set( 'mf_testcookie', 'test_value', { |
| 21 |
path: '/' |
| 22 |
} ); |
| 23 |
return mw.cookie.get( 'mf_testcookie' ) === 'test_value'; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
function desktopViewClick() { |
| 38 |
if ( !cookiesEnabled() ) { |
| 39 |
mw.notify( |
| 40 |
mw.msg( 'mobile-frontend-cookies-required' ), |
| 41 |
{ type: 'error' } |
| 42 |
); |
| 43 |
|
| 44 |
return false; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
function amcDesktopClickHandler( ev ) { |
| 55 |
const self = this; |
| 56 |
const executeWrappedEvent = function () { |
| 57 |
if ( desktopViewClick() === false ) { |
| 58 |
return false; |
| 59 |
} |
| 60 |
|
| 61 |
window.location = self.href; |
| 62 |
}; |
| 63 |
const amcCampaign = amcOutreach.loadCampaign(); |
| 64 |
const onDismiss = function () { |
| 65 |
executeWrappedEvent(); |
| 66 |
}; |
| 67 |
const drawer = amcCampaign.showIfEligible( |
| 68 |
amcOutreach.ACTIONS.onDesktopLink, |
| 69 |
onDismiss, |
| 70 |
currentPage.title |
| 71 |
); |
| 72 |
|
| 73 |
if ( drawer ) { |
| 74 |
ev.preventDefault(); |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
ev.stopPropagation(); |
| 79 |
|
| 80 |
drawers.displayDrawer( drawer, {} ); |
| 81 |
drawers.lockScroll(); |
| 82 |
|
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
return executeWrappedEvent(); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
$( '#mw-mf-display-toggle' ).on( 'click', amcDesktopClickHandler ); |
| 91 |
}; |