1 /**
  2  * @namespace Information about the current browsing environment (browser type
  3  * and capabilities, screen size, browser viewport size, etc.)
  4  */
  5 Jelo.Environment = function() {
  6     /** @private convenience */
  7     var D = window.document, DB = D.body;
  8     
  9     // many of these are verbatim or adapted from Ext.JS
 10     var ua = navigator.userAgent.toLowerCase();
 11     var isStrict = D.compatMode == "CSS1Compat";
 12     var isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1);
 13     var isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1);
 14     var isLinux = (ua.indexOf("linux") != -1);
 15     var isAir = (ua.indexOf("adobeair") != -1);
 16     var isWebkit = (/webkit|khtml/).test(ua);
 17     var isSafari3 = (/webkit\/5/).test(ua);
 18     var isGecko = !isWebkit && (/gecko/).test(ua);
 19     var isFirefox = isGecko && (/firefox\/\d/).test(ua);
 20     var isFirefoxOld = isGecko && (/firefox\/[0-2]/).test(ua);
 21     var isOpera = (/opera/).test(ua);
 22     var isIE = !!(window.attachEvent && !isOpera);
 23     var isIE7 = isIE && (/msie 7/).test(ua);
 24     var isIE8 = isIE && (/msie 8/).test(ua);
 25     var isIEOld = isIE && (/msie [0-6]/).test(ua);
 26     var isGoogle = (/google/).test(ua);
 27     var isGoogleChrome = (/chrome\/[0-1]/).test(ua);
 28     var isYahoo = (/yahoo/).test(ua);
 29     var isBot = (/bot|crawler|http/).test(ua);
 30     var isSecure = window.location.href.toLowerCase().indexOf("https") === 0;
 31     var isModern = (typeof XMLHttpRequest != "undefined");
 32     
 33     // fix css image flicker
 34     if (isIEOld) {
 35         try {
 36             D.execCommand("BackgroundImageCache", false, true);
 37         } catch (e) {}
 38     }
 39     
 40     return {
 41         /**
 42          * When "full" is true, returns the width of the physical display screen.
 43          * When "full" is false, returns the screen width minus the taskbar (if applicable).
 44          * @param {Boolean} [full]
 45          * @returns {Number}
 46          */
 47         getScreenWidth    : function(full) {
 48             return full ? screen.width : screen.availWidth;
 49         },
 50         /**
 51          * When "full" is true, returns the height of the physical display screen.
 52          * When "full" is false, returns the screen height minus the taskbar (if applicable).
 53          * @param {Boolean} [full]
 54          * @returns {Number}
 55          */
 56         getScreenHeight   : function(full) {
 57             return full ? screen.height : screen.availHeight;
 58         },
 59         /**
 60          * When "full" is true, shorthand for getDocumentWidth.
 61          * When "full" is false, shorthand for getViewportWidth.
 62          * @param {Boolean} [full]
 63          * @returns {Number}
 64          */
 65         getViewWidth      : function(full) {
 66             return full ? this.getDocumentWidth() : this.getViewportWidth();
 67         },
 68         /**
 69          * When "full" is true, shorthand for getDocumentHeight.
 70          * When "full" is false, shorthand for getViewportHeight.
 71          * @param {Boolean} [full]
 72          * @returns {Number} The Viewport or Document height.
 73          */
 74         getViewHeight     : function(full) {
 75             return full ? this.getDocumentHeight() : this.getViewportHeight();
 76         },
 77         /**
 78          * @returns {Number} The complete horizontal size of the document, including scrollable content.
 79          */
 80         getDocumentWidth  : function() {
 81             var scrollWidth = (D.compatMode != "CSS1Compat")
 82                 ? DB.scrollWidth
 83                 : D.documentElement.scrollWidth;
 84             return Math.max(scrollWidth, this.getViewportWidth());
 85         },
 86         /**
 87          * @returns {Number} The complete vertical size of the document, including scrollable content.
 88          */
 89         getDocumentHeight : function() {
 90             var scrollHeight = (D.compatMode != "CSS1Compat")
 91                 ? DB.scrollHeight
 92                 : D.documentElement.scrollHeight;
 93             return Math.max(scrollHeight, this.getViewportHeight());
 94         },
 95         /**
 96          * @returns {Number} The current width of the browser's visible area.
 97          */
 98         getViewportWidth  : function() {
 99             if (this.isIE) {
100                 return this.isStrict ? D.documentElement.clientWidth : DB.clientWidth;
101             } else {
102                 return window.innerWidth;
103             }
104         },
105         /**
106          * @returns {Number} The current height of the browser's visible area.
107          */
108         getViewportHeight : function() {
109             if (this.isIE) {
110                 return this.isStrict ? D.documentElement.clientHeight : DB.clientHeight;
111             } else {
112                 return window.innerHeight;
113             }
114         },
115         /**
116          * @returns {String} The browser's User Agent.
117          */
118         getUA             : function() {
119             return ua;
120         },
121         /**
122          * True if the browser is in strict mode.
123          *
124          * @type Boolean
125          */
126         isStrict          : isStrict,
127         /**
128          * True in a Windows environment.
129          *
130          * @type Boolean
131          */
132         isWindows         : isWindows,
133         /**
134          * True in an Apple Macintosh environment.
135          *
136          * @type Boolean
137          */
138         isMac             : isMac,
139         /**
140          * True in a Linux environment.
141          *
142          * @type Boolean
143          */
144         isLinux           : isLinux,
145         /**
146          * True in an Adobe AIR environment.
147          *
148          * @type Boolean
149          */
150         isAir             : isAir,
151         /**
152          * True if the browser identifies itself as using the Webkit rendering
153          * engine (includes Safari and Google Chrome).
154          *
155          * @type Boolean
156          */
157         isWebkit          : isWebkit,
158         /**
159          * True if the browser appears to be Safari 3.x.
160          *
161          * @type Boolean
162          */
163         isSafari3         : isSafari3,
164         /**
165          * True if the browser identifies itself as using the Gecko rendering
166          * engine (includes Firefox and several "microbrew" browsers).
167          *
168          * @type Boolean
169          */
170         isGecko           : isGecko,
171         /**
172          * True if the browser identifies itself as Mozilla Firefox.
173          *
174          * @type Boolean
175          */
176         isFirefox         : isFirefox,
177         /**
178          * True if the browser identifies itself as Opera.
179          *
180          * @type Boolean
181          */
182         isOpera           : isOpera,
183         /**
184          * True if the browser identifies itself as Microsoft Internet Explorer.
185          *
186          * @type Boolean
187          */
188         isIE              : isIE,
189         /**
190          * True if the browser identifies itself as Microsoft Internet Explorer
191          * 7.
192          *
193          * @type Boolean
194          */
195         isIE7             : isIE7,
196         /**
197          * True if the browser identifies itself as Microsoft Internet Explorer
198          * 8.
199          *
200          * @type Boolean
201          */
202         isIE8             : isIE8,
203         /**
204          * True if the browser identifies itself as Microsoft Internet Explorer
205          * 6 or older.
206          *
207          * @type Boolean
208          */
209         isIEOld           : isIEOld,
210         /**
211          * True if the visitor identifies itself as Google, including the
212          * Googlebot search engine and various other Google robots (which may or
213          * may not support JavaScript anyway...).
214          *
215          * @type Boolean
216          */
217         isGoogle          : isGoogle,
218         /**
219          * True if the visitor identifies itself as Yahoo, including the Yahoo
220          * Slurp search engine (which may or may not support JavaScript
221          * anyway...)
222          *
223          * @type Boolean
224          */
225         isYahoo           : isYahoo,
226         /**
227          * True if the visitor appears to be a robot. Not necessarily a good or
228          * bad thing, nor does this imply support (or lack thereof) for any
229          * particular JS or CSS feature.
230          *
231          * @type Boolean
232          */
233         isBot             : isBot,
234         /**
235          * True if the browser is in secure mode (HTTPS).
236          *
237          * @type Boolean
238          */
239         isSecure          : isSecure,
240         /**
241          * True if the browser is standards-compliant. Note that actual
242          * compliance depends on the page being viewed, this just determines
243          * whether the browser can understand standards-compliant code.
244          *
245          * @type Boolean
246          * @deprecated Replaced with {@link Jelo.Environment.isModern}
247          * in v1.05, you should use that instead.
248          */
249         isStandard        : isModern, // deprecated
250         /**
251          * True in all modern browsers, indicates native AJAX support via
252          * XMLHttpRequest. IE version 6 and older are known to be false,
253          * nearly every other browser supports XMLHttpRequest natively.
254          * 
255          * @type Boolean
256          */
257         isModern          : isModern
258     };
259 }();
260 
261 /**
262  * Shorthand for {@link Jelo.Environment}
263  *
264  * @memberOf Jelo
265  * @namespace
266  */
267 Jelo.Env = Jelo.Environment;
268