utils.js
3.52 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.dataToArray = dataToArray;
exports.addEventListener = addEventListener;
exports.removeEventListener = removeEventListener;
exports.transformArguments = transformArguments;
exports.getTouchParentScroll = exports.windowIsUndefined = exports.isNumeric = exports.transitionEnd = exports.transitionStr = void 0;
function dataToArray(vars) {
if (Array.isArray(vars)) {
return vars;
}
return [vars];
}
var transitionEndObject = {
transition: 'transitionend',
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
OTransition: 'oTransitionEnd otransitionend'
};
var transitionStr = Object.keys(transitionEndObject).filter(function (key) {
if (typeof document === 'undefined') {
return false;
}
var html = document.getElementsByTagName('html')[0];
return key in (html ? html.style : {});
})[0];
exports.transitionStr = transitionStr;
var transitionEnd = transitionEndObject[transitionStr];
exports.transitionEnd = transitionEnd;
function addEventListener(target, eventType, callback, options) {
if (target.addEventListener) {
target.addEventListener(eventType, callback, options);
} else if (target.attachEvent) {
// tslint:disable-line
target.attachEvent("on".concat(eventType), callback); // tslint:disable-line
}
}
function removeEventListener(target, eventType, callback, options) {
if (target.removeEventListener) {
target.removeEventListener(eventType, callback, options);
} else if (target.attachEvent) {
// tslint:disable-line
target.detachEvent("on".concat(eventType), callback); // tslint:disable-line
}
}
function transformArguments(arg, cb) {
var result = typeof arg === 'function' ? arg(cb) : arg;
if (Array.isArray(result)) {
if (result.length === 2) {
return result;
}
return [result[0], result[1]];
}
return [result];
}
var isNumeric = function isNumeric(value) {
return !isNaN(parseFloat(value)) && isFinite(value);
};
exports.isNumeric = isNumeric;
var windowIsUndefined = !(typeof window !== 'undefined' && window.document && window.document.createElement);
exports.windowIsUndefined = windowIsUndefined;
var getTouchParentScroll = function getTouchParentScroll(root, currentTarget, differX, differY) {
if (!currentTarget || currentTarget === document || currentTarget instanceof Document) {
return false;
} // root 为 drawer-content 设定了 overflow, 判断为 root 的 parent 时结束滚动;
if (currentTarget === root.parentNode) {
return true;
}
var isY = Math.max(Math.abs(differX), Math.abs(differY)) === Math.abs(differY);
var isX = Math.max(Math.abs(differX), Math.abs(differY)) === Math.abs(differX);
var scrollY = currentTarget.scrollHeight - currentTarget.clientHeight;
var scrollX = currentTarget.scrollWidth - currentTarget.clientWidth;
var style = document.defaultView.getComputedStyle(currentTarget);
var overflowY = style.overflowY === 'auto' || style.overflowY === 'scroll';
var overflowX = style.overflowX === 'auto' || style.overflowX === 'scroll';
var y = scrollY && overflowY;
var x = scrollX && overflowX;
if (isY && (!y || y && (currentTarget.scrollTop >= scrollY && differY < 0 || currentTarget.scrollTop <= 0 && differY > 0)) || isX && (!x || x && (currentTarget.scrollLeft >= scrollX && differX < 0 || currentTarget.scrollLeft <= 0 && differX > 0))) {
return getTouchParentScroll(root, currentTarget.parentNode, differX, differY);
}
return false;
};
exports.getTouchParentScroll = getTouchParentScroll;