JavaScript
5 articles on JavaScript, each a problem from production engineering work and how it was solved.
-
Last day of the month in JavaScript without timezone bugs
Compute a month's last day from the year and month with Date.UTC and getUTCDate, so the browser's time zone can never shift a date-only value.
-
Inlining the same SVG many times breaks url(#id) in Firefox
Copies of an inline SVG share ids, so url(#id) resolves to the first copy. Give every injected copy unique ids, or a hidden first copy breaks the rest.
-
Fix a jQuery plugin that registers on the wrong jQuery in webpack
Webpack can bundle a private jQuery, so a plugin registers on the wrong one. Map jquery to the page global with a function externals entry for that plugin.
-
Show a Drupal Commerce checkout pane only for card payments
Ajax-replaced payment radios rule out #states, so toggle the pane with a data attribute and skip its validation server-side when hidden.
-
Reveal the Drupal tab holding an invalid required field
Listen for the invalid event in the capture phase and focus the first invalid control's horizontal tab so browser validation stops pointing at a hidden field.