More actions
No edit summary |
No edit summary |
||
Line 240: | Line 240: | ||
document.addEventListener("DOMContentLoaded", function () { | document.addEventListener("DOMContentLoaded", function () { | ||
// Handle main and nested collapsible headers | // Handle collapsible headers (main and nested) | ||
function handleCollapsibleToggle(header) { | |||
let collapsible = header.nextElementSibling; | |||
let arrow = header.querySelector(".mw-collapsible-arrow"); | |||
// Toggle the collapsible section | |||
if (collapsible.style.display === "none" || collapsible.style.display === "") { | |||
collapsible.style.display = "block"; | |||
arrow.innerHTML = "▼"; // ▼ Down arrow (expanded state) | |||
arrow.style.transform = "rotate(0deg)"; // No rotation when expanded | |||
} else { | |||
collapsible.style.display = "none"; | |||
arrow.innerHTML = "▲"; // ▲ Up arrow (collapsed state) | |||
arrow.style.transform = "rotate(180deg)"; // Rotate 180 degrees when collapsed | |||
} | |||
} | |||
// Handle main collapsible headers | |||
document.querySelectorAll(".mw-collapsible-header").forEach(function (header) { | document.querySelectorAll(".mw-collapsible-header").forEach(function (header) { | ||
header.addEventListener("click", function () { | header.addEventListener("click", function () { | ||
handleCollapsibleToggle(header); | |||
}); | }); | ||
}); | }); | ||
// Handle nested | // Handle nested collapsible headers separately (independent logic) | ||
document.querySelectorAll(".mw-collapsible-content .mw-collapsible-header").forEach(function (header) { | document.querySelectorAll(".mw-collapsible-content .mw-collapsible-header").forEach(function (header) { | ||
header.addEventListener("click", function () { | header.addEventListener("click", function () { | ||
handleCollapsibleToggle(header); | |||
}); | }); | ||
}); | }); | ||
}); | }); |
Revision as of 11:01, 2 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() {
// 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://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',
'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/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.45), rgba(0, 0, 0, 0.45)), url("${randomImage}")`,
'background-repeat': 'no-repeat',
'background-position': 'top center',
'background-size': 'cover',
'opacity': 1,
'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.1), rgba(0, 0, 0, 0.1)), url("${randomDefault}")`,
'background-repeat': 'no-repeat',
'background-position': 'top center',
'background-size': 'cover',
'background-attachment': 'fixed'
});
}
});
$(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.addEventListener("DOMContentLoaded", function () {
// Handle collapsible headers (main and nested)
function handleCollapsibleToggle(header) {
let collapsible = header.nextElementSibling;
let arrow = header.querySelector(".mw-collapsible-arrow");
// Toggle the collapsible section
if (collapsible.style.display === "none" || collapsible.style.display === "") {
collapsible.style.display = "block";
arrow.innerHTML = "▼"; // ▼ Down arrow (expanded state)
arrow.style.transform = "rotate(0deg)"; // No rotation when expanded
} else {
collapsible.style.display = "none";
arrow.innerHTML = "▲"; // ▲ Up arrow (collapsed state)
arrow.style.transform = "rotate(180deg)"; // Rotate 180 degrees when collapsed
}
}
// Handle main collapsible headers
document.querySelectorAll(".mw-collapsible-header").forEach(function (header) {
header.addEventListener("click", function () {
handleCollapsibleToggle(header);
});
});
// Handle nested collapsible headers separately (independent logic)
document.querySelectorAll(".mw-collapsible-content .mw-collapsible-header").forEach(function (header) {
header.addEventListener("click", function () {
handleCollapsibleToggle(header);
});
});
});