Created
February 13, 2020 21:46
-
-
Save michelarteta/b32c13e6973eb6a29b26ce31134b906f to your computer and use it in GitHub Desktop.
Code Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isTouchDevice } from './detect-touch-device'; | |
const $win = $(window); | |
const $doc = $(document); | |
const $navDropdownParent = $('.nav .has-dropdown'); | |
/** | |
* Show nav dropdowns for mobile devices | |
* @param { Object } $clickedElement DOM Element - clicked element | |
* @return { Void } | |
*/ | |
function showNavDropdownsForMobile(clickedElement) { | |
var expanded = $(clickedElement).find('span').attr('aria-expanded'); | |
if(expanded == "true") { | |
$(clickedElement).find('span').attr('aria-expanded', false); | |
$(clickedElement) | |
.removeClass('is-active') | |
.next('.nav__dropdown') | |
.slideUp() | |
} else { | |
$(clickedElement) | |
.closest('li') | |
.siblings() | |
.find('span') | |
.attr('aria-expanded', false); | |
$(clickedElement).find('span').attr('aria-expanded', true); | |
$(clickedElement) | |
.addClass('is-active') | |
.next('.nav__dropdown') | |
.slideDown() | |
.closest('li') | |
.siblings() | |
.find('.is-active') | |
.removeClass('is-active') | |
.next('.nav__dropdown') | |
.slideUp(); | |
$(clickedElement) | |
.closest('.nav__dropdown-col') | |
.siblings() | |
.find('.is-active') | |
.removeClass('is-active') | |
.next('.nav__dropdown') | |
.slideUp(); | |
} | |
} | |
/** | |
* Hide nav dropdowns for mobile devices | |
* @param { Object } event Event on page | |
* @return { Void } | |
*/ | |
function hideNavDropdownsForMobile(event) { | |
const $element = $(event.target); | |
if (!$element.parents().hasClass('nav')) { | |
$navDropdownParent.find('.nav__dropdown[style="display: block;"]').slideUp(); | |
$navDropdownParent | |
.removeClass('is-active') | |
.find('.is-active') | |
.removeClass('is-active'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment