Skip to content

Commit

Permalink
Fixed closing menus on all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
stowball committed Apr 1, 2013
1 parent 972c2f2 commit fbacf01
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions jquery.izilla.touchMenuHover.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ <h2>Mega Menu UL &raquo; LI &raquo; DIV &raquo; UL &raquo; LI pattern <i>(with T
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
/*
* Izilla touchMenuHover jQuery plugin v1.5
* Izilla touchMenuHover jQuery plugin v1.6
* Allows ULs (or any element of your choice) that open on li:hover to open on tap/click on mobile platforms such as iOS, Android, WP7, WP8, BlackBerry, Bada, WebOS, 3DS & WiiU
*
* Copyright (c) 2013 Izilla Partners Pty Ltd
Expand All @@ -293,7 +293,7 @@ <h2>Mega Menu UL &raquo; LI &raquo; DIV &raquo; UL &raquo; LI pattern <i>(with T
*
* Licensed under the MIT license
*/
;(function(a){a.fn.touchMenuHover=function(e){var g=a.extend({childTag:"ul",closeElement:"",forceiOS:false,openClass:"tmh-open"},e);var h=a(this).find("a"),c="3ds|android|bada|bb10|hpwos|iemobile|kindle fire|opera mini|opera mobi|opera tablet|rim|silk|wiiu",f="|ipad|ipod|iphone",i,d="aria-haspopup",b="html";if(g.childTag.toString().toLowerCase()!=="ul"||g.forceiOS){c+=f}i=new RegExp(c,"gi");if(h.length>0&&i.test(navigator.userAgent)){h.each(function(){var l=a(this),k=l.parent("li"),j=k.siblings().find("a");if(l.next(g.childTag).length>0){k.attr(d,true)}l.click(function(n){var m=a(this);n.stopPropagation();j.removeClass(g.openClass);if(!m.hasClass(g.openClass)&&m.next(g.childTag).length>0){n.preventDefault();m.addClass(g.openClass)}})});if(g.closeElement.length>1){b+=","+g.closeElement}a(b).click(function(){h.removeClass(openClass)})}return this}})(jQuery);
;(function(a){a.fn.touchMenuHover=function(j){var f=a.extend({childTag:"ul",closeElement:"",forceiOS:false,openClass:"tmh-open"},j);var d=a(this).find("a"),i="3ds|android|bada|bb10|hpwos|iemobile|kindle fire|opera mini|opera mobi|opera tablet|rim|silk|wiiu",c="|ipad|ipod|iphone",b,g="aria-haspopup",e="html",h;if(f.childTag.toString().toLowerCase()!=="ul"||f.forceiOS){i+=c}b=new RegExp(i,"gi");if(d.length>0&&b.test(navigator.userAgent)){d.each(function(){var m=a(this),l=m.parent("li"),k=l.siblings().find("a");if(m.next(f.childTag).length>0){l.attr(g,true)}m.click(function(o){var n=a(this);o.stopPropagation();k.removeClass(f.openClass);if(!n.hasClass(f.openClass)&&n.next(f.childTag).length>0){o.preventDefault();n.addClass(f.openClass)}})});if(f.closeElement.length>1){e+=","+f.closeElement}h=a(e);if("ontouchstart" in window){h.css("cursor","pointer")}h.click(function(){d.removeClass(f.openClass)})}return this}})(jQuery);
</script>
<script>
$(document).ready(function() {
Expand Down
16 changes: 11 additions & 5 deletions jquery.izilla.touchMenuHover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Izilla touchMenuHover jQuery plugin v1.5
* Izilla touchMenuHover jQuery plugin v1.6
* Allows ULs (or any element of your choice) that open on li:hover to open on tap/click on mobile platforms such as iOS, Android, WP7, WP8, BlackBerry, Bada, WebOS, 3DS & WiiU
*
* Copyright (c) 2013 Izilla Partners Pty Ltd
Expand All @@ -22,7 +22,8 @@
ios = '|ipad|ipod|iphone',
devicesRX,
aria = 'aria-haspopup',
closeStr = 'html';
closeStr = 'html',
$close;

if (settings.childTag.toString().toLowerCase() !== 'ul' || settings.forceiOS)
devices += ios;
Expand Down Expand Up @@ -52,9 +53,14 @@

if (settings.closeElement.length > 1)
closeStr += ',' + settings.closeElement;

$(closeStr).click(function() {
$a.removeClass(openClass);

$close = $(closeStr);

if ('ontouchstart' in window)
$close.css('cursor', 'pointer');

$close.click(function() {
$a.removeClass(settings.openClass);
});
}
return this;
Expand Down
4 changes: 2 additions & 2 deletions jquery.izilla.touchMenuHover.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fbacf01

Please sign in to comment.