<commit_before>
class UIDemo.Views.TransitionView extends Backbone.View

  transitionRemoveClass: (className, $el = @$el) ->
    p = @_transitionPromise($el)
    @_delay(=> $el.removeClass className).then -> p

  transitionAddClass: (className, $el = @$el) ->
    p = @_transitionPromise($el)
    @_delay(=> $el.addClass className).then -> p

  _transitionPromise: ($el) ->
    return `when`.resolve(this) if $('body').is('.no-transitions')

    defer = `when`.defer()
    transitionEvent = @_whichTransitionEvent()
    transitionEndEventHandler = =>
      $el[0].removeEventListener(
        transitionEvent
        transitionEndEventHandler
        false
      )
      defer.resolve(this)

    $el[0].addEventListener(
      transitionEvent
      transitionEndEventHandler
      false
    )
    defer.promise

  _whichTransitionEvent: ->
    el = document.createElement('fakeelement')
    transitions =
      'transition': 'transitionend'
      'OTransition': 'oTransitionEnd'
      'MozTransition': 'transitionend'
      'WebkitTransition': 'webkitTransitionEnd'
    return event for property, event of transitions when el.style[property]?

  _delay: (code, time = 0) ->
    time = 0 if $('body').is('.no-transitions')
    defer = `when`.defer()
    setTimeout(
      -> `when(code())`.then (result) => defer.resolve(result)
      time
    )
    defer.promise<commit_msg>Remove asynchronous working if transitions are disabled<commit_after>
class UIDemo.Views.TransitionView extends Backbone.View

  transitionRemoveClass: (className, $el = @$el) ->
    p = @_transitionPromise($el)
    @_delay(=> $el.removeClass className).then -> p

  transitionAddClass: (className, $el = @$el) ->
    p = @_transitionPromise($el)
    @_delay(=> $el.addClass className).then -> p

  _transitionPromise: ($el) ->
    return `when`.resolve(this) if $('body').is('.no-transitions')

    defer = `when`.defer()
    transitionEvent = @_whichTransitionEvent()
    transitionEndEventHandler = =>
      $el[0].removeEventListener(
        transitionEvent
        transitionEndEventHandler
        false
      )
      defer.resolve(this)

    $el[0].addEventListener(
      transitionEvent
      transitionEndEventHandler
      false
    )
    defer.promise

  _whichTransitionEvent: ->
    el = document.createElement('fakeelement')
    transitions =
      'transition': 'transitionend'
      'OTransition': 'oTransitionEnd'
      'MozTransition': 'transitionend'
      'WebkitTransition': 'webkitTransitionEnd'
    return event for property, event of transitions when el.style[property]?

  _delay: (code, time = 0) ->
    if $('body').is('.no-transitions')
      result = code()
      `when`.resolve(result)

    defer = `when`.defer()
    setTimeout(
      -> `when(code())`.then (result) => defer.resolve(result)
      time
    )
    defer.promise
{'fraction_non_alphanumeric': 0.1351923755735969, 'fraction_numerical': 0.0024708789269325803, 'mean_word_length': 3.1676470588235293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '1217431', 'n_tokens_mistral': 839, 'n_tokens_neox': 812, 'n_words': 172}