Last active
August 29, 2015 14:16
-
-
Save ramasilveyra/0f77e83f64f54437bbbc to your computer and use it in GitHub Desktop.
Drop-Down Navigation: Responsive and Touch-Friendly
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
/* | |
* By Osvaldas Valutis, www.osvaldas.info | |
* Available for use under the MIT License | |
* | |
* With minor syntax improvements to approve JsLint. (Ramiro Silveyra d'Avila - https://ramasilveyra.com.ar/) | |
*/ | |
(function ($, window, document) { | |
'use strict'; | |
$.fn.doubleTapToGo = function () { | |
if (typeof (window.ontouchstart) === 'undefined' && !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(), | |
i; | |
for (i = 0; i < parents.length; i + 1) { | |
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
This is my version of doubletaptogo.js by Osvaldas Valutis (http://osvaldas.info/drop-down-navigation-responsive-and-touch-friendly) with only minor syntax improvements to approve JSLint.