Difference between revisions of "MediaWiki:Common.js"

m (Replaced content with "Any JavaScript here will be loaded for all users on every page load.: ")
m
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
 +
 +
 +
var slideIndex = 1;
 +
showDivs(slideIndex);
 +
 +
function plusDivs(n) {
 +
  showDivs(slideIndex += n);
 +
}
 +
 +
function currentDiv(n) {
 +
  showDivs(slideIndex = n);
 +
}
 +
 +
function stopVideos() {
 +
var videos = document.querySelectorAll('iframe, video');
 +
Array.prototype.forEach.call(videos, function (video) {
 +
if (video.tagName.toLowerCase() === 'video') {
 +
video.pause();
 +
} else {
 +
var src = video.src;
 +
video.src = src;
 +
}
 +
});
 +
}
 +
 +
function showDivs(n) {
 +
  stopVideos();
 +
  var i;
 +
  var x = document.getElementsByClassName("vslide");
 +
  var dots = document.getElementsByClassName("vscap");
 +
  if (n > x.length) {slideIndex = 1}   
 +
  if (n < 1) {slideIndex = x.length}
 +
  for (i = 0; i < x.length; i++) {
 +
    x[i].style.display = "none";
 +
  }
 +
  for (i = 0; i < dots.length; i++) {
 +
    dots[i].className = dots[i].className.replace(" btn-special", "");
 +
  }
 +
  x[slideIndex-1].style.display = "block"; 
 +
  dots[slideIndex-1].className += " btn-special";
 +
}

Revision as of 12:29, 26 July 2023

/* Any JavaScript here will be loaded for all users on every page load. */


var slideIndex = 1;
showDivs(slideIndex);

function plusDivs(n) {
  showDivs(slideIndex += n);
}

function currentDiv(n) {
  showDivs(slideIndex = n);
}

function stopVideos() {
	var videos = document.querySelectorAll('iframe, video');
	Array.prototype.forEach.call(videos, function (video) {
		if (video.tagName.toLowerCase() === 'video') {
			video.pause();
		} else {
			var src = video.src;
			video.src = src;
		}
	});
}

function showDivs(n) {
  stopVideos();
  var i;
  var x = document.getElementsByClassName("vslide");
  var dots = document.getElementsByClassName("vscap");
  if (n > x.length) {slideIndex = 1}    
  if (n < 1) {slideIndex = x.length}
  for (i = 0; i < x.length; i++) {
    x[i].style.display = "none";
  }
  for (i = 0; i < dots.length; i++) {
    dots[i].className = dots[i].className.replace(" btn-special", "");
  }
  x[slideIndex-1].style.display = "block";  
  dots[slideIndex-1].className += " btn-special";
}