Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Last active March 3, 2016 09:23
Show Gist options
  • Save andreasvirkus/aad124281289bcdf1a4e to your computer and use it in GitHub Desktop.
Save andreasvirkus/aad124281289bcdf1a4e to your computer and use it in GitHub Desktop.
/**
* If the screen width is greater than the RV breakpoint, then make the sub-menu toggle
* act as a regular link based on the <a> tag's title attribute, otherwise toggle
* the sub menu's visibility.
*
* This found use in a WP theme
*/
$subMenuToggle = domCache('.sub-menu-toggle'),
$subMenuToggle.on('click', function (event) {
if (jQuery(window).width() < 768) {
jQuery(this).find('.sub-menu').slideToggle();
}
});
if ($subMenuToggle.length) {
if (jQuery(window).width() >= 768) {
var $link = $subMenuToggle.find('> a');
$link.attr('href', '/' + $link.attr('title'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment