437 lines
15 KiB
HTML
437 lines
15 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html lang="en">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
<title>Dog Calorie Calculator</title>
|
||
|
|
<style>
|
||
|
|
* {
|
||
|
|
box-sizing: border-box;
|
||
|
|
}
|
||
|
|
|
||
|
|
.calculator-container {
|
||
|
|
max-width: 600px;
|
||
|
|
margin: 0 auto;
|
||
|
|
padding: 20px;
|
||
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||
|
|
line-height: 1.6;
|
||
|
|
color: #333;
|
||
|
|
}
|
||
|
|
|
||
|
|
.section {
|
||
|
|
background: #f8f9fa;
|
||
|
|
border: 1px solid #e9ecef;
|
||
|
|
border-radius: 8px;
|
||
|
|
padding: 20px;
|
||
|
|
margin-bottom: 20px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.section h2 {
|
||
|
|
margin-top: 0;
|
||
|
|
margin-bottom: 20px;
|
||
|
|
color: #2c3e50;
|
||
|
|
font-size: 1.4em;
|
||
|
|
font-weight: 600;
|
||
|
|
}
|
||
|
|
|
||
|
|
.form-group {
|
||
|
|
margin-bottom: 15px;
|
||
|
|
}
|
||
|
|
|
||
|
|
label {
|
||
|
|
display: block;
|
||
|
|
margin-bottom: 5px;
|
||
|
|
font-weight: 500;
|
||
|
|
color: #495057;
|
||
|
|
}
|
||
|
|
|
||
|
|
select,
|
||
|
|
input[type="number"] {
|
||
|
|
width: 100%;
|
||
|
|
padding: 8px 12px;
|
||
|
|
border: 1px solid #ced4da;
|
||
|
|
border-radius: 4px;
|
||
|
|
font-size: 14px;
|
||
|
|
background-color: white;
|
||
|
|
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
|
||
|
|
}
|
||
|
|
|
||
|
|
select:focus,
|
||
|
|
input[type="number"]:focus {
|
||
|
|
outline: none;
|
||
|
|
border-color: #80bdff;
|
||
|
|
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
|
||
|
|
}
|
||
|
|
|
||
|
|
.results {
|
||
|
|
background: #e8f5e8;
|
||
|
|
border: 1px solid #c3e6c3;
|
||
|
|
border-radius: 4px;
|
||
|
|
padding: 15px;
|
||
|
|
margin-top: 20px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.result-item {
|
||
|
|
display: flex;
|
||
|
|
justify-content: space-between;
|
||
|
|
align-items: center;
|
||
|
|
margin-bottom: 8px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.result-item:last-child {
|
||
|
|
margin-bottom: 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
.result-label {
|
||
|
|
font-weight: 500;
|
||
|
|
color: #2d5a2d;
|
||
|
|
}
|
||
|
|
|
||
|
|
.result-value {
|
||
|
|
font-weight: 600;
|
||
|
|
color: #1e3a1e;
|
||
|
|
font-size: 1.1em;
|
||
|
|
}
|
||
|
|
|
||
|
|
.collapsible {
|
||
|
|
background: #fff;
|
||
|
|
border: 1px solid #dee2e6;
|
||
|
|
border-radius: 8px;
|
||
|
|
margin-bottom: 20px;
|
||
|
|
overflow: hidden;
|
||
|
|
}
|
||
|
|
|
||
|
|
.collapsible-header {
|
||
|
|
background: #f1f3f4;
|
||
|
|
padding: 15px 20px;
|
||
|
|
cursor: pointer;
|
||
|
|
user-select: none;
|
||
|
|
display: flex;
|
||
|
|
justify-content: space-between;
|
||
|
|
align-items: center;
|
||
|
|
border-bottom: 1px solid #dee2e6;
|
||
|
|
transition: background-color 0.2s ease;
|
||
|
|
}
|
||
|
|
|
||
|
|
.collapsible-header:hover {
|
||
|
|
background: #e9ecef;
|
||
|
|
}
|
||
|
|
|
||
|
|
.collapsible-header h3 {
|
||
|
|
margin: 0;
|
||
|
|
font-size: 1.2em;
|
||
|
|
color: #2c3e50;
|
||
|
|
font-weight: 600;
|
||
|
|
}
|
||
|
|
|
||
|
|
.collapsible-arrow {
|
||
|
|
transition: transform 0.2s ease;
|
||
|
|
font-size: 1.2em;
|
||
|
|
color: #6c757d;
|
||
|
|
}
|
||
|
|
|
||
|
|
.collapsible.active .collapsible-arrow {
|
||
|
|
transform: rotate(180deg);
|
||
|
|
}
|
||
|
|
|
||
|
|
.collapsible-content {
|
||
|
|
max-height: 0;
|
||
|
|
overflow: hidden;
|
||
|
|
transition: max-height 0.3s ease;
|
||
|
|
}
|
||
|
|
|
||
|
|
.collapsible.active .collapsible-content {
|
||
|
|
max-height: 1000px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.collapsible-inner {
|
||
|
|
padding: 20px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.input-group {
|
||
|
|
display: flex;
|
||
|
|
gap: 10px;
|
||
|
|
align-items: flex-end;
|
||
|
|
}
|
||
|
|
|
||
|
|
.input-group .form-group {
|
||
|
|
flex: 1;
|
||
|
|
margin-bottom: 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
.unit-select {
|
||
|
|
min-width: 80px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.error {
|
||
|
|
color: #dc3545;
|
||
|
|
font-size: 0.875em;
|
||
|
|
margin-top: 5px;
|
||
|
|
}
|
||
|
|
|
||
|
|
@media (max-width: 480px) {
|
||
|
|
.calculator-container {
|
||
|
|
padding: 15px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.section {
|
||
|
|
padding: 15px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.input-group {
|
||
|
|
flex-direction: column;
|
||
|
|
gap: 15px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.input-group .form-group {
|
||
|
|
margin-bottom: 15px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.result-item {
|
||
|
|
flex-direction: column;
|
||
|
|
align-items: flex-start;
|
||
|
|
gap: 5px;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
.hidden {
|
||
|
|
display: none;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="calculator-container">
|
||
|
|
<div class="section">
|
||
|
|
<h2>Dog's Characteristics</h2>
|
||
|
|
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="dogType">Dog Type / Activity Level:</label>
|
||
|
|
<select id="dogType" aria-describedby="dogTypeHelp">
|
||
|
|
<option value="">Select dog type...</option>
|
||
|
|
<option value="3.0">Puppy (0-4 months)</option>
|
||
|
|
<option value="2.0">Puppy (4 months - adult)</option>
|
||
|
|
<option value="1.2">Adult - inactive/obese</option>
|
||
|
|
<option value="1.6">Adult (neutered/spayed) - average activity</option>
|
||
|
|
<option value="1.8">Adult (intact) - average activity</option>
|
||
|
|
<option value="1.0">Adult - weight loss</option>
|
||
|
|
<option value="1.7">Adult - weight gain</option>
|
||
|
|
<option value="2.0">Working dog - light work</option>
|
||
|
|
<option value="3.0">Working dog - moderate work</option>
|
||
|
|
<option value="5.0">Working dog - heavy work</option>
|
||
|
|
<option value="1.1">Senior dog</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="weight">Dog's Weight (kg):</label>
|
||
|
|
<input type="number" id="weight" min="0.1" step="0.1" placeholder="Enter weight in kg" aria-describedby="weightHelp">
|
||
|
|
<div id="weightError" class="error hidden">Please enter a valid weight (minimum 0.1 kg)</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="results" id="calorieResults" style="display: none;">
|
||
|
|
<div class="result-item">
|
||
|
|
<span class="result-label">Resting Energy Requirement (RER):</span>
|
||
|
|
<span class="result-value" id="rerValue">- cal/day</span>
|
||
|
|
</div>
|
||
|
|
<div class="result-item">
|
||
|
|
<span class="result-label">Maintenance Energy Requirement (MER):</span>
|
||
|
|
<span class="result-value" id="merValue">- cal/day</span>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="collapsible" id="foodCalculator">
|
||
|
|
<div class="collapsible-header" onclick="toggleCollapsible('foodCalculator')">
|
||
|
|
<h3>How much food is that?</h3>
|
||
|
|
<span class="collapsible-arrow">▼</span>
|
||
|
|
</div>
|
||
|
|
<div class="collapsible-content">
|
||
|
|
<div class="collapsible-inner">
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="foodEnergy">Food Energy Content (kcal/100g):</label>
|
||
|
|
<input type="number" id="foodEnergy" min="1" step="1" placeholder="Enter kcal per 100g" aria-describedby="foodEnergyHelp">
|
||
|
|
<div id="foodEnergyError" class="error hidden">Please enter a valid energy content (minimum 1 kcal/100g)</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="results" id="dailyFoodResults" style="display: none;">
|
||
|
|
<div class="result-item">
|
||
|
|
<span class="result-label">Daily Food Amount:</span>
|
||
|
|
<span class="result-value" id="dailyFoodValue">- g/day</span>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="form-group" style="margin-top: 20px;">
|
||
|
|
<label for="days">Number of Days:</label>
|
||
|
|
<input type="number" id="days" min="1" step="1" value="1" placeholder="Enter number of days" aria-describedby="daysHelp">
|
||
|
|
<div id="daysError" class="error hidden">Please enter a valid number of days (minimum 1)</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="input-group">
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="totalFoodDisplay">Total Food Amount:</label>
|
||
|
|
<input type="text" id="totalFoodDisplay" readonly style="background-color: #f8f9fa; cursor: not-allowed;">
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="unit">Unit:</label>
|
||
|
|
<select id="unit" class="unit-select" aria-describedby="unitHelp">
|
||
|
|
<option value="g">grams (g)</option>
|
||
|
|
<option value="kg">kilograms (kg)</option>
|
||
|
|
<option value="oz">ounces (oz)</option>
|
||
|
|
<option value="lb">pounds (lb)</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
let currentMER = 0;
|
||
|
|
|
||
|
|
function toggleCollapsible(id) {
|
||
|
|
const element = document.getElementById(id);
|
||
|
|
element.classList.toggle('active');
|
||
|
|
}
|
||
|
|
|
||
|
|
function calculateRER(weightKg) {
|
||
|
|
return 70 * Math.pow(weightKg, 0.75);
|
||
|
|
}
|
||
|
|
|
||
|
|
function calculateMER(rer, factor) {
|
||
|
|
return rer * factor;
|
||
|
|
}
|
||
|
|
|
||
|
|
function validateInput(value, min = 0, isInteger = false) {
|
||
|
|
const num = parseFloat(value);
|
||
|
|
if (isNaN(num) || num < min) return false;
|
||
|
|
if (isInteger && !Number.isInteger(num)) return false;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
function showError(elementId, show = true) {
|
||
|
|
const errorElement = document.getElementById(elementId);
|
||
|
|
if (show) {
|
||
|
|
errorElement.classList.remove('hidden');
|
||
|
|
} else {
|
||
|
|
errorElement.classList.add('hidden');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function convertUnits(grams, unit) {
|
||
|
|
switch (unit) {
|
||
|
|
case 'kg':
|
||
|
|
return grams / 1000;
|
||
|
|
case 'oz':
|
||
|
|
return grams / 28.3495;
|
||
|
|
case 'lb':
|
||
|
|
return grams / 453.592;
|
||
|
|
default:
|
||
|
|
return grams;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function formatNumber(num, decimals = 0) {
|
||
|
|
return num.toFixed(decimals).replace(/\.?0+$/, '');
|
||
|
|
}
|
||
|
|
|
||
|
|
function updateCalorieCalculations() {
|
||
|
|
const weight = document.getElementById('weight').value;
|
||
|
|
const dogTypeFactor = document.getElementById('dogType').value;
|
||
|
|
|
||
|
|
showError('weightError', false);
|
||
|
|
|
||
|
|
if (!weight || !validateInput(weight, 0.1)) {
|
||
|
|
showError('weightError', true);
|
||
|
|
document.getElementById('calorieResults').style.display = 'none';
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!dogTypeFactor) {
|
||
|
|
document.getElementById('calorieResults').style.display = 'none';
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const weightKg = parseFloat(weight);
|
||
|
|
const factor = parseFloat(dogTypeFactor);
|
||
|
|
|
||
|
|
const rer = calculateRER(weightKg);
|
||
|
|
const mer = calculateMER(rer, factor);
|
||
|
|
|
||
|
|
currentMER = mer;
|
||
|
|
|
||
|
|
document.getElementById('rerValue').textContent = formatNumber(rer, 0) + ' cal/day';
|
||
|
|
document.getElementById('merValue').textContent = formatNumber(mer, 0) + ' cal/day';
|
||
|
|
document.getElementById('calorieResults').style.display = 'block';
|
||
|
|
|
||
|
|
updateFoodCalculations();
|
||
|
|
}
|
||
|
|
|
||
|
|
function updateFoodCalculations() {
|
||
|
|
if (currentMER === 0) return;
|
||
|
|
|
||
|
|
const foodEnergy = document.getElementById('foodEnergy').value;
|
||
|
|
const days = document.getElementById('days').value;
|
||
|
|
const unit = document.getElementById('unit').value;
|
||
|
|
|
||
|
|
showError('foodEnergyError', false);
|
||
|
|
showError('daysError', false);
|
||
|
|
|
||
|
|
if (!foodEnergy || !validateInput(foodEnergy, 1)) {
|
||
|
|
if (foodEnergy) showError('foodEnergyError', true);
|
||
|
|
document.getElementById('dailyFoodResults').style.display = 'none';
|
||
|
|
document.getElementById('totalFoodDisplay').value = '';
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!days || !validateInput(days, 1, true)) {
|
||
|
|
if (days) showError('daysError', true);
|
||
|
|
document.getElementById('totalFoodDisplay').value = '';
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const energyPer100g = parseFloat(foodEnergy);
|
||
|
|
const numDays = parseInt(days);
|
||
|
|
|
||
|
|
const dailyFoodGrams = (currentMER / energyPer100g) * 100;
|
||
|
|
const totalFoodGrams = dailyFoodGrams * numDays;
|
||
|
|
|
||
|
|
document.getElementById('dailyFoodValue').textContent = formatNumber(dailyFoodGrams, 1) + ' g/day';
|
||
|
|
document.getElementById('dailyFoodResults').style.display = 'block';
|
||
|
|
|
||
|
|
const convertedAmount = convertUnits(totalFoodGrams, unit);
|
||
|
|
const unitLabel = unit === 'g' ? 'g' : unit === 'kg' ? 'kg' : unit === 'oz' ? 'oz' : 'lb';
|
||
|
|
const decimals = unit === 'g' ? 0 : unit === 'kg' ? 2 : 1;
|
||
|
|
|
||
|
|
document.getElementById('totalFoodDisplay').value = formatNumber(convertedAmount, decimals) + ' ' + unitLabel;
|
||
|
|
}
|
||
|
|
|
||
|
|
document.getElementById('weight').addEventListener('input', updateCalorieCalculations);
|
||
|
|
document.getElementById('dogType').addEventListener('change', updateCalorieCalculations);
|
||
|
|
document.getElementById('foodEnergy').addEventListener('input', updateFoodCalculations);
|
||
|
|
document.getElementById('days').addEventListener('input', updateFoodCalculations);
|
||
|
|
document.getElementById('unit').addEventListener('change', updateFoodCalculations);
|
||
|
|
|
||
|
|
document.getElementById('weight').addEventListener('blur', function() {
|
||
|
|
const weight = this.value;
|
||
|
|
if (weight && !validateInput(weight, 0.1)) {
|
||
|
|
showError('weightError', true);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
document.getElementById('foodEnergy').addEventListener('blur', function() {
|
||
|
|
const energy = this.value;
|
||
|
|
if (energy && !validateInput(energy, 1)) {
|
||
|
|
showError('foodEnergyError', true);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
document.getElementById('days').addEventListener('blur', function() {
|
||
|
|
const days = this.value;
|
||
|
|
if (days && !validateInput(days, 1, true)) {
|
||
|
|
showError('daysError', true);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|