--- regenerate: false --- {% capture j1_cache %} {% comment %} # ----------------------------------------------------------------------------- # ~/assets/themes/j1/adapter/js/toccer.js # Liquid template to adapt Tocbot Core functions # # Product/Info: # https://jekyll.one # https://tscanlin.github.io/tocbot # # Copyright (C) 2019 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # Tocbot is licensed under under the MIT License. # For details, see https://tscanlin.github.io/tocbot # ----------------------------------------------------------------------------- # TODO: # 2019-03-10: Old BS Affix code is to be removed # ----------------------------------------------------------------------------- {% endcomment %} {% comment %} Liquid procedures -------------------------------------------------------------------------------- {% endcomment %} {% comment %} Set global settings -------------------------------------------------------------------------------- {% endcomment %} {% assign environment = site.environment %} {% assign template_version = site.version %} {% comment %} Process YML config data ================================================================================ {% endcomment %} {% comment %} Set config files -------------------------------------------------------------------------------- {% endcomment %} {% assign site_config = site %} {% assign template_config = site.data.template_settings %} {% assign blocks = site.data.blocks %} {% assign modules = site.data.modules %} {% comment %} Set config data -------------------------------------------------------------------------------- {% endcomment %} {% assign toccer_config = modules.j1_toccer %} {% assign footer_config = modules.j1_footer %} {% assign footer_id = modules.j1_footer.global.id %} {% comment %} Set config options -------------------------------------------------------------------------------- {% endcomment %} {% assign active_link_color_fallback = '#204A87' %} {% if toccer_config.defaults.activeLinkColor %} {% assign active_link_color = toccer_config.defaults.activeLinkColor %} {% else %} {% assign active_link_color = active_link_color_fallback %} {% endif %} /* # ----------------------------------------------------------------------------- # ~/assets/themes/j1/adapter/js/toccer.js # JS Adapter for J1 Toccer # # Product/Info: # https://jekyll.one # https://tscanlin.github.io/tocbot # # Copyright (C) 2019 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # Tocbot is licensed under under the MIT License. # For details, see https://tscanlin.github.io/tocbot # ----------------------------------------------------------------------------- # Adapter generated: {{site.time}} # ----------------------------------------------------------------------------- */ 'use strict'; {% comment %} Main -------------------------------------------------------------------------------- {% endcomment %} j1.adapter['toccer'] = (function () { {% comment %} Set global variables ------------------------------------------------------------------------------ {% endcomment %} var environment = '{{environment}}'; // Set environment var state = 'not_started'; var moduleOptions = {}; var _this; var logger; var logText; // --------------------------------------------------------------------------- // Helper functions // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- // Main object // --------------------------------------------------------------------------- return { // ------------------------------------------------------------------------- // Initializer // ------------------------------------------------------------------------- init: function ( options ) { {% comment %} Set global variables -------------------------------------------------------------------------- {% endcomment %} _this = j1.adapter.toccer; logger = log4javascript.getLogger('j1.adapter.toccer'); state = 'started'; logger.info('state: ' + state); logger.info('Module is being initialized'); if ( options !== undefined ) { var settings = $.extend({}, options); } else { var settings = false; } // cast text-based booleans var isToc = (options.toc === 'true'); var isComments = (options.comments === 'true'); if ( settings.collapseDepth === undefined ) { settings.collapseDepth = {{toccer_config.defaults.collapseDepth}}; } if ( settings.headingsOffset === undefined ) { settings.scrollOffset = {{toccer_config.defaults.smoothScrollOffset}}; } else { settings.scrollOffset = settings.headingsOffset } if ( settings.enabled === undefined ) { settings.enabled = true; } if ( isToc ) { this.initToccerCore( settings ); this.setCss(); /* jadams, 2011-03-11: For now, no need to adjust the top sticky position */ /* leave the code in for future use if needed */ /* this.setTop(); */ // if comments enabled if ( isToc && isComments ) { logText = 'Connector Disqus successfully initialized'; logger.info(logText); /* NOTE: BS or Tocbot Affix is not used anymore. Replaced by CSS style "sticky" */ /* j1.adapter.toccer.initAffix(); */ logText = 'Toccer Affix initialized successfully'; logger.info(logText); state = 'finished'; logger.info('Toccer initialized successfully'); logger.info('state: ' + state); // Set|Log status } else { // if toc enabled only if ( isToc ) { state = 'finished'; logger.info('state: ' + state); // Set|Log status logger.info('Toccer initialized successfully'); } } // ENDIF isComments (Disqus enabled) } // ENDIF isToc state = 'finished'; logger.info('state: ' + state); // Set|Log status logger.info('Toccer initialized successfully'); return true; }, // END init // --------------------------------------------------------------------- // Set Toccer options // --------------------------------------------------------------------- initToccerCore: function ( options ) { if ( options !== undefined ) { var settings = $.extend({}, options); } else { var settings = false; } state = 'running'; logger.info('state: ' + state); // Set|Log status tocbot.init({ log: {{ toccer_config.log | json }}, tocSelector: {{ toccer_config.defaults.tocSelector | json }}, headingSelector: {{ toccer_config.defaults.headingSelector | json }}, ignoreSelector: {{ toccer_config.defaults.ignoreSelector | json }}, contentSelector: {{ toccer_config.defaults.contentSelector | json }}, collapseDepth: settings.collapseDepth, throttleTimeout: {{ toccer_config.defaults.throttleTimeout | json }}, includeHtml: false, linkClass: 'toc-link', extraLinkClasses: '', activeLinkClass: 'is-active-link', listClass: 'toc-list', extraListClasses: '', isCollapsedClass: 'is-collapsed', collapsibleClass: 'is-collapsible', listItemClass: 'toc-list-item', positionFixedSelector: '', positionFixedClass: 'is-position-fixed', fixedSidebarOffset: 'auto', smoothScroll: {{ toccer_config.defaults.smoothScrollEnabled | json }}, smoothScrollOffset: {{ toccer_config.defaults.smoothScrollOffset | json }}, smoothScrollDuration: {{ toccer_config.defaults.smoothScrollDuration | json }}, headingsOffset: {{ toccer_config.defaults.headingsOffset | json }}, throttleTimeout: {{ toccer_config.defaults.throttleTimeout | json }} }); if (tocbot.options.log == true) { // Writes all of the current option settings to JS console console.log( tocbot.options ); } return true; }, // END initToccerCore // --------------------------------------------------------------------- // Calculate|Set Affix offset Top|Bottom of the Toccer menu // depending on the size of the page header (masthead) // --------------------------------------------------------------------- initAffix: function () { var nav_bar = $('nav.navbar'); var side_bar = $('#j1-sidebar'); var header = $('.j1-masthead'); //var disqus_id = $('#disqus'); var disqus_id = $('.bmd-layout-content'); var disqus_thread = $('#disqus_thread'); var adblock = $('#adblock'); var footer = '#' + '{{footer_id}}'; var footer_id = $(footer); var footer_offset = 100; $(side_bar).affix({ offset: { top: function() { var c = $(side_bar).offset().top; var a = adblock.length ? adblock.outerHeight() : 0; var e = $(nav_bar).height(); var h = $(header).height(); var z = c - e; return this.top = z - a; }, bottom: function () { /* space below the affixed element */ if (disqus_id.length) { return ( this.bottom = $(disqus_id).outerHeight(true) + $(footer_id).outerHeight(true) + footer_offset ) } else { return ( this.bottom = $(footer_id).outerHeight(true) + footer_offset ); } } } }); return true; }, // END initAffix // --------------------------------------------------------------------- // Calculate|Set Top position of the Toccer menu // depending on the size of the page header (masthead) // --------------------------------------------------------------------- setTop: function ( options) { $(window).scroll(function(event){ var navbar = $('nav.navbar.navigator'); var adblock = $('#adblock'); var pagehead = $('.j1-masthead'); var offset = 0; var m = parseInt(pagehead.css('margin-bottom'), 10); var n = navbar.outerHeight(); var a = adblock.length ? adblock.outerHeight() : 0; // var o = n + m + a + offset; var o = n + m + offset; if( navbar.hasClass('navbar-fixed')){ $('#j1-sidebar.affix').css('top', o); } else { $('#j1-sidebar.affix').css('top', m); } }); return true; }, // END setTop // --------------------------------------------------------------------- // Set dynamic styles // --------------------------------------------------------------------- setCss: function () { $('head').append(''); return true; }, // END setCss // ------------------------------------------------------------------------- // messageHandler: MessageHandler for J1 NAV module // Manage messages (paylods) send from other J1 modules // ------------------------------------------------------------------------- messageHandler: function ( sender, message ) { var json_message = JSON.stringify(message, undefined, 2); logText = 'Received message from ' + sender + ': ' + json_message; logger.debug(logText); // ----------------------------------------------------------------------- // Process commands|actions // ----------------------------------------------------------------------- if ( message.type === 'command' && message.action === 'module_initialized' ) { _this.setState('finished'); logger.info(message.text); } // // Place handling of other command|action here // return true; }, // END messageHandler // ------------------------------------------------------------------------- // Set the current (processing) state of the module // ------------------------------------------------------------------------- setState: function ( stat ) { state = stat; }, // end setState // ------------------------------------------------------------------------- // Returns the current (processing) state of the module // ------------------------------------------------------------------------- getState: function () { return state; } // end state }; // END return })(j1, window); {% endcapture %} {{ j1_cache | strip_empty_lines }} {% assign j1_cache = nil %}