Path: blob/trunk/third_party/closure/goog/events/browserfeature.js
4115 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview Browser capability checks for the events package.8*/910goog.module('goog.events.BrowserFeature');11goog.module.declareLegacyNamespace();121314/**15* Tricks Closure Compiler into believing that a function is pure. The compiler16* assumes that any `valueOf` function is pure, without analyzing its contents.17*18* @param {function(): T} fn19* @return {T}20* @template T21*/22const purify = (fn) => {23return ({valueOf: fn}).valueOf();24};252627/**28* Enum of browser capabilities.29* @enum {boolean}30*/31exports = {32/**33* Whether touch is enabled in the browser.34*/35TOUCH_ENABLED:36('ontouchstart' in goog.global ||37!!(goog.global['document'] && document.documentElement &&38'ontouchstart' in document.documentElement) ||39// IE10 uses non-standard touch events, so it has a different check.40!!(goog.global['navigator'] &&41(goog.global['navigator']['maxTouchPoints'] ||42goog.global['navigator']['msMaxTouchPoints']))),4344/**45* Whether addEventListener supports W3C standard pointer events.46* http://www.w3.org/TR/pointerevents/47*/48POINTER_EVENTS: ('PointerEvent' in goog.global),4950/**51* Whether addEventListener supports MSPointer events (only used in IE10).52* http://msdn.microsoft.com/en-us/library/ie/hh772103(v=vs.85).aspx53* http://msdn.microsoft.com/library/hh673557(v=vs.85).aspx54*/55MSPOINTER_EVENTS: false,5657/**58* Whether addEventListener supports {passive: true}.59* https://developers.google.com/web/updates/2016/06/passive-event-listeners60*/61PASSIVE_EVENTS: purify(function() {62// If we're in a web worker or other custom environment, we can't tell.63if (!goog.global.addEventListener || !Object.defineProperty) { // IE 864return false;65}6667var passive = false;68var options = Object.defineProperty({}, 'passive', {69get: function() {70passive = true;71}72});73try {74const nullFunction = () => {};75goog.global.addEventListener('test', nullFunction, options);76goog.global.removeEventListener('test', nullFunction, options);77} catch (e) {78}7980return passive;81})82};838485