Difference between revisions of "MediaWiki:Common.js"

From Innocent Witches
Jump to navigation Jump to search
Tag: Reverted
Tag: Reverted
Line 1: Line 1:
// Glowing Text Effect
function addGlowingEffect() {
  const elements = document.getElementsByClassName("glowing-text");
  for (let i = 0; i < elements.length; i++) {
    elements[i].classList.add("glowing");
  }
}
// Call the Function to Add Glowing Effect
addGlowingEffect();
// Back to Top Button
$(document).ready(function(){
    // Create the back to top button element
    var backButton = $('<button id="back-to-top" title="Back to top"> </button>');
   
    // Append the button to the body
    $('body').append(backButton);
   
    // Smooth scroll to top when the button is clicked
    backButton.click(function(){
        $('html, body').animate({scrollTop : 0},800);
        return false;
    });
});
mw.loader.using('mediawiki.util').then(function() {
mw.loader.using('mediawiki.util').then(function() {
      
      
Line 90: Line 116:
     mw.hook( 'wikipage.content' ).add( zselector );
     mw.hook( 'wikipage.content' ).add( zselector );
     zselector( mw.util.$content );
     zselector( mw.util.$content );
    // Add Glowing Effect to Text
    function addGlowingEffect() {
        const elements = document.getElementsByClassName("glowing-text");
        for (let i = 0; i < elements.length; i++) {
            elements[i].classList.add("glowing");
        }
    }
    // Call the Function to Add Glowing Effect
    addGlowingEffect();
});
// dynamic button "back to top"
$(document).ready(function(){
    // Create the back to top button element
    var backButton = $('<button id="back-to-top" title="Back to top"> </button>');
   
    // Append the button to the body
    $('body').append(backButton);
   
    // Smooth scroll to top when the button is clicked
    backButton.click(function(){
        $('html, body').animate({scrollTop : 0},800);
        return false;
    });
});
});

Revision as of 12:56, 31 March 2024

// Glowing Text Effect
function addGlowingEffect() {
  const elements = document.getElementsByClassName("glowing-text");
  for (let i = 0; i < elements.length; i++) {
    elements[i].classList.add("glowing");
  }
}

// Call the Function to Add Glowing Effect
addGlowingEffect();

// Back to Top Button
$(document).ready(function(){
    // Create the back to top button element
    var backButton = $('<button id="back-to-top" title="Back to top"> </button>');
    
    // Append the button to the body
    $('body').append(backButton);
    
    // Smooth scroll to top when the button is clicked
    backButton.click(function(){
        $('html, body').animate({scrollTop : 0},800);
        return false;
    });
});

mw.loader.using('mediawiki.util').then(function() {
    
    function zselector( $content ) {
        var ActiveID = '';
        $(function () {
            $('[class|="cc"]').click(function () {
                var cn = $(this).attr('class');
                if (typeof cn !== 'undefined') {
                    ZContent(cn, '0');
                }
            });
            $('[class|="hh"]').mouseenter(function () {
                var cn = $(this).attr('class');
                if (typeof cn !== 'undefined') {
                    ZContent(cn, '1');
                }
            });
            $('[class|="hh"]').mouseleave(function () {
                var cn = $(this).attr('class');
                if (typeof cn !== 'undefined') {
                    ZContent(cn, '2');
                }
            });
            $('[class|="zz"]').each(function (i, elem) {
                if ($(this).css('display') == 'none') {
                    $(this).css('opacity', 0);
                }
            });
        });
        function ZContent(classValue, effect) {
            if (classValue.split) {
                var ID = '';
                var elemClasses = classValue.split(' ');
                for (var i = 0; i < elemClasses.length; i++) {
                    var elemClass = elemClasses[i];
                    if (elemClass.substring(0, 3) == 'hh-' || elemClass.substring(0, 3) == 'cc-') {
                        ID = elemClass.substring(3);
                        if (effect == '0') {
                            ActiveID = ID;
                            ZEffect(ID);
                            SelectElem('cc', ID)
                            break;
                        } else if (effect == '1') {
                            ActiveID = ID;
                            ZEffect(ID);
                            SelectElem('hh', ID)
                            break;
                        } else if (effect == '2') {
                            ZEffect(ActiveID);
                            SelectElem('hh', ID);
                            break;
                        }
                    }
                }
            }
        }
        function ZEffect(ID) {
            $('[class|="zz"]').each(function (i, elem) {
                if ($(this).hasClass('zz-' + ID)) {
                    $(this).css('display', 'block');
                    $(window).trigger('scroll');
                    $(this).stop();
                    $(this).animate({
                        opacity: 1,
                        queue: false
                    }, 700);
                } else {
                    $(this).css('display', 'none');
                    $(this).stop();
                    $(this).animate({
                        opacity: 0,
                        queue: false
                    }, 0);
                }
            });
        }
        function SelectElem(type, ID) {
            $('[class|="cc"],[class|="hh"]').each(function (i, elem) {
                if ($(this).hasClass(type + '-' + ID)) {
                    $(this).removeClass('sn');
                    $(this).addClass('sy');
                } else {
                    $(this).removeClass('sy');
                    $(this).addClass('sn');
                }
            });
        }
    }
    
    mw.hook( 'wikipage.content' ).add( zselector );
    zselector( mw.util.$content );
});