Created
October 2, 2015 11:06
-
-
Save tarunranka/f931d49d474727560922 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
var agent = navigator.userAgent.toLowerCase(), appCheck = navigator.appVersion.match(/android|chrome|mobile/gi), | |
appInfo = { | |
platform: navigator.platform, | |
vendor: (/webkit/i).test(navigator.appVersion) ? 'webkit' : (/firefox/i).test(navigator.userAgent) ? 'Moz' : 'opera' in window ? 'O' : (window.ActiveXObject || "ActiveXObject" in window) ? 'ms' : '', | |
has3d: 'WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix(), | |
hasTouch: !!(("ontouchstart" in window) || window.DocumentTouch && document instanceof window.DocumentTouch), | |
hasTransform: this.vendor + 'Transform' in document.documentElement.style, | |
isIE10: (navigator.appVersion.indexOf("MSIE 10") != -1), | |
// We need to eliminate Symbian, Series 60, Windows Mobile and Blackberry | |
// browsers for this quick and dirty check. This can be done with the user agent. | |
//otherBrowser: (agent.indexOf("series60") != -1) || (agent.indexOf("symbian") != -1) || (agent.indexOf("windows ce") != -1) || (agent.indexOf("blackberry") != -1), | |
// If the screen orientation is defined we are in a modern mobile OS | |
mobileOS: typeof orientation != 'undefined' ? true : false, | |
// If touch events are defined we are in a modern touch screen OS | |
touchOS: ("ontouchstart" in document.documentElement) ? true : false, | |
// iPhone and iPad can be reliably identified with the navigator.platform | |
// string, which is currently only available on these devices. | |
iOS: (navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPad") != -1) ? true : false, | |
isAndroid: (/android/gi).test(navigator.appVersion), | |
isAndroidMobile: (appCheck) ? ((appCheck.indexOf("Android")>-1) && (appCheck.indexOf("Mobile")>-1 || appCheck.indexOf("chrome")>-1)) : false, | |
isIDevice: (/ipad/gi).test(navigator.appVersion), | |
isIphone: (/iphone/gi).test(navigator.appVersion), | |
isIos6plus:(navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPad") != -1)? (/OS [2-5]_\d(_\d)? like Mac OS X/i.test(navigator.userAgent) ? false : true):false, | |
//isPlaybook: (/playbook/gi).test(navigator.appVersion), | |
/** Detect android device versions **/ | |
isAndroidv2: (/android 2\.3/i).test(navigator.userAgent), | |
isAndroidv3plus : (/android [3-9]/i).test(navigator.userAgent), | |
isAndroidv4plus : (/android [4-9]/i).test(navigator.userAgent), | |
//hasTransitionEnd : this.isIDevice || this.isPlaybook, | |
isMobileVersion: false, | |
devicePixelRatio: (window.devicePixelRatio !== undefined) ? window.devicePixelRatio : 1, | |
screenWidth: function () { | |
return parseInt((window.screen.width/this.devicePixelRatio), 10); | |
}, | |
screenHeight: function () { | |
return parseInt((window.screen.height/this.devicePixelRatio), 10); | |
}, | |
iosVersion: function() { | |
if (/iP(hone|od|ad)/.test(navigator.platform)) { | |
// supports iOS 2.0 and later: <http://bit.ly/TJjs1V> | |
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/); | |
return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; | |
} | |
}, | |
detectOrientation: function () { | |
//if($S.U.get_window_resolution().width > $S.U.get_window_resolution().height) { | |
if(window.innerWidth > window.innerHeight) { | |
return "landscape"; | |
} else { | |
return "portrait"; | |
} | |
}, | |
deviceDisplay : { | |
"portrait" : { | |
"w" : "", | |
"h" : "" | |
}, | |
"landscape" : { | |
"w" : "", | |
"h" : "" | |
}, | |
"currentW" : "" | |
}, | |
isChrome: (agent.indexOf("chrome") > -1) ? true : false, | |
isTabletVersion: false, | |
}; | |
if(appInfo.isAndroid && appInfo.isAndroidMobile) { | |
// window.scroll(0,56); | |
} | |
var supportsOrientationChange = "onorientationchange" in window, orientationEvent = supportsOrientationChange ? "orientationchange" : "resize"; | |
function setupDevice (vType, timer) { | |
var body = getEl("body"), | |
className = ""; | |
if(vType === "initial") { | |
timer = 500; | |
if (appInfo.iOS) { | |
className += " ios"; | |
if (appInfo.isIphone) { | |
className += " iphone mobile"; | |
if (appInfo.iosVersion()[0] >= 8 && appInfo.devicePixelRatio == 3) { | |
className += " iPhone6Plus"; // identify better approach to get the device name (http://www.mobilexweb.com/blog/safari-ios8-iphone6-web-developers-designers) | |
} | |
} else { | |
className += " tablet"; | |
} | |
if (appInfo.iosVersion()[0] >= 7) { | |
className += " ios7"; | |
} | |
} else if (appInfo.isPlaybook) { | |
className += " playbook tablet"; | |
} else if(appInfo.isAndroid) { | |
className += " android"; | |
if(appInfo.isAndroidMobile) { | |
className += " mobile"; | |
} else { | |
className += " tablet"; | |
} | |
if(!appInfo.isAndroidv3plus) { | |
className += " less_than_three"; | |
} | |
if(appInfo.isAndroidv4plus) { | |
className += " v4plus"; | |
} | |
} else { | |
className += " desktop-lg"; | |
} | |
if (appInfo.isChrome) { | |
className += " chrome"; | |
} | |
//alert(body.attr('class')); | |
body.addClass(className); | |
appInfo.isMobileVersion = body.hasClass("mobile"); | |
appInfo.isTabletVersion = body.hasClass("tablet"); | |
} | |
setTimeout(function() { | |
body.removeClass("landscape").removeClass("portrait"); | |
body.addClass(appInfo.detectOrientation()); | |
if (body.hasClass("tablet") && appInfo.isAndroid) { | |
var screenHeight = appInfo.screenHeight(); | |
var screenWidth = appInfo.screenWidth(); | |
if((screenHeight <= 700 && screenWidth <= 1024) || (screenHeight <= 1024 && screenWidth <= 700)) { | |
body.addClass('samlldevice'); | |
} | |
} | |
}, timer); | |
} | |
ACC.Tap = appInfo.hasTouch?"touchend":"click"; |
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
$el = {}; | |
var getEl = function(elm) { | |
if($el[elm]) { | |
return $el[elm]; | |
} | |
var elmArr = new Array(); | |
/** General elements : Starts **/ | |
elmArr['html'] = 'html'; | |
elmArr['body'] = 'body'; | |
return $(elmArr[elm]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment