Skip to content

Commit

Permalink
Added iOS6 support. Added forceiOS option
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Stow committed Oct 8, 2012
1 parent 1b3fc99 commit ae9bd0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
15 changes: 12 additions & 3 deletions README.md
Expand Up @@ -3,15 +3,16 @@ Izilla jQuery Touch Menu Hover

### 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 etc

WebKit browsers on iOS are the only major mobile browsers that opens child ULs when tapped; every other platform just follows the link. With this plugin, the click/tap event is intercepted allowing the menu to be opened. Tapping the link again will follow it. Depending on the styles applied, tapping anywhere else on the document will try to close the menu.
WebKit browsers on iOS are the only major mobile browsers that (sometimes?) open child ULs when tapped; every other platform just follows the link. With this plugin, the click/tap event is intercepted allowing the menu to be opened. Tapping the link again will follow it. Depending on the styles applied, tapping anywhere else on the document will try to close the menu.

Additionally, no mobile browsers natively handle nested lists where the child ULs are wrapped in another element such as a DIV (for "mega menus"), so this plugin handles that, too.

The plugin has 2 default options which can be overwritten as required:
The plugin has 3 default options which can be overwritten as required:

```
'childTag': 'ul' // sets which element contains the child lists. Defaults to UL
'childTag': 'ul' // Sets which element contains the child lists. Defaults to UL. If not UL, forceiOS is set to true, regardless
'closeElement': '' // An additional selector that will close any open list when clicked/tapped. Doesn't work on iOS when childTag is set to UL
'forceiOS': false // iOS sometimes handles these menus fine so let it try
```

---
Expand All @@ -22,6 +23,14 @@ Basic

`$('parent-ul-selector').touchMenuHover();`

Force iOS to use the plugin

```
$('parent-ul-selector').touchMenuHover({
'forceiOS': true
});
```

Customising to use DIVs as the list wrapper and also bind a close-click event to #nav

```
Expand Down
13 changes: 7 additions & 6 deletions jquery.izilla.touchMenuHover.js
@@ -1,5 +1,5 @@
/*
* Izilla touchMenuHover jQuery plugin v1.1
* Izilla touchMenuHover jQuery plugin v1.2
* 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 etc
*
* Copyright (c) 2012 Izilla Partners Pty Ltd
Expand All @@ -13,7 +13,8 @@
$.fn.touchMenuHover = function(options) {
var settings = $.extend({
'childTag': 'ul',
'closeElement': ''
'closeElement': '',
'forceiOS': false
}, options);

var $a = this.find('a'),
Expand All @@ -23,17 +24,17 @@
openClass = 'touch-open',
closeStr = 'html';

if (settings['childTag'].toString().toLowerCase() != 'ul')
if (settings['childTag'].toString().toLowerCase() != 'ul' || settings['forceiOS'])
devices += ios;

devices = '\b' + devices + '\b';
devicesRX = new RegExp(devices, 'gi');

if ($a.length > 0 && devicesRX.test(navigator.userAgent)) {
$a.each(function(e) {
$a.each(function() {
var $siblings = $(this).parent('li').siblings().find('a');
$(this).click(function(e) {
e.stopPropagation();
$(this).parent('li').siblings().find('a').removeClass(openClass);
$siblings.removeClass(openClass);

if (!$(this).hasClass(openClass) && $(this).next(settings['childTag']).length > 0) {
e.preventDefault();
Expand Down
4 changes: 2 additions & 2 deletions jquery.izilla.touchMenuHover.min.js
@@ -1,5 +1,5 @@
/*
* Izilla touchMenuHover jQuery plugin v1.1
* Izilla touchMenuHover jQuery plugin v1.2
* 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 etc
*
* Copyright (c) 2012 Izilla Partners Pty Ltd
Expand All @@ -9,4 +9,4 @@
* Licensed under the MIT license
*
*/
;(function(a){a.fn.touchMenuHover=function(d){var f=a.extend({childTag:"ul",closeElement:""},d);var h=this.find("a"),c="3ds|android|bada|hpwos|iemobile|kindle fire|opera mini|opera mobi|playbook|silk",e="|ipad|ipod|iphone",i,g="touch-open",b="html";if(f.childTag.toString().toLowerCase()!="ul"){c+=e}c="\b"+c+"\b";i=new RegExp(c,"gi");if(h.length>0&&i.test(navigator.userAgent)){h.each(function(j){a(this).click(function(k){k.stopPropagation();a(this).parent("li").siblings().find("a").removeClass(g);if(!a(this).hasClass(g)&&a(this).next(f.childTag).length>0){k.preventDefault();a(this).addClass(g)}})});if(f.closeElement.length>1){b+=","+f.closeElement}a(b).click(function(){h.removeClass(g)})}return this}})(jQuery);
;(function(a){a.fn.touchMenuHover=function(d){var f=a.extend({childTag:"ul",closeElement:"",forceiOS:false},d);var h=this.find("a"),c="3ds|android|bada|hpwos|iemobile|kindle fire|opera mini|opera mobi|playbook|silk",e="|ipad|ipod|iphone",i,g="touch-open",b="html";if(f.childTag.toString().toLowerCase()!="ul"||f.forceiOS){c+=e}i=new RegExp(c,"gi");if(h.length>0&&i.test(navigator.userAgent)){h.each(function(){var j=a(this).parent("li").siblings().find("a");a(this).click(function(k){k.stopPropagation();j.removeClass(g);if(!a(this).hasClass(g)&&a(this).next(f.childTag).length>0){k.preventDefault();a(this).addClass(g)}})});if(f.closeElement.length>1){b+=","+f.closeElement}a(b).click(function(){h.removeClass(g)})}return this}})(jQuery);

0 comments on commit ae9bd0a

Please sign in to comment.