Created
May 16, 2016 14:18
-
-
Save jonesmac/f8a6585d14b0d190d39a8943731a40ec to your computer and use it in GitHub Desktop.
Revisions
-
jonesmac created this gist
May 16, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ function mobileMenuTouchHelper () { $(document).on('page:change', function () { var topLevelMenuItems = $('.menu__list > a'); menuTouches(topLevelMenuItems); $(window).on('orientationchange', function () { unbindTouches(topLevelMenuItems); menuTouches(topLevelMenuItems); }); }); } function unbindTouches (items) { $.each(items, function (index, elem) { $(elem).unbind('touchend'); }); } function menuTouches (items) { if ($(window).width() > 767) { $.each(items, function (index, elem) { $(elem).on('touchend', menuTouchHandler.bind(this, items)); }); } } function menuTouchHandler (items, e) { if ($(this).parent().hasClass('js-menu_hover')) { $(this).parent().removeClass('js-menu_hover'); } else { e.preventDefault(); $(this).parent().addClass('js-menu_hover'); removeOthers(this, items); } } function removeOthers (currentElem, items) { $.each(items, function (index, elem) { if ($(currentElem).text() !== $(elem).text()) { $(this).parent().removeClass('js-menu_hover'); } }); } module.exports = mobileMenuTouchHelper;