<commit_before># --------------------------------------------------
# Preview the selected image to upload
# --------------------------------------------------
define (require) ->

	# Dependencies
  $ = require('jquery')
  _ = require('underscore')
  Backbone = require('backbone')

  # Define a backbone view for each image
  Preview = Backbone.View.extend(

    initialize: ->

      _.bindAll this
      @$file = @$el.find('[type="file"]')
      @$holder = @$el.find('.image-holder')
      @$imagePreview = @$holder.find('.img-thumbnail')
      @$delete = @$el.find('.delete')

      # Listener
      @$file.on 'change', @onImageChange
      @$delete.on 'click', @onDelete

      return

    onImageChange: (input) ->
      if @$file[0].files and @$file[0].files[0]
        reader = new FileReader

        reader.onload = (e) =>
          @$file.addClass 'hidden'
          @$el.addClass 'has-image'
          @$imagePreview.attr 'src', e.target.result
          @trigger 'previewImage'

          return

        reader.readAsDataURL @$file[0].files[0]

      return

    onDelete: () ->
      @$imagePreview.attr 'src', ''
      @$el.removeClass 'has-image'
      @$file.removeClass 'hidden'
      @$file.val ''
      @trigger 'deleteImage'

      return
  )

  Preview<commit_msg>image gets replace with new file on delete/reupload<commit_after># --------------------------------------------------
# Preview the selected image to upload
# --------------------------------------------------
define (require) ->

	# Dependencies
  $ = require('jquery')
  _ = require('underscore')
  Backbone = require('backbone')

  # Define a backbone view for each image
  Preview = Backbone.View.extend(

    initialize: ->

      _.bindAll this
      @$file = @$el.find('[type="file"]')
      @$holder = @$el.find('.image-holder')
      @$imagePreview = @$holder.find('.img-thumbnail')
      @$delete = @$el.find('.delete')

      # Listener
      @$file.on 'change', @onImageChange
      @$delete.on 'click', @onDelete

      return

    onImageChange: (input) ->
      if @$file[0].files and @$file[0].files[0]
        reader = new FileReader

        reader.onload = (e) =>
          @$file.addClass 'hidden'
          @$el.addClass 'has-image'
          @$imagePreview.attr 'src', e.target.result
          @trigger 'previewImage'

          return

        reader.readAsDataURL @$file[0].files[0]

      return

    onDelete: () ->
      @$imagePreview.attr 'src', ''
      @$el.removeClass 'has-image'
      @$file.removeClass 'hidden'
      @$file.replaceWith @$file = @$file.clone(true)
      @trigger 'deleteImage'

      return

  )

  Preview
{'fraction_non_alphanumeric': 0.2203325774754346, 'fraction_numerical': 0.003779289493575208, 'mean_word_length': 1.8616216216216217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5552826', 'n_tokens_mistral': 818, 'n_tokens_neox': 782, 'n_words': 164}