User:Monster Domosed/common.js: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 30: | Line 30: | ||
function renderWidget($root, items) { | function renderWidget($root, items) { | ||
var $ | var $list = $('<ul class="vector-menu-content-list recent-changes-list"></ul>'); | ||
items.forEach(function (item) { | items.forEach(function (item, index) { | ||
var | var id = 'n-change' + (index + 1); | ||
var $ | var $li = $('<li class="mw-list-item recent-changes-item"></li>') | ||
.attr('id', id); | |||
var $link = $('<a class="recent-changes-link"></a>') | |||
.attr('href', mw.util.getUrl(item.title)) | .attr('href', mw.util.getUrl(item.title)) | ||
. | .attr( | ||
'title', | |||
(item.user || 'Unknown') + ' • ' + formatRelativeTime(item.timestamp) | |||
); | |||
$link.append( | |||
$('<span></span>').text(item.title) | |||
); | |||
$li.append($ | $li.append($link); | ||
$list.append($li); | $list.append($li); | ||
}); | }); | ||
var $ | // Add "Show more..." as the last item in the same list | ||
var $moreLi = $('<li class="mw-list-item recent-changes-item"></li>') | |||
.attr('id', 'n-change-more'); | |||
var $ | var $moreLink = $('<a class="recent-changes-link"></a>') | ||
.attr('href', mw.util.getUrl('Special:RecentChanges')) | .attr('href', mw.util.getUrl('Special:RecentChanges')) | ||
.text('Show more...'); | .attr('title', 'View full recent changes') | ||
.append($('<span></span>').text('Show more...')); | |||
$ | $moreLi.append($moreLink); | ||
$list.append($moreLi); | |||
$root.empty().append($list); | |||
$root.empty().append($ | |||
} | } | ||
function loadRecentEdits($root) { | function loadRecentEdits($root) { | ||
var limit = parseInt($root.data('limit'), 10) || | var limit = parseInt($root.data('limit'), 10) || 5; | ||
return new mw.Api().get({ | return new mw.Api().get({ | ||
| Line 98: | Line 90: | ||
function () { | function () { | ||
$root.html( | $root.html( | ||
'<div class="recent- | '<div class="recent-changes-error">Could not load recent changes.</div>' | ||
); | ); | ||
} | } | ||
| Line 108: | Line 100: | ||
$root.html( | $root.html( | ||
'<div class="recent- | '<div class="recent-changes-loading">Loading recent changes…</div>' | ||
); | ); | ||
| Line 120: | Line 112: | ||
function injectSidebarWidget() { | function injectSidebarWidget() { | ||
if ($('#p-recent- | if ($('#p-recent-changes').length) { | ||
return $('#p-recent- | return $('#p-recent-changes .recent-changes-widget'); | ||
} | } | ||
var $portlet = $( | var $portlet = $( | ||
'<nav id="p-recent- | '<nav id="p-recent-changes" class="mw-portlet mw-portlet-recent-changes vector-menu-portal portal vector-menu" aria-labelledby="p-recent-changes-label">' + | ||
'<h3 id="p-recent- | '<h3 id="p-recent-changes-label" class="vector-menu-heading">' + | ||
'<span class="vector-menu-heading-label">Recent Changes</span>' + | '<span class="vector-menu-heading-label">Recent Changes</span>' + | ||
'</h3>' + | '</h3>' + | ||
'<div class="vector-menu-content">' + | '<div class="vector-menu-content">' + | ||
'<div class="recent- | '<div class="recent-changes-widget" data-limit="5" data-refresh="300000"></div>' + | ||
'</div>' + | '</div>' + | ||
'</nav>' | '</nav>' | ||
); | ); | ||
// Insert where you want in the sidebar | |||
if ($('#p-Community').length) { | if ($('#p-Community').length) { | ||
$('#p-Community').after($portlet); | $('#p-Community').after($portlet); | ||
| Line 143: | Line 136: | ||
} | } | ||
return $portlet.find('.recent- | return $portlet.find('.recent-changes-widget'); | ||
} | } | ||
$(function () { | $(function () { | ||
var $widget = $('.recent- | var $widget = $('.recent-changes-widget'); | ||
if (!$widget.length) { | if (!$widget.length) { | ||