MediaWiki:Common.js: Difference between revisions

From e-girl wiki
No edit summary
m Protected "MediaWiki:Common.js" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))
 
(One intermediate revision 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. */


$(document).ready(function() {
    // Handle the toggle for all collapsible galleries
    $('.showhidetext').on('click', function() {
        var $toggleLink = $(this);
        var $toggleDefault = $toggleLink.find('.toggle-default');
        var $toggleShow = $toggleLink.find('.toggle-show');
       
        // Toggle visibility of the expand/collapse text
        if ($toggleDefault.is(':visible')) {
            $toggleDefault.hide();
            $toggleShow.show();
        } else {
            $toggleDefault.show();
            $toggleShow.hide();
        }
    });
    // Initialize the state of all galleries
    $('.mw-collapsible').each(function() {
        var $collapsible = $(this);
        var $toggleLink = $('#toggle-' + $collapsible.attr('id'));
        var $toggleDefault = $toggleLink.find('.toggle-default');
        var $toggleShow = $toggleLink.find('.toggle-show');
        if ($collapsible.hasClass('mw-collapsed')) {
            $toggleDefault.show();
            $toggleShow.hide();
        } else {
            $toggleDefault.hide();
            $toggleShow.show();
        }
    });
});




Line 143: Line 109:
     });
     });
}
}
/* Collapsible toggle */
$(document).ready(function() {
$(".collapsibletoggletext").click(function() {
$(this).parent().children(".collapsibletoggletext").toggleClass("hiddentext");
});
});
/* Cycle forwards or backwards through elements one at a time via click */
$(function(){
    $(".cyclesequence").find(".cyclesequencelinknext").click(function(){
        if ($(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").next(".cyclesequenceitem").length === 0) {
            $(this).closest(".cyclesequence").find(".cyclesequenceitem:first").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
      }
      else {
          $(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").next(".cyclesequenceitem").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
        }
    });
    $(".cyclesequence").find(".cyclesequencelinkprev").click(function(){
        if ($(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").prev(".cyclesequenceitem").length === 0) {
            $(this).closest(".cyclesequence").find(".cyclesequenceitem:last").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
      }
      else {
          $(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").prev(".cyclesequenceitem").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
        }
    });
});

Latest revision as of 01:52, 14 August 2024

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



/* Cycle forwards or backwards through elements one at a time via click */

$(function(){
    $(".cyclesequence").find(".cyclesequencelinknext").click(function(){
        if ($(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").next(".cyclesequenceitem").length === 0) {
            $(this).closest(".cyclesequence").find(".cyclesequenceitem:first").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
       }
       else {
           $(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").next(".cyclesequenceitem").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
         }
    });
    $(".cyclesequence").find(".cyclesequencelinkprev").click(function(){
        if ($(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").prev(".cyclesequenceitem").length === 0) {
            $(this).closest(".cyclesequence").find(".cyclesequenceitem:last").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
       }
       else {
           $(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").prev(".cyclesequenceitem").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
         }
    });
});

/* Click link to show one or more items and hide other items */

$(function() {
	$(".morphlink").click(function() {
		var correspondingContent = $(this).data("correspondingcontent");
		if ($(this).parents(".morphcontainer").length) {
			$(this).parents(".morphcontainer").find(".morphcontent").addClass("hiddentext");
			if ($("#" + correspondingContent).length) // morphing object uses IDs
				$("#" + correspondingContent).removeClass("hiddentext");
			else // morphing object uses classes
				$("." + correspondingContent).removeClass("hiddentext");
		}
		else {
			if ($("#" + correspondingContent).length) { // morphing object uses IDs
				$("#" + correspondingContent).removeClass("hiddentext");
				$("#" + correspondingContent).siblings().filter($(".morphcontent")).addClass("hiddentext");
			}
			else { // morphing object uses classes
				$("." + correspondingContent).removeClass("hiddentext");
				$("." + correspondingContent).siblings().filter($(".morphcontent")).addClass("hiddentext");
			}
		}
	});
});

/* Legacy collapse code. Being kept for backwards compatibility.
   Based on WhiteMystery's original script, but jQuery-fied. */

function createLegacyCollapsibles() {
	var allElements = $("span");
	var collapsibleRegex = new RegExp("^co;(.+?);(.+?);(.+?);(.+?)(;(.+?))?$");
	for (var i = 0; i < allElements.length; i++) {
		if (collapsibleRegex.test(allElements[i].className)) {
			console.warn("co; is deprecated. Use collapsibletoggle instead.");
			var collapsibleValues = collapsibleRegex.exec(allElements[i].className);
			var collapseText = collapsibleValues[1];
			var expandText = collapsibleValues[2];
			var defaultState = collapsibleValues[3];
			var correspondingContent = collapsibleValues[4];
			var toggleColor = collapsibleValues[6];
			var collapsibleContent = $("." + correspondingContent);
			var toggleLink;
			allElements[i].innerHTML = "<a class=\"collapsibletoggle legacycollapsible\" data-collapsetext=\"" + collapseText + "\" data-expandtext=\"" + expandText + "\" data-correspondingcontent=\"" + correspondingContent + "\"></a>";
			toggleLink = $(allElements[i]).find("a");
			if (defaultState == "0") {
				toggleLink[0].innerHTML = expandText;
				collapsibleContent[0].className += " hiddentext";
			}
			else
				toggleLink[0].innerHTML = collapseText;
			if (toggleColor)
				toggleLink[0].style.color = toggleColor;
		}
	}
}

$(document).ready(function() {
	createLegacyCollapsibles();
	$(".legacycollapsible").click(function() {
		var expandText = $(this).data("expandtext");
		var collapseText = $(this).data("collapsetext");
		var correspondingContent = $(this).data("correspondingcontent");
		$("." + correspondingContent).toggleClass("hiddentext");
		if ($(this).text() == expandText)
			$(this).text(collapseText);
		else
			$(this).text(expandText);
	});
});


// Ensure the script runs only in the Minerva skin
if (mw.config.get('skin') === 'minerva') {
    mw.loader.using('mobile.startup', function() {
        // Expand all sections by default
        var sections = document.querySelectorAll('.collapsible-block');
        sections.forEach(function(section) {
            var header = section.querySelector('.block-head');
            if (header && section.classList.contains('collapsed')) {
                // Click the header to expand the section
                header.click();
            }
        });
    });
}

/* Collapsible toggle */

$(document).ready(function() {
	$(".collapsibletoggletext").click(function() {
		$(this).parent().children(".collapsibletoggletext").toggleClass("hiddentext");
	});
});

/* Cycle forwards or backwards through elements one at a time via click */

$(function(){
    $(".cyclesequence").find(".cyclesequencelinknext").click(function(){
        if ($(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").next(".cyclesequenceitem").length === 0) {
            $(this).closest(".cyclesequence").find(".cyclesequenceitem:first").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
       }
       else {
           $(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").next(".cyclesequenceitem").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
         }
    });
    $(".cyclesequence").find(".cyclesequencelinkprev").click(function(){
        if ($(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").prev(".cyclesequenceitem").length === 0) {
            $(this).closest(".cyclesequence").find(".cyclesequenceitem:last").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
       }
       else {
           $(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").prev(".cyclesequenceitem").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
         }
    });
});