<commit_before>'use strict';
/*global window */

var $ = require('jquery')
  , $sidebar
  , $content
  ;

function browserSupportsHistoryApi(history) {
  return !!(history && history.pushState);
}

function update(sidebar, content) {
  if (sidebar && sidebar !== $sidebar.html()) $sidebar.html(sidebar);
  if (content && content !== $content.html()) $content.html(content);
}

function render(history, url, res) {
  update(res.sidebar, res.content);
  history.pushState({sidebar: res.sidebar, content: res.content }, null, url);
}  

$(function () {
  var history = window.history;
  if (!browserSupportsHistoryApi(history)) return;

  window.onpopstate = function (args) { 
    var state = args.state;
    if (!state) return;
    update(state.sidebar, state.content); 
  };

  $sidebar = $('.main .sidebar > ul');
  $content = $('.main .content');

  $('.main .sidebar')
    .on('click', 'a', function (event) {
      var url = this.href;
      $.ajax({
          url: url
        , dataType: 'json'
        })
        .success(function (res) { render(history, url, res); })
        .error(function () { console.log('error', arguments); })
        ;
      return false;
    });
});<commit_msg>using push state for main nav as well<commit_after>'use strict';
/*global window */

var $ = require('jquery')
  , $sidebar
  , $content
  ;

function browserSupportsHistoryApi(history) {
  return !!(history && history.pushState);
}

function update(sidebar, content) {
  if (sidebar && sidebar !== $sidebar.html()) $sidebar.html(sidebar);
  if (content && content !== $content.html()) $content.html(content);
}

function render(history, url, res) {
  update(res.sidebar, res.content);
  history.pushState({sidebar: res.sidebar, content: res.content }, null, url);
}  

function handleNavigation (history, url) {
  $.ajax({
      url: url
    , dataType: 'json'
    })
    .success(function (res) { render(history, url, res); })
    .error(function () { console.log('error', arguments); })
    ;
  return false;
}

$(function () {
  var history = window.history;
  if (!browserSupportsHistoryApi(history)) return;

  window.onpopstate = function (args) { 
    var state = args.state;
    if (!state) return;
    update(state.sidebar, state.content); 
  };

  $sidebar = $('.main .sidebar > ul');
  $content = $('.main .content');

  $('.main .sidebar')
    .on('click', 'a', function(event) { return handleNavigation(history, this.href); });
  $('.main.nav')
    .on('click', 'a', function(event) { return handleNavigation(history, this.href); });
});
{'fraction_non_alphanumeric': 0.18271119842829076, 'fraction_numerical': 0.0, 'mean_word_length': 3.5464285714285713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4404629', 'n_tokens_mistral': 800, 'n_tokens_neox': 783, 'n_words': 191}