MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */ /**Tooltip code by Ylimegirl start**/ $(".buddy-tooltip a, .magic-tooltip a").attr("title","");//removes link titles on tooltip'd elements $(".buddy-tooltip, .magic-tooltip").hover(function {//when mouse enters a tooltip'd element	$(this).children(".tooltip").addClass("tooltip-active");//show the current tooltip	$(this).mousemove(function(event){//as mouse moves $(this).children(".tooltip").css({//change the inline style of the corresponding tooltip			"left": event.clientX+10,//set it to appear to the right of			"top": event.clientY+10//and below the mouse position		}); }); }, function {//when mouse leaves	$(this).children(".tooltip").removeClass("tooltip-active");//hide the current tooltip	$(this).children(".tooltip").css({//change the inline style of the corresponding tooltip "left": "",//time to reset "top": "",//the parameters }); }); /**Tooltip code by Ylimegirl end**/

//back to top button window.BackToTopModern = true;

/* Toggler Toggles the display of elements on a page Author/contact: Austin Che https://openwetware.org/wiki/User:Austin_J._Che See https://openwetware.org/wiki/OpenWetWare:Toggle for examples and documentation

Indexed array of toggler ids to array of associated toggle operations each operation is a two element array, the first being the type, the second a class name or array of elements operation types are strings like "_reset" or "" for the default toggle operation

var togglers = []; var allClasses = {}; // associative map of class names to page elements

function toggler(id) { var toBeToggled = togglers[id]; if (!toBeToggled) return;

// if some element is in list more than once, it will be toggled multiple times for (var i = 0; i < toBeToggled.length; i++) { // get array of elements to operate on       var toggles = toBeToggled[i][1]; if (typeof(toggles) == "string") { if (toggles.charAt(0) == '-') { // treat as an element ID, not as class toggles = document.getElementById(toggles.substring(1)); if (toggles) toggles = new Array(toggles); } else { toggles = allClasses[toggles]; } }       if (!toggles || !toggles.length) continue;

var op = toBeToggled[i][0]; // what the operation will be       var j; //"j is already defined" fix

switch (op) { case "_reset": for (j in toggles) toggles[j].style.display = toggles[j]._toggle_original_display; break; case "_show": for (j in toggles) toggles[j].style.display = ''; $(window).trigger('scroll'); //trigger lazy loading break; case "_hide": for (j in toggles) toggles[j].style.display = 'none'; break; default: // Toggle for (j in toggles) if (toggles[j].style.display == 'none') { toggles[j].style.display = ''; } else { toggles[j].style.display = 'none'; }               $(window).trigger('scroll'); //trigger lazy loading break; }   } }

function createTogglerLink(toggler, id) { var toggle = document.createElement("a"); toggle.className = 'toggler-link'; toggle.setAttribute('id', 'toggler' + id); toggle.setAttribute('href', 'javascript:toggler("' + id + '");'); var child = toggler.firstChild; toggler.removeChild(child); toggle.appendChild(child); toggler.insertBefore(toggle, toggler.firstChild); }

function toggleInit { var togglerElems = []; var toggleGroup = [];

// initialize/clear any old information togglers = []; allClasses = {}; allClasses.watch = undefined; allClasses.unwatch = undefined;

// make list of all document classes var elems = document.getElementsByTagName("*"); var numelems = elems.length; var i = 0; //"i is already defined" fix for (i = 0; i < elems.length; i++) { var elem = elems[i]; if (!elem.className || !elem.className.split) { continue; }

elem._toggle_original_display = elem.style.display; var togglerID = -1; var elemClasses = elem.className.split(' '); // get list of classes for (var j = 0; j < elemClasses.length; j++) {           var elemClass = elemClasses[j]; if (! allClasses[elemClass]) { allClasses[elemClass] = []; } allClasses[elemClass].push(elem);

// all the special classes begin with _toggle if (elemClass.substring(0, 7) != "_toggle") { continue; }

if (elemClass == "_togglegroup") { toggleGroup = []; } else if (elemClass == "_toggle") { toggleGroup.push(elem); } else if (elemClass.substring(0, 12) == "_toggle_init") { // set initial value for display (ignore the original CSS set value) // understands _toggle_initshow and _toggle_inithide var disp = elemClass.substring(12); if (disp == "show") { elem.style.display = ''; } else if (disp == "hide") { elem.style.display = 'none'; } elem._toggle_original_display = disp; }           else if (elemClass.substring(0, 8) == "_toggler") { if (togglerID == -1) { togglerID = togglers.length; togglers[togglerID] = []; togglerElems[togglerID] = elem; }

// all classes are of form _toggler_op-CLASS // figure out what class we're toggling // if none is specified, then we use the current toggle group var toBeToggled; var hyphen = elemClass.indexOf('-'); if (hyphen != -1) { toBeToggled = elemClass.substring(hyphen+1); } else { toBeToggled = toggleGroup; hyphen = elemClass.length; }               var op = elemClass.substring(8, hyphen); togglers[togglerID].push(new Array(op, toBeToggled)); }       }    }    // add javascript links to all toggler elements for (i = 0; i < togglerElems.length; i++) createTogglerLink(togglerElems[i], i); }

window.toggler = toggler;

//toggler end

//countdown start


 * (function (module, mw, $, undefined) {

'use strict';

var translations = $.extend(true, {		// Language list - start		// Arabic (العربية)		ar: {			and: 'و',			second: 'ثانية',			seconds: 'ثواني',			minute: 'دقيقة',			minutes: 'دقائق',			hour: 'ساعة',			hours: 'ساعات',			day: 'يوم',			days: 'أيام'		},		// Belarusian (Беларуская)		be: {			and: 'і',			second: 'секунда',			seconds: 'секунд',			minute: 'хвіліна',			minutes: 'хвілін',			hour: 'гадзіну',			hours: 'гадзін',			day: 'дзень',			days: 'дзён'		},		// Catalan (Català)		ca: {			and: 'i',			second: 'segon',			seconds: 'segons',			minute: 'minut',			minutes: 'minuts',			hour: 'hora',			hours: 'hores',			day: 'dia',			days: 'dies'		},		// German (Deutsch)		de: {			and: 'und',			second: 'Sekunde',			seconds: 'Sekunden',			minute: 'Minute',			minutes: 'Minuten',			hour: 'Stunde',			hours: 'Stunden',			day: 'Tag',			days: 'Tage'		},		// English (English)		en: {			and: 'and',			second: 'second', seconds: 'seconds', minute: 'minute', minutes: 'minutes', hour: 'hour', hours: 'hours', day: 'day', days: 'days' },		// Greek (Ελληνικά) el: { and: 'και', second: 'δευτερόλεπτο', seconds: 'δευτερόλεπτα', minute: 'λεπτό', minutes: 'λεπτά', hour: 'ώρα', hours: 'ώρες', day: 'ημέρα', days: 'ημέρες' },		// Spanish (Español) es: { and: 'y', second: 'segundo', seconds: 'segundos', minute: 'minuto', minutes: 'minutos', hour: 'hora', hours: 'horas', day: 'día', days: 'días' },		// French (Français) fr: { and: 'et', second: 'seconde', seconds: 'secondes', minute: 'minute', minutes: 'minutes', hour: 'heure', hours: 'heures', day: 'jour', days: 'jours' },		//Hindi (हिंदी) hi: { and: 'और', second: 'सेकंड', seconds: 'सेकंड', minute: 'मिनट', minutes: 'मिनट', hour: 'घंटा', hours: 'घंटे', day: 'दिन', days: 'दिन' },		// Hungarian (Magyar) hu: { and: 'és', second: 'másodperc', seconds: 'másodperc', minute: 'perc', minutes: 'perc', hour: 'óra', hours: 'óra', day: 'nap', days: 'nap' },		// Indonesia (Bahasa Indonesia) id: { and: 'dan', second: 'detik', seconds: 'detik', minute: 'menit', minutes: 'menit', hour: 'jam', hours: 'jam', day: 'hari', days: 'hari' },		// Italian (Italiano) it: { and: 'e', second: 'secondo', seconds: 'secondi', minute: 'minuto', minutes: 'minuti', hour: 'ora', hours: 'ore', day: 'giorno', days: 'giorni' },		// Japanese (日本語) ja: { and: '', second: '秒', seconds: '秒', minute: '分', minutes: '分', hour: '時間', hours: '時間', day: '日', days: '日' },		// Korean (한국어) ko:{ and: ' ', second: '초', seconds: '초', minute: '분', minutes: '분', hour: '시간', hours: '시간', day: '일', days: '일' },		// Malay (Bahasa Melayu) ms: { and: 'dan', second: 'saat', seconds: 'saat', minute: 'minit', minutes: 'minit', hour: 'jam', hours: 'jam', day: 'hari', days: 'hari' },		// Dutch (Nederlands) nl: { and: 'en', second: 'seconde', seconds: 'seconden', minute: 'minuut', minutes: 'minuten', hour: 'uur', hours: 'uur', day: 'dag', days: 'dagen' },		// Polish (Polski) pl: { and: 'i', second: 'sekunda', seconds: 'sekund(y)', minute: 'minuta', minutes: 'minut(y)', hour: 'godzina', hours: 'godzin(y)', day: 'dzień', days: 'dni' },		// Portuguese (Português) pt: { and: 'e', second: 'segundo', seconds: 'segundos', minute: 'minuto', minutes: 'minutos', hour: 'hora', hours: 'horas', day: 'dia', days: 'dias' },		// Brazilian Portuguese (Português do Brasil) 'pt-br': { and: 'e', second: 'segundo', seconds: 'segundos', minute: 'minuto', minutes: 'minutos', hour: 'hora', hours: 'horas', day: 'dia', days: 'dias' },		// Romanian (Română) ro: { and: 'și', second: 'secundă', seconds: 'secunde', minute: 'minut', minutes: 'minute', hour: 'oră', hours: 'ore', day: 'zi', days: 'zile', },		// Russian (русский) ru: { and: 'и', second: 'секунда', seconds: 'секунд', minute: 'минута', minutes: 'минут', hour: 'час', hours: 'часов', day: 'день', days: 'дней' },		// Serbian (српски језик) sr: { and: 'i', second: 'sekundu', seconds: 'sekunde/-i', minute: 'minutu', minutes: 'minute/-a', hour: 'sat', hours: 'sata/-i', day: 'dan', days: 'dana' },		// Tagalog tl: { and: 'at', second: 'segundo', seconds: 'mga segundo', minute: 'minuto', minutes: 'mga minuto', hour: 'oras', hours: 'mga oras', day: 'araw', days: 'mga araw' },		// Turkish (Türkçe) tr: { and: 've', second: 'saniye', seconds: 'saniye', minute: 'dakika', minutes: 'dakika', hour: 'saat', hours: 'saat', day: 'gün', days: 'gün' },		// Ukrainian (Українська) uk: { and: 'та', second: 'секунда', seconds: 'секунд', minute: 'хвилина', minutes: 'хвилин', hour: 'годину', hours: 'годин', day: 'день', days: 'днів' },		// Vietnamese (Tiếng Việt) vi: { and: 'và', second: 'giây', seconds: 'giây', minute: 'phút', minutes: 'phút', hour: 'giờ', hours: 'giờ', day: 'ngày', days: 'ngày' },		// Chinese (简体中文) zh: { and: ' ', second: '秒', seconds: '秒', minute: '分', minutes: '分', hour: '时', hours: '时', day: '天', days: '天' },		// Chinese (台湾繁體中文) 'zh-tw':{ and: ' ', second: '秒', seconds: '秒', minute: '分', minutes: '分', hour: '時', hours: '時', day: '天', days: '天' },		// Chinese (香港繁體中文) 'zh-hk':{ and: ' ', second: '秒', seconds: '秒', minute: '分', minutes: '分', hour: '時', hours: '時', day: '天', days: '天' }		// Language list - stop }, module.translations || {}),	i18n = translations[		mw.config.get('wgContentLanguage')	] || translations.en;

var countdowns = [];

var NO_LEADING_ZEROS = 1, SHORT_FORMAT = 2, NO_ZEROS = 4;

function output (i, diff) { /*jshint bitwise:false*/ var delta, result, parts = []; delta = diff % 60; result = ' ' + i18n[delta === 1 ? 'second' : 'seconds']; if (countdowns[i].opts & SHORT_FORMAT) result = result.charAt(1); parts.unshift(delta + result); diff = Math.floor(diff / 60); delta = diff % 60; result = ' ' + i18n[delta === 1 ? 'minute' : 'minutes']; if (countdowns[i].opts & SHORT_FORMAT) result = result.charAt(1); parts.unshift(delta + result); diff = Math.floor(diff / 60); delta = diff % 24; result = ' ' + i18n[delta === 1 ? 'hour'  : 'hours'  ]; if (countdowns[i].opts & SHORT_FORMAT) result = result.charAt(1); parts.unshift(delta + result); diff = Math.floor(diff / 24); result = ' ' + i18n[diff === 1 ? 'day'   : 'days'   ]; if (countdowns[i].opts & SHORT_FORMAT) result = result.charAt(1); parts.unshift(diff + result); result = parts.pop; if (countdowns[i].opts & NO_LEADING_ZEROS) { while (parts.length && parts[0][0] === '0') { parts.shift; }		}		if (countdowns[i].opts & NO_ZEROS) { parts = parts.filter(function(part) {				return part[0] !== '0';			}); }		if (parts.length) { if (countdowns[i].opts & SHORT_FORMAT) { result = parts.join(' ') + ' ' + result; } else { result = parts.join(', ') + ' ' + i18n.and + ' ' + result; }		}		countdowns[i].node.text(result); }

