Spaces:
Running
// Build Calculator and Utility Handling
Browse filesdocument.addEventListener('DOMContentLoaded', function() {
const buildForm = document.getElementById('build-form');
const previewElements = {
toon: document.getElementById('preview-toon'),
buildName: document.getElementById('preview-build-name'),
trinkets: document.getElementById('preview-trinkets'),
rationale: document.getElementById('preview-rationale'),
ratingSection: document.getElementById('build-rating')
};
// --- Configuration Maps ---
const config = {
toonNames: { 'vee': 'Vee', 'pebble': 'Pebble', 'sprout': 'Sprout', 'shelly': 'Shelly' },
goalNames: { 'ichor': 'Ichor Farming', 'survival': 'Solo Survival', 'research': 'Research Farming', 'support': 'Team Support' },
trinketNames: { 'remote': "Vee's Remote", 'magnifying': 'Magnifying Glass', 'plush': 'Dandy Plush', 'bow': 'Pink Bow' }
};
if (buildForm) {
// --- Real-time Preview Update ---
buildForm.addEventListener('input', function() {
const formData = new FormData(buildForm);
const data = Object.fromEntries(formData.entries());
// Toon and Goal Display
const toonDisplay = config.toonNames[data.toon] || 'Select a Toon';
previewElements.toon.textContent = toonDisplay;
// Build Name and Goal
let buildNameDisplay = data.buildName || 'No build name yet';
if (data.goal && config.goalNames[data.goal]) {
buildNameDisplay = `${buildNameDisplay} - ${config.goalNames[data.goal]}`;
}
previewElements.buildName.textContent = buildNameDisplay;
// Trinket Display
const trinkets = [];
if (data.trinket1 && config.trinketNames[data.trinket1]) trinkets.push(config.trinketNames[data.trinket1]);
if (data.trinket2 && config.trinketNames[data.trinket2]) trinkets.push(config.trinketNames[data.trinket2]);
previewElements.trinkets.textContent = trinkets.join(' + ') || 'No trinkets selected';
// Rationale Display
previewElements.rationale.textContent = data.rationale || 'Add your strategic rationale to see it here';
// Show rating section when key fields are filled
const isComplete = data.toon && data.goal && data.trinket1 && data.trinket2 && data.buildName;
previewElements.ratingSection.classList.toggle('hidden', !isComplete);
// Re-render Feather icons if used in the preview
feather.replace();
});
// --- Form Submission and Local Storage Save ---
buildForm.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(buildForm);
const data = Object.fromEntries(formData.entries());
// Simple validation check (assuming select fields have default value="")
if (!data.toon || !data.goal || !data.trinket1 || !data.trinket2 || !data.buildName || !data.rationale) {
alert('Please fill all required fields, including the rationale!');
return;
}
// Save to localStorage
const builds = JSON.parse(localStorage.getItem('builds') || '[]');
builds.push({ ...data, date: new Date().toISOString() }); // Use spread syntax for efficiency
localStorage.setItem('builds', JSON.stringify(builds));
alert('Build saved successfully!');
buildForm.reset();
// Re-render Feather icons after reset
feather.replace();
});
}
// --- Smooth Scrolling for Anchor Links ---
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({ behavior: 'smooth' });
}
});
});
// --- Initialize Tooltips ---
const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
tooltipTriggers.forEach(trigger => {
const tooltip = document.createElement('div');
// Use consistent classes for styling
tooltip.className = 'tooltip hidden md:block bg-gray-800 text-white px-3 py-1 rounded text-xs absolute z-40 whitespace-nowrap opacity-95 transition-opacity duration-200';
tooltip.textContent = trigger.getAttribute('data-tooltip');
// Use a relative container for better positioning
trigger.style.position = 'relative';
trigger.appendChild(tooltip);
trigger.addEventListener('mouseenter', () => {
tooltip.classList.remove('hidden');
});
trigger.addEventListener('mouseleave', () => {
tooltip.classList.add('hidden');
});
});
});
|
@@ -1,9 +1,7 @@
|
|
| 1 |
|
| 2 |
-
// Build Calculator
|
| 3 |
document.addEventListener('DOMContentLoaded', function() {
|
| 4 |
const buildForm = document.getElementById('build-form');
|
| 5 |
-
if (!buildForm) return;
|
| 6 |
-
|
| 7 |
const previewElements = {
|
| 8 |
toon: document.getElementById('preview-toon'),
|
| 9 |
buildName: document.getElementById('preview-build-name'),
|
|
@@ -12,125 +10,94 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 12 |
ratingSection: document.getElementById('build-rating')
|
| 13 |
};
|
| 14 |
|
| 15 |
-
//
|
| 16 |
-
const
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
'sprout': 'Sprout',
|
| 21 |
-
'shelly': 'Shelly'
|
| 22 |
-
},
|
| 23 |
-
goal: {
|
| 24 |
-
'ichor': 'Ichor Farming',
|
| 25 |
-
'survival': 'Solo Survival',
|
| 26 |
-
'research': 'Research Farming',
|
| 27 |
-
'support': 'Team Support'
|
| 28 |
-
},
|
| 29 |
-
trinket: {
|
| 30 |
-
'remote': "Vee's Remote",
|
| 31 |
-
'magnifying': 'Magnifying Glass',
|
| 32 |
-
'plush': 'Dandy Plush',
|
| 33 |
-
'bow': 'Pink Bow'
|
| 34 |
-
}
|
| 35 |
};
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
previewElements.buildName.textContent = data.buildName;
|
| 52 |
-
if (data.goal && displayNames.goal[data.goal]) {
|
| 53 |
-
previewElements.buildName.textContent += ` - ${displayNames.goal[data.goal]}`;
|
| 54 |
}
|
| 55 |
-
|
| 56 |
-
previewElements.buildName.textContent = 'No build name yet';
|
| 57 |
-
}
|
| 58 |
|
| 59 |
-
|
| 60 |
-
if (data.trinket1 || data.trinket2) {
|
| 61 |
const trinkets = [];
|
| 62 |
-
if (data.trinket1 &&
|
| 63 |
-
if (data.trinket2 &&
|
| 64 |
previewElements.trinkets.textContent = trinkets.join(' + ') || 'No trinkets selected';
|
| 65 |
-
} else {
|
| 66 |
-
previewElements.trinkets.textContent = 'No trinkets selected';
|
| 67 |
-
}
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
previewElements.rationale.textContent = data.rationale;
|
| 72 |
-
} else {
|
| 73 |
-
previewElements.rationale.textContent = 'Add your strategic rationale to see it here';
|
| 74 |
-
}
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
previewElements.ratingSection.classList.
|
| 79 |
-
} else {
|
| 80 |
-
previewElements.ratingSection.classList.add('hidden');
|
| 81 |
-
}
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
// Initialize preview
|
| 87 |
-
updatePreview();
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
}
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
});
|
| 110 |
-
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
document.querySelector(this.getAttribute('href')).scrollIntoView({
|
| 121 |
-
behavior: 'smooth'
|
| 122 |
});
|
| 123 |
});
|
| 124 |
-
});
|
| 125 |
|
| 126 |
-
// Initialize
|
| 127 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 128 |
const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
|
| 129 |
|
| 130 |
tooltipTriggers.forEach(trigger => {
|
| 131 |
const tooltip = document.createElement('div');
|
| 132 |
-
|
|
|
|
| 133 |
tooltip.textContent = trigger.getAttribute('data-tooltip');
|
|
|
|
|
|
|
|
|
|
| 134 |
trigger.appendChild(tooltip);
|
| 135 |
|
| 136 |
trigger.addEventListener('mouseenter', () => {
|
|
@@ -141,4 +108,4 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 141 |
tooltip.classList.add('hidden');
|
| 142 |
});
|
| 143 |
});
|
| 144 |
-
});
|
|
|
|
| 1 |
|
| 2 |
+
// Build Calculator and Utility Handling
|
| 3 |
document.addEventListener('DOMContentLoaded', function() {
|
| 4 |
const buildForm = document.getElementById('build-form');
|
|
|
|
|
|
|
| 5 |
const previewElements = {
|
| 6 |
toon: document.getElementById('preview-toon'),
|
| 7 |
buildName: document.getElementById('preview-build-name'),
|
|
|
|
| 10 |
ratingSection: document.getElementById('build-rating')
|
| 11 |
};
|
| 12 |
|
| 13 |
+
// --- Configuration Maps ---
|
| 14 |
+
const config = {
|
| 15 |
+
toonNames: { 'vee': 'Vee', 'pebble': 'Pebble', 'sprout': 'Sprout', 'shelly': 'Shelly' },
|
| 16 |
+
goalNames: { 'ichor': 'Ichor Farming', 'survival': 'Solo Survival', 'research': 'Research Farming', 'support': 'Team Support' },
|
| 17 |
+
trinketNames: { 'remote': "Vee's Remote", 'magnifying': 'Magnifying Glass', 'plush': 'Dandy Plush', 'bow': 'Pink Bow' }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
};
|
| 19 |
|
| 20 |
+
if (buildForm) {
|
| 21 |
+
// --- Real-time Preview Update ---
|
| 22 |
+
buildForm.addEventListener('input', function() {
|
| 23 |
+
const formData = new FormData(buildForm);
|
| 24 |
+
const data = Object.fromEntries(formData.entries());
|
| 25 |
+
|
| 26 |
+
// Toon and Goal Display
|
| 27 |
+
const toonDisplay = config.toonNames[data.toon] || 'Select a Toon';
|
| 28 |
+
previewElements.toon.textContent = toonDisplay;
|
| 29 |
+
|
| 30 |
+
// Build Name and Goal
|
| 31 |
+
let buildNameDisplay = data.buildName || 'No build name yet';
|
| 32 |
+
if (data.goal && config.goalNames[data.goal]) {
|
| 33 |
+
buildNameDisplay = `${buildNameDisplay} - ${config.goalNames[data.goal]}`;
|
|
|
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
+
previewElements.buildName.textContent = buildNameDisplay;
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
// Trinket Display
|
|
|
|
| 38 |
const trinkets = [];
|
| 39 |
+
if (data.trinket1 && config.trinketNames[data.trinket1]) trinkets.push(config.trinketNames[data.trinket1]);
|
| 40 |
+
if (data.trinket2 && config.trinketNames[data.trinket2]) trinkets.push(config.trinketNames[data.trinket2]);
|
| 41 |
previewElements.trinkets.textContent = trinkets.join(' + ') || 'No trinkets selected';
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
// Rationale Display
|
| 44 |
+
previewElements.rationale.textContent = data.rationale || 'Add your strategic rationale to see it here';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
// Show rating section when key fields are filled
|
| 47 |
+
const isComplete = data.toon && data.goal && data.trinket1 && data.trinket2 && data.buildName;
|
| 48 |
+
previewElements.ratingSection.classList.toggle('hidden', !isComplete);
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
// Re-render Feather icons if used in the preview
|
| 51 |
+
feather.replace();
|
| 52 |
+
});
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
// --- Form Submission and Local Storage Save ---
|
| 55 |
+
buildForm.addEventListener('submit', function(e) {
|
| 56 |
+
e.preventDefault();
|
| 57 |
+
const formData = new FormData(buildForm);
|
| 58 |
+
const data = Object.fromEntries(formData.entries());
|
| 59 |
+
|
| 60 |
+
// Simple validation check (assuming select fields have default value="")
|
| 61 |
+
if (!data.toon || !data.goal || !data.trinket1 || !data.trinket2 || !data.buildName || !data.rationale) {
|
| 62 |
+
alert('Please fill all required fields, including the rationale!');
|
| 63 |
+
return;
|
| 64 |
+
}
|
| 65 |
|
| 66 |
+
// Save to localStorage
|
| 67 |
+
const builds = JSON.parse(localStorage.getItem('builds') || '[]');
|
| 68 |
+
builds.push({ ...data, date: new Date().toISOString() }); // Use spread syntax for efficiency
|
| 69 |
+
localStorage.setItem('builds', JSON.stringify(builds));
|
|
|
|
| 70 |
|
| 71 |
+
alert('Build saved successfully!');
|
| 72 |
+
buildForm.reset();
|
| 73 |
+
|
| 74 |
+
// Re-render Feather icons after reset
|
| 75 |
+
feather.replace();
|
| 76 |
});
|
| 77 |
+
}
|
| 78 |
|
| 79 |
+
// --- Smooth Scrolling for Anchor Links ---
|
| 80 |
+
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
| 81 |
+
anchor.addEventListener('click', function (e) {
|
| 82 |
+
e.preventDefault();
|
| 83 |
+
const target = document.querySelector(this.getAttribute('href'));
|
| 84 |
+
if (target) {
|
| 85 |
+
target.scrollIntoView({ behavior: 'smooth' });
|
| 86 |
+
}
|
|
|
|
|
|
|
| 87 |
});
|
| 88 |
});
|
|
|
|
| 89 |
|
| 90 |
+
// --- Initialize Tooltips ---
|
|
|
|
| 91 |
const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
|
| 92 |
|
| 93 |
tooltipTriggers.forEach(trigger => {
|
| 94 |
const tooltip = document.createElement('div');
|
| 95 |
+
// Use consistent classes for styling
|
| 96 |
+
tooltip.className = 'tooltip hidden md:block bg-gray-800 text-white px-3 py-1 rounded text-xs absolute z-40 whitespace-nowrap opacity-95 transition-opacity duration-200';
|
| 97 |
tooltip.textContent = trigger.getAttribute('data-tooltip');
|
| 98 |
+
|
| 99 |
+
// Use a relative container for better positioning
|
| 100 |
+
trigger.style.position = 'relative';
|
| 101 |
trigger.appendChild(tooltip);
|
| 102 |
|
| 103 |
trigger.addEventListener('mouseenter', () => {
|
|
|
|
| 108 |
tooltip.classList.add('hidden');
|
| 109 |
});
|
| 110 |
});
|
| 111 |
+
});
|