You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: modernize event binding using .on() instead of deprecated methods
Replace all instances of direct event binding methods (.click(), .focus(),
.bind(), .blur(), etc.) with the modern .on() API across the codebase.
The jQuery .on() method has been the recommended way to attach event
handlers since jQuery 1.7 (2011), superseding:
- .bind()
- .live() (removed in 1.9)
- .delegate()
- shorthand methods (.click(), .hover()) when delegation or cleanup is needed
While the shorthand methods still work, using .on() consistently provides:
- A single, unified pattern for event attachment
- Clear intent for both direct and delegated events
- Better compatibility with future jQuery versions
- Easier event namespace management and removal (.off())
This change touches multiple modules:
- GitTurns20: popstate handling and tagline click counter
- Search: focus, blur, keydown, and result interaction
- Dropdowns: toggle activation via click
- Forms: input selection
- Downloads: OS filter navigation
- DarkMode: toggle button interaction
- ScrollToTop: scroll monitoring and click behavior
Notable improvements:
- $(window).bind('popstate', ...) → $(window).on('popstate', ...): aligns with current best practices
- $("#tagline").click(...) → .on('click', ...): enables future delegation if needed
- $(document).keydown(...) → .on('keydown', ...): consistent event model
- $('#scrollToTop').click(...) → .on('click', ...): unified pattern across UI components
Additionally:
- Fixed event trigger in keyboard shortcut handler: now uses .trigger('focus') instead of direct .focus() to ensure consistent event flow
- Preserved event argument (e) and logic (e.preventDefault(), timeStamp checks) — no behavioral changes
- All selectors and functionality remain intact; this is a syntactic and maintainability upgrade
This refactor was guided by warnings from jQuery Migrate and is part of the larger migration plan:
1. Add jQuery Migrate → done
2. Fix deprecated patterns (like .bind(), .click()) → this commit
3. Upgrade to jQuery 3.7.1
4. Remove Migrate when clean
The code remains functionally identical, but is now more maintainable,
consistent, and future-proof. No regressions expected.
See: https://api.jquery.com/on/
See: https://github.com/jquery/jquery-migrate#readme
0 commit comments