Created
July 11, 2013 20:23
-
-
Save adesignl/5978896 to your computer and use it in GitHub Desktop.
Double Tap.js
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 characters
$(function(){ | |
// Prevent click event on first tap on mobile devices | |
var parent = $('li.hs-item-has-children '); | |
$(parent).doubleTapToGo(); | |
}); |
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 characters
/* | |
AUTHOR: Osvaldas Valutis, www.osvaldas.info | |
$( '#nav li:has(ul)' ).doubleTapToGo(); | |
*/ | |
;(function( $, window, document, undefined ) | |
{ | |
$.fn.doubleTapToGo = function( params ) | |
{ | |
if( !( 'ontouchstart' in window ) && | |
!navigator.msMaxTouchPoints && | |
!navigator.userAgent.toLowerCase().match( /windows phone os 7/i ) ) return false; | |
this.each( function() | |
{ | |
var curItem = false; | |
$( this ).on( 'click', function( e ) | |
{ | |
var item = $( this ); | |
if( item[ 0 ] != curItem[ 0 ] ) | |
{ | |
e.preventDefault(); | |
curItem = item; | |
} | |
}); | |
$( document ).on( 'click touchstart MSPointerDown', function( e ) | |
{ | |
var resetItem = true, | |
parents = $( e.target ).parents(); | |
for( var i = 0; i < parents.length; i++ ) | |
if( parents[ i ] == curItem[ 0 ] ) | |
resetItem = false; | |
if( resetItem ) | |
curItem = false; | |
}); | |
}); | |
return this; | |
}; | |
})( jQuery, window, document ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment