Spaces:
Running
on
Zero
Running
on
Zero
add js file to handle scrolling (#18)
Browse files- add js file to handle scrolling (b7a0e76744e877b0bd849acd1cc605dc9a037c24)
Co-authored-by: Kai <[email protected]>
- static/js/scroll_helpers.js +51 -0
static/js/scroll_helpers.js
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Script to handle text scrolling in the RAG Summarizer Arena
|
3 |
+
* Uses a simplified approach relying primarily on Gradio's autoscroll parameter
|
4 |
+
*/
|
5 |
+
|
6 |
+
// Scroll to the query section when loading new content
|
7 |
+
function scrollToQuerySection() {
|
8 |
+
const querySection = document.getElementById('query-section');
|
9 |
+
if (querySection) {
|
10 |
+
setTimeout(() => {
|
11 |
+
querySection.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
12 |
+
console.log('Scrolled to query section');
|
13 |
+
}, 300); // Small delay to ensure content is loaded
|
14 |
+
}
|
15 |
+
}
|
16 |
+
|
17 |
+
// Set up event listeners when DOM is loaded
|
18 |
+
document.addEventListener('DOMContentLoaded', function() {
|
19 |
+
console.log('Setting up basic scroll helpers...');
|
20 |
+
|
21 |
+
// Monitor button clicks for scrolling to the query section
|
22 |
+
function setupButtonListeners() {
|
23 |
+
const tryAnotherBtn = document.getElementById('try-another-btn');
|
24 |
+
if (tryAnotherBtn && !tryAnotherBtn.hasAttribute('data-scroll-handler')) {
|
25 |
+
tryAnotherBtn.addEventListener('click', scrollToQuerySection);
|
26 |
+
tryAnotherBtn.setAttribute('data-scroll-handler', 'true');
|
27 |
+
console.log('Added listener to try-another-btn');
|
28 |
+
}
|
29 |
+
|
30 |
+
const randomQuestionBtn = document.querySelector('.query-button');
|
31 |
+
if (randomQuestionBtn && !randomQuestionBtn.hasAttribute('data-scroll-handler')) {
|
32 |
+
randomQuestionBtn.addEventListener('click', scrollToQuerySection);
|
33 |
+
randomQuestionBtn.setAttribute('data-scroll-handler', 'true');
|
34 |
+
console.log('Added listener to query-button');
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
// Set up button listeners
|
39 |
+
setupButtonListeners();
|
40 |
+
|
41 |
+
// Watch for DOM changes to catch dynamically added elements
|
42 |
+
const bodyObserver = new MutationObserver(() => {
|
43 |
+
setupButtonListeners();
|
44 |
+
});
|
45 |
+
|
46 |
+
// Start observing the body for changes
|
47 |
+
bodyObserver.observe(document.body, {
|
48 |
+
childList: true,
|
49 |
+
subtree: true
|
50 |
+
});
|
51 |
+
});
|