MediaWiki:Chameleon.js: Difference between revisions

From Variscite Wiki
No edit summary
No edit summary
Line 1: Line 1:
const mq = window.matchMedia("(max-width: 1105px)");
/* Any JavaScript here will be loaded for all users on every page load. */
$(function() {
$('#mw-navigation .nav-item .nav-link').not('.dropdown-menu .nav-link').addClass('hvr-underline-from-center');
const products = $('#products-dropdown');
$('#products-menu > li').append(products);
$('#products-menu .dropdown-menu a.dropdown-toggle').on('click', function(e) {
  if (!$(this).next().hasClass('show')) {
$(this).parents('.dropdown-menu').first().find('.show').removeClass("show");
  }
  var $subMenu = $(this).next(".dropdown-menu");
  $subMenu.toggleClass('show');


$('a.ca-history').html('History').addClass('mr-2');
  $(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function(e) {
 
$('.dropdown-submenu .show').removeClass("show");
(function($, mw) {
  });
 
  return false;
$('<div>')
.addClass('back-top')
.html('<i class="fas fa-chevron-up"></i>')
.appendTo('.bodyContent')
.bind({
click: function(e) {
e.preventDefault();
$('html, body').animate({
scrollTop: "0"
});
}
});
 
$(window).scroll(function() {
if ($(this).scrollTop()) {
$('.back-top').css('visibility', 'visible');
} else {
$('.back-top').css('visibility', 'hidden');
}
});
});


})(jQuery, mw);
});
 
/**
* Offset the target heading on the height of the fixed elements.
*/
! function(window) {
'use strict';
 
// Update this function so it returns the height of your fixed headers
function fixedHeaderOffset() {
if (mq.matches) {
return 100;
} else {
return 50;
}
}
 
// Run on first scroll (in case the user loaded a page with a hash in the url)
window.addEventListener('scroll', onScroll);
 
function onScroll() {
window.removeEventListener('scroll', onScroll);
scrollUpToCompensateForFixedHeader();
}
 
// Run on hash change (user clicked on anchor link)
if ('onhashchange' in window) {
window.addEventListener('hashchange', scrollUpToCompensateForFixedHeader);
}
 
function scrollUpToCompensateForFixedHeader() {
var hash,
target,
offset;
 
// Get hash, e.g. #mathematics
hash = window.location.hash;
if (hash.length < 2) {
return;
}
 
// Get :target, e.g. &lt;h2 id="mathematics"&gt;...&lt;/h2&gt;
target = document.getElementById(hash.slice(1));
if (target === null) {
return;
}
 
// Get distance of :target from top of viewport. If it's near zero, we assume
// that the user was just scrolled to the :target.
if (target.getBoundingClientRect().top < 2) {
window.scrollBy(0, -fixedHeaderOffset());
}
}
 
}(window);

Revision as of 15:14, 2 November 2021

/* Any JavaScript here will be loaded for all users on every page load. */
$(function() {
	$('#mw-navigation .nav-item .nav-link').not('.dropdown-menu .nav-link').addClass('hvr-underline-from-center');
	
	const products = $('#products-dropdown');
	$('#products-menu > li').append(products);
	$('#products-menu .dropdown-menu a.dropdown-toggle').on('click', function(e) {
	  if (!$(this).next().hasClass('show')) {
		$(this).parents('.dropdown-menu').first().find('.show').removeClass("show");
	  }
	  var $subMenu = $(this).next(".dropdown-menu");
	  $subMenu.toggleClass('show');

	  $(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function(e) {
		$('.dropdown-submenu .show').removeClass("show");
	  });
	  return false;
	});

});