Skip to content
Merged
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
15 changes: 14 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@
}
</script>
<link rel="stylesheet" href="css/styles.css">
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/jsmol-setup.js"></script>
<script type="text/javascript" src="js/image-export.js"></script>
<script type="text/javascript" src="js/molecule-data.js"></script>
<script type="text/javascript" src="js/viewer-controls.js"></script>
<script type="text/javascript" src="js/search.js"></script>
<script type="text/javascript" src="js/orbitals.js"></script>
<script type="text/javascript" src="js/xyz-editor.js"></script>
<script type="text/javascript" src="js/selection.js"></script>
<script type="text/javascript" src="js/ui.js"></script>
<script type="text/javascript" src="js/jsme-2d.js"></script>
<script type="text/javascript" src="js/elemco.js"></script>
<script type="text/javascript" src="js/xtb.js"></script>
<script type="text/javascript" src="js/app-init.js"></script>
<script type="text/javascript" src="js/preferences.js"></script>
</head>
<body>
<div id="container">
Expand Down
69 changes: 69 additions & 0 deletions js/app-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Initialize ElemCo panel elements
function initElemCoPanel() {
// Clean up any existing elements first
const dfLabel = document.querySelector('.df-toggle-label');
if (dfLabel) {
// Remove existing content to prevent memory leaks
dfLabel.innerHTML = '';
dfLabel.innerHTML = `
<input type="checkbox" id="elemco-df" onchange="updateMethodOptions()">
<span>Use DF</span>
`;
}

// Initialize method options
updateMethodOptions();

// Update input text
updateElemCoInput();
}

// Add initialization to both window.onload and document.ready
if (typeof window !== 'undefined') {
window.addEventListener('load', function() {
// Use a proper initialization sequence with dependency checking
initializeApplication();
});
}

// Proper initialization function with dependency checking
function initializeApplication() {
let initAttempts = 0;
const maxAttempts = 20; // Allow up to 2 seconds (20 * 100ms)

function attemptInit() {
initAttempts++;

// Check if required DOM elements exist
const elemcoPanel = document.getElementById('elemcoPanel');
const searchInput = document.getElementById('pubchemInput');

if (elemcoPanel && searchInput) {
// All required elements are available, proceed with initialization
try {
initElemCoPanel();
updateInputPlaceholder();
setupDatabaseInputHandlers();
initPreferences();
console.log('Application initialized successfully');
} catch (error) {
console.warn('Error during initialization:', error);
// Retry if we haven't exceeded max attempts
if (initAttempts < maxAttempts) {
setTimeout(attemptInit, 100);
}
}
} else {
// Required elements not ready yet, retry if we haven't exceeded max attempts
if (initAttempts < maxAttempts) {
setTimeout(attemptInit, 100);
} else {
console.warn('Application initialization failed: required DOM elements not found after', maxAttempts, 'attempts');
}
}
}

// Start initialization
attemptInit();
}

Loading