<commit_before>require "scripts/setup"

_ = require "underscore"
PrefixFree = require "prefixfree"
Bounce = require "bounce"

Events = require "scripts/events"
BaseView = require "scripts/views/base"
PreferencesView = require "scripts/views/preferences"
BoxView = require "scripts/views/box"
Events = require "scripts/events"

template = require "templates/app"

class App extends BaseView
  el: ".app"
  template: template

  events:
    "click .spin-link": "animateSpin"
    "click .play-button": "onClickPlay"
    "mousedown .box": "startBoxDrag"
    "ifChanged .loop-input, .slow-input": "playAnimation"

  initialize: ->
    super
    @preferences = new PreferencesView
    @boxView = new BoxView

    @$style = @$ "#animation"
    @$result = @$ "#result"
    @$box = @$result.find ".box"
    @$loop = @$ ".actions .loop-input"
    @$slow = @$ ".actions .slow-input"

    for checkbox in [@$loop, @$slow]
      checkbox.iCheck insert: "<i class=\"fa fa-check\"></i>"

    Events.on
      "animationOptionsChanged": @playAnimation
      "selectedPresetAnimation": @onSelectPreset
      "componentRemoved": @playAnimation

    @readURL()

  onClickPlay: ->
    if @preferences.getBounceObject().components.length
      @playAnimation()
    else
      $body = $ "body"
      $body.addClass "play-empty"
      setTimeout (-> $body.removeClass "play-empty"), 1000

  playAnimation: (options = {}) =>
    bounce = options.bounceObject or @preferences.getBounceObject()
    unless bounce.components.length
      window.location.hash = ""
      @$box.removeClass "animate"
      return

    duration = options.duration or bounce.duration
    duration *= 10 if @$slow.prop("checked") and not options.duration

    properties = []
    properties.push "animation-duration: #{duration}ms"
    properties.push("animation-iteration-count: infinite") if @$loop.prop("checked")

    css = """
    .box.animate {
      #{properties.join(";\n  ")};
    }
    #{bounce.getKeyframeCSS(name: "animation")}
    """

    @$style.text PrefixFree.prefixCSS(css, true)

    @$box.removeClass "animate"
    @$box[0].offsetWidth
    @$box.addClass "animate"

    @updateURL(bounce) unless options.updateURL is false<commit_msg>Fix weirdness when clicking on play multiple times on empty sidebar<commit_after>require "scripts/setup"

_ = require "underscore"
PrefixFree = require "prefixfree"
Bounce = require "bounce"

Events = require "scripts/events"
BaseView = require "scripts/views/base"
PreferencesView = require "scripts/views/preferences"
BoxView = require "scripts/views/box"
Events = require "scripts/events"

template = require "templates/app"

class App extends BaseView
  el: ".app"
  template: template

  events:
    "click .spin-link": "animateSpin"
    "click .play-button": "onClickPlay"
    "mousedown .box": "startBoxDrag"
    "ifChanged .loop-input, .slow-input": "playAnimation"

  initialize: ->
    super
    @preferences = new PreferencesView
    @boxView = new BoxView

    @$style = @$ "#animation"
    @$result = @$ "#result"
    @$box = @$result.find ".box"
    @$loop = @$ ".actions .loop-input"
    @$slow = @$ ".actions .slow-input"

    for checkbox in [@$loop, @$slow]
      checkbox.iCheck insert: "<i class=\"fa fa-check\"></i>"

    Events.on
      "animationOptionsChanged": @playAnimation
      "selectedPresetAnimation": @onSelectPreset
      "componentRemoved": @playAnimation

    @readURL()

  onClickPlay: ->
    if @preferences.getBounceObject().components.length
      @playAnimation()
    else
      $body = $ "body"
      $body.addClass "play-empty"
      clearTimeout(@playEmptyTimeout) if @playEmptyTimeout
      @playEmptyTimeout = setTimeout (-> $body.removeClass "play-empty"), 1000

  playAnimation: (options = {}) =>
    bounce = options.bounceObject or @preferences.getBounceObject()
    unless bounce.components.length
      window.location.hash = ""
      @$box.removeClass "animate"
      return

    duration = options.duration or bounce.duration
    duration *= 10 if @$slow.prop("checked") and not options.duration

    properties = []
    properties.push "animation-duration: #{duration}ms"
    properties.push("animation-iteration-count: infinite") if @$loop.prop("checked")

    css = """
    .box.animate {
      #{properties.join(";\n  ")};
    }
    #{bounce.getKeyframeCSS(name: "animation")}
    """

    @$style.text PrefixFree.prefixCSS(css, true)

    @$box.removeClass "animate"
    @$box[0].offsetWidth
    @$box.addClass "animate"

    @updateURL(bounce) unless options.updateURL is false
{'fraction_non_alphanumeric': 0.14314027747192248, 'fraction_numerical': 0.0030830213609337152, 'mean_word_length': 3.4182879377431905, 'pattern_counts': {'":': 14, '<': 7, '<?xml version=': 0, '>': 15, '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': '1839208', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1386, 'n_words': 315}