Autore Topic: Personalizzazione informativa COOKIE  (Letto 1774 volte)

ziobello1976

  • Utente inesperto
  • **
  • Post: 154
Personalizzazione informativa COOKIE
« il: 15 Luglio, 2015, 17:03:55 »
Ciao vorrei fare una piccola modifica a questo codice (non di mia produzione, nn saprei nemmeno da dove iniziare)
Vorrei che cliccando sul link INFO, si apra una nuova finestra pop-up delle dimensioni di 650x450
Sapete dirmi come procedere?
Grazie
Fabio



FILE SCRIPT ALLEGATO:

/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

(function(window) {

  if (!!window.cookieChoices) {
    return window.cookieChoices;
  }

  var document = window.document;
  // IE8 does not support textContent, so we should fallback to innerText.
  var supportsTextContent = 'textContent' in document.body;

  var cookieChoices = (function() {

    var cookieName = 'displayCookieConsent';
    var cookieConsentId = 'cookieChoiceInfo';
    var dismissLinkId = 'cookieChoiceDismiss';

    function _createHeaderElement(cookieText, dismissText, linkText, linkHref) {
      var butterBarStyles = 'position:fixed; width:100%; margin:0; left:0; z-index:10001;'; // modificato

      var cookieConsentElement = document.createElement('div');
      cookieConsentElement.id = cookieConsentId;
      cookieConsentElement.style.cssText = butterBarStyles;
      cookieConsentElement.appendChild(_createConsentText(cookieText));

      if (!!linkText && !!linkHref) {
        cookieConsentElement.appendChild(_createInformationLink(linkText, linkHref));
      }
      cookieConsentElement.appendChild(_createDismissLink(dismissText));
      return cookieConsentElement;
    }

    function _createDialogElement(cookieText, dismissText, linkText, linkHref) {
      var glassStyle = 'position:fixed;width:100%;height:100%;z-index:999;' 
          'top:0;left:0;opacity:0.5;filter:alpha(opacity=50);' 
          'background-color:#ccc;';
      var dialogStyle = 'z-index:1000;position:fixed;left:50%;top:50%';
      var contentStyle = 'position:relative;left:-50%;margin-top:-25%;' 
          'background-color:#fff;padding:20px;box-shadow:4px 4px 25px #888;';

      var cookieConsentElement = document.createElement('div');
      cookieConsentElement.id = cookieConsentId;

      var glassPanel = document.createElement('div');
      glassPanel.style.cssText = glassStyle;

      var content = document.createElement('div');
      content.style.cssText = contentStyle;

      var dialog = document.createElement('div');
      dialog.style.cssText = dialogStyle;

      var dismissLink = _createDismissLink(dismissText);
      dismissLink.style.display = 'block';
      dismissLink.style.textAlign = 'right';
      dismissLink.style.marginTop = '8px';

      content.appendChild(_createConsentText(cookieText));
      if (!!linkText && !!linkHref) {
        content.appendChild(_createInformationLink(linkText, linkHref));
      }
      content.appendChild(dismissLink);
      dialog.appendChild(content);
      cookieConsentElement.appendChild(glassPanel);
      cookieConsentElement.appendChild(dialog);
      return cookieConsentElement;
    }

    function _setElementText(element, text) {
      if (supportsTextContent) {
        element.textContent = text;
      } else {
        element.innerText = text;
      }
    }

    function _createConsentText(cookieText) {
      var consentText = document.createElement('span');
      _setElementText(consentText, cookieText);
      return consentText;
    }

    function _createDismissLink(dismissText) {
      var dismissLink = document.createElement('a');
      _setElementText(dismissLink, dismissText);
      dismissLink.id = dismissLinkId;
      dismissLink.href = '#';
      // dismissLink.style.marginLeft = '24px';
      return dismissLink;
    }

    function _createInformationLink(linkText, linkHref) {
      var infoLink = document.createElement('a');
      _setElementText(infoLink, linkText);
     infoLink.id = 'more-info'; // aggiunto id
      infoLink.href = linkHref;
      infoLink.target = '_blank';
      // infoLink.style.marginLeft = '8px';
      return infoLink;
    }

    function _dismissLinkClick() {
      _saveUserPreference();
      _removeCookieConsent();
      return false;
    }

    function _showCookieConsent(cookieText, dismissText, linkText, linkHref, isDialog) {
      if (_shouldDisplayConsent()) {
        _removeCookieConsent();
        var consentElement = (isDialog) ?
            _createDialogElement(cookieText, dismissText, linkText, linkHref) :
            _createHeaderElement(cookieText, dismissText, linkText, linkHref);
        var fragment = document.createDocumentFragment();
        fragment.appendChild(consentElement);
        document.body.appendChild(fragment.cloneNode(true));
        document.getElementById(dismissLinkId).onclick = _dismissLinkClick;
      }
    }

    function showCookieConsentBar(cookieText, dismissText, linkText, linkHref) {
      _showCookieConsent(cookieText, dismissText, linkText, linkHref, false);
    }

    function showCookieConsentDialog(cookieText, dismissText, linkText, linkHref) {
      _showCookieConsent(cookieText, dismissText, linkText, linkHref, true);
    }

    function _removeCookieConsent() {
      var cookieChoiceElement = document.getElementById(cookieConsentId);
      if (cookieChoiceElement != null) {
        cookieChoiceElement.parentNode.removeChild(cookieChoiceElement);
      }
    }

    function _saveUserPreference() {
      // Set the cookie expiry to one year after today.
      // var expiryDate = new Date();
      // expiryDate.setFullYear(expiryDate.getFullYear()   1);
      // document.cookie = cookieName   '=y; expires='   expiryDate.toGMTString();
     
     // Durata del cookie
      var d = new Date();
      var expiryDate = new Date(d.getTime()   86400000 * 30); // cookie impostato a 30 giorni
      document.cookie = cookieName   '=y; expires='   expiryDate;
    }

    function _shouldDisplayConsent() {
      // Display the header only if the cookie has not been set.
      return !document.cookie.match(new RegExp(cookieName   '=([^;] )'));
    }

    var exports = {};
    exports.showCookieConsentBar = showCookieConsentBar;
    exports.showCookieConsentDialog = showCookieConsentDialog;
    return exports;
  })();

  window.cookieChoices = cookieChoices;
  return cookieChoices;
})(this);




