MediaWiki:Common.js: Difference between revisions

Disabled Minerva-specific styles workaround
No edit summary
Tag: Reverted
(Disabled Minerva-specific styles workaround)
 
(31 intermediate revisions by 2 users not shown)
Line 5:
window.location.replace("https://bluearchive.wiki" + window.location.pathname);
}
// Common styles are currently loaded through an @import statement in MediaWiki:Mobile.css. I do not know what calls mw.loader.using('mobile.site.styles') currently, but it appears to happen. This code is preserved in case something breaks after caches expire.
if (mw.config.get("skin") === "minerva") {
// if (mw.config.get("skin") === "minerva") {
// This hack is required to get custom css to load in mobile view. See https://phabricator.wikimedia.org/T270845
// // This hack is required to get custom css to load in mobile view. See https://phabricator.wikimedia.org/T270845
loadMobileStylesheet();
// loadMobileStylesheet();
}
// }
function initCountdown() {
var reset = new Date();
Line 54 ⟶ 55:
initBirthdays();
}
if (mw.config.get("wgPageName") === "Characters") {
initCharacterTable();
}
if (mw.config.get("wgPageName") === "Characters" || mw.config.get("wgPageName") === "Characters_StatChart") {
}
mw.loader.load( '/w/index.php?title=MediaWiki:CharacterTable.js&action=raw&ctype=text/javascript' );
}
/* Character stat calc*/
if (mw.config.get("wgPageName") === "An_Unconcealed_Heart/Mitcher") {
mw.loader.load( '/w/index.php?title=MediaWiki:StatCalc.js&action=raw&ctype=text/javascript' );
mw.loader.load( '/w/index.php?title=MediaWiki:Mitcher.js&action=raw&ctype=text/javascript' );
}
if (mw.config.get("wgPageName") === "A_Game_Before_the_New_Year's_Feast_~_One-and-Done_Match_~/Junby") {
mw.loader.load( '/w/index.php?title=MediaWiki:Junby.js&action=raw&ctype=text/javascript' );
}
 
const title_split = mw.config.get('wgTitle').toLowerCase().split("/");
if (mw.config.get('wgNamespaceNumber') === 0 && title_split.length === 2 && title_split[1] === 'momotalk') {
mw.loader.load( '/w/index.php?title=MediaWiki:MomotalkChoice.js&action=raw&ctype=text/javascript' );
}
 
}
/* Character birthdays - start */
});
function initBirthdays(){
const separator = ' <span></span> ';
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
 
var birthdays = [];
var data_out = [];
var html_out = '';
 
/* Character stat calc & affection table */
var raw_data = $('#character-birthdays').attr('data-birthdays').split('&');
mw.loader.load( '/w/index.php?title=MediaWiki:StatCalc.js&action=raw&ctype=text/javascript' );
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);
});
 
for (var index = -1; index <= 30; index++) {
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();}));
 
/* Character birthdays - start */
if (data_out.length >= 5) { break; }
function initBirthdays(){
}
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
 
var birthdays = [];
data_out.forEach(
var data_out = [];
function (character) { html_out += '<a href="/wiki/'+character[0]+'">'+character[2]+'&nbsp;('+character[1].replace(' ', '&nbsp;')+')</a>'+separator; }
var html_out = '';
);
 
var raw_data = $('#character-birthdays').appendattr(html_out.substring(0,html_out.length'data-separator.length)birthdays').csssplit( "display", "" '&');
}
raw_data.forEach(function (character) {
/* Character birthdays - end */
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);
});
 
for (var index = -1; index <= 30; index++) {
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; }
/* Character affection table - start */
}
const affection_start = 50;
const affection_cap = 50;
var affection_data = {};
var affectionTableCounter = 0;
 
data_out.forEach(
function (character) { html_out += '<a href="/wiki/'+character[0]+'">'+character[2]+'&nbsp;('+character[1].replace(' ', '&nbsp;')+')</a>'; }
$( document ).ready(function() {
);
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'));});
});
 
$('#character-birthdays').append(html_out).css( "display", "" );
function initAffectionTable(){
}
$(".character-affectiontable").each(function(){
/* Character birthdays - end */
var id = 'affectionTable-'+(++affectionTableCounter);
$(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(' ');
 
/* Character voice preview - start */
$.each( bonus, function( index ) {
$( document ).ready(function() {
bonus[index] = bonus[index].split('+');
initCharacterVoice();
data[level][bonus[index][0]] = parseInt(bonus[index][1]);
});
});
});
affection_data[id] = data;
 
function initCharacterVoice(){
$(this).find(".affection-level").html('<input type="number" value="'+affection_start+'" step="1" min="1" max="'+affection_cap+'" />');
var voice = $(".character td.character-voice");
if (voice.length && voice.attr('data-voice').length) {
affectionChange($(this), affection_start);
voice.addClass('character-voice-preview').on("click", function(){playCharacterVoice();});
if (typeof affection !== 'undefined') {
voice.wrapInner('<span>');
affectionGet($(".character-stattable"));
if (voice.find("span").width() > voice.width()-36 ) voice.css('padding-right', '16px');
statTableRecalc($(".character-stattable"));
voice.find("span").children().unwrap();
}
});
}
}
 
function affectionChange playCharacterVoice(affectionTable, level){
var voice = $(".character td.character-voice");
var effective_bonus = {};
if (voice.find('audio').length == 0) {
var html_out = '';
voice.append('<audio class="voice-clip" src="'+voice.attr('data-voice')+'"></audio>');
voice.find('audio')[0].volume=0.6;
}
voice.find('audio')[0].play();
}
/* Character voice preview - end */
 
level = (typeof level !== 'undefined' && !isNaN(level)) ? level : 1 ;
if (level < 1) { affectionTable.find(".affection-level input").val(1); level = 1; }
if (level > affection_cap) { affectionTable.find(".affection-level input").val(affection_cap); level = affection_cap; }
 
/* Character video preview - start */
for (var index = 2; index <= level; index++) {
$( document ).ready(function() {
$.each( affection_data[affectionTable.attr('id')][index], function(stat_name, stat_value){
//if video tab is open on inital page display
if (typeof effective_bonus[stat_name] == 'undefined') effective_bonus[stat_name] = 0;
if ($(".character-images [data-title='Chibi']").attr('aria-hidden') == 'false' || window.location.hash == '#Chibi-0' || window.location.hash == '#Other-0' ) initCharacterVideo($('.character-images'));
effective_bonus[stat_name] += stat_value;
});
}
$.each( effective_bonus, function(stat_name, stat_value){
html_out += '<b>' + stat_name + '</b>' + ' +' + stat_value + ', ';
});
 
//Tabber initializes late so events are bound at first click on parent div
affection_data[affectionTable.attr('id')].current = effective_bonus;
$(".character-images div.tabber").on("click", function(){
if ($(".character-images [data-title='Chibi']").attr('aria-hidden') == 'false') initCharacterVideo($('.character-images'));
$(".character-images [data-title='Chibi']").on("click", function(){initCharacterVideo($('.character-images'));});
});
})
 
function initCharacterVideo(element) {
if (affectionTable.find(".affection-level input").val() !== level) affectionTable.find(".affection-level input").val(level);
var container = element.find('div.video');
affectionTable.find(".affection-total").html(html_out.substring(0,html_out.length-2));
if (!container.attr('data-video-initialized')) {
 
var video_src = container.attr('data-videosrc');
//update StatCalc if present
container.html('<video autoplay loop playsinline><source src="'+video_src+'" type="video/webm" /></video>');
if (typeof affection !== 'undefined') {
container.on("click", function(){playToggle(container)});
affectionGet($(".character-stattable"));
container.attr('data-video-initialized', true);
statTableRecalc($(".character-stattable"));
}
}
}
/* Character affection table - end */
 
function playToggle(element) {
var video = element.find('video').get(0);
if (video.paused) video.play();
else video.pause();
}
/* Character video preview - end */
 
/* Character voice preview - start */
$( document ).ready(function() {
initCharacterVoice();
});
 
/* XP tables */
function initCharacterVoice(){
mw.loader.load( '/w/index.php?title=MediaWiki:XPtable.js&action=raw&ctype=text/javascript' );
var voice = $(".character td.character-voice");
if (voice.length && voice.attr('data-voice').length) {
voice.wrapInner('<span>');
if (voice.find("span").width() > voice.width()-36 ) voice.css('padding-right', '16px');
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(); })
}
}
/* Character voice preview - end */
});