Last active
April 1, 2017 19:50
-
-
Save znechai/d288a7f0921e6770c00fed3d4d4f5242 to your computer and use it in GitHub Desktop.
Angular - Device Detector Factory
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 useragent($q, $window) { | |
return { | |
// Get user agent | |
getUserAgent: function () { | |
var deffered = $q.defer(); | |
if ($window.navigator && $window.navigator.userAgent){ | |
var ua = $window.navigator.userAgent; | |
deffered.resolve(ua); | |
} | |
return deffered.promise; | |
}, | |
// Get if user connected via mobile or desktop using params from above function | |
getIcon: function (ua) { | |
var deffered = $q.defer(); | |
var icon = ua.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i) ? 'mobile' : 'desktop'; | |
deffered.resolve(icon); | |
return deffered.promise; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment