2025-06-02 16:22:54 +02:00
|
|
|
/**
|
2025-07-15 17:31:14 +02:00
|
|
|
* Price Calculator Module Loader
|
|
|
|
* Loads the modular price calculator components
|
|
|
|
* The original monolithic code has been split into multiple files for better maintainability
|
2025-06-02 16:22:54 +02:00
|
|
|
*/
|
|
|
|
|
2025-07-15 17:31:14 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Check if we're on a page that needs the price calculator
|
|
|
|
if (!document.getElementById('cpuRange')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the current script's directory
|
|
|
|
const getCurrentScriptPath = () => {
|
|
|
|
const scripts = document.getElementsByTagName('script');
|
|
|
|
// Find the script that contains 'price-calculator.js'
|
|
|
|
for (let script of scripts) {
|
|
|
|
if (script.src.includes('price-calculator.js')) {
|
|
|
|
const scriptPath = script.src;
|
|
|
|
const lastSlash = scriptPath.lastIndexOf('/');
|
|
|
|
return scriptPath.substring(0, lastSlash + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '/static/js/';
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define the modules to load in dependency order
|
|
|
|
const modules = [
|
|
|
|
'price-calculator/dom-manager.js',
|
|
|
|
'price-calculator/pricing-data-manager.js',
|
|
|
|
'price-calculator/plan-manager.js',
|
|
|
|
'price-calculator/addon-manager.js',
|
|
|
|
'price-calculator/ui-manager.js',
|
|
|
|
'price-calculator/order-manager.js',
|
|
|
|
'price-calculator/price-calculator.js'
|
|
|
|
];
|
|
|
|
|
|
|
|
// Helper function to load a script
|
|
|
|
const loadScript = (src) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const script = document.createElement('script');
|
|
|
|
script.src = src;
|
|
|
|
script.onload = resolve;
|
|
|
|
script.onerror = reject;
|
|
|
|
document.head.appendChild(script);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Load modules sequentially
|
|
|
|
const loadModules = async () => {
|
|
|
|
const basePath = getCurrentScriptPath();
|
|
|
|
|
|
|
|
for (const module of modules) {
|
|
|
|
try {
|
|
|
|
await loadScript(basePath + module);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Failed to load module: ${module}`, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the calculator after modules are loaded
|
|
|
|
if (window.PriceCalculator) {
|
|
|
|
window.priceCalculator = new window.PriceCalculator();
|
2025-06-20 09:51:22 +02:00
|
|
|
} else {
|
2025-07-15 17:31:14 +02:00
|
|
|
console.error('PriceCalculator class not found after module loading');
|
2025-06-20 09:51:22 +02:00
|
|
|
}
|
2025-07-15 17:31:14 +02:00
|
|
|
};
|
2025-06-20 09:51:22 +02:00
|
|
|
|
2025-07-15 17:31:14 +02:00
|
|
|
// Start loading modules when DOM is ready
|
|
|
|
if (document.readyState === 'loading') {
|
|
|
|
document.addEventListener('DOMContentLoaded', loadModules);
|
|
|
|
} else {
|
|
|
|
loadModules();
|
2025-06-02 16:22:54 +02:00
|
|
|
}
|
2025-07-15 17:31:14 +02:00
|
|
|
})();
|
2025-06-23 13:25:46 +02:00
|
|
|
|
2025-07-15 17:31:14 +02:00
|
|
|
// Global function for traditional plan selection (used by template buttons)
|
2025-06-23 13:25:46 +02:00
|
|
|
function selectPlan(element) {
|
|
|
|
const planId = element.getAttribute('data-plan-id');
|
|
|
|
const planName = element.getAttribute('data-plan-name');
|
|
|
|
|
|
|
|
// Find the plan dropdown in the contact form
|
|
|
|
const planDropdown = document.getElementById('id_choice');
|
|
|
|
if (planDropdown) {
|
|
|
|
// Find the option with matching plan id and select it
|
|
|
|
for (let i = 0; i < planDropdown.options.length; i++) {
|
|
|
|
const optionValue = planDropdown.options[i].value;
|
|
|
|
if (optionValue.startsWith(planId + '|')) {
|
|
|
|
planDropdown.selectedIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|