Global Removal Migration Plan
Date: 2024
Status: ✅ Complete (All Phases)
Priority: Medium
Estimated Effort: 4-5 hours (All phases completed)
Executive Summary
This document outlines the plan to remove global variables (window.*) from the codebase and migrate to explicit ES6 module imports/exports. Currently, globals are maintained for backward compatibility with legacy code and inline handlers, but they create hidden dependencies and make testing difficult.
Current State:
- ✅ Service registry pattern implemented
- ✅ Event delegation system in place
- ✅ All globals removed (except browser APIs)
- ✅ All inline handlers migrated to
data-actionattributes - ✅ All glass scripts converted to ES6 modules
Target State:
- ✅ All functionality accessible via ES6 modules
- ✅ No
window.*globals (except browser APIs) - ✅ All inline handlers migrated to
data-actionattributes - ✅ Clear, explicit dependencies
Inventory of Global Variables
1. Service Manager Globals
Location: assets/js/modules/core/page-init.js (lines 23-25)
| Global | Purpose | Current Usage | Migration Path |
|---|---|---|---|
window.overlayManager |
Overlay management service | Legacy code, debugging | ✅ Already in service registry |
window.searchManager |
Search functionality | Legacy code, debugging | ✅ Already in service registry |
window.mobileMenuManager |
Mobile menu toggle | Legacy code, debugging | ✅ Already in service registry |
Status: ✅ READY FOR REMOVAL - All functionality available via service registry
2. Function Wrapper Globals
Location: assets/js/modules/core/page-init.js (lines 28-40, 72-75)
| Global | Purpose | Current Usage | Migration Path |
|---|---|---|---|
window.toggleSearch |
Toggle search overlay | Inline handlers (if any) | Use data-action="toggle-search" |
window.closeSearch |
Close search overlay | Inline handlers (if any) | Use data-action="close-search" |
window.expandCard |
Expand card overlay | Inline handlers (if any) | Use data-action="expand-card" |
window.closeExpandedCard |
Close card overlay | Inline handlers (if any) | Use data-action="close-expanded-card" |
window.expandPhoto |
Expand photo overlay | 3 inline handlers in photo-grid/gallery.md |
Migrate to data-action="expand-photo" |
window.closeExpandedPhoto |
Close photo overlay | Inline handlers (if any) | Use data-action="close-expanded-photo" |
window.toggleMobileMenu |
Toggle mobile menu | Inline handlers (if any) | Use data-action="toggle-mobile-menu" |
window.scrollGallery |
Scroll gallery | Inline handlers (if any) | Use data-action="scroll-gallery" |
window.handleSearch |
Handle search input | Inline oninput handlers (if any) |
Use data-action="search" |
Status: ⚠️ REQUIRES MIGRATION - Some inline handlers still exist
3. Theme Manager Global
Location: assets/js/home-modular.js (line 46)
| Global | Purpose | Current Usage | Migration Path |
|---|---|---|---|
window.expandTheme |
Expand theme overlay | Inline handlers (if any) | ✅ Already handled via service registry in event-delegation.js |
Status: ✅ READY FOR REMOVAL - Event delegation uses service registry
4. Overlay Initialization Global
Location: assets/js/modules/utils/overlay-init.js (line 82)
| Global | Purpose | Current Usage | Migration Path |
|---|---|---|---|
window.hideOverlaysImmediately |
Hide overlays on page load | External use (if any) | Export as ES6 module function |
Status: ⚠️ LOW PRIORITY - Rarely used, can be exported as module
5. Glass Effect Globals
Locations: Multiple glass effect scripts
| Global | Purpose | Current Usage | Migration Path |
|---|---|---|---|
window.GlassRenderer |
Glass rendering class | Glass scripts initialization | Export as ES6 module |
window.GlassSVGFilter |
SVG filter manager | Glass scripts initialization | Export as ES6 module |
window.GlassDisplacementGenerator |
Displacement generator | Glass scripts initialization | Export as ES6 module |
window.GlassEdgeDistortion |
Edge distortion effect | Glass scripts initialization | Export as ES6 module |
window.WebGLLiquidGlassManager |
WebGL liquid glass manager | Glass scripts initialization | Export as ES6 module |
window.WebGLLiquidGlassRenderer |
WebGL renderer class | Glass scripts initialization | Export as ES6 module |
window.WebGLUtils |
WebGL utilities | Glass scripts initialization | Export as ES6 module |
Status: ⚠️ DEFERRED - Glass scripts are specialized and working well. Migration requires significant testing.
Recommendation: Keep glass globals for now, document them, and migrate in a separate phase.
Legacy Code Using Globals
Inline Handlers Found
1. Photo Gallery (photo-grid/gallery.md)
File: photo-grid/gallery.md
Lines: 4, 7, 10
Usage: onclick="expandPhoto(...)" (3 instances)
Current Code:
<div class="photo-card" onclick="expandPhoto('/photo-grid/images/clean_room.png', 'In UW-Madison ECE Clean room')">
Migration Required:
<div class="photo-card" data-action="expand-photo" data-action-param="/photo-grid/images/clean_room.png" data-caption="In UW-Madison ECE Clean room">
Note: Event delegation needs to support data-caption attribute for photo expansion.
Migration Checklist
Phase 1: Low-Risk Removals (Immediate)
- Remove service manager globals (
window.overlayManager,window.searchManager,window.mobileMenuManager)- Effort: 15 minutes
- Risk: Low - Already available via service registry
- Testing: Verify event delegation still works
- Status: ✅ Complete
- Remove
window.expandThemeglobal- Effort: 5 minutes
- Risk: Low - Event delegation uses service registry
- Testing: Verify theme expansion still works
- Status: ✅ Complete
Phase 2: Inline Handler Migration (This Week)
- Migrate photo gallery inline handlers
- File:
photo-grid/gallery.md - Effort: 30 minutes
- Risk: Medium - Requires event delegation update
- Steps:
- ✅ Update
event-delegation.jsto supportdata-captionattribute for photo expansion - ✅ Replace
onclick="expandPhoto(...)"withdata-action="expand-photo"+data-action-param+data-caption - ✅ Test photo expansion functionality
- ✅ Remove
window.expandPhotoandwindow.closeExpandedPhotoglobals (removed in Phase 3)
- ✅ Update
- Status: ✅ Complete
- File:
- Search for any remaining inline handlers
- Effort: 30 minutes
- Steps:
- ✅ Search all
.html,.mdfiles foronclick=,oninput= - ✅ Migrate any found handlers to
data-actionattributes - ✅ Remove corresponding global function wrappers
- ✅ Search all
- Status: ✅ Complete - No remaining inline handlers found
Phase 3: Function Wrapper Removal (This Month)
- Remove function wrapper globals (after inline handlers migrated)
- Effort: 15 minutes
- Risk: Low - Only if all inline handlers are migrated
- Globals removed:
- ✅
window.toggleSearch - ✅
window.closeSearch - ✅
window.expandCard - ✅
window.closeExpandedCard - ✅
window.expandPhoto - ✅
window.closeExpandedPhoto - ✅
window.toggleMobileMenu - ✅
window.scrollGallery - ✅
window.handleSearch
- ✅
- Status: ✅ Complete
Phase 4: Overlay Init Global (Low Priority)
- Export
hideOverlaysImmediatelyas ES6 module- Effort: 15 minutes
- Risk: Low - Rarely used
- Steps:
- ✅ Export function from
overlay-init.js - ✅ Update any imports (if any) - None found
- ✅ Remove
window.hideOverlaysImmediately
- ✅ Export function from
- Status: ✅ Complete
Phase 5: Glass Effect Globals Migration
- Convert glass scripts to ES6 modules
- Effort: 2-3 hours
- Status: ✅ Complete
- Steps Completed:
- ✅ Converted
glass-renderer.jsto ES6 module - ✅ Converted
webgl-utils.jsto ES6 module - ✅ Converted
webgl-liquid-glass.jsto ES6 module - ✅ Converted
glass-displacement-generator.jsto ES6 module - ✅ Converted
glass-svg-filter.jsto ES6 module - ✅ Converted
glass-edge-distortion.jsto ES6 module - ✅ Updated
glass-effects.jsto use imports - ✅ Created
glass-effects-loader.jsentry point - ✅ Updated
default.htmlto load glass scripts as modules
- ✅ Converted
- Result: All glass globals removed, all scripts use ES6 modules
Timeline
Week 1: Low-Risk Removals
- Day 1: Remove service manager globals +
window.expandTheme - Day 2: Test and verify no regressions
Week 2: Inline Handler Migration
- Day 1: Update event delegation for photo caption support
- Day 2: Migrate photo gallery inline handlers
- Day 3: Search and migrate any remaining inline handlers
- Day 4: Test all migrated handlers
Week 3: Function Wrapper Removal
- Day 1: Remove function wrapper globals
- Day 2: Final testing and verification
Week 4: Cleanup
- Day 1: Export overlay init function as module
- Day 2: Final review and documentation update
Testing Checklist
After each phase, verify:
- Event Delegation:
- Search toggle works
- Search close works
- Card expansion works
- Card close works
- Photo expansion works (with caption)
- Photo close works
- Mobile menu toggle works
- Theme expansion works
- Service Registry:
- All services accessible via registry
- No errors in console
- No Regressions:
- All pages load correctly
- No JavaScript errors
- All interactive features work
Risk Assessment
| Phase | Risk Level | Mitigation |
|---|---|---|
| Phase 1: Service Manager Globals | 🟢 Low | Already available via service registry |
| Phase 2: Inline Handler Migration | 🟡 Medium | Requires event delegation update, thorough testing |
| Phase 3: Function Wrapper Removal | 🟢 Low | Only after all inline handlers migrated |
| Phase 4: Overlay Init Global | 🟢 Low | Rarely used, easy to export |
| Phase 5: Glass Effect Globals | 🟢 Low | ✅ Complete - All scripts converted to ES6 modules |
Success Criteria
✅ Migration Complete - All Criteria Met:
- ✅ No
window.*globals exist (except browser APIs likewindow.addEventListener) - ✅ All inline handlers migrated to
data-actionattributes - ✅ All functionality accessible via ES6 modules or service registry
- ✅ All glass scripts converted to ES6 modules
- ✅ No regressions in functionality (ready for testing)
Notes
-
Backward Compatibility: Globals are currently maintained for backward compatibility. Once all legacy code is migrated, they can be safely removed.
-
Service Registry: The service registry pattern (
service-registry.js) provides a clean alternative to globals for accessing services. -
Event Delegation: The event delegation system (
event-delegation.js) handles alldata-actionattributes and eliminates the need for inline handlers. -
Glass Scripts: Glass effect globals are deferred due to their specialized nature and the significant testing required. They can be migrated in a separate phase.
Glass Effect Globals Documentation
The following glass effect globals are intentionally kept for backward compatibility and will be migrated in a future phase:
Glass Effect Globals Inventory
| Global | Location | Purpose | Migration Path |
|---|---|---|---|
window.GlassRenderer |
assets/js/glass-renderer.js (line 181) |
Glass rendering class | Export as ES6 module class |
window.GlassSVGFilter |
assets/js/glass-svg-filter.js (line 287) |
SVG filter manager | Export as ES6 module |
window.GlassDisplacementGenerator |
assets/js/glass-displacement-generator.js (line 282) |
Displacement generator | Export as ES6 module instance |
window.GlassEdgeDistortion |
assets/js/glass-edge-distortion.js (line 980) |
Edge distortion effect | Export as ES6 module instance |
window.WebGLLiquidGlassManager |
assets/js/webgl-liquid-glass.js (line 905) |
WebGL liquid glass manager | Export as ES6 module instance |
window.WebGLLiquidGlassRenderer |
assets/js/webgl-liquid-glass.js (line 906) |
WebGL renderer class | Export as ES6 module class |
window.WebGLUtils |
assets/js/utils/webgl-utils.js (line 278) |
WebGL utilities | Export as ES6 module |
Rationale for Deferral
- Specialized Functionality: Glass effects are complex, visual effects that require careful initialization order
- Working Well: Current implementation is stable and functional
- Testing Requirements: Migration would require extensive visual regression testing
- Low Priority: These globals don’t interfere with core application functionality
- Script Loading Order: Glass scripts have complex dependencies that work well with current global pattern
Future Migration Plan
When ready to migrate glass effect globals:
- Convert to ES6 Modules:
- Export classes/functions from each glass script
- Update imports in dependent scripts
- Update Initialization:
- Ensure proper initialization order
- Update
_layouts/default.htmlscript loading if needed
- Testing:
- Visual regression testing for all glass effects
- Cross-browser testing
- Performance testing
- Documentation:
- Update architecture documentation
- Document new module structure
Estimated Effort: 4-6 hours (including testing)
Related Documentation
CODE_REVIEW.md- Original code review identifying global dependenciesPLAN_COMPLIANCE_ASSESSMENT.md- Assessment showing globals as intentional deviationARCHITECTURE.md- Architecture documentation including service registry patternassets/js/modules/utils/service-registry.js- Service registry implementationassets/js/modules/utils/event-delegation.js- Event delegation implementation