diginext-utils 0.0.1
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.
- package/.eslintrc.json +21 -0
- package/README.md +0 -0
- package/index.js +1 -0
- package/package.json +21 -0
- package/src/ArrayExtra.js +299 -0
- package/src/Browser.js +297 -0
- package/src/Camera.js +412 -0
- package/src/Checker.js +24 -0
- package/src/Color.js +81 -0
- package/src/Console.js +18 -0
- package/src/Device.js +56 -0
- package/src/EventDispatcher.js +58 -0
- package/src/FileUpload.js +59 -0
- package/src/FileUtils.js +30 -0
- package/src/MathExtra.js +172 -0
- package/src/OS.js +203 -0
- package/src/ObjectExtra.js +109 -0
- package/src/ReactUtils.js +25 -0
- package/src/ScrollPos.js +31 -0
- package/src/Slug.js +383 -0
- package/src/Timer.js +7 -0
- package/src/Url.js +109 -0
- package/src/UrlUtils.js +109 -0
- package/src/UserLS.js +104 -0
- package/src/Uuid.js +66 -0
- package/src/Validation.js +35 -0
- package/src/array/index.js +301 -0
- package/src/backend/file/createDir.js +13 -0
- package/src/backend/file/fileMove.js +35 -0
- package/src/backend/file/findFilesByExt.js +42 -0
- package/src/backend/zip/extractZip.js +58 -0
- package/src/device/browser.js +29 -0
- package/src/device/camera.js +228 -0
- package/src/device/index.js +233 -0
- package/src/isMobileOrTablet.js +28 -0
- package/src/math/index.js +211 -0
- package/src/object/index.js +40 -0
- package/src/permission/requestCamera.js +43 -0
- package/src/permission/requestDeviceOrientationControl.js +32 -0
- package/src/string/index.js +194 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"es2021": true
|
|
5
|
+
},
|
|
6
|
+
"parserOptions": {
|
|
7
|
+
"ecmaFeatures": {
|
|
8
|
+
"jsx": true
|
|
9
|
+
},
|
|
10
|
+
"ecmaVersion": 13,
|
|
11
|
+
"sourceType": "module"
|
|
12
|
+
},
|
|
13
|
+
"plugins": ["react"],
|
|
14
|
+
"extends": "next",
|
|
15
|
+
"rules": {
|
|
16
|
+
"react-hooks/exhaustive-deps": "off",
|
|
17
|
+
"react/no-unescaped-entities": "off",
|
|
18
|
+
"react/display-name": "off",
|
|
19
|
+
"@next/next/no-img-element": "off"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/README.md
ADDED
|
File without changes
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/object";
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "diginext-utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "TOP GROUP (a.k.a Digitop)",
|
|
7
|
+
"email": "dev@wearetopgroup.com"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"publish": "npm publish",
|
|
11
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"chalk": "^5.0.1",
|
|
15
|
+
"dayjs": "^1.11.3",
|
|
16
|
+
"lodash": "^4.17.21"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import MathExtra from "./MathExtra";
|
|
2
|
+
|
|
3
|
+
const ArrayExtra = {
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {Array} array
|
|
7
|
+
* @param {string} key
|
|
8
|
+
* @returns {Number}
|
|
9
|
+
*/
|
|
10
|
+
sum(array, key) {
|
|
11
|
+
if (!array) {
|
|
12
|
+
console.warn("ARRAY NOT EXITED !");
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
if (key) return array.reduce((c, v) => c + v[key], 0);
|
|
16
|
+
else return array.reduce((c, v) => c + v, 0);
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {Array} array
|
|
22
|
+
* @param {string} key
|
|
23
|
+
* @returns {Number}
|
|
24
|
+
*/
|
|
25
|
+
average(array, key) {
|
|
26
|
+
if (!array) {
|
|
27
|
+
console.warn("ARRAY NOT EXITED !");
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
return this.sum(array, key) / array.length || 0;
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {Array} array
|
|
36
|
+
* @param {string} key
|
|
37
|
+
* @returns {Number}
|
|
38
|
+
*/
|
|
39
|
+
min(array, key) {
|
|
40
|
+
if (!array) {
|
|
41
|
+
console.warn("ARRAY NOT EXITED !");
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
if (array.length > 0) {
|
|
45
|
+
if (key) return array.reduce((c, v) => (c < v[key] ? c : v[key]));
|
|
46
|
+
else return array.reduce((c, v) => (c < v ? c : v));
|
|
47
|
+
}
|
|
48
|
+
return 0;
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {Array} array
|
|
54
|
+
* @param {string} key
|
|
55
|
+
* @returns {Number}
|
|
56
|
+
*/
|
|
57
|
+
max(array, key) {
|
|
58
|
+
if (!array) {
|
|
59
|
+
console.warn("ARRAY NOT EXITED !");
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
if (array.length > 0) {
|
|
63
|
+
if (key) return array.reduce((c, v) => (c > v[key] ? c : v[key]));
|
|
64
|
+
else return array.reduce((c, v) => (c > v ? c : v));
|
|
65
|
+
}
|
|
66
|
+
return 0;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param {Array} array
|
|
72
|
+
* @param {string} key
|
|
73
|
+
* @returns {Array}
|
|
74
|
+
*/
|
|
75
|
+
sortElementByString(array, key) {
|
|
76
|
+
if (!Array.isArray(array)) return [];
|
|
77
|
+
if (key)
|
|
78
|
+
return array.sort((x, y) => {
|
|
79
|
+
var a = x[key].toUpperCase(),
|
|
80
|
+
b = y[key].toUpperCase();
|
|
81
|
+
return a == b ? 0 : a > b ? 1 : -1;
|
|
82
|
+
});
|
|
83
|
+
console.log("NO KEY");
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* @param {Array} array
|
|
89
|
+
* @param {string} key
|
|
90
|
+
* @returns {Array}
|
|
91
|
+
*/
|
|
92
|
+
sortElementByNumber(array, key) {
|
|
93
|
+
if (!Array.isArray(array)) return [];
|
|
94
|
+
return array.sort((a, b) => {
|
|
95
|
+
return a[key] - b[key];
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
* @param {Array} array
|
|
102
|
+
* @returns {any}
|
|
103
|
+
*/
|
|
104
|
+
first(array) {
|
|
105
|
+
if (array) if (array.length || array.length > 0) return array[0];
|
|
106
|
+
return null;
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @param {Array} array
|
|
112
|
+
* @returns {any}
|
|
113
|
+
*/
|
|
114
|
+
last(array) {
|
|
115
|
+
if (array) if (array.length || array.length > 0) return array[array.length - 1];
|
|
116
|
+
return null;
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
* @param {Array} array
|
|
122
|
+
* @returns {any}
|
|
123
|
+
*/
|
|
124
|
+
randomIndex(array) {
|
|
125
|
+
if (array) return MathExtra.randInt(0, array.length - 1);
|
|
126
|
+
return -1;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
*
|
|
131
|
+
* @param {Array} array
|
|
132
|
+
* @returns {any}
|
|
133
|
+
*/
|
|
134
|
+
randomElement(array) {
|
|
135
|
+
if (array) return array[this.randomIndex(array)];
|
|
136
|
+
return null;
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
* @param {Array} list1
|
|
142
|
+
* @param {Array} list2
|
|
143
|
+
* @param {string} key
|
|
144
|
+
* @returns {Array}
|
|
145
|
+
*/
|
|
146
|
+
filterTwoArrayByKey(list1, list2, key) {
|
|
147
|
+
if (key) {
|
|
148
|
+
if (list1 && list2) {
|
|
149
|
+
return list1.filter((item1) => {
|
|
150
|
+
return !list2.find((item2) => {
|
|
151
|
+
return item1[key] == item2[key];
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
return list1.filter((item1) => {
|
|
157
|
+
return !list2.find((item2) => {
|
|
158
|
+
return item1 == item2;
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return [];
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
*
|
|
167
|
+
* @param {Array} target
|
|
168
|
+
* @param {Array} toMatch
|
|
169
|
+
* @returns {Boolean}
|
|
170
|
+
*/
|
|
171
|
+
allMatchInArray(target, toMatch) {
|
|
172
|
+
const found = toMatch.every((item) => {
|
|
173
|
+
return target.includes(item);
|
|
174
|
+
});
|
|
175
|
+
return found;
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
*
|
|
180
|
+
* @param {any} item
|
|
181
|
+
* @param {Array} array
|
|
182
|
+
* @returns {Array}
|
|
183
|
+
*/
|
|
184
|
+
removeItem(item, array) {
|
|
185
|
+
const index = array.indexOf(item);
|
|
186
|
+
if (index == -1) {
|
|
187
|
+
console.warn("[ArrayExtra.removeItem] Item not found.");
|
|
188
|
+
return array;
|
|
189
|
+
}
|
|
190
|
+
array.splice(index, 1);
|
|
191
|
+
return array;
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
*
|
|
196
|
+
* @param {string} key
|
|
197
|
+
* @param {any} value
|
|
198
|
+
* @param {Array} array
|
|
199
|
+
* @returns {Array}
|
|
200
|
+
*/
|
|
201
|
+
removeItemByKey(key, value, array) {
|
|
202
|
+
const foundIndex = array.findIndex((item) => {
|
|
203
|
+
return item[key] == value;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (foundIndex < 0) {
|
|
207
|
+
console.warn("[ArrayExtra.removeItemByKey] Item not found.", key, value);
|
|
208
|
+
return array;
|
|
209
|
+
}
|
|
210
|
+
array.splice(foundIndex, 1);
|
|
211
|
+
return array;
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Get an array with shuffle element
|
|
216
|
+
* @param {Array} array
|
|
217
|
+
* @param {Number} n
|
|
218
|
+
* @returns {Array}
|
|
219
|
+
*/
|
|
220
|
+
getRandom(array, n) {
|
|
221
|
+
var result = new Array(n),
|
|
222
|
+
len = array.length,
|
|
223
|
+
taken = new Array(len);
|
|
224
|
+
if (n > len) throw new RangeError("getRandom: more elements taken than available");
|
|
225
|
+
while (n--) {
|
|
226
|
+
var x = Math.floor(Math.random() * len);
|
|
227
|
+
result[n] = array[x in taken ? taken[x] : x];
|
|
228
|
+
taken[x] = --len in taken ? taken[len] : len;
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Get an array with shuffle element
|
|
235
|
+
* @param {Array} array
|
|
236
|
+
* @param {Number} n
|
|
237
|
+
* @returns {Array}
|
|
238
|
+
*/
|
|
239
|
+
getHalfRandom(array, n) {
|
|
240
|
+
var n = Math.ceil(array.length / 2);
|
|
241
|
+
return array.getRandom(n);
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @param {Array} array
|
|
246
|
+
* @returns {Array}
|
|
247
|
+
*/
|
|
248
|
+
shuffle(array) {
|
|
249
|
+
var i = array.length,
|
|
250
|
+
j,
|
|
251
|
+
temp;
|
|
252
|
+
if (i == 0) return array;
|
|
253
|
+
while (--i) {
|
|
254
|
+
j = Math.floor(Math.random() * (i + 1));
|
|
255
|
+
temp = array[i];
|
|
256
|
+
array[i] = array[j];
|
|
257
|
+
array[j] = temp;
|
|
258
|
+
}
|
|
259
|
+
return array;
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
*
|
|
264
|
+
* @param {Array} array
|
|
265
|
+
* @param {Number} oldIndex
|
|
266
|
+
* @param {Number} newIndex
|
|
267
|
+
* @returns {Array}
|
|
268
|
+
*/
|
|
269
|
+
moveIndex(array, oldIndex, newIndex) {
|
|
270
|
+
// return Math.floor(Math.random() * array.length);
|
|
271
|
+
if (newIndex >= array.length) {
|
|
272
|
+
var k = newIndex - array.length + 1;
|
|
273
|
+
while (k--) {
|
|
274
|
+
array.push(undefined);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
|
|
278
|
+
return array; // for testing
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
moveArray(array, oldIndex, newIndex) {
|
|
282
|
+
while (oldIndex < 0) {
|
|
283
|
+
oldIndex += array.length;
|
|
284
|
+
}
|
|
285
|
+
while (newIndex < 0) {
|
|
286
|
+
newIndex += array.length;
|
|
287
|
+
}
|
|
288
|
+
if (newIndex >= array.length) {
|
|
289
|
+
var k = newIndex - array.length;
|
|
290
|
+
while (k-- + 1) {
|
|
291
|
+
array.push(999);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
|
|
295
|
+
return array;
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export default ArrayExtra;
|
package/src/Browser.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { findKey } from "lodash";
|
|
2
|
+
import Swal from "sweetalert2";
|
|
3
|
+
|
|
4
|
+
const BROWSER = {
|
|
5
|
+
messenger: /\bFB[\w_]+\/(Messenger|MESSENGER)/,
|
|
6
|
+
facebook: /\bFB[\w_]+\//,
|
|
7
|
+
twitter: /\bTwitter/i,
|
|
8
|
+
line: /\bLine\//i,
|
|
9
|
+
wechat: /\bMicroMessenger\//i,
|
|
10
|
+
puffin: /\bPuffin/i,
|
|
11
|
+
miui: /\bMiuiBrowser\//i,
|
|
12
|
+
instagram: /\bInstagram/i,
|
|
13
|
+
chrome: /\bCrMo\b|CriOS|Android.*Chrome\/[.0-9]* (Mobile)?/,
|
|
14
|
+
safari: /Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari/,
|
|
15
|
+
ie: /IEMobile|MSIEMobile/,
|
|
16
|
+
firefox: /fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS/,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
let isInit = false;
|
|
20
|
+
let _listeners = [];
|
|
21
|
+
export class BrowserEvent {
|
|
22
|
+
static get CHANGED() {
|
|
23
|
+
return "changed";
|
|
24
|
+
}
|
|
25
|
+
static get VIEW_MODE_CHANGED() {
|
|
26
|
+
return "view_mode_changed";
|
|
27
|
+
}
|
|
28
|
+
static get ORIENTATION_CHANGED() {
|
|
29
|
+
return "orientation_changed";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const Browser = {
|
|
34
|
+
get ua() {
|
|
35
|
+
return navigator.userAgent || navigator.vendor || window.opera;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
get browser() {
|
|
39
|
+
return findKey(BROWSER, (regex) => regex.test(this.ua)) || "other";
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
get isMobile() {
|
|
43
|
+
return /(iPhone|Mobile|Android)/i.test(this.ua) || false;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
get isTablet() {
|
|
47
|
+
return !this.isMobile && !this.isDesktop;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
get isMobileAndTablet() {
|
|
51
|
+
return this.isMobile && this.isTablet;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
get isTouchDevice() {
|
|
55
|
+
return this.isMobileAndTablet;
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
get isDesktop() {
|
|
59
|
+
return typeof window != "undefined" && !("ontouchstart" in window);
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
get isFacebookWebview() {
|
|
63
|
+
var ua = ua;
|
|
64
|
+
return ua.indexOf("FBAN") > -1 || ua.indexOf("FBAV") > -1;
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
get isInAppWebview() {
|
|
68
|
+
const rules = ["WebView", "(iPhone|iPod|iPad)(?!.*Safari/)", "Android.*(wv|.0.0.0)"];
|
|
69
|
+
const regex = new RegExp(`(${rules.join("|")})`, "ig");
|
|
70
|
+
return Boolean(this.ua.match(regex));
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
orientation: "potrait",
|
|
74
|
+
viewMode: "normal",
|
|
75
|
+
device: "desktop",
|
|
76
|
+
init: (autoFixFullscreen = true) => {
|
|
77
|
+
isInit = true;
|
|
78
|
+
var isLandscape = false;
|
|
79
|
+
var isFullscreen = false;
|
|
80
|
+
var scope = Browser;
|
|
81
|
+
|
|
82
|
+
onResize();
|
|
83
|
+
|
|
84
|
+
window.addEventListener("resize", onResize);
|
|
85
|
+
// window.addEventListener('touchstart', onTouchMove)
|
|
86
|
+
window.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
87
|
+
|
|
88
|
+
function onTouchMove(e) {
|
|
89
|
+
if (e.changedTouches.length > 1) {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function onResize(e) {
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
var _isLandscape = window.matchMedia("(orientation: landscape)").matches;
|
|
97
|
+
var _isFullscreen = window.innerHeight >= window.outerHeight - 64;
|
|
98
|
+
|
|
99
|
+
// console.log(window.outerHeight, window.innerHeight, window.screen.height)
|
|
100
|
+
// console.log(window.outerWidth, window.innerWidth, window.screen.width)
|
|
101
|
+
|
|
102
|
+
// setCurrentOrientation(isLandscape ? "landscape" : "potrait")
|
|
103
|
+
// setCurrentView(isFullscreen ? "fullscreen" : "normal")
|
|
104
|
+
|
|
105
|
+
// var scope = Browser;
|
|
106
|
+
// console.log(scope)
|
|
107
|
+
scope.orientation = _isLandscape ? "landscape" : "potrait";
|
|
108
|
+
scope.viewMode = _isFullscreen ? "fullscreen" : "normal";
|
|
109
|
+
// console.log('window.orientation:', window.orientation)
|
|
110
|
+
|
|
111
|
+
if (scope.isDesktop) {
|
|
112
|
+
scope.device = "desktop";
|
|
113
|
+
} else if (scope.isTablet) {
|
|
114
|
+
scope.device = "tablet";
|
|
115
|
+
} else {
|
|
116
|
+
scope.device = "mobile";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (_isFullscreen != isFullscreen) {
|
|
120
|
+
scope.dispatchEvent(BrowserEvent.VIEW_MODE_CHANGED);
|
|
121
|
+
isFullscreen = _isFullscreen;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (_isLandscape != isLandscape) {
|
|
125
|
+
scope.dispatchEvent(BrowserEvent.ORIENTATION_CHANGED);
|
|
126
|
+
isLandscape = _isLandscape;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
scope.dispatchEvent(BrowserEvent.CHANGED);
|
|
130
|
+
|
|
131
|
+
if (autoFixFullscreen) {
|
|
132
|
+
if (!isLandscape) {
|
|
133
|
+
// POTRAIT
|
|
134
|
+
// window.document.body.style.height = "10000px"
|
|
135
|
+
// window.document.body.style.overflow = "auto";
|
|
136
|
+
window.document.body.style.height = "100%";
|
|
137
|
+
window.document.body.style.overflow = "hidden";
|
|
138
|
+
} else {
|
|
139
|
+
// LANDSCAPE
|
|
140
|
+
if (isFullscreen) {
|
|
141
|
+
if (scope.isMobile) {
|
|
142
|
+
window.document.body.style.height = "100%";
|
|
143
|
+
window.document.body.style.overflow = "hidden";
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
window.document.body.style.height = "10000px";
|
|
147
|
+
window.document.body.style.overflow = "auto";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}, 50);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
addEventListener: (event, cb) => {
|
|
156
|
+
if (!isInit) {
|
|
157
|
+
console.warn("You need to call 'Browser.init()' first.");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
switch (event) {
|
|
162
|
+
case BrowserEvent.CHANGED:
|
|
163
|
+
_listeners.push({ event: event, listener: cb });
|
|
164
|
+
break;
|
|
165
|
+
case BrowserEvent.CHANGED:
|
|
166
|
+
_listeners.push({ event: event, listener: cb });
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
console.warn(`No event "${event}" found`);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
dispatchEvent: (event) => {
|
|
175
|
+
var scope = Browser;
|
|
176
|
+
var response = {
|
|
177
|
+
event: event,
|
|
178
|
+
orientation: scope.orientation,
|
|
179
|
+
viewMode: scope.viewMode,
|
|
180
|
+
device: scope.device,
|
|
181
|
+
};
|
|
182
|
+
_listeners.forEach((dispatcher) => {
|
|
183
|
+
if (dispatcher.event == event) {
|
|
184
|
+
if (dispatcher.listener) dispatcher.listener(response);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
get isSupportWebGL() {
|
|
190
|
+
// return Detector.webgl();
|
|
191
|
+
var Detector = {
|
|
192
|
+
canvas: window && !!window.CanvasRenderingContext2D,
|
|
193
|
+
webgl: (function () {
|
|
194
|
+
try {
|
|
195
|
+
var canvas = document.createElement("canvas");
|
|
196
|
+
return !!(window.WebGLRenderingContext && (canvas.getContext("webgl") || canvas.getContext("experimental-webgl")));
|
|
197
|
+
} catch (e) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
})(),
|
|
201
|
+
workers: !!window.Worker,
|
|
202
|
+
fileapi: window.File && window.FileReader && window.FileList && window.Blob,
|
|
203
|
+
|
|
204
|
+
getWebGLErrorMessage: function () {
|
|
205
|
+
var element = document.createElement("div");
|
|
206
|
+
element.id = "webgl-error-message";
|
|
207
|
+
element.style.fontFamily = "monospace";
|
|
208
|
+
element.style.fontSize = "13px";
|
|
209
|
+
element.style.fontWeight = "normal";
|
|
210
|
+
element.style.textAlign = "center";
|
|
211
|
+
element.style.background = "#fff";
|
|
212
|
+
element.style.color = "#000";
|
|
213
|
+
element.style.padding = "1.5em";
|
|
214
|
+
element.style.width = "400px";
|
|
215
|
+
element.style.margin = "5em auto 0";
|
|
216
|
+
|
|
217
|
+
if (!this.webgl) {
|
|
218
|
+
element.innerHTML = window.WebGLRenderingContext
|
|
219
|
+
? [
|
|
220
|
+
'Your graphics card does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">WebGL</a>.<br />',
|
|
221
|
+
'Find out how to get it <a href="http://get.webgl.org/" style="color:#000">here</a>.',
|
|
222
|
+
].join("\n")
|
|
223
|
+
: [
|
|
224
|
+
'Your browser does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">WebGL</a>.<br/>',
|
|
225
|
+
'Find out how to get it <a href="http://get.webgl.org/" style="color:#000">here</a>.',
|
|
226
|
+
].join("\n");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return element;
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
addGetWebGLMessage: function (parameters) {
|
|
233
|
+
var parent, id, element;
|
|
234
|
+
|
|
235
|
+
parameters = parameters || {};
|
|
236
|
+
|
|
237
|
+
parent = parameters.parent !== undefined ? parameters.parent : document.body;
|
|
238
|
+
id = parameters.id !== undefined ? parameters.id : "oldie";
|
|
239
|
+
|
|
240
|
+
element = Detector.getWebGLErrorMessage();
|
|
241
|
+
element.id = id;
|
|
242
|
+
|
|
243
|
+
parent.appendChild(element);
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
return Detector.webgl;
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
requestUsingSafariIOS(options) {
|
|
251
|
+
var _this = this;
|
|
252
|
+
_this.ftpBridgeToSafari = "ftp://159.65.130.187/bridge.html";
|
|
253
|
+
_this.minChrome = "<b>Chrome</b>";
|
|
254
|
+
_this.minFirefox = "<b>Firefox</b>";
|
|
255
|
+
_this.minOpera = "<b>Opera</b>";
|
|
256
|
+
_this.brands = "<b>Samsung</b>";
|
|
257
|
+
_this.veTrangChu = "Về <b>Trang chủ</b>!";
|
|
258
|
+
_this.skip = "<b>Bỏ qua!</b>!";
|
|
259
|
+
_this.direct_link = location.host + location.pathname + "?redirect_src=inappwebview";
|
|
260
|
+
|
|
261
|
+
if (typeof gaTrackingClick != "undefined") gaTrackingClick("tee_device", "not_support_get_camera");
|
|
262
|
+
if (typeof gaTrackingClick != "undefined") gaTrackingClick("tee_browser", "no_support_webRTC");
|
|
263
|
+
|
|
264
|
+
options = typeof options != "undefined" ? options : {};
|
|
265
|
+
|
|
266
|
+
var onCancelCallback = options.hasOwnProperty("onCancelCallback") ? options["onCancelCallback"] : null;
|
|
267
|
+
|
|
268
|
+
Swal.fire({
|
|
269
|
+
html: "<b>Rất tiếc, trình duyệt trên chương trình này chưa hỗ trợ.</b> Vui lòng sử dụng Safari để có trải nghiệm tốt nhất!",
|
|
270
|
+
type: "warning",
|
|
271
|
+
allowOutsideClick: false,
|
|
272
|
+
confirmButtonText: '<a href="#" style="color: white;"">Mở Safari!</a> ',
|
|
273
|
+
showCancelButton: true,
|
|
274
|
+
cancelButtonText: '<a href="#" style="color: white;"">' + _this.skip + "</a> ",
|
|
275
|
+
}).then(function (result) {
|
|
276
|
+
if (result.value) {
|
|
277
|
+
// if (typeof gaTrackingClick != "undefined") gaTrackingClick('popup', 'tai-lai-trang');
|
|
278
|
+
// if (typeof trackingClickGA != "undefined") trackingClickGA('ChangeBrowser', 'ChangeBrowser');
|
|
279
|
+
|
|
280
|
+
// var _browser = window.deviceInfo.browser.toLowerCase();
|
|
281
|
+
// if (typeof gaTrackingClick != "undefined") gaTrackingClick('tee_browser', 'redirect_' + _browser + '_' + "safari");
|
|
282
|
+
|
|
283
|
+
window.open(_this.ftpBridgeToSafari + "?url=" + location.href);
|
|
284
|
+
// window.open(_this.ftpBridgeToSafari + "?url=" + location.href);
|
|
285
|
+
} else {
|
|
286
|
+
// if (typeof gaTrackingClick != "undefined") gaTrackingClick('tee_redirect_from_other_browser', 'cancel');
|
|
287
|
+
// if (typeof gaTrackingClick != "undefined") gaTrackingClick('popup', 'cta-trang-chu');
|
|
288
|
+
|
|
289
|
+
Swal.close();
|
|
290
|
+
if (onCancelCallback != null) onCancelCallback();
|
|
291
|
+
// window.open(basePath, "_self");
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export default Browser;
|