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(function(window) { 18 19 if (!!window.cookieChoices) { 20 return window.cookieChoices; 21 } 22 23 var document = window.document; 24 // IE8 does not support textContent, so we should fallback to innerText. 25 var supportsTextContent = 'textContent' in document.body; 26 27 var cookieChoices = (function() { 28 29 var cookieName = 'displayCookieConsent'; 30 var cookieConsentId = 'cookieChoiceInfo'; 31 var dismissLinkId = 'cookieChoiceDismiss'; 32 33 function _createHeaderElement(cookieText, dismissText, linkText, linkHref) { 34 var butterBarStyles = 'position:fixed; width:100%; margin:0; left:0; z-index:10001;'; // modificato 35 36 var cookieConsentElement = document.createElement('div'); 37 cookieConsentElement.id = cookieConsentId; 38 cookieConsentElement.style.cssText = butterBarStyles; 39 cookieConsentElement.appendChild(_createConsentText(cookieText)); 40 41 if (!!linkText && !!linkHref) { 42 cookieConsentElement.appendChild(_createInformationLink(linkText, linkHref)); 43 } 44 cookieConsentElement.appendChild(_createDismissLink(dismissText)); 45 return cookieConsentElement; 46 } 47 48 function _createDialogElement(cookieText, dismissText, linkText, linkHref) { 49 var glassStyle = 'position:fixed;width:100%;height:100%;z-index:999;' + 50 'top:0;left:0;opacity:0.5;filter:alpha(opacity=50);' + 51 'background-color:#ccc;'; 52 var dialogStyle = 'z-index:1000;position:fixed;left:50%;top:50%'; 53 var contentStyle = 'position:relative;left:-50%;margin-top:-25%;' + 54 'background-color:#fff;padding:20px;box-shadow:4px 4px 25px #888;'; 55 56 var cookieConsentElement = document.createElement('div'); 57 cookieConsentElement.id = cookieConsentId; 58 59 var glassPanel = document.createElement('div'); 60 glassPanel.style.cssText = glassStyle; 61 62 var content = document.createElement('div'); 63 content.style.cssText = contentStyle; 64 65 var dialog = document.createElement('div'); 66 dialog.style.cssText = dialogStyle; 67 68 var dismissLink = _createDismissLink(dismissText);
69 dismissLink.style.display = 'block'; 70 dismissLink.style.textAlign = 'right'; 71 dismissLink.style.marginTop = '8px'; 72 73 content.appendChild(_createConsentText(cookieText)); 74 if (!!linkText && !!linkHref) { 75 content.appendChild(_createInformationLink(linkText, linkHref)); 76 } 77 content.appendChild(dismissLink); 78 dialog.appendChild(content); 79 cookieConsentElement.appendChild(glassPanel); 80 cookieConsentElement.appendChild(dialog); 81 return cookieConsentElement; 82 } 83 84 function _setElementText(element, text) { 85 if (supportsTextContent) { 86 element.textContent = text; 87 } else { 88 element.innerText = text; 89 } 90 } 91 92 function _createConsentText(cookieText) { 93 var consentText = document.createElement('span'); 94 _setElementText(consentText, cookieText); 95 return consentText; 96 } 97 98 function _createDismissLink(dismissText) { 99 var dismissLink = document.createElement('a'); 100 _setElementText(dismissLink, dismissText);
101 dismissLink.id = dismissLinkId; 102 dismissLink.href = '#'; 103 // dismissLink.style.marginLeft = '24px'; 104 return dismissLink; 105 } 106 107 function _createInformationLink(linkText, linkHref) { 108 var infoLink = document.createElement('a'); 109 _setElementText(infoLink, linkText); 110 infoLink.id = 'more-info'; // aggiunto id 111 infoLink.href = linkHref; 112 infoLink.target = '_blank'; 113 // infoLink.style.marginLeft = '8px'; 114 return infoLink; 115 } 116 117 function _dismissLinkClick() { 118 _saveUserPreference(); 119 _removeCookieConsent(); 120 return false; 121 } 122 123 function _showCookieConsent(cookieText, dismissText, linkText, linkHref, isDialog) { 124 if (_shouldDisplayConsent()) { 125 _removeCookieConsent(); 126 var consentElement = (isDialog) ? 127 _createDialogElement(cookieText, dismissText, linkText, linkHref) : 128 _createHeaderElement(cookieText, dismissText, linkText, linkHref); 129 var fragment = document.createDocumentFragment(); 130 fragment.appendChild(consentElement); 131 document.body.appendChild(fragment.cloneNode(true)); 132 document.getElementById(dismissLinkId).onclick = _dismissLinkClick; 133 } 134 } 135 136 function showCookieConsentBar(cookieText, dismissText, linkText, linkHref) { 137 _showCookieConsent(cookieText, dismissText, linkText, linkHref, false); 138 } 139 140 function showCookieConsentDialog(cookieText, dismissText, linkText, linkHref) { 141 _showCookieConsent(cookieText, dismissText, linkText, linkHref, true); 142 } 143 144 function _removeCookieConsent() { 145 var cookieChoiceElement = document.getElementById(cookieConsentId); 146 if (cookieChoiceElement != null) { 147 cookieChoiceElement.parentNode.removeChild(cookieChoiceElement); 148 } 149 } 150 151 function _saveUserPreference() { 152 // Set the cookie expiry to one year after today. 153 // var expiryDate = new Date(); 154 // expiryDate.setFullYear(expiryDate.getFullYear() + 1); 155 // document.cookie = cookieName + '=y; expires=' + expiryDate.toGMTString(); 156 157 // Durata del cookie 158 var d = new Date(); 159 var expiryDate = new Date(d.getTime() + 86400000 * 30); // cookie impostato a 30 giorni 160 document.cookie = cookieName + '=y; expires=' + expiryDate; 161 } 162 163 function _shouldDisplayConsent() { 164 // Display the header only if the cookie has not been set. 165 return !document.cookie.match(new RegExp(cookieName + '=([^;]+)')); 166 } 167 168 var exports = {}; 169 exports.showCookieConsentBar = showCookieConsentBar; 170 exports.showCookieConsentDialog = showCookieConsentDialog; 171 return exports; 172 })(); 173 174 window.cookieChoices = cookieChoices; 175 return cookieChoices; 176})(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.