参考: https://github.com/masakihongo/searchUA多謝 ゆるいタッチ判定もつけてみた しかしだいぶ原型から離れた
addUaClass = ->
classUa = []
nameUa = window.navigator.userAgent.toLowerCase()
isiPhone = nameUa.indexOf("iphone") > -1
isiPod = nameUa.indexOf("ipod") > -1
isiPad = nameUa.indexOf("ipad") > -1
isiOS = isiPhone or isiPod or isiPad
isAndroid = nameUa.indexOf("android") > -1
if isiOS
classUa.push "iOS"
verArray = /(os)\s([0-9]{1,})([\_0-9]{1,})/.exec(nameUa)
ver = parseInt(verArray[2].replace(/\./g, ""), 10) if verArray
classUa.push "iOS_#{ver}" if ver
if isiPhone
classUa.push "iPhone"
h = Math.max screen.width, screen.height
classUa.push switch h
when 480 then "iPhone4"
when 568 then "iPhone5"
when 667 then "iPhone6"
when 736 then "iPhone6plus"
else "iPhone-unknown"
classUa.push "iPod" if isiPod
classUa.push "iPad" if isiPad
if isAndroid
classUa.push "android"
verArray = /(android)\s([0-9]{1,}[\.0-9]{1,})/.exec(nameUa)
ver = parseInt(verArray[2].replace(/\./g, ""), 10) if verArray
classUa.push "android_#{ver}" if ver
classUa.push "tablet" if isiPad or (isAndroid and nameUa.indexOf("mobile") < 0)
classUa.push if "ontouchstart" of window then "touch" else "no-touch"
# console.log classUa
$("body")
.addClass classUa.join " "
return