From c239d32f1cd6510d026d5cd47843522cd4803fbb Mon Sep 17 00:00:00 2001 From: Johannes Nickel Date: Tue, 11 Jun 2013 14:53:15 +0200 Subject: [PATCH] browser check --- .../app/lib/app_post/browser_check.js.coffee | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 app/assets/javascripts/app/lib/app_post/browser_check.js.coffee diff --git a/app/assets/javascripts/app/lib/app_post/browser_check.js.coffee b/app/assets/javascripts/app/lib/app_post/browser_check.js.coffee new file mode 100644 index 000000000..e0e7beb24 --- /dev/null +++ b/app/assets/javascripts/app/lib/app_post/browser_check.js.coffee @@ -0,0 +1,99 @@ +class App.browser extends App.Contoller + constructor: -> + + + init: -> + @browser = @searchString(@dataBrowser) or "An unknown browser" + @version = @searchVersion(navigator.userAgent) or @searchVersion(navigator.appVersion) or "an unknown version" + @OS = @searchString(@dataOS) or "an unknown OS" + + searchString: (data) -> + i = 0 + + while i < data.length + dataString = data[i].string + dataProp = data[i].prop + @versionSearchString = data[i].versionSearch or data[i].identity + if dataString + return data[i].identity unless dataString.indexOf(data[i].subString) is -1 + else return data[i].identity if dataProp + i++ + + searchVersion: (dataString) -> + index = dataString.indexOf(@versionSearchString) + return if index is -1 + parseFloat dataString.substring(index + @versionSearchString.length + 1) + + dataBrowser: [ + string: navigator.userAgent + subString: "Chrome" + identity: "Chrome" + , + string: navigator.userAgent + subString: "OmniWeb" + versionSearch: "OmniWeb/" + identity: "OmniWeb" + , + string: navigator.vendor + subString: "Apple" + identity: "Safari" + versionSearch: "Version" + , + prop: window.opera + identity: "Opera" + versionSearch: "Version" + , + string: navigator.vendor + subString: "iCab" + identity: "iCab" + , + string: navigator.vendor + subString: "KDE" + identity: "Konqueror" + , + string: navigator.userAgent + subString: "Firefox" + identity: "Firefox" + , + string: navigator.vendor + subString: "Camino" + identity: "Camino" + , + # for newer Netscapes (6+) + string: navigator.userAgent + subString: "Netscape" + identity: "Netscape" + , + string: navigator.userAgent + subString: "MSIE" + identity: "Explorer" + versionSearch: "MSIE" + , + string: navigator.userAgent + subString: "Gecko" + identity: "Mozilla" + versionSearch: "rv" + , + # for older Netscapes (4-) + string: navigator.userAgent + subString: "Mozilla" + identity: "Netscape" + versionSearch: "Mozilla" + ] + dataOS: [ + string: navigator.platform + subString: "Win" + identity: "Windows" + , + string: navigator.platform + subString: "Mac" + identity: "Mac" + , + string: navigator.userAgent + subString: "iPhone" + identity: "iPhone/iPod" + , + string: navigator.platform + subString: "Linux" + identity: "Linux" + ]