function end(i) { var c = countdowns[i].node.parent; switch (c.attr('data-end')) { case 'remove': c.remove; return true; case 'stop': output(i, 0); return true; case 'toggle': var toggle = c.attr('data-toggle'); if (toggle && toggle == 'next') { c.next.css('display', 'inline'); c.css('display', 'none'); return true; }			if (toggle && $(toggle).length) { $(toggle).css('display', 'inline'); c.css('display', 'none'); return true; }			break; case 'callback': var callback = c.attr('data-callback'); if (callback && $.isFunction(module[callback])) { output(i, 0); module[callback].call(c); return true; }			break; }		countdowns[i].countup = true; output(i, 0); return false; }

function update { var now = Date.now; var countdownsToRemove = []; $.each(countdowns.slice(0), function (i, countdown) {			var diff = Math.floor((countdown.date - now) / 1000);			if (diff <= 0 && !countdown.countup) {				if (end(i)) countdownsToRemove.push(i);			} else {				output(i, Math.abs(diff));			}		}); var x;		while((x = countdownsToRemove.pop) !== undefined) { countdowns.splice(x, 1); }		if (countdowns.length) { window.setTimeout(function {				update;			}, 1000); }	}

function getOptions (node) { /*jshint bitwise:false*/ var text = node.parent.attr('data-options'), opts = 0; if (text) { if (/no-leading-zeros/.test(text)) { opts |= NO_LEADING_ZEROS; }			if (/short-format/.test(text)) { opts |= SHORT_FORMAT; }			if (/no-zeros/.test(text)) { opts |= NO_ZEROS; }		}		return opts; }

