MediaWiki
Common.js
From Dogcraft Wiki
m (Undo revision 27769 by Domino) Tag: Undo |
m (testing automatic banner image selection) |
||
Line 10: | Line 10: | ||
window.popupSummaryData = false; | window.popupSummaryData = false; | ||
*/ | */ | ||
function randomPageImage( category ) { | |||
params = { | |||
action: 'query', | |||
list: 'categorymembers', | |||
cmtitle: 'Category:Builds', | |||
cmprop: 'ids', | |||
cmtype: 'page', | |||
cmlimit: '5000', | |||
format: 'json' | |||
}, | |||
api = new mw.Api(); | |||
api.get( params ).done( function ( data ) { | |||
var pages = data.query.categorymembers, | |||
page, | |||
cat_random = Math.floor(Math.random() * pages.length), | |||
id_random = pages[cat_random].pageid; | |||
var paramsPI = { | |||
action: 'query', | |||
prop: 'pageimages', | |||
pageids: id_random, | |||
piprop: 'original', | |||
format: 'json' | |||
} | |||
api.get( paramsPI ).done( function (data ) { | |||
return data.query.pages[id_random].original; | |||
}); | |||
} ); | |||
} | |||
$(document).ready(function() { | $(document).ready(function() { | ||
Line 50: | Line 81: | ||
if (headbanner) { | if (headbanner) { | ||
var firstHeading = document.getElementById("firstHeading"); | var firstHeading = document.getElementById("firstHeading"); | ||
if (headbanner.hasAttribute("title")) { firstHeading.style.setProperty('--banner-padding', headbanner.title); | if (headbanner.hasAttribute("title")) { | ||
if (headbanner.title == "auto") { | |||
params = { | |||
action: 'query', | |||
list: 'categorymembers', | |||
cmtitle: 'Category:Builds', | |||
cmprop: 'ids', | |||
cmtype: 'page', | |||
cmlimit: '5000', | |||
format: 'json' | |||
}, | |||
api = new mw.Api(); | |||
api.get( params ).done( function ( data ) { | |||
var pages = data.query.categorymembers, | |||
page, | |||
cat_random = Math.floor(Math.random() * pages.length), | |||
id_random = pages[cat_random].pageid; | |||
var paramsPI = { | |||
action: 'query', | |||
prop: 'pageimages', | |||
pageids: id_random, | |||
piprop: 'original', | |||
format: 'json' | |||
} | |||
api.get( paramsPI ).done( function (data ) { | |||
pageimage = data.query.pages[id_random].original; | |||
padding = (pageimage.height / pageimage.width) * 100 + "%"; | |||
firstHeading.style.setProperty('--banner-padding', padding); | |||
firstHeading.style.setProperty('--banner-image', 'url(' + pageimage.source + ')'); | |||
}); | |||
} ); | |||
} else { | |||
firstHeading.style.setProperty('--banner-padding', headbanner.title); | |||
firstHeading.style.setProperty('--banner-image', 'url(' + headbanner.textContent + ')'); | |||
} | |||
} | |||
firstHeading.classList.add('banner'); | firstHeading.classList.add('banner'); | ||
$("#siteSub").prepend($("#main > .content > .top")); | $("#siteSub").prepend($("#main > .content > .top")); | ||
Line 65: | Line 132: | ||
} | } | ||
} | } | ||
}); | }); |
Revision as of 14:17, 11 January 2023
/* Any JavaScript here will be loaded for all users on every page load. */
/* Navigation Popups */
/* Currently Disabled
mw.loader.load('/load.php?modules=ext.gadget.Navigation_popups');
window.popupAdminLinks = false;
window.popupActionsMenu = false;
window.popupStructure = 'lite';
window.popupSubpopups = false;
window.popupSummaryData = false;
*/
function randomPageImage( category ) {
params = {
action: 'query',
list: 'categorymembers',
cmtitle: 'Category:Builds',
cmprop: 'ids',
cmtype: 'page',
cmlimit: '5000',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var pages = data.query.categorymembers,
page,
cat_random = Math.floor(Math.random() * pages.length),
id_random = pages[cat_random].pageid;
var paramsPI = {
action: 'query',
prop: 'pageimages',
pageids: id_random,
piprop: 'original',
format: 'json'
}
api.get( paramsPI ).done( function (data ) {
return data.query.pages[id_random].original;
});
} );
}
$(document).ready(function() {
var pagename = mw.config.get('wgPageName'),
namespace = mw.config.get('wgNamespaceNumber');
// var indicator = document.querySelectorAll(".mw-indicators");
// var indicator1 = indicator[0];
// if (indicator1.childNodes.length !== 1) {document.getElementById("tagline").innerHTML = indicator1.innerHTML;}
/*== Hides the actions button and indicators while in the Visual editor ==*/
mw.hook( 've.activationComplete' ).add( function () {
$('.content .top').hide();
});
mw.hook( 've.deactivationComplete' ).add( function () {
$('.content .top').show();
});
/*== Dogcraft.net topbar: Automatically enabled to display the Dogcraft.net topbar on the Help Resources(WIP) and Rules pages. (moved from gadget) ==*/
$(document).ready(function() {
if (mw.config.get('wgPageName') === "Rules" || mw.config.get('wgPageName') === "Help_Resources")
{
$('.nav .nav-title a span').text('Dogcraft');
$('#wikiNav').removeClass('expanded');
}
});
/*== Shows edit button on Rules and Help Resources for those who can edit it ==*/
if (pagename === 'Rules' || pagename === 'Help_Resources') {
if (mw.config.get('wgIsProbablyEditable')) {
$('#wikiActions').show();
}
}
/*= Top header banner =*/
if (namespace === 14) {
var headbanner = document.getElementById("headbanner");
if (headbanner) {
var firstHeading = document.getElementById("firstHeading");
if (headbanner.hasAttribute("title")) {
if (headbanner.title == "auto") {
params = {
action: 'query',
list: 'categorymembers',
cmtitle: 'Category:Builds',
cmprop: 'ids',
cmtype: 'page',
cmlimit: '5000',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var pages = data.query.categorymembers,
page,
cat_random = Math.floor(Math.random() * pages.length),
id_random = pages[cat_random].pageid;
var paramsPI = {
action: 'query',
prop: 'pageimages',
pageids: id_random,
piprop: 'original',
format: 'json'
}
api.get( paramsPI ).done( function (data ) {
pageimage = data.query.pages[id_random].original;
padding = (pageimage.height / pageimage.width) * 100 + "%";
firstHeading.style.setProperty('--banner-padding', padding);
firstHeading.style.setProperty('--banner-image', 'url(' + pageimage.source + ')');
});
} );
} else {
firstHeading.style.setProperty('--banner-padding', headbanner.title);
firstHeading.style.setProperty('--banner-image', 'url(' + headbanner.textContent + ')');
}
}
firstHeading.classList.add('banner');
$("#siteSub").prepend($("#main > .content > .top"));
}
/** custom category page marker class
* added to firstHeading because requesting the page <body> (which normally has marker classes) on every category page load is
* not a good idea - its the parent for the whole page. The firstHeading is siblings with every other 1st child of the page content,
* which includes the div.top on pages with a top banner image set. (But this can be used on non-bannered cat pages as well)
*/
if ( mw.config.get('wgCategories').includes('Custom category pages') ) {
document.getElementById("firstHeading").classList.add("category-custom");
}
}
});
This page was last modified on 11 January 2023, at 14:17. (2 months ago)