Sha256: 2712340c964e8509a1742befd835192c9d900ebbc4f8016a4aedd39a669604a5

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

$ ->

  $body = $('body')

  # init
  $('.dropdown').each ->
    unless $(@).attr('aria-pressed') == 'true'
      $(@).attr('aria-pressed', 'false')
      $(@).children('ul').attr
        'aria-expanded': 'false'
        'aria-hidden': 'true'
        'role': 'menu'

  $body.on 'dropdown', (e) ->
    $target = $(e.target)
    $('.dropdown').not($target).attr('aria-pressed', 'false')
    $('.dropdown').children('ul').attr
      'aria-expanded': 'false'
      'aria-hidden': 'true'
    if $target.attr('aria-pressed') == 'true'
      dropdownState = 'false'
    else
      dropdownState = 'true'
    $target.attr('aria-pressed', dropdownState)
    $target.children('ul').attr
      'aria-expanded': !dropdownState
      'aria-hidden': dropdownState

  $body.on 'click', '.dropdown', (e) ->
    $target = $(e.currentTarget)
    if not ($target.is('a') || $target.is('button'))
      e.stopPropagation()
    if !$target.hasClass('focused')
      $target.trigger('dropdown')
    else
      $target.removeClass('focused')

  $body.on 'click', ->
    $dropdown = $('.dropdown[aria-pressed="true"]')
    if $dropdown.length
      $dropdown.attr('aria-pressed', 'false')

  $body.on 'focusout', '.dropdown li:last-child a,
                        .dropdown li:last-child button', (e) ->
    $('.dropdown[aria-pressed="true"]').attr('aria-pressed', 'false')

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
groundworkcss-2.3.7 app/assets/javascripts/groundworkcss/components/menus.coffee
groundworkcss-2.3.6 app/assets/javascripts/groundworkcss/components/menus.coffee
groundworkcss-2.3.5 app/assets/javascripts/groundworkcss/components/menus.coffee
groundworkcss-2.3.4 app/assets/javascripts/groundworkcss/components/menus.coffee
groundworkcss-2.3.3 app/assets/javascripts/groundworkcss/components/menus.coffee
groundworkcss-2.3.2 app/assets/javascripts/groundworkcss/components/menus.coffee
groundworkcss-2.3.1 app/assets/javascripts/groundworkcss/components/menus.coffee
groundworkcss-2.2.1 app/assets/javascripts/groundworkcss/components/menus.coffee