Skip to content

Instantly share code, notes, and snippets.

@ptb
Created May 30, 2013 20:16
Show Gist options
  • Select an option

  • Save ptb/5680798 to your computer and use it in GitHub Desktop.

Select an option

Save ptb/5680798 to your computer and use it in GitHub Desktop.
define ->
class Detect
ios: ->
if @ipad() or @ipod()
# supports iOS 2.0 and later: <http://bit.ly/TJjs1V>
v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/)
return [true, parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]
else
return [false]
ipad: ->
/iPad/.test(navigator.platform)
ipod: ->
/iP(hone|od)/.test(navigator.platform)
orientation: ->
if Math.abs(window.orientation) is 90 then 'landscape' else 'portrait'
retina: ->
window.devicePixelRatio > 1
standalone: ->
Boolean navigator.standalone
(function(){define(function(){var d;return d=function(){function d(){}return d.prototype.ios=function(){var v;return this.ipad()||this.ipod()?(v=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),[!0,parseInt(v[1],10),parseInt(v[2],10),parseInt(v[3]||0,10)]):[!1]},d.prototype.ipad=function(){return/iPad/.test(navigator.platform)},d.prototype.ipod=function(){return/iP(hone|od)/.test(navigator.platform)},d.prototype.orientation=function(){return Math.abs(window.orientation)===90?"landscape":"portrait"},d.prototype.retina=function(){return window.devicePixelRatio>1},d.prototype.standalone=function(){return Boolean(navigator.standalone)},d}()})}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment