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.11.7 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.6 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.5 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.4 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.3 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.2 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.1.1 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.1 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.11.0 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.15.1 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.15 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.14 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.13 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.12 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.11 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.10 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.9 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.8.2 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.8.1 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee
nfg_ui-0.10.7 app/assets/javascripts/nfg_ui/collapsible_toggle.coffee