get-support.js 782 Bytes
Newer Older
xhw committed
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
let support;

function getMobile() {
	if (navigator.userAgent.indexOf('Mobile') > -1) {
		return true;
	} else {
		return false;
	}
}

function calcSupport() {
	return {
		smoothScroll: true,
		// #ifdef H5
		touch: getMobile(),
		// #endif
		// #ifndef H5
		touch: true,
		// #endif
		passiveListener: function checkPassiveListener() {
			let supportsPassive = false;

			try {
				const opts = Object.defineProperty({}, 'passive', {
					// eslint-disable-next-line
					get() {
						supportsPassive = true;
					}

				});
			} catch (e) { // No support
			}

			return supportsPassive;
		}(),
		gestures: function checkGestures() {
			return false;
		}()
	};
}

function getSupport() {
	if (!support) {
		support = calcSupport();
	}
	return support;
}

export {
	getSupport
};