regenerate: true


{% capture j1_cache %}

{% comment %}

# -----------------------------------------------------------------------------
#  ~/assets/themes/j1/core/js/adapter/toccer.js
#  Liquid template to create the j1_template Adapter for J1 Toccer (TOC Module)
#
#  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 %}

/*

# -----------------------------------------------------------------------------
#  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';

// TODO: Fix the flicker caused by displaying the disqus thread

{% comment %} Variables ——————————————————————————– {% endcomment %} {% assign environment = site.environment %} {% assign modules = site.data.modules %} {% assign toccer_config = modules.j1_toccer %}

{% assign footer_config = modules.j1_footer %} {% assign footer_id = modules.j1_footer.global.id %}

{% 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 %}

{% comment %} Main ——————————————————————————– {% endcomment %} j1.Toccer = function () {

 var environment = '{{environment}}'; // Set environment
 var state       = 'not_started';
 var logger;
 var logText;

return {

  // Initialize
  init: function ( options ) {
    // Setup logger
    logger = log4javascript.getLogger('j1.Toccer.adapter');
    state = 'started';
    logger.info('state: ' + state); // Set|Log status
    logger.info('Toccer 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.toccerInit( 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);
        j1.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
  // ---------------------------------------------------------------------
  toccerInit: 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 toccerInit

  // ---------------------------------------------------------------------
  // 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('<style>.is-active-link::before { font-weight: 700; background-color: {{ active_link_color }}; }</style>');

    return true;
  }, // END setCss

  // -------------------------------------------------------------------------
  //  returns the current (processing) state of the module
  // -------------------------------------------------------------------------
  state: function () {
    return state;
  } // END state

}; // END return

}(j1, window);

{% endcapture %}

{{ j1_cache | strip_empty_lines }} {% assign j1_cache = nil %}