MediaWiki:Common.js: Difference between revisions

From ANZUS Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(10 intermediate revisions by the same user not shown)
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. */


/* Collapsible Icon Menu */
/*Upgrade Icon Menu*/
document.addEventListener("DOMContentLoaded", function() {
mw.loader.using(['jquery'], function() {
    var icons = document.querySelectorAll('.collapsible-icon');
$(document).ready(function(){
    var contents = document.querySelectorAll('.collapsible-content');
$('.upgrade-icon').click(function(e){
$('.upgrade-icon').removeClass('active-icon');
$(this).toggleClass('active-icon');
var id = $(this).attr('id');
$('.upgrade-content').hide();
$('#' + id + '.upgrade-content').show();
});
});
});


    if (icons.length === 0 || contents.length === 0) {
/*Accordions*/
        console.error("No icons or content sections found.");
mw.loader.using(['jquery'], function() {
        return;
$(document).ready(function(){
    }
$('.accordion-button').click(function(e){
 
$(this).toggleClass('active-accordion');
    icons.forEach(function(icon, index) {
var panel = $(this).next();
        function toggleContent() {
$(panel).toggle();
            console.log("Icon clicked:", index); // Debugging
});  
 
});
            // Remove 'active' class from all icons and content sections
            icons.forEach(function(icon) {
                icon.classList.remove('active');
            });
            contents.forEach(function(content) {
                content.classList.remove('active');
            });
 
            // Add 'active' class to the clicked icon and its corresponding content
            icons[index].classList.add('active');
            contents[index].classList.add('active');
        }
 
        icon.addEventListener('click', toggleContent);
        icon.addEventListener('touchstart', function(e) {
            e.preventDefault(); // Prevents default touch behavior
            toggleContent();
        });
    });
});
});

Latest revision as of 14:51, 12 June 2024

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

/*Upgrade Icon Menu*/
mw.loader.using(['jquery'], function() {
	$(document).ready(function(){
		$('.upgrade-icon').click(function(e){
			$('.upgrade-icon').removeClass('active-icon');
			$(this).toggleClass('active-icon');
				var id = $(this).attr('id');
			$('.upgrade-content').hide();
			$('#' + id + '.upgrade-content').show();
		}); 
	});
});

/*Accordions*/
mw.loader.using(['jquery'], function() {
	$(document).ready(function(){
		$('.accordion-button').click(function(e){
			$(this).toggleClass('active-accordion');
				var panel = $(this).next();
			$(panel).toggle();
		}); 
	});
});