MediaWiki

Common.js

From Dogcraft Wiki

No edit summary
m (document.document. is an error)
 
(81 intermediate revisions by 3 users not shown)
Line 2: Line 2:


/* Navigation Popups */
/* Navigation Popups */
/* Currently Disabled
/* Currently Disabled ü
mw.loader.load('/load.php?modules=ext.gadget.Navigation_popups');
mw.loader.load('/load.php?modules=ext.gadget.Navigation_popups');*/
window.popupAdminLinks = false;
window.popupAdminLinks = false;
window.popupActionsMenu = false;
window.popupActionsMenu = false;
Line 9: Line 9:
window.popupSubpopups = false;
window.popupSubpopups = false;
window.popupSummaryData = false;
window.popupSummaryData = false;
*/
 
function randomPageImage( category ) {
params = {
        action: 'query',
        list: 'categorymembers',
        cmtitle: 'Category:' + category,
        cmprop: 'ids',
        cmtype: 'page',
        cmlimit: '5000',
        format: 'json'
    },
    api = new mw.Api();
return new Promise(function(resolve,reject) {
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 ) {
        resolve(data.query.pages[id_random].original);
    });
} );
});
}


$(document).ready(function() {
$(document).ready(function() {
/*var goToDogcraft = document.querySelectorAll("#p-Go_to_Dogcraft > a");
var pagename = mw.config.get('wgPageName'),
goToDogcraft[0].setAttribute("href", "//dogcraft.net");*/
namespace = mw.config.get('wgNamespaceNumber');
$("#p-Go_to_Dogcraft > a").attr("href", "http://dogcraft.net");
// var indicator = document.querySelectorAll(".mw-indicators");
$("#p-Go_to_Dogcraft").removeClass("not-click has-dropdown");
// var indicator1 = indicator[0];
/* Pride Month topbar logo*/
// if (indicator1.childNodes.length !== 1) {document.getElementById("tagline").innerHTML = indicator1.innerHTML;}
$("#navwrapper .top-bar-logo").attr("src", "https://dogcraft.net/wiki/images/7/7a/Wiki_logo_pride.png");
var indicator = document.querySelectorAll(".mw-indicators");
/*== Hides the actions button and indicators while in the Visual editor ==*/
var indicator1 = indicator[0];
mw.hook( 've.activationComplete' ).add( function () {
$('.content .top').hide();
});
if (indicator1.childNodes.length !== 1) {document.getElementById("tagline").innerHTML = indicator1.innerHTML;}
mw.hook( 've.deactivationComplete' ).add( function () {
$('.content .top').show();
});
//$(".mw-dismissable-notice-close a").text('X');
/*== 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');
}
});
var dismissableNoticeClose = $(".mw-dismissable-notice-close");
/*== Shows edit button on Rules and Help Resources for those who can edit it ==*/
if (dismissableNoticeClose !== null) {
if (pagename === 'Rules' || pagename === 'Help_Resources') {
$(".dismissable-notice-close-message-container").append(dismissableNoticeClose);
if (mw.config.get('wgIsProbablyEditable')) {
$('#wikiActions').show();
}
}
}
/* FontAwesome v6. */
/* pagecount */
/* $("head").append('<script src="https://kit.fontawesome.com/4b7e90e654.js" crossorigin="anonymous"></script>'); */
var pagecount = document.createElement('div'),
link = document.createElement('a'),
pages = document.createElement('span'),
text = document.createElement('span'),
actions = document.getElementById('wikiActions'),
api = new mw.Api(),
num = api.get( {
action:"query",
meta:"siteinfo",
siprop:"statistics",
formatversion:"2"
});
/* Slick (license information and setup is included at https://dogcraft.net/wiki/MediaWiki:Gadget-slick.js)*/
pagecount.id = 'pagecount';
/*$("head").append('<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/[email protected]/slick/slick.css"/>');
link.href = "/wiki/Special:AllPages?namespace=0&hideredirects=1";
$("head").append('<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/[email protected].1/slick/slick-theme.css"/>');*/
text.textContent = 'pages';
$("body").append('<script type="text/javascript" src="//cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>');
$.when( num ).then( function ( data ) {
/* Points actions menu talk page buttons to a discord invite */
pages.textContent = data.query.statistics.articles;
$("#ca-talk > a[rel='discussion']").attr("href", "https://discord.com/invite/r5xDRcy/login")
link.append(pages, text);
.attr("title", "Discussion about the page on Discord [Alt+Shift+t]")
pagecount.append(link);
.attr("target", "_blank");
actions.parentNode.insertBefore(pagecount, actions);
mw.hook( 'userjs.pagecount.done' ).fire();
$('.slider').slick({
dots:true,
responsive: [
  {
  breakpoint: 640,
  settings: {
  arrows: false,
  slidesToShow: 1,
  centerMode: true
  }
  }
]
});
$('.slider-fade').slick({
dots:true,
fade:true,
responsive: [
  {
  breakpoint: 640,
  settings: {
  arrows: false,
  slidesToShow: 1,
  centerMode: true
  }
  }
]
});
$('.slider-center').slick({
  dots:true,
  centerMode: true,
  centerPadding: '60px',
  responsive: [
  {
  breakpoint: 640,
  settings: {
  arrows: false,
  slidesToShow: 1,
  centerMode: true
  }
  }
]
});
});
});
/*= Top header banner =*/
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0) {
var headbanner = document.getElementById("headbanner");
if (headbanner) {
var firstHeading = document.querySelectorAll("#content h1:first-of-type")[0];//document.getElementById("firstHeading");
if (headbanner.hasAttribute("title")) {
if (headbanner.title == "auto") {
randomPageImage(pagename.split(":")[1].split("/")[0]).then(function(result) {
firstHeading.style.setProperty('--banner-padding', "300px");
firstHeading.style.setProperty('--banner-image', 'url(' + result.source + ')');
});
} else {
firstHeading.style.setProperty('--banner-padding', headbanner.title);
firstHeading.style.setProperty('--banner-image', 'url(' + headbanner.textContent + ')');
}
}
firstHeading.classList.add('banner');
$("#contentSub").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.querySelectorAll("#content h1:first-of-type")[0].classList.add("category-custom");
}
}


//temp: move news-info indicator into pagecount's place
if ((mw.config.get('wgNamespaceNumber') === 3004) && (mw.config.get('wgUserName') == null)) {
$('#siteSub > .top')[0].classList.add('indicator-right');
}


/**
});
* Slick was created by Ken Wheeler.
* Website: https://kenwheeler.github.io/slick/
* This gadget was copied from: https://github.com/kenwheeler/slick/
*
* LICENSE:
* The MIT License (MIT)


Copyright (c) 2013-2016
//temp: move news-info indicator into pagecount's place
 
mw.hook( 'userjs.pagecount.done' ).add( function() {
Permission is hereby granted, free of charge, to any person obtaining a copy of
if ((mw.config.get('wgNamespaceNumber') === 3004) && ($(window).width() > 700) && (mw.config.get('wgUserName') != null)) {
this software and associated documentation files (the "Software"), to deal in
$("#pagecount").append($(".mw-indicators.mw-body-content"));
the Software without restriction, including without limitation the rights to
}
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
});
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
 
/*
    _ _      _      _
___| (_) ___| | __  (_)___
/ __| | |/ __| |/ /  | / __|
\__ \ | | (__|  < _ | \__ \
|___/_|_|\___|_|\_(_)/ |___/
                  |__/
Version: 1.8.1
  Author: Ken Wheeler
Website: http://kenwheeler.github.io
    Docs: http://kenwheeler.github.io/slick
    Repo: http://github.com/kenwheeler/slick
  Issues: http://github.com/kenwheeler/slick/issues
*/

Latest revision as of 02:45, 4 December 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:' + category,
	        cmprop: 'ids',
	        cmtype: 'page',
	        cmlimit: '5000',
	        format: 'json'
    },
    api = new mw.Api();
	
	return new Promise(function(resolve,reject) { 
		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 ) {
		        resolve(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();
		}
	}
	
	/* pagecount */
	var pagecount = document.createElement('div'),
		link = document.createElement('a'),
		pages = document.createElement('span'),
		text = document.createElement('span'),
		actions = document.getElementById('wikiActions'),
		api = new mw.Api(),
		num = api.get( {
			action:"query",
			meta:"siteinfo",
			siprop:"statistics",
			formatversion:"2"
		});
	
	pagecount.id = 'pagecount';
	link.href = "/wiki/Special:AllPages?namespace=0&hideredirects=1";
	text.textContent = 'pages';
	
	$.when( num ).then( function ( data ) {
		pages.textContent = data.query.statistics.articles;
		link.append(pages, text);
		pagecount.append(link);
	
		actions.parentNode.insertBefore(pagecount, actions);
		mw.hook( 'userjs.pagecount.done' ).fire();
	});
	
	/*= Top header banner =*/
	if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0) {
		var headbanner = document.getElementById("headbanner");
		if (headbanner) {
			var firstHeading = document.querySelectorAll("#content h1:first-of-type")[0];//document.getElementById("firstHeading");
			if (headbanner.hasAttribute("title")) { 
				if (headbanner.title == "auto") {
					randomPageImage(pagename.split(":")[1].split("/")[0]).then(function(result) {
						firstHeading.style.setProperty('--banner-padding', "300px");
						firstHeading.style.setProperty('--banner-image', 'url(' + result.source + ')');
					});
				} else {
					firstHeading.style.setProperty('--banner-padding', headbanner.title);
					firstHeading.style.setProperty('--banner-image', 'url(' + headbanner.textContent + ')');
				}
			}
			firstHeading.classList.add('banner');
			$("#contentSub").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.querySelectorAll("#content h1:first-of-type")[0].classList.add("category-custom");
		}
	}

	//temp: move news-info indicator into pagecount's place
	if ((mw.config.get('wgNamespaceNumber') === 3004) && (mw.config.get('wgUserName') == null)) {
		$('#siteSub > .top')[0].classList.add('indicator-right');
	}

});

//temp: move news-info indicator into pagecount's place
mw.hook( 'userjs.pagecount.done' ).add( function() {
	if ((mw.config.get('wgNamespaceNumber') === 3004) && ($(window).width() > 700) && (mw.config.get('wgUserName') != null)) {
		$("#pagecount").append($(".mw-indicators.mw-body-content")); 
	}
});
Background SRN Opening by Montenator