Skip to content

Commit

Permalink
Merge pull request #58 from indyplanets/touch-bug
Browse files Browse the repository at this point in the history
Adds timeout flags to aid in stopping double touch/click events for some...
  • Loading branch information
mrjasonweaver committed Aug 11, 2013
2 parents 43dc9ae + e2c52ea commit 1e78df7
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 36 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ Initialize
* * *
### Changelog

#### v.1.1 : August 11th, 2013
* Adds timeout flags to aid in stopping double touch/click events for some Android browsers

#### v.1.0.1 : August 5th, 2013
* Fixes hover out bug if user clicks arrow on large screens

Expand Down
35 changes: 22 additions & 13 deletions coffeescripts/jquery.flexnav.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###
FlexNav.js 1.0
FlexNav.js 1.1
Copyright 2013, Jason Weaver http://jasonweaver.name
Created by Jason Weaver http://jasonweaver.name
Released under http://unlicense.org/
//
Expand All @@ -20,6 +20,7 @@ $.fn.flexNav = (options) ->
options

$nav = $(@)
flag = false

# Set some classes in the markup
$nav.addClass('with-js')
Expand Down Expand Up @@ -109,7 +110,11 @@ $.fn.flexNav = (options) ->
bs = settings['buttonSelector']
$btnParent = if ($(@).is(bs)) then $(@) else $(@).parent(bs)
$thisNav = $btnParent.data('navEl')
$thisNav.toggleClass('show')
if flag is false
flag = true
setTimeout( -> flag = false
100)
$thisNav.toggleClass('show')
)

# Toggle for sub-menus
Expand All @@ -118,16 +123,20 @@ $.fn.flexNav = (options) ->
e.stopPropagation()
$sub = $(@).parent('.item-with-ul').find('>ul')
$touchButton = $(@).parent('.item-with-ul').find('>span.touch-button')
# remove class of show from all elements that are not current
if $nav.hasClass('lg-screen') is true
$(@).parent('.item-with-ul').siblings().find('ul.show').removeClass('show').hide()
# add class of show to current
if $sub.hasClass('show') is true
$sub.removeClass('show').slideUp(settings.animationSpeed)
$touchButton.removeClass('active')
else if $sub.hasClass('show') is false
$sub.addClass('show').slideDown(settings.animationSpeed)
$touchButton.addClass('active')
if flag is false
flag = true
setTimeout( -> flag = false
100)
# remove class of show from all elements that are not current
if $nav.hasClass('lg-screen') is true
$(@).parent('.item-with-ul').siblings().find('ul.show').removeClass('show').hide()
# add class of show to current
if $sub.hasClass('show') is true
$sub.removeClass('show').slideUp(settings.animationSpeed)
$touchButton.removeClass('active')
else if $sub.hasClass('show') is false
$sub.addClass('show').slideDown(settings.animationSpeed)
$touchButton.addClass('active')
)

# Sub ul's should have a class of 'open' if an element has focus
Expand Down
7 changes: 2 additions & 5 deletions css/flexnav.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
top: 0;
right: auto;
max-width: 1080px; }
.oldie .flexnav li {
.oldie .flexnav li {
position: relative;
list-style: none;
float: left;
Expand All @@ -177,7 +177,7 @@
border-bottom: none;
overflow: visible; }
.oldie .flexnav li > ul {
background:#acaca1;
background: #acaca1;
position: absolute;
top: auto;
left: 0;
Expand All @@ -186,9 +186,6 @@
overflow: visible; }
.oldie .flexnav li ul li ul {
top: 0; }
.oldie .flexnav li ul li {
padding-bottom: 0;
margin-bottom: 0;}
.oldie .flexnav li ul li a {
border-bottom: none; }
.oldie .flexnav li ul.open {
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h2>Options</h2>
<div class="article-wrap">
<div class="block"><img src="http://jasonweaver.name/img/devices.png" alt="devices" class="img-devices"></div>
<div class="block">
<h2>Get FlexNav v1.0.1</h2>
<h2>Get FlexNav v1.1</h2>
<p><a href="https://github.com/indyplanets/flexnav" class="callout">Download on GitHub &rarr;</a></p>
</div>
<div class="block">
Expand Down
39 changes: 26 additions & 13 deletions js/jquery.flexnav.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
FlexNav.js 1.0
FlexNav.js 1.1
Copyright 2013, Jason Weaver http://jasonweaver.name
Created by Jason Weaver http://jasonweaver.name
Released under http://unlicense.org/
//
Expand All @@ -14,7 +14,7 @@
$ = jQuery;

$.fn.flexNav = function(options) {
var $nav, breakpoint, resetMenu, resizer, selector, settings, showMenu;
var $nav, breakpoint, flag, resetMenu, resizer, selector, settings, showMenu;
settings = $.extend({
'animationSpeed': 250,
'transitionOpacity': true,
Expand All @@ -23,6 +23,7 @@
'hoverIntentTimeout': 150
}, options);
$nav = $(this);
flag = false;
$nav.addClass('with-js');
if (settings.transitionOpacity === true) {
$nav.addClass('opacity');
Expand Down Expand Up @@ -94,23 +95,35 @@
bs = settings['buttonSelector'];
$btnParent = $(this).is(bs) ? $(this) : $(this).parent(bs);
$thisNav = $btnParent.data('navEl');
return $thisNav.toggleClass('show');
if (flag === false) {
flag = true;
setTimeout(function() {
return flag = false;
}, 100);
return $thisNav.toggleClass('show');
}
});
$('.touch-button').on('touchstart click', function(e) {
var $sub, $touchButton;
e.preventDefault();
e.stopPropagation();
$sub = $(this).parent('.item-with-ul').find('>ul');
$touchButton = $(this).parent('.item-with-ul').find('>span.touch-button');
if ($nav.hasClass('lg-screen') === true) {
$(this).parent('.item-with-ul').siblings().find('ul.show').removeClass('show').hide();
}
if ($sub.hasClass('show') === true) {
$sub.removeClass('show').slideUp(settings.animationSpeed);
return $touchButton.removeClass('active');
} else if ($sub.hasClass('show') === false) {
$sub.addClass('show').slideDown(settings.animationSpeed);
return $touchButton.addClass('active');
if (flag === false) {
flag = true;
setTimeout(function() {
return flag = false;
}, 100);
if ($nav.hasClass('lg-screen') === true) {
$(this).parent('.item-with-ul').siblings().find('ul.show').removeClass('show').hide();
}
if ($sub.hasClass('show') === true) {
$sub.removeClass('show').slideUp(settings.animationSpeed);
return $touchButton.removeClass('active');
} else if ($sub.hasClass('show') === false) {
$sub.addClass('show').slideDown(settings.animationSpeed);
return $touchButton.addClass('active');
}
}
});
$nav.find('.item-with-ul *').focus(function() {
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.flexnav.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flexnav",
"version": "0.8.0",
"version": "1.1",
"repository": "https://github.com/indyplanets/flexnav",
"license": "http://unlicense.org/",
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion single-page-pattern.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h2>Section 5</h2>
<div class="article-wrap">
<div class="block"><img src="http://jasonweaver.name/img/devices.png" alt="devices" class="img-devices"></div>
<div class="block">
<h2>Get FlexNav v1.0.1</h2>
<h2>Get FlexNav v1.1</h2>
<p><a href="https://github.com/indyplanets/flexnav" class="callout">Download on GitHub &rarr;</a></p>
</div>
<div class="block">
Expand Down

0 comments on commit 1e78df7

Please sign in to comment.