2012-06-01 10:57:09 +00:00
|
|
|
( function($,mw) {
|
|
|
|
$( function() {
|
|
|
|
var $link = $('#pt-notifications');
|
|
|
|
if ( ! $link.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildOverlay(callback) {
|
|
|
|
var $overlay = $('<div></div>')
|
|
|
|
.addClass('mw-echo-overlay');
|
|
|
|
|
2012-06-08 05:55:01 +00:00
|
|
|
$overlay.append(
|
2012-06-08 06:07:57 +00:00
|
|
|
$('<div/>')
|
|
|
|
.addClass('mw-echo-overlay-title')
|
2012-06-08 05:55:01 +00:00
|
|
|
.text(mw.msg('echo-overlay-title'))
|
|
|
|
);
|
|
|
|
|
2012-06-01 10:57:09 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-06-08 05:55:01 +00:00
|
|
|
if ( ! $ul.find('li').length ) {
|
2012-06-08 06:07:57 +00:00
|
|
|
$ul.remove();
|
|
|
|
$overlay.append(
|
|
|
|
$('<div></div>')
|
2012-06-08 05:55:01 +00:00
|
|
|
.text(mw.msg('echo-none'))
|
2012-06-08 06:07:57 +00:00
|
|
|
);
|
2012-06-08 05:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$overlay.append(
|
|
|
|
$('<div/>')
|
|
|
|
.addClass('mw-echo-overlay-link')
|
|
|
|
.append($('<a/>')
|
|
|
|
.attr('href', $('#pt-notifications a').attr('href'))
|
|
|
|
.text( mw.msg('echo-overlay-link') )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2012-06-01 10:57:09 +00:00
|
|
|
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 );
|