<commit_before>class @Components.Collapse extends @Components.Base
  @autoInit: ->
    $('.component-collapse').each (i, el) => new @($(el))

  constructor: (@el) ->
    @breakpoints = {sm: 750, md: 1000}

    super

    @text           = $('.text', @el)
    @collapseToggle = $('.toggle-wrapper button', @el)

    @initModal()
    @text.dotdotdot watch: 'window'
    @onCollapseToggleClick()

  refresh: ->
    @closeCollapse()
    @fitText()

  initModal: ->
    @modalToggle  = $('> .inner > [data-toggle="modal"]', @el)
    @modalDismiss = $("[data-dismiss][data-target='#{@modalToggle.data('target')}']")
    @modal        = $(@modalToggle.data('target'))

    @modal.on 'shown.bs.modal', =>
      @modalDismiss.show()

    @modal.on 'hide.bs.modal', =>
      @modalDismiss.hide()

    @modalDismiss.on 'touchstart click', =>
      @modal.modal('hide')

  fitText: =>
    setTimeout =>
      @textCollapsedHeight = @computeTextCollapseHeight()
      @text.css height: @textCollapsedHeight
      @text.trigger('update')
    , 0

  computeTextCollapseHeight: ->
    @text.css 'height', 0

    collapse_or_modal_toggle =
      if @collapseToggle.is(':visible')
        @collapseToggle
      else
        @modalToggle

    diff = collapse_or_modal_toggle.offset().top - @text.offset().top - 30
    if diff < 160 then 160 else diff

  computeTextFullHeight: ->
    elClone = @el.clone()

    elClone.css
      'width':       @el.width()
      'margin-left': '-9999px'
      'position':    'fixed'

    $('.text', elClone).css
      'height':   'auto'
      'overflow': ''

    elClone.appendTo 'body'
    result = $('.text', elClone).height()
    elClone.remove()
    result

  openCollapse: ->
    return if @text.open
    @text.trigger('destroy')
    @text.css('height', @textCollapsedHeight) # Hack, 'cause .trigger('destroy') clean inline syle too
    @text.css 'overflow', 'hidden'
    @collapseToggle.velocity rotateX: '180deg', translateZ: '-1px'

    @text.velocity
      height: @computeTextFullHeight()
    ,
      complete: =>
        @text.open = true
        @text.css overflow: ''

  closeCollapse: ->
    return unless @text.open
    @collapseToggle.velocity rotateX: '0deg'
    @text.css 'overflow', 'hidden'

    @text.velocity
      height: @textCollapsedHeight
    ,
      complete: =>
        @text.dotdotdot watch: 'window'
        @text.open = false
        @text.css 'overflow', ''

  onCollapseToggleClick: ->
    @collapseToggle.on 'click', =>
      return if @text.hasClass 'velocity-animating'
      if @text.open then @closeCollapse() else @openCollapse()

  onResponsiveSizeChange: ->
    @refresh()
<commit_msg>Fix collapse arrow on iPad<commit_after>class @Components.Collapse extends @Components.Base
  @autoInit: ->
    $('.component-collapse').each (i, el) => new @($(el))

  constructor: (@el) ->
    @breakpoints = {sm: 750, md: 1000}

    super

    @text           = $('.text', @el)
    @collapseToggle = $('.toggle-wrapper button', @el)

    @initModal()
    @text.dotdotdot watch: 'window'
    @onCollapseToggleClick()

  refresh: ->
    @closeCollapse()
    @fitText()

  initModal: ->
    @modalToggle  = $('> .inner > [data-toggle="modal"]', @el)
    @modalDismiss = $("[data-dismiss][data-target='#{@modalToggle.data('target')}']")
    @modal        = $(@modalToggle.data('target'))

    @modal.on 'shown.bs.modal', =>
      @modalDismiss.show()

    @modal.on 'hide.bs.modal', =>
      @modalDismiss.hide()

    @modalDismiss.on 'touchstart click', =>
      @modal.modal('hide')

  fitText: =>
    setTimeout =>
      @textCollapsedHeight = @computeTextCollapseHeight()
      @text.css height: @textCollapsedHeight
      @text.trigger('update')
    , 0

  computeTextCollapseHeight: ->
    @text.css 'height', 0

    collapse_or_modal_toggle =
      if @collapseToggle.is(':visible')
        @collapseToggle
      else
        @modalToggle

    diff = collapse_or_modal_toggle.offset().top - @text.offset().top - 30
    if diff < 160 then 160 else diff

  computeTextFullHeight: ->
    elClone = @el.clone()

    elClone.css
      'width':       @el.width()
      'margin-left': '-9999px'
      'position':    'fixed'

    $('.text', elClone).css
      'height':   'auto'
      'overflow': ''

    elClone.appendTo 'body'
    result = $('.text', elClone).height()
    elClone.remove()
    result

  openCollapse: ->
    return if @text.open
    @text.trigger('destroy')
    @text.css('height', @textCollapsedHeight) # Hack, 'cause .trigger('destroy') clean inline syle too
    @text.css 'overflow', 'hidden'
    @collapseToggle.velocity rotateX: '180deg', translateZ: '-1px'

    @text.velocity
      height: @computeTextFullHeight()
    ,
      complete: =>
        @text.open = true
        @text.css overflow: ''

  closeCollapse: ->
    return unless @text.open
    @collapseToggle.velocity rotateX: '0deg', translateZ: '0px'
    @text.css 'overflow', 'hidden'

    @text.velocity
      height: @textCollapsedHeight
    ,
      complete: =>
        @text.dotdotdot watch: 'window'
        @text.open = false
        @text.css 'overflow', ''

  onCollapseToggleClick: ->
    @collapseToggle.on 'click', =>
      return if @text.hasClass 'velocity-animating'
      if @text.open then @closeCollapse() else @openCollapse()

  onResponsiveSizeChange: ->
    @refresh()

{'fraction_non_alphanumeric': 0.16108392924350773, 'fraction_numerical': 0.009973654497553632, 'mean_word_length': 2.7403237156931737, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '2893146', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1693, 'n_words': 346}