Last active
December 16, 2015 16:40
-
-
Save ralphcrisostomo/5464850 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
# TO USE: | |
# window.app.helpers.browserDetect.initialize() | |
# window.app.helpers.browserDetect.browser == "Safari" | |
# window.app.helpers.browserDetect.version == 2 | |
"use strict"; | |
window.app = window.app or {} | |
window.app.helpers = window.app.helpers or {} | |
window.app.helpers.browserDetect = | |
initialize : -> | |
console.log "Browser Detect Initialize" | |
@browser = @searchString(@dataBrowser) or "Other" | |
@version = @searchVersion(navigator.userAgent) or @searchVersion(navigator.appVersion) or "Unknown" | |
searchString : (data) -> | |
lock = false | |
for item in data | |
dataString = item.string | |
if dataString.indexOf(item.subString) != -1 and lock is false | |
@versionSearchString = item.subString | |
identity = item.identity | |
lock = true | |
identity | |
searchVersion : (dataString) -> | |
index = dataString.indexOf @versionSearchString | |
if index is -1 | |
return | |
parseFloat(dataString.substring(index + @versionSearchString.length + 1)) | |
dataBrowser : [ | |
"string" : navigator.userAgent | |
"subString" : "Chrome" | |
"identity" : "Chrome" | |
, | |
"string" : navigator.userAgent | |
"subString" : "MSIE" | |
"identity" : "Explorer" | |
, | |
"string" : navigator.userAgent | |
"subString" : "Firefox" | |
"identity" : "Firefox" | |
, | |
"string" : navigator.userAgent | |
"subString" : "Safari" | |
"identity" : "Safari" | |
, | |
"string" : navigator.userAgent | |
"subString" : "Opera" | |
"identity" : "Opera" | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment