Skip to content

Commit

Permalink
docs: update browser jsdoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
06wj committed Sep 27, 2020
1 parent cad5726 commit ad80bbf
Showing 1 changed file with 117 additions and 86 deletions.
203 changes: 117 additions & 86 deletions src/utils/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,109 +7,124 @@
import log from './log';

/**
* @language=en
* @class Browser feature set
* @static
* 浏览器特性集合
* @namespace
*/
const browser = (function() {
let ua = navigator.userAgent;
let doc = document;
let win = window;
let docElem = doc.documentElement;
const ua = navigator.userAgent;
const doc = document;
const win = window;
const docElem = doc.documentElement;

let data = /** @lends browser */ {
/**
* 是否是iphone
* @type {Boolean}
*/
const data = /** @lends browser */ {
/**
* 是否是iphone
* @readOnly
* @type {boolean}
*/
iphone: /iphone/i.test(ua),

/**
* 是否是ipad
* @type {Boolean}
*/
* 是否是ipad
* @readOnly
* @type {boolean}
*/
ipad: /ipad/i.test(ua),

/**
* 是否是ipod
* @type {Boolean}
*/
* 是否是ipod
* @readOnly
* @type {boolean}
*/
ipod: /ipod/i.test(ua),

/**
* 是否是ios
* @type {Boolean}
*/
* 是否是ios
* @readOnly
* @type {boolean}
*/
ios: /iphone|ipad|ipod/i.test(ua),

/**
* 是否是android
* @type {Boolean}
*/
* 是否是android
* @readOnly
* @type {boolean}
*/
android: /android/i.test(ua),

/**
* 是否是webkit
* @type {Boolean}
*/
* 是否是webkit
* @readOnly
* @type {boolean}
*/
webkit: /webkit/i.test(ua),

/**
* 是否是chrome
* @type {Boolean}
*/
* 是否是chrome
* @readOnly
* @type {boolean}
*/
chrome: /chrome/i.test(ua),

/**
* 是否是safari
* @type {Boolean}
*/
* 是否是safari
* @readOnly
* @type {boolean}
*/
safari: /safari/i.test(ua),

/**
* 是否是firefox
* @type {Boolean}
*/
* 是否是firefox
* @readOnly
* @type {boolean}
*/
firefox: /firefox/i.test(ua),

/**
* 是否是ie
* @type {Boolean}
*/
* 是否是ie
* @readOnly
* @type {boolean}
*/
ie: /msie/i.test(ua),

/**
* 是否是opera
* @type {Boolean}
*/
* 是否是opera
* @readOnly
* @type {boolean}
*/
opera: /opera/i.test(ua),
/**
* 是否支持触碰事件。
* @type {String}
*/
* 是否支持触碰事件。
* @readOnly
* @type {boolean}
*/
supportTouch: 'ontouchstart' in win,

/**
* 是否支持canvas元素。
* @type {Boolean}
*/
* 是否支持canvas元素。
* @readOnly
* @type {boolean}
*/
supportCanvas: !!doc.createElement('canvas').getContext,
/**
* 是否支持本地存储localStorage。
* @type {Boolean}
*/
supportStorage: false,
* 是否支持本地存储localStorage。
* @readOnly
* @type {boolean}
*/
supportStorage: undefined,

/**
* 是否支持检测设备方向orientation。
* @type {Boolean}
*/
* 是否支持检测设备方向orientation。
* @readOnly
* @type {boolean}
*/
supportOrientation: 'orientation' in win || 'orientation' in win.screen,

/**
* 是否支持检测加速度devicemotion。
* @type {Boolean}
*/
* 是否支持检测加速度devicemotion。
* @readOnly
* @type {boolean}
*/
supportDeviceMotion: 'ondevicemotion' in win,
};

Expand All @@ -120,14 +135,16 @@ const browser = (function() {
localStorage.removeItem(value);
data.supportStorage = true;
} catch (e) {
data.supportStorage = false;
log.warn('LocalStorage disabled');
}

/**
* 浏览器厂商CSS前缀的js值。比如:webkit。
* @type {String}
*/

* 浏览器厂商CSS前缀的js值。比如:webkit。
* @memberOf browser
* @readOnly
* @type {string}
*/
let jsVendor;

if (data.webkit) {
Expand All @@ -144,24 +161,30 @@ const browser = (function() {

data.jsVendor = jsVendor;
/**
* 浏览器厂商CSS前缀的css值。比如:-webkit-。
* @type {String}
*/
* 浏览器厂商CSS前缀的css值。比如:-webkit-。
* @memberOf browser
* @readOnly
* @type {string}
*/
let cssVendor = (data.cssVendor = '-' + jsVendor + '-');

// css transform/3d feature dectection
let testElem = doc.createElement('div');
const testElem = doc.createElement('div');
let style = testElem.style;
/**
* 是否支持CSS Transform变换。
* @type {Boolean}
*/
let supportTransform = style[jsVendor + 'Transform'] !== undefined;
* 是否支持CSS Transform变换。
* @memberOf browser
* @readOnly
* @type {boolean}
*/
const supportTransform = style[jsVendor + 'Transform'] !== undefined;

/**
* 是否支持CSS Transform 3D变换。
* @type {Boolean}
*/
* 是否支持CSS Transform 3D变换。
* @memberOf browser
* @readOnly
* @type {boolean}
*/
let supportTransform3D = style[jsVendor + 'Perspective'] !== undefined;
if (supportTransform3D) {
testElem.id = 'test3d';
Expand All @@ -174,33 +197,41 @@ const browser = (function() {
doc.head.removeChild(style);
docElem.removeChild(testElem);
}

data.supportTransform = supportTransform;
data.supportTransform3D = supportTransform3D;

let supportTouch = data.supportTouch;
const supportTouch = data.supportTouch;

/**
* 鼠标或触碰开始事件。对应touchstart或mousedown。
* @type {String}
*/
let POINTER_START = supportTouch ? 'touchstart' : 'mousedown';
* 鼠标或触碰开始事件。对应touchstart或mousedown。
* @memberOf browser
* @readOnly
* @type {string}
*/
const POINTER_START = supportTouch ? 'touchstart' : 'mousedown';

/**
* 鼠标或触碰移动事件。对应touchmove或mousemove。
* @type {String}
*/
let POINTER_MOVE = supportTouch ? 'touchmove' : 'mousemove';
* 鼠标或触碰移动事件。对应touchmove或mousemove。
* @memberOf browser
* @readOnly
* @type {string}
*/
const POINTER_MOVE = supportTouch ? 'touchmove' : 'mousemove';

/**
* 鼠标或触碰结束事件。对应touchend或mouseup。
* @type {String}
*/
let POINTER_END = supportTouch ? 'touchend' : 'mouseup';
* 鼠标或触碰结束事件。对应touchend或mouseup。
* @memberOf browser
* @readOnly
* @type {string}
*/
const POINTER_END = supportTouch ? 'touchend' : 'mouseup';

data.POINTER_START = POINTER_START;
data.POINTER_MOVE = POINTER_MOVE;
data.POINTER_END = POINTER_END;

return data;
}());

export default browser;

0 comments on commit ad80bbf

Please sign in to comment.