From 94b867d3d46ac443b1fa54d5f10b918477c86314 Mon Sep 17 00:00:00 2001
From: Jesse Hofmann-Smith <jesse@opensourcery.com>
Date: Tue, 17 Dec 2013 11:01:52 -0800
Subject: [PATCH] add support for touch devices when using modernizr.js

---
 megamenu.js | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/megamenu.js b/megamenu.js
index a270bcf..e3d40e9 100644
--- a/megamenu.js
+++ b/megamenu.js
@@ -187,6 +187,43 @@ Drupal.behaviors.megamenu = {
 
 	$(window).bind('resize', megamenu_sizer);
 	megamenu_sizetimer();
+
+  /**
+   * If the Modernizr library is available (with the "touch" option loaded),
+   * and the device supports touch, alter the megamenu behavior so clicking
+   * on top level links show/hide the menu, rather than using hover.
+   */
+  if (typeof(Modernizr) == 'object' && Modernizr.touch) {
+    $('.megamenu-parent').unbind('megamenu_open', megamenu_open_progress);
+    $('.megamenu-parent').unbind('megamenu_close', megamenu_close_progress);
+    $('.megamenu-parent-title').unbind('mouseover', megamenu_open);
+    $('.megamenu-parent-title').unbind('mouseout', megamenu_timer);
+    $('.megamenu-bin').unbind('mouseover', megamenu_open);
+    $('.megamenu-bin').unbind('mouseout', megamenu_timer);
+    $("body").unbind('click', megamenu_closeAll);
+    $("body").click(function(e) {
+      megaParents.siblings().find('megamenu-bin').css('top', hideOffset);
+    })
+    $('.megamenu-parent-title > a').click(function(e) {
+      // Don't follow the link.
+      e.stopPropagation();
+      e.preventDefault();
+      // Make top level links open/close the megamenu.
+      $hoverParent = $(this).parents('li.megamenu-parent');
+      if ($hoverParent.hasClass('hovering')) {
+        // This menu is already open. Close it.
+        $hoverParent.removeClass('hovering');
+        $hoverBin = $hoverParent.find('.megamenu-bin');
+        $hoverBin.css('top', hideOffset);
+      }
+      else {
+        $hoverParent.siblings().removeClass('hovering');
+        $hoverParent.siblings().find('.megamenu-bin').css('top', hideOffset);
+        $hoverParent.addClass('hovering');
+        $hoverParent.find('.megamenu-bin').css('top', 'auto');
+      }
+    });
+  }
 }
 }
 })(jQuery);
\ No newline at end of file
-- 
1.8.3.4 (Apple Git-47)

