PageSourceSearch

https://www.cakemail.com/blog/assets/js/language-switcher.1e287ffc…20db2d3dddc405e062b131fbcd07e29dd533d6e1.js

js cakemail.com collected 2026-09-24 10:46:45 UTC 2,082 bytes, 40 lines download raw bytes

1/* Language switcher hrefs, rebuilt from the page's own hreflang alternates.
2 *
3 * The switcher ships absolute per-host URLs in the markup, but on a Weglot-fronted host Weglot's
4 * proxy rewrites any link pointing at its original domain (www.cakemail.com) into the host being
5 * viewed, so the English option is served as a self-link. Live repaired this with general.js's
6 * initWeglot(), which read Weglot's own injected container and bailed out entirely when Weglot was
7 * absent. This does the same job from `link[rel=alternate][hreflang]` instead, which is correct
8 * whether or not Weglot is in front: with Weglot those tags are its own (verified: hreflang="en"
9 * points at www.cakemail.com on every locale host), without it they are ours.
10 *
11 * Deliberately Weglot-free, so the switcher keeps working on the day Weglot is dropped.
12 *
13 * Lives in assets/js/ rather than assets/vendor/js/ because it is ours: that directory holds
14 * third-party bundles only. Not linted - eslint here runs off the TypeScript project service and
15 * cannot parse browser JS - so it is covered by tools/verify's own tests instead, same arrangement
16 * as edge/cloudfront/.
17 */
18(function () {
19  function syncSwitcher() {
20    var map = {};
21    document.querySelectorAll('link[rel="alternate"][hreflang]').forEach(function (link) {
22      var code = link.getAttribute('hreflang');
23      if (code) map[code] = link.href;
24    });
25    var current = document.documentElement.getAttribute('lang');
26    document.querySelectorAll('.wg-element-wrapper.sw1 a[lang]').forEach(function (anchor) {
27      var code = anchor.getAttribute('lang');
28      var target = map[code];
29      /* Leave anything the page has no alternate for untouched - the hidden `br` entry lives on
30         href="#" in live too, and must not become undefined. */
31      if (target) anchor.setAttribute('href', target);
32      if (code === current) anchor.classList.add('selected');
33    });
34  }
35  if (document.readyState === 'loading') {
36    document.addEventListener('DOMContentLoaded', syncSwitcher);
37  } else {
38    syncSwitcher();
39  }
40})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.