function init { var countdown = $('.countdown:not(.handled)'); if (!countdown.length) return; $('.nocountdown').css('display', 'none'); countdown .css('display', 'inline') .find('.countdowndate') .each(function {			var $this = $(this),				date = (new Date($this.text)).valueOf;			if (isNaN(date)) {				$this.text('BAD DATE');				return;			}			countdowns.push({ node: $this, opts: getOptions($this), date: date, });		});		countdown.addClass('handled'); if (countdowns.length) { update; }	}

mw.hook('wikipage.content').add(init);

}(window.countdownTimer = window.countdownTimer || {}, mediaWiki, jQuery));

$(toggleInit);

//countdown end //audioplayer start var audioplayerz = document.getElementsByClassName("audio-button"); var audioPlayer = function { var audioplayerx = this; var audioplayery = audioplayerx.getElementsByTagName("audio")[0]; if (audioplayery.paused) { var audio = document.getElementsByTagName('audio'), audioplayeri = audio.length; while (audioplayeri--) { audio[audioplayeri].pause; audio[audioplayeri].currentTime = 0; }		var audioplayerj = document.getElementsByClassName("audio-button playing"); while(audioplayerj.length > 0) { audioplayerj[0].className = 'audio-button'; }	   audioplayery.play; audioplayerx.className = "audio-button playing"; audioplayery.addEventListener("timeupdate", audioUpdate, false); audioplayery.addEventListener("canplaythrough", function {			audioplayerd = audioplayery.duration;		}, false); } else { audioplayery.pause; audioplayery.currentTime = 0; audioplayerx.className = "audio-button"; } }; function audioUpdate { if (this.currentTime == audioplayerd) { this.parentElement.className = "audio-button" this.removeEventListener('timeupdate', audioUpdate, false); } } for (var audioplayeri = 0; audioplayeri < audioplayerz.length; audioplayeri++) { audioplayerz[audioplayeri].addEventListener('click', audioPlayer, false); }

