| 1 |
|
| 2 |
module.exports = function () { |
| 3 |
var mobileMediaQuery = window.matchMedia( 'screen and (max-width: 550px)' ), |
| 4 |
echoHacked = false, |
| 5 |
echoHackActive = false, |
| 6 |
notifications = $( '#pt-notifications-alert a' ).data( 'counter-num' ) + $( '#pt-notifications-notice a' ).data( 'counter-num' ), |
| 7 |
notificationsString; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
function getNotificationIcons() { |
| 12 |
return $( '#pt-notifications-alert, #pt-notifications-notice' ); |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
function monoBookMobileMoveEchoIcons() { |
| 17 |
var $notificationIcons = getNotificationIcons(); |
| 18 |
if ( $notificationIcons.length ) { |
| 19 |
if ( !echoHackActive && mobileMediaQuery.matches ) { |
| 20 |
$( '#echo-hack-badges' ).append( $notificationIcons ); |
| 21 |
|
| 22 |
echoHackActive = true; |
| 23 |
} else if ( echoHackActive && !mobileMediaQuery.matches ) { |
| 24 |
$( $notificationIcons ).insertBefore( '#pt-mytalk' ); |
| 25 |
|
| 26 |
echoHackActive = false; |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
function monoBookMobileEchoHack() { |
| 32 |
var $notificationIcons = getNotificationIcons(); |
| 33 |
if ( $notificationIcons.length ) { |
| 34 |
if ( !echoHacked && mobileMediaQuery.matches ) { |
| 35 |
if ( notifications ) { |
| 36 |
notificationsString = mw.msg( 'monobook-notifications-link', notifications ); |
| 37 |
} else { |
| 38 |
notificationsString = mw.msg( 'monobook-notifications-link-none' ); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
mw.util.addPortletLink( |
| 43 |
'p-personal', |
| 44 |
mw.util.getUrl( 'Special:Notifications' ), |
| 45 |
notificationsString, |
| 46 |
'pt-notifications', |
| 47 |
$( '#pt-notifications-notice' ).attr( 'tooltip' ), |
| 48 |
null, |
| 49 |
'#pt-preferences' |
| 50 |
); |
| 51 |
|
| 52 |
$( '#p-personal-toggle' ).append( $( '<ul>' ).attr( 'id', 'echo-hack-badges' ) ); |
| 53 |
|
| 54 |
echoHacked = true; |
| 55 |
} |
| 56 |
|
| 57 |
monoBookMobileMoveEchoIcons(); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
$( window ).on( 'resize', monoBookMobileEchoHack ); |
| 62 |
monoBookMobileEchoHack(); |
| 63 |
}; |