<commit_before>function SidebarController () {
  this.displayedEntries = 0;
  this.entriesToFetch = 25;
  this.$sidebar = $(".sidebar-nav");
  this.baseApiUrl = 'http://flatiron-magazine-cpk.herokuapp.com/api/v0/entries';
  this.arrayOfSlugs = [];
}

SidebarController.prototype.initialize = function() {
  this.fetchEntries();
  this.selectEntryBeingRead();
  this.selectClickedEntry();
}

SidebarController.prototype.reset = function() {

}

SidebarController.prototype.fetchEntries = function() {
  var that = this;
  $.get(this.fetchNextEntriesApiUrl(), function(data) {
    that.appendEntries(data);
  });
}

SidebarController.prototype.appendEntries = function(jsonEntries) {
  var that = this,
      entry;
  $.map(jsonEntries, function(jsonEntry, i) {
    entry = new Entry(jsonEntry);
    that.$sidebar.append(HandlebarsTemplates['entries/sidebar_entry'](entry));
    that.arrayOfSlugs.push(entry.slug);
    that.displayedEntries++;
  });
}

SidebarController.prototype.fetchNextEntriesApiUrl = function() {
  var url = this.baseApiUrl + '?concise=true&limit=' + this.entriesToFetch;
  if (this.displayedEntries > 0)  {
    url += '&offset=' + this.displayedEntries;
  }
  return url;
}

SidebarController.prototype.selectEntryBeingRead = function() {
  var that = this;

  $( window ).scroll(function() {
    var $windowPos = $( window ).scrollTop(),
        $windowHeight = $( window ).height(),
        $documentHeight = $( document ).height();

    for ( var i = 0; i < that.arrayOfSlugs.length; i++ ) {
      var slug = that.arrayOfSlugs[i],
          $divPos = $( "#" + slug ).offset().top - 60,
          $divHeight = $( "#" + slug ).height();
      if ( $windowPos >= $divPos && $windowPos < ( $divPos + $divHeight ) ) {
        $( "a[href='" + slug + "']" ).addClass( "nav-active" );
      } else {
        $( "a[href='" + slug + "']" ).removeClass( "nav-active" );
      }
    }

    if ( $windowPos + $windowHeight === $documentHeight ) {
      if ( !$( ".sidebar-nav li:last-child a" ).hasClass( "nav-active" ) ) {
        var $highlightedSlug = $( ".nav-active" ).attr( "href" );
        $( "a[href='" + $highlightedSlug + "']" ).removeClass( "nav-active" );
        $( ".sidebar-nav li:last-child a" ).addClass( "nav-active" );
      }
    }
  });
}

SidebarController.prototype.selectClickedEntry = function() {<commit_msg>Use jquery.inview for selecting the currently-selected entry in the sidebar<commit_after>function SidebarController () {
  this.displayedEntries = 0;
  this.entriesToFetch = 25;
  this.$sidebar = $(".sidebar-nav");
  this.baseApiUrl = 'http://flatiron-magazine-cpk.herokuapp.com/api/v0/entries';
  this.arrayOfSlugs = [];
}

SidebarController.prototype.initialize = function() {
  this.fetchEntries();
  this.selectEntryBeingRead();
  this.selectClickedEntry();
}

SidebarController.prototype.reset = function() {

}

SidebarController.prototype.fetchEntries = function() {
  var that = this;
  $.get(this.fetchNextEntriesApiUrl(), function(data) {
    that.appendEntries(data);
  });
}

SidebarController.prototype.appendEntries = function(jsonEntries) {
  var that = this,
      entry;
  $.map(jsonEntries, function(jsonEntry, i) {
    entry = new Entry(jsonEntry);
    that.$sidebar.append(HandlebarsTemplates['entries/sidebar_entry'](entry));
    that.arrayOfSlugs.push(entry.slug);
    that.displayedEntries++;
  });
}

SidebarController.prototype.fetchNextEntriesApiUrl = function() {
  var url = this.baseApiUrl + '?concise=true&limit=' + this.entriesToFetch;
  if (this.displayedEntries > 0)  {
    url += '&offset=' + this.displayedEntries;
  }
  return url;
}

SidebarController.prototype.selectEntryBeingRead = function() {
  var sidebar = this.$sidebar,
      slug;
  $( '#page-content-wrapper' ).on('inview', 'div.entry', function(event, isInView) {
    if (isInView) {
      slug = $(this).attr('id');
      sidebar.find('a').removeClass('nav-active');
      sidebar.find('a[href="' + slug + '"]').addClass('nav-active');
    }
  });
}

SidebarController.prototype.selectClickedEntry = function() {
{'fraction_non_alphanumeric': 0.17048534121704853, 'fraction_numerical': 0.003202759300320276, 'mean_word_length': 3.7652582159624415, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '976934', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1304, 'n_words': 217}