Sha256: ef0df0f1e235bb83ca5de441bb2d603df3310e29fb0e4f380fb7f657d67251b3

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

Tao.Table.Expandable = ->

  @attribute 'expandable', type: 'boolean'

  _initExpandable: ->
    @on 'click', 'tbody > tr.expandable', (e) =>
      return if !@expandable || $(e.target).is('a, input')
      $row = $ e.currentTarget
      if $row.hasClass 'expanded'
        @collapseRow $row
        @namespacedTrigger 'expandRow', $row
      else
        @expandRow $row
        @namespacedTrigger 'collapseRow', $row
      null

  expandRow: (row) ->
    $row = $ row
    return @ if $row.is('.disabled, .hidden, .expanded, .expanding')

    $panel = $row.next('.expandable-panel')
    return @ unless $panel.length > 0
    $panelWrapper = $panel.find('> td > div:first')

    $panel.show()
    $panel[0].offsetHeight # force reflow
    $panelWrapper.one 'transitionend', (e) ->
      $row.removeClass 'expanding'

    $row.addClass 'expanded expanding'
    $panel.addClass 'expanded'
    $panelWrapper.css 'height', $panelWrapper[0].scrollHeight
    @_loadRemotePanel $panelWrapper
    @

  collapseRow: (row) ->
    $row = $ row
    return @ if $row.is('.disabled, .hidden, :not(.expanded), .collapsing')

    $panel = $row.next('.expandable-panel')
    return @ unless $panel.length > 0
    $panelWrapper = $panel.find('> td > div:first')

    $panelWrapper.one 'transitionend', (e) ->
      $row.removeClass 'collapsing'
      $panel.hide()

    $row.removeClass 'expanded'
      .addClass 'collapsing'
    $panel.removeClass 'expanded'
    $panelWrapper.css 'height', 0
    @

  _loadRemotePanel: ($panelWrapper) ->
    return unless $panelWrapper.is('[data-url]')
    $.ajax
      url: $panelWrapper.data('url')
      method: 'get'
      dataType: 'script'
    .done ->
      $panelWrapper.removeAttr 'data-url'
      $panelWrapper.css 'height', $panelWrapper[0].scrollHeight

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tao_ui-0.3.4 lib/assets/javascripts/tao/ui/table/expandable.coffee
tao_ui-0.3.3 lib/assets/javascripts/tao/ui/table/expandable.coffee
tao_ui-0.3.2 lib/assets/javascripts/tao/ui/table/expandable.coffee