Skip to content

Instantly share code, notes, and snippets.

@ramasilveyra
Last active August 29, 2015 14:16
Show Gist options
  • Save ramasilveyra/0f77e83f64f54437bbbc to your computer and use it in GitHub Desktop.
Save ramasilveyra/0f77e83f64f54437bbbc to your computer and use it in GitHub Desktop.
Drop-Down Navigation: Responsive and Touch-Friendly
/*
* 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));
@ramasilveyra
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment