--- regenerate: true --- {% capture cache %} {% comment %} # ----------------------------------------------------------------------------- # ~/assets/themes/j1/core/js/adapter/template.js # Liquid template to create the Template Adapter for J1 Template Core # # Product/Info: # https://jekyll.one # # Copyright (C) 2019 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # # ----------------------------------------------------------------------------- # TODO: jadams, 2019-01-20: Isolate drawer, switch from BME code # ----------------------------------------------------------------------------- # Test data: # {{ liquid_var | debug }} # # ----------------------------------------------------------------------------- {% endcomment %} /* # ----------------------------------------------------------------------------- # ~/assets/themes/j1/core/js/adapter/j1_template.js # JS Adapter for J1 Template # # Product/Info: # https://jekyll.one # # Copyright (C) 2019 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # # ----------------------------------------------------------------------------- # Adapter generated: {{site.time}} # ----------------------------------------------------------------------------- */ 'use strict'; {% comment %} Variables -------------------------------------------------------------------------------- {% endcomment %} {% if site.permalink == 'none' %} {% capture page_url %}{{ site.url }}.html{% endcapture %} {% else %} {% capture page_url %}{{ site.url }}{% endcapture %} {% endif %} {% assign environment = site.environment %} {% assign template_version = site.version %} {% assign hideOnReload = site.data.modules.j1_theme_switcher.hideOnReload %} {% assign flickerTimeout = site.data.modules.j1_theme_switcher.flicker_timeout %} {% unless flickerTimeout %} {% assign flickerTimeout = 250 %} {% endunless %} {% assign modules = site.data.modules %} {% assign banner_config = modules.j1_banner.banners %} {% assign panel_config = modules.j1_panel.panels %} {% assign toccer_config = modules.j1_toccer %} {% assign footer_config = modules.j1_footer %} {% assign footer_id = modules.j1_footer.global.id %} {% assign banner_data_path = modules.j1_banner.global.data_path %} {% assign panel_data_path = modules.j1_panel.global.data_path %} {% assign footer_data_path = modules.j1_footer.global.data_path %} {% comment %} Main -------------------------------------------------------------------------------- {% endcomment %} var j1 = function () { var environment = '{{environment}}'; // Set environment // Status information var state = 'not_started'; var app_detected; var user_state_detected; // Theme information var themeName; var themeCss; var themeExtensionCss; // J1 data files var j1_colors = {}; var colors_data_path = "/assets/data/colors.json"; // Logger var logger; var logText; // J1 UserState Cookie (initial values) var j1_user_state = { 'theme_css' : '/assets/themes/j1/core/css/uno.css', 'theme_extension_css' : '/assets/themes/j1/core/css/theme_extensions.css', 'theme_name' : 'Uno', 'theme_author' : 'J1 Team', 'theme_link' : 'https://support.jekyll-one.com/', 'previous_page' : 'unknown', 'current_page' : 'unknown', 'provider' : 'j1', 'provider_membership' : 'guest', "provider_permissions" : "public", "provider_url" : "https:/jekyll.one", 'status' : 'pending', 'user_name' : 'visitor', 'language' : 'unknown', 'cookies_accepted' : "pending", 'writer' : 'web' }; return { // Initialize init: function ( options ) { var logger = log4javascript.getLogger('j1.Template.adapter'); state = 'started'; logger.info('state: ' + state); // Set|Log status if ( options !== undefined ) { var settings = $.extend({}, options); } else { var settings = false; } if ( settings.scrollbar === 'false' ) { $( 'body' ).addClass( 'hide-scrollbar' ) } // Detect|Set J1 AppSession app_detected = j1.existsCookie ( 'j1.web.session' ); // Detect|Set J1 UserState user_state_detected = j1.existsCookie ( 'j1.user.state' ); if ( user_state_detected ) { logger.info('Read UserState cookie'); j1_user_state = j1.getUserStateCookie(); themeName = j1_user_state.theme_name; themeCss = j1_user_state.theme_css; themeExtensionCss = j1_user_state.theme_extension_css; } else { logger.warn('UserState cookie NOT found'); } // Hide signin/signout button if cookies are DECLINED // if ( app_detected && j1_user_state.cookies_accepted == 'declined') { // $('#quickLinksSignInOutButton').css('display', 'none'); // } {% comment %} Deferred data load -------------------------------------------------------------------------- {% endcomment %} // Load banner and panel HTML data asychronously // See: https://stackoverflow.com/questions/3709597/wait-until-all-jquery-ajax-requests-are-done $.when( j1.initBanner(settings), j1.initPanel(settings), j1.initFooter( settings ) ).done ( function(initBanner_response, initPanel_response) { var logger = log4javascript.getLogger('j1.Template.adapter'); state = 'running'; logger.info('initBanner: state: ' + state); j1_user_state.language = j1.getLanguage(); j1.setUserStateCookie( j1_user_state ); // jadams, 2019-01-20: enabled only drawer, switch and ripples, // initialize BMD JS components j1.initMDB(settings); j1.initClipboard(settings); j1.displayPage(settings); }); return; }, // END init // ------------------------------------------------------------------------- // AJAX loader to load and place all banner used for a page // ------------------------------------------------------------------------- // ToDo: initBanner: function ( options ) { var logger = log4javascript.getLogger('j1.Template.adapter'); var banner = []; var bannerOptions = []; var logText = 'initBanner: Start initialization'; logger.info(logText); {% comment %} helper functions for (AJAX) data load -------------------------------------------------------------------------- {% endcomment %} function load_color_data() { // Returns the j1_colors object return $.ajax({ url: colors_data_path, success: function (data) { if (typeof data == 'string') { j1_colors = JSON.parse(data); } if (typeof data == 'object') { j1_colors = data; } } }); }; // closure to pass additional data (e.g. div #id) // to AJAX load callback (panel_id) // See: http://stackoverflow.com/questions/939032/jquery-pass-more-parameters-into-callback var cb_load_closure = function(panel_id) { return function ( responseTxt, statusTxt, xhr ) { if ( statusTxt == 'success' ) { logText = 'initBanner: Banner on ID ' +panel_id+ ' loaded successfully'; logger.info(logText); } if ( statusTxt == 'error' ) { logText = 'initBanner: Banner on ID ' +panel_id+ ' loading failed. Error: ' + xhr.status + ': ' + xhr.statusText; logger.error(logText); // Set|Log status state = 'failed'; logger.error('state: ' + state); } }; }; {% comment %} Create CSS styles -------------------------------------------------------------------------- {% endcomment %} // Load color and font (json) data asychronously // See: https://stackoverflow.com/questions/3709597/wait-until-all-jquery-ajax-requests-are-done $.when( load_color_data() ).done ( function( color_data ) { // Collect all banner id|s configured {% for items in banner_config %} {% for banners in items %} {% for banner in banners %} {% for item in banner %} {% assign key = item[0] %} {% assign value = item[1] %} {% if key == 'id' %} {% assign id = value %} {% endif %} {% if key == 'background_color_1' %} {% assign background_color_1 = value %} {% endif %} {% if key == 'background_color_2' %} {% assign background_color_2 = value %} {% endif %} {% endfor %} {% endfor %} {% comment %} Add header CSS styles to ------------------------------------------------------------------ {% endcomment %} var banner_backround_style = ''; // Initialze banner background gradient/colors banner_backround_style += ""; $('head').append( banner_backround_style ); {% endfor %} {% endfor %} }); {% comment %} Collect all banner id|s configured -------------------------------------------------------------------------- {% endcomment %} {% for items in banner_config %} {% for banners in items %} {% for banner in banners %} {% for item in banner %} {% assign key = item[0] %} {% assign value = item[1] %} {% if key == 'id' %} {% assign id = value %} {% endif %} {% if key == 'background_color_1' %} {% assign background_color_1 = value %} {% endif %} {% if key == 'background_color_2' %} {% assign background_color_2 = value %} {% endif %} {% endfor %} {% endfor %} banner.push('{{id}}'); {% endfor %} {% endfor %} if ( banner.length ) { logText = 'initBanner Banner are being loaded deferred (if any)'; logger.info(logText); } for (var i in banner) { var id = '#' + banner[i]; var selector = $(id); if ( selector.length ) { var banner_data_path = '{{banner_data_path}} ' + id + ' > *'; selector.load( banner_data_path, cb_load_closure( id ) ); } } return; }, // END initBanner // ------------------------------------------------------------------------- // AJAX loader for panel used with J1 Template fo all pages // ------------------------------------------------------------------------- // ToDo: initPanel: function ( options ) { var logger = log4javascript.getLogger('j1.Template.adapter'); var panel = []; var logText = 'initPanel: Start initialization'; logger.info(logText); // closure to pass additional data (e.g. div #id) // to AJAX load callback (panel_id) // See: http://stackoverflow.com/questions/939032/jquery-pass-more-parameters-into-callback var cb_load_closure = function(panel_id) { return function ( responseTxt, statusTxt, xhr ) { if ( statusTxt == 'success' ) { logText = 'initPanel: Panel on ID ' +panel_id+ ' loaded successfully'; logger.info(logText); } if ( statusTxt == 'error' ) { logText = 'initPanel: Panel on ID ' +panel_id+ ' loading failed. Error: ' + xhr.status + ': ' + xhr.statusText; logger.error(logText); // Set|Log status state = 'Error'; logger.error('state: ' + state); } }; }; // Collect all panel id|s configured {% for items in panel_config %} {% for panels in items %} {% for panel in panels %} {% for item in panel %} {% assign key = item[0] %} {% assign value = item[1] %} {% if key == 'id' %} {% assign id = value %} {% endif %} {% endfor %} {% endfor %} panel.push('{{id}}'); {% endfor %} {% endfor %} if ( panel.length ) { logText = 'initPanel: Panel are being loaded deferred (if any)'; logger.info(logText); } for (var i in panel) { var id = "#" + panel[i]; var selector = $(id); if ( selector.length ) { // Set the return URL (user by news pager) for the News Banner // Cookies.set(cookieUserState, '{{page_url}}#news_panel', { expires: 365 }); // j1_user_state.previous_page = "{{page_url}}" // j1.setUserStateCookie( j1_user_state ); var panel_data_path = '{{panel_data_path}} ' + id + ' > *'; selector.load( panel_data_path, cb_load_closure( id ) ); } } return; }, // END initPanel // ------------------------------------------------------------------------- // AJAX loader for page footer used with J1 Template fo all pages // ------------------------------------------------------------------------- // ToDo: initFooter: function ( options ) { var logger = log4javascript.getLogger('j1.Template.adapter'); var logText = 'initFooter: Start initialization'; logger.info(logText); var cb_load_closure = function(footer_id) { return function ( responseTxt, statusTxt, xhr ) { if ( statusTxt == 'success' ) { logText = 'initFooter: Footer on ID ' +footer_id+ ' loaded successfully'; logger.info(logText); } if ( statusTxt == 'error' ) { logText = 'initFooter: Footer on ID ' +footer_id+ ' loading failed. Error: ' + xhr.status + ': ' + xhr.statusText; logger.error(logText); // Set|Log status state = 'failed'; logger.error('state: ' + state); } }; }; var id = '#' + '{{footer_id}}'; var selector = $(id); if ( selector.length ) { var footer_data_path = '{{footer_data_path}}'; selector.load( footer_data_path, cb_load_closure( id ) ); } return; }, // END initFooter // ------------------------------------------------------------------------- // Create copy-to-clipboard for all pages // ------------------------------------------------------------------------- // ToDo: initClipboard: function ( options ) { var logger = log4javascript.getLogger('j1.Template.adapter'); var logText = 'initClipboard: Start initialization'; logger.info(logText); // insert copy to clipboard button before all elements having a // class of ".highlight" assigned to (e.g. Asciidoc source blocks) $('.highlight').each(function () { // Check if no clipboard should be applied var isNoClip = $(this).closest('.noclip'); if ( isNoClip.length == 0) { var btnHtml = '
Copy
'; var bumms = $(this).closest('.noclip'); $(this).before(btnHtml); $('.btn-clipboard').tooltip(); } }); var clipboard = new Clipboard( '.btn-clipboard', { target: function target(trigger) { return trigger.parentNode.nextElementSibling; } }); // Manage clipboard events clipboard.on('success', function (e) { $(e.trigger).attr('title', 'Copied!').tooltip('_fixTitle').tooltip('show').attr('title', 'Copy to clipboard').tooltip('_fixTitle'); var logger = log4javascript.getLogger('j1.Template.adapterrr'); var logText = 'initClipboard: Copy-To-Clipboard sucessfull'; logger.info(logText); /* Cleanup clipped data for trailing numbers */ var splitted = e.text.split('\n'); var concat; var i; for (i=0; i