Loading...

Hold on, just a second while we get things ready for you!

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
No edit summary
No edit summary
Line 61: Line 61:
     });
     });
});
});


$(document).ready(function() {
$(document).ready(function() {
  // Check if there are categories in the page
   var categories = mw.config.get('wgCategories');
   var categories = mw.config.get('wgCategories');


   // Define a mapping of categories to background images
   // Define a mapping of categories to arrays of background images
   var categoryBackgrounds = {
   var categoryBackgrounds = {
     'Dead Island': 'linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("https://www.chromengine.com/images/c/c9/DIBackground.jpg")',
     'Dead Island': [
     'Dying Light': 'linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("https://www.chromengine.com/images/2/26/Background.png")',
      'https://www.chromengine.com/images/5/5b/Dead_islan_background.png'
     'Call of Juarez: Gunslinger': 'linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.5)), url("https://www.chromengine.com/images/3/36/Random_project_call_of_juaez_gunslingerupscaled.png")',
    ],
     'Dead Island Riptide': 'linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.5)), url("https://www.chromengine.com/images/b/b6/Random_project_di_riptide_1.png")',
     'Dying Light': [
     'Call of Juarez: BiB': 'linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.5)), url("https://www.chromengine.com/images/2/24/Project_juaez_no_title_1.png")'
      'https://www.chromengine.com/images/2/26/Background.png'
    ],
     'Call of Juarez: Gunslinger': [
      'https://www.chromengine.com/images/3/36/Random_project_call_of_juaez_gunslingerupscaled.png'
    ],
     'Dead Island Riptide': [
      'https://www.chromengine.com/images/b/b6/Random_project_di_riptide_1.png'
    ],
     'Call of Juarez: BiB': [
      'https://www.chromengine.com/images/2/24/Project_juaez_no_title_1.png'
    ],
    'Call of Juarez: The Cartel': [
      'https://www.chromengine.com/images/6/64/Callofjuarezcartel.png'
    ],
    'Call of Juarez':[
      'https://www.chromengine.com/images/c/cf/Call_of_juarez_background_1.png',
      'https://www.chromengine.com/images/3/38/Call_of_juarez_background_2.png'
    ]
   };
   };


  // Default background image if no category matches
   var defaultBackgrounds = [
   var defaultBackground = 'linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("https://www.chromengine.com/images/8/89/Newbackground.png")';
    'https://www.chromengine.com/images/8/89/Newbackground.png',
 
   ];
   // Variable to check if a category matches
  var backgroundImageSet = false;


  // Preload function to cache the background images
   function preloadImage(url) {
   function preloadImage(url) {
     var img = new Image();
     var img = new Image();
Line 87: Line 102:
   }
   }


   // Preload the background images (this can also be done for the default image)
   // Preload all background images
   for (var category in categoryBackgrounds) {
   for (var category in categoryBackgrounds) {
     var imageUrl = categoryBackgrounds[category].match(/url\("([^"]+)"\)/)[1];
     categoryBackgrounds[category].forEach(preloadImage);
    preloadImage(imageUrl);
   }
   }
  defaultBackgrounds.forEach(preloadImage);


   // Preload the default background image
   function getRandomBackground(images) {
  preloadImage(defaultBackground.match(/url\("([^"]+)"\)/)[1]);
    return images[Math.floor(Math.random() * images.length)];
  }
 
  var backgroundImageSet = false;


   // Iterate through categories to find a matching background
   // Set a random background for the matching category
   categories.forEach(function(category) {
   categories.forEach(function(category) {
     if (categoryBackgrounds[category]) {
     if (categoryBackgrounds[category]) {
      var randomImage = getRandomBackground(categoryBackgrounds[category]);
       $('body').css({
       $('body').css({
         'background': categoryBackgrounds[category],
         'background': `linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("${randomImage}")`,
         'background-repeat': 'no-repeat',
         'background-repeat': 'no-repeat',
         'background-position': 'top center',
         'background-position': 'top center',
Line 112: Line 131:
   });
   });


  // If no category matched, apply the default background
   if (!backgroundImageSet) {
   if (!backgroundImageSet) {
    var randomDefault = getRandomBackground(defaultBackgrounds);
     $('body').css({
     $('body').css({
       'background-image': defaultBackground,
       'background': `linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("${randomDefault}")`,
       'background-repeat': 'no-repeat',
       'background-repeat': 'no-repeat',
       'background-position': 'top center',
       'background-position': 'top center',

Revision as of 20:19, 15 January 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.querySelectorAll('.sub-card').forEach(card => {
    card.addEventListener('click', function(event) {
        event.stopPropagation(); // Prevent event bubbling

        // Toggle the expanded state of the clicked card
        const isExpanded = card.getAttribute('data-expanded') === 'true';
        
        // Flip the current sub-card
        card.setAttribute('data-expanded', isExpanded ? 'false' : 'true');

        // Hide all other sub-cards
        document.querySelectorAll('.sub-card').forEach(otherCard => {
            if (otherCard !== card) {
                otherCard.setAttribute('data-expanded', 'false');
            }
        });
    });
});

document.querySelectorAll('.card').forEach(card => {
    card.addEventListener('mouseleave', function() {
        // Collapse all sub-cards when mouse leaves the main card
        document.querySelectorAll('.sub-card').forEach(subCard => {
            subCard.setAttribute('data-expanded', 'false');
        });
    });
});

$(document).ready(function() {
    // Click event for the header or the arrow
    $('.mw-collapsible-header').click(function() {
        var parentDiv = $(this).closest('.mw-collapsible');
        var content = parentDiv.find('.mw-collapsible-content');
        
        // Toggle the collapse/expand state
        parentDiv.toggleClass('mw-collapsed');
        
        // Toggle visibility of the content
        content.stop(true, true).slideToggle(); // Stop any ongoing animation before toggling visibility
    });

    // Ensure that the arrow starts pointing up for expanded sections by default
    $('.mw-collapsible').each(function() {
        var parentDiv = $(this);
        var content = parentDiv.find('.mw-collapsible-content');
        
        if (!parentDiv.hasClass('mw-collapsed')) {
            content.show(); // Ensure content is visible
        }
    });
});



$(document).ready(function() {
  var categories = mw.config.get('wgCategories');

  // Define a mapping of categories to arrays of background images
  var categoryBackgrounds = {
    'Dead Island': [
      'https://www.chromengine.com/images/5/5b/Dead_islan_background.png'
    ],
    'Dying Light': [
      'https://www.chromengine.com/images/2/26/Background.png'
    ],
    'Call of Juarez: Gunslinger': [
      'https://www.chromengine.com/images/3/36/Random_project_call_of_juaez_gunslingerupscaled.png'
    ],
    'Dead Island Riptide': [
      'https://www.chromengine.com/images/b/b6/Random_project_di_riptide_1.png'
    ],
    'Call of Juarez: BiB': [
      'https://www.chromengine.com/images/2/24/Project_juaez_no_title_1.png'
    ],
    'Call of Juarez: The Cartel': [
      'https://www.chromengine.com/images/6/64/Callofjuarezcartel.png'
    ],
    'Call of Juarez':[
      'https://www.chromengine.com/images/c/cf/Call_of_juarez_background_1.png',
      'https://www.chromengine.com/images/3/38/Call_of_juarez_background_2.png'
    ]
  };

  var defaultBackgrounds = [
    'https://www.chromengine.com/images/8/89/Newbackground.png',
  ];

  function preloadImage(url) {
    var img = new Image();
    img.src = url;
  }

  // Preload all background images
  for (var category in categoryBackgrounds) {
    categoryBackgrounds[category].forEach(preloadImage);
  }
  defaultBackgrounds.forEach(preloadImage);

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

  var backgroundImageSet = false;

  // Set a random background for the matching category
  categories.forEach(function(category) {
    if (categoryBackgrounds[category]) {
      var randomImage = getRandomBackground(categoryBackgrounds[category]);
      $('body').css({
        'background': `linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("${randomImage}")`,
        'background-repeat': 'no-repeat',
        'background-position': 'top center',
        'background-size': 'cover',
        'opacity': 30,
        'transition': 'opacity 0.5s ease',
        'background-attachment': 'fixed'
      });
      backgroundImageSet = true;
    }
  });

  if (!backgroundImageSet) {
    var randomDefault = getRandomBackground(defaultBackgrounds);
    $('body').css({
      'background': `linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("${randomDefault}")`,
      'background-repeat': 'no-repeat',
      'background-position': 'top center',
      'background-size': 'cover',
      'opacity': 30,
      'transition': 'opacity 0.5s ease',
      'background-attachment': 'fixed'
    });
  }
});
Cookies help us deliver our services. By using our services, you agree to our use of cookies.