44 lines
1.1 KiB
CoffeeScript
44 lines
1.1 KiB
CoffeeScript
$(document).ready( ->
|
|
|
|
$('#nav-toggle').on('click', toggleNav)
|
|
if getCookie('navCollapsed') == 'true'
|
|
$('body').addClass('collapsed')
|
|
$('#mobile-nav-toggle').on('click', toggleMobileNav)
|
|
|
|
)
|
|
|
|
toggleNav = () ->
|
|
bodyElem = $('body')
|
|
if bodyElem.hasClass('collapsed')
|
|
bodyElem.removeClass('collapsed')
|
|
setCookie('navCollapsed', 'false')
|
|
else
|
|
bodyElem.addClass('collapsed')
|
|
setCookie('navCollapsed', 'true')
|
|
|
|
toggleMobileNav = () ->
|
|
navElem = $('#mobile-nav')
|
|
if navElem.hasClass('expanded')
|
|
navElem.removeClass('expanded')
|
|
else
|
|
navElem.addClass('expanded')
|
|
|
|
getCookie = (cName) ->
|
|
name = cName + '='
|
|
cDecoded = decodeURIComponent(document.cookie)
|
|
#to be careful
|
|
cArr = cDecoded.split('; ')
|
|
res = undefined
|
|
cArr.forEach (val) ->
|
|
if val.indexOf(name) == 0
|
|
res = val.substring(name.length)
|
|
return
|
|
res
|
|
|
|
setCookie = (cName, cValue, expDays = 30) ->
|
|
date = new Date
|
|
date.setTime date.getTime() + expDays * 24 * 60 * 60 * 1000
|
|
expires = 'expires=' + date.toUTCString()
|
|
document.cookie = cName + '=' + cValue + '; ' + expires + '; path=/'
|
|
return
|