oipage 1.2.1 → 1.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,31 @@
1
- export type throttleOpportunityType = "begin" | "end" | "wide"
2
-
3
- export interface throttleOptionType {
4
-
5
- /**
6
- * 节流时长
7
- */
8
- time?: number
9
-
10
- /**
11
- * 是否持续节流
12
- */
13
- keep?: boolean
14
-
15
- /**
16
- * 执行时机
17
- *
18
- * begin(开始触发)、end(结束触发)、wide(第一次开始触发,其余结束触发)
19
- */
20
- opportunity?: throttleOpportunityType
21
-
22
- }
23
-
24
- /**
25
- * 节流函数
26
- */
27
- export interface throttleType {
28
- (callback: Function, option?: throttleOptionType): Function
29
- }
30
-
1
+ export type throttleOpportunityType = "begin" | "end" | "wide"
2
+
3
+ export interface throttleOptionType {
4
+
5
+ /**
6
+ * 节流时长
7
+ */
8
+ time?: number
9
+
10
+ /**
11
+ * 是否持续节流
12
+ */
13
+ keep?: boolean
14
+
15
+ /**
16
+ * 执行时机
17
+ *
18
+ * begin(开始触发)、end(结束触发)、wide(第一次开始触发,其余结束触发)
19
+ */
20
+ opportunity?: throttleOpportunityType
21
+
22
+ }
23
+
24
+ /**
25
+ * 节流函数
26
+ */
27
+ export interface throttleType {
28
+ (callback: Function, option?: throttleOptionType): Function
29
+ }
30
+
31
31
  export let throttle: throttleType
@@ -1,55 +1,55 @@
1
1
  /*!
2
- * throttle of OIPage v1.2.1
2
+ * throttle of OIPage v1.3.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
6
- export function throttle(callback, _option) {
7
-
8
- // 缺省值
9
- var option = {
10
- time: 200,
11
- keep: false,
12
- opportunity: "end"
13
- };
14
-
15
- // 校对
16
- if (_option) {
17
- for (var key in _option) {
18
- option[key] = _option[key];
19
- }
20
- }
21
-
22
- var hadInterval = false, hadClick = false, oneClick = false, arg;
23
- return function () {
24
- const _this = this;
25
- arg = arguments;
26
-
27
- // 如果前置任务都完成了
28
- if (!hadInterval) {
29
- if (option.opportunity != 'end') {
30
- callback.apply(_this, arg);
31
- }
32
- hadInterval = true;
33
-
34
- var interval = setInterval(() => {
35
- if (hadClick) {
36
- if (!option.keep) {
37
- callback.apply(_this, arg);
38
- }
39
- } else {
40
- if (option.opportunity != 'begin') {
41
- if (oneClick || option.opportunity == 'end') callback.apply(_this, arg);
42
- }
43
- hadInterval = false;
44
- oneClick = false;
45
- clearInterval(interval);
46
- }
47
- hadClick = false;
48
- }, option.time);
49
- } else {
50
- hadClick = true;
51
- oneClick = true;
52
- }
53
-
54
- };
6
+ export function throttle(callback, _option) {
7
+
8
+ // 缺省值
9
+ var option = {
10
+ time: 200,
11
+ keep: false,
12
+ opportunity: "end"
13
+ };
14
+
15
+ // 校对
16
+ if (_option) {
17
+ for (var key in _option) {
18
+ option[key] = _option[key];
19
+ }
20
+ }
21
+
22
+ var hadInterval = false, hadClick = false, oneClick = false, arg;
23
+ return function () {
24
+ const _this = this;
25
+ arg = arguments;
26
+
27
+ // 如果前置任务都完成了
28
+ if (!hadInterval) {
29
+ if (option.opportunity != 'end') {
30
+ callback.apply(_this, arg);
31
+ }
32
+ hadInterval = true;
33
+
34
+ var interval = setInterval(() => {
35
+ if (hadClick) {
36
+ if (!option.keep) {
37
+ callback.apply(_this, arg);
38
+ }
39
+ } else {
40
+ if (option.opportunity != 'begin') {
41
+ if (oneClick || option.opportunity == 'end') callback.apply(_this, arg);
42
+ }
43
+ hadInterval = false;
44
+ oneClick = false;
45
+ clearInterval(interval);
46
+ }
47
+ hadClick = false;
48
+ }, option.time);
49
+ } else {
50
+ hadClick = true;
51
+ oneClick = true;
52
+ }
53
+
54
+ };
55
55
  }