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'] ) {
|
|
|
|
$( '#pt-notifications a' )
|
|
|
|
.text( mw.msg( 'echo-link' ) )
|
|
|
|
.badge( newCount, true, true );
|
|
|
|
} else {
|
|
|
|
$( '#pt-notifications a' )
|
|
|
|
.text( '' )
|
|
|
|
.badge( newCount, true, true );
|
|
|
|
$( '#pt-notifications .mw-badge' ).css( 'margin-left', '-5px' );
|
|
|
|
}
|
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
|
|
|
|
var notificationLimit = Math.floor( ( $( window ).height() - 134 ) / 85 );
|
|
|
|
|
|
|
|
if ( notificationLimit < 1 ) {
|
|
|
|
notificationLimit = 1;
|
|
|
|
}
|
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-01-03 19:59:42 +00:00
|
|
|
$ul.css( 'max-height', notificationLimit * 85 + '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 )
|
|
|
|
.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
|
|
|
}
|
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
|
|
|
}
|
2012-12-27 16:50:00 +00:00
|
|
|
$title.html( $( '<a/>' ).attr( 'href', mw.util.wikiGetlink( 'Special:Notifications' ) ).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' );
|
|
|
|
|
2012-11-14 19:20:11 +00:00
|
|
|
// only show 'All notifications...' link if there is notification
|
|
|
|
if ( notifications.index.length > 0 ) {
|
2012-12-22 00:43:41 +00:00
|
|
|
$overlayFooter.append(
|
2012-11-14 19:20:11 +00:00
|
|
|
$( '<div/>' )
|
2012-12-17 21:58:18 +00:00
|
|
|
.attr( 'id', 'mw-echo-overlay-link' )
|
2012-11-14 19:20:11 +00:00
|
|
|
.append( $link
|
|
|
|
.clone()
|
|
|
|
.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(
|
2012-12-10 05:01:00 +00:00
|
|
|
$( '<div/>' )
|
2012-12-17 21:58:18 +00:00
|
|
|
.attr( 'id', 'mw-echo-overlay-pref-link' )
|
2012-12-10 05:01:00 +00:00
|
|
|
.append( $prefLink
|
|
|
|
.clone()
|
|
|
|
.attr( 'href', $prefLink.attr( 'href' ) + '#mw-prefsection-echo' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
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()
|
2012-12-17 21:58:18 +00:00
|
|
|
.appendTo( $( 'body' ) );
|
|
|
|
// Figure out which footer link is first and pad it appropriately
|
|
|
|
// (Sometimes the 'All notifications' link doesn't exist)
|
|
|
|
if ( $( '#mw-echo-overlay-link' ).length ) {
|
|
|
|
$( '#mw-echo-overlay-link' )
|
|
|
|
.addClass( 'mw-echo-overlay-first-footer-link' );
|
|
|
|
} else {
|
|
|
|
$( '#mw-echo-overlay-pref-link' )
|
|
|
|
.addClass( 'mw-echo-overlay-first-footer-link' );
|
|
|
|
}
|
|
|
|
$overlay.slideDown( 'fast' );
|
2012-06-01 10:57:09 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
$( 'body' ).click( function( e ) {
|
|
|
|
if ( ! $( e.target ).is( '.mw-echo-overlay,.mw-echo-overlay *' ) ) {
|
|
|
|
$( '.mw-echo-overlay' ).fadeOut( 'fast',
|
|
|
|
function() { $( this ).remove(); }
|
2012-06-01 10:57:09 +00:00
|
|
|
);
|
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} )( jQuery, mediaWiki );
|