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
|
|
|
|
|
|
|
'notificationLimit' : 8,
|
|
|
|
|
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-08-30 16:04:39 +00:00
|
|
|
$( '#pt-notifications a' )
|
|
|
|
.text( mw.msg( 'echo-link' ) )
|
2012-11-09 01:50:26 +00:00
|
|
|
.badge( newCount, 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
|
|
|
|
2012-06-08 05:55:01 +00:00
|
|
|
$overlay.append(
|
2012-08-30 16:04:39 +00:00
|
|
|
$( '<div/>' )
|
|
|
|
.addClass( 'mw-echo-overlay-title' )
|
|
|
|
.text( mw.msg( 'echo-overlay-title' ) )
|
2012-06-08 05:55:01 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 22:07:53 +00:00
|
|
|
$overlay.css( 'max-height', $( window ).height() * 0.75 );
|
|
|
|
|
2012-06-01 10:57:09 +00:00
|
|
|
var Api = new mw.Api();
|
|
|
|
|
|
|
|
Api.get( {
|
|
|
|
'action' : 'query',
|
|
|
|
'meta' : 'notifications',
|
|
|
|
'notformat' : 'html',
|
2012-12-10 05:01:00 +00:00
|
|
|
'notlimit' : mw.echo.overlay.notificationLimit,
|
2012-06-01 10:57:09 +00:00
|
|
|
'notprop' : 'index|list'
|
|
|
|
}, {
|
2012-08-30 16:04:39 +00:00
|
|
|
'ok' : function( result ) {
|
2012-09-26 05:09:43 +00:00
|
|
|
var notifications = result.query.notifications,
|
2012-12-10 05:01:00 +00:00
|
|
|
$ul = $( '<ul class="mw-echo-notifications"></ul>' ).appendTo( $overlay );
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
$.each( notifications.index, function( index, id ) {
|
2012-12-07 01:08:33 +00:00
|
|
|
var data = notifications['list'][id];
|
|
|
|
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-06-01 10:57:09 +00:00
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
} );
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
if ( ! $ul.find( 'li' ).length ) {
|
2012-06-08 06:07:57 +00:00
|
|
|
$ul.remove();
|
|
|
|
$overlay.append(
|
2012-08-30 16:04:39 +00:00
|
|
|
$( '<div></div>' )
|
2012-08-01 19:53:05 +00:00
|
|
|
.addClass( 'mw-echo-overlay-none' )
|
2012-08-30 16:04:39 +00:00
|
|
|
.text( mw.msg( 'echo-none' ) )
|
2012-06-08 06:07:57 +00:00
|
|
|
);
|
2012-06-08 05:55:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-14 19:20:11 +00:00
|
|
|
// only show 'All notifications...' link if there is notification
|
|
|
|
if ( notifications.index.length > 0 ) {
|
|
|
|
$overlay.append(
|
|
|
|
$( '<div/>' )
|
|
|
|
.addClass( 'mw-echo-overlay-link' )
|
|
|
|
.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
|
|
|
|
$overlay.append(
|
|
|
|
$( '<div/>' )
|
|
|
|
.addClass( 'mw-echo-overlay-pref-link' )
|
|
|
|
.append( $prefLink
|
|
|
|
.clone()
|
|
|
|
.attr( 'href', $prefLink.attr( 'href' ) + '#mw-prefsection-echo' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
callback( $overlay );
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
Api.get( {
|
2012-06-01 10:57:09 +00:00
|
|
|
'action' : 'query',
|
|
|
|
'meta' : 'notifications',
|
2012-08-30 16:04:39 +00:00
|
|
|
'notmarkread' : notifications.index.join( '|' ),
|
2012-06-01 10:57:09 +00:00
|
|
|
'notprop' : 'count'
|
|
|
|
}, {
|
2012-08-30 16:04:39 +00:00
|
|
|
'ok' : function( result ) {
|
2012-11-09 01:50:26 +00:00
|
|
|
if ( result.query.notifications.count !== undefined ) {
|
|
|
|
count = result.query.notifications.count;
|
|
|
|
mw.echo.overlay.updateCount( count );
|
|
|
|
}
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
} );
|
2012-06-01 10:57:09 +00:00
|
|
|
},
|
|
|
|
'err' : function() {
|
2012-08-30 16:04:39 +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-08-30 16:04:39 +00:00
|
|
|
.appendTo( $( 'body' ) )
|
|
|
|
.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 );
|