Subversion Repositories Sites.tela-botanica.org

Rev

Rev 1125 | Blame | Compare with Previous | Last modification | View Log | RSS feed

function ajouterStyle() {
  var urlCss = "http://resources.tela-botanica.org/tb/reseau/bandeau_cnil.css";
  // http://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript
  link = document.createElement("link");
  link.href = urlCss;
  link.type = "text/css";
  link.rel = "stylesheet";
  link.media = "screen,print";
  document.getElementsByTagName( "head" )[0].appendChild(link);
}

function ajouterBandeau() {
  var divCookie = 
    '<div class="bandeau" id="bandeau_cookie_cnil">'+
        '<div class="bandeau_cookie_cnil_titre"> Utilisation des cookies </div>'+
        '<hr />'+
                '<div class="avertissement_cookie">  '+
                'Le site de Tela Botanica utilise des cookies. En poursuivant votre navigation sur le site, vous acceptez l\'utilisation de ces cookies qui permettent notamment de se souvenir de vos pr&eacute;f&eacute;rences. <br />'+
                '<a class="en_savoir_plus" target="_blank" href="http://www.tela-botanica.org/page:licence"> En savoir plus</a>'+
                '<a class="button" id="accepterCookie" onclick="javascript:accepterCookie()" href="#" > OK </a>'+
                '</div>'+
    '</div>';
  var nDiv = document.createElement('div');
  nDiv.innerHTML = divCookie;
  document.getElementsByTagName("body")[0].appendChild(nDiv);
}

function accepterCookie() {
  var element = document.getElementById("bandeau_cookie_cnil");
  element.parentNode.removeChild(element);
  createCookie("cnil", 1, 365);
  return false;
}

function initialiserBandeauCnil() {
    ajouterStyle();
    ajouterBandeau();
}

/**
 * Fonctions tirées de stackoverflow
 */
// http://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie
function createCookie(name, value, days) {
  var expires;
  if (days) {
      var date = new Date();
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
      expires = "; expires=" + date.toGMTString();
  }
  else {
      expires = "";
  }
  document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
                c_start = document.cookie.indexOf(c_name + "=");
                if (c_start != -1) {
                    c_start = c_start + c_name.length + 1;
                    c_end = document.cookie.indexOf(";", c_start);
                    if (c_end == -1) {
                        c_end = document.cookie.length;
                    }
                    return unescape(document.cookie.substring(c_start, c_end));
                }
    }
    return "";
}

function contentLoaded(win, fn) {

        var done = false, top = true,

        doc = win.document,
        root = doc.documentElement,
        modern = doc.addEventListener,

        add = modern ? 'addEventListener' : 'attachEvent',
        rem = modern ? 'removeEventListener' : 'detachEvent',
        pre = modern ? '' : 'on',

        init = function(e) {
                if (e.type == 'readystatechange' && doc.readyState != 'complete') return;
                (e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
                if (!done && (done = true)) fn.call(win, e.type || e);
        },

        poll = function() {
                try { root.doScroll('left'); } catch(e) { setTimeout(poll, 50); return; }
                init('poll');
        };

        if (doc.readyState == 'complete') fn.call(win, 'lazy');
        else {
                if (!modern && root.doScroll) {
                        try { top = !win.frameElement; } catch(e) { }
                        if (top) poll();
                }
                doc[add](pre + 'DOMContentLoaded', init, false);
                doc[add](pre + 'readystatechange', init, false);
                win[add](pre + 'load', init, false);
        }

}


/**
 * Initialisation
 */
var tIdBandeau = setInterval(function() {
        if (document.readyState == "complete") {
            clearInterval(tIdBandeau);    
            var cookieCnil = getCookie("cnil");
                if(cookieCnil == null || cookieCnil != 1) {
                        initialiserBandeauCnil();
                } 
        }
}, 200);