Commit 9d2ef6b
committed
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#readme1 parent 0fd4dd0 commit 9d2ef6b
1 file changed
+14
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
| 187 | + | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| |||
470 | 470 | | |
471 | 471 | | |
472 | 472 | | |
473 | | - | |
| 473 | + | |
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
| |||
491 | 491 | | |
492 | 492 | | |
493 | 493 | | |
494 | | - | |
| 494 | + | |
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
| |||
545 | 545 | | |
546 | 546 | | |
547 | 547 | | |
548 | | - | |
| 548 | + | |
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
| |||
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
651 | | - | |
| 651 | + | |
652 | 652 | | |
653 | 653 | | |
654 | 654 | | |
| |||
780 | 780 | | |
781 | 781 | | |
782 | 782 | | |
783 | | - | |
| 783 | + | |
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
787 | 787 | | |
788 | | - | |
| 788 | + | |
789 | 789 | | |
790 | 790 | | |
791 | 791 | | |
| |||
0 commit comments