Skip to content

Instantly share code, notes, and snippets.

View joonassandell's full-sized avatar

Joonas Sandell joonassandell

View GitHub Profile
@joonassandell
joonassandell / JS: Detect touch
Last active September 13, 2016 14:46
Detect touch support
/**
* Detect "touch" support and act accordingly.
* Adds `touch` class and assumes there is `no-touch` class added in <html> element.
*/
let hasTouch = false;
const docEl = document.documentElement;
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch || navigator.msMaxTouchPoints) {
docEl.className = docEl.className.replace(/(^|\s)no-touch(\s|$)/, ' touch ');
hasTouch = true;
@joonassandell
joonassandell / Regex: Remove comments
Last active August 29, 2015 14:14
Remove single and multiline comments
(^\/\/.*)|(\s+\/\/.*)|((\/\*)(.|\n)+?(\*\/))