$('.audio-button a.new').parent.addClass('no-audio');

//audioplayer end

//story config stuff $( document ).ready(function {   mw.loader.using('mediawiki.api', function {

console.log("%cSTORY.JS v0.4.1 — github/jeaoq/enstars-wiki", "display: inline-block; color:#3434eb; background:white; padding: 10px 40px; margin: 0px 5px 5px 0px; border-radius: 15px 5px; border: solid 2px #3434eb; box-shadow: 5px 5px 0px 0px #3434eb; font-weight: 700; font-size: 1.2em;");

$('.storyNavBar').parent.addClass('storyOptions'); ///Adds the button to the top $('.storyTopNav > tbody > tr > *:nth-child(2)').after('\       \            \                text_fields \            \        \        ');

///Adds the specific options row $('.storyTopNav > tbody').append('\       \        \        \            \                question_answer \            \ //            \ //                palette \ //            \ //            \ //                format_color_fill \ //            \ //            \ //                copy_all \ //            \        \        \            \                format_size \            \            \                <li id="sf-14" onclick="storyOptionsFontSize(14);">14px</li>\                <li id="sf-16" onclick="storyOptionsFontSize(16);">16px</li>\                <li id="sf-18" onclick="storyOptionsFontSize(18);">18px</li>\ <li id="sf-21" onclick="storyOptionsFontSize(21);">21px</li>\ </ul>\ \       \            \ <img src="https://static.miraheze.org/twistedwonderlandwiki/9/91/Grim_Head.png" alt="Disable Natsume Spell Font"> \ </a>\ \       \        \        ');    }); });

