MediaWiki:Common.js: Difference between revisions
Re-format JS
LeTrashman (talk | contribs) No edit summary Tag: Reverted |
LeTrashman (talk | contribs) (Re-format JS) Tag: Reverted |
||
Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
}▼
// This hack is required to get custom css to load in mobile view. See https://phabricator.wikimedia.org/T270845
loadMobileStylesheet();
}
function initCountdown() {
var reset = new Date();
reset.setUTCHours(19, 0, 0, 0);
function pad(n) {
return ("0" + (n | 0)).slice(-2);
Line 20 ⟶ 22:
var now = new Date();
if (now > reset) {
reset.setUTCDate(reset.getUTCDate() + 1);
}
var remaining = ((reset - now) /
var hours = (remaining / 3600) % 60;
var minutes = (remaining / 60) % 60;
Line 32 ⟶ 34:
tick();
}
function initCharacterTable() {
mw.loader.using("jquery.tablesorter", function () {
$("table.sortable").tablesorter({ sortList: [{ 2: "desc" }, { 1: "asc" }] });
});
}
function loadMobileStylesheet() {
var common = document.createElement("link");
common.rel = mobile.rel = "stylesheet";
common.type = mobile.type = "text/css";
common.href = "https://bluearchive.miraheze.org/w/load.php?lang=en&modules=site.styles&only=styles&skin=minerva";
head.appendChild(common);
head.appendChild(mobile);
}
if (mw.config.get("wgIsArticle")) {
}
/* Character stat calc*/
mw.loader.load(
/* Character birthdays - start */
function initBirthdays() {
const separator = ' <span></span> ';
const months = [
Line 86 ⟶ 91:
var raw_data = $('#character-birthdays').attr('data-birthdays').split('&');
raw_data.forEach(function (character) {
var char_data = character.split(' |');
char_data.push(char_data[0].split('(')[0].trim()); //normalized name
if (!birthdays.some(function (data) { return data[2] == char_data[2]; })) birthdays.push(char_data);
});
Line 96 ⟶ 101:
var date = new Date();
date.setDate(date.getDate() + index);
data_out = data_out.concat(birthdays.filter(function (data) { return data[1] == months[date.getMonth()] + ' ' + date.getDate(); }));
if (data_out.length >= 5) { break; }
Line 102 ⟶ 107:
data_out.forEach(
function (character) { html_out += '<a href="/wiki/' + character[0] + '">' + character[2] + ' (' + character[1].replace(' ', ' ') + ')</a>' + separator; }
);
$('#character-birthdays').append(html_out.substring(0, html_out.length - separator.length)).css(
}
/* Character birthdays - end */
Line 113 ⟶ 118:
const affection_start = 50;
const affection_cap = 50;
var affection_data = {};
var affectionTableCounter = 0;
$(
initAffectionTable();
$(".affection-level input").on("change mouseup keyup click", function () { affectionChange($(this).closest("table"), $(this).val()); });
$(".affection-data").children("div").on("click", function () { affectionChange($(this).closest("table"), $(this).attr('data-level')); });
});
function initAffectionTable() {
$(".character-affectiontable").each(function () {
$(this).attr('id', id);
var data = {};
$(this).find(".affection-data > div").each(function () {
var level = $(this).attr('data-level');
data[level] = {};
var bonus = $(this).attr('data-stats').split(' ');
$.each(
bonus[index] = bonus[index].split('+');
data[level][bonus[index][0]] =
});
});
affection_data[id] = data;
$(this).find(".affection-level").html('<input type="number" value="' + affection_start + '" step="1" min="1" max="' + affection_cap + '" />');
affectionChange($(this), affection_start);
if (typeof affection !== 'undefined') {
Line 153 ⟶ 158:
});
}
function affectionChange
var effective_bonus = {};
var html_out = '';
level = (typeof level !== 'undefined' && !isNaN(level)) ? level : 1
if (level < 1)
if (level > affection_cap)
for (var index = 2; index <= level; index++) {
$.each(
if (typeof effective_bonus[stat_name] == 'undefined') effective_bonus[stat_name] = 0;
effective_bonus[stat_name] += stat_value;
});
}
$.each(
html_out += '<b>' + stat_name + '</b>' + ' +' + stat_value + ', ';
});
Line 178 ⟶ 183:
if (affectionTable.find(".affection-level input").val() !== level) affectionTable.find(".affection-level input").val(level);
affectionTable.find(".affection-total").html(html_out.substring(0, html_out.length - 2));
//update StatCalc if present
Line 190 ⟶ 195:
/* Character voice preview - start */
$(
initCharacterVoice();
});
function initCharacterVoice() {
var voice = $(".character td.character-voice");
if (voice.length && voice.attr('data-voice').length) {
voice.wrapInner('<span>');
if (voice.find("span").width() > voice.width() -
voice.find("span").children().unwrap();
voice.append('<audio class="voice-clip" src="' + voice.attr('data-voice') + '"></audio>').addClass('character-voice-preview');
voice.find('audio')[0].volume = 0.6;
$(".character td.character-voice-preview").on("click", function () { voice.find('audio')[0].play(); })
}
}
|