| 1 | // Copyright 2010 The Closure Library Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | /** |
| 16 | * @fileoverview Browser capability checks for the events package. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | goog.provide('goog.events.BrowserFeature'); |
| 22 | |
| 23 | goog.require('goog.userAgent'); |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * Enum of browser capabilities. |
| 28 | * @enum {boolean} |
| 29 | */ |
| 30 | goog.events.BrowserFeature = { |
| 31 | /** |
| 32 | * Whether the button attribute of the event is W3C compliant. False in |
| 33 | * Internet Explorer prior to version 9; document-version dependent. |
| 34 | */ |
| 35 | HAS_W3C_BUTTON: !goog.userAgent.IE || |
| 36 | goog.userAgent.isDocumentModeOrHigher(9), |
| 37 | |
| 38 | /** |
| 39 | * Whether the browser supports full W3C event model. |
| 40 | */ |
| 41 | HAS_W3C_EVENT_SUPPORT: !goog.userAgent.IE || |
| 42 | goog.userAgent.isDocumentModeOrHigher(9), |
| 43 | |
| 44 | /** |
| 45 | * To prevent default in IE7-8 for certain keydown events we need set the |
| 46 | * keyCode to -1. |
| 47 | */ |
| 48 | SET_KEY_CODE_TO_PREVENT_DEFAULT: goog.userAgent.IE && |
| 49 | !goog.userAgent.isVersionOrHigher('9'), |
| 50 | |
| 51 | /** |
| 52 | * Whether the {@code navigator.onLine} property is supported. |
| 53 | */ |
| 54 | HAS_NAVIGATOR_ONLINE_PROPERTY: !goog.userAgent.WEBKIT || |
| 55 | goog.userAgent.isVersionOrHigher('528'), |
| 56 | |
| 57 | /** |
| 58 | * Whether HTML5 network online/offline events are supported. |
| 59 | */ |
| 60 | HAS_HTML5_NETWORK_EVENT_SUPPORT: |
| 61 | goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9b') || |
| 62 | goog.userAgent.IE && goog.userAgent.isVersionOrHigher('8') || |
| 63 | goog.userAgent.OPERA && goog.userAgent.isVersionOrHigher('9.5') || |
| 64 | goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher('528'), |
| 65 | |
| 66 | /** |
| 67 | * Whether HTML5 network events fire on document.body, or otherwise the |
| 68 | * window. |
| 69 | */ |
| 70 | HTML5_NETWORK_EVENTS_FIRE_ON_BODY: |
| 71 | goog.userAgent.GECKO && !goog.userAgent.isVersionOrHigher('8') || |
| 72 | goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('9'), |
| 73 | |
| 74 | /** |
| 75 | * Whether touch is enabled in the browser. |
| 76 | */ |
| 77 | TOUCH_ENABLED: |
| 78 | ('ontouchstart' in goog.global || |
| 79 | !!(goog.global['document'] && |
| 80 | document.documentElement && |
| 81 | 'ontouchstart' in document.documentElement) || |
| 82 | // IE10 uses non-standard touch events, so it has a different check. |
| 83 | !!(goog.global['navigator'] && |
| 84 | goog.global['navigator']['msMaxTouchPoints'])) |
| 85 | }; |