MediaWiki:Common.js: Difference between revisions
From Valve Cut Content
(Created page with "/** * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally * loaded for all users on every wiki page. If possible create a gadget that is * enabled by def...") |
m (no article todo for wiki todo page) |
||
(12 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
window.overwikiCommon = {}; | |||
/* | |||
* Collapsible navigation boxes | |||
* | |||
*/ | */ | ||
overwikiCommon.navtemp = {}; | |||
overwikiCommon.navtemp.toggle = function(button) { | |||
$(button.parentNode.parentNode.parentNode.parentNode.parentNode).toggleClass('navtempcoll'); | |||
} | } | ||
overwikiCommon.navtemp.createToggles = function(content) { | |||
var headers = content.find('.navtemp th'); | |||
if (headers.length === 0) { | |||
return; | |||
} | |||
var buttonHTML = '<span class="navtemptoggle"><span class="navtempshow" onclick="overwikiCommon.navtemp.toggle(this);">[show]</span><span class="navtemphide" onclick="overwikiCommon.navtemp.toggle(this);">[hide]</span></span>'; | |||
headers.each(function(headerIndex, header) { | |||
header.insertAdjacentHTML('afterbegin', buttonHTML); | |||
$(header.parentNode.parentNode.parentNode).addClass('navtempcoll'); | |||
}); | |||
} | } | ||
mw.hook('wikipage.content').add(overwikiCommon.navtemp.createToggles); | |||
/ | /* | ||
* | * Proper positioning of the license box when uploading. | ||
*/ | */ | ||
overwikiCommon.upload = {}; | |||
} | |||
overwikiCommon.upload.updateLicense = function() { | |||
var description = document.getElementById('wpUploadDescription'); | |||
var license = document.getElementById('wpLicense'); | |||
if (description != null && license != null) { | |||
var | description.value = description.value.replace(/\|licensing=.*/m, '|licensing=' + (license.value ? '{{' + license.value + '}}' : '')); | ||
} | |||
} | |||
overwikiCommon.upload.setupLicensing = function(/* content */) { | |||
var license = /* content.find('#wpLicense').get() */ document.getElementById('wpLicense'); | |||
if (license != null) { | |||
license.removeAttribute('name'); | |||
if (license.addEventListener != null) { | |||
license.addEventListener('change', overwikiCommon.upload.updateLicense); | |||
} else if (license.attachEvent != null) { | |||
license.attachEvent('onchange', overwikiCommon.upload.updateLicense); | |||
} | |||
} | |||
} | } | ||
if ( | if (wgPageName === 'Special:Upload' && !document.location.search.match(/[?&]wpForReUpload=1/)) { | ||
// mw.hook('wikipage.content').add(overwikiCommon.upload.setupLicensing); | |||
overwikiCommon.upload.setupLicensing(); | |||
} | } | ||
$('.audioplayer').click(function(){ | |||
var name = $(this).children('img').attr('class'); | |||
var content = '<audio controls autoplay src="' + name + '"> </audio>'; | |||
$(this).html(content); | |||
$(this).off('click'); | |||
}); | |||
* | /* | ||
* custom usage of talk pages and redirecting the user to the discord | |||
*/ | */ | ||
var tab = window.document.getElementById('ca-talk'); | |||
// if this is a page with a discussion board | |||
if(tab){ | |||
// change it's name | |||
var tabs = tab.parentElement; | |||
var | |||
if(wgPageName != 'Wiki_Todo'){ | |||
var talkpage = tab.firstChild.firstChild; | |||
talkpage.setAttribute("title","Things to be included on the content page[alt-shift-t]"); | |||
talkpage.innerHTML = "Article-ToDo"; | |||
} | } | ||
/ | // duplicate it and make it look like the normal tab to direct people to the discord instead | ||
var discordtab = tab.cloneNode(true); | |||
discordtab.setAttribute("class","new"); | |||
var discord = discordtab.firstChild.firstChild; | |||
var | |||
discord.setAttribute("title","Discussion about the wiki or pages"); | |||
discord.innerHTML = "Discussion"; | |||
discord.href = window.document.getElementById('n-Official-VCC-Discord').firstChild.href; | |||
tabs.appendChild(discordtab); | |||
if(wgPageName === 'Wiki_Todo'){ | |||
tabs.removeChild(tab); | |||
if ( | |||
} | } | ||
} | } | ||
/* | |||
/ | * quick link to wiki todo | ||
* | |||
*/ | */ | ||
var tabe = window.document.getElementById('ca-edit'); | |||
var tabv = window.document.getElementById('ca-view'); | |||
var tabp = window.document.getElementById('ca-nstab-main'); | |||
// if the user has edit access | |||
if(tabe){ | |||
// get the tabs | |||
var tabs = tabe.parentElement; | |||
// | if(wgPageName === 'Wiki_Todo'){ | ||
// change the text if we are on the wiki todo page | |||
tabp.firstChild.firstChild.innerHTML = "Wiki Todo"; | |||
}else{ | |||
// duplicate it and make it look like the normal tab to direct people to the wiki todo | |||
var todotab = tabe.cloneNode(true); | |||
todotab.setAttribute("class","new"); | |||
var todo = todotab.firstChild.firstChild; | |||
todo.setAttribute("title","Pages that are work in progress"); | |||
todo.innerHTML = "Wiki Todo"; | |||
todo.href = "/wiki/Wiki_Todo"; | |||
tabs.insertBefore(todotab, tabs.children[2]); | |||
} | |||
} | |||
} | } | ||
Latest revision as of 00:50, 20 December 2020
window.overwikiCommon = {}; /* * Collapsible navigation boxes */ overwikiCommon.navtemp = {}; overwikiCommon.navtemp.toggle = function(button) { $(button.parentNode.parentNode.parentNode.parentNode.parentNode).toggleClass('navtempcoll'); } overwikiCommon.navtemp.createToggles = function(content) { var headers = content.find('.navtemp th'); if (headers.length === 0) { return; } var buttonHTML = '<span class="navtemptoggle"><span class="navtempshow" onclick="overwikiCommon.navtemp.toggle(this);">[show]</span><span class="navtemphide" onclick="overwikiCommon.navtemp.toggle(this);">[hide]</span></span>'; headers.each(function(headerIndex, header) { header.insertAdjacentHTML('afterbegin', buttonHTML); $(header.parentNode.parentNode.parentNode).addClass('navtempcoll'); }); } mw.hook('wikipage.content').add(overwikiCommon.navtemp.createToggles); /* * Proper positioning of the license box when uploading. */ overwikiCommon.upload = {}; overwikiCommon.upload.updateLicense = function() { var description = document.getElementById('wpUploadDescription'); var license = document.getElementById('wpLicense'); if (description != null && license != null) { description.value = description.value.replace(/\|licensing=.*/m, '|licensing=' + (license.value ? '{{' + license.value + '}}' : '')); } } overwikiCommon.upload.setupLicensing = function(/* content */) { var license = /* content.find('#wpLicense').get() */ document.getElementById('wpLicense'); if (license != null) { license.removeAttribute('name'); if (license.addEventListener != null) { license.addEventListener('change', overwikiCommon.upload.updateLicense); } else if (license.attachEvent != null) { license.attachEvent('onchange', overwikiCommon.upload.updateLicense); } } } if (wgPageName === 'Special:Upload' && !document.location.search.match(/[?&]wpForReUpload=1/)) { // mw.hook('wikipage.content').add(overwikiCommon.upload.setupLicensing); overwikiCommon.upload.setupLicensing(); } $('.audioplayer').click(function(){ var name = $(this).children('img').attr('class'); var content = '<audio controls autoplay src="' + name + '"> </audio>'; $(this).html(content); $(this).off('click'); }); /* * custom usage of talk pages and redirecting the user to the discord */ var tab = window.document.getElementById('ca-talk'); // if this is a page with a discussion board if(tab){ // change it's name var tabs = tab.parentElement; if(wgPageName != 'Wiki_Todo'){ var talkpage = tab.firstChild.firstChild; talkpage.setAttribute("title","Things to be included on the content page[alt-shift-t]"); talkpage.innerHTML = "Article-ToDo"; } // duplicate it and make it look like the normal tab to direct people to the discord instead var discordtab = tab.cloneNode(true); discordtab.setAttribute("class","new"); var discord = discordtab.firstChild.firstChild; discord.setAttribute("title","Discussion about the wiki or pages"); discord.innerHTML = "Discussion"; discord.href = window.document.getElementById('n-Official-VCC-Discord').firstChild.href; tabs.appendChild(discordtab); if(wgPageName === 'Wiki_Todo'){ tabs.removeChild(tab); } } /* * quick link to wiki todo */ var tabe = window.document.getElementById('ca-edit'); var tabv = window.document.getElementById('ca-view'); var tabp = window.document.getElementById('ca-nstab-main'); // if the user has edit access if(tabe){ // get the tabs var tabs = tabe.parentElement; if(wgPageName === 'Wiki_Todo'){ // change the text if we are on the wiki todo page tabp.firstChild.firstChild.innerHTML = "Wiki Todo"; }else{ // duplicate it and make it look like the normal tab to direct people to the wiki todo var todotab = tabe.cloneNode(true); todotab.setAttribute("class","new"); var todo = todotab.firstChild.firstChild; todo.setAttribute("title","Pages that are work in progress"); todo.innerHTML = "Wiki Todo"; todo.href = "/wiki/Wiki_Todo"; tabs.insertBefore(todotab, tabs.children[2]); } }