<commit_before>var PhotoRenderer = function(container, photo) {
  bindEvents();

  this.render = function() {
    startProgress()
    renderImage(photo)

    return this
  }

  function bindEvents() {
    $("a").click($.proxy(renderNewImage, this))

    $(window).on("popstate", $.proxy(renderImageFromHistory, this))
  }

  function renderImage(photo) {
    var dfd = $.Deferred()

    loadPhoto(photo).done(function() {
      $(this).remove()

      container.fadeOut(function() {
        $(this)
          .css("background-image", "url(" + photo.url + ")")
          .find(".caption").html(photo.photoset.title._content + "<br>" + photo.title + "<br>" + photo.ownername).end()
          .fadeIn()
      })

      NProgress.done()
      dfd.resolve()
    })

    this.nextRandomImage = getRandomImageJSON()

    return dfd
  }

  function renderNewImage(ev) {
    ev.preventDefault()

    startProgress()

    var photoRequest = this.nextRandomImage || getRandomImageJSON()
    photoRequest.done(replaceCurrentImage)
  }

  function getRandomImageJSON() {
    var photoJSONUrl = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port + $("a").attr("href") + ".json"
    return $.getJSON(photoJSONUrl).done(loadPhoto)
  }

  function loadPhoto(photo) {
    var dfd = $.Deferred()
    $("<img>").load(function() { $(this).remove(); dfd.resolve() }).attr("src", photo.url)    

    return dfd
  }

  function renderImageFromHistory() {
    if (!event.state) return

    startProgress()
    renderImage(event.state)
  }

  function replaceCurrentImage(photo) {
    renderImage(photo).done(function() {
      history.pushState(photo, "", photo.browser_url)      
    })
  }

  function startProgress() {
    NProgress.configure({minimum: 0.3}).start()    
  }
}
<commit_msg>Simplify code.<commit_after>var PhotoRenderer = function(container, photo) {
  bindEvents();

  this.render = function() {
    startProgress()
    renderImage(photo)

    return this
  }

  function bindEvents() {
    $("a").click($.proxy(renderNewImage, this))

    $(window).on("popstate", $.proxy(renderImageFromHistory, this))
  }

  function renderImage(photo) {
    var dfd = $.Deferred()

    loadPhoto(photo).done(function() {
      $(this).remove()

      container.fadeOut(function() {
        $(this)
          .css("background-image", "url(" + photo.url + ")")
          .find(".caption").html(photo.photoset.title._content + "<br>" + photo.title + "<br>" + photo.ownername).end()
          .fadeIn()
      })

      NProgress.done()
      dfd.resolve()
    })

    this.nextRandomImage = getRandomImageJSON()

    return dfd
  }

  function renderNewImage(ev) {
    ev.preventDefault()

    startProgress()

    var photoRequest = this.nextRandomImage || getRandomImageJSON()
    photoRequest.done(replaceCurrentImage)
  }

  function getRandomImageJSON() {
    var photoJSONUrl = $("a").attr("href") + ".json"
    return $.getJSON(photoJSONUrl).done(loadPhoto)
  }

  function loadPhoto(photo) {
    var dfd = $.Deferred()
    $("<img>").load(function() { $(this).remove(); dfd.resolve() }).attr("src", photo.url)    

    return dfd
  }

  function renderImageFromHistory() {
    if (!event.state) return

    startProgress()
    renderImage(event.state)
  }

  function replaceCurrentImage(photo) {
    renderImage(photo).done(function() {
      history.pushState(photo, "", photo.browser_url)      
    })
  }

  function startProgress() {
    NProgress.configure({minimum: 0.3}).start()    
  }
}

{'fraction_non_alphanumeric': 0.1628303495311168, 'fraction_numerical': 0.0011366865586814436, 'mean_word_length': 3.0599769319492505, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 9, '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': '6048230', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1073, 'n_words': 178}