Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bihar-culture-landing/culture.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ <h2>Want to Contribute to Bihar’s Cultural Archive?</h2>
<p>Celebrating the spirit, art, and heritage of Bihar.</p>
</div>
</footer>
</main>

<script src="script.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions bihar-culture-landing/festivals.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ <h3>Shravani Mela</h3>
Bihar's rich heritage reflected in it's festivals</p>
<br>
</footer>
<script src="script.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions bihar-culture-landing/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ <h2>Freedom Fighters</h2>
<footer>
<p>Help us add more historical events and personalities!</p>
</footer>
<script src="script.js"></script>
</body>
</html>
19 changes: 0 additions & 19 deletions bihar-culture-landing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,6 @@ <h2>Contribute to Bihar Culture</h2>
</div>
</footer>

<!-- Back to Top Button -->
<button id="backToTopBtn" title="Back to Top">↑ Back to Top</button>

<script src="script.js"></script>
<script>
// Show/hide button on scroll
const backToTopBtn = document.getElementById('backToTopBtn');
window.onscroll = function() {
if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
backToTopBtn.style.display = "block";
} else {
backToTopBtn.style.display = "none";
}
};

// Smooth scroll to top
backToTopBtn.onclick = function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
</script>
</body>
</html>
1 change: 1 addition & 0 deletions bihar-culture-landing/modern.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ <h2>Bihar in Cinema</h2>
<footer>
<p>Modern Bihar section welcomes more contributions!</p>
</footer>
<script src="script.js"></script>
</body>
</html>
66 changes: 66 additions & 0 deletions bihar-culture-landing/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ document.addEventListener('DOMContentLoaded', function() {
initAccessibility();
initProgressiveEnhancement();
initQuiz(); // attach quiz logic if present
initBackToTop(); // initialize back-to-top button across pages
});

// Navigation enhancements
Expand Down Expand Up @@ -447,4 +448,69 @@ document.head.appendChild(style);
// Export for module usage (if needed)
if (typeof module !== 'undefined' && module.exports) {
module.exports = BiharCulture;
}

// Back to Top button: create a single reusable button and behavior across pages
function initBackToTop() {
try {
if (document.getElementById('backToTopBtn')) return; // already present

const btn = document.createElement('button');
btn.id = 'backToTopBtn';
btn.type = 'button';
btn.title = 'Back to Top';
btn.setAttribute('aria-label', 'Back to top');
btn.innerHTML = '↑';
btn.style.display = 'none';

// Make sure the button is added after the rest of content
document.body.appendChild(btn);

const showThreshold = 200;

const updateVisibility = () => {
const scrolled = window.pageYOffset || document.documentElement.scrollTop;
if (scrolled > showThreshold) {
btn.style.display = 'block';
} else {
btn.style.display = 'none';
}
};

// Throttle using requestAnimationFrame for better perf
let ticking = false;
window.addEventListener('scroll', () => {
if (!ticking) {
window.requestAnimationFrame(() => {
updateVisibility();
ticking = false;
});
ticking = true;
}
}, { passive: true });

// Smooth scroll while respecting user preference for reduced motion
btn.addEventListener('click', () => {
const prefersReduced = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (prefersReduced) {
window.scrollTo(0, 0);
} else {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
btn.blur();
});

// Keyboard accessibility (Enter/Space)
btn.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
btn.click();
}
});

// Initialize visibility on load
updateVisibility();
} catch (err) {
console.error('BackToTop initialization failed:', err);
}
}
Loading