aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts/main_menu.coffee
blob: 9357cff34da082836a857d50c25876f3c36b9fef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$(document).on 'ready page:load', ->

  link = []
  ptitleCont = ""
  $(document).on 'page:before-change', ->
    link = []
    ptitleCont = ""

  $el = $('#main_nav')
    # Opening/closing left-side menu
  $el.find('.openMenu').on 'click', (e) ->
    $(this).parent().addClass 'open'

  $el.find('.closeMenu').on 'click', (e) ->
    $(this).closest('.nav-menu').removeClass 'open'

  # Opening menu panel according to current url
  selectedItem = $el.find('.active')
  selectedItem.closest('.panel-collapse').addClass 'in'
  selectedItem.closest('.panel-title').children('a').attr('aria-expanded') == true

  # Sticky content

  # Sticky behavior
  $(document).on 'scroll', ->
    limit = 51

    if $(window).scrollTop() >= limit
      if ($('.page-action .small').length > 0)
        data = $('.page-action .small')[0].innerHTML

      if ($(".page-title").length > 0)
        ptitleCont = $(".page-title").html()

      stickyContent = '<div class="sticky-content">'
      stickyContent += '<div class="sticky-ptitle">' + ptitleCont + '</div>'
      stickyContent += '<div class="sticky-paction"><div class="small">' + data + '</div></div>'
      stickyContent += '</div>'
      $('#main_nav').addClass 'sticky'

      if $('#menu_top').find('.sticky-content').length == 0
        if ptitleCont.length > 0
          $('#menu_top').children('.menu-content').after(stickyContent)
        if link.length == 0
          link = $('.page-action .small').next()
        $('.sticky-paction .small').after(link)

    else
      $('#main_nav').removeClass 'sticky'

      if $('#menu_top').find('.sticky-content').length > 0
        $('.page-action .small').after(link)
        $('.sticky-content').remove()