More languages
More actions
m (Restoring CSS to Citizen.css (it makes no difference)) |
m (Added more span to be configure through CSS) |
||
Line 132: | Line 132: | ||
}) | }) | ||
}(jQuery, mediaWiki)); | }(jQuery, mediaWiki)); | ||
/** | |||
* Adds icons for the Citizen skin toggle menu | |||
* | |||
**/ | |||
(function($, mw) { | (function($, mw) { | ||
var $ul = $('#p-Navigation').children()[1]; // This selects the <ul> list of elements | var $ul = $('#p-Navigation').children()[1]; // This selects the <ul> list of elements | ||
Line 138: | Line 143: | ||
var $span = $('<span>').text("") | var $span = $('<span>').text("") | ||
.addClass('citizen-ui-icon') | .addClass('citizen-ui-icon') | ||
if ($a.text == "Recruitment") { | if ($a.text == "Recruitment") { | ||
$span.addClass('prolewiki-ui-icon-recruitment') | |||
$a.prepend($span[0]); | |||
} else if ($a.text == "Wanted pages") { | |||
$span.addClass('prolewiki-ui-icon-wanted') | |||
$a.prepend($span[0]); | |||
} else if ($a.text == "Library") { | |||
$span.addClass('prolewiki-ui-icon-library') | |||
$a.prepend($span[0]); | $a.prepend($span[0]); | ||
} | } |
Revision as of 19:12, 17 June 2023
/* All JavaScript here will be loaded for users of the Citizen skin */
/**
* Recent changes sidebar gadget for the Citizen skin
* Originally created by @author JaydenKieran from RunescapeWiki
**/
"use strict";
(function($, mw) {
var $prependTo;
var $rcContainer;
var recentChanges;
var $recentChangesDOM;
var $final;
function init() {
$prependTo = $('#p-Navigation');
var api = new mw.Api();
$final = $('<ul>').after($rcContainer);
// Build our container
var $rcLabelSpan = $('<span>').text('Recent changes')
.addClass('citizen-menu__heading-label');
var $rcLabel = $('<label>')
.addClass('citizen-menu__heading')
.attr('id', 'p-RecentChanges-label')
.append($rcLabelSpan);
$rcContainer = $('<nav>')
.addClass('mw-portlet mw-portlet-RecentChanges')
.attr('id', 'p-RecentChanges')
.append($rcLabel)
.append($final);
// Add the container to the sidebar
$prependTo.after($rcContainer)
api.get({
action: "query",
list: "recentchanges",
rcprop: "title|timestamp|sizes|user",
rcnamespace: "0|3000",
rclimit: "5",
rctype: "edit|new",
rcshow: "!bot|!redirect",
rctoponly: 1,
format: "json"
})
.done(function(data) {
if (data.query && data.query.recentchanges) {
recentChanges = data.query.recentchanges
}
if (recentChanges.length > 0) {
var Time = 1;
$recentChangesDOM = recentChanges.map(function(rc) {
const timeMatch = rc.timestamp.match(/([0-9]+)-([0-9]+)-([0-9]+)T([0-9]+):([0-9]+):([0-9]+)Z/);
var editYear = timeMatch[1];
var editMonth = timeMatch[2];
var editDay = timeMatch[3];
var editHour = timeMatch[4];
var editMinute = timeMatch[5];
var editSecond = timeMatch[6];
var editDate = new Date(editYear, (editMonth-1), editDay, editHour, editMinute, editSecond);
var currentDate = new Date();
currentDate = currentDate.getTime() + (currentDate.getTimezoneOffset() * 60000)
var diffDate = currentDate - editDate;
var diffDays = Math.floor(diffDate/(1000*60*60*24));
var diffHours = Math.floor(diffDate/(1000*60*60));
var diffMinutes = Math.floor(diffDate/(1000*60));
var diffSeconds = Math.floor(diffDate/(1000));
if (diffDays > 0) {
Time = diffDays + 'd ago – ';
} else if (diffHours > 0) {
Time = diffHours + 'h ago – ';
} else if (diffMinutes > 0) {
Time = diffMinutes + 'm ago – ';
} else if (diffSeconds > 0) {
Time = diffSeconds + 's ago – ';
} else {
Time = 1 + Math.floor(Math.random() * 10) + 'm ago – ';
}
return $('<li>').addClass('mw-list-item').append(
$('<a>')
.css('white-space', 'normal')
.addClass('rc-sidebar-page')
.text(' ' + rc.title)
.attr('href', new mw.Title(rc.title).getUrl()),
$('<p>')
.css({
'text-align': 'right',
'margin-right': '2.5em'
})
.addClass('rc-sidebar-user')
.text(Time)
.append(
$('<a>')
.css({
'display' : '-webkit-inline-box',
'padding' : '0px'
})
.text(rc.user)
.attr('href', new mw.Title(rc.user, 2).getUrl())
)
)
})
} else {
$recentChangesDOM = $('<p>').text('No recent changes.')
}
$final.append($recentChangesDOM)
var $showMore
$showMore = $('<div>')
.addClass('rc-sidebar-item rc-sidebar-more')
.append(
$('<a>')
.addClass('rc-sidebar-page')
.text('See more...')
.attr('href', '/wiki/Special:RecentChanges')
)
$final.append($showMore)
})
.fail(function(_, data) {
alert(data.error.info)
});
}
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function() {
$(init)
})
}(jQuery, mediaWiki));
/**
* Adds icons for the Citizen skin toggle menu
*
**/
(function($, mw) {
var $ul = $('#p-Navigation').children()[1]; // This selects the <ul> list of elements
for (var i=0;i<$ul.children.length;i++) {
var $a = $ul.children[i].children[0];
var $span = $('<span>').text("")
.addClass('citizen-ui-icon')
if ($a.text == "Recruitment") {
$span.addClass('prolewiki-ui-icon-recruitment')
$a.prepend($span[0]);
} else if ($a.text == "Wanted pages") {
$span.addClass('prolewiki-ui-icon-wanted')
$a.prepend($span[0]);
} else if ($a.text == "Library") {
$span.addClass('prolewiki-ui-icon-library')
$a.prepend($span[0]);
}
}
}(jQuery, mediaWiki));
//</nowiki>