Skip to content

Commit 5f1135c

Browse files
committed
Ensure DOM is loaded
1 parent dabc931 commit 5f1135c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

app/views/papers/_vote_summary.html.erb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
return;
3939
}
4040

41-
document.addEventListener('DOMContentLoaded', function() {
42-
console.log('DOM Content Loaded - Initializing vote comment storage');
41+
// Function to initialize the storage functionality
42+
function initializeStorage() {
43+
console.log('Initializing storage functionality');
4344

4445
const commentField = document.getElementById('vote-comment');
4546
if (!commentField) {
@@ -95,7 +96,20 @@
9596
} else {
9697
console.error('Could not find parent form element');
9798
}
99+
}
100+
101+
// Try to initialize immediately if DOM is already loaded
102+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
103+
console.log('DOM already loaded, initializing immediately');
104+
initializeStorage();
105+
}
106+
107+
// Also set up the DOMContentLoaded listener as a backup
108+
document.addEventListener('DOMContentLoaded', function() {
109+
console.log('DOM Content Loaded event fired');
110+
initializeStorage();
98111
});
112+
99113
} catch (e) {
100114
console.error('Error in vote comment storage script:', e);
101115
}

0 commit comments

Comments
 (0)