CodeSOD: Height of the Accordion
In the bad old days of web development, you had to deal with the fact that there weren't really any standards, and you had to customize your code for different browsers. The "right" way was to sniff for which features were available, but the most commonly used way was to check the user-agent string and guess based on the browser name. Because of this, browsers started to keyword spam their user-agent, to pass these checks, which is why my browser reports as Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36. My browser of choice is a Chrome fork, and I'm running on an M1 Mac, so basically none of those things are true.
But let's look back at some code Lucas found, still lingering in a web app he maintains.
if (navigator.appName == 'Microsoft Internet Explorer'){ $("##accordion").accordion({ autoHeight: false });}else{ $("##accordion").accordion({ autoHeight: false });}
Maybe once, this was useful, but clearly the last time anyone touched it, it became vestigial. This is a "just in case" branch: it remains just in case you need to change the behavior for non IE browsers, and forget how to reconstruct the branch when you actually need it. Maybe someday it'll need to be changed, we don't know.
We do know: it should be changed, and the whole thing made to go away. With a bonus of the recognition that this is calling into JQuery UI components, components you use specifically because the JQuery UI developers are doing the hard work of managing browser compatibility for you. Now, I can't guarantee that there was never a need to hack in some of your own cross-browser compatibility, but at this point, it looks like clearly not.
[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!