1window.makeLink = function (element) { 2 var link = document.createElement('a'); 3 4 while (element.firstChild) { 5 link.appendChild(element.firstChild); 6 } 7 8 Array.prototype.forEach.call(element.attributes, function(attr) { 9 var name = attr.name; 10 11 if (name === 'data-future-href') { 12 name = 'href'; 13 14 if (!attr.value) { 15 return; 16 } 17 } 18 19 link.setAttribute(name, attr.value); 20 }); 21 22 var parent = element.parentNode; 23 parent.insertBefore(link, element); 24 parent.removeChild(element); 25}; 26 27/** 28 * Legacy desktop/mobile flavour switch. 29 * 30 * The footer "Mobile version" / "Desktop version" controls used to link to 31 * ?flavour=full|mobile, which created crawlable duplicate URLs. They now carry a 32 * `data-flavour-switch="<flavour>"` attribute and no href, so nothing is 33 * crawlable. Clicking (or pressing Enter/Space) sets the `flavour` cookie that 34 * FlavourMiddleware reads, then reloads the current, unchanged URL. 35 */ 36(function () { 37 var COOKIE_MAX_AGE = 60 * 60 * 24 * 365; // 1 year 38 39 // Reload seam, kept overridable so it can be stubbed in tests (window.location 40 // .reload is non-configurable in modern browsers and cannot be spied directly). 41 window.reloadPage = window.reloadPage || function () { 42 window.location.reload(); 43 }; 44 45 function findSwitch(target) { 46 var el = target; 47 while (el && el.nodeType === 1) { 48 if (el.hasAttribute('data-flavour-switch')) { 49 return el; 50 } 51 el = el.parentNode; 52 } 53 return null; 54 } 55 56 function applyFlavour(el) { 57 document.cookie = 'flavour=' + el.getAttribute('data-flavour-switch') 58 + '; path=/; max-age=' + COOKIE_MAX_AGE; 59 window.reloadPage(); 60 } 61 62 document.addEventListener('click', function (e) { 63 var el = findSwitch(e.target); 64 if (el) { 65 e.preventDefault(); 66 applyFlavour(el); 67 } 68 }, false); 69 70 document.addEventListener('keydown', function (e) { 71 if (e.key !== 'Enter' && e.key !== ' ' && e.key !== 'Spacebar') { 72 return; 73 } 74 var el = findSwitch(e.target); 75 if (el) { 76 e.preventDefault(); 77 applyFlavour(el); 78 } 79 }, false); 80}());
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.