Skip to content

Instantly share code, notes, and snippets.

@michelarteta
Created February 13, 2020 21:46
Show Gist options
  • Save michelarteta/b32c13e6973eb6a29b26ce31134b906f to your computer and use it in GitHub Desktop.
Save michelarteta/b32c13e6973eb6a29b26ce31134b906f to your computer and use it in GitHub Desktop.
Code Sample
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