--- regenerate: true --- {% capture cache %} {% comment %} # ----------------------------------------------------------------------------- # ~/assets/themes/j1/core/js/adapter/cookie_consent.js # Liquid template to create the Template Adapter for J1 CookieConsent # # Product/Info: # http://jekyll.one # # Copyright (C) 2019 Juergen Adams # # J1 CookieConsent is licensed under the MIT License. # For details, see https://jekyll.one # # ----------------------------------------------------------------------------- # Test data: # {{ liquid_var | debug }} # # ----------------------------------------------------------------------------- {% endcomment %} {% comment %} Load YML config data -------------------------------------------------------------------------------- {% endcomment %} {% assign cookie_consent_config = site.data.modules.j1_cookie_consent %} {% assign consent_defaults = cookie_consent_config.defaults %} {% assign consent_settings = cookie_consent_config.consent %} {% assign consent_config = consent_settings | merge: consent_defaults %} {% assign consent_modal_html_data = consent_config.modal_html_data_path %} /* # ----------------------------------------------------------------------------- # ~/assets/themes/j1/core/js/adapter/cookie_consent.js # JS Adapter for J1 Cookie Consent module # # Product/Info: # http://jekyll.one # # Copyright (C) 2019 Juergen Adams # # J1 Cookie Consent is licensed under the MIT License. # For details, see https://jekyll.one # # ----------------------------------------------------------------------------- # Adapter generated: {{site.time}} # ----------------------------------------------------------------------------- */ 'use strict'; j1.cookieConsent = (function (j1, window) { var environment = '{{environment}}'; // Set environment var state = 'not started'; var consent_modal_html_data = "{{consent_modal_html_data}}" var logger; var logText; return { // ------------------------------------------------------------------------- // Initialize cookieConsent // ------------------------------------------------------------------------- init: function ( options ) { // // Module setting objects var consentDefaults = {}; var consentSettings = {}; var consentConfig = {}; // Setup logger logger = log4javascript.getLogger('j1.cookieConsent.adapter'); // Set|Log status state = 'started'; logger.info('state: ' + state); {% comment %} Load module config from yml data file -------------------------------------------------------------------------- {% endcomment %} consentDefaults = $.extend({}, {{consent_defaults | replace: '=>', ':' }}); consentSettings = $.extend({}, {{consent_settings | replace: '=>', ':' }}); // Merge|Overload module CONFIG by DEFAULTS consentConfig = j1.mergeData( consentDefaults, consentSettings ); // Load (individual) frontmatter options (currently NOT used) if ( options != null ) { var frontmatterOptions = $.extend({}, options) } // Set|Log status state = 'initialized'; logger.info('state: ' + state); logger.info("J1 CookieBar initialized successfully"); {% comment %} Deferred (AJAX) data load -------------------------------------------------------------------------- {% endcomment %} // Load color and font (json) data asychronously // See: https://stackoverflow.com/questions/3709597/wait-until-all-jquery-ajax-requests-are-done $.when( j1.cookieConsent.loadModals( consentConfig ) ).done ( function( ) { // Run initializer functions cookieConsent.init ({ whitelisted_pages: consentConfig.whitelisted_pages, stopScrolling: consentConfig.stop_scrolling, policyButton: consentConfig.buttons['policy_button'], acceptButton: consentConfig.buttons['accept_button'], declineButton: consentConfig.buttons['decline_button'] }); j1.cookieConsent.modalEventHandler( consentConfig ); }); return; }, // END init cookieConsent // ------------------------------------------------------------------------- // load the modals used by cookieConsent // ------------------------------------------------------------------------- loadModals: function ( consentConfig ) { // closure to pass additional data (#id) var cb_load_closure = function( id ) { return function ( responseTxt, statusTxt, xhr ) { if ( statusTxt == "success" ) { var logText = "cookie_consent Modals on ID " +id+ " loaded successfully" logger.info(logText); state = 'finished'; logger.info('state: ' + state); } if ( statusTxt == "error" ) { state = 'failed'; logger.error('state: ' + state); var logText = "Cookiebar Modals on ID " +id+ " loading failed. Error: " + xhr.status + ": " + xhr.statusText; logger.error(logText); } }; }; var id = "#" + consentConfig.consent_modal_id; var selector = $(id); if ( selector.length ) { var modal_html_data_path = consentConfig.modal_html_data_path + " > *"; selector.load( modal_html_data_path, cb_load_closure( id ) ); } else { var logText = "AuthClient Modals not loaded" logger.info(logText); // Set processing to 'finished' to display page state = 'finished'; logger.info('state: ' + state); } return; }, // END loadModals // ------------------------------------------------------------------------- // returns the current (processing) state of the module // ------------------------------------------------------------------------- state: function () { return state; }, // END state // ------------------------------------------------------------------------- // EventHandler for J1 Cookie Consent // Manage button click events for all BS Modals // See: https://www.nickang.com/add-event-listener-for-loop-problem-in-javascript/ // ------------------------------------------------------------------------- modalEventHandler: function ( options ) { var consentConfig = options; var logText; logText = "modalEventHandler: Initialize button click events"; logger.info(logText); var modalsLoaded = setInterval(function() { if ( j1.cookieConsent.state() === 'finished' ) { var options = consentConfig; var current_page = window.location.pathname; var modalButtons = document.querySelectorAll('a.btn'); var appDetected = j1.Navigator.appDetected(); var authClientEnabled = j1.Navigator.authClientEnabled(); var user_state = {}; var web_session_state = {}; var whitelisted; var json_data; // Manage button click events for modal "topFullCookieConsent" // ------------------------------------------------------------------- $(document).on('shown.bs.modal','#topFullCookieConsent', function () { if (consentConfig.stopScrolling) { $('body').addClass('stop-scrolling'); } user_state = j1.getUserStateCookie(); if ( appDetected ) { web_session_state = j1.getWebSessionCookie(); } modalButtons.forEach(function(button, index) { button.addEventListener('click', function() { // policyButton // ------------------------------------------------------------- if (this.id === 'policyButton') { logger.info('User clicked policyButton'); // toggle|display cookie policy $('#cookiePolicyInfo').toggle( 'fast', function() { // toggle container classes $('#modal-footer').toggleClass('modal-footer-hidden modal-footer-show'); }); } // acceptButton // ------------------------------------------------------------- if (this.id === 'acceptButton') { logger.info('User clicked acceptButton'); // Set user state data user_state.status = 'active'; user_state.cookies_accepted = 'accepted'; user_state.provider_membership = 'guest'; //default user_state.provider_permissions = 'public'; //default // Update cookies j1.updateCookies( user_state ); // Display cookie icon $('#quickLinksCookieButton').css('display', 'block'); return; } // declineButton // ------------------------------------------------------------- if (this.id === 'declineButton') { logger.info('User clicked declineButton'); current_page = window.location.pathname; whitelisted = (options.whitelisted_pages.indexOf(current_page) > -1); // Set user state|web session data user_state.status = 'pending'; user_state.cookies_accepted = 'declined'; user_state.provider_permissions = 'public'; // Update cookies j1.updateCookies( user_state ); $('#quickLinksCookieButton').css('display', 'none'); // Set route to home page if current page is NOT whitelisted if ( !whitelisted ) { window.location.href = '/'; } } }); }); }); // Manage button click events for modal "cookieRevokeCentralDanger" // ------------------------------------------------------------------- $(document).on('shown.bs.modal','#cookieRevokeCentralDanger', function () { modalButtons.forEach(function(button, index) { button.addEventListener('click', function() { // revokeCookiesButton // ------------------------------------------------------------- if (this.id === 'revokeCookies') { logger.info('User clicked revokeCookiesButton'); current_page = window.location.pathname; whitelisted = (options.whitelisted_pages.indexOf(current_page) > -1); // Set user state data user_state.status = 'pending'; user_state.cookies_accepted = 'declined'; user_state.provider_permissions = 'public'; // Update cookies j1.updateCookies( user_state ); // Hide cookie icon $('#quickLinksCookieButton').css('display', 'none'); // Set route to home page if current page is NOT whitelisted if ( !whitelisted ) { window.location.href = '/'; } } // remainCookiesButton // ------------------------------------------------------------- if (this.id === 'remainCookies') { logger.info('User clicked remainCookiesButton'); return; } }); }); }); // Manage post events on modal "topFullCookieConsent" // ------------------------------------------------------------------- $(document).on('hide.bs.modal','#topFullCookieConsent', function () { logger.info('User closed topFullCookieConsent'); appDetected = j1.Navigator.appDetected(); authClientEnabled = j1.Navigator.authClientEnabled(); // Show or Hide signin|cookie icon if ( appDetected && authClientEnabled ) { $('#quickLinksSignInOutButton').css('display', 'block'); } else { $('#quickLinksSignInOutButton').css('display', 'none'); } // Update sidebar logger.info('Update sidebar'); j1.updateSidebar(); $('body').removeClass('stop-scrolling'); }); // Manage post events on modal "cookieRevokeCentralDanger" // ------------------------------------------------------------------- $(document).on('hide.bs.modal','#cookieRevokeCentralDanger', function () { logger.info('User closed cookieRevokeCentralDanger'); appDetected = j1.Navigator.appDetected(); authClientEnabled = j1.Navigator.authClientEnabled(); // Show or Hide signin|cookie icon if ( appDetected && authClientEnabled ) { $('#quickLinksSignInOutButton').css('display', 'block'); } else { $('#quickLinksSignInOutButton').css('display', 'none'); } }); // Update sidebar logger.info('Update sidebar'); j1.updateSidebar(); // clear interval checking clearInterval(modalsLoaded); } // END Manage cookie consent dialog }, 50); // END setInterval logText = "modalEventHandler: EventHandler initialized"; logger.info(logText); return; } // END modalEventHandler }; // END return })(j1, window); {% endcapture %} {{ cache | strip_empty_lines }} {% assign cache = nil %}