Prima della chiusura del tag BODY:

<script src="files/cookiechoices.js"></script>
<script>
$(function () {
    cookieChoices.showCookieConsentBar('Questo sito fa uso di cookies. Continuando la navigazione se ne autorizza l\'uso.', 'OK', 'Info', 'cookie.html');
});
</script>



Prima della chiusura del tag BODY:

<style>
/* div barra */
#cookieChoiceInfo{
    color:white;
    font-family:Sintony, Geneva, sans-serif;
    font-size:11px;
    line-height:14px;
    background-color: rgb(77, 77, 77); /* per IE7/8 */
    background-color: rgba(77, 77, 77, 0.9);
    top:0; /* bottom:0; per avere la barra in basso */   
    text-align:center;
    padding:20px 0 20px 0;
}
/* links */
    #cookieChoiceInfo a{
    text-decoration:none;
    padding:4px;
    background-color:white;
    font-size:10px;
    border-radius:6px;
    color:#585858;
}
/* link pagina informativa */
    a#more-info{
    margin-left:12px;
}
/* link accettazione */
    a#cookieChoiceDismiss{
    margin-left:24px;
    padding:4px 11px;
}
</style>

lemonsong

  • Anziani
  • Utente storico
  • *
  • Post: 1867
    • lemonsong's world
Re:Personalizzazione informativa COOKIE
« Risposta #1 il: 15 Luglio, 2015, 17:28:49 »
C'è già un topic dove si parla di questo script e relative modifiche (non quelle che chiedi tu).
Non capisco perché aprire un nuovo topic con una valanga di codice inutile.