<commit_before>/*
 * scrollNav
 * http://scrollnav.com
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

(function($) {

  // Animate scrolling to section location
  var scroll_to = function(value, speed, offset, animated) {
    if ( $(value).length > 0 ) {
      var destination = $(value).offset().top;
      speed = animated ? speed : 0;

      $('html:not(:animated),body:not(:animated)')
        .animate({scrollTop: destination - offset }, speed );
    }
  };

  // Get url hash if one exists
  var get_hash = function() {
    return window.location.hash;
  };

  var S = {
    classes: {
      loading: 'sn-loading',
      failed: 'sn-failed',
      success: 'sn-active'
    },
    defaults: {
      sections: 'h2',
      subSections: false,
      sectionElem: 'section',
      navClass: 'scroll-nav',
      showHeadline: true,
      headlineText: 'Scroll To',
      showTopLink: true,
      topLinkText: 'Top',
      fixedMargin: 40,
      scrollOffset: 40,
      animated: true,
      speed: 500,
      insertLocation: 'insertBefore',
      arrowKeys: false,
      onInit: null,
      onRender: null,
      onDestroy: null
    },
    _set_body_class: function(state) {
      // Set and swap our loading hooks to the body

      var $body = $('body');

      if (state === 'loading') {
        $body.addClass(S.classes.loading);
      } else if (state === 'success') {
        $body.removeClass(S.classes.loading).addClass(S.classes.success);
      } else {
        $body.removeClass(S.classes.loading).addClass(S.classes.failed);
      }
    },
    _find_sections: function($el) {
      // Find the html for each section

      var target_elems = S.settings.sections;
      var raw_html = [];

      if (S.settings.showTopLink) {
        var $firstElem = $el.children().first();

        if ( !$firstElem.is(target_elems) ) {
          raw_html.push( $firstElem.nextUntil(target_elems).andSelf() );
        }
      }

      $el.find(target_elems).each(function() {
        raw_html.push( $(this).nextUntil(target_elems).andSelf() );
      });

      S.sections = {
        raw: raw_html
      };
    },
    _setup_sections: function(sections) {
      // Wrap each section and add it's details to the section array

      var section_data = [];

      $(sections).each(function(i) {
        var sub_data      = [];
        var $this_section = $(this);
        var section_id    = 'scrollNav-' + (i + 1);
        var isFirst       = function() { return i === 0; };
        var hasHeading    = function() { return !$this_section.eq(0).is(S.settings.sections); };
        var text          = ( S.settings.showTopLink && isFirst() && hasHeading() ) ? S.settings.topLinkText : $this_section.filter(S.settings.sections).text();

        $this_section.wrapAll('<' + S.settings.sectionElem + ' id="' + section_id + '" class="' + S.settings.navClass + '__section" />');

        if (S.settings.subSections) {
          var $sub_sections  = $this_section.filter(S.settings.subSections);

          if ($sub_sections.length > 0) {
            $sub_sections.each(function(i) {
              var sub_id      = section_id + '-' + (i + 1);
              var sub_text    = $(this).text();
              var $this_sub   = $this_section.filter($(this).nextUntil($sub_sections).andSelf());

              $this_sub.wrapAll('<div id="' + sub_id + '" class="' + S.settings.navClass + '__sub-section" />');
              sub_data.push( {id: sub_id, text: sub_text} );
            });
          }
        }

        section_data.push( {id: section_id, text: text, sub_sections: sub_data} );
      });

      S.sections.data = section_data;
    },
    _tear_down_sections: function(sections) {
      $(sections).each(function() {
        var sub_sections = this.sub_sections;

        $('#' + this.id).children().unwrap();

        if (sub_sections.length > 0) {
          $(sub_sections).each(function() {
            $('#' + this.id).children().unwrap();
          });
        }
      });
    },
    _setup_nav: function(sections) {
    // Populate an ordered list from the section array we built

      var $headline = $('<span />', {'class': S.settings.navClass + '__heading', text: S.settings.headlineText});
      var $wrapper  = $('<div />', {'class': S.settings.navClass + '__wrapper'});
      var $nav      = $('<nav />', {'class': S.settings.navClass, 'role': 'navigation'});
      var $nav_list = $('<ol />', {'class': S.settings.navClass + '__list'});

      $.each(sections, function(i) {
        var $item     = (i === 0) ? $('<li />', {'class': S.settings.navClass + '__item active'}) : $('<li />', {'class': S.settings.navClass + '__item'});
        var $link     = $('<a />', {'href': '#' + this.id, 'class': S.settings.navClass + '__link', text: this.text});
        var $sub_nav_list;

        if (this.sub_sections.length > 0) {
          $item.addClass('is-parent-item');
          $sub_nav_list = $('<ol />', {'class': S.settings.navClass + '__sub-list'});

          $.each(this.sub_sections, function() {
            var $sub_item = $('<li />', {'class': S.settings.navClass + '__sub-item'});
            var $sub_link = $('<a />', {'href': '#' + this.id, 'class': S.settings.navClass + '__sub-link', text: this.text});

            $sub_nav_list.append( $sub_item.append($sub_link) );
          });
        }

        $nav_list.append( $item.append($link).append($sub_nav_list) );
      });

      if (S.settings.showHeadline) {
        $nav.append( $wrapper.append($headline).append($nav_list) );
      } else {
        $nav.append( $wrapper.append($nav_list) );
      }

      if (S.settings.navClass) {
        $nav.addClass(S.settings.navClass);
      }

      S.nav = $nav;
    },
    _insert_nav: function() {
      // Add the nav to our page

      var insert_location = S.settings.insertLocation;
      var $insert_target = S.settings.insertTarget;<commit_msg>Removed extra class name insertion from original PR<commit_after>/*
 * scrollNav
 * http://scrollnav.com
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

(function($) {

  // Animate scrolling to section location
  var scroll_to = function(value, speed, offset, animated) {
    if ( $(value).length > 0 ) {
      var destination = $(value).offset().top;
      speed = animated ? speed : 0;

      $('html:not(:animated),body:not(:animated)')
        .animate({scrollTop: destination - offset }, speed );
    }
  };

  // Get url hash if one exists
  var get_hash = function() {
    return window.location.hash;
  };

  var S = {
    classes: {
      loading: 'sn-loading',
      failed: 'sn-failed',
      success: 'sn-active'
    },
    defaults: {
      sections: 'h2',
      subSections: false,
      sectionElem: 'section',
      navClass: 'scroll-nav',
      showHeadline: true,
      headlineText: 'Scroll To',
      showTopLink: true,
      topLinkText: 'Top',
      fixedMargin: 40,
      scrollOffset: 40,
      animated: true,
      speed: 500,
      insertLocation: 'insertBefore',
      arrowKeys: false,
      onInit: null,
      onRender: null,
      onDestroy: null
    },
    _set_body_class: function(state) {
      // Set and swap our loading hooks to the body

      var $body = $('body');

      if (state === 'loading') {
        $body.addClass(S.classes.loading);
      } else if (state === 'success') {
        $body.removeClass(S.classes.loading).addClass(S.classes.success);
      } else {
        $body.removeClass(S.classes.loading).addClass(S.classes.failed);
      }
    },
    _find_sections: function($el) {
      // Find the html for each section

      var target_elems = S.settings.sections;
      var raw_html = [];

      if (S.settings.showTopLink) {
        var $firstElem = $el.children().first();

        if ( !$firstElem.is(target_elems) ) {
          raw_html.push( $firstElem.nextUntil(target_elems).andSelf() );
        }
      }

      $el.find(target_elems).each(function() {
        raw_html.push( $(this).nextUntil(target_elems).andSelf() );
      });

      S.sections = {
        raw: raw_html
      };
    },
    _setup_sections: function(sections) {
      // Wrap each section and add it's details to the section array

      var section_data = [];

      $(sections).each(function(i) {
        var sub_data      = [];
        var $this_section = $(this);
        var section_id    = 'scrollNav-' + (i + 1);
        var isFirst       = function() { return i === 0; };
        var hasHeading    = function() { return !$this_section.eq(0).is(S.settings.sections); };
        var text          = ( S.settings.showTopLink && isFirst() && hasHeading() ) ? S.settings.topLinkText : $this_section.filter(S.settings.sections).text();

        $this_section.wrapAll('<' + S.settings.sectionElem + ' id="' + section_id + '" class="' + S.settings.navClass + '__section" />');

        if (S.settings.subSections) {
          var $sub_sections  = $this_section.filter(S.settings.subSections);

          if ($sub_sections.length > 0) {
            $sub_sections.each(function(i) {
              var sub_id      = section_id + '-' + (i + 1);
              var sub_text    = $(this).text();
              var $this_sub   = $this_section.filter($(this).nextUntil($sub_sections).andSelf());

              $this_sub.wrapAll('<div id="' + sub_id + '" class="' + S.settings.navClass + '__sub-section" />');
              sub_data.push( {id: sub_id, text: sub_text} );
            });
          }
        }

        section_data.push( {id: section_id, text: text, sub_sections: sub_data} );
      });

      S.sections.data = section_data;
    },
    _tear_down_sections: function(sections) {
      $(sections).each(function() {
        var sub_sections = this.sub_sections;

        $('#' + this.id).children().unwrap();

        if (sub_sections.length > 0) {
          $(sub_sections).each(function() {
            $('#' + this.id).children().unwrap();
          });
        }
      });
    },
    _setup_nav: function(sections) {
    // Populate an ordered list from the section array we built

      var $headline = $('<span />', {'class': S.settings.navClass + '__heading', text: S.settings.headlineText});
      var $wrapper  = $('<div />', {'class': S.settings.navClass + '__wrapper'});
      var $nav      = $('<nav />', {'class': S.settings.navClass, 'role': 'navigation'});
      var $nav_list = $('<ol />', {'class': S.settings.navClass + '__list'});

      $.each(sections, function(i) {
        var $item     = (i === 0) ? $('<li />', {'class': S.settings.navClass + '__item active'}) : $('<li />', {'class': S.settings.navClass + '__item'});
        var $link     = $('<a />', {'href': '#' + this.id, 'class': S.settings.navClass + '__link', text: this.text});
        var $sub_nav_list;

        if (this.sub_sections.length > 0) {
          $item.addClass('is-parent-item');
          $sub_nav_list = $('<ol />', {'class': S.settings.navClass + '__sub-list'});

          $.each(this.sub_sections, function() {
            var $sub_item = $('<li />', {'class': S.settings.navClass + '__sub-item'});
            var $sub_link = $('<a />', {'href': '#' + this.id, 'class': S.settings.navClass + '__sub-link', text: this.text});

            $sub_nav_list.append( $sub_item.append($sub_link) );
          });
        }

        $nav_list.append( $item.append($link).append($sub_nav_list) );
      });

      if (S.settings.showHeadline) {
        $nav.append( $wrapper.append($headline).append($nav_list) );
      } else {
        $nav.append( $wrapper.append($nav_list) );
      }

      S.nav = $nav;
    },
    _insert_nav: function() {
      // Add the nav to our page

      var insert_location = S.settings.insertLocation;
      var $insert_target = S.settings.insertTarget;
{'fraction_non_alphanumeric': 0.17251063829787233, 'fraction_numerical': 0.00374468085106383, 'mean_word_length': 2.3017701601573477, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 37, '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': '2708736', 'n_tokens_mistral': 3800, 'n_tokens_neox': 3694, 'n_words': 751}