Skip to content

Instantly share code, notes, and snippets.

@ingozoell
Last active December 20, 2017 15:08
Show Gist options
  • Save ingozoell/7dc7f37d6eb00e3a162420ea6df4c21f to your computer and use it in GitHub Desktop.
Save ingozoell/7dc7f37d6eb00e3a162420ea6df4c21f to your computer and use it in GitHub Desktop.
Drop-Down Navigation: Responsive and Touch-Friendly (moseover, hover) https://osvaldas.info/drop-down-navigation-responsive-and-touch-friendly
/*
By Osvaldas Valutis, www.osvaldas.info
Available for use under the MIT License
*/
;(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 );
/* WP */
$(function () {
$('.touch #navi .menu-item-has-children > a').not('.sub-menu a').doubleTapToGo();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment