Search

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:

Target State:


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

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)

Phase 2: Inline Handler Migration (This Week)

Phase 3: Function Wrapper Removal (This Month)

Phase 4: Overlay Init Global (Low Priority)

Phase 5: Glass Effect Globals Migration


Timeline

Week 1: Low-Risk Removals

Week 2: Inline Handler Migration

Week 3: Function Wrapper Removal

Week 4: Cleanup


Testing Checklist

After each phase, verify:


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:

  1. ✅ No window.* globals exist (except browser APIs like window.addEventListener)
  2. ✅ All inline handlers migrated to data-action attributes
  3. ✅ All functionality accessible via ES6 modules or service registry
  4. ✅ All glass scripts converted to ES6 modules
  5. ✅ No regressions in functionality (ready for testing)

Notes


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

  1. Specialized Functionality: Glass effects are complex, visual effects that require careful initialization order
  2. Working Well: Current implementation is stable and functional
  3. Testing Requirements: Migration would require extensive visual regression testing
  4. Low Priority: These globals don’t interfere with core application functionality
  5. 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:

  1. Convert to ES6 Modules:
    • Export classes/functions from each glass script
    • Update imports in dependent scripts
  2. Update Initialization:
    • Ensure proper initialization order
    • Update _layouts/default.html script loading if needed
  3. Testing:
    • Visual regression testing for all glass effects
    • Cross-browser testing
    • Performance testing
  4. Documentation:
    • Update architecture documentation
    • Document new module structure

Estimated Effort: 4-6 hours (including testing)