Created
March 7, 2012 20:12
-
-
Save trevorsheridan/1995716 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
(function() { | |
var Detective = window.Detective = Backbone.Base.extend({ | |
initialize: function() { | |
snack.publisher(this); | |
this.ua = window.navigator.userAgent; | |
return this; | |
}, | |
watch: function() { | |
var orientationevent = 'onorientationchange' in window ? 'orientationchange' : 'resize'; | |
window.addEventListener(orientationevent, snack.bind(function(e) { | |
this.publish('orientation', [this.orientation()]); | |
}, this)); | |
return this; | |
}, | |
orientation: function() { | |
if ('onorientationchange' in window) | |
return window.orientation & 2 ? 'landscape' : 'portrait'; | |
else | |
return window.innerWidth / window.innerHeight << 0 ? 'landscape' : 'portrait'; | |
}, | |
device: function() { | |
var processed = /(iPad.*?|iPhone.*?|iPod.*?)?;.*(CPU\s.*\d?|Android\s.*\d|MSIE.*?|BlackBerry\s.*\d?)(OS X\)|;)/i.exec(this.ua); | |
var device = ''; | |
processed = processed ? processed : device; | |
if (typeof processed === 'object' && typeof processed[2] === 'string') { | |
device = processed[2]; | |
if (/iPad.*?|iPhone.*?|iPod.*?/i.test(processed[1])) | |
device = processed[1] + ' ' + /(OS.*\d)/.exec(processed[2])[1]; | |
} | |
return device.replace(/\s/g, '-'); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment