mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-29 01:54:33 +00:00
5c841cafe3
Change-Id: I1a350e5d051bd0e776e5043f0ba189a576ac7ee7 TODO: Add date/time stamp to notifications as shown in overlay
98 lines
2.1 KiB
JavaScript
98 lines
2.1 KiB
JavaScript
( function($,mw) {
|
|
$( function() {
|
|
var $link = $('#pt-notifications');
|
|
if ( ! $link.length ) {
|
|
return;
|
|
}
|
|
|
|
function buildOverlay(callback) {
|
|
var $overlay = $('<div></div>')
|
|
.addClass('mw-echo-overlay');
|
|
|
|
var Api = new mw.Api();
|
|
|
|
Api.get( {
|
|
'action' : 'query',
|
|
'meta' : 'notifications',
|
|
'notformat' : 'html',
|
|
'notprop' : 'index|list'
|
|
}, {
|
|
'ok' : function(result) {
|
|
var notifications = result.query.notifications;
|
|
var $ul = $('<ul></ul>').appendTo($overlay);
|
|
|
|
$.each( notifications.index, function(index, id) {
|
|
data = notifications[id];
|
|
var $li = $('<li></li>')
|
|
.data('details', data)
|
|
.data('id', id)
|
|
.addClass('mw-echo-notification')
|
|
.append(data['*'])
|
|
.appendTo($ul);
|
|
|
|
if (! data.read ) {
|
|
$li.addClass('mw-echo-unread');
|
|
}
|
|
});
|
|
|
|
callback($overlay);
|
|
|
|
Api.get({
|
|
'action' : 'query',
|
|
'meta' : 'notifications',
|
|
'notmarkread' : notifications.index.join('|'),
|
|
'notprop' : 'count'
|
|
}, {
|
|
'ok' : function(result) {
|
|
var count = result.query.notifications.count;
|
|
|
|
var newText;
|
|
if ( count > 0 ) {
|
|
newText = mw.msg('echo-link-new', count);
|
|
} else {
|
|
newText = mw.msg('echo-link-none');
|
|
}
|
|
$('#pt-notifications a').text(newText);
|
|
}
|
|
});
|
|
},
|
|
'err' : function() {
|
|
window.location.href = $('#pt-notifications a').attr('href');
|
|
}
|
|
} );
|
|
}
|
|
|
|
$link.click( function(e) {
|
|
e.preventDefault();
|
|
|
|
if ($(e.target).is('.mw-echo-overlay,.mw-echo-overlay *') ) {
|
|
return;
|
|
}
|
|
|
|
var $overlay = $('.mw-echo-overlay');
|
|
|
|
if ( $overlay.length ) {
|
|
$overlay.fadeOut( 'fast',
|
|
function() { $overlay.remove(); }
|
|
);
|
|
return;
|
|
}
|
|
|
|
$overlay = buildOverlay(
|
|
function($overlay) {
|
|
$overlay
|
|
.hide()
|
|
.appendTo($('body'))
|
|
.slideDown('fast');
|
|
} );
|
|
} );
|
|
|
|
$('body').click( function(e) {
|
|
if ( ! $(e.target).is('#pt-notifications *') ) {
|
|
$('.mw-echo-overlay').fadeOut( 'fast',
|
|
function() { $(this).remove(); }
|
|
);
|
|
}
|
|
});
|
|
});
|
|
})( jQuery, mediaWiki ); |