Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
mNo edit summary
mNo edit summary
Line 13: Line 13:


$(document).ready(function () {
$(document).ready(function () {
     // Create a new body element with a loading screen
     // Ensure the body is initially hidden but visible
     var newBody = $('<body id="loading-screen-body">');
     $('html').css('visibility', 'visible');
     $('html').append(newBody);
     $('body').css({
        'opacity': '0',
        'transition': 'opacity 0.5s ease-in-out'
    });


     // Create the loading screen HTML
     // Create the loading screen
     $('#loading-screen-body').append(`
     const loadingScreen = $(`
         <div id="loading-screen">
         <div id="loading-screen">
             <div class="loading-circle"></div>
             <div class="loading-circle"></div>
             <p id="loading-message">Loading...</p>
             <p id="loading-message">Loading...</p>
         </div>
         </div>
     `);
     `).appendTo('body');


     // Set up the loading screen CSS
     // Apply styles for the loading screen
     $('#loading-screen').css({
     $('#loading-screen').css({
         position: 'fixed',
         position: 'fixed',
Line 42: Line 45:
     });
     });


    // Create the loading circle CSS
     $('.loading-circle').css({
     $('.loading-circle').css({
         width: '50px',
         width: '50px',
Line 52: Line 54:
     });
     });


    // Style the loading message
     $('#loading-message').css({
     $('#loading-message').css({
         marginTop: '10px',
         marginTop: '10px',
Line 59: Line 60:
     });
     });


    // Keyframes for the loading circle animation
     $('head').append(`
     $('head').append(`
         <style>
         <style>
Line 69: Line 69:
     `);
     `);


     // Set up the categories and background images (same as before)
     // Handle first-time visits
    const firstVisitMessages = [
        "Uh oh, I've never seen you here before, let me preload some stuff first...",
        "Welcome to the Chrome Engine Modding Wiki! Oh, seems like I need to load a bit...",
        "A new explorer? Give me a moment to set things up!"
    ];
 
    const randomMessages = [
        "Just a moment, let me load a few things for you...",
        "Hang tight, your content is almost ready!",
        "Loading your next page, please be patient...",
        "A few more things to load, thanks for waiting!"
    ];
 
    let loadingMessage = localStorage.getItem("visitedBefore") ?
        randomMessages[Math.floor(Math.random() * randomMessages.length)] :
        firstVisitMessages[Math.floor(Math.random() * firstVisitMessages.length)];
 
    $('#loading-message').text(loadingMessage);
    localStorage.setItem("visitedBefore", "true");
 
    // Function to fade in content after loading
    function hideLoadingScreen() {
        $('#loading-screen').fadeOut(500, function () {
            $(this).remove();
        });
        $('body').css('opacity', '1');
    }
 
    // Wait for everything to load, then remove loading screen
    $(window).on('load', function () {
        setTimeout(hideLoadingScreen, 500);
    });
 
    // Category-based background handling
     var categories = mw.config.get('wgCategories');
     var categories = mw.config.get('wgCategories');
     var categoryBackgrounds = {
     var categoryBackgrounds = {
Line 96: Line 130:


     var defaultBackgrounds = ['https://cemodding.wiki/images/1/1f/Wiki_page.png'];
     var defaultBackgrounds = ['https://cemodding.wiki/images/1/1f/Wiki_page.png'];
 
     let selectedBackground = null;
     function preloadImage(url) {
        var img = new Image();
        img.src = url;
    }
 
    // Preload all background images
    Object.values(categoryBackgrounds).flat().forEach(preloadImage);
    defaultBackgrounds.forEach(preloadImage);


     function getRandomBackground(images) {
     function getRandomBackground(images) {
         return images[Math.floor(Math.random() * images.length)];
         return images[Math.floor(Math.random() * images.length)];
     }
     }
    // Store background for this session
    let selectedBackground = null;


     function applyBackground() {
     function applyBackground() {
Line 118: Line 141:


         if (isLightMode) {
         if (isLightMode) {
            // Light mode background
             $('body').css({
             $('body').css({
                 'background': 'url("https://cemodding.wiki/images/c/c8/Lightgreybackground.png")',
                 'background': 'url("https://cemodding.wiki/images/c/c8/Lightgreybackground.png")',
Line 127: Line 149:
             });
             });
         } else {
         } else {
            // If background is already selected, don't change it
             if (!selectedBackground) {
             if (!selectedBackground) {
                // Pick a random category background
                 for (let category of categories) {
                 for (let category of categories) {
                     if (categoryBackgrounds[category]) {
                     if (categoryBackgrounds[category]) {
Line 136: Line 156:
                     }
                     }
                 }
                 }
                // If no category-specific background, use default
                 if (!selectedBackground) {
                 if (!selectedBackground) {
                     selectedBackground = getRandomBackground(defaultBackgrounds);
                     selectedBackground = getRandomBackground(defaultBackgrounds);
Line 143: Line 161:
             }
             }


            // Apply background (fixed, no random changes while on page)
             $('body').css({
             $('body').css({
                 'background': `linear-gradient(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.15)), url("${selectedBackground}")`,
                 'background': `linear-gradient(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.15)), url("${selectedBackground}")`,
Line 154: Line 171:
     }
     }


    // Apply the background on page load
     applyBackground();
     applyBackground();


    // Observe theme switch (Light/Dark mode toggle)
     const observer = new MutationObserver(() => {
     const observer = new MutationObserver(() => {
         setTimeout(() => applyBackground(), 50); // Prevent flicker
         setTimeout(applyBackground, 50);
     });
     });


     observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
     observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });


     // Show loading screen until everything is ready
     // Make sure internal links trigger the loading screen
     $('#loading-screen').fadeIn();
     $(document).on("click", "a[href^='https://cemodding.wiki/']", function (event) {
 
         showLoadingScreen();
    // Wait for all images to load
    var imagesToLoad = [...Object.values(categoryBackgrounds).flat(), ...defaultBackgrounds];
    var loadedImages = 0;
 
    imagesToLoad.forEach(function (imageUrl) {
         var img = new Image();
        img.onload = function () {
            loadedImages++;
            if (loadedImages === imagesToLoad.length) {
                // Once all images are loaded, fade out the loading screen
                $('#loading-screen').fadeOut(1000);
                // Now that everything is ready, remove the custom body and let MediaWiki's content load
                $('#loading-screen-body').remove();
            }
        };
        img.src = imageUrl;
     });
     });
});


    // First-time visit message
    if (localStorage.getItem('firstVisit') === null) {
        localStorage.setItem('firstVisit', 'true');
        var welcomeMessages = [
            "Uh oh I have never seen you here before, let me preload some stuff first",
            "Welcome to the Chrome Engine Modding Wiki, oh it seems I have to load for a while"
        ];
        var randomMessage = welcomeMessages[Math.floor(Math.random() * welcomeMessages.length)];
        $('#loading-message').text(randomMessage);
    } else {
        // Random messages for subsequent visits
        var randomMessages = [
            "Just a moment, let me load a few things for you",
            "Hang tight, your content is almost ready!",
            "Loading your next page, please be patient",
            "A few more things to load, thanks for waiting!"
        ];
        var randomMessage = randomMessages[Math.floor(Math.random() * randomMessages.length)];
        $('#loading-message').text(randomMessage);
    }
});





Revision as of 20:37, 10 February 2025

/* Any JavaScript here will be loaded for all users on every page load. */
 $(function(){
  $('.card').on('mousenter', function(event){
    event.preventDefault();
    $(this).toggleClass('hovered');
  });
   $('.card').on('mouseleave', function(event){
    event.preventDefault();
    $(this).toggleClass('hovered');
  });
});


$(document).ready(function () {
    // Ensure the body is initially hidden but visible
    $('html').css('visibility', 'visible');
    $('body').css({
        'opacity': '0',
        'transition': 'opacity 0.5s ease-in-out'
    });

    // Create the loading screen
    const loadingScreen = $(`
        <div id="loading-screen">
            <div class="loading-circle"></div>
            <p id="loading-message">Loading...</p>
        </div>
    `).appendTo('body');

    // Apply styles for the loading screen
    $('#loading-screen').css({
        position: 'fixed',
        top: 0,
        left: 0,
        width: '100%',
        height: '100%',
        background: 'white',
        display: 'flex',
        flexDirection: 'column',
        justifyContent: 'center',
        alignItems: 'center',
        zIndex: 9999,
        opacity: 1,
        transition: 'opacity 0.3s ease-in-out'
    });

    $('.loading-circle').css({
        width: '50px',
        height: '50px',
        border: '5px solid rgba(0, 0, 0, 0.2)',
        borderTop: '5px solid black',
        borderRadius: '50%',
        animation: 'spin 1s linear infinite'
    });

    $('#loading-message').css({
        marginTop: '10px',
        fontSize: '18px',
        color: 'black'
    });

    $('head').append(`
        <style>
            @keyframes spin {
                0% { transform: rotate(0deg); }
                100% { transform: rotate(360deg); }
            }
        </style>
    `);

    // Handle first-time visits
    const firstVisitMessages = [
        "Uh oh, I've never seen you here before, let me preload some stuff first...",
        "Welcome to the Chrome Engine Modding Wiki! Oh, seems like I need to load a bit...",
        "A new explorer? Give me a moment to set things up!"
    ];

    const randomMessages = [
        "Just a moment, let me load a few things for you...",
        "Hang tight, your content is almost ready!",
        "Loading your next page, please be patient...",
        "A few more things to load, thanks for waiting!"
    ];

    let loadingMessage = localStorage.getItem("visitedBefore") ? 
        randomMessages[Math.floor(Math.random() * randomMessages.length)] :
        firstVisitMessages[Math.floor(Math.random() * firstVisitMessages.length)];

    $('#loading-message').text(loadingMessage);
    localStorage.setItem("visitedBefore", "true");

    // Function to fade in content after loading
    function hideLoadingScreen() {
        $('#loading-screen').fadeOut(500, function () {
            $(this).remove();
        });
        $('body').css('opacity', '1');
    }

    // Wait for everything to load, then remove loading screen
    $(window).on('load', function () {
        setTimeout(hideLoadingScreen, 500);
    });

    // Category-based background handling
    var categories = mw.config.get('wgCategories');
    var categoryBackgrounds = {
        'Dead Island': ['https://cemodding.wiki/images/5/5b/Dead_islan_background.png'],
        'Dying Light': ['https://cemodding.wiki/images/f/fe/Dying_light.png'],
        'Call of Juarez: Gunslinger': ['https://cemodding.wiki/images/4/4b/Call_of_juaez_gunslinger.png'],
        'Dead Island Riptide': ['https://cemodding.wiki/images/b/b6/Random_project_di_riptide_1.png'],
        'Dead Island Riptide DE': ['https://cemodding.wiki/images/0/09/Dead_island_riptide_DE.png'],
        'Call of Juarez: BiB': ['https://cemodding.wiki/images/2/24/Project_juaez_no_title_1.png'],
        'Call of Juarez: The Cartel': ['https://cemodding.wiki/images/6/64/Callofjuarezcartel.png'],
        'Call of Juarez': [
            'https://cemodding.wiki/images/c/cf/Call_of_juarez_background_1.png',
            'https://cemodding.wiki/images/3/38/Call_of_juarez_background_2.png'
        ],
        'Dead Island DE': ['https://cemodding.wiki/images/4/45/Dead_island_DE.png'],
        'Dying Light: The Beast': [
            'https://cemodding.wiki/images/1/12/Dying_light_the_beast.png',
            'https://cemodding.wiki/images/c/c3/Dying_light_the_beast_2.png'
        ],
        'Dying Light 2': [
            'https://cemodding.wiki/images/0/04/Dying_light_2.png',
            'https://cemodding.wiki/images/0/02/Dying_light_2_.png',
            'https://cemodding.wiki/images/3/3f/Dying_light_2_some_layered_effects.png'
        ]
    };

    var defaultBackgrounds = ['https://cemodding.wiki/images/1/1f/Wiki_page.png'];
    let selectedBackground = null;

    function getRandomBackground(images) {
        return images[Math.floor(Math.random() * images.length)];
    }

    function applyBackground() {
        const htmlElement = document.documentElement;
        const isLightMode = htmlElement.classList.contains("skin-citizen-light");

        if (isLightMode) {
            $('body').css({
                'background': 'url("https://cemodding.wiki/images/c/c8/Lightgreybackground.png")',
                'background-repeat': 'no-repeat',
                'background-position': 'top center',
                'background-size': 'cover',
                'background-attachment': 'fixed'
            });
        } else {
            if (!selectedBackground) {
                for (let category of categories) {
                    if (categoryBackgrounds[category]) {
                        selectedBackground = getRandomBackground(categoryBackgrounds[category]);
                        break;
                    }
                }
                if (!selectedBackground) {
                    selectedBackground = getRandomBackground(defaultBackgrounds);
                }
            }

            $('body').css({
                'background': `linear-gradient(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.15)), url("${selectedBackground}")`,
                'background-repeat': 'no-repeat',
                'background-position': 'top center',
                'background-size': 'cover',
                'background-attachment': 'fixed'
            });
        }
    }

    applyBackground();

    const observer = new MutationObserver(() => {
        setTimeout(applyBackground, 50);
    });

    observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });

    // Make sure internal links trigger the loading screen
    $(document).on("click", "a[href^='https://cemodding.wiki/']", function (event) {
        showLoadingScreen();
    });
});




















$(function () {
    var categoryList = [];

    // Fetch categories from the API
    $.ajax({
        url: mw.util.wikiScript('api'),
        data: {
            action: 'query',
            list: 'allcategories',
            aclimit: '500',
            format: 'json'
        },
        dataType: 'json',
        success: function (data) {
            categoryList = data.query.allcategories.map(function (cat) {
                return cat['*'];
            });
        }
    });

    function createSuggestionBox(input, suggestions, cursorPosition) {
        $('.category-suggestions').remove(); // Clear old suggestions

        var suggestionBox = $('<ul class="category-suggestions"></ul>').css({
            position: 'absolute',
            zIndex: 1000,
            backgroundColor: 'rgba(0, 0, 0, 0.7)',
            color: 'white',
            border: '1px solid #ccc',
            padding: '0',
            listStyleType: 'none',
            margin: '0',
            maxHeight: '200px',
            overflowY: 'auto',
            cursor: 'pointer'
        });

        suggestions.forEach(function (suggestion) {
            var item = $('<li></li>').text(suggestion).css({ padding: '5px' });
            item.on('mousedown', function () {
                var text = input.val();
                var beforeCursor = text.substring(0, cursorPosition).replace(/\[\[Category:[^\]]*$/, '[[Category:' + suggestion);
                var afterCursor = text.substring(cursorPosition);
                input.val(beforeCursor + afterCursor);
                suggestionBox.remove();
            });
            suggestionBox.append(item);
        });

        $('body').append(suggestionBox);
        positionSuggestionBox(input, cursorPosition, suggestionBox);
    }

    function positionSuggestionBox(input, cursorPos, suggestionBox) {
        var text = input.val().substring(0, cursorPos);
        var textarea = input[0];
        var div = $('<div></div>').css({
            position: 'absolute',
            whiteSpace: 'pre-wrap',
            wordWrap: 'break-word',
            visibility: 'hidden',
            font: input.css('font'),
            padding: input.css('padding'),
            width: input.width(),
            lineHeight: input.css('line-height')
        }).appendTo('body');
        
        // Simulate the text up to the cursor
        var beforeCursorText = text.replace(/ /g, '\u00a0');  // Non-breaking spaces for correct width
        div.text(beforeCursorText);
        var span = $('<span>|</span>').appendTo(div);  // Add a cursor marker
        var cursorOffset = span.offset();

        // Adjust position to match textarea
        var inputOffset = input.offset();
        suggestionBox.css({
            top: inputOffset.top + (cursorOffset.top - div.offset().top) + parseInt(input.css('padding-top'), 10),
            left: inputOffset.left + (cursorOffset.left - div.offset().left) + parseInt(input.css('padding-left'), 10)
        });

        div.remove();
    }

    $('#wpTextbox1').on('input', function () {
        var input = $(this);
        var cursorPos = this.selectionStart;
        var text = input.val().substring(0, cursorPos);
        var match = text.match(/\[\[Category:([^\]]*)$/);
        if (match) {
            var partial = match[1].toLowerCase();
            var matches = categoryList.filter(function (category) {
                return category.toLowerCase().startsWith(partial);
            }).slice(0, 10);  // Limit suggestions
            if (matches.length) {
                createSuggestionBox(input, matches, cursorPos);
            }
        } else {
            $('.category-suggestions').remove();
        }
    });

    $(document).on('mousedown', function (e) {
        if (!$(e.target).closest('.category-suggestions').length) {
            $('.category-suggestions').remove();
        }
    });
});

$(document).ready(function() {
    $('.mw-collapsible-header').each(function() {
        // Wrap indicator and spinner inside a container for positioning
        $(this).prepend('<span class="mw-collapsible-icon"><span class="mw-collapsible-indicator">•</span><span class="mw-collapsible-loading hidden"></span></span> ');
    });

    $('.mw-collapsible-header').click(function() {
        var parentDiv = $(this).closest('.mw-collapsible');
        var content = parentDiv.find('.mw-collapsible-content');
        var indicator = $(this).find('.mw-collapsible-indicator');
        var spinner = $(this).find('.mw-collapsible-loading');

        // Fade out indicator and show spinner at the same position
        indicator.addClass('fade-out');
        setTimeout(() => {
            spinner.removeClass('hidden');
        }, 100);

        // Toggle content visibility
        parentDiv.toggleClass('mw-collapsed');
        content.stop(true, true).slideToggle();

        // Restore indicator and hide spinner after animation
        setTimeout(function() {
            indicator.removeClass('fade-out');
            spinner.addClass('hidden');
        }, 300);
    });

    // Ensure correct initial state for collapsibles
    $('.mw-collapsible').each(function() {
        var parentDiv = $(this);
        var content = parentDiv.find('.mw-collapsible-content');

        if (parentDiv.hasClass('mw-collapsed')) {
            content.hide();
        } else {
            content.show();
        }
    });
});
Cookies help us deliver our services. By using our services, you agree to our use of cookies.