<commit_before>import {
  h,
  render,
  define,
  props,
  BoltComponent,
  css,
  spacingSizes,
  hasNativeShadowDomSupport,
} from '@bolt/core';

import gumshoe from 'gumshoejs';
import isVisible from 'is-visible';

// const indicatorElement = '.js-bolt-nav-indicator';
const navLinkElement = 'bolt-navlink'; // Custom element
const isActiveClass = 'is-active';

// Listen for smooth scroll events so we can determine whether or not a link was just clicked on vs if the user is scrolling (to change animation behavior)
function logScrollEvent(event) {
  if (event.type === 'scrollStart'){
    window.isScrolling = true;
  } else if (event.type === 'scrollStop' || event.type === 'scrollCancel') {
    window.isScrolling = false;
  }
}

// Listen for smooth-scroll events
document.addEventListener('scrollStart', logScrollEvent, false);
document.addEventListener('scrollStop', logScrollEvent, false);
document.addEventListener('scrollCancel', logScrollEvent, false);


/* From Modernizr */
function whichTransitionEndEvent() {
  var t;
  var el = document.createElement('fakeelement');
  var transitions = {
    'transition': 'transitionend',
    'OTransition': 'oTransitionEnd',
    'MozTransition': 'transitionend',
    'WebkitTransition': 'webkitTransitionEnd',
  }

  for (t in transitions) {
    if (el.style[t] !== undefined) {
      return transitions[t];
    }
  }
}


// gumshoeStateModule stores an offset value that persists even when it's called multiple times.  If the offset
// is the same as the last time it was called, it avoids initializing gumshoe again (among other things, when
// initializing multiple navbars on one page, this only initializes gumshoe once).  If the offset value HAS changed--
// presumably because the header has adjusted its own height--gumshoe will be re-initialized with the new value.
let gumshoeStateModule = (function () {
  let offset; // Private variable
  let pub = {}; // public object - returned at end of module to allow external interaction
  let reference;

  // navSelectorInstance is used to map up the element calling setOffset so <bolt-nav-indicator> methods can get used
  pub.setOffset = function (newOffset, navSelectorInstance) {
    if (offset !== newOffset) {
      offset = newOffset;

      gumshoe.init({
        selector: 'bolt-nav-indicator a',
        // All the link activation logic is handled in the callback, but gumshoe won't work
        // without a value for activeClass, so we give it a placeholder.
        activeClass: 'has-gumshoe-focus',
        scrollDelay: false,
        offset,
        callback(nav) {
          // Exit early if nav.nav (the target) is undefined. Workaround to occasional JS
          // error throwing `Cannot read property 'nav' of undefined`
          if (!nav.nav){
            return;
          }

          // if this there's a <bolt-nav-priority> instance, make sure that component's ready to go before proceeding trying to animate anything.
          if (nav.nav.closest('bolt-nav-priority')){
            const priorityNav = nav.nav.closest('bolt-nav-priority');

            if (!priorityNav.isReady){
              return;
            }
          }<commit_msg>fix: make sure nav AND nav.nav are both not undefined before trying to animate<commit_after>import {
  h,
  render,
  define,
  props,
  BoltComponent,
  css,
  spacingSizes,
  hasNativeShadowDomSupport,
} from '@bolt/core';

import gumshoe from 'gumshoejs';
import isVisible from 'is-visible';

// const indicatorElement = '.js-bolt-nav-indicator';
const navLinkElement = 'bolt-navlink'; // Custom element
const isActiveClass = 'is-active';

// Listen for smooth scroll events so we can determine whether or not a link was just clicked on vs if the user is scrolling (to change animation behavior)
function logScrollEvent(event) {
  if (event.type === 'scrollStart'){
    window.isScrolling = true;
  } else if (event.type === 'scrollStop' || event.type === 'scrollCancel') {
    window.isScrolling = false;
  }
}

// Listen for smooth-scroll events
document.addEventListener('scrollStart', logScrollEvent, false);
document.addEventListener('scrollStop', logScrollEvent, false);
document.addEventListener('scrollCancel', logScrollEvent, false);


/* From Modernizr */
function whichTransitionEndEvent() {
  var t;
  var el = document.createElement('fakeelement');
  var transitions = {
    'transition': 'transitionend',
    'OTransition': 'oTransitionEnd',
    'MozTransition': 'transitionend',
    'WebkitTransition': 'webkitTransitionEnd',
  }

  for (t in transitions) {
    if (el.style[t] !== undefined) {
      return transitions[t];
    }
  }
}


// gumshoeStateModule stores an offset value that persists even when it's called multiple times.  If the offset
// is the same as the last time it was called, it avoids initializing gumshoe again (among other things, when
// initializing multiple navbars on one page, this only initializes gumshoe once).  If the offset value HAS changed--
// presumably because the header has adjusted its own height--gumshoe will be re-initialized with the new value.
let gumshoeStateModule = (function () {
  let offset; // Private variable
  let pub = {}; // public object - returned at end of module to allow external interaction
  let reference;

  // navSelectorInstance is used to map up the element calling setOffset so <bolt-nav-indicator> methods can get used
  pub.setOffset = function (newOffset, navSelectorInstance) {
    if (offset !== newOffset) {
      offset = newOffset;

      gumshoe.init({
        selector: 'bolt-nav-indicator a',
        // All the link activation logic is handled in the callback, but gumshoe won't work
        // without a value for activeClass, so we give it a placeholder.
        activeClass: 'has-gumshoe-focus',
        scrollDelay: false,
        offset,
        callback(nav) {
          /**
            * Exit early if nav OR nav.nav (the target) is undefined. Workaround to occasional JS error throwing:
            * `Cannot read property 'nav' of undefined`
            */
          if (nav === undefined) {
            return;
          }

          if (nav.nav === undefined){
            return;
          }

          // if this there's a <bolt-nav-priority> instance, make sure that component's ready to go before proceeding trying to animate anything.
          if (nav.nav.closest('bolt-nav-priority')){
            const priorityNav = nav.nav.closest('bolt-nav-priority');

            if (!priorityNav.isReady){
              return;
            }
          }
{'fraction_non_alphanumeric': 0.10059623910717015, 'fraction_numerical': 0.0, 'mean_word_length': 3.0709396390790293, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1213617', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1746, 'n_words': 650}