forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathINST.js
More file actions
76 lines (65 loc) · 2.85 KB
/
Copy pathINST.js
File metadata and controls
76 lines (65 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* global ScriptEngineMajorVersion: false, escape: false */
define(['jquery'], function($) {
var classesToAdd, userAgent, isIEGreaterThan10;
var addClasses = true;
var classifyIE = function(version) {
version = parseInt(version, 10);
INST.browser['ie' + version] = INST.browser.ie = true;
INST.browser.version = version;
};
// for backwards compat, this might be defined already but we expose
// it as a module here
if (!('INST' in window)) window.INST = {};
// ============================================================================================
// = Try to figure out what browser they are using and set INST.broswer.theirbrowser to true =
// = and add a css class to the body for that browser =
// ============================================================================================
INST.browser = {};
// Conditional comments were dropped as of IE10, so we need to sniff.
//
// See: http://msdn.microsoft.com/en-us/library/ie/hh801214(v=vs.85).aspx
if (!INST.browser.ie) {
userAgent = navigator.userAgent;
isIEGreaterThan10 = /\([^\)]*Trident[^\)]*rv:([\d\.]+)/.exec(userAgent);
if (isIEGreaterThan10) {
if ('ScriptEngineMajorVersion' in window &&
typeof ScriptEngineMajorVersion === 'function') {
classifyIE(ScriptEngineMajorVersion());
} else {
classifyIE(isIEGreaterThan10[1]);
}
// don't add the special "ie" class for IE10+ because their renderer is
// not far behind Gecko and Webkit
addClasses = false;
}
// need to eval here because the optimizer will strip any comments, so using
// /*@cc_on@*/ will not make it through:
else if (eval('/*@cc_on!@*/0')) {
classifyIE(10);
addClasses = false;
}
}
// Test for WebKit.
//
// The IE test is needed because IE11+ defines this property too.
if (window.devicePixelRatio && !INST.browser.ie) {
INST.browser.webkit = true;
//from: http://www.byond.com/members/?command=view_post&post=53727
INST.browser[(escape(navigator.javaEnabled.toString()) == 'function%20javaEnabled%28%29%20%7B%20%5Bnative%20code%5D%20%7D') ? 'chrome' : 'safari'] = true;
}
//this is just using jquery's browser sniffing result of if its firefox, it
//should probably use feature detection
INST.browser.ff = $.browser.mozilla;
INST.browser.touch = 'ontouchstart' in document;
INST.browser['no-touch'] = !INST.browser.touch;
// now we have some degree of knowing which of the common browsers it is,
// on dom ready, give the body those classes
// so for example, if you were on IE6 the body would have the classes "ie" AND "ie6"
if (addClasses) {
classesToAdd = $.map(INST.browser, function(v,k){ if (v === true) return k }).join(' ');
$(function(){
$('body').addClass(classesToAdd);
});
}
return INST;
});