1/* 2 Copyright 2014 Google Inc. All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17/* 18 * For more information on this file, see http://www.cookiechoices.org/ 19 */ 20 21(function(window) { 22 23 if (!!window.cookieChoices) { 24 return window.cookieChoices; 25 } 26 27 var document = window.document; 28 // IE8 does not support textContent, so we should fallback to innerText. 29 var supportsTextContent = 'textContent' in document.body; 30 31 var cookieChoices = (function() { 32 33 var cookieName = 'displayCookieConsent'; 34 var cookieConsentId = 'cookieChoiceInfo'; 35 var divClass = 'cookie-choices-info'; 36 var innerDivClass = 'cookie-choices-inner'; 37 var textSpan = 'cookie-choices-text'; 38 var buttonsClass = 'cookie-choices-buttons'; 39 var buttonClass = 'cookie-choices-button'; 40 var singletonClass = 'singleton-element'; 41 var dismissLinkId = 'cookieChoiceDismiss'; 42 43 function _createHeaderElement(cookieText, dismissText, linkText, linkHref) { 44 var cookieInnerElement = document.createElement('div'); 45 cookieInnerElement.className = innerDivClass; 46 cookieInnerElement.appendChild(_createConsentText(cookieText)); 47 48 var buttonsElement = document.createElement('span'); 49 buttonsElement.className = buttonsClass; 50 cookieInnerElement.appendChild(buttonsElement); 51 52 if (!!linkText && !!linkHref) { 53 buttonsElement.appendChild(_createInformationLink(linkText, linkHref)); 54 } 55 56 buttonsElement.appendChild(_createDismissLink(dismissText)); 57 58 var cookieConsentElement = document.createElement('div'); 59 cookieConsentElement.id = cookieConsentId; 60 cookieConsentElement.className = divClass + ' ' + singletonClass; 61 cookieConsentElement.appendChild(cookieInnerElement); 62 return cookieConsentElement; 63 } 64 65 function _createStyleElement() { 66 var style = document.createElement('style'); 67 style.className = singletonClass; 68 style.type = 'text/css'; 69 _setElementText(style, 70 '.' + divClass + ' { ' + 71 'position:fixed;width:100%;background-color:#666;margin:0;' + 72 'left:0;top:0;padding:0;z-index:4000;text-align:center;' + 73 'color:#fff;line-height:140%;padding:10px 0;' + 74 'font-family:roboto,Arial; } ' + 75 '.' + divClass + ' .' + innerDivClass + ' { ' + 76 'position:relative;width:initial;margin:0;left:0;top:0; } ' + 77 '.' + divClass + ' .' + textSpan + ' { ' + 78 'display:inline-block;vertical-align:middle;font-size:16px;' + 79 'margin:10px 20px;color:#ccc;max-width:800px;' + 80 'text-align:left; }' + 81 '.' + divClass + ' .' + buttonsClass + ' { ' + 82 'display:inline-block;vertical-align:middle;' + 83 'white-space:nowrap;margin:0 10px; } ' + 84 '.' + divClass + ' .' + buttonClass + ':hover { ' + 85 ' color: #fff; } ' + 86 '.' + divClass + ' .' + buttonClass + ' { ' + 87 'font-weight:bold;text-transform:UPPERCASE;' + 88 'white-space:nowrap;' + 89 'color:#eee;margin-left:8px;padding:0 6px; ' + 90 'text-decoration:none; }'); 91 document.getElementsByTagName('head')[0].appendChild(style); 92 } 93 94 function _setElementText(element, text) { 95 if (supportsTextContent) { 96 element.textContent = text; 97 } else { 98 element.innerText = text; 99 } 100 } 101 102 function _createConsentText(cookieText) { 103 var consentText = document.createElement('span'); 104 _setElementText(consentText, cookieText); 105 consentText.className = textSpan; 106 return consentText; 107 } 108 109 function _createDismissLink(dismissText) { 110 var dismissLink = document.createElement('a'); 111 _setElementText(dismissLink, dismissText);
112 dismissLink.id = dismissLinkId; 113 dismissLink.href = '#'; 114 dismissLink.className = buttonClass; 115 return dismissLink; 116 } 117 118 function _createInformationLink(linkText, linkHref) { 119 var infoLink = document.createElement('a'); 120 _setElementText(infoLink, linkText); 121 infoLink.href = linkHref; 122 infoLink.target = '_blank'; 123 infoLink.className = buttonClass; 124 return infoLink; 125 } 126 127 function _dismissLinkClick(e) { 128 _saveUserPreference(); 129 _removeCookieConsent(); 130 e.stopPropagation && e.stopPropagation(); 131 e.cancelBubble = true; 132 return false; 133 } 134 135 function _showCookieConsent(cookieText, dismissText, linkText, linkHref) { 136 if (_shouldDisplayConsent()) { 137 _removeCookieConsent(); 138 _createStyleElement(); 139 var consentElement = 140 _createHeaderElement(cookieText, dismissText, linkText, linkHref); 141 var fragment = document.createDocumentFragment(); 142 fragment.appendChild(consentElement); 143 document.body.appendChild(fragment.cloneNode(true)); 144 document.getElementById(dismissLinkId).onclick = _dismissLinkClick; 145 } 146 } 147 148 function _removeCookieConsent() { 149 var cookieChoiceElement = document.getElementById(cookieConsentId); 150 if (cookieChoiceElement != null) { 151 cookieChoiceElement.parentNode.removeChild(cookieChoiceElement); 152 } 153 } 154 155 function _saveUserPreference() { 156 // Set the cookie expiry to one year after today. 157 var expiryDate = new Date(); 158 expiryDate.setFullYear(expiryDate.getFullYear() + 1); 159 document.cookie = cookieName + '=y; expires=' + expiryDate.toGMTString(); 160 } 161 162 function _shouldDisplayConsent() { 163 // Display the header only if the cookie has not been set. 164 return !document.cookie.match(new RegExp(cookieName + '=([^;]+)')); 165 } 166 167 var exports = {}; 168 exports.showCookieConsentBar = _showCookieConsent; 169 return exports; 170 })(); 171 172 window.cookieChoices = cookieChoices; 173 return cookieChoices; 174})(this);
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.