//hides or shows options row function showOptions { $('.storyTopNav').toggleClass('storyOptions'); }

//button for switching formats function resizeImg{ $('body').toggleClass('story-minimized'); setPreference('format', $('body').hasClass('story-minimized')); }

//font size changer button function storyOptionsFontSize(val) { console.log('Font size = ' + val); document.documentElement.style.setProperty('--story-font-size', val + 'px'); $('[id|="sf"]').removeClass("currentFontSize"); $('#sf-'+val).addClass("currentFontSize"); setPreference('fontSize', val); }

//font changer button function opendyslexic{ $('body').toggleClass('opendyslexic'); setPreference('opendyslexic', $('body').hasClass('opendyslexic')); }

//adds classes to story table function setPreference(param, val){ var params = { action: 'options', optionname: 'userjs-'+param, optionvalue: val, format: 'json' },       api = new mw.Api; api.postWithToken( 'csrf', params ).done( function ( data ) {       // console.log(param + ' ' + val);        // console.log(data);    } ); }

function initialConfigStory{ document.documentElement.style.setProperty('--content-width', $('#content').width + 'px'); var params = { action: 'query', meta: 'userinfo', uiprop: 'options', format: 'json' },       api = new mw.Api; api.get( params ).done( function ( data ) {   	var pref = data.query.userinfo;        // console.log( pref );        if(pref.options['userjs-fontSize'] === "undefined"){        	setPreference('fontSize', '16');        }        storyOptionsFontSize(pref.options['userjs-fontSize']);

if(pref.options['userjs-format'] === "undefined"){ setPreference('format', false); }       else if(pref.options['userjs-format']){ $('body').addClass('story-minimized'); }

if(pref.options['userjs-color'] === "undefined"){ setPreference('color', false); }       else if(pref.options['userjs-color']){ $('body').addClass('story-color'); }

if(pref.options['userjs-colorFill'] === "undefined"){ setPreference('colorFill', false); }       else if(pref.options['userjs-colorFill']){ $('body').addClass('story-colorFill'); }

if(pref.options['userjs-colorShadow'] === "undefined"){ setPreference('colorShadow', false); }       else if(pref.options['userjs-colorShadow']){ $('body').addClass('story-colorShadow'); }

if(pref.options['userjs-notsume'] === "undefined"){ setPreference('notsume', false); }       else if(pref.options['userjs-notsume']){ $('body').addClass('notsume'); }

if(pref.options['userjs-opendyslexic'] === "undefined"){ setPreference('opendyslexic', false); }       else if(pref.options['userjs-opendyslexic']){ $('body').addClass('opendyslexic'); }       tagRenders; } ); }

function getPreference(param){ var params = { action: 'query', meta: 'userinfo', uiprop: 'options', format: 'json' },       api = new mw.Api, pref;

api.get( params ).done( function ( data ) {   	pref = data.query.userinfo.options['userjs-'+param];        // console.log( pref );    } );

} //