--- regenerate: true --- {% capture 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) 2023 Juergen Adams # # J1 Theme is licensed under the MIT License. # For details, see: https://github.com/jekyll-one-org/j1-template/blob/main/LICENSE.md # 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 # ----------------------------------------------------------------------------- # TODO: # Height of the window # $(window).height() # should be calculated and checked against the effective height of # the toc menu: # $('#toc_mmenu').outerHeight() # to remove unneded overflow-y indicator (the scrollbar) # ----------------------------------------------------------------------------- {% endcomment %} {% comment %} Liquid procedures -------------------------------------------------------------------------------- {% endcomment %} {% comment %} Process YML config data ================================================================================ {% endcomment %} {% comment %} Set config files -------------------------------------------------------------------------------- {% endcomment %} {% assign template_config = site.data.j1_config %} {% assign blocks = site.data.blocks %} {% assign modules = site.data.modules %} {% comment %} Set config data -------------------------------------------------------------------------------- {% endcomment %} {% assign environment = site.environment %} {% assign template_version = site.version %} {% assign toccer_defaults = modules.defaults.toccer.defaults %} {% assign toccer_settings = modules.toccer.settings %} {% assign scroller_defaults = modules.defaults.scroller.defaults %} {% assign scroller_settings = modules.scroller.settings %} {% assign footer_config = modules.j1_footer %} {% assign footer_id = modules.j1_footer.global.id %} {% comment %} Set config options -------------------------------------------------------------------------------- {% endcomment %} {% assign toccer_options = toccer_defaults | merge: toccer_settings %} {% comment %} Detect prod mode -------------------------------------------------------------------------------- {% endcomment %} {% assign production = false %} {% if environment == 'prod' or environment == 'production' %} {% assign production = true %} {% 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) 2023 Juergen Adams # # J1 Theme is licensed under the MIT License. # For details, see: https://github.com/jekyll-one-org/j1-template/blob/main/LICENSE.md # Tocbot is licensed under under the MIT License. # For details, see https://tscanlin.github.io/tocbot # ----------------------------------------------------------------------------- # Adapter generated: {{site.time}} # ----------------------------------------------------------------------------- */ // ----------------------------------------------------------------------------- // ESLint shimming // ----------------------------------------------------------------------------- /* eslint indent: "off" */ // ----------------------------------------------------------------------------- 'use strict'; j1.adapter.toccer = (function () { {% comment %} Set global variables ------------------------------------------------------------------------------ {% endcomment %} var environment = '{{environment}}'; var scrollerSettings = {}; var scrollerOptions = {}; var scrollerDefaults = {}; var toccerDefaults = {}; var toccerSettings = {}; var toccerOptions = {}; var frontmatterOptions = {}; var _this; var logger; var logText; // --------------------------------------------------------------------------- // helper functions // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- // main object // --------------------------------------------------------------------------- return { // ------------------------------------------------------------------------- // initializer // ------------------------------------------------------------------------- init: function (options) { // ----------------------------------------------------------------------- // Default module settings // ----------------------------------------------------------------------- var settings = $.extend({ module_name: 'j1.adapter.toccer', generated: '{{site.time}}' }, options); // ----------------------------------------------------------------------- // Global variable settings // ----------------------------------------------------------------------- _this = j1.adapter.toccer; logger = log4javascript.getLogger('j1.adapter.toccer'); // create settings object from frontmatter frontmatterOptions = options != null ? $.extend({}, options) : {}; // Load module DEFAULTS|CONFIG toccerDefaults = $.extend({}, {{toccer_defaults | replace: 'nil', 'null' | replace: '=>', ':' }}); toccerSettings = $.extend({}, {{toccer_settings | replace: 'nil', 'null' | replace: '=>', ':' }}); toccerOptions = $.extend(true, {}, toccerDefaults, toccerSettings, frontmatterOptions); // Load scroller module DEFAULTS|CONFIG scrollerDefaults = $.extend({}, {{scroller_defaults | replace: 'nil', 'null' | replace: '=>', ':' }}); scrollerSettings = $.extend({}, {{scroller_settings | replace: 'nil', 'null' | replace: '=>', ':' }}); scrollerOptions = $.extend(true, {}, scrollerDefaults, scrollerSettings); // initialize state flag _this.setState('started'); logger.debug('\n' + 'state: ' + _this.getState()); logger.info('\n' + 'module is being initialized'); // save config settings into the toccer object for later access _this['moduleOptions'] = toccerOptions; if (j1.stringToBoolean(toccerOptions.toc)) { var dependencies_met_navigator = setInterval(function() { var pageState = $('#no_flicker').css("display"); var pageVisible = (pageState == 'block') ? true: false; if ( j1.getState() == 'finished' && pageVisible ) { _this.initToccerCore(toccerOptions); _this.setState('finished'); logger.debug('\n' + 'state: ' + _this.getState()); logger.info('\n' + 'module initialized successfully'); logger.debug('\n' + 'met dependencies for: j1'); clearInterval(dependencies_met_navigator); } }, 25); } }, // END init // ------------------------------------------------------------------------- // Initialize the toccer on page // ------------------------------------------------------------------------- initToccerCore: function (options) { var scrollOffsetCorrection = scrollerOptions.smoothscroll.offsetCorrection; var scrollOffset = j1.getScrollOffset(scrollOffsetCorrection); _this.setState('running'); logger.debug('\n' + 'state: ' + _this.getState()); // tocbot get fired if HTML portion is loaded (AJAX load finished) // var dependencies_met_ajax_load_finished = setInterval (function () { if ($('#toc_mmenu').length) { /* eslint-disable */ tocbot.init({ log: options.log, activeLinkColor: options.activeLinkColor, tocSelector: options.tocSelector, headingSelector: options.headingSelector, ignoreSelector: options.ignoreSelector, contentSelector: options.contentSelector, collapseDepth: options.collapseDepth, throttleTimeout: options.throttleTimeout, hasInnerContainers: false, 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', scrollContainer: null, scrollSmooth: options.scrollSmooth, scrollSmoothDuration: options.scrollSmoothDuration, scrollSmoothOffset: scrollOffset, headingsOffset: 1, throttleTimeout: options.throttleTimeout }); /* eslint-enable */ logger.debug('\n' + 'met dependencies for: loadHTML'); clearInterval(dependencies_met_ajax_load_finished); } // END AJAX load finished }, 25); // END dependencies_met_ajax_load_finished }, // END initToccerCore // ------------------------------------------------------------------------- // 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 = '\n' + 'received message from ' + sender + ': ' + json_message; logger.debug(logText); // ----------------------------------------------------------------------- // Process commands|actions // ----------------------------------------------------------------------- if (message.type === 'command' && message.action === 'module_initialized') { // // Place handling of command|action here // logger.info('\n' + message.text); } // // Place handling of other command|action here // return true; }, // END messageHandler // ------------------------------------------------------------------------- // setState() // Sets the current (processing) state of the module // ------------------------------------------------------------------------- setState: function (stat) { _this.state = stat; }, // END setState // ------------------------------------------------------------------------- // getState() // Returns the current (processing) state of the module // ------------------------------------------------------------------------- getState: function () { return _this.state; } // END getState }; // END return })(j1, window); {% endcapture %} {% if production %} {{ cache | minifyJS }} {% else %} {{ cache | strip_empty_lines }} {% endif %} {% assign cache = nil %}