1 /** |
|
2 * Env.js |
|
3 * |
|
4 * Copyright, Moxiecode Systems AB |
|
5 * Released under LGPL License. |
|
6 * |
|
7 * License: http://www.tinymce.com/license |
|
8 * Contributing: http://www.tinymce.com/contributing |
|
9 */ |
|
10 |
|
11 /** |
|
12 * This class contains various environment constants like browser versions etc. |
|
13 * Normally you don't want to sniff specific browser versions but sometimes you have |
|
14 * to when it's impossible to feature detect. So use this with care. |
|
15 * |
|
16 * @class tinymce.Env |
|
17 * @static |
|
18 */ |
|
19 define("tinymce/Env", [], function() { |
|
20 var nav = navigator, userAgent = nav.userAgent; |
|
21 var opera, webkit, ie, ie11, ie12, gecko, mac, iDevice, android; |
|
22 |
|
23 opera = window.opera && window.opera.buildNumber; |
|
24 android = /Android/.test(userAgent); |
|
25 webkit = /WebKit/.test(userAgent); |
|
26 ie = !webkit && !opera && (/MSIE/gi).test(userAgent) && (/Explorer/gi).test(nav.appName); |
|
27 ie = ie && /MSIE (\w+)\./.exec(userAgent)[1]; |
|
28 ie11 = userAgent.indexOf('Trident/') != -1 && (userAgent.indexOf('rv:') != -1 || nav.appName.indexOf('Netscape') != -1) ? 11 : false; |
|
29 ie12 = (document.msElementsFromPoint && !ie && !ie11) ? 12 : false; |
|
30 ie = ie || ie11 || ie12; |
|
31 gecko = !webkit && !ie11 && /Gecko/.test(userAgent); |
|
32 mac = userAgent.indexOf('Mac') != -1; |
|
33 iDevice = /(iPad|iPhone)/.test(userAgent); |
|
34 |
|
35 if (ie12) { |
|
36 webkit = false; |
|
37 } |
|
38 |
|
39 // Is a iPad/iPhone and not on iOS5 sniff the WebKit version since older iOS WebKit versions |
|
40 // says it has contentEditable support but there is no visible caret. |
|
41 var contentEditable = !iDevice || userAgent.match(/AppleWebKit\/(\d*)/)[1] >= 534; |
|
42 |
|
43 return { |
|
44 /** |
|
45 * Constant that is true if the browser is Opera. |
|
46 * |
|
47 * @property opera |
|
48 * @type Boolean |
|
49 * @final |
|
50 */ |
|
51 opera: opera, |
|
52 |
|
53 /** |
|
54 * Constant that is true if the browser is WebKit (Safari/Chrome). |
|
55 * |
|
56 * @property webKit |
|
57 * @type Boolean |
|
58 * @final |
|
59 */ |
|
60 webkit: webkit, |
|
61 |
|
62 /** |
|
63 * Constant that is more than zero if the browser is IE. |
|
64 * |
|
65 * @property ie |
|
66 * @type Boolean |
|
67 * @final |
|
68 */ |
|
69 ie: ie, |
|
70 |
|
71 /** |
|
72 * Constant that is true if the browser is Gecko. |
|
73 * |
|
74 * @property gecko |
|
75 * @type Boolean |
|
76 * @final |
|
77 */ |
|
78 gecko: gecko, |
|
79 |
|
80 /** |
|
81 * Constant that is true if the os is Mac OS. |
|
82 * |
|
83 * @property mac |
|
84 * @type Boolean |
|
85 * @final |
|
86 */ |
|
87 mac: mac, |
|
88 |
|
89 /** |
|
90 * Constant that is true if the os is iOS. |
|
91 * |
|
92 * @property iOS |
|
93 * @type Boolean |
|
94 * @final |
|
95 */ |
|
96 iOS: iDevice, |
|
97 |
|
98 /** |
|
99 * Constant that is true if the os is android. |
|
100 * |
|
101 * @property android |
|
102 * @type Boolean |
|
103 * @final |
|
104 */ |
|
105 android: android, |
|
106 |
|
107 /** |
|
108 * Constant that is true if the browser supports editing. |
|
109 * |
|
110 * @property contentEditable |
|
111 * @type Boolean |
|
112 * @final |
|
113 */ |
|
114 contentEditable: contentEditable, |
|
115 |
|
116 /** |
|
117 * Transparent image data url. |
|
118 * |
|
119 * @property transparentSrc |
|
120 * @type Boolean |
|
121 * @final |
|
122 */ |
|
123 transparentSrc: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", |
|
124 |
|
125 /** |
|
126 * Returns true/false if the browser can or can't place the caret after a inline block like an image. |
|
127 * |
|
128 * @property noCaretAfter |
|
129 * @type Boolean |
|
130 * @final |
|
131 */ |
|
132 caretAfter: ie != 8, |
|
133 |
|
134 /** |
|
135 * Constant that is true if the browser supports native DOM Ranges. IE 9+. |
|
136 * |
|
137 * @property range |
|
138 * @type Boolean |
|
139 */ |
|
140 range: window.getSelection && "Range" in window, |
|
141 |
|
142 /** |
|
143 * Returns the IE document mode for non IE browsers this will fake IE 10. |
|
144 * |
|
145 * @property documentMode |
|
146 * @type Number |
|
147 */ |
|
148 documentMode: ie && !ie12 ? (document.documentMode || 7) : 10 |
|
149 }; |
|
150 }); |
|