2019-03-13 18:57:00 -04:00
|
|
|
/* eslint-disable no-jquery/no-global-selector */
|
2019-01-14 16:00:07 -05:00
|
|
|
$( function () {
|
2019-07-12 15:51:58 -04:00
|
|
|
var mobileMediaQuery = window.matchMedia( 'screen and (max-width: 550px)' ),
|
2019-01-14 16:00:07 -05:00
|
|
|
echoHacked = false,
|
|
|
|
echoHackActive = false,
|
|
|
|
notifications = $( '#pt-notifications-alert a' ).data( 'counter-num' ) + $( '#pt-notifications-notice a' ).data( 'counter-num' ),
|
|
|
|
notificationsString;
|
|
|
|
|
2019-07-12 15:35:55 -04:00
|
|
|
// When the icons are clicked for the first time, they are replaced with a JS interface,
|
|
|
|
// so don't cache this in a long-lived variable
|
|
|
|
function getNotificationIcons() {
|
|
|
|
return $( '#pt-notifications-alert, #pt-notifications-notice' );
|
|
|
|
}
|
|
|
|
|
2019-01-14 16:00:07 -05:00
|
|
|
// Move echo badges in/out of p-personal
|
|
|
|
function monoBookMobileMoveEchoIcons() {
|
2019-07-12 15:35:55 -04:00
|
|
|
var $notificationIcons = getNotificationIcons();
|
|
|
|
if ( $notificationIcons.length ) {
|
2019-07-12 15:51:58 -04:00
|
|
|
if ( !echoHackActive && mobileMediaQuery.matches ) {
|
2019-07-12 15:35:55 -04:00
|
|
|
$( '#echo-hack-badges' ).append( $notificationIcons );
|
2019-01-14 16:00:07 -05:00
|
|
|
|
|
|
|
echoHackActive = true;
|
2019-07-12 15:51:58 -04:00
|
|
|
} else if ( echoHackActive && !mobileMediaQuery.matches ) {
|
2019-07-12 15:35:55 -04:00
|
|
|
$( $notificationIcons ).insertBefore( '#pt-mytalk' );
|
2019-01-14 16:00:07 -05:00
|
|
|
|
|
|
|
echoHackActive = false;
|
2018-05-19 14:42:05 -04:00
|
|
|
}
|
|
|
|
}
|
2019-01-14 16:00:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function monoBookMobileEchoHack() {
|
2019-07-12 15:35:55 -04:00
|
|
|
var $notificationIcons = getNotificationIcons();
|
|
|
|
if ( $notificationIcons.length ) {
|
2019-07-12 15:51:58 -04:00
|
|
|
if ( !echoHacked && mobileMediaQuery.matches ) {
|
2019-01-14 16:00:07 -05:00
|
|
|
if ( notifications ) {
|
|
|
|
notificationsString = mw.msg( 'monobook-notifications-link', notifications );
|
|
|
|
} else {
|
|
|
|
notificationsString = mw.msg( 'monobook-notifications-link-none' );
|
2018-05-19 14:42:05 -04:00
|
|
|
}
|
|
|
|
|
2019-01-14 16:00:07 -05:00
|
|
|
// add inline p-personal echo link
|
|
|
|
mw.util.addPortletLink(
|
|
|
|
'p-personal',
|
|
|
|
mw.util.getUrl( 'Special:Notifications' ),
|
|
|
|
notificationsString,
|
|
|
|
'pt-notifications',
|
|
|
|
$( '#pt-notifications-notice' ).attr( 'tooltip' ),
|
|
|
|
null,
|
|
|
|
'#pt-preferences'
|
|
|
|
);
|
|
|
|
|
|
|
|
$( '#p-personal-toggle' ).append( $( '<ul>' ).attr( 'id', 'echo-hack-badges' ) );
|
|
|
|
|
|
|
|
echoHacked = true;
|
2018-05-19 14:42:05 -04:00
|
|
|
}
|
2019-01-14 16:00:07 -05:00
|
|
|
|
|
|
|
monoBookMobileMoveEchoIcons();
|
2018-05-19 14:42:05 -04:00
|
|
|
}
|
2019-01-14 16:00:07 -05:00
|
|
|
}
|
2018-05-19 14:42:05 -04:00
|
|
|
|
2019-01-14 16:00:07 -05:00
|
|
|
$( window ).on( 'resize', monoBookMobileEchoHack );
|
|
|
|
monoBookMobileEchoHack();
|
|
|
|
} );
|