Last active
September 29, 2017 17:42
-
-
Save krivaten/056cf3367872d11390f7 to your computer and use it in GitHub Desktop.
A nice little Ember Service to determine certain browser types and platforms.
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
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
isPrivate: Ember.computed(() => { | |
let nativeStorage; | |
// Safari's private tabs do not allow for the use of localStorage or sessionStorage | |
// This script checks to see if either service is available | |
// If not, it indicates that the user is in a private tab | |
try { | |
nativeStorage = localStorage || sessionStorage; | |
nativeStorage.setItem('storageCheck', true); | |
nativeStorage.removeItem('storageCheck'); | |
} catch (e) { | |
nativeStorage = false; | |
} | |
// A deliberate true or false must be returned otherwise the result is buggy | |
return nativeStorage ? false : true; | |
}), | |
isAndroid: Ember.computed(() => { | |
return !!navigator.userAgent.match(/Android/i); | |
}), | |
isIOS: Ember.computed(() => { | |
return !!navigator.userAgent.match(/iPhone|iPad|iPod/i); | |
}), | |
isWindows: Ember.computed(() => { | |
return !!navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i); | |
}), | |
isMobile: Ember.computed.or('isAndroid', 'isIOS', 'isWindows') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment