MediaWiki:Common.js: Difference between revisions

Try to fix script error causing mobile stylesheets to not be loaded
No edit summary
Tag: Reverted
(Try to fix script error causing mobile stylesheets to not be loaded)
Tag: Reverted
Line 59:
}
}
});
/* Character stat calc*/
mw.loader.load( '/w/index.php?title=MediaWiki:StatCalc.js&action=raw&ctype=text/javascript' );
 
 
/* Character statbirthdays - start calc*/
function initBirthdays(){
mw.loader.load( '/w/index.php?title=MediaWiki:StatCalc.js&action=raw&ctype=text/javascript' );
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 = '';
 
var raw_data = $('#character-birthdays').attr('data-birthdays').split('&');
/* Character birthdays - start */
function initBirthdays(){
raw_data.forEach(function (character) {
const separator = ' <span></span> ';
var char_data = character.split(' |');
const months = [
char_data.push(char_data[0].split('(')[0].trim()); //normalized name
'January',
if (!birthdays.some(function (data) {return data[2] == char_data[2];})) birthdays.push(char_data);
'February',
});
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
 
for (var index = -1; index <= 30; index++) {
var birthdays = [];
var data_outdate = []new Date();
date.setDate(date.getDate() + index);
var html_out = '';
data_out = data_out.concat(birthdays.filter(function (data) { return data[1] == months[date.getMonth()]+' '+date.getDate();}));
 
if (data_out.length >= 5) { break; }
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);
});
 
data_out.forEach(
for (var index = -1; index <= 30; index++) {
function (character) { html_out += '<a href="/wiki/'+character[0]+'">'+character[2]+'&nbsp;('+character[1].replace(' ', '&nbsp;')+')</a>'+separator; }
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').append(html_out.substring(0,html_out.length-separator.length)).css( "display", "" );
if (data_out.length >= 5) { break; }
}
}
/* Character birthdays - end */
 
data_out.forEach(
function (character) { html_out += '<a href="/wiki/'+character[0]+'">'+character[2]+'&nbsp;('+character[1].replace(' ', '&nbsp;')+')</a>'+separator; }
);
 
/* Character affection table - start */
$('#character-birthdays').append(html_out.substring(0,html_out.length-separator.length)).css( "display", "" );
const affection_start = 50;
}
const affection_cap = 50;
/* Character birthdays - end */
var affection_data = {};
var affectionTableCounter = 0;
 
$( 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'));});
});
 
function initAffectionTable(){
/* Character affection table - start */
$(".character-affectiontable").each(function(){
const affection_start = 50;
var id = 'affectionTable-'+(++affectionTableCounter);
const affection_cap = 50;
$(this).attr('id',id);
var affection_data = {};
var data = {};
var affectionTableCounter = 0;
 
$(this).find(".affection-data > div").each(function(){
var level = $(this).attr('data-level');
$( document ).ready(function() {
data[level] = {};
initAffectionTable();
var bonus = $(this).attr('data-stats').split(' ');
$(".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'));});
});
 
$.each( bonus, function( index ) {
function initAffectionTable(){
bonus[index] = bonus[index].split('+');
$(".character-affectiontable").each(function(){
data[level][bonus[index][0]] = parseInt(bonus[index][1]);
var id = 'affectionTable-'+(++affectionTableCounter);
});
$(this).attr('id',id);
});
affection_data[id] = data;
var data = {};
 
$(this).find(".affection-level").html('<input type="number" value="'+affection_start+'" step="1" min="1" max="'+affection_cap+'" />');
$(this).find(".affection-data > div").each(function(){
var level = $(this).attr('data-level');
affectionChange($(this), affection_start);
data[level] = {};
if (typeof affection !== 'undefined') {
var bonus = $(this).attr('data-stats').split(' ');
affectionGet($(".character-stattable"));
statTableRecalc($(".character-stattable"));
}
});
}
 
$.each( bonus, function( indexaffectionChange )(affectionTable, level){
var effective_bonus = {};
bonus[index] = bonus[index].split('+');
var html_out = '';
data[level][bonus[index][0]] = parseInt(bonus[index][1]);
});
});
affection_data[id] = data;
 
level = (typeof level !== 'undefined' && !isNaN(level)) ? level : 1 ;
$(this).find(".affection-level").html('<input type="number" value="'+affection_start+'" step="1" min="1" max="'+affection_cap+'" />');
if (level < 1) { affectionTable.find(".affection-level input").val(1); level = 1; }
affectionChange($(this), affection_start);
if (level > affection_cap) { affectionTable.find(".affection-level input").val(affection_cap); level = affection_cap; }
if (typeof affection !== 'undefined') {
affectionGet($(".character-stattable"));
statTableRecalc($(".character-stattable"));
}
});
}
 
for (var index = 2; index <= level; index++) {
function affectionChange (affectionTable, level){
$.each( affection_data[affectionTable.attr('id')][index], function(stat_name, stat_value){
var effective_bonus = {};
if (typeof effective_bonus[stat_name] == 'undefined') effective_bonus[stat_name] = 0;
var html_out = '';
effective_bonus[stat_name] += stat_value;
});
}
$.each( effective_bonus, function(stat_name, stat_value){
html_out += '<b>' + stat_name + '</b>' + ' +' + stat_value + ', ';
});
 
affection_data[affectionTable.attr('id')].current = effective_bonus;
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; }
 
if (affectionTable.find(".affection-level input").val() !== level) affectionTable.find(".affection-level input").val(level);
for (var index = 2; index <= level; index++) {
affectionTable.find(".affection-total").html(html_out.substring(0,html_out.length-2));
$.each( affection_data[affectionTable.attr('id')][index], function(stat_name, stat_value){
if (typeof effective_bonus[stat_name] == 'undefined') effective_bonus[stat_name] = 0;
effective_bonus[stat_name] += stat_value;
});
}
$.each( effective_bonus, function(stat_name, stat_value){
html_out += '<b>' + stat_name + '</b>' + ' +' + stat_value + ', ';
});
 
//update StatCalc if present
affection_data[affectionTable.attr('id')].current = effective_bonus;
if (typeof affection !== 'undefined') {
affectionGet($(".character-stattable"));
statTableRecalc($(".character-stattable"));
}
}
/* Character affection table - end */
 
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));
 
/* Character voice preview - start */
//update StatCalc if present
$( document ).ready(function() {
if (typeof affection !== 'undefined') {
initCharacterVoice();
affectionGet($(".character-stattable"));
});
statTableRecalc($(".character-stattable"));
}
}
/* Character affection table - end */
 
function initCharacterVoice(){
 
var voice = $(".character td.character-voice");
/* Character voice preview - start */
if (voice.length && voice.attr('data-voice').length) {
$( document ).ready(function() {
voice.wrapInner('<span>');
initCharacterVoice();
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 */
});
 
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()-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 */