2013-01-03 19:59:42 +00:00
|
|
|
/*global window:false */
|
2012-09-26 05:09:43 +00:00
|
|
|
( function( $, mw ) {
|
|
|
|
'use strict';
|
|
|
|
|
2012-08-01 19:53:05 +00:00
|
|
|
mw.echo.overlay = {
|
2012-12-10 05:01:00 +00:00
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
'updateCount' : function( newCount ) {
|
2012-11-09 01:50:26 +00:00
|
|
|
// Accomodate '10' or '100+'. Numbers need to be
|
|
|
|
// passed as numbers for correct behavior of '0'.
|
|
|
|
if ( !isNaN( newCount ) ) {
|
|
|
|
newCount = Number( newCount );
|
|
|
|
}
|
|
|
|
|
2012-12-12 02:18:51 +00:00
|
|
|
if ( mw.echo.overlay.configuration['notifications-link-full'] ) {
|
2013-01-16 01:29:06 +00:00
|
|
|
$( '#pt-notifications > a' )
|
2012-12-12 02:18:51 +00:00
|
|
|
.text( mw.msg( 'echo-link' ) )
|
|
|
|
.badge( newCount, true, true );
|
|
|
|
} else {
|
2013-01-16 01:29:06 +00:00
|
|
|
$( '#pt-notifications > a' )
|
2013-02-27 00:15:31 +00:00
|
|
|
.addClass( 'mw-echo-short-link' )
|
2012-12-12 02:18:51 +00:00
|
|
|
.text( '' )
|
|
|
|
.badge( newCount, true, true );
|
|
|
|
}
|
2012-07-31 21:18:16 +00:00
|
|
|
|
2012-08-01 19:53:05 +00:00
|
|
|
mw.echo.overlay.notification_count = newCount;
|
|
|
|
},
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
'configuration' : mw.config.get( 'wgEchoOverlayConfiguration' ),
|
2012-08-01 19:53:05 +00:00
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
'buildOverlay' : function( callback ) {
|
2012-09-26 05:09:43 +00:00
|
|
|
var $overlay = $( '<div></div>' ).addClass( 'mw-echo-overlay' ),
|
2012-11-09 01:50:26 +00:00
|
|
|
$link = $( '#pt-notifications a' ),
|
2012-12-10 05:01:00 +00:00
|
|
|
$prefLink = $( '#pt-preferences a' ),
|
2012-11-09 01:50:26 +00:00
|
|
|
count = 0;
|
2012-06-01 10:57:09 +00:00
|
|
|
var Api = new mw.Api();
|
2013-01-03 19:59:42 +00:00
|
|
|
// Set notification limit based on height of the window
|
2013-04-10 00:43:57 +00:00
|
|
|
var notificationLimit = Math.floor( ( $( window ).height() - 134 ) / 90 );
|
2013-01-03 19:59:42 +00:00
|
|
|
|
|
|
|
if ( notificationLimit < 1 ) {
|
|
|
|
notificationLimit = 1;
|
2013-04-10 00:43:57 +00:00
|
|
|
} else if ( notificationLimit > 8 ) {
|
|
|
|
notificationLimit = 8;
|
2013-01-03 19:59:42 +00:00
|
|
|
}
|
2012-06-01 10:57:09 +00:00
|
|
|
|
|
|
|
Api.get( {
|
|
|
|
'action' : 'query',
|
|
|
|
'meta' : 'notifications',
|
2013-01-07 22:44:58 +00:00
|
|
|
'notformat' : 'flyout',
|
2013-01-03 19:59:42 +00:00
|
|
|
'notlimit' : notificationLimit,
|
2012-12-17 21:58:18 +00:00
|
|
|
'notprop' : 'index|list|count'
|
2012-06-01 10:57:09 +00:00
|
|
|
}, {
|
2012-08-30 16:04:39 +00:00
|
|
|
'ok' : function( result ) {
|
2012-12-17 21:58:18 +00:00
|
|
|
var notifications = result.query.notifications,
|
|
|
|
unread = [],
|
|
|
|
unreadTotalCount = result.query.notifications.count,
|
|
|
|
$title = $( '<div class="mw-echo-overlay-title"></div>' ),
|
2012-12-27 16:50:00 +00:00
|
|
|
$ul = $( '<ul class="mw-echo-notifications"></ul>' ),
|
|
|
|
titleText = '';
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2013-02-16 02:20:34 +00:00
|
|
|
$ul.css( 'max-height', notificationLimit * 95 + 'px' );
|
2012-08-30 16:04:39 +00:00
|
|
|
$.each( notifications.index, function( index, id ) {
|
Try to fix jenkins lint tests
From
https://integration.mediawiki.org/ci/job/mwext-Echo-jslint/142/console
18:54:22 >> modules/overlay/ext.echo.overlay.js: line 56, col 49, ['list']
is better written in dot notation.
18:54:22 >> modules/overlay/ext.echo.overlay.js: line 37, col 44, 'window'
is not defined.
18:54:22 >> modules/overlay/ext.echo.overlay.js: line 127, col 21,
'window' is not defined.
18:54:22 >> modules/special/ext.echo.special.js: line 58, col 49, ['list']
is better written in dot notation.
18:54:22 >> modules/special/ext.echo.special.js: line 112, col 25, Bad
line breaking before '&&'.
Change-Id: I2676a3e07d9d5f7419dd9030dbf218b2c0094cf1
2012-12-27 22:06:20 +00:00
|
|
|
var data = notifications.list[id];
|
2012-12-07 01:08:33 +00:00
|
|
|
var $li = $( '<li></li>' )
|
2012-09-26 05:09:43 +00:00
|
|
|
.data( 'details', data )
|
|
|
|
.data( 'id', id )
|
2013-03-07 22:51:25 +00:00
|
|
|
.attr( 'data-notification-category', data.category )
|
2012-09-26 05:09:43 +00:00
|
|
|
.addClass( 'mw-echo-notification' )
|
|
|
|
.append( data['*'] )
|
|
|
|
.appendTo( $ul );
|
2012-08-30 16:04:39 +00:00
|
|
|
|
2012-12-07 01:08:33 +00:00
|
|
|
if ( !data.read ) {
|
2012-08-30 16:04:39 +00:00
|
|
|
$li.addClass( 'mw-echo-unread' );
|
2012-12-14 01:04:37 +00:00
|
|
|
unread.push( id );
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
2013-02-13 02:08:36 +00:00
|
|
|
|
|
|
|
// Set up each individual notification with a close box and dismiss
|
|
|
|
// interface if it is dismissable.
|
|
|
|
if ( $li.find( '.mw-echo-dismiss' ).length ) {
|
|
|
|
mw.echo.setUpDismissability( $li );
|
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
} );
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2012-12-17 21:58:18 +00:00
|
|
|
if ( notifications.index.length > 0 ) {
|
|
|
|
if ( unreadTotalCount > unread.length ) {
|
2012-12-27 16:50:00 +00:00
|
|
|
titleText = mw.msg( 'echo-overlay-title-overflow', unread.length, unreadTotalCount );
|
2012-12-17 21:58:18 +00:00
|
|
|
} else {
|
2012-12-27 16:50:00 +00:00
|
|
|
titleText = mw.msg( 'echo-overlay-title' );
|
2012-12-17 21:58:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-12-27 16:50:00 +00:00
|
|
|
titleText = mw.msg( 'echo-none' );
|
2012-12-17 21:58:18 +00:00
|
|
|
}
|
2013-02-26 21:08:34 +00:00
|
|
|
$title.text( titleText );
|
2012-12-17 21:58:18 +00:00
|
|
|
$title.appendTo( $overlay );
|
|
|
|
|
|
|
|
if ( $ul.find( 'li' ).length ) {
|
|
|
|
$ul.appendTo( $overlay );
|
2012-06-08 05:55:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-22 00:43:41 +00:00
|
|
|
var $overlayFooter = $( '<div/>' )
|
|
|
|
.attr( 'id', 'mw-echo-overlay-footer' );
|
|
|
|
|
2013-04-03 00:47:40 +00:00
|
|
|
// add link to notifications archive
|
|
|
|
$overlayFooter.append(
|
|
|
|
$link
|
|
|
|
.clone()
|
|
|
|
.attr( 'id', 'mw-echo-overlay-link' )
|
|
|
|
.text( mw.msg( 'echo-overlay-link' ) )
|
|
|
|
);
|
2012-06-08 05:55:01 +00:00
|
|
|
|
2012-12-10 05:01:00 +00:00
|
|
|
// add link to notification preferences
|
2012-12-22 00:43:41 +00:00
|
|
|
$overlayFooter.append(
|
2013-04-03 00:47:40 +00:00
|
|
|
$prefLink
|
|
|
|
.clone()
|
2012-12-17 21:58:18 +00:00
|
|
|
.attr( 'id', 'mw-echo-overlay-pref-link' )
|
2013-04-03 00:47:40 +00:00
|
|
|
.attr( 'href', $prefLink.attr( 'href' ) + '#mw-prefsection-echo' )
|
2012-12-10 05:01:00 +00:00
|
|
|
);
|
|
|
|
|
2012-12-22 00:43:41 +00:00
|
|
|
$overlay.append( $overlayFooter );
|
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
callback( $overlay );
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2012-12-14 01:04:37 +00:00
|
|
|
// only need to mark as read if there is unread item
|
|
|
|
if ( unread.length > 0 ) {
|
|
|
|
Api.get( {
|
|
|
|
'action' : 'query',
|
|
|
|
'meta' : 'notifications',
|
|
|
|
'notmarkread' : unread.join( '|' ),
|
|
|
|
'notprop' : 'count'
|
|
|
|
}, {
|
|
|
|
'ok' : function( result ) {
|
|
|
|
if ( result.query.notifications.count !== undefined ) {
|
|
|
|
count = result.query.notifications.count;
|
|
|
|
mw.echo.overlay.updateCount( count );
|
|
|
|
}
|
2012-11-09 01:50:26 +00:00
|
|
|
}
|
2012-12-14 01:04:37 +00:00
|
|
|
} );
|
|
|
|
}
|
2012-06-01 10:57:09 +00:00
|
|
|
},
|
|
|
|
'err' : function() {
|
2013-01-03 19:59:42 +00:00
|
|
|
window.location.href = $link.attr( 'href' );
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2012-08-01 19:53:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mw.echo.overlay.notification_count = mw.echo.overlay.configuration['notification-count'];
|
|
|
|
|
|
|
|
$( function() {
|
|
|
|
mw.echo.overlay.updateCount( mw.echo.overlay.notification_count );
|
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
var $link = $( '#pt-notifications a' );
|
2012-08-01 19:53:05 +00:00
|
|
|
if ( ! $link.length ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
$link.click( function( e ) {
|
2012-06-01 10:57:09 +00:00
|
|
|
e.preventDefault();
|
2012-08-30 16:04:39 +00:00
|
|
|
var $target = $( e.target );
|
2012-08-01 19:42:06 +00:00
|
|
|
// If the user clicked on the overlay or any child,
|
|
|
|
// ignore the click
|
2012-08-30 16:04:39 +00:00
|
|
|
if ( $target.hasClass( 'mw-echo-overlay' ) ||
|
|
|
|
$target.is( 'mw-echo-overlay *' )
|
2012-08-01 19:42:06 +00:00
|
|
|
) {
|
2012-06-01 10:57:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
var $overlay = $( '.mw-echo-overlay' );
|
2012-06-01 10:57:09 +00:00
|
|
|
|
|
|
|
if ( $overlay.length ) {
|
|
|
|
$overlay.fadeOut( 'fast',
|
|
|
|
function() { $overlay.remove(); }
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-01 19:53:05 +00:00
|
|
|
$overlay = mw.echo.overlay.buildOverlay(
|
2012-08-30 16:04:39 +00:00
|
|
|
function( $overlay ) {
|
2012-06-01 10:57:09 +00:00
|
|
|
$overlay
|
|
|
|
.hide()
|
2013-01-10 04:13:08 +00:00
|
|
|
.appendTo( $( '#pt-notifications' ) );
|
|
|
|
// Create the pokey (aka chevron)
|
|
|
|
$( '.mw-echo-overlay' ).before( $( '<div/>' ).addClass( 'mw-echo-overlay-pokey' ) );
|
|
|
|
// Show the notifications overlay
|
|
|
|
$overlay.show();
|
2012-06-01 10:57:09 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
$( 'body' ).click( function( e ) {
|
2013-01-10 04:13:08 +00:00
|
|
|
if ( ! $( e.target ).is( '.mw-echo-overlay, .mw-echo-overlay *, .mw-echo-overlay-pokey' ) ) {
|
|
|
|
$( '.mw-echo-overlay, .mw-echo-overlay-pokey' ).fadeOut( 'fast',
|
2012-08-30 16:04:39 +00:00
|
|
|
function() { $( this ).remove(); }
|
2012-06-01 10:57:09 +00:00
|
|
|
);
|
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} )( jQuery, mediaWiki );
|