(function($) { jQuery.cookieBar = function(options, val) { if (options == 'cookies') { var doReturn = 'cookies'; } else if (options == 'set') { var doReturn = 'set'; } else { var doReturn = false; } var defaults = { message: 'We use cookies to track usage and preferences.', //Message displayed on bar acceptButton: true, //Set to true to show accept/enable button acceptText: 'I Understand', //Text on accept/enable button declineButton: false, //Set to true to show decline/disable button declineText: 'Disable Cookies', //Text on decline/disable button policyButton: false, //Set to true to show Privacy Policy button policyText: 'Privacy Policy', //Text on Privacy Policy button policyURL: '/privacy-policy/', //URL of Privacy Policy autoEnable: true, //Set to true for cookies to be accepted automatically. Banner still shows acceptOnContinue: false, //Set to true to silently accept cookies when visitor moves to another page expireDays: 365, //Number of days for cookieBar cookie to be stored for forceShow: false, //Force cookieBar to show regardless of user cookie preference effect: 'slide', //Options: slide, fade, hide element: 'body', //Element to append/prepend cookieBar to. Remember "." for class or "#" for id. append: false, //Set to true for cookieBar HTML to be placed at base of website. Actual position may change according to CSS fixed: false, //Set to true to add the class "fixed" to the cookie bar. Default CSS should fix the position bottom: false, //Force CSS when fixed, so bar appears at bottom of website zindex: '', //Can be set in CSS, although some may prefer to set here redirect: String(window.location.href), //Current location domain: String(window.location.hostname), //Location of privacy policy referrer: String(document.referrer) //Where visitor has come from }; var options = jQuery.extend(defaults, options); //Sets expiration date for cookie var expireDate = new Date(); expireDate.setTime(expireDate.getTime() + (options.expireDays * 24 * 60 * 60 * 1000)); expireDate = expireDate.toGMTString(); var cookieEntry = 'cb-enabled={value}; expires=' + expireDate + '; path=/'; //Retrieves current cookie preference var i, cookieValue = '', aCookie, aCookies = document.cookie.split('; '); for (i = 0; i < aCookies.length; i++) { aCookie = aCookies[i].split('='); if (aCookie[0] == 'cb-enabled') { cookieValue = aCookie[1]; } } //Sets up default cookie preference if not already set if (cookieValue == '' && doReturn != 'cookies' && options.autoEnable) { cookieValue = 'enabled'; document.cookie = cookieEntry.replace('{value}', 'enabled'); } if (options.acceptOnContinue) { if (options.referrer.indexOf(options.domain) >= 0 && String(window.location.href).indexOf(options.policyURL) == -1 && doReturn != 'cookies' && doReturn != 'set' && cookieValue != 'accepted' && cookieValue != 'declined') { doReturn = 'set'; val = 'accepted'; } } if (doReturn == 'cookies') { //Returns true if cookies are enabled, false otherwise if (cookieValue == 'enabled' || cookieValue == 'accepted') { return true; } else { return false; } } else if (doReturn == 'set' && (val == 'accepted' || val == 'declined')) { //Sets value of cookie to 'accepted' or 'declined' document.cookie = cookieEntry.replace('{value}', val); if (val == 'accepted') { return true; } else { return false; } } else { //Sets up enable/accept button if required var message = options.message.replace('{policy_url}', options.policyURL); if (options.acceptButton) { var acceptButton = '' + options.acceptText + ''; } else { var acceptButton = ''; } //Sets up disable/decline button if required if (options.declineButton) { var declineButton = '' + options.declineText + ''; } else { var declineButton = ''; } //Sets up privacy policy button if required if (options.policyButton) { var policyButton = '' + options.policyText + ''; } else { var policyButton = ''; } //Whether to add "fixed" class to cookie bar if (options.fixed) { if (options.bottom) { var fixed = ' class="fixed bottom"'; } else { var fixed = ' class="fixed"'; } } else { var fixed = ''; } if (options.zindex != '') { var zindex = ' style="z-index:' + options.zindex + ';"'; } else { var zindex = ''; } //Displays the cookie bar if arguments met if (options.forceShow || cookieValue == 'enabled' || cookieValue == '') { if (options.append) { $(options.element).append(''); } else { $(options.element).prepend(''); } // Silverback $('head').append('\ \ '); } //Sets the cookie preference to accepted if enable/accept button pressed $('#cookie-bar .cb-enable').click(function(event) { event.preventDefault(); document.cookie = cookieEntry.replace('{value}', 'accepted'); if (cookieValue != 'enabled' && cookieValue != 'accepted') { //window.location = options.redirect; window.location.assign(options.redirect); //console.log(options.redirect); } else { if (options.effect == 'slide') { $('#cookie-bar').slideUp(300, function() { $('#cookie-bar').remove(); }); } else if (options.effect == 'fade') { $('#cookie-bar').fadeOut(300, function() { $('#cookie-bar').remove(); }); } else { $('#cookie-bar').hide(0, function() { $('#cookie-bar').remove(); }); } return false; } }); //Sets the cookie preference to declined if disable/decline button pressed $('#cookie-bar .cb-disable').click(function(event) { event.preventDefault(); var deleteDate = new Date(); deleteDate.setTime(deleteDate.getTime() - (864000000)); deleteDate = deleteDate.toGMTString(); aCookies = document.cookie.split('; '); for (i = 0; i < aCookies.length; i++) { aCookie = aCookies[i].split('='); if (aCookie[0].indexOf('_') >= 0) { document.cookie = aCookie[0] + '=0; expires=' + deleteDate + '; domain=' + options.domain.replace('www', '') + '; path=/'; } else { document.cookie = aCookie[0] + '=0; expires=' + deleteDate + '; path=/'; } } document.cookie = cookieEntry.replace('{value}', 'declined'); if (cookieValue == 'enabled' && cookieValue != 'accepted') { window.location = options.redirect; } else { if (options.effect == 'slide') { $('#cookie-bar').slideUp(300, function() { $('#cookie-bar').remove(); }); } else if (options.effect == 'fade') { $('#cookie-bar').fadeOut(300, function() { $('#cookie-bar').remove(); }); } else { $('#cookie-bar').hide(0, function() { $('#cookie-bar').remove(); }); } return false; } }); } }; })(jQuery); jQuery(document).ready(function() { //$('body').css('overflow','hidden'); cookieBarOptions = { acceptButton: true, declineButton: false, policyButton: true, autoEnable: false, acceptOnContinue: false, expireDays: 365, forceShow: false, effect: 'slide', element: 'body', append: false, fixed: true, bottom: true, zindex: '9999', redirect: window.location.href, } cookieBarOptionsde = { message: 'Diese Website verwendet harmlose Cookies, um den Besuchern die bestmögliche Nutzererfahrung zu bereiten. Diese Cookies erfassen Präferenzen und Navigationsverhalten der Besucher.', acceptText: 'Cookies Annehmen', declineText: 'Cookies ablehnen', policyText: 'Was sind Cookies?', policyURL: 'http://de.wikipedia.org/wiki/Cookie' } cookieBarOptionsit = { message: 'Questo sito utilizza cookies per offrire agli utenti la miglior navigazione del sito possibile. I cookies rilevano preferenze e navigazione dei visitatori.', acceptText: 'Accettare cookies', declineText: 'Rifiutare cookies', policyText: 'Cosa sono i cookies?', policyURL: 'http://it.wikipedia.org/wiki/Cookie' } cookieBarOptionsen = { message: 'This Website uses cookies to provide visitors with the best possible experience and service. Cookies detect preferences and navigation behavior of visitors.', acceptText: 'Accept cookies', declineText: 'Decline cookies', policyText: 'What are cookies?', policyURL: 'http://en.wikipedia.org/wiki/HTTP_cookie' } cookieBarOptionsfr = { message: 'Ce site utilise des cookies pour offrir aux visiteurs la meilleure expérience et service possible. Cookies détectent les préférences et les comportements de navigation des visiteurs', acceptText: 'Accepter les cookies', declineText: 'Refuser les cookies', policyText: 'Que sont les cookies?', policyURL: 'http://fr.wikipedia.org/wiki/Cookie_(informatique)' } cookieBarOptionses = { message: 'Este sitio web utiliza cookies para ofrecer a los visitantes la mejor experiencia y el mejor servicio posible. Los cookies detectan las preferencias y el comportamiento de navegación de los visitantes.', acceptText: 'Aceptar cookies', declineText: 'Rechazar las cookies', policyText: '¿Qué son las cookies?', policyURL: 'http://es.wikipedia.org/wiki/Cookie_(inform%C3%A1tica)' } cookieBarOptionspt = { message: 'Este site usa cookies para oferecer aos visitantes a melhor experiência eo melhor serviço possível. Os cookies detectar preferências e comportamento de navegação dos visitantes.', acceptText: 'Aceitar cookies', declineText: 'Recusar cookies', policyText: 'O que são cookies?', policyURL: 'http://pt.wikipedia.org/wiki/Cookie_HTTP' } cookieBarOptionsru = { message: 'Этот сайт использует куки, чтобы обеспечить посетителей с наилучшим опытом и обслуживания. Печенье обнаружить предпочтения и навигации поведение посетителей.', acceptText: 'Принять печенье', declineText: 'Снижение печенье', policyText: 'Какие печенье?', policyURL: 'http://ru.wikipedia.org/wiki/HTTP_cookie' } cookieBarOptionsja = { message: 'このウェブサイトは、可能な限り最高の経験やサービスに訪問者を提供するためにクッキーを使用しています。クッキーは、好みや観光客のナビゲーション動作を検出します。', acceptText: 'クッキーを受け入れます', declineText: 'Cookieを拒否。', policyText: 'クッキーとは何ですか?', policyURL: 'http://ru.wikipedia.org/wiki/HTTP_cookie' } cookieBarOptionsLoc = eval('cookieBarOptions' + jQuery('html').attr('lang').toLowerCase()); cookieBarOptionsFinal = jQuery.extend(cookieBarOptions, cookieBarOptionsLoc); console.log(cookieBarOptionsFinal); jQuery.cookieBar(cookieBarOptionsFinal); });