<commit_before>#= require jquery
#= require jquery_ujs
#= require underscore
#= require_self

Gif =
  load: ($gif) ->
    @toggle $gif

  pause: ($gif) ->
    @toggle $gif

  toggle: ($gif) ->
    $image = $gif.find('img')
    url    = $image.data 'url'

    $image.data 'url', $image.attr('src')
    $image.attr 'src', url

  find: (element) ->
    jQuery(element).closest('.gif')

jQuery ->
  jQuery('.gif-inner').on
    mouseenter: (event) ->
      Gif.load Gif.find(event.target)
    mouseleave: (event) ->
      Gif.pause Gif.find(event.target)<commit_msg>First cut at preloading.<commit_after>#= require jquery
#= require jquery_ujs
#= require underscore
#= require_self

Gif =
  load: (url, options) ->
    xhr = new XMLHttpRequest()
    xhr.open "GET", url

    xhr.onload = (event) ->
      options.completed()

    xhr.onprogress = (event) ->
      percentage = (event.loaded / event.total) * 100

    xhr.send()

  play: ($gif) ->
    @toggle $gif

  pause: ($gif) ->
    @toggle $gif

  toggle: ($gif) ->
    $image = $gif.find('img')
    url    = $image.data 'url'

    Gif.load url,
      progress: ->
        console.log arguments
      completed: ->
        $image.data 'url', $image.attr('src')
        $image.attr 'src', url

  find: (element) ->
    jQuery(element).closest('.gif')

jQuery ->
  jQuery('.gif-inner').on
    mouseenter: (event) ->
      Gif.play Gif.find(event.target)
    mouseleave: (event) ->
      Gif.pause Gif.find(event.target)
{'fraction_non_alphanumeric': 0.17574931880108993, 'fraction_numerical': 0.0020435967302452314, 'mean_word_length': 2.53125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '5553488', 'n_tokens_mistral': 537, 'n_tokens_neox': 516, 'n_words': 113}