mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Fixed the print view for brackets
This commit is contained in:
@@ -1,20 +1,20 @@
|
|||||||
<style>
|
<style>
|
||||||
|
/* General styles for pages */
|
||||||
@page {
|
@page {
|
||||||
size: 8.5in 11in;
|
margin: 0.5in; /* Universal margin for all pages */
|
||||||
margin: 0.5in;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.page {
|
.page {
|
||||||
width: 7.5in;
|
width: 7.5in; /* Portrait width (8.5in - margins) */
|
||||||
height: 10in;
|
height: 10in; /* Portrait height (11in - margins) */
|
||||||
margin: auto;
|
margin: auto;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-landscape {
|
.page-landscape {
|
||||||
height: 7.5in;
|
width: 10in; /* Landscape width (11in - margins) */
|
||||||
width: 10in;
|
height: 7.5in; /* Landscape height (8.5in - margins) */
|
||||||
margin: auto;
|
margin: auto;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -26,30 +26,88 @@
|
|||||||
transform-origin: top left;
|
transform-origin: top left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Print-specific styles */
|
||||||
@media print {
|
@media print {
|
||||||
|
/* Set orientation for portrait pages */
|
||||||
.page {
|
.page {
|
||||||
page-break-after: always;
|
size: 8.5in 11in; /* Portrait */
|
||||||
|
page-break-after: always; /* Force new page */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set orientation for landscape pages */
|
||||||
.page-landscape {
|
.page-landscape {
|
||||||
page-break-after: always;
|
size: 11in 8.5in; /* Landscape */
|
||||||
|
page-break-after: always; /* Force new page */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset body margins for print */
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure correct scaling during print */
|
||||||
|
.bracket-container {
|
||||||
|
transform-origin: top left;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optional: Hide elements not needed in print */
|
||||||
|
.no-print {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.onload = function () {
|
function scaleContent() {
|
||||||
document.querySelectorAll('.page').forEach(page => {
|
document.querySelectorAll('.page, .page-landscape').forEach(page => {
|
||||||
const container = page.querySelector('.bracket-container');
|
const container = page.querySelector('.bracket-container');
|
||||||
const isLandscape = page.classList.contains('landscape');
|
const isLandscape = page.classList.contains('page-landscape');
|
||||||
const availableWidth = isLandscape ? 10 * 96 : 7.5 * 96; // Convert inches to px
|
|
||||||
const availableHeight = isLandscape ? 7.5 * 96 : 10 * 96;
|
|
||||||
|
|
||||||
const scaleX = availableWidth / container.scrollWidth;
|
// Page dimensions (1 inch = 96px)
|
||||||
const scaleY = availableHeight / container.scrollHeight;
|
const pageWidth = isLandscape ? 10 * 96 : 7.5 * 96;
|
||||||
const scale = Math.min(scaleX, scaleY); // Choose the smaller scale to fit
|
const pageHeight = isLandscape ? 7.5 * 96 : 10 * 96;
|
||||||
|
|
||||||
|
// Subtract margins (0.5 inch margin)
|
||||||
|
const availableWidth = pageWidth - (0.5 * 96 * 2);
|
||||||
|
const availableHeight = pageHeight - (0.5 * 96 * 2);
|
||||||
|
|
||||||
|
// Measure content dimensions
|
||||||
|
const contentWidth = container.scrollWidth;
|
||||||
|
const contentHeight = container.scrollHeight;
|
||||||
|
|
||||||
|
// Calculate scale factors
|
||||||
|
const scaleX = availableWidth / contentWidth;
|
||||||
|
const scaleY = availableHeight / contentHeight;
|
||||||
|
|
||||||
|
// Use a slightly relaxed scaling to avoid over-aggressive shrinking
|
||||||
|
const scale = Math.min(scaleX, scaleY, 1); // Ensure scale does not exceed 100% (1)
|
||||||
|
|
||||||
|
// Apply the scale
|
||||||
container.style.transform = `scale(${scale})`;
|
container.style.transform = `scale(${scale})`;
|
||||||
|
container.style.transformOrigin = 'top left';
|
||||||
|
|
||||||
|
// Calculate the scaled dimensions
|
||||||
|
const scaledWidth = contentWidth * scale;
|
||||||
|
const scaledHeight = contentHeight * scale;
|
||||||
|
|
||||||
|
// Center the content within the page
|
||||||
|
const horizontalPadding = (pageWidth - scaledWidth) / 2;
|
||||||
|
const verticalPadding = (pageHeight - scaledHeight) / 2;
|
||||||
|
|
||||||
|
// Apply margin adjustments
|
||||||
|
container.style.marginLeft = `${Math.max(0, horizontalPadding)}px`;
|
||||||
|
container.style.marginTop = `${Math.max(0, verticalPadding)}px`;
|
||||||
|
|
||||||
|
// Ensure container maintains consistent dimensions
|
||||||
|
container.style.width = `${contentWidth}px`;
|
||||||
|
container.style.height = `${contentHeight}px`;
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
window.onload = scaleContent; // Ensure scaling on load
|
||||||
|
window.onresize = scaleContent; // Recalculate on resize
|
||||||
|
window.addEventListener('beforeprint', scaleContent); // Scale before printing
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<% cache ["#{@tournament.id}_all_brackets", @tournament] do %>
|
<% cache ["#{@tournament.id}_all_brackets", @tournament] do %>
|
||||||
|
|||||||
Reference in New Issue
Block a user