/** * HVAC jQuery Compatibility Fix * * Resolves jQuery no-conflict mode issues in WordPress environments * where $ is not available globally but window.jQuery is. * * This fix ensures all HVAC JavaScript files can access jQuery * methods like removeClass, addClass, etc. without errors. * * @version 1.0.0 * @date August 12, 2025 */ (function() { 'use strict'; console.log('๐ง HVAC jQuery Compatibility Fix Loading...'); // Ensure jQuery is available if (typeof window.jQuery === 'undefined') { console.error('โ HVAC Compatibility Fix: jQuery not found!'); return; } // Store jQuery version for debugging const jqueryVersion = window.jQuery.fn.jquery; console.log(`โ jQuery ${jqueryVersion} detected`); // Create global $ alias if not available if (typeof window.$ === 'undefined') { window.$ = window.jQuery; console.log('๐ Global $ alias created from window.jQuery'); } // Extend jQuery with HVAC-specific compatibility methods window.jQuery.extend({ hvacSafeFind: function(selector) { try { return window.jQuery(selector); } catch (error) { console.warn('โ ๏ธ HVAC Safe Find Error:', error.message, 'for selector:', selector); return window.jQuery(); } } }); // Add HVAC-specific jQuery methods to prototype for enhanced compatibility window.jQuery.fn.extend({ hvacSafeRemoveClass: function(className) { try { if (this.length > 0) { return this.removeClass(className); } return this; } catch (error) { console.warn('โ ๏ธ HVAC Safe Remove Class Error:', error.message); // Fallback to vanilla JavaScript this.each(function() { if (this.classList && className) { this.classList.remove(className); } }); return this; } }, hvacSafeAddClass: function(className) { try { if (this.length > 0) { return this.addClass(className); } return this; } catch (error) { console.warn('โ ๏ธ HVAC Safe Add Class Error:', error.message); // Fallback to vanilla JavaScript this.each(function() { if (this.classList && className) { this.classList.add(className); } }); return this; } }, hvacSafeVal: function(value) { try { if (typeof value !== 'undefined') { return this.val(value); } return this.val(); } catch (error) { console.warn('โ ๏ธ HVAC Safe Val Error:', error.message); if (this.length > 0) { return this[0].value || ''; } return ''; } } }); // Global error handler for jQuery-related errors window.addEventListener('error', function(event) { if (event.error && event.error.message) { const message = event.error.message; if (message.includes('removeClass') || message.includes('addClass') || message.includes('$ is not defined') || message.includes('jQuery')) { console.warn('๐จ HVAC jQuery Compatibility Issue Detected:', message); console.warn('๐ก Suggestion: Use window.jQuery instead of $ or wrap code in jQuery(document).ready()'); // Attempt to fix common issues if (typeof window.$ === 'undefined' && typeof window.jQuery !== 'undefined') { window.$ = window.jQuery; console.log('๐ง Auto-fixed: Created global $ alias'); } } } }); // Enhanced Field Population System Integration function initializeEnhancedFieldPopulation() { // Wait for enhanced field population system to load const checkInterval = setInterval(function() { if (typeof window.HVACEnhancedFieldPopulation !== 'undefined') { console.log('โ Enhanced Field Population System detected'); clearInterval(checkInterval); // Test the system try { if (typeof window.HVACEnhancedFieldPopulation.testFieldAccess === 'function') { const testResult = window.HVACEnhancedFieldPopulation.testFieldAccess(); console.log('๐งช Field Access Test Result:', testResult); } } catch (error) { console.error('โ Enhanced Field Population Test Error:', error.message); } } }, 500); // Stop checking after 10 seconds setTimeout(function() { clearInterval(checkInterval); }, 10000); } // Safe document ready function function safeDocumentReady(callback) { if (typeof window.jQuery !== 'undefined') { window.jQuery(document).ready(callback); } else { if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', callback); } else { callback(); } } } // Initialize when DOM is ready safeDocumentReady(function() { console.log('๐ฏ HVAC jQuery Compatibility Fix Active'); // Test jQuery operations try { const testElement = window.jQuery('