Created
April 28, 2017 09:02
-
-
Save dsingleton/8e64484b6da8171b7679774471390982 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*@cc_on | |
@if (@_jscript_version <= 9) | |
(function(f){ | |
window.setTimeout = f(window.setTimeout); | |
window.setInterval = f(window.setInterval); | |
})(function(f){return function(c,t){var a=[].slice.call(arguments,2);return f(function(){c.apply(this,a)},t)}}); | |
@end | |
@*/ | |
(function(window) { | |
var lastTime, vendors; | |
if (!window.requestAnimationFrame) { | |
lastTime = 0; | |
vendors = ["ms", "moz", "webkit", "o"]; | |
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { | |
window.requestAnimationFrame = window[vendors[x] + "RequestAnimationFrame"]; | |
window.cancelAnimationFrame = window[vendors[x] + "CancelAnimationFrame"] || window[vendors[x] + "CancelRequestAnimationFrame"] | |
} | |
window.requestAnimationFrame = function(callback, element) { | |
var currTime = (new Date).getTime(); | |
var timeToCall = Math.max(0, 16 - (currTime - lastTime)); | |
var id = window.setTimeout(function() { | |
callback(currTime + timeToCall) | |
}, timeToCall); | |
lastTime = currTime + timeToCall; | |
return id | |
} | |
} | |
if (!window.cancelAnimationFrame) window.cancelAnimationFrame = function(id) { | |
clearTimeout(id) | |
} | |
})(window); | |
(function(window, document) { | |
var weShouldPolyfill = !("open" in document.createElement("details")); | |
function toggleDetailsState(details) { | |
if (details.hasAttribute("open")) details.removeAttribute("open"); | |
else details.setAttribute("open", "open") | |
} | |
function handleEvent(event) { | |
var targetNode = event.target; | |
while (targetNode.nodeName.toLowerCase() !== "summary" && targetNode !== document) targetNode = targetNode.parentNode; | |
if (targetNode.nodeName.toLowerCase() === "summary") toggleDetailsState(targetNode.parentNode) | |
} | |
function bindEvents() { | |
document.addEventListener("click", handleEvent, true); | |
document.addEventListener("keypress", function(event) { | |
if (event.key && (event.key === " " || event.key === "Enter")) handleEvent(event); | |
else if (event.keyCode === 32 || event.keyCode === 13) handleEvent(event) | |
}, true) | |
} | |
function appendCss() { | |
if (document.querySelector("#details-polyfill-css") === null) { | |
var style = document.createElement("style"); | |
style.id = "details-polyfill-css"; | |
style.textContent = "details:not([open]) \x3e *:not(summary) {display: none;}"; | |
document.head.insertBefore(style, document.head.firstChild) | |
} | |
} | |
if (weShouldPolyfill) { | |
bindEvents(); | |
appendCss() | |
} | |
})(window, document); | |
(function(window) { | |
var location = window.location; | |
var hash = location.hash; | |
var navigator = window.navigator; | |
var platform = navigator.platform; | |
var isFront = true; | |
var enhancedKey = "gu.prefs.enhanced"; | |
var preferEnhanced; | |
try { | |
preferEnhanced = JSON.parse(localStorage.getItem(enhancedKey)).value | |
} catch (e) { | |
preferEnhanced = null | |
} | |
function mustEnhance() { | |
if (hash === "#enhanced" || hash === "#" + enhancedKey + "\x3dtrue") return true; | |
if (preferEnhanced) return true; | |
return false | |
} | |
function mustNotEnhance() { | |
return hash === "#standard" || hash === "#" + enhancedKey + "\x3dfalse" | |
} | |
function couldEnhance() { | |
return preferEnhanced !== false | |
} | |
function weWantToEnhance() { | |
if (isOlderIOSDevice()) return false; | |
if (isFront) return !isIpad(); | |
return true | |
} | |
function isOlderIOSDevice() { | |
return /.*(iPhone|iPad|iPod; CPU) OS ([34567])_\d+.*/.test(navigator.userAgent) | |
} | |
function isIpad() { | |
return platform === "iPad" | |
} | |
window.shouldEnhance = mustNotEnhance() ? false : mustEnhance() ? true : couldEnhance() && weWantToEnhance() | |
})(window); | |
var isModernBrowser = "querySelector" in document && "addEventListener" in window && "localStorage" in window && "sessionStorage" in window && "bind" in Function && (("XMLHttpRequest" in window && "withCredentials" in new XMLHttpRequest()) || "XDomainRequest" in window); | |
window.guardian = { | |
isModernBrowser: isModernBrowser, | |
isEnhanced: window.shouldEnhance && isModernBrowser, | |
css: { | |
loaded: false | |
}, | |
polyfilled: false, | |
adBlockers: { | |
active: undefined, | |
onDetect: [] | |
}, | |
config: { | |
"page": { | |
"avatarApiUrl": "https://avatar.theguardian.com", | |
"membershipUrl": "https://membership.theguardian.com", | |
"isProd": true, | |
"discussionFrontendUrl": "", | |
"membershipAccess": "", | |
"allowUserGeneratedContent": false, | |
"forecastsapiurl": "/weatherapi/forecast", | |
"idOAuthUrl": "https://oauth.theguardian.com", | |
"supportUrl": "https://support.theguardian.com", | |
"webTitle": "Network Front", | |
"isFront": true, | |
"idWebAppUrl": "https://oauth.theguardian.com", | |
"googleSearchUrl": "//www.google.co.uk/cse/cse.js", | |
"googleSearchId": "007466294097402385199:m2ealvuxh1i", | |
"idUrl": "https://profile.theguardian.com", | |
"omnitureAmpAccount": "guardiangu-thirdpartyapps", | |
"dfpAdUnitRoot": "theguardian.com", | |
"host": "https://www.theguardian.com", | |
"fbAppId": "180444840287", | |
"dfpAccountId": "59666047", | |
"plistaPublicApiKey": "462925f4f131001fd974bebe", | |
"switchPreFlightJsUrl": "//delivery.guardian.switchadhub.com/0.js", | |
"cardStyle": "", | |
"adUnit": "/59666047/theguardian.com/uk/front/ng", | |
"discussionApiUrl": "https://discussion.theguardian.com/discussion-api", | |
"ophanEmbedJsUrl": "//j.ophan.co.uk/ophan.embed", | |
"edition": "UK", | |
"userAttributesApiUrl": "https://members-data-api.theguardian.com/user-attributes", | |
"discussionApiClientHeader": "nextgen", | |
"hasSuperStickyBanner": false, | |
"section": "uk", | |
"dfpHost": "pubads.g.doubleclick.net", | |
"weatherapiurl": "/weatherapi/city", | |
"sentryPublicApiKey": "344003a8d11c41d8800fbad8383fdc50", | |
"pageId": "uk", | |
"sonobiHeaderBiddingJsUrl": "//api.nextgen.guardianapps.co.uk/morpheus.theguardian.12913.js", | |
"beaconUrl": "//beacon.gu-web.net", | |
"discussionD2Uid": "zHoBy6HNKsk", | |
"ophanJsUrl": "//j.ophan.co.uk/ophan.ng", | |
"keywordIds": "", | |
"contentType": "Network Front", | |
"isDev": false, | |
"facebookIaAdUnitRoot": "facebook-instant-articles", | |
"stripePublicToken": "pk_live_2O6zPMHXNs2AGea4bAmq5R7Z", | |
"omnitureAccount": "guardiangu-network", | |
"locationapiurl": "/weatherapi/locations?query=", | |
"isPaidContent": false, | |
"externalEmbedHost": "https://embed.theguardian.com", | |
"thirdPartyAppsAccount": "guardiangu-thirdpartyapps", | |
"ajaxUrl": "https://api.nextgen.guardianapps.co.uk", | |
"keywords": "Network Front", | |
"mobileAppsAdUnitRoot": "beta-guardian-app", | |
"hasPageSkin": false, | |
"requiresMembershipAccess": false, | |
"revisionNumber": "c13753ecf671f7f8efaea5897eaef4e2d0f6f92f", | |
"assetsPath": "https://assets.guim.co.uk/", | |
"avatarImagesUrl": "https://avatar.guim.co.uk", | |
"idApiJsClientToken": "ARwXnPbUzJ9T2qcUJRv15DuT_LkxAKnUqtdrHdx7XXtQrKpm6j0suScJVsymJ1TC6VxwHlzRt5yVBdw-3ARbpA", | |
"sentryHost": "app.getsentry.com/35463", | |
"buildNumber": "8420", | |
"sharedAdTargeting": { | |
"ct": "network-front", | |
"url": "/uk", | |
"edition": "uk", | |
"p": "ng", | |
"k": "uk" | |
}, | |
"onwardWebSocket": "ws://api.nextgen.guardianapps.co.uk/recently-published", | |
"shouldHideAdverts": false, | |
"googletagJsUrl": "//www.googletagservices.com/tag/js/gpt.js", | |
"idApiUrl": "https://idapi.theguardian.com", | |
"isPreview": false | |
}, | |
"switches": { | |
"boostGaUserTimingFidelity": false, | |
"thirdPartyEmbedTracking": true, | |
"scrollDepth": true, | |
"enableSentryReporting": true, | |
"ophan": true, | |
"openCta": false, | |
"discussionPageSize": true, | |
"discussion": true, | |
"externalVideoEmbeds": true, | |
"relatedContent": true, | |
"autoRefresh": true, | |
"lazyLoadContainers": true, | |
"registerWithPhone": false, | |
"discussionAllowAnonymousRecommendsSwitch": false, | |
"discussionAllPageSize": true, | |
"preflightAdCall": true, | |
"adFeedback": false, | |
"sonobiHeaderBidding": true, | |
"kruxVideoTracking": false, | |
"adblock": false, | |
"membershipEngagementBanner": true, | |
"simpleReach": true, | |
"remarketing": true, | |
"krux": true, | |
"imrWorldwide": true, | |
"audienceScienceGateway": true, | |
"tourismAustralia": true, | |
"adFreeMembershipTrial": true, | |
"blockIas": true, | |
"commercial": true, | |
"abPaidContentVsOutbrain2": true, | |
"abPaidCommentingInternal": true, | |
"abFilmTodayEmailVariants": false, | |
"abBookmarksEmailVariants2": true, | |
"abFashionStatementEmailVariants": false, | |
"abTheLongReadEmailVariants": false, | |
"abSleeveNotesLegacyEmailVariant": true, | |
"abSleeveNotesNewEmailVariant": true, | |
"abTailorSurvey": true, | |
"abAcquisitionsEpicLiveblog": true, | |
"abContributionsEpicAskFourEarning": true, | |
"abContributionsEpicAlwaysAskStrategy": true, | |
"abOpinionEmailVariants": true, | |
"abIncreaseInlineAdsRedux": true, | |
"abAuMembEngagementMsgCopyTest8": true, | |
"abMembershipEngagementInternationalExperimentTest12": true, | |
"abNavigationMoreToggleVariant": true, | |
"abNavigationMoreToggleControl": true, | |
"abNewRecipeDesign": true, | |
"commercialClientLogging": true, | |
"useTailorEndpoints": true, | |
"liveBlogChromeNotificationsProd": true, | |
"targeting": true, | |
"steadyPageUtil": false, | |
"sharingComments": true, | |
"smartAppBanner": true, | |
"emailSignupEuRef": true, | |
"emailSignupLabNotes": true, | |
"emailInArticleOutbrain": true, | |
"emailInArticleGtoday": true, | |
"emailInArticle": true, | |
"emailInlineInFooter": true, | |
"crosswordSvgThumbnails": true, | |
"historyTags": true, | |
"weather": true, | |
"breakingNews": true, | |
"enhancedMediaPlayer": true, | |
"enhanceTweets": true, | |
"idCookieRefresh": true, | |
"idProfileNavigation": true, | |
"googleSearch": true, | |
"webFonts": true, | |
"geoMostPopular": true, | |
"foresee": false, | |
"plistaForOutbrainAu": true, | |
"outbrain": true, | |
"exploreMainMedia": true, | |
"serverShareCounts": true | |
}, | |
"tests": {}, | |
"modules": {}, | |
"images": { | |
"commercial": { | |
"ab-icon": "https:\/\/assets.guim.co.uk\/images\/commercial\/504a6bc5825d269eaf8ffdc77ad1f5b8\/ab-icon.png", | |
"abp-icon": "https:\/\/assets.guim.co.uk\/images\/commercial\/15fa8f9f99ce2a6b804097d348622727\/abp-icon.png", | |
"abp-whitelist-instruction-chrome": "https:\/\/assets.guim.co.uk\/images\/commercial\/862b03a008061af5c3b77c1f2dd52dd4\/ad-block-instructions-chrome.png" | |
}, | |
"membership": { | |
"adblock-coins": "https:\/\/assets.guim.co.uk\/images\/membership\/6b077732beb2d9bf9dcbb78c953a3de5\/adblock-coins.png", | |
"adblock-coins-us": "https:\/\/assets.guim.co.uk\/images\/membership\/103510d0b88a6444f383b492d556c539\/adblock-coins-us.png" | |
} | |
}, | |
"stylesheets": { | |
"fonts": { | |
"hintingCleartype": { | |
"kerningOn": "https:\/\/assets.guim.co.uk\/stylesheets\/9f78997fd3b37533007e55334c9e7c8b\/webfonts-hinting-cleartype-kerning-on.css" | |
}, | |
"hintingOff": { | |
"kerningOn": "https:\/\/assets.guim.co.uk\/stylesheets\/50441b3bda46af4af85a3f0a1b61f8bb\/webfonts-hinting-off-kerning-on.css" | |
}, | |
"hintingAuto": { | |
"kerningOn": "https:\/\/assets.guim.co.uk\/stylesheets\/4f3512b7ca058a60dea4f4b994ab4ebc\/webfonts-hinting-auto-kerning-on.css" | |
} | |
} | |
}, | |
"googleAnalytics": { | |
"trackers": { | |
"editorialTest": "guardianTestPropertyTracker", | |
"editorialProd": "allEditorialPropertyTracker", | |
"editorial": "allEditorialPropertyTracker" | |
}, | |
"timingEvents": [] | |
}, | |
"libs": { | |
"foresee": "https:\/\/assets.guim.co.uk\/javascripts\/vendor\/foresee\/20150703\/527c6ee26fbdc0149bd153a26c7b9175\/foresee-trigger.js", | |
"googletag": "\/\/www.googletagservices.com\/tag\/js\/gpt.js", | |
"sonobi": "\/\/api.nextgen.guardianapps.co.uk\/morpheus.theguardian.12913.js", | |
"switch": "\/\/delivery.guardian.switchadhub.com\/0.js" | |
} | |
} | |
}; | |
if (window.esi && window.esi.viewId) { | |
window.guardian.config.ophan = { | |
pageViewId: window.esi.viewId | |
}; | |
} else { | |
window.guardian.config.ophan = { | |
pageViewId: new Date().getTime().toString(36) + 'xxxxxxxxxxxx'.replace(/x/g, function() { | |
return Math.floor(Math.random() * 36).toString(36); | |
}) | |
}; | |
} | |
/*@cc_on | |
@if (@_jscript_version <= 9) | |
guardian.config.page.ajaxUrl = guardian.config.page.ajaxUrl.replace(/^https:/, ''); | |
@end | |
@*/ | |
(function(documentElement, window, navigator) { | |
var docClass = documentElement.className; | |
var testCssSupportForPropertyAndValue = function(supportsSupports) { | |
return supportsSupports ? nativeCSSSupports : shimCSSSupports() | |
}("CSS" in window && "supports" in window.CSS); | |
function nativeCSSSupports(prop, value) { | |
return window.CSS.supports(prop, value) | |
} | |
function shimCSSSupports() { | |
var cssToDOMRegExp = /([a-z])-([a-z])/g; | |
var testElem = document.createElement("test"); | |
function cssToDOM(name) { | |
return name.replace(cssToDOMRegExp, cssToDOMReplacer).replace(/^-/, "") | |
} | |
function cssToDOMReplacer(str, m1, m2) { | |
return m1 + m2.toUpperCase() | |
} | |
return function(prop, value) { | |
try { | |
prop = cssToDOM(prop); | |
var originalValue = testElem.style[prop]; | |
if (originalValue === undefined) return false; | |
if (originalValue === value) return true; | |
testElem.style[prop] = value; | |
return testElem.style[prop] !== originalValue | |
} catch (e) { | |
return false | |
} | |
} | |
} | |
function testAndAddClass(tests) { | |
docClass += " " + tests.map(function(test) { | |
return (test.props.some(function(prop) { | |
return test.values.some(function(value) { | |
return testCssSupportForPropertyAndValue(prop, value) | |
}) | |
}) ? "has-" : "has-no-") + test.feature | |
}).join(" ") | |
} | |
if (!!document.createElementNS && !!document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGRect) docClass += " svg"; | |
else docClass += " no-svg"; | |
testAndAddClass([{ | |
feature: "flex", | |
props: ["flex", "-ms-flex", "-webkit-flex", "-moz-box-flex", "-webkit-box-flex"], | |
values: ["inherit"] | |
}, { | |
feature: "flex-wrap", | |
props: ["flex-wrap", "-ms-flex-wrap", "-webkit-flex-wrap"], | |
values: ["inherit"] | |
}, { | |
feature: "fixed", | |
props: ["position"], | |
values: ["fixed"] | |
}, { | |
feature: "sticky", | |
props: ["position"], | |
values: ["sticky", "-webkit-sticky"] | |
}]); | |
if (window.guardian.isEnhanced) docClass = docClass.replace(/\bis-not-modern\b/g, "is-modern"); | |
if (window.location.hash === "#kern") docClass += " should-kern"; | |
var baseFontSize = null; | |
if ("getComputedStyle" in window) baseFontSize = window.getComputedStyle(documentElement).getPropertyValue("font-size"); | |
if (baseFontSize && parseInt(baseFontSize, 10) !== 16) documentElement.style.fontSize = baseFontSize; | |
documentElement.className = docClass.replace(/\bjs-off\b/g, "js-on") | |
})(document.documentElement, window, navigator); | |
(function(window, document) { | |
var ua = navigator.userAgent; | |
var fontHinting = function() { | |
var windowsNT = /Windows NT (\d\.\d+)/.exec(ua); | |
var hinting = "Off"; | |
try { | |
if (windowsNT) { | |
var version = parseFloat(windowsNT[1], 10); | |
if (version >= 5.1 && version <= 6.1) | |
if (/Chrome/.exec(ua) && version < 6) hinting = "Auto"; | |
else hinting = "Cleartype" | |
} | |
} catch (e) {} | |
return hinting | |
}(); | |
function loadFontsFromStorage() { | |
try { | |
if ("localStorage" in window) { | |
var saveFont = function(fontName, fontHash, css) { | |
for (var i = 0, totalItems = localStorage.length; i < totalItems - 1; i++) { | |
var key = localStorage.key(i); | |
if (key.indexOf(fontStorageKey(fontName)) !== -1) { | |
localStorage.removeItem(key); | |
break | |
} | |
} | |
localStorage.setItem(fontStorageKey(fontName, fontHash), JSON.stringify({ | |
value: css | |
})) | |
}; | |
var fetchFont = function(url, el, fontName, fontHash) { | |
var xhr = new XMLHttpRequest; | |
this["guFont"] = function(fontData) { | |
return fontData.css | |
}; | |
xhr.open("GET", url, true); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
var css = eval(xhr.responseText); | |
useFont(el, css); | |
saveFont(fontName, fontHash, css) | |
} | |
}; | |
xhr.send() | |
}; | |
var useFont = function(el, css) { | |
el.innerHTML = css | |
}; | |
var fontStorageKey = function(fontName, fontHash) { | |
fontHash = fontHash === undefined ? "" : fontHash; | |
return "gu.fonts." + fontName + "." + fontHash | |
}; | |
var fontFormat = function() { | |
var formatStorageKey = "gu.fonts.format"; | |
var format = localStorage.getItem(formatStorageKey); | |
function supportsWoff2() { | |
if ("FontFace" in window) try { | |
var f = new window.FontFace("t", 'url("data:application/font-woff2,") format("woff2")', {}); | |
f.load()["catch"](function() {}); | |
if (f.status === "loading") return true | |
} catch (e) {} | |
if (!/edge\/([0-9]+)/.test(ua.toLowerCase())) { | |
var browser = /(chrome|firefox)\/([0-9]+)/.exec(ua.toLowerCase()); | |
var supportsWoff2$0 = { | |
"chrome": 36, | |
"firefox": 39 | |
}; | |
return !!browser && supportsWoff2$0[browser[1]] < parseInt(browser[2], 10) | |
} | |
return false | |
} | |
if (/value/.test(format)) { | |
format = JSON.parse(format).value; | |
localStorage.setItem(formatStorageKey, format) | |
} | |
if (!format) { | |
format = supportsWoff2() ? "woff2" : ua.indexOf("android") > -1 ? "ttf" : "woff"; | |
localStorage.setItem(formatStorageKey, format) | |
} | |
return format | |
}(); | |
var fonts = document.querySelectorAll(".webfont"); | |
var hinting = fontHinting === "Off" ? "" : "hinted-" + fontHinting + "-"; | |
var urlAttribute = "data-cache-file-" + hinting + fontFormat; | |
for (var i = 0, j = fonts.length; i < j; ++i) { | |
var font = fonts[i]; | |
var fontURL = font.getAttribute(urlAttribute); | |
var fontInfo = fontURL.match(/fonts\/([^/]*?)\/?([^/]*)\.(woff2|woff|ttf).json$/); | |
var fontName = fontInfo[2]; | |
var fontHash = fontInfo[1]; | |
var fontData = localStorage.getItem(fontStorageKey(fontName, fontHash)); | |
if (fontData) useFont(font, JSON.parse(fontData).value); | |
else fetchFont(fontURL, font, fontName, fontHash) | |
} | |
return true | |
} | |
} catch (e) {} | |
return false | |
} | |
function loadFontsAsynchronously() { | |
try { | |
var scripts = document.getElementsByTagName("script"); | |
var thisScript = scripts[scripts.length - 1]; | |
var fonts = document.createElement("link"); | |
fonts.rel = "stylesheet"; | |
fonts.className = "webfonts"; | |
fonts.href = window.guardian.config.stylesheets.fonts["hinting" + fontHinting].kerningOn; | |
window.setTimeout(function() { | |
thisScript.parentNode.insertBefore(fonts, thisScript) | |
}) | |
} catch (e) {} | |
} | |
function fontSmoothingEnabled() { | |
try { | |
var saveFontSmoothing = function(state) { | |
state = state ? "on" : "off"; | |
document.cookie = "GU_fonts_smoothing\x3d " + state + "; domain\x3d" + location.hostname + "; path\x3d/; max-age\x3d" + 60 * 60 * 24 * 30 | |
}; | |
if (document.cookie.indexOf("GU_fonts_smoothing") !== -1 && window.location.hash !== "#check-smoothing") return document.cookie.indexOf("GU_fonts_smoothing\x3don") !== -1; | |
if (/Windows NT (\d\.\d+)/.exec(ua) && !/MSIE|Trident/.exec(ua)) { | |
try { | |
var canvasNode = document.createElement("canvas"); | |
canvasNode.width = "35"; | |
canvasNode.height = "35"; | |
canvasNode.style.display = "none"; | |
document.documentElement.appendChild(canvasNode); | |
var ctx = canvasNode.getContext("2d"); | |
ctx.textBaseline = "top"; | |
ctx.font = "32px Arial"; | |
ctx.fillStyle = "black"; | |
ctx.strokeStyle = "black"; | |
ctx.fillText("@", 0, 0); | |
for (var x = 0; x <= 16; x++) | |
for (var y = 0; y <= 16; y++) { | |
var alpha = ctx.getImageData(x, y, 1, 1).data[3]; | |
if (alpha > 0 && alpha < 255) { | |
saveFontSmoothing(true); | |
return true | |
} | |
} | |
} catch (e) {} | |
saveFontSmoothing(false); | |
return false | |
} else return true | |
} catch (e$1) {} | |
} | |
var fontCookie = "GU_fonts\x3doff; domain\x3d" + location.hostname + "; path\x3d/"; | |
function disableFonts() { | |
document.cookie = fontCookie + "; max-age\x3d" + 60 * 60 * 24 * 365 | |
} | |
function enableFonts() { | |
document.cookie = fontCookie + "; expires\x3dThu, 01 Jan 1970 00:00:00 GMT" | |
} | |
function checkUserFontDisabling() { | |
if (window.location.hash === "#fonts-off") disableFonts(); | |
else if (window.location.hash === "#fonts-on" || window.location.hash === "#check-smoothing") enableFonts() | |
} | |
var fontsEnabled = document.cookie.indexOf("GU_fonts\x3doff") === -1; | |
function loadFonts() { | |
checkUserFontDisabling(); | |
if (fontsEnabled) | |
if (fontSmoothingEnabled()) loadFontsFromStorage() || loadFontsAsynchronously(); | |
else disableFonts() | |
} | |
loadFonts() | |
})(window, document); | |
(function(w) { | |
var exposeLoadedState = function() { | |
w.guardian.css.loaded = true; | |
try { | |
w.guardian.css.onLoad() | |
} catch (e) {} | |
}; | |
var loadCSS = function(href, before, media) { | |
var doc = w.document; | |
var ss = doc.createElement("link"); | |
var ref; | |
if (before) ref = before; | |
else { | |
var refs = (doc.body || doc.getElementsByTagName("head")[0]).childNodes; | |
ref = refs[refs.length - 1] | |
} | |
var sheets = doc.styleSheets; | |
ss.rel = "stylesheet"; | |
ss.href = href; | |
ss.media = "only x"; | |
function ready(cb) { | |
if (doc.body) return cb(); | |
setTimeout(function() { | |
ready(cb) | |
}) | |
} | |
ready(function() { | |
ref.parentNode.insertBefore(ss, before ? ref : ref.nextSibling) | |
}); | |
var onloadcssdefined = function(cb) { | |
var resolvedHref = ss.href; | |
var i = sheets.length; | |
while (i--) | |
if (sheets[i].href === resolvedHref) return cb(); | |
setTimeout(function() { | |
onloadcssdefined(cb) | |
}) | |
}; | |
function loadCB() { | |
if (ss.addEventListener) ss.removeEventListener("load", loadCB); | |
ss.media = media || "all"; | |
exposeLoadedState() | |
} | |
if (ss.addEventListener) ss.addEventListener("load", loadCB); | |
ss.onloadcssdefined = onloadcssdefined; | |
onloadcssdefined(loadCB); | |
return ss | |
}; | |
var initialize = function() { | |
var isPreloadSpported = function() { | |
try { | |
return document.createElement("link").relList.supports("preload") | |
} catch (e) { | |
return false | |
} | |
}; | |
var preloadPolyfill = function() { | |
var links = document.getElementsByTagName("link"); | |
for (var i = 0; i < links.length; i++) { | |
var link = links[i]; | |
if (link.rel === "preload" && link.getAttribute("as") === "style") { | |
loadCSS(link.href, link, link.getAttribute("media")); | |
link.rel = null | |
} | |
} | |
}; | |
if (isPreloadSpported()) { | |
exposeLoadedState(); | |
return | |
} | |
preloadPolyfill(); | |
if (w.addEventListener) { | |
var run = setInterval(preloadPolyfill, 300); | |
w.addEventListener("load", function() { | |
preloadPolyfill(); | |
clearInterval(run) | |
}) | |
} | |
}; | |
initialize() | |
})(window); | |
function guardianPolyfilled() { | |
try { | |
window.guardian.polyfilled = true | |
} catch (e) {} | |
}(function(document, window) { | |
var scripts = []; | |
var src; | |
var script; | |
var pendingScripts = []; | |
var firstScript = document.scripts[0]; | |
scripts.push("https://assets.guim.co.uk/polyfill.io/v2/polyfill.min.js?rum\x3d0\x26features\x3des6,es7,default-3.6\x26flags\x3dgated\x26callback\x3dguardianPolyfilled"); | |
scripts.push("https://assets.guim.co.uk/javascripts/4a011b07ca43dff1eb56/graun.standard.js"); | |
function stateChange() { | |
var pendingScript; | |
while (pendingScripts[0] && pendingScripts[0].readyState == "loaded") { | |
pendingScript = pendingScripts.shift(); | |
pendingScript.onreadystatechange = null; | |
firstScript.parentNode.insertBefore(pendingScript, firstScript) | |
} | |
} | |
while (src = scripts.shift()) | |
if ("async" in firstScript) { | |
script = document.createElement("script"); | |
script.async = false; | |
script.src = src; | |
document.head.appendChild(script) | |
} else if (firstScript.readyState) { | |
script = document.createElement("script"); | |
pendingScripts.push(script); | |
script.onreadystatechange = stateChange; | |
script.src = src | |
} else document.write('\x3cscript src\x3d"' + src + '" defer\x3e\x3c/' + "script\x3e") | |
})(document, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment