Created
August 29, 2014 19:52
-
-
Save rafaelcardoso/cffbfbd2c055fcc9b67d to your computer and use it in GitHub Desktop.
touchtest
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
mod = 'modernizr'; | |
injectElementWithStyles = function( rule, callback, nodes, testnames ) { | |
var style, ret, node, docOverflow, | |
div = document.createElement('div'), | |
body = document.body, | |
fakeBody = body || document.createElement('body'); | |
if ( parseInt(nodes, 10) ) { | |
while ( nodes-- ) { | |
node = document.createElement('div'); | |
node.id = testnames ? testnames[nodes] : mod + (nodes + 1); | |
div.appendChild(node); | |
} | |
} | |
style = ['­','<style id="s', mod, '">', rule, '</style>'].join(''); | |
div.id = mod; | |
(body ? div : fakeBody).innerHTML += style; | |
fakeBody.appendChild(div); | |
if ( !body ) { | |
fakeBody.style.background = ''; | |
fakeBody.style.overflow = 'hidden'; | |
docOverflow = docElement.style.overflow; | |
docElement.style.overflow = 'hidden'; | |
docElement.appendChild(fakeBody); | |
} | |
ret = callback(div, rule); | |
if ( !body ) { | |
fakeBody.parentNode.removeChild(fakeBody); | |
docElement.style.overflow = docOverflow; | |
} else { | |
div.parentNode.removeChild(div); | |
} | |
return !!ret; | |
} | |
var bool; | |
prefixes = ' -webkit- -moz- -o- -ms- '.split(' '); | |
if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) { | |
bool = true; | |
} else { | |
var query = ['@media (',prefixes.join('touch-enabled),('),'heartz',')','{#modernizr{top:9px;position:absolute}}'].join(''); | |
injectElementWithStyles(query, function( node ) { | |
bool = node.offsetTop === 9; | |
}); | |
} | |
console.log('bool', bool); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment