mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-01 02:46:46 +00:00
c638d44190
This provides some rudimentary styling support to make Echo usable with the Modern skin. It also fixes the Notifications special page so it is styled correctly in Modern, CologneBlue, or with Javascript turned off. Also some more tweaks for Monobook skin. Retiring the 'feedback' link from the special page, per PM. Bug: 47932 Change-Id: I633a93a78f5a78d0642a3a059fa6f7208f99cec4
162 lines
4 KiB
JavaScript
162 lines
4 KiB
JavaScript
( function( $, mw ) {
|
|
'use strict';
|
|
|
|
mw.echo.special = {
|
|
|
|
'notcontinue': null,
|
|
'header': '',
|
|
'processing': false,
|
|
|
|
/**
|
|
* Initialize the property in special notification page.
|
|
*/
|
|
'initialize': function() {
|
|
var _this = this,
|
|
skin = mw.config.get('skin');
|
|
|
|
// 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' )
|
|
.click( function( e ) {
|
|
e.preventDefault();
|
|
if ( !_this.processing ) {
|
|
_this.processing = true;
|
|
_this.loadMore();
|
|
}
|
|
}
|
|
);
|
|
_this.notcontinue = mw.config.get( 'wgEchoNextContinue' );
|
|
_this.header = mw.config.get( 'wgEchoDateHeader' );
|
|
|
|
// Set up each individual notification with a close box and dismiss
|
|
// interface if it is dismissable.
|
|
$( '.mw-echo-notification' ).each( function() {
|
|
if ( $( this ).find( '.mw-echo-dismiss' ).length ) {
|
|
mw.echo.setUpDismissability( this );
|
|
}
|
|
} );
|
|
|
|
// 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();
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
* Load more notification records.
|
|
*/
|
|
'loadMore': function() {
|
|
var api = new mw.Api(), notifications, data, container, $li, _this = this, unread = [];
|
|
|
|
api.get(
|
|
{
|
|
'action' : 'query',
|
|
'meta' : 'notifications',
|
|
'notformat' : 'html',
|
|
'notprop' : 'index|list',
|
|
'notcontinue': this.notcontinue,
|
|
'notlimit': mw.config.get( 'wgEchoDisplayNum' )
|
|
},
|
|
{
|
|
'ok' : function( result ) {
|
|
container = $( '#mw-echo-special-container' );
|
|
notifications = result.query.notifications;
|
|
unread = [];
|
|
|
|
$.each( notifications.index, function( index, id ) {
|
|
data = notifications.list[id];
|
|
|
|
if ( _this.header !== data.timestamp.date ) {
|
|
_this.header = data.timestamp.date;
|
|
$( '<li></li>' ).addClass( 'mw-echo-date-section' ).append( _this.header ).appendTo( container );
|
|
}
|
|
|
|
$li = $( '<li></li>' )
|
|
.data( 'details', data )
|
|
.data( 'id', id )
|
|
.addClass( 'mw-echo-notification' )
|
|
.attr( 'data-notification-category', data.category )
|
|
.append( data['*'] )
|
|
.appendTo( container );
|
|
|
|
if ( !data.read ) {
|
|
$li.addClass( 'mw-echo-unread' );
|
|
unread.push( id );
|
|
}
|
|
|
|
if ( $li.find( '.mw-echo-dismiss' ).length ) {
|
|
mw.echo.setUpDismissability( $li );
|
|
}
|
|
} );
|
|
|
|
_this.notcontinue = notifications['continue'];
|
|
if ( unread.length > 0 ) {
|
|
_this.markAsRead( unread );
|
|
} else {
|
|
_this.onSuccess();
|
|
}
|
|
},
|
|
'err' : function() {
|
|
_this.onError();
|
|
}
|
|
}
|
|
);
|
|
},
|
|
|
|
/**
|
|
* Mark notifications as read.
|
|
*/
|
|
'markAsRead': function( unread ) {
|
|
var api = new mw.Api(), _this = this;
|
|
|
|
api.get( {
|
|
'action' : 'query',
|
|
'meta' : 'notifications',
|
|
'notmarkread' : unread.join( '|' ),
|
|
'notprop' : 'count'
|
|
}, {
|
|
'ok' : function( result ) {
|
|
// update the badge if the link is enabled
|
|
if ( typeof result.query.notifications.count !== 'undefined' &&
|
|
$( '#pt-notifications').length && typeof mw.echo.overlay === 'object'
|
|
) {
|
|
mw.echo.overlay.updateCount( result.query.notifications.count );
|
|
}
|
|
_this.onSuccess();
|
|
},
|
|
'err': function() {
|
|
_this.onError();
|
|
}
|
|
} );
|
|
},
|
|
|
|
'onSuccess': function() {
|
|
if ( !this.notcontinue ) {
|
|
$( '#mw-echo-more' ).hide();
|
|
}
|
|
this.processing = false;
|
|
},
|
|
|
|
'onError': function() {
|
|
// Todo: Show detail error message based on error code
|
|
$( '#mw-echo-more' ).text( mw.msg( 'echo-load-more-error' ) );
|
|
this.processing = false;
|
|
}
|
|
};
|
|
|
|
mw.echo.special.initialize();
|
|
|
|
} )( jQuery, mediaWiki );
|