2013-06-18 15:23:35 +00:00
|
|
|
( function ( $, mw ) {
|
2012-12-07 01:08:33 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
mw.echo.special = {
|
|
|
|
|
2013-06-12 00:44:01 +00:00
|
|
|
notcontinue: null,
|
|
|
|
header: '',
|
|
|
|
processing: false,
|
2013-01-14 23:52:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the property in special notification page.
|
2012-12-07 01:08:33 +00:00
|
|
|
*/
|
2013-06-18 15:23:35 +00:00
|
|
|
initialize: function () {
|
2013-06-12 01:01:41 +00:00
|
|
|
var skin = mw.config.get('skin');
|
2013-06-02 20:04:29 +00:00
|
|
|
|
2013-04-09 22:38:36 +00:00
|
|
|
// Convert more link into a button
|
|
|
|
$( '#mw-echo-more' )
|
|
|
|
.button()
|
|
|
|
// Override jQuery UI button margins
|
|
|
|
.css( 'margin', '0.5em 0 0 0' )
|
|
|
|
.addClass( 'ui-button-blue' )
|
2013-06-18 15:23:35 +00:00
|
|
|
.click( function ( e ) {
|
2012-12-07 01:08:33 +00:00
|
|
|
e.preventDefault();
|
2013-06-12 01:01:41 +00:00
|
|
|
if ( !mw.echo.special.processing ) {
|
|
|
|
mw.echo.special.processing = true;
|
|
|
|
mw.echo.special.loadMore();
|
2012-12-15 01:44:07 +00:00
|
|
|
}
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
|
|
|
);
|
2013-06-12 01:01:41 +00:00
|
|
|
mw.echo.special.notcontinue = mw.config.get( 'wgEchoNextContinue' );
|
|
|
|
mw.echo.special.header = mw.config.get( 'wgEchoDateHeader' );
|
2013-01-04 21:56:30 +00:00
|
|
|
|
2013-06-05 20:44:06 +00:00
|
|
|
// Set up each individual notification with eventlogging, a close
|
|
|
|
// box and dismiss interface if it is dismissable.
|
2013-06-18 15:23:35 +00:00
|
|
|
$( '.mw-echo-notification' ).each( function () {
|
2013-06-05 20:44:06 +00:00
|
|
|
mw.echo.setupNotificationLogging( $( this ), 'archive' );
|
2013-01-14 23:52:46 +00:00
|
|
|
if ( $( this ).find( '.mw-echo-dismiss' ).length ) {
|
2013-02-13 02:08:36 +00:00
|
|
|
mw.echo.setUpDismissability( this );
|
2013-01-14 23:52:46 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2013-06-18 15:23:35 +00:00
|
|
|
$( '#mw-echo-moreinfo-link' ).click( function () {
|
2013-06-05 20:44:06 +00:00
|
|
|
mw.echo.logInteraction( 'ui-help-click', 'archive' );
|
|
|
|
} );
|
2013-06-18 15:23:35 +00:00
|
|
|
$( '#mw-echo-pref-link' ).click( function () {
|
2013-06-05 20:44:06 +00:00
|
|
|
mw.echo.logInteraction( 'ui-prefs-click', 'archive' );
|
|
|
|
} );
|
|
|
|
|
2013-06-02 20:04:29 +00:00
|
|
|
// Apply custom header styling for vector and monobook skins
|
|
|
|
if ( skin === 'vector' || skin === 'monobook' ) {
|
|
|
|
$( '#firstHeading' )
|
|
|
|
.css( { 'max-width': '555px', 'margin-left': '50px' } );
|
|
|
|
$( '#mw-echo-moreinfo-link' )
|
|
|
|
.text( '' )
|
|
|
|
.appendTo( '#firstHeading' );
|
|
|
|
$( '#mw-echo-pref-link' )
|
|
|
|
.text( '' )
|
|
|
|
.appendTo( '#firstHeading' );
|
|
|
|
$( '#contentSub' ).empty();
|
|
|
|
}
|
2013-04-12 18:52:34 +00:00
|
|
|
|
2012-12-07 01:08:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-01-14 23:52:46 +00:00
|
|
|
* Load more notification records.
|
2012-12-07 01:08:33 +00:00
|
|
|
*/
|
2013-06-18 15:23:35 +00:00
|
|
|
loadMore: function () {
|
|
|
|
var api = new mw.Api(), notifications, data, container, $li, that = this, unread = [];
|
|
|
|
|
|
|
|
api.get( {
|
|
|
|
'action' : 'query',
|
|
|
|
'meta' : 'notifications',
|
|
|
|
'notformat' : 'html',
|
|
|
|
'notprop' : 'index|list',
|
|
|
|
'notcontinue': this.notcontinue,
|
|
|
|
'notlimit': mw.config.get( 'wgEchoDisplayNum' )
|
|
|
|
} ).done( function ( result ) {
|
|
|
|
container = $( '#mw-echo-special-container' );
|
|
|
|
notifications = result.query.notifications;
|
|
|
|
unread = [];
|
|
|
|
|
|
|
|
$.each( notifications.index, function ( index, id ) {
|
|
|
|
data = notifications.list[id];
|
|
|
|
|
|
|
|
if ( that.header !== data.timestamp.date ) {
|
|
|
|
that.header = data.timestamp.date;
|
|
|
|
$( '<li></li>' ).addClass( 'mw-echo-date-section' ).append( that.header ).appendTo( container );
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
2013-06-18 15:23:35 +00:00
|
|
|
|
|
|
|
$li = $( '<li></li>' )
|
|
|
|
.data( 'details', data )
|
|
|
|
.data( 'id', id )
|
|
|
|
.addClass( 'mw-echo-notification' )
|
|
|
|
.attr( {
|
|
|
|
'data-notification-category': data.category,
|
|
|
|
'data-notification-event': data.id,
|
|
|
|
'data-notification-type': data.type
|
|
|
|
} )
|
|
|
|
.append( data['*'] )
|
|
|
|
.appendTo( container );
|
|
|
|
|
|
|
|
if ( !data.read ) {
|
|
|
|
$li.addClass( 'mw-echo-unread' );
|
|
|
|
unread.push( id );
|
|
|
|
}
|
|
|
|
|
|
|
|
mw.echo.setupNotificationLogging( $li, 'archive' );
|
|
|
|
|
|
|
|
if ( $li.find( '.mw-echo-dismiss' ).length ) {
|
|
|
|
mw.echo.setUpDismissability( $li );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
that.notcontinue = notifications['continue'];
|
|
|
|
if ( unread.length > 0 ) {
|
|
|
|
that.markAsRead( unread );
|
|
|
|
} else {
|
|
|
|
that.onSuccess();
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
2013-06-18 15:23:35 +00:00
|
|
|
} ).fail( function () {
|
|
|
|
that.onError();
|
|
|
|
} );
|
2012-12-15 01:44:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-01-14 23:52:46 +00:00
|
|
|
* Mark notifications as read.
|
2012-12-15 01:44:07 +00:00
|
|
|
*/
|
2013-06-18 15:23:35 +00:00
|
|
|
markAsRead: function ( unread ) {
|
|
|
|
var api = new mw.Api(), that = this;
|
2012-12-15 01:44:07 +00:00
|
|
|
|
|
|
|
api.get( {
|
|
|
|
'action' : 'query',
|
|
|
|
'meta' : 'notifications',
|
|
|
|
'notmarkread' : unread.join( '|' ),
|
|
|
|
'notprop' : 'count'
|
2013-06-18 15:23:35 +00:00
|
|
|
} ).done( function ( result ) {
|
|
|
|
// update the badge if the link is enabled
|
|
|
|
if ( result.query.notifications.count !== undefined &&
|
|
|
|
$( '#pt-notifications').length && typeof mw.echo.overlay === 'object'
|
|
|
|
) {
|
|
|
|
mw.echo.overlay.updateCount( result.query.notifications.count );
|
2012-12-15 01:44:07 +00:00
|
|
|
}
|
2013-06-18 15:23:35 +00:00
|
|
|
that.onSuccess();
|
|
|
|
} ).fail( function () {
|
|
|
|
that.onError();
|
2012-12-15 01:44:07 +00:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2013-06-18 15:23:35 +00:00
|
|
|
onSuccess: function () {
|
2013-05-03 23:58:56 +00:00
|
|
|
if ( !this.notcontinue ) {
|
2012-12-15 01:44:07 +00:00
|
|
|
$( '#mw-echo-more' ).hide();
|
|
|
|
}
|
|
|
|
this.processing = false;
|
|
|
|
},
|
|
|
|
|
2013-06-18 15:23:35 +00:00
|
|
|
onError: function () {
|
2012-12-15 01:44:07 +00:00
|
|
|
// Todo: Show detail error message based on error code
|
|
|
|
$( '#mw-echo-more' ).text( mw.msg( 'echo-load-more-error' ) );
|
|
|
|
this.processing = false;
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-11 20:01:23 +00:00
|
|
|
$( document ).ready( mw.echo.special.initialize );
|
2012-12-07 01:08:33 +00:00
|
|
|
|
|
|
|
} )( jQuery, mediaWiki );
|