mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-27 23:50:30 +00:00
Trigger AmcOutreach on History, Talk, and Desktop links
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
This commit is contained in:
parent
783e391bb9
commit
33236091f2
|
@ -136,7 +136,7 @@
|
|||
* to show a human friendly date in seconds, minutes, hours, days
|
||||
* months or years
|
||||
* @ignore
|
||||
* @param {JQuery.Object} [$lastModifiedLink]
|
||||
* @param {JQuery.Object} $lastModifiedLink
|
||||
*/
|
||||
function initHistoryLink( $lastModifiedLink ) {
|
||||
var delta, historyUrl, msg, $bar,
|
||||
|
@ -162,6 +162,34 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @param {JQuery.Event} ev
|
||||
*/
|
||||
function amcHistoryClickHandler( ev ) {
|
||||
var
|
||||
self = this,
|
||||
amcOutreach = mobile.amcOutreach,
|
||||
amcCampaign = amcOutreach.loadCampaign(),
|
||||
onDismiss = function () {
|
||||
toast.showOnPageReload( mw.message( 'mobile-frontend-amc-outreach-dismissed-message' ).text() );
|
||||
window.location = self.href;
|
||||
};
|
||||
|
||||
if ( amcCampaign.showIfEligible( amcOutreach.ACTIONS.onHistoryLink, onDismiss, currentPage.title, 'action=history' ) ) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @param {JQuery.Object} $lastModifiedLink
|
||||
* @ignore
|
||||
*/
|
||||
function initAmcHistoryLink( $lastModifiedLink ) {
|
||||
$lastModifiedLink.one( 'click', amcHistoryClickHandler );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisation function for last modified times
|
||||
*
|
||||
|
@ -319,12 +347,14 @@
|
|||
// - search
|
||||
search();
|
||||
// - mobile redirect
|
||||
mobileRedirect();
|
||||
mobileRedirect( mobile.amcOutreach, currentPage );
|
||||
// Update anything else that needs enhancing (e.g. watchlist)
|
||||
initModifiedInfo();
|
||||
initRegistrationInfo();
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
initHistoryLink( $( 'a.last-modified-bar__text' ) );
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
initAmcHistoryLink( $( '.last-modified-bar__text a' ) );
|
||||
if ( toolbarElement ) {
|
||||
Toolbar.bind( window, toolbarElement );
|
||||
Toolbar.render( window, toolbarElement );
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Warn people if they're trying to switch to desktop but have cookies disabled.
|
||||
*/
|
||||
module.exports = function () {
|
||||
module.exports = function ( amcOutreach, currentPage ) {
|
||||
/**
|
||||
* Checks whether cookies are enabled
|
||||
* @method
|
||||
|
@ -41,6 +41,35 @@ module.exports = function () {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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', desktopViewClick );
|
||||
$( '#mw-mf-display-toggle' ).on( 'click', amcDesktopClickHandler );
|
||||
};
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
module.exports = function ( mobile ) {
|
||||
var
|
||||
toast = mobile.toast,
|
||||
currentPage = mobile.currentPage(),
|
||||
loader = mobile.rlModuleLoader,
|
||||
loadingOverlay = mobile.loadingOverlay,
|
||||
eventBus = mobile.eventBusSingleton,
|
||||
|
@ -88,7 +90,7 @@ module.exports = function ( mobile ) {
|
|||
},
|
||||
// T184273 using `currentPage` because 'wgPageName'
|
||||
// contains underscores instead of spaces.
|
||||
currentPageTitle: mobile.currentPage().title,
|
||||
currentPageTitle: currentPage.title,
|
||||
licenseMsg: skin.getLicenseMsg(),
|
||||
eventBus: eventBus,
|
||||
id: id
|
||||
|
@ -110,22 +112,46 @@ module.exports = function ( mobile ) {
|
|||
}
|
||||
} );
|
||||
|
||||
function changeHash() {
|
||||
// eslint-disable-next-line no-jquery/no-class-state
|
||||
if ( $talk.hasClass( 'add' ) ) {
|
||||
window.location.hash = '#/talk/new';
|
||||
} else {
|
||||
window.location.hash = '#/talk';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @param {JQuery.Event} ev
|
||||
* @return {undefined}
|
||||
*/
|
||||
function amcTalkClickHandler( ev ) {
|
||||
var
|
||||
amcOutreach = mobile.amcOutreach,
|
||||
amcCampaign = amcOutreach.loadCampaign(),
|
||||
onDismiss = function () {
|
||||
changeHash();
|
||||
toast.show( mw.message( 'mobile-frontend-amc-outreach-dismissed-message' ).text() );
|
||||
};
|
||||
|
||||
// avoiding navigating to original URL
|
||||
// DO NOT USE stopPropagation or you'll break click tracking in WikimediaEvents
|
||||
ev.preventDefault();
|
||||
|
||||
if ( amcCampaign.showIfEligible( amcOutreach.ACTIONS.onTalkLink, onDismiss, currentPage.title, '#/talk' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
changeHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create route '#/talk'
|
||||
* @ignore
|
||||
*/
|
||||
function init() {
|
||||
$talk.on( 'click', function ( ev ) {
|
||||
// eslint-disable-next-line no-jquery/no-class-state
|
||||
if ( $talk.hasClass( 'add' ) ) {
|
||||
window.location.hash = '#/talk/new';
|
||||
} else {
|
||||
window.location.hash = '#/talk';
|
||||
}
|
||||
// avoiding navigating to original URL
|
||||
// DO NOT USE stopPropagation or you'll break click tracking in WikimediaEvents
|
||||
ev.preventDefault();
|
||||
} );
|
||||
$talk.on( 'click', amcTalkClickHandler );
|
||||
}
|
||||
|
||||
init();
|
||||
|
|
Loading…
Reference in a new issue