Sha256: cb3a189f4b53e79effc2ce8d795c62aa7681273e2e79aa5b42d423fa079a0481

Contents?: true

Size: 1.38 KB

Versions: 42

Compression:

Stored size: 1.38 KB

Contents

class NfgUi.CollapsibleToggle
  constructor: (@el) ->
    @target = @collapseTarget()
    @iconBase = 'fa'
    @collapseIconClass = "fa-#{@el.data 'collapsed-icon'}"
    @collapsedIconClass = "fa-#{@el.data 'collapse-icon'}"

    @initialize()

    @el.click (e) =>
      @swapIcon()

  initialize: ->
    if @target.hasClass 'show'
      @el
      .find ".#{@collapseIconClass}"
      .removeClass @collapseIconClass
      .addClass @collapsedIconClass
    else
      @el
        .find ".#{@collapsedIconClass}"
        .removeClass @collapsedIconClass
        .addClass @collapseIconClass

  collapseTarget: ->
    if @el.is('a') then return $(@el.attr 'href')
    if @el.is('button') then return $(@el.data 'target')

  swapIcon: ->
    @target.on 'show.bs.collapse', (e) =>
      @el
        .find ".#{@collapseIconClass}"
        .removeClass @collapseIconClass
        .addClass @collapsedIconClass

    @target.on 'hide.bs.collapse', (e) =>
      @el
        .find ".#{@collapsedIconClass}"
        .removeClass @collapsedIconClass
        .addClass @collapseIconClass

initNfgUiCollapsibleToggle = () ->
  el = $("[data-toggle='collapse'][data-collapse-icon][data-collapsed-icon]")

  return unless el.length
  el.each ->
    inst = new NfgUi.CollapsibleToggle $(@)

if NfgUi.turbolinks
  $(document).on('turbolinks:load', initNfgUiCollapsibleToggle)
else
  $(document).ready(initNfgUiCollapsibleToggle)

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
nfg_ui-0.12.2 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.12.1 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.12.0.5 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.12.0.4 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.12.0.3 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.12.0.2 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.12.0.1 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.12.0 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.18 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.17 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.16 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.15 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.14 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.13 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.12 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.11.1 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.11 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.10 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.9 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.8 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee