Sha256: c1c9c41545eea641f7b5c2c6ca2b6cb815a9604d1b86964c93845a379aa9ea54

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

# -----------------------------------------------------------------------------
# Author: Alexander Kravets <alex@slatestudio.com>,
#         Slate Studio (http://www.slatestudio.com)
# -----------------------------------------------------------------------------
# VIEW TABS
# -----------------------------------------------------------------------------
# Example:
#
#   viewTabs:
#     editor: 'Page'
#     settings: 'Options'
#   formSchema:
#     editor:
#       type: 'group'
#       inputs:
#         ...
#     settings:
#       type: 'group'
#       inputs:
#         ...
# -----------------------------------------------------------------------------
@viewTabs =
  # PRIVATE ===================================================================
  _build_tabs: ->
    @$title.addClass 'title-with-tabs'

    @_create_tabs()
    @_activate_tab(0)

  _create_tabs: ->
    @tabGroups = []
    groupsHash      = {}

    for g in @form.groups
      groupsHash[g.klassName] = g

    @$tabs =$ "<aside class='header-tabs'></aside>"
    @$title.after @$tabs

    for tab_id, tab_title of @config.viewTabs
      @tabGroups.push(groupsHash[tab_id])
      @$tabs.append(@_create_button(tab_title))

  _create_button: (name) ->
    $tabButton =$ "<a href='#'>#{ name }</a>"
    $tabButton.on 'click', (e) =>
      @_on_tab_click($(e.currentTarget))
      e.preventDefault()
    return $tabButton

  _on_tab_click: ($link) ->
    index = @$tabs.children().index($link)
    @_activate_tab(index)

  _activate_tab: (index) ->
    @$tabs.children().removeClass('active')
    @$tabs.find(":nth-child(#{ index + 1 })").addClass('active')

    for g in @tabGroups
      g.$el.hide()

    @tabGroups[index].$el.show()

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
chr-0.5.7 app/assets/javascripts/chr/view_tabs.coffee
chr-0.5.6 app/assets/javascripts/chr/view_tabs.coffee
chr-0.5.5 app/assets/javascripts/chr/view_tabs.coffee
chr-0.5.4 app/assets/javascripts/chr/view_tabs.coffee
chr-0.5.3 app/assets/javascripts/chr/view_tabs.coffee