Created
December 7, 2012 07:46
-
-
Save arielsalminen/4231549 to your computer and use it in GitHub Desktop.
This file contains 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
// Variables | |
var hasTouch = false, | |
ua = navigator.userAgent, | |
docEl = document.documentElement; | |
// Clear html classes and add "js" class | |
docEl.className = ""; | |
docEl.className += " js"; | |
// Determine if the device supports touch | |
if (("ontouchstart" in window) || window.DocumentTouch && document instanceof DocumentTouch) { | |
docEl.className += " touch"; | |
hasTouch = true; | |
} | |
// Using UA detection is the only way to solve font-face problems on | |
// devices which report that they support it, but really don’t. | |
if (ua.match(/(Android (2.0|2.1))|(Symbian)|(Opera (Mini|Mobi))|(w(eb)?OSBrowser)|(UCWEB)|(Windows Phone)|(XBLWP)|(ZuneWP)/)) { | |
docEl.className += " nofontface"; | |
} | |
// Test element | |
var testEl = …; | |
// The touchstart event fires before the mousedown event, and therefore | |
// we can wipe the mousedown event handler before it’s ever executed | |
// http://www.quirksmode.org/blog/archives/2010/02/do_we_need_touc.html | |
testEl.onmousedown = function () { | |
// initialize mouse interface | |
} | |
testEl.ontouchstart = function () { | |
testEl.onmousedown = null; | |
// initialize touch interface | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment