1(function() { 2 'use strict'; 3 var DOM_ID = 'DIGITAL_CLIMATE_STRIKE'; 4 var CLOSED_COOKIE = '_DIGITAL_CLIMATE_STRIKE_WIDGET_CLOSED_'; 5 var NOW = new Date().getTime(); 6 var MS_PER_DAY = 86400000; 7 8 // user-configurable options 9 var options = window.DIGITAL_CLIMATE_STRIKE_OPTIONS || {}; 10 var iframeHost = options.iframeHost !== undefined ? options.iframeHost : 'https://assets.digitalclimatestrike.net'; 11 var websiteName = options.websiteName || null; 12 var footerDisplayStartDate = options.footerDisplayStartDate || new Date(2019, 7, 1); // August 1st, 2019 - arbitrary date in the past 13 var fullPageDisplayStartDate = options.fullPageDisplayStartDate || new Date(2019, 8, 20); // September 20th, 2019 14 var forceFullPageWidget = !!options.forceFullPageWidget; 15 var cookieExpirationDays = parseFloat(options.cookieExpirationDays || 1); 16 var alwaysShowWidget = !!(options.alwaysShowWidget || window.location.hash.indexOf('ALWAYS_SHOW_DIGITAL_CLIMATE_STRIKE') !== -1); 17 var disableGoogleAnalytics = !!options.disableGoogleAnalytics; 18 var showCloseButtonOnFullPageWidget = !!options.showCloseButtonOnFullPageWidget; 19 var language = getLanguage(); 20 21 function getIframeSrc() { 22 var src = iframeHost; 23 src += language === 'en' ? '/index.html?' : '/index-' + language + '.html?'; 24 25 var urlParams = [ 26 ['hostname', window.location.host], 27 ['fullPageDisplayStartDate', fullPageDisplayStartDate.toISOString()], 28 ['language', language] 29 ]; 30 31 forceFullPageWidget && urlParams.push(['forceFullPageWidget', 'true']); 32 showCloseButtonOnFullPageWidget && urlParams.push(['showCloseButtonOnFullPageWidget', 'true']); 33 disableGoogleAnalytics && urlParams.push(['googleAnalytics', 'false']); 34 websiteName && urlParams.push(['websiteName', encodeURI(websiteName)]); 35 36 var params = urlParams.map(function(el) { 37 return el.join('='); 38 }); 39 40 return src + params.join('&'); 41 } 42 43 function createIframe() { 44 var wrapper = document.createElement('div'); 45 wrapper.id = DOM_ID; 46 var iframe = document.createElement('iframe'); 47 iframe.src = getIframeSrc(); 48 iframe.frameBorder = 0; 49 iframe.allowTransparency = true; 50 wrapper.appendChild(iframe); 51 document.body.appendChild(wrapper); 52 return wrapper; 53 } 54 55 function getLanguage() { 56 var language = 'en'; 57 58 // Spanish is specified or no language is set and browser is set to spanish 59 if (options.language === 'es' || (!options.language && navigator && navigator.language.match(/^es/))) { 60 language = 'es'; 61 } 62 63 // German is specified or no language is set and browser is set to German 64 if (options.language === 'de' || (!options.language && navigator && navigator.language.match(/^de/))) { 65 language = 'de'; 66 } 67 68 // Czech is specified or no language is set and browser is set to German 69 if (options.language === 'cs' || (!options.language && navigator && navigator.language.match(/^cs/))) { 70 language = 'cs'; 71 } 72 73 // French is specified or no language is set and browser is set to French 74 if (options.language === 'fr' || (!options.language && navigator && navigator.language.match(/^fr/))) { 75 language = 'fr'; 76 } 77 78 // Dutch is specified or no language is set and browser is set to Dutch 79 if (options.language === 'nl' || (!options.language && navigator && navigator.language.match(/^nl/))) { 80 language = 'nl'; 81 } 82 83 // Turkish is specified or no language is set and browser is set to Turkish 84 if (options.language === 'tr' || (!options.language && navigator && navigator.language.match(/^tr/))) { 85 language = 'tr'; 86 } 87 88 // Portuguese is specified or no language is set and browser is set to Portuguese 89 if (options.language === 'pt' || (!options.language && navigator && navigator.language.match(/^pt/))) { 90 language = 'pt'; 91 } 92 93 return language; 94 } 95 96 function maximize() { 97 document.getElementById(DOM_ID).style.width = '100%'; 98 document.getElementById(DOM_ID).style.height = '100%'; 99 } 100 101 function closeWindow() { 102 document.getElementById(DOM_ID).remove(); 103 window.removeEventListener('message', receiveMessage);
104 setCookie(CLOSED_COOKIE, 'true', cookieExpirationDays); 105 } 106 107 function navigateToLink(linkUrl) { 108 document.location = linkUrl; 109 } 110 111 function injectCSS(id, css) { 112 var style = document.createElement('style'); 113 style.type = 'text/css'; 114 style.id = id; 115 if (style.styleSheet) { 116 style.styleSheet.cssText = css; 117 } 118 else { 119 style.appendChild(document.createTextNode(css)); 120 } 121 document.head.appendChild(style); 122 } 123 124 function setCookie(name, value, expirationDays) { 125 var d = new Date(); 126 d.setTime(d.getTime()+(expirationDays * MS_PER_DAY)); 127 128 var expires = 'expires='+d.toGMTString(); 129 document.cookie = name + '=' + value + '; ' + expires + '; path=/'; 130 } 131 132 function getCookie(cookieName) { 133 var name = cookieName + '='; 134 var ca = document.cookie.split(';'); 135 var c; 136 137 for(var i = 0; i < ca.length; i++) { 138 c = ca[i].trim(); 139 if (c.indexOf(name) == 0) { 140 return c.substring(name.length, c.length); 141 } 142 } 143 144 return ''; 145 } 146 147 function receiveMessage(event) { 148 if (!event.data.DIGITAL_CLIMATE_STRIKE) return; 149 if (event.origin.lastIndexOf(iframeHost, 0) !== 0) return; 150 151 switch (event.data.action) { 152 case 'maximize': 153 return maximize(); 154 case 'closeButtonClicked': 155 return closeWindow(); 156 case 'buttonClicked': 157 if (event.data.linkUrl.lastIndexOf('http', 0) !== 0) return; 158 return navigateToLink(event.data.linkUrl); 159 } 160 } 161 162 /** 163 * There are a few circumstances when the iFrame should not be shown: 164 * 1. When the CLOSED_COOKIE has been set on that device 165 * 2. We haven't reached either display start date 166 * 3. We're past the date to display the full screen widget. 167 * 4. We haven't set alwaysShowWidget to be true in the config. 168 */ 169 function iFrameShouldNotBeShown() { 170 return (footerDisplayStartDate.getTime() > NOW && fullPageDisplayStartDate.getTime() > NOW) 171 || new Date(fullPageDisplayStartDate.getTime() + MS_PER_DAY) < NOW 172 || !!getCookie(CLOSED_COOKIE) 173 && !alwaysShowWidget; 174 } 175 176 function initializeInterface() { 177 if (iFrameShouldNotBeShown()) { 178 return; 179 } 180 181 createIframe(); 182 183 var iFrameHeight = getIframeHeight(); 184 185 injectCSS('DIGITAL_STRIKE_CSS', 186 '#' + DOM_ID + ' { position: fixed; right: 0; left: 0; bottom: 0px; width: 100%; height: ' + iFrameHeight + '; z-index: 20000; -webkit-overflow-scrolling: touch; overflow: hidden; } ' + 187 '#' + DOM_ID + ' iframe { width: 100%; height: 100%; }' 188 ); 189 190 // listen for messages from iframe 191 window.addEventListener('message', receiveMessage); 192 193 document.removeEventListener('DOMContentLoaded', initializeInterface); 194 } 195 196 function getIframeHeight() { 197 198 var isProbablyMobile = window.innerWidth < 600; 199 200 if (isProbablyMobile) { 201 return '200px'; 202 } else { 203 return '145px'; 204 } 205 } 206 207 // Wait for DOM content to load. 208 switch(document.readyState) { 209 case 'complete': 210 case 'loaded': 211 case 'interactive': 212 initializeInterface(); 213 break; 214 default: 215 document.addEventListener('DOMContentLoaded', initializeInterface); 216 } 217})();
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.