Difference between revisions of "MediaWiki:Common.js"

From Innocent Witches
Jump to navigation Jump to search
Tag: Reverted
Tag: Manual revert
Line 1: Line 1:
function initDynamicShowHide() {
mw.loader.using('mediawiki.util').then(function() {
     function zselector( $content ) {
      
        var ActiveID = '';
function zselector( $content ) {
        $(function () {
    var ActiveID = '';
            $('[class|="cc"]').click(function () {
    $(function () {
                var cn = $(this).attr('class');
        $('[class|="cc"]').click(function () {
                if (typeof cn !== 'undefined') {
            var cn = $(this).attr('class');
                    ZContent(cn, '0');
            if (typeof cn !== 'undefined') {
                }
                ZContent(cn, '0');
            });
            }
            $('[class|="hh"]').mouseenter(function () {
        });
                var cn = $(this).attr('class');
        $('[class|="hh"]').mouseenter(function () {
                if (typeof cn !== 'undefined') {
            var cn = $(this).attr('class');
                    ZContent(cn, '1');
            if (typeof cn !== 'undefined') {
                }
                ZContent(cn, '1');
            });
            }
            $('[class|="hh"]').mouseleave(function () {
        });
                var cn = $(this).attr('class');
        $('[class|="hh"]').mouseleave(function () {
                if (typeof cn !== 'undefined') {
            var cn = $(this).attr('class');
                    ZContent(cn, '2');
            if (typeof cn !== 'undefined') {
                }
                ZContent(cn, '2');
            });
            }
            $('[class|="zz"]').each(function (i, elem) {
        });
                if ($(this).css('display') == 'none') {
        $('[class|="zz"]').each(function (i, elem) {
                    $(this).css('opacity', 0);
            if ($(this).css('display') == 'none') {
                }
                $(this).css('opacity', 0);
             });
             }
         });
         });
        function ZContent(classValue, effect) {
    });
            if (classValue.split) {
    function ZContent(classValue, effect) {
                var ID = '';
        if (classValue.split) {
                var elemClasses = classValue.split(' ');
            var ID = '';
                for (var i = 0; i < elemClasses.length; i++) {
            var elemClasses = classValue.split(' ');
                    var elemClass = elemClasses[i];
            for (var i = 0; i < elemClasses.length; i++) {
                    if (elemClass.substring(0, 3) == 'hh-' || elemClass.substring(0, 3) == 'cc-') {
                var elemClass = elemClasses[i];
                        ID = elemClass.substring(3);
                if (elemClass.substring(0, 3) == 'hh-' || elemClass.substring(0, 3) == 'cc-') {
                        if (effect == '0') {
                    ID = elemClass.substring(3);
                            ActiveID = ID;
                    if (effect == '0') {
                            ZEffect(ID);
                        ActiveID = ID;
                            SelectElem('cc', ID)
                        ZEffect(ID);
                            break;
                        SelectElem('cc', ID)
                        } else if (effect == '1') {
                        break;
                            ActiveID = ID;
                    } else if (effect == '1') {
                            ZEffect(ID);
                        ActiveID = ID;
                            SelectElem('hh', ID)
                        ZEffect(ID);
                            break;
                        SelectElem('hh', ID)
                        } else if (effect == '2') {
                        break;
                            ZEffect(ActiveID);
                    } else if (effect == '2') {
                            SelectElem('hh', ID);
                        ZEffect(ActiveID);
                            break;
                        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');
                }
            });
        }
     }
     }
    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 );
     mw.hook( 'wikipage.content' ).add( zselector );
     zselector( mw.util.$content );
     zselector( mw.util.$content );
}
});


// Динамическая кнопка "back to top"
$(document).ready(function(){
$(document).ready(function(){
    initDynamicShowHide();
});
function initBackToTop() {
     // Create the back to top button element
     // Create the back to top button element
     var backButton = $('<button id="back-to-top" title="Back to top"> </button>');
     var backButton = $('<button id="back-to-top" title="Back to top"> </button>');
Line 107: Line 103:
     // Smooth scroll to top when the button is clicked
     // Smooth scroll to top when the button is clicked
     backButton.click(function(){
     backButton.click(function(){
         $('html, body').animate({scrollTop : 0}, 800);
         $('html, body').animate({scrollTop : 0},800);
         return false;
         return false;
     });
     });
    window.addEventListener('scroll', function() {
        var toc = document.getElementById('toc');
        var bodyContent = document.getElementById('bodyContent');
        var scrollY = window.scrollY || window.pageYOffset;
        // Adjust the top position of the TOC based on scrolling
        if (scrollY > bodyContent.offsetTop) {
            toc.style.top = (scrollY - bodyContent.offsetTop) + 'px';
        } else {
            toc.style.top = '0';
        }
    });
}
$(document).ready(function(){
    initBackToTop();
});
});


window.addEventListener('scroll', function() {
    var toc = document.getElementById('toc');
    var bodyContent = document.getElementById('bodyContent');
    var scrollY = window.scrollY || window.pageYOffset;


 
    // Adjust the top position of the TOC based on scrolling
function initSlideshow() {
     if (scrollY > bodyContent.offsetTop) {
     const slideshows = document.querySelectorAll('.slideshow');
         toc.style.top = (scrollY - bodyContent.offsetTop) + 'px';
 
    } else {
    slideshows.forEach(slideshow => {
        toc.style.top = '0';
         const gallery = slideshow.querySelector('.gallery-slideshow');
     }
        const images = gallery.querySelectorAll('img');
        let currentSlide = 0;
 
        function showSlide(index) {
            images.forEach(image => {
                image.style.display = 'none';
            });
 
            images[index].style.display = 'block';
        }
 
        function nextSlide() {
            currentSlide = (currentSlide + 1) % images.length;
            showSlide(currentSlide);
        }
 
        // Automatically advance to the next slide every 5 seconds
        setInterval(nextSlide, 5000);
 
        // Show the first slide initially
        showSlide(currentSlide);
     });
}
 
$(document).ready(function(){
    initSlideshow();
});
});

Revision as of 06:27, 31 March 2024

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 );
});

// Динамическая кнопка "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;
    });
});

window.addEventListener('scroll', function() {
    var toc = document.getElementById('toc');
    var bodyContent = document.getElementById('bodyContent');
    var scrollY = window.scrollY || window.pageYOffset;

    // Adjust the top position of the TOC based on scrolling
    if (scrollY > bodyContent.offsetTop) {
        toc.style.top = (scrollY - bodyContent.offsetTop) + 'px';
    } else {
        toc.style.top = '0';
    }
});