@wiajs/core 0.1.19 → 1.0.2
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.js +104 -73
- package/.prettierignore +5 -7
- package/LICENSE +1 -1
- package/babel.config.js +73 -19
- package/babel.web.js +86 -0
- package/dist/core.cmn.js +2209 -0
- package/dist/core.esm.js +1463 -1509
- package/dist/core.js +406 -893
- package/dist/core.min.js +9 -4
- package/gulpfile.js +57 -8
- package/index.js +2 -2
- package/package.json +17 -19
- package/prettier.config.js +4 -1
- package/test/test.js +73 -0
- package/util/tool.js +29 -26
- package/build.js +0 -102
- package/config.js +0 -69
- package/dist/core.common.js +0 -2257
- package/dist/core.common.min.js +0 -6
- package/dist/core.esm.min.js +0 -6
package/dist/core.esm.js
CHANGED
|
@@ -1,46 +1,45 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia core
|
|
3
|
-
* (c)
|
|
4
|
-
*
|
|
2
|
+
* wia core v1.0.1
|
|
3
|
+
* (c) 2015-2023 Sibyl Yu and contributors
|
|
4
|
+
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* promise version ajax get、post
|
|
8
8
|
* return Promise objext.
|
|
9
9
|
* get move to base.js
|
|
10
10
|
*/
|
|
11
|
-
var Ajax = /*#__PURE__*/function () {
|
|
12
|
-
function Ajax() {}
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
xhr.onreadystatechange = function () {
|
|
12
|
+
class Ajax {
|
|
13
|
+
post(url, data) {
|
|
14
|
+
const pm = new Promise((res, rej) => {
|
|
15
|
+
const xhr = $.getXhr();
|
|
16
|
+
xhr.onreadystatechange = () => {
|
|
21
17
|
if (xhr.readyState === 4) {
|
|
22
|
-
if (xhr.status === 200) res(xhr.responseText);
|
|
18
|
+
if (xhr.status === 200) res(xhr.responseText);
|
|
19
|
+
else rej(new Error(xhr.statusText), xhr.responseText);
|
|
23
20
|
}
|
|
24
21
|
/*
|
|
25
22
|
if ((xhr.readyState === 4) && (xhr.status === 200)) {
|
|
26
23
|
cb(xhr.responseText);
|
|
27
24
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}; // 异步 post,回调通知
|
|
31
|
-
|
|
25
|
+
*/
|
|
26
|
+
};
|
|
32
27
|
|
|
28
|
+
// 异步 post,回调通知
|
|
33
29
|
xhr.open('POST', url, true);
|
|
34
|
-
|
|
35
|
-
if (typeof data === 'object') param = objToParam(data);
|
|
30
|
+
let param = data;
|
|
31
|
+
if (typeof data === 'object') param = objToParam(data);
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
// 发送 FormData 数据, 会自动设置为 multipart/form-data
|
|
34
|
+
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
35
|
+
// xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=AaB03x');
|
|
38
36
|
// alert(param);
|
|
39
|
-
|
|
40
37
|
xhr.send(param);
|
|
41
38
|
});
|
|
39
|
+
|
|
42
40
|
return pm;
|
|
43
41
|
}
|
|
42
|
+
|
|
44
43
|
/**
|
|
45
44
|
* xmlHttpRequest POST 方法
|
|
46
45
|
* 发送 FormData 数据, 会自动设置为 multipart/form-data
|
|
@@ -49,236 +48,150 @@ var Ajax = /*#__PURE__*/function () {
|
|
|
49
48
|
* @param data 要post的数据
|
|
50
49
|
* @param cb 回调
|
|
51
50
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var xhr = $.getXhr();
|
|
57
|
-
|
|
58
|
-
xhr.onreadystatechange = function () {
|
|
51
|
+
postForm(url, data) {
|
|
52
|
+
const pm = new Promise((res, rej) => {
|
|
53
|
+
const xhr = $.getXhr();
|
|
54
|
+
xhr.onreadystatechange = () => {
|
|
59
55
|
if (xhr.readyState === 4) {
|
|
60
|
-
if (xhr.status === 200) res(null, xhr.responseText);
|
|
56
|
+
if (xhr.status === 200) res(null, xhr.responseText);
|
|
57
|
+
else rej(new Error(xhr.status), xhr.responseText);
|
|
61
58
|
}
|
|
62
|
-
};
|
|
63
|
-
|
|
59
|
+
};
|
|
64
60
|
|
|
65
|
-
|
|
61
|
+
// 异步 post,回调通知
|
|
62
|
+
xhr.open('POST', url, true);
|
|
63
|
+
// 发送 FormData 数据, 会自动设置为 multipart/form-data
|
|
66
64
|
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
67
65
|
// xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=AaB03x');
|
|
68
|
-
|
|
69
66
|
xhr.send(data);
|
|
70
67
|
});
|
|
71
|
-
return pm;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
_proto.get = function get(url, param) {
|
|
75
|
-
return $.get(url, param);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
return Ajax;
|
|
79
|
-
}();
|
|
80
|
-
|
|
81
|
-
function objToParam(obj) {
|
|
82
|
-
var rs = '';
|
|
83
|
-
var arr = [];
|
|
84
|
-
|
|
85
|
-
for (var k in obj) {
|
|
86
|
-
if (obj.hasOwnProperty(k)) {
|
|
87
|
-
arr.push(k + "=" + obj[k]);
|
|
88
|
-
} // rs += `${k}=${obj[k]}&`;
|
|
89
|
-
|
|
90
|
-
} // 排序
|
|
91
68
|
|
|
92
|
-
|
|
93
|
-
rs = arr.sort().join('&'); // alert(rs);
|
|
94
|
-
|
|
95
|
-
return rs;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function _defineProperties(target, props) {
|
|
99
|
-
for (var i = 0; i < props.length; i++) {
|
|
100
|
-
var descriptor = props[i];
|
|
101
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
102
|
-
descriptor.configurable = true;
|
|
103
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
104
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
69
|
+
return pm;
|
|
105
70
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
109
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
110
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
111
|
-
return Constructor;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function _inheritsLoose(subClass, superClass) {
|
|
115
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
116
|
-
subClass.prototype.constructor = subClass;
|
|
117
|
-
|
|
118
|
-
_setPrototypeOf(subClass, superClass);
|
|
119
|
-
}
|
|
120
71
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
o.__proto__ = p;
|
|
124
|
-
return o;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return _setPrototypeOf(o, p);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function _isNativeReflectConstruct() {
|
|
131
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
132
|
-
if (Reflect.construct.sham) return false;
|
|
133
|
-
if (typeof Proxy === "function") return true;
|
|
134
|
-
|
|
135
|
-
try {
|
|
136
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
137
|
-
return true;
|
|
138
|
-
} catch (e) {
|
|
139
|
-
return false;
|
|
72
|
+
get(url, param) {
|
|
73
|
+
return $.get(url, param);
|
|
140
74
|
}
|
|
141
75
|
}
|
|
142
76
|
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
_construct = Reflect.construct;
|
|
146
|
-
} else {
|
|
147
|
-
_construct = function _construct(Parent, args, Class) {
|
|
148
|
-
var a = [null];
|
|
149
|
-
a.push.apply(a, args);
|
|
150
|
-
var Constructor = Function.bind.apply(Parent, a);
|
|
151
|
-
var instance = new Constructor();
|
|
152
|
-
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
153
|
-
return instance;
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return _construct.apply(null, arguments);
|
|
158
|
-
}
|
|
77
|
+
function objToParam(obj) {
|
|
78
|
+
let rs = '';
|
|
159
79
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
80
|
+
const arr = [];
|
|
81
|
+
for (const k in obj) {
|
|
82
|
+
if (obj.hasOwnProperty(k)) {
|
|
83
|
+
arr.push(`${k}=${obj[k]}`);
|
|
84
|
+
}
|
|
85
|
+
// rs += `${k}=${obj[k]}&`;
|
|
163
86
|
}
|
|
164
|
-
|
|
165
|
-
|
|
87
|
+
// 排序
|
|
88
|
+
rs = arr.sort().join('&');
|
|
89
|
+
// alert(rs);
|
|
90
|
+
return rs;
|
|
166
91
|
}
|
|
167
92
|
|
|
168
93
|
/* eslint no-control-regex: "off" */
|
|
169
|
-
var _uniqueNumber = 1;
|
|
170
|
-
var Utils = {
|
|
171
|
-
uniqueNumber: function uniqueNumber() {
|
|
172
|
-
_uniqueNumber += 1;
|
|
173
|
-
return _uniqueNumber;
|
|
174
|
-
},
|
|
175
|
-
id: function id(mask, map) {
|
|
176
|
-
if (mask === void 0) {
|
|
177
|
-
mask = 'xxxxxxxxxx';
|
|
178
|
-
}
|
|
179
94
|
|
|
180
|
-
|
|
181
|
-
map = '0123456789abcdef';
|
|
182
|
-
}
|
|
95
|
+
let uniqueNumber = 1;
|
|
183
96
|
|
|
97
|
+
const Utils = {
|
|
98
|
+
uniqueNumber() {
|
|
99
|
+
uniqueNumber += 1;
|
|
100
|
+
return uniqueNumber;
|
|
101
|
+
},
|
|
102
|
+
id(mask = 'xxxxxxxxxx', map = '0123456789abcdef') {
|
|
184
103
|
return $.uid(mask, map);
|
|
185
104
|
},
|
|
186
|
-
mdPreloaderContent:
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
105
|
+
mdPreloaderContent: `
|
|
106
|
+
<span class="preloader-inner">
|
|
107
|
+
<svg viewBox="0 0 36 36">
|
|
108
|
+
<circle cx="18" cy="18" r="16"></circle>
|
|
109
|
+
</svg>
|
|
110
|
+
</span>
|
|
111
|
+
`.trim(),
|
|
112
|
+
iosPreloaderContent: `
|
|
113
|
+
<span class="preloader-inner">
|
|
114
|
+
${[0, 1, 2, 3, 4, 5, 6, 7].map(() => '<span class="preloader-inner-line"></span>').join('')}
|
|
115
|
+
</span>
|
|
116
|
+
`.trim(),
|
|
117
|
+
auroraPreloaderContent:`
|
|
118
|
+
<span class="preloader-inner">
|
|
119
|
+
<span class="preloader-inner-circle"></span>
|
|
120
|
+
</span>
|
|
121
|
+
`,
|
|
122
|
+
eventNameToColonCase(eventName) {
|
|
123
|
+
let hasColon;
|
|
124
|
+
return eventName
|
|
125
|
+
.split('')
|
|
126
|
+
.map((char, index) => {
|
|
127
|
+
if (char.match(/[A-Z]/) && index !== 0 && !hasColon) {
|
|
128
|
+
hasColon = true;
|
|
129
|
+
return `:${char.toLowerCase()}`;
|
|
130
|
+
}
|
|
131
|
+
return char.toLowerCase();
|
|
132
|
+
})
|
|
133
|
+
.join('');
|
|
201
134
|
},
|
|
202
|
-
deleteProps
|
|
135
|
+
deleteProps(obj) {
|
|
203
136
|
$.deleteProps(obj);
|
|
204
137
|
},
|
|
205
|
-
nextTick
|
|
206
|
-
if (delay === void 0) {
|
|
207
|
-
delay = 0;
|
|
208
|
-
}
|
|
209
|
-
|
|
138
|
+
nextTick(callback, delay = 0) {
|
|
210
139
|
return setTimeout(callback, delay);
|
|
211
140
|
},
|
|
212
|
-
nextFrame
|
|
141
|
+
nextFrame(cb) {
|
|
213
142
|
return $.nextFrame(cb);
|
|
214
143
|
},
|
|
215
|
-
now
|
|
144
|
+
now() {
|
|
216
145
|
return Date.now();
|
|
217
146
|
},
|
|
218
|
-
requestAnimationFrame
|
|
147
|
+
requestAnimationFrame(cb) {
|
|
219
148
|
return $.requestAnimationFrame(cb);
|
|
220
149
|
},
|
|
221
|
-
cancelAnimationFrame
|
|
150
|
+
cancelAnimationFrame(id) {
|
|
222
151
|
return $.cancelAnimationFrame(id);
|
|
223
152
|
},
|
|
224
|
-
parseUrlQuery
|
|
153
|
+
parseUrlQuery(url) {
|
|
225
154
|
return $.urlParam(url);
|
|
226
155
|
},
|
|
227
|
-
getTranslate
|
|
228
|
-
if (axis === void 0) {
|
|
229
|
-
axis = 'x';
|
|
230
|
-
}
|
|
231
|
-
|
|
156
|
+
getTranslate(el, axis = 'x') {
|
|
232
157
|
return $.getTranslate(el, axis);
|
|
233
158
|
},
|
|
234
|
-
serializeObject
|
|
235
|
-
if (parents === void 0) {
|
|
236
|
-
parents = [];
|
|
237
|
-
}
|
|
238
|
-
|
|
159
|
+
serializeObject(obj, parents = []) {
|
|
239
160
|
if (typeof obj === 'string') return obj;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
161
|
+
const resultArray = [];
|
|
162
|
+
const separator = '&';
|
|
163
|
+
let newParents;
|
|
244
164
|
function varName(name) {
|
|
245
165
|
if (parents.length > 0) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
166
|
+
let parentParts = '';
|
|
167
|
+
for (let j = 0; j < parents.length; j += 1) {
|
|
168
|
+
if (j === 0) parentParts += parents[j];
|
|
169
|
+
else parentParts += `[${encodeURIComponent(parents[j])}]`;
|
|
250
170
|
}
|
|
251
|
-
|
|
252
|
-
return parentParts + "[" + encodeURIComponent(name) + "]";
|
|
171
|
+
return `${parentParts}[${encodeURIComponent(name)}]`;
|
|
253
172
|
}
|
|
254
|
-
|
|
255
173
|
return encodeURIComponent(name);
|
|
256
174
|
}
|
|
257
|
-
|
|
258
175
|
function varValue(value) {
|
|
259
176
|
return encodeURIComponent(value);
|
|
260
177
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
var toPush;
|
|
264
|
-
|
|
178
|
+
Object.keys(obj).forEach(prop => {
|
|
179
|
+
let toPush;
|
|
265
180
|
if (Array.isArray(obj[prop])) {
|
|
266
181
|
toPush = [];
|
|
267
|
-
|
|
268
|
-
for (var i = 0; i < obj[prop].length; i += 1) {
|
|
182
|
+
for (let i = 0; i < obj[prop].length; i += 1) {
|
|
269
183
|
if (!Array.isArray(obj[prop][i]) && typeof obj[prop][i] === 'object') {
|
|
270
184
|
newParents = parents.slice();
|
|
271
185
|
newParents.push(prop);
|
|
272
186
|
newParents.push(String(i));
|
|
273
187
|
toPush.push(Utils.serializeObject(obj[prop][i], newParents));
|
|
274
188
|
} else {
|
|
275
|
-
toPush.push(varName(prop)
|
|
189
|
+
toPush.push(`${varName(prop)}[]=${varValue(obj[prop][i])}`);
|
|
276
190
|
}
|
|
277
191
|
}
|
|
278
|
-
|
|
279
192
|
if (toPush.length > 0) resultArray.push(toPush.join(separator));
|
|
280
193
|
} else if (obj[prop] === null || obj[prop] === '') {
|
|
281
|
-
resultArray.push(varName(prop)
|
|
194
|
+
resultArray.push(`${varName(prop)}=`);
|
|
282
195
|
} else if (typeof obj[prop] === 'object') {
|
|
283
196
|
// Object, convert to named array
|
|
284
197
|
newParents = parents.slice();
|
|
@@ -287,154 +200,136 @@ var Utils = {
|
|
|
287
200
|
if (toPush !== '') resultArray.push(toPush);
|
|
288
201
|
} else if (typeof obj[prop] !== 'undefined' && obj[prop] !== '') {
|
|
289
202
|
// Should be string or plain value
|
|
290
|
-
resultArray.push(varName(prop)
|
|
203
|
+
resultArray.push(`${varName(prop)}=${varValue(obj[prop])}`);
|
|
291
204
|
} else if (obj[prop] === '') resultArray.push(varName(prop));
|
|
292
205
|
});
|
|
293
206
|
return resultArray.join(separator);
|
|
294
207
|
},
|
|
295
|
-
isObject
|
|
208
|
+
isObject(o) {
|
|
296
209
|
return typeof o === 'object' && o !== null && o.constructor && o.constructor === Object;
|
|
297
210
|
},
|
|
298
|
-
merge
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return (_$ = $).merge.apply(_$, arguments);
|
|
211
|
+
merge(...args) {
|
|
212
|
+
return $.merge(...args);
|
|
302
213
|
},
|
|
303
|
-
extend
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
307
|
-
args[_key] = arguments[_key];
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
var to = args[0];
|
|
214
|
+
extend(...args) {
|
|
215
|
+
const to = args[0];
|
|
311
216
|
args.splice(0, 1);
|
|
312
|
-
return
|
|
217
|
+
return $.assign(to, ...args);
|
|
313
218
|
},
|
|
314
219
|
// ���������ʵ�������������ԡ���������
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(h);
|
|
335
|
-
return result ? result.slice(1).map(function (n) {
|
|
336
|
-
return parseInt(n, 16);
|
|
337
|
-
}) : null;
|
|
220
|
+
bindMethods(instance, obj) {
|
|
221
|
+
Object.keys(obj).forEach((key) => {
|
|
222
|
+
if (this.isObject(obj[key])) {
|
|
223
|
+
Object.keys(obj[key]).forEach((subKey) => {
|
|
224
|
+
if (typeof obj[key][subKey] === 'function') {
|
|
225
|
+
obj[key][subKey] = obj[key][subKey].bind(instance);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
instance[key] = obj[key];
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
colorHexToRgb(hex) {
|
|
233
|
+
const h = hex.replace(
|
|
234
|
+
/^#?([a-f\d])([a-f\d])([a-f\d])$/i,
|
|
235
|
+
(m, r, g, b) => r + r + g + g + b + b
|
|
236
|
+
);
|
|
237
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(h);
|
|
238
|
+
return result ? result.slice(1).map(n => parseInt(n, 16)) : null;
|
|
338
239
|
},
|
|
339
|
-
colorRgbToHex
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
240
|
+
colorRgbToHex(r, g, b) {
|
|
241
|
+
const result = [r, g, b]
|
|
242
|
+
.map(n => {
|
|
243
|
+
const hex = n.toString(16);
|
|
244
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
245
|
+
})
|
|
246
|
+
.join('');
|
|
247
|
+
return `#${result}`;
|
|
345
248
|
},
|
|
346
|
-
colorRgbToHsl
|
|
249
|
+
colorRgbToHsl(r, g, b) {
|
|
347
250
|
r /= 255; // eslint-disable-line
|
|
348
|
-
|
|
349
251
|
g /= 255; // eslint-disable-line
|
|
350
|
-
|
|
351
252
|
b /= 255; // eslint-disable-line
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
253
|
+
const max = Math.max(r, g, b);
|
|
254
|
+
const min = Math.min(r, g, b);
|
|
255
|
+
const d = max - min;
|
|
256
|
+
let h;
|
|
257
|
+
if (d === 0) h = 0;
|
|
258
|
+
else if (max === r) h = ((g - b) / d) % 6;
|
|
259
|
+
else if (max === g) h = (b - r) / d + 2;
|
|
260
|
+
else if (max === b) h = (r - g) / d + 4;
|
|
261
|
+
const l = (min + max) / 2;
|
|
262
|
+
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
360
263
|
if (h < 0) h = 360 / 60 + h;
|
|
361
264
|
return [h * 60, s, l];
|
|
362
265
|
},
|
|
363
|
-
colorHslToRgb
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
266
|
+
colorHslToRgb(h, s, l) {
|
|
267
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
268
|
+
const hp = h / 60;
|
|
269
|
+
const x = c * (1 - Math.abs((hp % 2) - 1));
|
|
270
|
+
let rgb1;
|
|
369
271
|
if (Number.isNaN(h) || typeof h === 'undefined') {
|
|
370
272
|
rgb1 = [0, 0, 0];
|
|
371
|
-
} else if (hp <= 1) rgb1 = [c, x, 0];
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
273
|
+
} else if (hp <= 1) rgb1 = [c, x, 0];
|
|
274
|
+
else if (hp <= 2) rgb1 = [x, c, 0];
|
|
275
|
+
else if (hp <= 3) rgb1 = [0, c, x];
|
|
276
|
+
else if (hp <= 4) rgb1 = [0, x, c];
|
|
277
|
+
else if (hp <= 5) rgb1 = [x, 0, c];
|
|
278
|
+
else if (hp <= 6) rgb1 = [c, 0, x];
|
|
279
|
+
const m = l - c / 2;
|
|
280
|
+
return rgb1.map(n => Math.max(0, Math.min(255, Math.round(255 * (n + m)))));
|
|
377
281
|
},
|
|
378
|
-
colorHsbToHsl
|
|
379
|
-
|
|
380
|
-
h
|
|
282
|
+
colorHsbToHsl(h, s, b) {
|
|
283
|
+
const HSL = {
|
|
284
|
+
h,
|
|
381
285
|
s: 0,
|
|
382
|
-
l: 0
|
|
286
|
+
l: 0,
|
|
383
287
|
};
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
HSL.s = HSL.l && HSL.l < 1 ? HSB.s * HSB.b / (HSL.l < 0.5 ? HSL.l * 2 : 2 - HSL.l * 2) : HSL.s;
|
|
288
|
+
const HSB = {h, s, b};
|
|
289
|
+
|
|
290
|
+
HSL.l = ((2 - HSB.s) * HSB.b) / 2;
|
|
291
|
+
HSL.s =
|
|
292
|
+
HSL.l && HSL.l < 1 ? (HSB.s * HSB.b) / (HSL.l < 0.5 ? HSL.l * 2 : 2 - HSL.l * 2) : HSL.s;
|
|
293
|
+
|
|
391
294
|
return [HSL.h, HSL.s, HSL.l];
|
|
392
295
|
},
|
|
393
|
-
colorHslToHsb
|
|
394
|
-
|
|
395
|
-
h
|
|
296
|
+
colorHslToHsb(h, s, l) {
|
|
297
|
+
const HSB = {
|
|
298
|
+
h,
|
|
396
299
|
s: 0,
|
|
397
|
-
b: 0
|
|
300
|
+
b: 0,
|
|
398
301
|
};
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
l: l
|
|
403
|
-
};
|
|
404
|
-
var t = HSL.s * (HSL.l < 0.5 ? HSL.l : 1 - HSL.l);
|
|
302
|
+
const HSL = {h, s, l};
|
|
303
|
+
|
|
304
|
+
const t = HSL.s * (HSL.l < 0.5 ? HSL.l : 1 - HSL.l);
|
|
405
305
|
HSB.b = HSL.l + t;
|
|
406
|
-
HSB.s = HSL.l > 0 ? 2 * t / HSB.b : HSB.s;
|
|
306
|
+
HSB.s = HSL.l > 0 ? (2 * t) / HSB.b : HSB.s;
|
|
307
|
+
|
|
407
308
|
return [HSB.h, HSB.s, HSB.b];
|
|
408
309
|
},
|
|
409
|
-
colorThemeCSSProperties
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
414
|
-
args[_key2] = arguments[_key2];
|
|
415
|
-
}
|
|
416
|
-
|
|
310
|
+
colorThemeCSSProperties(...args) {
|
|
311
|
+
let hex;
|
|
312
|
+
let rgb;
|
|
417
313
|
if (args.length === 1) {
|
|
418
314
|
hex = args[0];
|
|
419
315
|
rgb = Utils.colorHexToRgb(hex);
|
|
420
316
|
} else if (args.length === 3) {
|
|
421
317
|
rgb = args;
|
|
422
|
-
hex = Utils.colorRgbToHex
|
|
318
|
+
hex = Utils.colorRgbToHex(...rgb);
|
|
423
319
|
}
|
|
424
|
-
|
|
425
320
|
if (!rgb) return {};
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
321
|
+
const hsl = Utils.colorRgbToHsl(...rgb);
|
|
322
|
+
const hslShade = [hsl[0], hsl[1], Math.max(0, hsl[2] - 0.08)];
|
|
323
|
+
const hslTint = [hsl[0], hsl[1], Math.max(0, hsl[2] + 0.08)];
|
|
324
|
+
const shade = Utils.colorRgbToHex(...Utils.colorHslToRgb(...hslShade));
|
|
325
|
+
const tint = Utils.colorRgbToHex(...Utils.colorHslToRgb(...hslTint));
|
|
431
326
|
return {
|
|
432
327
|
'--f7-theme-color': hex,
|
|
433
328
|
'--f7-theme-color-rgb': rgb.join(', '),
|
|
434
329
|
'--f7-theme-color-shade': shade,
|
|
435
|
-
'--f7-theme-color-tint': tint
|
|
330
|
+
'--f7-theme-color-tint': tint,
|
|
436
331
|
};
|
|
437
|
-
}
|
|
332
|
+
},
|
|
438
333
|
};
|
|
439
334
|
|
|
440
335
|
/**
|
|
@@ -442,429 +337,594 @@ var Utils = {
|
|
|
442
337
|
* 需要支持事件的对象,可以从这个类继承,则类实例具备事件功能。
|
|
443
338
|
* Fork from Framework7,
|
|
444
339
|
*/
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
340
|
+
class Event {
|
|
341
|
+
/**
|
|
342
|
+
* 页面Page实例事件触发,f7 UI组件需要
|
|
343
|
+
* @param {Object} params 参数
|
|
344
|
+
* @param {Array} parents 事件组件的父对象,用于向上传播事件!
|
|
345
|
+
* 组件的parents 是 Page实例,Page实例的Parent是App实例
|
|
346
|
+
* @param {String} pre 向上传播前缀,避免事件重名冲突
|
|
347
|
+
* @private
|
|
348
|
+
*/
|
|
349
|
+
constructor(params = {}, parents = [], pre = '') {
|
|
350
|
+
const m = this;
|
|
351
|
+
m.params = params;
|
|
352
|
+
|
|
353
|
+
if (parents) {
|
|
354
|
+
if (!Array.isArray(parents)) m.eventsParents = [parents];
|
|
355
|
+
else m.eventsParents = parents.filter(p => p);
|
|
356
|
+
} else m.eventsParents = [];
|
|
357
|
+
|
|
358
|
+
m.eventsListeners = {};
|
|
359
|
+
m.pre = pre;
|
|
360
|
+
|
|
361
|
+
// 通过 params 中的 on 加载事件响应
|
|
362
|
+
if (m.params && m.params.on) {
|
|
363
|
+
Object.keys(m.params.on).forEach(eventName => {
|
|
364
|
+
m.on(eventName, m.params.on[eventName]);
|
|
463
365
|
});
|
|
464
366
|
}
|
|
465
367
|
}
|
|
466
368
|
|
|
467
|
-
|
|
369
|
+
/**
|
|
370
|
+
* 添加事件响应函数
|
|
371
|
+
* @param {*} events 多个事件用空格隔开
|
|
372
|
+
* @param {*} handler 事件响应函数
|
|
373
|
+
* @param {*} priority 是否优先,缺省不优先
|
|
374
|
+
* @returns
|
|
375
|
+
*/
|
|
376
|
+
on(events, handler, priority = false) {
|
|
377
|
+
const m = this;
|
|
378
|
+
if (typeof handler !== 'function') return m;
|
|
379
|
+
const method = priority ? 'unshift' : 'push';
|
|
380
|
+
events.split(' ').forEach(event => {
|
|
381
|
+
const lis = {
|
|
382
|
+
owner: '',
|
|
383
|
+
appName: '',
|
|
384
|
+
handler,
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// 应用事件
|
|
388
|
+
if (event.includes('app::')) {
|
|
389
|
+
let page = null;
|
|
390
|
+
if ($.isPage(m)) page = m;
|
|
391
|
+
else if ($.isPage(m?.page)) page = m.page;
|
|
392
|
+
else if ($.isPage(m?.parent)) page = m.parent;
|
|
393
|
+
|
|
394
|
+
if (page && page.app && $.isApp(page.app)) {
|
|
395
|
+
lis.owner = page.owner;
|
|
396
|
+
lis.appName = page.appName;
|
|
397
|
+
const {app} = page;
|
|
398
|
+
|
|
399
|
+
const ev = event.replace('app::', '');
|
|
400
|
+
if (!app.eventsListeners[ev]) app.eventsListeners[ev] = [];
|
|
401
|
+
app.eventsListeners[ev][method](lis);
|
|
402
|
+
}
|
|
403
|
+
} else {
|
|
404
|
+
// 对象自身事件
|
|
405
|
+
if (!m.eventsListeners[event]) m.eventsListeners[event] = [];
|
|
468
406
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (typeof handler !== 'function') return self;
|
|
472
|
-
var method = priority ? 'unshift' : 'push';
|
|
473
|
-
events.split(' ').forEach(function (event) {
|
|
474
|
-
if (!self.eventsListeners[event]) self.eventsListeners[event] = [];
|
|
475
|
-
self.eventsListeners[event][method](handler);
|
|
407
|
+
m.eventsListeners[event][method](lis);
|
|
408
|
+
}
|
|
476
409
|
});
|
|
477
|
-
return self;
|
|
478
|
-
};
|
|
479
410
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (typeof handler !== 'function') return self;
|
|
411
|
+
return m;
|
|
412
|
+
}
|
|
483
413
|
|
|
484
|
-
|
|
485
|
-
|
|
414
|
+
/**
|
|
415
|
+
* 调用一次后清除
|
|
416
|
+
* @param {*} events 多个事件用空格隔开
|
|
417
|
+
* @param {*} handler 事件响应函数
|
|
418
|
+
* @param {*} priority 是否优先,缺省不优先
|
|
419
|
+
* @returns
|
|
420
|
+
*/
|
|
421
|
+
once(events, handler, priority = false) {
|
|
422
|
+
const m = this;
|
|
423
|
+
if (typeof handler !== 'function') return m;
|
|
486
424
|
|
|
425
|
+
// 调用一次后自动删除事件
|
|
426
|
+
function onceHandler(...args) {
|
|
427
|
+
m.off(events, onceHandler);
|
|
487
428
|
if (onceHandler.proxy) {
|
|
429
|
+
onceHandler.proxy.apply(m, args);
|
|
488
430
|
delete onceHandler.proxy;
|
|
489
431
|
}
|
|
490
|
-
|
|
491
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
492
|
-
args[_key] = arguments[_key];
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
handler.apply(self, args);
|
|
496
432
|
}
|
|
497
433
|
|
|
498
434
|
onceHandler.proxy = handler;
|
|
499
|
-
return
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
435
|
+
return m.on(events, onceHandler, priority);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* 删除事件响应函数
|
|
440
|
+
* @param {*} events 事件,多个事件空格隔开,不传则清除该对象所有事件响应函数
|
|
441
|
+
* @param {*} handler 事件响应函数
|
|
442
|
+
* @returns
|
|
443
|
+
*/
|
|
444
|
+
off(events, handler) {
|
|
445
|
+
const m = this;
|
|
446
|
+
if (!m.eventsListeners) return m;
|
|
447
|
+
|
|
448
|
+
if (events) {
|
|
449
|
+
events.split(' ').forEach(event => {
|
|
450
|
+
if (typeof handler === 'undefined') m.eventsListeners[event] = [];
|
|
451
|
+
else if (m.eventsListeners[event]) {
|
|
452
|
+
const arr = m.eventsListeners[event];
|
|
453
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
454
|
+
const lis = arr[i];
|
|
455
|
+
if (lis.handler === handler || lis.handler?.proxy === handler)
|
|
456
|
+
arr.splice(i, 1);
|
|
512
457
|
}
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
} else m.eventsListeners = {};
|
|
461
|
+
|
|
462
|
+
return m;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* 事件触发,应用事件只能由 Page 实例触发,才能按同页面所有者触发事件
|
|
467
|
+
* @param {*} 事件,字符串、数组或对象
|
|
468
|
+
* @param {*} 数据,传递到事件响应函数的数据
|
|
469
|
+
*/
|
|
470
|
+
emit(...args) {
|
|
471
|
+
const m = this;
|
|
472
|
+
if (!m.eventsListeners) return m;
|
|
473
|
+
|
|
474
|
+
let events;
|
|
475
|
+
let data;
|
|
476
|
+
let context;
|
|
477
|
+
let eventsParents;
|
|
478
|
+
|
|
479
|
+
let pop = false;
|
|
480
|
+
|
|
481
|
+
let event = args[0]; // 事件
|
|
482
|
+
if (!event) return m;
|
|
483
|
+
|
|
484
|
+
// 原始触发事件
|
|
485
|
+
if (typeof event === 'string' || Array.isArray(event)) {
|
|
486
|
+
event = event.split(' ');
|
|
487
|
+
// 带前缀,自动添加前缀向父节点传递事件
|
|
488
|
+
if (m.pre) {
|
|
489
|
+
events = [];
|
|
490
|
+
event.forEach(ev => {
|
|
491
|
+
events.push(`.${ev}`); // 本组件事件
|
|
492
|
+
events.push(`${m.pre}${ev[0].toUpperCase()}${ev.substr(1)}`); // 向上事件
|
|
513
493
|
});
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
return self;
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
_proto.emit = function emit() {
|
|
520
|
-
var self = this;
|
|
521
|
-
if (!self.eventsListeners) return self;
|
|
522
|
-
var events;
|
|
523
|
-
var data;
|
|
524
|
-
var context;
|
|
525
|
-
var eventsParents;
|
|
526
|
-
|
|
527
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
528
|
-
args[_key2] = arguments[_key2];
|
|
529
|
-
}
|
|
494
|
+
} else events = event;
|
|
530
495
|
|
|
531
|
-
if (typeof args[0] === 'string' || Array.isArray(args[0])) {
|
|
532
|
-
events = args[0];
|
|
533
496
|
data = args.slice(1, args.length);
|
|
534
|
-
context =
|
|
535
|
-
eventsParents =
|
|
497
|
+
context = m;
|
|
498
|
+
eventsParents = m.eventsParents;
|
|
536
499
|
} else {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
500
|
+
// 冒泡向上传递事件,或指定对象触发事件
|
|
501
|
+
pop = event.pop;
|
|
502
|
+
events = event.events;
|
|
503
|
+
data = event.data;
|
|
504
|
+
context = event.context || m;
|
|
505
|
+
eventsParents = event.local ? [] : event.parents || m.eventsParents;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const eventsArray = Array.isArray(events) ? events : events.split(' ');
|
|
509
|
+
|
|
510
|
+
// 本对象事件
|
|
511
|
+
// ['local:event'] or ['.event'],不向父组件传递
|
|
512
|
+
const selfEvents = eventsArray.map(ev => ev.replace(/local::|^[.]/, ''));
|
|
513
|
+
|
|
514
|
+
// 非本对象事件,向上传递时,转换为对象,记录来源
|
|
515
|
+
let parentEvents = null;
|
|
516
|
+
if (pop) parentEvents = event;
|
|
517
|
+
else {
|
|
518
|
+
const popEvents = eventsArray.filter(ev => !ev.match(/^local::|^[.]/));
|
|
519
|
+
if (popEvents?.length) {
|
|
520
|
+
parentEvents = {
|
|
521
|
+
pop: true, // 冒泡事件
|
|
522
|
+
events: popEvents,
|
|
523
|
+
context: m, // 事件发起者
|
|
524
|
+
data,
|
|
525
|
+
owner: '',
|
|
526
|
+
appName: '',
|
|
527
|
+
};
|
|
528
|
+
}
|
|
541
529
|
}
|
|
542
530
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
531
|
+
// 记录page属性,标记事件来源,冒泡到app时判断是否触发本页面应用事件
|
|
532
|
+
if (parentEvents && $.isPage(m)) {
|
|
533
|
+
parentEvents.owner = m?.owner;
|
|
534
|
+
parentEvents.appName = m?.appName;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// 调用对象事件函数,父对象emit后,调用父对象事件函数
|
|
538
|
+
selfEvents.forEach(ev => {
|
|
539
|
+
if (m.eventsListeners && m.eventsListeners[ev]) {
|
|
540
|
+
const handlers = [];
|
|
541
|
+
m.eventsListeners[ev].forEach(lis => {
|
|
542
|
+
// 应用事件,需判断所有者
|
|
543
|
+
if (lis.owner && lis.appName) {
|
|
544
|
+
// 同一html页面运行多个应用页面层时,只有所有者、应用名称相同才能触发跨页面事件,避免跨应用事件安全问题。
|
|
545
|
+
// 页面冒泡到应用事件
|
|
546
|
+
if (pop && lis.owner === ev.owner && lis.appName === ev.appName)
|
|
547
|
+
handlers.push(lis.handler);
|
|
548
|
+
} else handlers.push(lis.handler);
|
|
555
549
|
});
|
|
556
|
-
|
|
557
|
-
|
|
550
|
+
|
|
551
|
+
// 由 window 对象异步调用,而不是事件对象直接调用
|
|
552
|
+
handlers.forEach(fn => {
|
|
553
|
+
// setTimeout(() => fn.apply(context, data), 0);
|
|
554
|
+
fn.apply(context, data); // this 指针为原始触发事件对象,事件函数中可引用
|
|
558
555
|
});
|
|
559
556
|
}
|
|
560
557
|
});
|
|
561
558
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
});
|
|
559
|
+
// 向上一级一级迭代冒泡传递后,触发父对象事件响应函数
|
|
560
|
+
if (parentEvents && eventsParents?.length > 0) {
|
|
561
|
+
eventsParents.forEach(eventsParent => eventsParent.emit(parentEvents));
|
|
566
562
|
}
|
|
567
563
|
|
|
568
|
-
return
|
|
569
|
-
}
|
|
564
|
+
return m;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
570
567
|
|
|
571
|
-
|
|
572
|
-
|
|
568
|
+
/**
|
|
569
|
+
* 所有页面从该类继承,并必须实现 load 事件!
|
|
570
|
+
* 事件
|
|
571
|
+
* 五个个事件:load -> ready -> show / hide -> unload
|
|
572
|
+
* load:必选,加载视图、代码,第一次加载后缓存,后续不会重复加载,动态代码也要在这里加载
|
|
573
|
+
* 参数;param
|
|
574
|
+
* 如果需要前路由数据,通过 $.lastPage.data 访问
|
|
575
|
+
* view 还未创建,隐藏page 不存在
|
|
576
|
+
* ready:可选,对视图中的对象事件绑定,已经缓存的视图,比如回退,不会再次触发 ready
|
|
577
|
+
* 参数;view、param
|
|
578
|
+
* 如果需要前路由数据,通过 $.lastPage.data 访问
|
|
579
|
+
* show:可选,视图显示时触发,可以接收参数,操作视图,无论是否缓存(比如回退)都会触发
|
|
580
|
+
* 对于已经加载、绑定隐藏(缓存)的页面,重新显示时,不会触发load和ready,只会触发show
|
|
581
|
+
* 参数:view、param
|
|
582
|
+
* hide:可选,视图卸载删除时触发,适合保存卸载页面的数据,卸载的页面从页面删除,进入缓存
|
|
583
|
+
* unload:可选,页面从缓存中删除时触发,目前暂未实现
|
|
584
|
+
*
|
|
585
|
+
* 数据传递
|
|
586
|
+
* 每个页面都能访问当前路由,路由存在以下参数,用户跨页面数据传递
|
|
587
|
+
* url:页面跳转时的原始网址
|
|
588
|
+
* param:页面网址及go中传入的参数合并,保存在 param 中
|
|
589
|
+
* data:路由中需要保存的数据
|
|
590
|
+
* view:当前页面层,dom 对象,已经包括绑定的事件
|
|
591
|
+
* $.page:当前页面对象
|
|
592
|
+
* $.lastPage:前路由,可通过该参数,获取前路由的 data,在后续路由中使用
|
|
593
|
+
*
|
|
594
|
+
*/
|
|
573
595
|
|
|
574
|
-
var Module = /*#__PURE__*/function (_Event) {
|
|
575
|
-
_inheritsLoose(Module, _Event);
|
|
576
596
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
597
|
+
class Page extends Event {
|
|
598
|
+
constructor(app, name, title, style) {
|
|
599
|
+
super(null, [app]);
|
|
600
|
+
this.app = app; // 应用实例
|
|
601
|
+
this.cfg = app.cfg;
|
|
602
|
+
this.name = name; // 名称,可带路径 admin/login
|
|
603
|
+
this.title = title; // 浏览器标题
|
|
604
|
+
this.style = style || `./page/${name}.css`;
|
|
605
|
+
|
|
606
|
+
// 以下变量由路由器赋值
|
|
607
|
+
this.owner = '';
|
|
608
|
+
this.appName = '';
|
|
609
|
+
this.path = '';
|
|
610
|
+
this.view = null; // 页面的div层$Dom对象,router创建实例时赋值
|
|
611
|
+
this.dom = null; // 页面的div层dom对象,router创建实例时赋值
|
|
612
|
+
this.$el = null; // $dom === view
|
|
613
|
+
this.el = null; // dom === dom
|
|
614
|
+
|
|
615
|
+
this.html = ''; // 页面html文本,router创建实例时赋值
|
|
616
|
+
this.css = ''; // 页面css样式,router创建实例时赋值
|
|
617
|
+
this.js = ''; // 页面代码,router创建实例时赋值
|
|
618
|
+
this.data = {}; // 页面数据对象
|
|
619
|
+
this.param = {}; // 页面切换传递进来的参数对象,router创建实例时赋值
|
|
620
|
+
}
|
|
581
621
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
622
|
+
/**
|
|
623
|
+
* 异步加载页面视图内容
|
|
624
|
+
* 返回Promise对象
|
|
625
|
+
* @param {*} param
|
|
626
|
+
* @param {*} cfg
|
|
627
|
+
*/
|
|
628
|
+
load(param) {
|
|
629
|
+
// $.assign(this.data, param);
|
|
630
|
+
this.emit('local::load pageLoad', param);
|
|
631
|
+
this.emit('pageLoad', this);
|
|
632
|
+
}
|
|
585
633
|
|
|
586
|
-
|
|
587
|
-
|
|
634
|
+
/**
|
|
635
|
+
* 在已经加载就绪的视图上操作
|
|
636
|
+
* @param {*} view 页面层的 Dom 对象,已经使用`$(#page-name)`,做了处理
|
|
637
|
+
* @param {*} param go 函数的参数,或 网址中 url 中的参数
|
|
638
|
+
* @param {*} back 是否为回退,A->B, B->A,这种操作属于回退
|
|
639
|
+
*/
|
|
640
|
+
ready(view, param, back) {
|
|
641
|
+
// $.assign(this, {page, param, back});
|
|
642
|
+
// $.assign(this.data, param);
|
|
643
|
+
// 隐藏所有模板
|
|
644
|
+
this.init();
|
|
645
|
+
this.emit('local::ready', view, param, back);
|
|
646
|
+
// 向上触发跨页面事件,存在安全问题
|
|
647
|
+
this.emit('pageReady', this);
|
|
648
|
+
}
|
|
588
649
|
|
|
650
|
+
/**
|
|
651
|
+
* 对页面进行初始化处理,或页面内容动态变更时,对局部页面容器进行初始化
|
|
652
|
+
* @param {*} v dom 容器,默认为页面实例的view
|
|
653
|
+
*/
|
|
654
|
+
init(v) {
|
|
655
|
+
const {view} = this;
|
|
656
|
+
v = v ? $(v) : view;
|
|
657
|
+
}
|
|
589
658
|
|
|
590
|
-
|
|
659
|
+
// 显示已加载的页面
|
|
660
|
+
// view:页面Dom层,param:参数
|
|
661
|
+
show(view, param) {
|
|
662
|
+
// 隐藏所有模板
|
|
663
|
+
view.qus('[name$=-tp]').hide();
|
|
664
|
+
// 防止空链接,刷新页面
|
|
665
|
+
view.qus('a[href=""]').attr('href', 'javascript:;');
|
|
666
|
+
// this.init();
|
|
667
|
+
if (this.reset) this.reset();
|
|
668
|
+
this.emit('local::show', view, param);
|
|
669
|
+
// 向上触发跨页面事件,存在安全问题
|
|
670
|
+
this.emit('pageShow', this);
|
|
671
|
+
}
|
|
591
672
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
$.extend(instanceParams, module.params);
|
|
600
|
-
Object.keys(originalParams).forEach(function (paramKey) {
|
|
601
|
-
$.extend(instanceParams[paramKey], originalParams[paramKey]);
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
};
|
|
673
|
+
// 回退显示已加载的页面
|
|
674
|
+
// view:页面Dom层,param:参数
|
|
675
|
+
back(view, param) {
|
|
676
|
+
// 隐藏所有模板
|
|
677
|
+
view.qus('[name$=-tp]').hide();
|
|
678
|
+
// 防止空链接,刷新页面
|
|
679
|
+
view.qus('a[href=""]').attr('href', 'javascript:;');
|
|
605
680
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
var module = instance.modules[moduleName]; // Extend params
|
|
681
|
+
this.emit('local::back', view, param);
|
|
682
|
+
// 向上触发跨页面事件,存在安全问题
|
|
683
|
+
this.emit('pageBack', this);
|
|
684
|
+
}
|
|
611
685
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
686
|
+
hide(view) {
|
|
687
|
+
this.emit('local::hide', view);
|
|
688
|
+
// 向上触发跨页面事件,存在安全问题
|
|
689
|
+
this.emit('pageHide', this);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
unload(view) {
|
|
693
|
+
this.emit('local::unload', view);
|
|
694
|
+
// 向上触发跨页面事件,存在安全问题
|
|
695
|
+
this.emit('pageUnload', this);
|
|
616
696
|
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Wia app、router等继承类,通过模块化扩展类功能
|
|
701
|
+
*/
|
|
702
|
+
|
|
703
|
+
class Module extends Event {
|
|
704
|
+
constructor(params = {}, parents = []) {
|
|
705
|
+
super(params, parents);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// eslint-disable-next-line
|
|
709
|
+
useModuleParams(module, instanceParams) {
|
|
710
|
+
if (module.params) {
|
|
711
|
+
const originalParams = {};
|
|
712
|
+
Object.keys(module.params).forEach(paramKey => {
|
|
713
|
+
if (typeof instanceParams[paramKey] === 'undefined') return;
|
|
714
|
+
originalParams[paramKey] = $.extend({}, instanceParams[paramKey]);
|
|
715
|
+
});
|
|
716
|
+
$.extend(instanceParams, module.params);
|
|
717
|
+
Object.keys(originalParams).forEach(paramKey => {
|
|
718
|
+
$.extend(instanceParams[paramKey], originalParams[paramKey]);
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
useModulesParams(instanceParams) {
|
|
724
|
+
const instance = this;
|
|
725
|
+
if (!instance.modules) return;
|
|
726
|
+
Object.keys(instance.modules).forEach(moduleName => {
|
|
727
|
+
const module = instance.modules[moduleName];
|
|
728
|
+
// Extend params
|
|
729
|
+
if (module.params) {
|
|
730
|
+
$.extend(instanceParams, module.params);
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
|
|
617
735
|
/**
|
|
618
736
|
* 将扩展模块的相关方法、事件加载到类实例
|
|
619
737
|
* @param {*} moduleName 扩展模块名称
|
|
620
|
-
* @param {*} moduleParams
|
|
621
|
-
*/
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
if (
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
module.create.bind(instance)(moduleParams);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
738
|
+
* @param {*} moduleParams
|
|
739
|
+
*/
|
|
740
|
+
useModule(moduleName = '', moduleParams = {}) {
|
|
741
|
+
const instance = this;
|
|
742
|
+
if (!instance.modules) return;
|
|
743
|
+
|
|
744
|
+
// 从原型中获得的模块类引用
|
|
745
|
+
const module =
|
|
746
|
+
typeof moduleName === 'string'
|
|
747
|
+
? instance.modules[moduleName]
|
|
748
|
+
: moduleName;
|
|
749
|
+
if (!module) return;
|
|
750
|
+
|
|
751
|
+
// 扩展实例的方法和属性,Extend instance methods and props
|
|
752
|
+
if (module.instance) {
|
|
753
|
+
Object.keys(module.instance).forEach(modulePropName => {
|
|
754
|
+
const moduleProp = module.instance[modulePropName];
|
|
755
|
+
if (typeof moduleProp === 'function') {
|
|
756
|
+
instance[modulePropName] = moduleProp.bind(instance);
|
|
757
|
+
} else {
|
|
758
|
+
instance[modulePropName] = moduleProp;
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// 将扩展模块中的on加载到实例的事件侦听中,比如 init 在实例初始化时被调用
|
|
764
|
+
if (module.on && instance.on) {
|
|
765
|
+
Object.keys(module.on).forEach(moduleEventName => {
|
|
766
|
+
instance.on(moduleEventName, module.on[moduleEventName]);
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// 加载扩展模块的vnodeHooks,Add vnode hooks
|
|
771
|
+
if (module.vnode) {
|
|
772
|
+
if (!instance.vnodeHooks) instance.vnodeHooks = {};
|
|
773
|
+
Object.keys(module.vnode).forEach(vnodeId => {
|
|
774
|
+
Object.keys(module.vnode[vnodeId]).forEach(hookName => {
|
|
775
|
+
const handler = module.vnode[vnodeId][hookName];
|
|
776
|
+
if (!instance.vnodeHooks[hookName])
|
|
777
|
+
instance.vnodeHooks[hookName] = {};
|
|
778
|
+
if (!instance.vnodeHooks[hookName][vnodeId])
|
|
779
|
+
instance.vnodeHooks[hookName][vnodeId] = [];
|
|
780
|
+
instance.vnodeHooks[hookName][vnodeId].push(handler.bind(instance));
|
|
781
|
+
});
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// 执行模块的create方法,模块实例化回调,Module create callback
|
|
786
|
+
if (module.create) {
|
|
787
|
+
module.create.bind(instance)(moduleParams);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
676
791
|
/**
|
|
677
792
|
* 实例创建初始化时,执行扩展模块中定义的相关回调
|
|
678
|
-
* @param {*} modulesParams
|
|
679
|
-
*/
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
|
|
793
|
+
* @param {*} modulesParams
|
|
794
|
+
*/
|
|
795
|
+
useModules(modulesParams = {}) {
|
|
796
|
+
const instance = this;
|
|
797
|
+
if (!instance.modules) return;
|
|
798
|
+
Object.keys(instance.modules).forEach(moduleName => {
|
|
799
|
+
const moduleParams = modulesParams[moduleName] || {};
|
|
800
|
+
instance.useModule(moduleName, moduleParams);
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
static set components(components) {
|
|
805
|
+
const Class = this;
|
|
806
|
+
if (!Class.use) return;
|
|
807
|
+
Class.use(components);
|
|
808
|
+
}
|
|
809
|
+
|
|
695
810
|
/**
|
|
696
811
|
* 将模块类装配到指定类的modules属性,用于扩展类
|
|
697
812
|
* @param {*} module 模块类
|
|
698
813
|
* @param {...any} params 参数
|
|
699
|
-
*/
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
if (!Class.prototype.modules) Class.prototype.modules = {};
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
if (module.install) {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
return Class;
|
|
730
|
-
}
|
|
814
|
+
*/
|
|
815
|
+
static installModule(module, ...params) {
|
|
816
|
+
const Class = this;
|
|
817
|
+
if (!Class.prototype.modules) Class.prototype.modules = {};
|
|
818
|
+
const name =
|
|
819
|
+
module.name ||
|
|
820
|
+
`${Object.keys(Class.prototype.modules).length}_${$.now()}`;
|
|
821
|
+
// 原型属性中引用该模块类,类实例
|
|
822
|
+
Class.prototype.modules[name] = module;
|
|
823
|
+
// 模块如果定义了原型,则将模块原型加载到类原型
|
|
824
|
+
if (module.proto) {
|
|
825
|
+
Object.keys(module.proto).forEach(key => {
|
|
826
|
+
Class.prototype[key] = module.proto[key];
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
// 加载静态属性
|
|
830
|
+
if (module.static) {
|
|
831
|
+
Object.keys(module.static).forEach(key => {
|
|
832
|
+
Class[key] = module.static[key];
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
// 执行加载回调函数
|
|
836
|
+
if (module.install) {
|
|
837
|
+
module.install.apply(Class, params);
|
|
838
|
+
}
|
|
839
|
+
return Class;
|
|
840
|
+
}
|
|
841
|
+
|
|
731
842
|
/**
|
|
732
843
|
* 加载类扩展模块到类
|
|
733
|
-
* @param {*} module
|
|
734
|
-
* @param {...any} params
|
|
735
|
-
*/
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
return Class;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
749
|
-
params[_key2 - 1] = arguments[_key2];
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
return Class.installModule.apply(Class, [module].concat(params));
|
|
753
|
-
};
|
|
754
|
-
|
|
755
|
-
_createClass(Module, null, [{
|
|
756
|
-
key: "components",
|
|
757
|
-
set: function set(components) {
|
|
758
|
-
var Class = this;
|
|
759
|
-
if (!Class.use) return;
|
|
760
|
-
Class.use(components);
|
|
761
|
-
}
|
|
762
|
-
}]);
|
|
763
|
-
|
|
764
|
-
return Module;
|
|
765
|
-
}(Event);
|
|
844
|
+
* @param {*} module
|
|
845
|
+
* @param {...any} params
|
|
846
|
+
*/
|
|
847
|
+
static use(module, ...params) {
|
|
848
|
+
const Class = this;
|
|
849
|
+
if (Array.isArray(module)) {
|
|
850
|
+
module.forEach(m => Class.installModule(m));
|
|
851
|
+
return Class;
|
|
852
|
+
}
|
|
853
|
+
return Class.installModule(module, ...params);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
766
856
|
|
|
767
857
|
/**
|
|
768
858
|
* 扩展构造函数
|
|
769
|
-
* @param {*} parameters
|
|
770
|
-
*/
|
|
771
|
-
function Constructors (parameters) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
if (
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
if (addMethods && Array.isArray(addMethods)) {
|
|
809
|
-
addMethods.forEach(function (methodName) {
|
|
810
|
-
methods[methodName] = function (el) {
|
|
811
|
-
if (el === void 0) {
|
|
812
|
-
el = defaultSelector;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
var instance = methods.get(el);
|
|
816
|
-
|
|
817
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
818
|
-
args[_key2 - 1] = arguments[_key2];
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
if (instance && instance[methodName]) return instance[methodName].apply(instance, args);
|
|
822
|
-
return undefined;
|
|
823
|
-
};
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
return methods;
|
|
859
|
+
* @param {*} parameters
|
|
860
|
+
*/
|
|
861
|
+
function Constructors (parameters = {}) {
|
|
862
|
+
const {
|
|
863
|
+
defaultSelector,
|
|
864
|
+
constructor: Constructor,
|
|
865
|
+
domProp,
|
|
866
|
+
app,
|
|
867
|
+
addMethods,
|
|
868
|
+
} = parameters;
|
|
869
|
+
const methods = {
|
|
870
|
+
create(...args) {
|
|
871
|
+
if (app) return new Constructor(app, ...args);
|
|
872
|
+
return new Constructor(...args);
|
|
873
|
+
},
|
|
874
|
+
get(el = defaultSelector) {
|
|
875
|
+
if (el instanceof Constructor) return el;
|
|
876
|
+
const $el = $(el);
|
|
877
|
+
if ($el.length === 0) return undefined;
|
|
878
|
+
return $el[0][domProp];
|
|
879
|
+
},
|
|
880
|
+
destroy(el) {
|
|
881
|
+
const instance = methods.get(el);
|
|
882
|
+
if (instance && instance.destroy) return instance.destroy();
|
|
883
|
+
return undefined;
|
|
884
|
+
},
|
|
885
|
+
};
|
|
886
|
+
if (addMethods && Array.isArray(addMethods)) {
|
|
887
|
+
addMethods.forEach(methodName => {
|
|
888
|
+
methods[methodName] = (el = defaultSelector, ...args) => {
|
|
889
|
+
const instance = methods.get(el);
|
|
890
|
+
if (instance && instance[methodName])
|
|
891
|
+
return instance[methodName](...args);
|
|
892
|
+
return undefined;
|
|
893
|
+
};
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
return methods;
|
|
828
897
|
}
|
|
829
898
|
|
|
830
|
-
function Modals (parameters) {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
if ($el.length === 0) return undefined;
|
|
860
|
-
var instance = $el[0].f7Modal;
|
|
861
|
-
if (!instance) instance = new constructor(app, {
|
|
862
|
-
el: $el
|
|
863
|
-
});
|
|
864
|
-
return instance.close(animate);
|
|
865
|
-
}
|
|
866
|
-
});
|
|
867
|
-
return methods;
|
|
899
|
+
function Modals (parameters = {}) {
|
|
900
|
+
const { defaultSelector, constructor, app } = parameters;
|
|
901
|
+
const methods = $.extend(
|
|
902
|
+
Constructors({
|
|
903
|
+
defaultSelector,
|
|
904
|
+
constructor,
|
|
905
|
+
app,
|
|
906
|
+
domProp: 'f7Modal',
|
|
907
|
+
}),
|
|
908
|
+
{
|
|
909
|
+
open(el, animate) {
|
|
910
|
+
const $el = $(el);
|
|
911
|
+
let instance = $el[0].f7Modal;
|
|
912
|
+
if (!instance)
|
|
913
|
+
instance = new constructor(app, {el: $el});
|
|
914
|
+
return instance.open(animate);
|
|
915
|
+
},
|
|
916
|
+
close(el = defaultSelector, animate) {
|
|
917
|
+
const $el = $(el);
|
|
918
|
+
if ($el.length === 0)
|
|
919
|
+
return undefined;
|
|
920
|
+
let instance = $el[0].f7Modal;
|
|
921
|
+
if (!instance)
|
|
922
|
+
instance = new constructor(app, {el: $el});
|
|
923
|
+
return instance.close(animate);
|
|
924
|
+
},
|
|
925
|
+
}
|
|
926
|
+
);
|
|
927
|
+
return methods;
|
|
868
928
|
}
|
|
869
929
|
|
|
870
930
|
/**
|
|
@@ -872,16 +932,16 @@ function Modals (parameters) {
|
|
|
872
932
|
* 通过写入页面标签实现动态加载js、css
|
|
873
933
|
* wia base中已经实现了动态下载、加载模块功能,该模块应删除
|
|
874
934
|
*/
|
|
875
|
-
var fetchedModules = [];
|
|
876
935
|
|
|
936
|
+
const fetchedModules = [];
|
|
877
937
|
function loadModule(moduleToLoad) {
|
|
878
|
-
|
|
879
|
-
return new Promise(function (resolve, reject) {
|
|
880
|
-
var app = App.instance;
|
|
881
|
-
var modulePath;
|
|
882
|
-
var moduleObj;
|
|
883
|
-
var moduleFunc;
|
|
938
|
+
const App = this;
|
|
884
939
|
|
|
940
|
+
return new Promise((resolve, reject) => {
|
|
941
|
+
const app = App.instance;
|
|
942
|
+
let modulePath;
|
|
943
|
+
let moduleObj;
|
|
944
|
+
let moduleFunc;
|
|
885
945
|
if (!moduleToLoad) {
|
|
886
946
|
reject(new Error('Wia: Lazy module must be specified'));
|
|
887
947
|
return;
|
|
@@ -897,15 +957,21 @@ function loadModule(moduleToLoad) {
|
|
|
897
957
|
}
|
|
898
958
|
|
|
899
959
|
if (typeof moduleToLoad === 'string') {
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
960
|
+
const matchNamePattern = moduleToLoad.match(/([a-z0-9-]*)/i);
|
|
961
|
+
if (
|
|
962
|
+
moduleToLoad.indexOf('.') < 0 &&
|
|
963
|
+
matchNamePattern &&
|
|
964
|
+
matchNamePattern[0].length === moduleToLoad.length
|
|
965
|
+
) {
|
|
966
|
+
if (!app || (app && !app.params.lazyModulesPath)) {
|
|
967
|
+
reject(
|
|
968
|
+
new Error(
|
|
969
|
+
'Wia: "lazyModulesPath" app parameter must be specified to fetch module by name'
|
|
970
|
+
)
|
|
971
|
+
);
|
|
905
972
|
return;
|
|
906
973
|
}
|
|
907
|
-
|
|
908
|
-
modulePath = app.params.lazyModulesPath + "/" + moduleToLoad + ".js";
|
|
974
|
+
modulePath = `${app.params.lazyModulesPath}/${moduleToLoad}.js`;
|
|
909
975
|
} else {
|
|
910
976
|
modulePath = moduleToLoad;
|
|
911
977
|
}
|
|
@@ -917,160 +983,160 @@ function loadModule(moduleToLoad) {
|
|
|
917
983
|
}
|
|
918
984
|
|
|
919
985
|
if (moduleFunc) {
|
|
920
|
-
|
|
921
|
-
|
|
986
|
+
const module = moduleFunc(App, false);
|
|
922
987
|
if (!module) {
|
|
923
988
|
reject(new Error("Wia: Can't find Wia component in specified component function"));
|
|
924
989
|
return;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
|
|
990
|
+
}
|
|
991
|
+
// Check if it was added
|
|
928
992
|
if (App.prototype.modules && App.prototype.modules[module.name]) {
|
|
929
993
|
resolve();
|
|
930
994
|
return;
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
|
|
995
|
+
}
|
|
996
|
+
// Install It
|
|
934
997
|
install(module);
|
|
998
|
+
|
|
935
999
|
resolve();
|
|
936
1000
|
}
|
|
937
|
-
|
|
938
1001
|
if (moduleObj) {
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
if (!_module) {
|
|
1002
|
+
const module = moduleObj;
|
|
1003
|
+
if (!module) {
|
|
942
1004
|
reject(new Error("Wia: Can't find Wia component in specified component"));
|
|
943
1005
|
return;
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
if (App.prototype.modules && App.prototype.modules[_module.name]) {
|
|
1006
|
+
}
|
|
1007
|
+
// Check if it was added
|
|
1008
|
+
if (App.prototype.modules && App.prototype.modules[module.name]) {
|
|
948
1009
|
resolve();
|
|
949
1010
|
return;
|
|
950
|
-
}
|
|
951
|
-
|
|
1011
|
+
}
|
|
1012
|
+
// Install It
|
|
1013
|
+
install(module);
|
|
952
1014
|
|
|
953
|
-
install(_module);
|
|
954
1015
|
resolve();
|
|
955
1016
|
}
|
|
956
|
-
|
|
957
1017
|
if (modulePath) {
|
|
958
1018
|
if (fetchedModules.indexOf(modulePath) >= 0) {
|
|
959
1019
|
resolve();
|
|
960
1020
|
return;
|
|
961
1021
|
}
|
|
1022
|
+
fetchedModules.push(modulePath);
|
|
1023
|
+
// 动态加载 js 脚本
|
|
1024
|
+
const scriptLoad = new Promise((resolveScript, rejectScript) => {
|
|
1025
|
+
App.request.get(
|
|
1026
|
+
modulePath,
|
|
1027
|
+
scriptContent => {
|
|
1028
|
+
const id = $.id();
|
|
1029
|
+
const callbackLoadName = `wia_component_loader_callback_${id}`;
|
|
1030
|
+
|
|
1031
|
+
const scriptEl = document.createElement('script');
|
|
1032
|
+
scriptEl.innerHTML = `window.${callbackLoadName} = function (Wia, WiaAutoInstallComponent) {return ${scriptContent.trim()}}`;
|
|
1033
|
+
// 动态加载 js
|
|
1034
|
+
$('head').append(scriptEl);
|
|
1035
|
+
|
|
1036
|
+
const componentLoader = window[callbackLoadName];
|
|
1037
|
+
delete window[callbackLoadName];
|
|
1038
|
+
$(scriptEl).remove();
|
|
1039
|
+
|
|
1040
|
+
const module = componentLoader(App, false);
|
|
1041
|
+
|
|
1042
|
+
if (!module) {
|
|
1043
|
+
rejectScript(new Error(`Wia: Can't find Wia component in ${modulePath} file`));
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// Check if it was added
|
|
1048
|
+
if (App.prototype.modules && App.prototype.modules[module.name]) {
|
|
1049
|
+
resolveScript();
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// Install It
|
|
1054
|
+
install(module);
|
|
962
1055
|
|
|
963
|
-
fetchedModules.push(modulePath); // 动态加载 js 脚本
|
|
964
|
-
|
|
965
|
-
var scriptLoad = new Promise(function (resolveScript, rejectScript) {
|
|
966
|
-
App.request.get(modulePath, function (scriptContent) {
|
|
967
|
-
var id = $.id();
|
|
968
|
-
var callbackLoadName = "wia_component_loader_callback_" + id;
|
|
969
|
-
var scriptEl = document.createElement('script');
|
|
970
|
-
scriptEl.innerHTML = "window." + callbackLoadName + " = function (Wia, WiaAutoInstallComponent) {return " + scriptContent.trim() + "}"; // 动态加载 js
|
|
971
|
-
|
|
972
|
-
$('head').append(scriptEl);
|
|
973
|
-
var componentLoader = window[callbackLoadName];
|
|
974
|
-
delete window[callbackLoadName];
|
|
975
|
-
$(scriptEl).remove();
|
|
976
|
-
var module = componentLoader(App, false);
|
|
977
|
-
|
|
978
|
-
if (!module) {
|
|
979
|
-
rejectScript(new Error("Wia: Can't find Wia component in " + modulePath + " file"));
|
|
980
|
-
return;
|
|
981
|
-
} // Check if it was added
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
if (App.prototype.modules && App.prototype.modules[module.name]) {
|
|
985
1056
|
resolveScript();
|
|
986
|
-
|
|
987
|
-
|
|
1057
|
+
},
|
|
1058
|
+
(xhr, status) => {
|
|
1059
|
+
rejectScript(xhr, status);
|
|
1060
|
+
}
|
|
1061
|
+
);
|
|
1062
|
+
});
|
|
988
1063
|
|
|
1064
|
+
// 动态加载css样式
|
|
1065
|
+
const styleLoad = new Promise(resolveStyle => {
|
|
1066
|
+
App.request.get(
|
|
1067
|
+
modulePath.replace('.js', app.rtl ? '.rtl.css' : '.css'),
|
|
1068
|
+
styleContent => {
|
|
1069
|
+
const styleEl = document.createElement('style');
|
|
1070
|
+
styleEl.innerHTML = styleContent;
|
|
1071
|
+
$('head').append(styleEl);
|
|
1072
|
+
|
|
1073
|
+
resolveStyle();
|
|
1074
|
+
},
|
|
1075
|
+
() => {
|
|
1076
|
+
resolveStyle();
|
|
1077
|
+
}
|
|
1078
|
+
);
|
|
1079
|
+
});
|
|
989
1080
|
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
var styleLoad = new Promise(function (resolveStyle) {
|
|
998
|
-
App.request.get(modulePath.replace('.js', app.rtl ? '.rtl.css' : '.css'), function (styleContent) {
|
|
999
|
-
var styleEl = document.createElement('style');
|
|
1000
|
-
styleEl.innerHTML = styleContent;
|
|
1001
|
-
$('head').append(styleEl);
|
|
1002
|
-
resolveStyle();
|
|
1003
|
-
}, function () {
|
|
1004
|
-
resolveStyle();
|
|
1081
|
+
Promise.all([scriptLoad, styleLoad])
|
|
1082
|
+
.then(() => {
|
|
1083
|
+
resolve();
|
|
1084
|
+
})
|
|
1085
|
+
.catch(err => {
|
|
1086
|
+
reject(err);
|
|
1005
1087
|
});
|
|
1006
|
-
});
|
|
1007
|
-
Promise.all([scriptLoad, styleLoad]).then(function () {
|
|
1008
|
-
resolve();
|
|
1009
|
-
}).catch(function (err) {
|
|
1010
|
-
reject(err);
|
|
1011
|
-
});
|
|
1012
1088
|
}
|
|
1013
1089
|
});
|
|
1014
1090
|
}
|
|
1015
1091
|
|
|
1016
|
-
|
|
1017
|
-
name: 'resize',
|
|
1018
|
-
instance: {
|
|
1019
|
-
getSize
|
|
1020
|
-
|
|
1021
|
-
if (!app.root[0])
|
|
1022
|
-
width: 0,
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
app
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
};
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
}
|
|
1058
|
-
},
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
setTimeout(function () {
|
|
1065
|
-
document.body.scrollLeft = 0;
|
|
1066
|
-
}, 0);
|
|
1067
|
-
}
|
|
1068
|
-
},
|
|
1069
|
-
resize: function resize() {
|
|
1070
|
-
var app = this;
|
|
1071
|
-
app.getSize();
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1092
|
+
const Resize = {
|
|
1093
|
+
name: 'resize',
|
|
1094
|
+
instance: {
|
|
1095
|
+
getSize() {
|
|
1096
|
+
const app = this;
|
|
1097
|
+
if (!app.root[0])
|
|
1098
|
+
return {width: 0, height: 0, left: 0, top: 0};
|
|
1099
|
+
const offset = app.root.offset();
|
|
1100
|
+
const [width, height, left, top] = [app.root[0].offsetWidth, app.root[0].offsetHeight, offset.left, offset.top];
|
|
1101
|
+
app.width = width;
|
|
1102
|
+
app.height = height;
|
|
1103
|
+
app.left = left;
|
|
1104
|
+
app.top = top;
|
|
1105
|
+
return { width, height, left, top };
|
|
1106
|
+
},
|
|
1107
|
+
},
|
|
1108
|
+
on: {
|
|
1109
|
+
init() {
|
|
1110
|
+
const app = this;
|
|
1111
|
+
|
|
1112
|
+
// Get Size
|
|
1113
|
+
app.getSize();
|
|
1114
|
+
|
|
1115
|
+
// Emit resize
|
|
1116
|
+
window.addEventListener('resize', () => {
|
|
1117
|
+
app.emit('resize');
|
|
1118
|
+
}, false);
|
|
1119
|
+
|
|
1120
|
+
// Emit orientationchange
|
|
1121
|
+
window.addEventListener('orientationchange', () => {
|
|
1122
|
+
app.emit('orientationchange');
|
|
1123
|
+
});
|
|
1124
|
+
},
|
|
1125
|
+
orientationchange() {
|
|
1126
|
+
const app = this;
|
|
1127
|
+
// Fix iPad weird body scroll
|
|
1128
|
+
if (app.device.ipad) {
|
|
1129
|
+
document.body.scrollLeft = 0;
|
|
1130
|
+
setTimeout(() => {
|
|
1131
|
+
document.body.scrollLeft = 0;
|
|
1132
|
+
}, 0);
|
|
1133
|
+
}
|
|
1134
|
+
},
|
|
1135
|
+
resize() {
|
|
1136
|
+
const app = this;
|
|
1137
|
+
app.getSize();
|
|
1138
|
+
},
|
|
1139
|
+
},
|
|
1074
1140
|
};
|
|
1075
1141
|
|
|
1076
1142
|
/**
|
|
@@ -1078,197 +1144,211 @@ var Resize = {
|
|
|
1078
1144
|
* 支持touch则绑定touch,否则绑定click
|
|
1079
1145
|
* 无论touch 还是 click事件,都会触发事件响应函数
|
|
1080
1146
|
* @param {*} cb
|
|
1081
|
-
*/
|
|
1082
|
-
function bindClick(cb) {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
document.addEventListener('
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
function
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
Object.keys(app.modules).forEach(
|
|
1128
|
-
|
|
1129
|
-
if (!moduleClicks) return;
|
|
1130
|
-
if (e.preventF7Router) return;
|
|
1131
|
-
Object.keys(moduleClicks).forEach(
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1147
|
+
*/
|
|
1148
|
+
function bindClick(cb) {
|
|
1149
|
+
let touchStartX;
|
|
1150
|
+
let touchStartY;
|
|
1151
|
+
function touchStart(ev) {
|
|
1152
|
+
// ev.preventDefault();
|
|
1153
|
+
touchStartX = ev.changedTouches[0].clientX;
|
|
1154
|
+
touchStartY = ev.changedTouches[0].clientY;
|
|
1155
|
+
}
|
|
1156
|
+
function touchEnd(ev) {
|
|
1157
|
+
// ev.preventDefault();
|
|
1158
|
+
const x = Math.abs(ev.changedTouches[0].clientX - touchStartX);
|
|
1159
|
+
const y = Math.abs(ev.changedTouches[0].clientY - touchStartY);
|
|
1160
|
+
// console.log('touchEnd', {x, y});
|
|
1161
|
+
|
|
1162
|
+
if (x <= 5 && y <= 5) {
|
|
1163
|
+
cb.call(this, ev);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
// 在捕捉时触发,不影响后续冒泡阶段再次触发
|
|
1168
|
+
if ($.support.touch) {
|
|
1169
|
+
// console.log('bind touch');
|
|
1170
|
+
document.addEventListener('touchstart', touchStart, true);
|
|
1171
|
+
document.addEventListener('touchend', touchEnd, true);
|
|
1172
|
+
} else {
|
|
1173
|
+
// console.log('bind click');
|
|
1174
|
+
document.addEventListener('click', cb, true);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
function initClicks(app) {
|
|
1179
|
+
function appClick(ev) {
|
|
1180
|
+
app.emit({
|
|
1181
|
+
events: 'click',
|
|
1182
|
+
data: [ev],
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
function handleClicks(e) {
|
|
1187
|
+
const $clickedEl = $(e.target);
|
|
1188
|
+
const $clickedLinkEl = $clickedEl.closest('a');
|
|
1189
|
+
const isLink = $clickedLinkEl.length > 0;
|
|
1190
|
+
isLink && $clickedLinkEl.attr('href');
|
|
1191
|
+
|
|
1192
|
+
// call Modules Clicks
|
|
1193
|
+
Object.keys(app.modules).forEach(moduleName => {
|
|
1194
|
+
const moduleClicks = app.modules[moduleName].clicks;
|
|
1195
|
+
if (!moduleClicks) return;
|
|
1196
|
+
if (e.preventF7Router) return;
|
|
1197
|
+
Object.keys(moduleClicks).forEach(clickSelector => {
|
|
1198
|
+
const matchingClickedElement = $clickedEl.closest(clickSelector).eq(0);
|
|
1199
|
+
if (matchingClickedElement.length > 0) {
|
|
1200
|
+
moduleClicks[clickSelector].call(
|
|
1201
|
+
app,
|
|
1202
|
+
matchingClickedElement,
|
|
1203
|
+
matchingClickedElement.dataset(),
|
|
1204
|
+
e
|
|
1205
|
+
);
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// 绑定click 或 touch 事件,触发时,发射click事件
|
|
1212
|
+
bindClick(appClick);
|
|
1213
|
+
// click event 响应
|
|
1214
|
+
app.on('click', handleClicks);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
const Click = {
|
|
1218
|
+
name: 'clicks',
|
|
1219
|
+
params: {
|
|
1220
|
+
clicks: {
|
|
1221
|
+
// External Links
|
|
1222
|
+
externalLinks: '.ext',
|
|
1223
|
+
},
|
|
1224
|
+
},
|
|
1225
|
+
on: {
|
|
1226
|
+
// app 创建时被调用
|
|
1227
|
+
init() {
|
|
1228
|
+
const app = this;
|
|
1229
|
+
initClicks(app);
|
|
1230
|
+
},
|
|
1231
|
+
},
|
|
1162
1232
|
};
|
|
1163
1233
|
|
|
1164
|
-
|
|
1165
|
-
registrations: [],
|
|
1166
|
-
register
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
return Promise.all(registrations.map(
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
if (SW.registrations.indexOf(reg) >= 0) {
|
|
1203
|
-
SW.registrations.splice(SW.registrations.indexOf(reg), 1);
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
app.emit('serviceWorkerUnregisterError', reg, error);
|
|
1210
|
-
reject(error);
|
|
1211
|
-
});
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
name: 'sw',
|
|
1218
|
-
params: {
|
|
1219
|
-
serviceWorker: {
|
|
1220
|
-
path: undefined,
|
|
1221
|
-
scope: undefined
|
|
1222
|
-
}
|
|
1223
|
-
},
|
|
1224
|
-
create
|
|
1225
|
-
|
|
1226
|
-
$.extend(app, {
|
|
1227
|
-
serviceWorker: {
|
|
1228
|
-
container: 'serviceWorker' in window.navigator ? window.navigator.serviceWorker : undefined,
|
|
1229
|
-
registrations: SW.registrations,
|
|
1230
|
-
register: SW.register.bind(app),
|
|
1231
|
-
unregister: SW.unregister.bind(app)
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1234
|
-
},
|
|
1235
|
-
on: {
|
|
1236
|
-
init
|
|
1237
|
-
if (!('serviceWorker' in window.navigator))
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1234
|
+
const SW = {
|
|
1235
|
+
registrations: [],
|
|
1236
|
+
register(path, scope) {
|
|
1237
|
+
const app = this;
|
|
1238
|
+
if (!('serviceWorker' in window.navigator) || !app.serviceWorker.container) {
|
|
1239
|
+
return new Promise((resolve, reject) => {
|
|
1240
|
+
reject(new Error('Service worker is not supported'));
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
return new Promise((resolve, reject) => {
|
|
1244
|
+
app.serviceWorker.container.register(path, (scope ? { scope } : {}))
|
|
1245
|
+
.then((reg) => {
|
|
1246
|
+
SW.registrations.push(reg);
|
|
1247
|
+
app.emit('serviceWorkerRegisterSuccess', reg);
|
|
1248
|
+
resolve(reg);
|
|
1249
|
+
}).catch((error) => {
|
|
1250
|
+
app.emit('serviceWorkerRegisterError', error);
|
|
1251
|
+
reject(error);
|
|
1252
|
+
});
|
|
1253
|
+
});
|
|
1254
|
+
},
|
|
1255
|
+
unregister(registration) {
|
|
1256
|
+
const app = this;
|
|
1257
|
+
if (!('serviceWorker' in window.navigator) || !app.serviceWorker.container) {
|
|
1258
|
+
return new Promise((resolve, reject) => {
|
|
1259
|
+
reject(new Error('Service worker is not supported'));
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
let registrations;
|
|
1263
|
+
if (!registration)
|
|
1264
|
+
registrations = SW.registrations;
|
|
1265
|
+
else if (Array.isArray(registration))
|
|
1266
|
+
registrations = registration;
|
|
1267
|
+
else
|
|
1268
|
+
registrations = [registration];
|
|
1269
|
+
return Promise.all(registrations.map(reg => new Promise((resolve, reject) => {
|
|
1270
|
+
reg.unregister()
|
|
1271
|
+
.then(() => {
|
|
1272
|
+
if (SW.registrations.indexOf(reg) >= 0) {
|
|
1273
|
+
SW.registrations.splice(SW.registrations.indexOf(reg), 1);
|
|
1274
|
+
}
|
|
1275
|
+
app.emit('serviceWorkerUnregisterSuccess', reg);
|
|
1276
|
+
resolve();
|
|
1277
|
+
})
|
|
1278
|
+
.catch((error) => {
|
|
1279
|
+
app.emit('serviceWorkerUnregisterError', reg, error);
|
|
1280
|
+
reject(error);
|
|
1281
|
+
});
|
|
1282
|
+
})));
|
|
1283
|
+
},
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
const SW$1 = {
|
|
1287
|
+
name: 'sw',
|
|
1288
|
+
params: {
|
|
1289
|
+
serviceWorker: {
|
|
1290
|
+
path: undefined,
|
|
1291
|
+
scope: undefined,
|
|
1292
|
+
},
|
|
1293
|
+
},
|
|
1294
|
+
create() {
|
|
1295
|
+
const app = this;
|
|
1296
|
+
$.extend(app, {
|
|
1297
|
+
serviceWorker: {
|
|
1298
|
+
container: ('serviceWorker' in window.navigator) ? window.navigator.serviceWorker : undefined,
|
|
1299
|
+
registrations: SW.registrations,
|
|
1300
|
+
register: SW.register.bind(app),
|
|
1301
|
+
unregister: SW.unregister.bind(app),
|
|
1302
|
+
},
|
|
1303
|
+
});
|
|
1304
|
+
},
|
|
1305
|
+
on: {
|
|
1306
|
+
init() {
|
|
1307
|
+
if (!('serviceWorker' in window.navigator))
|
|
1308
|
+
return;
|
|
1309
|
+
const app = this;
|
|
1310
|
+
if (!app.serviceWorker.container)
|
|
1311
|
+
return;
|
|
1312
|
+
const paths = app.params.serviceWorker.path;
|
|
1313
|
+
const scope = app.params.serviceWorker.scope;
|
|
1314
|
+
if (!paths || (Array.isArray(paths) && !paths.length))
|
|
1315
|
+
return;
|
|
1316
|
+
const toRegister = Array.isArray(paths) ? paths : [paths];
|
|
1317
|
+
toRegister.forEach((path) => {
|
|
1318
|
+
app.serviceWorker.register(path, scope);
|
|
1319
|
+
});
|
|
1320
|
+
},
|
|
1321
|
+
},
|
|
1249
1322
|
};
|
|
1250
1323
|
|
|
1251
|
-
var Support$1 = $.support;
|
|
1252
|
-
var Device$1 = $.device;
|
|
1253
1324
|
/**
|
|
1254
|
-
*
|
|
1325
|
+
* Wia App 基类,从 Module 和 Event 继承。
|
|
1255
1326
|
*/
|
|
1327
|
+
// 使用 rollup打包注意
|
|
1328
|
+
// import $ from '@wiajs/dom'; // dom操作库,这种引用,导致 dom的压缩、非压缩 common包都会打入 core
|
|
1329
|
+
// const $ = require('@wiajs/dom'); // dom操作库,这种引用,导致 dom的压缩、非压缩 common包都不会打入 core,保留了 require
|
|
1256
1330
|
|
|
1257
|
-
var App = /*#__PURE__*/function (_Module) {
|
|
1258
|
-
_inheritsLoose(App, _Module);
|
|
1259
1331
|
|
|
1260
|
-
|
|
1261
|
-
|
|
1332
|
+
const Support$1 = $.support;
|
|
1333
|
+
const Device$1 = $.device;
|
|
1262
1334
|
|
|
1263
|
-
|
|
1264
|
-
|
|
1335
|
+
/**
|
|
1336
|
+
* 应用类,每个wia应用从该类继承,由 首页加载创建或者路由创建
|
|
1337
|
+
*/
|
|
1338
|
+
class App extends Module {
|
|
1339
|
+
static apps = {};
|
|
1340
|
+
constructor(opt) {
|
|
1341
|
+
super(opt);
|
|
1265
1342
|
|
|
1266
|
-
|
|
1343
|
+
const passedParams = $.extend({}, opt);
|
|
1267
1344
|
|
|
1345
|
+
const app = this;
|
|
1268
1346
|
app.device = Device$1;
|
|
1269
|
-
app.support = Support$1;
|
|
1347
|
+
app.support = Support$1;
|
|
1348
|
+
console.log('App constructor', {Device: Device$1, Support: Support$1});
|
|
1270
1349
|
|
|
1271
|
-
|
|
1350
|
+
// Default
|
|
1351
|
+
const def = {
|
|
1272
1352
|
version: '0.0.1',
|
|
1273
1353
|
root: 'body',
|
|
1274
1354
|
theme: 'auto',
|
|
@@ -1281,17 +1361,25 @@ var App = /*#__PURE__*/function (_Module) {
|
|
|
1281
1361
|
iosTranslucentBars: true,
|
|
1282
1362
|
iosTranslucentModals: true,
|
|
1283
1363
|
component: undefined,
|
|
1284
|
-
componentUrl: undefined
|
|
1285
|
-
};
|
|
1364
|
+
componentUrl: undefined,
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1367
|
+
// Extend defaults with modules params
|
|
1368
|
+
app.useModulesParams(def);
|
|
1369
|
+
|
|
1370
|
+
// Extend defaults with passed params
|
|
1371
|
+
app.params = $.extend(def, opt);
|
|
1372
|
+
|
|
1373
|
+
const $rootEl = $(app.params.root);
|
|
1286
1374
|
|
|
1287
|
-
|
|
1375
|
+
// 判断Page、App实例
|
|
1376
|
+
$.isPage = p => p instanceof Page;
|
|
1377
|
+
$.isApp = p => p instanceof App;
|
|
1288
1378
|
|
|
1289
|
-
app.params = $.extend(def, opt);
|
|
1290
|
-
var $rootEl = $(app.params.root);
|
|
1291
1379
|
$.extend(app, {
|
|
1292
1380
|
owner: app.params.owner,
|
|
1293
1381
|
name: app.params.name,
|
|
1294
|
-
id: app.params.owner
|
|
1382
|
+
id: `${app.params.owner}.${app.params.name}`,
|
|
1295
1383
|
// App version
|
|
1296
1384
|
version: app.params.version,
|
|
1297
1385
|
// Routes
|
|
@@ -1301,128 +1389,131 @@ var App = /*#__PURE__*/function (_Module) {
|
|
|
1301
1389
|
// Root
|
|
1302
1390
|
root: $rootEl,
|
|
1303
1391
|
$el: $rootEl,
|
|
1304
|
-
cfg: app.params.cfg,
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
// api config
|
|
1392
|
+
cfg: app.params.cfg, // app config
|
|
1393
|
+
api: app.params.api, // api config
|
|
1394
|
+
|
|
1308
1395
|
// RTL
|
|
1309
1396
|
rtl: $rootEl.css('direction') === 'rtl',
|
|
1310
1397
|
// Theme
|
|
1311
|
-
theme: function getTheme() {
|
|
1398
|
+
theme: (function getTheme() {
|
|
1312
1399
|
if (app.params.theme === 'auto') {
|
|
1313
1400
|
if (Device$1.ios) return 'ios';
|
|
1314
1401
|
if (Device$1.desktop) return 'aurora';
|
|
1315
1402
|
return 'md';
|
|
1316
1403
|
}
|
|
1317
|
-
|
|
1318
1404
|
return app.params.theme;
|
|
1319
|
-
}(),
|
|
1405
|
+
})(),
|
|
1320
1406
|
// Initially passed parameters
|
|
1321
|
-
passedParams
|
|
1322
|
-
online: window.navigator.onLine
|
|
1323
|
-
});
|
|
1407
|
+
passedParams,
|
|
1408
|
+
online: window.navigator.onLine,
|
|
1409
|
+
});
|
|
1324
1410
|
|
|
1411
|
+
// Save Root
|
|
1325
1412
|
if (app.root && app.root[0]) {
|
|
1326
1413
|
app.root[0].wia = app;
|
|
1327
1414
|
}
|
|
1328
1415
|
|
|
1329
1416
|
app.touchEvents = {
|
|
1330
|
-
start: Support$1.touch
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1417
|
+
start: Support$1.touch
|
|
1418
|
+
? 'touchstart'
|
|
1419
|
+
: Support$1.pointerEvents
|
|
1420
|
+
? 'pointerdown'
|
|
1421
|
+
: 'mousedown',
|
|
1422
|
+
move: Support$1.touch
|
|
1423
|
+
? 'touchmove'
|
|
1424
|
+
: Support$1.pointerEvents
|
|
1425
|
+
? 'pointermove'
|
|
1426
|
+
: 'mousemove',
|
|
1427
|
+
end: Support$1.touch
|
|
1428
|
+
? 'touchend'
|
|
1429
|
+
: Support$1.pointerEvents
|
|
1430
|
+
? 'pointerup'
|
|
1431
|
+
: 'mouseup',
|
|
1432
|
+
};
|
|
1433
|
+
|
|
1434
|
+
// 加载use插入的模块类,每个模块作为app的一个属性,合并到实例。
|
|
1334
1435
|
// 模块包括相关属性及方法(如:create、get、destroy)
|
|
1335
1436
|
// 调用每个模块的 create 方法
|
|
1437
|
+
app.useModules();
|
|
1336
1438
|
|
|
1337
|
-
|
|
1439
|
+
// 初始化数据,Init Data & Methods
|
|
1440
|
+
app.initData();
|
|
1338
1441
|
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
var LIGHT = '(prefers-color-scheme: light)';
|
|
1442
|
+
// 自动暗黑主题,Auto Dark Theme
|
|
1443
|
+
const DARK = '(prefers-color-scheme: dark)';
|
|
1444
|
+
const LIGHT = '(prefers-color-scheme: light)';
|
|
1343
1445
|
app.mq = {};
|
|
1344
|
-
|
|
1345
1446
|
if (window.matchMedia) {
|
|
1346
1447
|
app.mq.dark = window.matchMedia(DARK);
|
|
1347
1448
|
app.mq.light = window.matchMedia(LIGHT);
|
|
1348
1449
|
}
|
|
1349
|
-
|
|
1350
|
-
app.colorSchemeListener = function (_ref) {
|
|
1351
|
-
var matches = _ref.matches,
|
|
1352
|
-
media = _ref.media;
|
|
1353
|
-
|
|
1450
|
+
app.colorSchemeListener = function ({matches, media}) {
|
|
1354
1451
|
if (!matches) {
|
|
1355
1452
|
return;
|
|
1356
1453
|
}
|
|
1357
|
-
|
|
1358
|
-
var html = document.querySelector('html');
|
|
1359
|
-
|
|
1454
|
+
const html = document.querySelector('html');
|
|
1360
1455
|
if (media === DARK) {
|
|
1361
1456
|
html.classList.add('theme-dark');
|
|
1362
1457
|
} else if (media === LIGHT) {
|
|
1363
1458
|
html.classList.remove('theme-dark');
|
|
1364
1459
|
}
|
|
1365
|
-
};
|
|
1366
|
-
|
|
1460
|
+
};
|
|
1367
1461
|
|
|
1462
|
+
// app 初始化,Init
|
|
1368
1463
|
function init() {
|
|
1369
1464
|
if (Device$1.cordova && app.params.initOnDeviceReady) {
|
|
1370
|
-
$(document).on('deviceready',
|
|
1465
|
+
$(document).on('deviceready', () => {
|
|
1371
1466
|
app.init();
|
|
1372
1467
|
});
|
|
1373
1468
|
} else {
|
|
1374
1469
|
app.init();
|
|
1375
1470
|
}
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
if (app.params.init) init(); // Return app instance
|
|
1380
|
-
|
|
1381
|
-
return app || _assertThisInitialized(_this);
|
|
1382
|
-
} // 首次加载事件,全局只触发一次
|
|
1471
|
+
}
|
|
1383
1472
|
|
|
1473
|
+
// 应用初始化,路由跳转时不执行初始化
|
|
1474
|
+
if (app.params.init) init();
|
|
1384
1475
|
|
|
1385
|
-
|
|
1476
|
+
// Return app instance
|
|
1477
|
+
return app;
|
|
1478
|
+
}
|
|
1386
1479
|
|
|
1387
|
-
|
|
1480
|
+
// 首次加载事件,全局只触发一次
|
|
1481
|
+
load(param) {
|
|
1388
1482
|
this.emit('local::load appLoad', param);
|
|
1389
|
-
}
|
|
1390
|
-
;
|
|
1483
|
+
}
|
|
1391
1484
|
|
|
1392
|
-
|
|
1485
|
+
// 从后台切换到前台显示事件
|
|
1486
|
+
show(url, data) {
|
|
1393
1487
|
this.emit('local::show appShow', url, data);
|
|
1394
|
-
}
|
|
1395
|
-
;
|
|
1488
|
+
}
|
|
1396
1489
|
|
|
1397
|
-
|
|
1490
|
+
// 从前台显示切换到后台事件
|
|
1491
|
+
hide() {
|
|
1398
1492
|
this.emit('local::hide appHide');
|
|
1399
|
-
}
|
|
1400
|
-
;
|
|
1493
|
+
}
|
|
1401
1494
|
|
|
1402
|
-
|
|
1495
|
+
// 卸载应用事件
|
|
1496
|
+
unload() {
|
|
1403
1497
|
this.emit('local::unload appUnload');
|
|
1404
1498
|
}
|
|
1499
|
+
|
|
1405
1500
|
/**
|
|
1406
1501
|
* 初始化数据
|
|
1407
1502
|
*/
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
_proto.initData = function initData() {
|
|
1411
|
-
var app = this; // Data
|
|
1503
|
+
initData() {
|
|
1504
|
+
const app = this;
|
|
1412
1505
|
|
|
1506
|
+
// Data
|
|
1413
1507
|
app.data = {};
|
|
1414
|
-
|
|
1415
1508
|
if (app.params.data && typeof app.params.data === 'function') {
|
|
1416
1509
|
$.extend(app.data, app.params.data.bind(app)());
|
|
1417
1510
|
} else if (app.params.data) {
|
|
1418
1511
|
$.extend(app.data, app.params.data);
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1512
|
+
}
|
|
1513
|
+
// Methods
|
|
1422
1514
|
app.methods = {};
|
|
1423
|
-
|
|
1424
1515
|
if (app.params.methods) {
|
|
1425
|
-
Object.keys(app.params.methods).forEach(
|
|
1516
|
+
Object.keys(app.params.methods).forEach(methodName => {
|
|
1426
1517
|
if (typeof app.params.methods[methodName] === 'function') {
|
|
1427
1518
|
app.methods[methodName] = app.params.methods[methodName].bind(app);
|
|
1428
1519
|
} else {
|
|
@@ -1430,200 +1521,203 @@ var App = /*#__PURE__*/function (_Module) {
|
|
|
1430
1521
|
}
|
|
1431
1522
|
});
|
|
1432
1523
|
}
|
|
1433
|
-
}
|
|
1524
|
+
}
|
|
1434
1525
|
|
|
1435
|
-
|
|
1526
|
+
enableAutoDarkTheme() {
|
|
1436
1527
|
if (!window.matchMedia) return;
|
|
1437
|
-
var app = this;
|
|
1438
|
-
var html = document.querySelector('html');
|
|
1439
1528
|
|
|
1529
|
+
const app = this;
|
|
1530
|
+
const html = document.querySelector('html');
|
|
1440
1531
|
if (app.mq.dark && app.mq.light) {
|
|
1441
1532
|
app.mq.dark.addListener(app.colorSchemeListener);
|
|
1442
1533
|
app.mq.light.addListener(app.colorSchemeListener);
|
|
1443
1534
|
}
|
|
1444
|
-
|
|
1445
1535
|
if (app.mq.dark && app.mq.dark.matches) {
|
|
1446
1536
|
html.classList.add('theme-dark');
|
|
1447
1537
|
} else if (app.mq.light && app.mq.light.matches) {
|
|
1448
1538
|
html.classList.remove('theme-dark');
|
|
1449
1539
|
}
|
|
1450
|
-
}
|
|
1540
|
+
}
|
|
1451
1541
|
|
|
1452
|
-
|
|
1542
|
+
disableAutoDarkTheme() {
|
|
1453
1543
|
if (!window.matchMedia) return;
|
|
1454
|
-
|
|
1544
|
+
|
|
1545
|
+
const app = this;
|
|
1455
1546
|
if (app.mq.dark) app.mq.dark.removeListener(app.colorSchemeListener);
|
|
1456
1547
|
if (app.mq.light) app.mq.light.removeListener(app.colorSchemeListener);
|
|
1457
|
-
}
|
|
1458
|
-
;
|
|
1548
|
+
}
|
|
1459
1549
|
|
|
1460
|
-
|
|
1461
|
-
|
|
1550
|
+
// 初始化,包括控制 html 样式,wia app 启动时需要执行,切换app时,不需要
|
|
1551
|
+
init() {
|
|
1552
|
+
const app = this;
|
|
1462
1553
|
if (app.initialized) return app;
|
|
1554
|
+
|
|
1463
1555
|
$.App = App;
|
|
1464
1556
|
|
|
1465
1557
|
if (Device$1.ios && Device$1.webView) {
|
|
1466
1558
|
// Strange hack required for iOS 8 webview to work on inputs
|
|
1467
|
-
window.addEventListener('touchstart',
|
|
1559
|
+
window.addEventListener('touchstart', () => {});
|
|
1468
1560
|
}
|
|
1469
1561
|
|
|
1470
|
-
app.root.addClass('framework7-initializing');
|
|
1562
|
+
app.root.addClass('framework7-initializing');
|
|
1471
1563
|
|
|
1564
|
+
// RTL attr
|
|
1472
1565
|
if (app.rtl) {
|
|
1473
1566
|
$('html').attr('dir', 'rtl');
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1567
|
+
}
|
|
1476
1568
|
|
|
1569
|
+
// Auto Dark Theme
|
|
1477
1570
|
if (app.params.autoDarkTheme) {
|
|
1478
1571
|
app.enableAutoDarkTheme();
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1572
|
+
}
|
|
1481
1573
|
|
|
1482
|
-
|
|
1574
|
+
// Watch for online/offline state
|
|
1575
|
+
window.addEventListener('offline', () => {
|
|
1483
1576
|
app.online = false;
|
|
1484
1577
|
app.emit('offline');
|
|
1485
1578
|
app.emit('connection', false);
|
|
1486
1579
|
});
|
|
1487
|
-
|
|
1580
|
+
|
|
1581
|
+
window.addEventListener('online', () => {
|
|
1488
1582
|
app.online = true;
|
|
1489
1583
|
app.emit('online');
|
|
1490
1584
|
app.emit('connection', true);
|
|
1491
|
-
});
|
|
1585
|
+
});
|
|
1492
1586
|
|
|
1493
|
-
|
|
1587
|
+
// Root class
|
|
1588
|
+
app.root.addClass('framework7-root');
|
|
1494
1589
|
|
|
1495
|
-
|
|
1590
|
+
// Theme class
|
|
1591
|
+
$('html').removeClass('ios md aurora').addClass(app.theme);
|
|
1496
1592
|
|
|
1593
|
+
// iOS Translucent
|
|
1497
1594
|
if (app.params.iosTranslucentBars && app.theme === 'ios' && Device$1.ios) {
|
|
1498
1595
|
$('html').addClass('ios-translucent-bars');
|
|
1499
1596
|
}
|
|
1500
|
-
|
|
1501
1597
|
if (app.params.iosTranslucentModals && app.theme === 'ios' && Device$1.ios) {
|
|
1502
1598
|
$('html').addClass('ios-translucent-modals');
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1599
|
+
}
|
|
1505
1600
|
|
|
1506
|
-
|
|
1601
|
+
// Init class
|
|
1602
|
+
$.nextFrame(() => {
|
|
1507
1603
|
app.root.removeClass('framework7-initializing');
|
|
1508
1604
|
});
|
|
1509
|
-
initStyle(); // Emit, init other modules
|
|
1510
1605
|
|
|
1511
|
-
|
|
1606
|
+
initStyle();
|
|
1607
|
+
|
|
1608
|
+
// Emit, init other modules
|
|
1609
|
+
app.initialized = true;
|
|
1512
1610
|
|
|
1611
|
+
// 发起init 事件,模块 on 里面有 init方法的会被触发
|
|
1513
1612
|
app.emit('init');
|
|
1514
|
-
return app;
|
|
1515
|
-
} // eslint-disable-next-line
|
|
1516
|
-
;
|
|
1517
1613
|
|
|
1518
|
-
|
|
1519
|
-
|
|
1614
|
+
return app;
|
|
1615
|
+
}
|
|
1520
1616
|
|
|
1617
|
+
// eslint-disable-next-line
|
|
1618
|
+
loadModule(m) {
|
|
1619
|
+
App.loadModule(m);
|
|
1620
|
+
// 模块初始化
|
|
1521
1621
|
if (this[m.name].init) this[m.name].init();
|
|
1522
|
-
}
|
|
1523
|
-
;
|
|
1622
|
+
}
|
|
1524
1623
|
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1624
|
+
// eslint-disable-next-line
|
|
1625
|
+
loadModules(...args) {
|
|
1626
|
+
return App.loadModules(...args);
|
|
1627
|
+
}
|
|
1528
1628
|
|
|
1529
|
-
|
|
1530
|
-
|
|
1629
|
+
getVnodeHooks(hook, id) {
|
|
1630
|
+
const app = this;
|
|
1531
1631
|
if (!app.vnodeHooks || !app.vnodeHooks[hook]) return [];
|
|
1532
1632
|
return app.vnodeHooks[hook][id] || [];
|
|
1533
|
-
}
|
|
1534
|
-
;
|
|
1633
|
+
}
|
|
1535
1634
|
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
key: "Event",
|
|
1558
|
-
get: function get() {
|
|
1559
|
-
return Event;
|
|
1560
|
-
}
|
|
1561
|
-
}]);
|
|
1635
|
+
// eslint-disable-next-line
|
|
1636
|
+
get $() {
|
|
1637
|
+
return $;
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
static get Dom() {
|
|
1641
|
+
return $;
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
static get $() {
|
|
1645
|
+
return $;
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
static get Module() {
|
|
1649
|
+
return Module;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
static get Event() {
|
|
1653
|
+
return Event;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1562
1656
|
|
|
1563
|
-
return App;
|
|
1564
|
-
}(Module);
|
|
1565
1657
|
/**
|
|
1566
1658
|
* 初始化html样式
|
|
1567
1659
|
* from device module
|
|
1568
1660
|
*/
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
App.apps = {};
|
|
1572
|
-
|
|
1573
1661
|
function initStyle() {
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1662
|
+
const classNames = [];
|
|
1663
|
+
const html = document.querySelector('html');
|
|
1664
|
+
const metaStatusbar = document.querySelector(
|
|
1665
|
+
'meta[name="apple-mobile-web-app-status-bar-style"]'
|
|
1666
|
+
);
|
|
1577
1667
|
if (!html) return;
|
|
1578
|
-
|
|
1579
|
-
|
|
1668
|
+
if (
|
|
1669
|
+
Device$1.standalone &&
|
|
1670
|
+
Device$1.ios &&
|
|
1671
|
+
metaStatusbar &&
|
|
1672
|
+
metaStatusbar.content === 'black-translucent'
|
|
1673
|
+
) {
|
|
1580
1674
|
classNames.push('device-full-viewport');
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
classNames.push("device-pixel-ratio-" + Math.floor(Device$1.pixelRatio)); // OS classes
|
|
1675
|
+
}
|
|
1585
1676
|
|
|
1677
|
+
// Pixel Ratio
|
|
1678
|
+
classNames.push(`device-pixel-ratio-${Math.floor(Device$1.pixelRatio)}`);
|
|
1679
|
+
// OS classes
|
|
1586
1680
|
if (Device$1.os && !Device$1.desktop) {
|
|
1587
|
-
classNames.push(
|
|
1681
|
+
classNames.push(`device-${Device$1.os}`);
|
|
1588
1682
|
} else if (Device$1.desktop) {
|
|
1589
1683
|
classNames.push('device-desktop');
|
|
1590
|
-
|
|
1591
1684
|
if (Device$1.os) {
|
|
1592
|
-
classNames.push(
|
|
1685
|
+
classNames.push(`device-${Device$1.os}`);
|
|
1593
1686
|
}
|
|
1594
1687
|
}
|
|
1595
|
-
|
|
1596
1688
|
if (Device$1.cordova || Device$1.phonegap) {
|
|
1597
1689
|
classNames.push('device-cordova');
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1690
|
+
}
|
|
1600
1691
|
|
|
1601
|
-
|
|
1602
|
-
|
|
1692
|
+
// Add html classes
|
|
1693
|
+
classNames.forEach(className => {
|
|
1694
|
+
html.classList.add(className);
|
|
1695
|
+
// console.log({className});
|
|
1603
1696
|
});
|
|
1604
|
-
}
|
|
1697
|
+
}
|
|
1605
1698
|
|
|
1699
|
+
// App 类 静态方法、属性
|
|
1606
1700
|
|
|
1607
1701
|
App.ModalMethods = Modals;
|
|
1608
|
-
App.ConstructorMethods = Constructors;
|
|
1609
|
-
|
|
1702
|
+
App.ConstructorMethods = Constructors;
|
|
1703
|
+
// 动态加载模块(base里面已经内置动态加载,这个方法应该用不上)
|
|
1610
1704
|
App.loadModule = loadModule;
|
|
1611
|
-
|
|
1612
1705
|
App.loadModules = function (modules) {
|
|
1613
|
-
return Promise.all(modules.map(
|
|
1614
|
-
|
|
1615
|
-
}));
|
|
1616
|
-
}; // app 加载到 app实例的一些扩展模块
|
|
1617
|
-
|
|
1706
|
+
return Promise.all(modules.map(module => App.loadModule(module)));
|
|
1707
|
+
};
|
|
1618
1708
|
|
|
1709
|
+
// app 加载到 app实例的一些扩展模块
|
|
1619
1710
|
App.support = Support$1;
|
|
1620
1711
|
App.device = Device$1;
|
|
1621
|
-
App.utils = Utils;
|
|
1712
|
+
App.utils = Utils;
|
|
1713
|
+
|
|
1714
|
+
// 添加应用缺省模块
|
|
1715
|
+
App.use([
|
|
1716
|
+
Resize, // 控制屏幕大小
|
|
1717
|
+
Click, // 触发UI组件的点击(Click 或 Touch)事件
|
|
1718
|
+
SW$1, // ServiceWorker
|
|
1622
1719
|
|
|
1623
|
-
|
|
1624
|
-
Click, // 触发UI组件的点击(Click 或 Touch)事件
|
|
1625
|
-
SW$1 // ServiceWorker
|
|
1626
|
-
//INSTALL_COMPONENTS
|
|
1720
|
+
//INSTALL_COMPONENTS
|
|
1627
1721
|
]);
|
|
1628
1722
|
|
|
1629
1723
|
/**
|
|
@@ -1637,37 +1731,36 @@ SW$1 // ServiceWorker
|
|
|
1637
1731
|
* loadView 加载视图中(每次页面更新内容后,需调用)
|
|
1638
1732
|
* _lazy.update(); // 没有显示的图片,加入 待加载数组,并检查是否可视,可视则加载!
|
|
1639
1733
|
*/
|
|
1734
|
+
|
|
1640
1735
|
// options
|
|
1641
|
-
|
|
1642
|
-
normal: 'nor',
|
|
1643
|
-
// 'data-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
srcset: 'set',
|
|
1647
|
-
// 'data-srcset', 浏览器根据宽、高和像素密度来加载相应的图片资源
|
|
1648
|
-
threshold: 0
|
|
1736
|
+
const _opts = {
|
|
1737
|
+
normal: 'nor', // 'data-normal' 普通图片
|
|
1738
|
+
retina: 'ret', // 'data-retina',
|
|
1739
|
+
srcset: 'set', // 'data-srcset', 浏览器根据宽、高和像素密度来加载相应的图片资源
|
|
1740
|
+
threshold: 0,
|
|
1649
1741
|
};
|
|
1650
1742
|
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
var _windowHeight = window.innerHeight;
|
|
1743
|
+
let _opt;
|
|
1744
|
+
let _ticking;
|
|
1745
|
+
let _nodes;
|
|
1746
|
+
let _windowHeight = window.innerHeight;
|
|
1747
|
+
let _root;
|
|
1658
1748
|
|
|
1659
|
-
|
|
1749
|
+
// private
|
|
1750
|
+
let _prevLoc = getLoc();
|
|
1660
1751
|
|
|
1661
|
-
|
|
1662
|
-
var _prevLoc = getLoc(); // feature detection
|
|
1752
|
+
// feature detection
|
|
1663
1753
|
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/img/srcset.js
|
|
1754
|
+
const _srcset =
|
|
1755
|
+
document.body.classList.contains('srcset') ||
|
|
1756
|
+
'srcset' in document.createElement('img');
|
|
1664
1757
|
|
|
1665
|
-
|
|
1666
|
-
var _srcset = document.body.classList.contains('srcset') || 'srcset' in document.createElement('img'); // 设备分辨率
|
|
1758
|
+
// 设备分辨率
|
|
1667
1759
|
// not supported in IE10 - https://msdn.microsoft.com/en-us/library/dn265030(v=vs.85).aspx
|
|
1760
|
+
const _dpr =
|
|
1761
|
+
window.devicePixelRatio ||
|
|
1762
|
+
window.screen.deviceXDPI / window.screen.logicalXDPI;
|
|
1668
1763
|
|
|
1669
|
-
|
|
1670
|
-
var _dpr = window.devicePixelRatio || window.screen.deviceXDPI / window.screen.logicalXDPI;
|
|
1671
1764
|
/**
|
|
1672
1765
|
* 输外部可调用的类
|
|
1673
1766
|
* 类外面的变量、函数作为模块内部私有属性、方法,外部无法调用
|
|
@@ -1675,67 +1768,62 @@ var _dpr = window.devicePixelRatio || window.screen.deviceXDPI / window.screen.l
|
|
|
1675
1768
|
* 也可以直接使用 export default (options = {}) => {} 输出一个函数!
|
|
1676
1769
|
* 函数内部反而不需要this,比较方便。
|
|
1677
1770
|
*/
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
var Lazy = /*#__PURE__*/function () {
|
|
1771
|
+
class Lazy {
|
|
1681
1772
|
// 实例属性
|
|
1682
|
-
|
|
1773
|
+
constructor(opt) {
|
|
1683
1774
|
_opt = $.assign({}, _opts, opt);
|
|
1684
|
-
}
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
// API
|
|
1778
|
+
|
|
1685
1779
|
//----------------------------------------
|
|
1686
1780
|
// dom 就绪后 start,dom 更新后,需 update
|
|
1687
|
-
|
|
1688
1781
|
/**
|
|
1689
1782
|
* 启动延迟加载, 加载事件, dom ready时调用!
|
|
1690
1783
|
* @param root 根对象, scroll的目标对象,错了无法触发scroll 事件!
|
|
1691
1784
|
* @returns {init}
|
|
1692
1785
|
*/
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
var _proto = Lazy.prototype;
|
|
1696
|
-
|
|
1697
|
-
_proto.start = function start(root) {
|
|
1786
|
+
start(root) {
|
|
1698
1787
|
// sui window scroll event invalid!!!
|
|
1699
1788
|
// ['scroll', 'resize'].forEach(event => window[action](event, requestScroll));
|
|
1700
|
-
['scroll', 'resize'].forEach(
|
|
1701
|
-
|
|
1702
|
-
|
|
1789
|
+
['scroll', 'resize'].forEach(event =>
|
|
1790
|
+
root['addEventListener'](event, requestScroll)
|
|
1791
|
+
);
|
|
1703
1792
|
_root = root;
|
|
1704
1793
|
return this;
|
|
1705
1794
|
}
|
|
1795
|
+
|
|
1706
1796
|
/**
|
|
1707
1797
|
* 停止延迟加载,卸载事件!
|
|
1708
1798
|
* @param root 根对象, scroll的目标对象
|
|
1709
1799
|
* @returns {init}
|
|
1710
1800
|
*/
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
_proto.stop = function stop() {
|
|
1801
|
+
stop() {
|
|
1714
1802
|
// sui window scroll event invalid!!!
|
|
1715
1803
|
// ['scroll', 'resize'].forEach(event => window[action](event, requestScroll));
|
|
1716
|
-
['scroll', 'resize'].forEach(
|
|
1717
|
-
|
|
1718
|
-
|
|
1804
|
+
['scroll', 'resize'].forEach(event =>
|
|
1805
|
+
_root['removeEventListener'](event, requestScroll)
|
|
1806
|
+
);
|
|
1719
1807
|
return this;
|
|
1720
|
-
}
|
|
1721
|
-
|
|
1722
|
-
_proto.update = function update() {
|
|
1723
|
-
setTimeout(function () {
|
|
1724
|
-
_update();
|
|
1808
|
+
}
|
|
1725
1809
|
|
|
1810
|
+
update() {
|
|
1811
|
+
setTimeout(() => {
|
|
1812
|
+
update();
|
|
1726
1813
|
check();
|
|
1727
1814
|
}, 1);
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
return Lazy;
|
|
1731
|
-
}();
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1732
1817
|
|
|
1818
|
+
/**
|
|
1819
|
+
* Y 坐标,好像一直是 0
|
|
1820
|
+
*/
|
|
1733
1821
|
function getLoc() {
|
|
1734
1822
|
// console.log(`window.scrollY:${window.scrollY} window.pageYOffset:${window.pageYOffset}`);
|
|
1735
1823
|
return window.scrollY || window.pageYOffset;
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1824
|
+
}
|
|
1738
1825
|
|
|
1826
|
+
// debounce helpers
|
|
1739
1827
|
function requestScroll() {
|
|
1740
1828
|
_prevLoc = getLoc();
|
|
1741
1829
|
requestFrame();
|
|
@@ -1743,22 +1831,21 @@ function requestScroll() {
|
|
|
1743
1831
|
|
|
1744
1832
|
function requestFrame() {
|
|
1745
1833
|
if (!_ticking) {
|
|
1746
|
-
window.requestAnimationFrame(
|
|
1747
|
-
return check();
|
|
1748
|
-
});
|
|
1834
|
+
window.requestAnimationFrame(() => check());
|
|
1749
1835
|
_ticking = true;
|
|
1750
1836
|
}
|
|
1751
|
-
}
|
|
1837
|
+
}
|
|
1752
1838
|
|
|
1839
|
+
// offset helper
|
|
1753
1840
|
/**
|
|
1754
1841
|
* 节点相对视口的坐标,对于动态加载的,好像得到都是0,使用定时器延迟加载就能正确获取!
|
|
1755
1842
|
*/
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
1843
|
function getOffset(node) {
|
|
1759
1844
|
// 元素四个位置的相对于视口的坐标
|
|
1760
|
-
return node.getBoundingClientRect().top + _prevLoc;
|
|
1845
|
+
return node.getBoundingClientRect().top + _prevLoc;
|
|
1846
|
+
// return node.offsetTop + _prevLoc;
|
|
1761
1847
|
}
|
|
1848
|
+
|
|
1762
1849
|
/**
|
|
1763
1850
|
* 节点是否在可视窗口判断
|
|
1764
1851
|
* 通过可视窗口顶部、底部坐标来判断
|
|
@@ -1767,263 +1854,136 @@ function getOffset(node) {
|
|
|
1767
1854
|
* dom元素中心:元素到最顶端的高度加上自身高度的一半
|
|
1768
1855
|
* @param {*} node
|
|
1769
1856
|
*/
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
1857
|
function inViewport(node) {
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
var viewBot = viewTop + _windowHeight; // 视口底部坐标
|
|
1858
|
+
const viewTop = _prevLoc; // 视口顶部坐标
|
|
1859
|
+
const viewBot = viewTop + _windowHeight; // 视口底部坐标
|
|
1776
1860
|
// console.log(`viewTop:${viewTop} viewBot:${viewBot}`);
|
|
1777
|
-
// 节点坐标
|
|
1778
|
-
|
|
1779
|
-
var nodeTop = getOffset(node);
|
|
1780
|
-
var nodeBot = nodeTop + node.offsetHeight; // console.log(`nodeTop:${nodeTop} nodeBot:${nodeBot}`);
|
|
1781
|
-
|
|
1782
|
-
var offset = _opt.threshold / 100 * _windowHeight; // 节点在可视范围内
|
|
1783
1861
|
|
|
1784
|
-
|
|
1862
|
+
// 节点坐标
|
|
1863
|
+
const nodeTop = getOffset(node);
|
|
1864
|
+
const nodeBot = nodeTop + node.offsetHeight;
|
|
1865
|
+
// console.log(`nodeTop:${nodeTop} nodeBot:${nodeBot}`);
|
|
1866
|
+
|
|
1867
|
+
const offset = (_opt.threshold / 100) * _windowHeight;
|
|
1868
|
+
// 节点在可视范围内
|
|
1869
|
+
const rc = nodeBot >= viewTop - offset && nodeTop <= viewBot + offset;
|
|
1870
|
+
// if (rc)
|
|
1785
1871
|
// console.log(`nodeBot:${nodeBot} >= view:${viewTop - offset} nodeTop:${nodeTop} <= view:${viewBot + offset}`);
|
|
1786
1872
|
|
|
1787
1873
|
return rc;
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1874
|
+
}
|
|
1790
1875
|
|
|
1876
|
+
// source helper
|
|
1791
1877
|
function setSource(node) {
|
|
1792
|
-
$.emit('lazy:src:before', node);
|
|
1878
|
+
$.emit('lazy:src:before', node);
|
|
1793
1879
|
|
|
1880
|
+
// prefer srcset, fallback to pixel density
|
|
1794
1881
|
if (_srcset && node.hasAttribute(_opt.srcset)) {
|
|
1795
1882
|
node.setAttribute('srcset', node.getAttribute(_opt.srcset));
|
|
1796
1883
|
} else {
|
|
1797
|
-
|
|
1798
|
-
|
|
1884
|
+
const retina = _dpr > 1 && node.getAttribute(_opt.retina);
|
|
1885
|
+
const src = retina || node.getAttribute(_opt.normal);
|
|
1799
1886
|
node.setAttribute('src', src);
|
|
1800
|
-
console.log(
|
|
1887
|
+
console.log(`set src:${src}`);
|
|
1801
1888
|
}
|
|
1802
1889
|
|
|
1803
|
-
$.emit('lazy:src:after', node);
|
|
1804
|
-
|
|
1805
|
-
[_opt.normal, _opt.retina, _opt.srcset].forEach(
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
_update();
|
|
1890
|
+
$.emit('lazy:src:after', node);
|
|
1891
|
+
// 删除懒加载属性,避免重复加载
|
|
1892
|
+
[_opt.normal, _opt.retina, _opt.srcset].forEach(attr =>
|
|
1893
|
+
node.removeAttribute(attr)
|
|
1894
|
+
);
|
|
1895
|
+
update();
|
|
1810
1896
|
}
|
|
1897
|
+
|
|
1811
1898
|
/**
|
|
1812
1899
|
* 检查是否可视,如果可视则更改图片src,加载图片
|
|
1813
1900
|
* @returns {check}
|
|
1814
1901
|
*/
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
1902
|
function check() {
|
|
1818
1903
|
if (!_nodes) return;
|
|
1819
|
-
_windowHeight = window.innerHeight;
|
|
1820
|
-
|
|
1821
|
-
_nodes.forEach(function (node) {
|
|
1822
|
-
return inViewport(node) && setSource(node);
|
|
1823
|
-
});
|
|
1824
1904
|
|
|
1905
|
+
_windowHeight = window.innerHeight;
|
|
1906
|
+
_nodes.forEach(node => inViewport(node) && setSource(node));
|
|
1825
1907
|
_ticking = false;
|
|
1826
1908
|
return this;
|
|
1827
1909
|
}
|
|
1910
|
+
|
|
1828
1911
|
/**
|
|
1829
1912
|
* 新的图片加入dom,需重新获取属性为nor的图片节点,
|
|
1830
1913
|
* @returns {update}
|
|
1831
1914
|
*/
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1915
|
+
function update(root) {
|
|
1916
|
+
if (root)
|
|
1917
|
+
_nodes = Array.prototype.slice.call(
|
|
1918
|
+
root.querySelectorAll(`[${_opt.normal}]`)
|
|
1919
|
+
);
|
|
1920
|
+
else
|
|
1921
|
+
_nodes = Array.prototype.slice.call(
|
|
1922
|
+
document.querySelectorAll(`[${_opt.normal}]`)
|
|
1923
|
+
);
|
|
1836
1924
|
return this;
|
|
1837
1925
|
}
|
|
1838
1926
|
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
function Page(app, name, title, style) {
|
|
1843
|
-
var _this;
|
|
1844
|
-
|
|
1845
|
-
_this = _Event.call(this, null, [app]) || this;
|
|
1846
|
-
_this.app = app;
|
|
1847
|
-
_this.cfg = app.cfg;
|
|
1848
|
-
_this.name = name; // 名称,支持带路径:admin/login
|
|
1849
|
-
|
|
1850
|
-
_this.title = title; // 浏览器标题
|
|
1851
|
-
|
|
1852
|
-
_this.style = style || "./page/" + name + ".css";
|
|
1853
|
-
_this.path = "" + name; // url 路径,不使用正则,直接查找
|
|
1854
|
-
|
|
1855
|
-
_this.view = null; // 页面的div层$Dom对象,router创建实例时赋值
|
|
1856
|
-
|
|
1857
|
-
_this.el = null; // $dom
|
|
1858
|
-
|
|
1859
|
-
_this.$el = null; // $dom
|
|
1860
|
-
|
|
1861
|
-
_this.html = ''; // 页面html文本,router创建实例时赋值
|
|
1862
|
-
|
|
1863
|
-
_this.css = ''; // 页面css样式,router创建实例时赋值
|
|
1864
|
-
|
|
1865
|
-
_this.js = ''; // 页面代码,router创建实例时赋值
|
|
1866
|
-
|
|
1867
|
-
_this.data = {}; // 页面数据对象
|
|
1868
|
-
|
|
1869
|
-
_this.param = {}; // 页面切换传递进来的参数对象,router创建实例时赋值
|
|
1870
|
-
|
|
1871
|
-
return _this;
|
|
1872
|
-
}
|
|
1873
|
-
/**
|
|
1874
|
-
* 异步加载页面视图内容
|
|
1875
|
-
* 返回Promise对象
|
|
1876
|
-
* @param {*} param
|
|
1877
|
-
* @param {*} cfg
|
|
1878
|
-
*/
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
var _proto = Page.prototype;
|
|
1882
|
-
|
|
1883
|
-
_proto.load = function load(param) {
|
|
1884
|
-
// $.assign(this.data, param);
|
|
1885
|
-
this.emit('local::load pageLoad', param);
|
|
1886
|
-
}
|
|
1887
|
-
/**
|
|
1888
|
-
* 在已经加载就绪的视图上操作
|
|
1889
|
-
* @param {*} view 页面层的 Dom 对象,已经使用`$(#page-name)`,做了处理
|
|
1890
|
-
* @param {*} param go 函数的参数,或 网址中 url 中的参数
|
|
1891
|
-
* @param {*} back 是否为回退,A->B, B->A,这种操作属于回退
|
|
1892
|
-
*/
|
|
1893
|
-
;
|
|
1894
|
-
|
|
1895
|
-
_proto.ready = function ready(view, param, back) {
|
|
1896
|
-
// $.assign(this, {page, param, back});
|
|
1897
|
-
// $.assign(this.data, param);
|
|
1898
|
-
// 隐藏所有模板
|
|
1899
|
-
this.init();
|
|
1900
|
-
this.emit('local::ready pageReady', view, param, back);
|
|
1901
|
-
}
|
|
1902
|
-
/**
|
|
1903
|
-
* 对页面进行初始化处理,或页面内容动态变更时,对局部页面容器进行初始化
|
|
1904
|
-
* 具备name属性的dom节点直接赋值给页面view
|
|
1905
|
-
* 只挂载一个,多个同名name,最后一个起作用,因此一个页面内,name不要重复
|
|
1906
|
-
* 同节点多次调用不覆盖,同名不同dom节点,覆盖
|
|
1907
|
-
* 覆盖后,原直接节点属性的 bind 会失效,需真的新的$dom重新bind
|
|
1908
|
-
* @param {*} v dom 容器,默认为页面实例的view
|
|
1909
|
-
*/
|
|
1910
|
-
;
|
|
1911
|
-
|
|
1912
|
-
_proto.init = function init(v) {
|
|
1913
|
-
var view = this.view;
|
|
1914
|
-
v = v ? $(v) : view; // 页面上带name属性节点,直接作为page.view的属性,方便页面代码直接调用
|
|
1915
|
-
|
|
1916
|
-
var ns = v.qus('[name]');
|
|
1917
|
-
ns === null || ns === void 0 ? void 0 : ns.forEach(function (n) {
|
|
1918
|
-
var $n = $(n);
|
|
1919
|
-
var name = $n.attr('name');
|
|
1920
|
-
if (!view[name] || view[name].dom !== n) view[name] = $n;
|
|
1921
|
-
}); // 隐藏所有模板
|
|
1922
|
-
|
|
1923
|
-
v.qus('[name$=-tp]').hide(); // 防止空链接,刷新页面
|
|
1924
|
-
|
|
1925
|
-
v.qus('a[href=""]').attr('href', 'javascript:;');
|
|
1926
|
-
} // 显示已加载的页面
|
|
1927
|
-
// view:页面Dom层,param:参数
|
|
1928
|
-
;
|
|
1929
|
-
|
|
1930
|
-
_proto.show = function show(view, param) {
|
|
1931
|
-
// 隐藏所有模板
|
|
1932
|
-
view.qus('[name$=-tp]').hide(); // 防止空链接,刷新页面
|
|
1933
|
-
|
|
1934
|
-
view.qus('a[href=""]').attr('href', 'javascript:;'); // this.init();
|
|
1935
|
-
|
|
1936
|
-
if (this.reset) this.reset();
|
|
1937
|
-
this.emit('local::show pageShow', view, param);
|
|
1938
|
-
} // 回退显示已加载的页面
|
|
1939
|
-
// view:页面Dom层,param:参数
|
|
1940
|
-
;
|
|
1941
|
-
|
|
1942
|
-
_proto.back = function back(view, param) {
|
|
1943
|
-
// 隐藏所有模板
|
|
1944
|
-
view.qus('[name$=-tp]').hide(); // 防止空链接,刷新页面
|
|
1945
|
-
|
|
1946
|
-
view.qus('a[href=""]').attr('href', 'javascript:;');
|
|
1947
|
-
this.emit('local::back pageBack', view, param);
|
|
1948
|
-
};
|
|
1949
|
-
|
|
1950
|
-
_proto.hide = function hide(view) {
|
|
1951
|
-
this.emit('local::hide pageHide', view);
|
|
1952
|
-
};
|
|
1953
|
-
|
|
1954
|
-
return Page;
|
|
1955
|
-
}(Event);
|
|
1956
|
-
|
|
1957
|
-
var openedModals = [];
|
|
1958
|
-
var dialogsQueue = [];
|
|
1959
|
-
|
|
1927
|
+
const openedModals = [];
|
|
1928
|
+
const dialogsQueue = [];
|
|
1960
1929
|
function clearDialogsQueue() {
|
|
1961
1930
|
if (dialogsQueue.length === 0) return;
|
|
1962
|
-
|
|
1931
|
+
const dialog = dialogsQueue.shift();
|
|
1963
1932
|
dialog.open();
|
|
1964
1933
|
}
|
|
1934
|
+
class Modal extends Event {
|
|
1935
|
+
constructor(app, params) {
|
|
1936
|
+
super(params, [app]);
|
|
1965
1937
|
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
function Modal(app, params) {
|
|
1970
|
-
var _this;
|
|
1971
|
-
|
|
1972
|
-
_this = _Event.call(this, params, [app]) || this;
|
|
1973
|
-
|
|
1974
|
-
var modal = _assertThisInitialized(_this);
|
|
1975
|
-
|
|
1976
|
-
var defaults = {};
|
|
1938
|
+
const modal = this;
|
|
1939
|
+
const defaults = {};
|
|
1977
1940
|
modal.params = Utils.extend(defaults, params);
|
|
1978
1941
|
modal.opened = false;
|
|
1979
|
-
return
|
|
1942
|
+
return this;
|
|
1980
1943
|
}
|
|
1981
1944
|
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
_proto.onOpen = function onOpen() {
|
|
1985
|
-
var modal = this;
|
|
1945
|
+
onOpen() {
|
|
1946
|
+
const modal = this;
|
|
1986
1947
|
modal.opened = true;
|
|
1987
1948
|
openedModals.push(modal);
|
|
1988
|
-
$('html').addClass(
|
|
1989
|
-
modal.$el.trigger(
|
|
1990
|
-
modal.emit(
|
|
1991
|
-
}
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
modal.$el.trigger(
|
|
1996
|
-
modal.emit(
|
|
1997
|
-
}
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
1949
|
+
$('html').addClass(`with-modal-${modal.type.toLowerCase()}`);
|
|
1950
|
+
modal.$el.trigger(`modal:open ${modal.type.toLowerCase()}:open`);
|
|
1951
|
+
modal.emit(`local::open modalOpen ${modal.type}Open`, modal);
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
onOpened() {
|
|
1955
|
+
const modal = this;
|
|
1956
|
+
modal.$el.trigger(`modal:opened ${modal.type.toLowerCase()}:opened`);
|
|
1957
|
+
modal.emit(`local::opened modalOpened ${modal.type}Opened`, modal);
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
onClose() {
|
|
1961
|
+
const modal = this;
|
|
2001
1962
|
modal.opened = false;
|
|
2002
1963
|
if (!modal.type || !modal.$el) return;
|
|
2003
1964
|
openedModals.splice(openedModals.indexOf(modal), 1);
|
|
2004
|
-
$('html').removeClass(
|
|
2005
|
-
modal.$el.trigger(
|
|
2006
|
-
modal.emit(
|
|
2007
|
-
}
|
|
1965
|
+
$('html').removeClass(`with-modal-${modal.type.toLowerCase()}`);
|
|
1966
|
+
modal.$el.trigger(`modal:close ${modal.type.toLowerCase()}:close`);
|
|
1967
|
+
modal.emit(`local::close modalClose ${modal.type}Close`, modal);
|
|
1968
|
+
}
|
|
2008
1969
|
|
|
2009
|
-
|
|
2010
|
-
|
|
1970
|
+
onClosed() {
|
|
1971
|
+
const modal = this;
|
|
2011
1972
|
if (!modal.type || !modal.$el) return;
|
|
2012
1973
|
modal.$el.removeClass('modal-out');
|
|
2013
1974
|
modal.$el.hide();
|
|
2014
|
-
modal.$el.trigger(
|
|
2015
|
-
modal.emit(
|
|
2016
|
-
}
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
if (typeof animateModal !== 'undefined') animate = animateModal;else if (typeof modal.params.animate !== 'undefined') {
|
|
1975
|
+
modal.$el.trigger(`modal:closed ${modal.type.toLowerCase()}:closed`);
|
|
1976
|
+
modal.emit(`local::closed modalClosed ${modal.type}Closed`, modal);
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
open(animateModal) {
|
|
1980
|
+
const modal = this;
|
|
1981
|
+
const {app, $el, type, $backdropEl} = modal;
|
|
1982
|
+
const {moveToRoot} = modal.params;
|
|
1983
|
+
|
|
1984
|
+
let animate = true;
|
|
1985
|
+
if (typeof animateModal !== 'undefined') animate = animateModal;
|
|
1986
|
+
else if (typeof modal.params.animate !== 'undefined') {
|
|
2027
1987
|
animate = modal.params.animate;
|
|
2028
1988
|
}
|
|
2029
1989
|
|
|
@@ -2032,42 +1992,43 @@ var Modal = /*#__PURE__*/function (_Event) {
|
|
|
2032
1992
|
}
|
|
2033
1993
|
|
|
2034
1994
|
if (type === 'dialog' && app.params.modal.queueDialogs) {
|
|
2035
|
-
|
|
2036
|
-
|
|
1995
|
+
let pushToQueue;
|
|
2037
1996
|
if ($('.dialog.modal-in').length > 0) {
|
|
2038
1997
|
pushToQueue = true;
|
|
2039
1998
|
} else if (openedModals.length > 0) {
|
|
2040
|
-
openedModals.forEach(
|
|
1999
|
+
openedModals.forEach(openedModal => {
|
|
2041
2000
|
if (openedModal.type === 'dialog') pushToQueue = true;
|
|
2042
2001
|
});
|
|
2043
2002
|
}
|
|
2044
|
-
|
|
2045
2003
|
if (pushToQueue) {
|
|
2046
2004
|
dialogsQueue.push(modal);
|
|
2047
2005
|
return modal;
|
|
2048
2006
|
}
|
|
2049
2007
|
}
|
|
2050
2008
|
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2009
|
+
const $modalParentEl = $el.parent();
|
|
2010
|
+
const wasInDom = $el.parents(document).length > 0;
|
|
2011
|
+
if (
|
|
2012
|
+
moveToRoot &&
|
|
2013
|
+
app.params.modal.moveToRoot &&
|
|
2014
|
+
!$modalParentEl.is(app.root)
|
|
2015
|
+
) {
|
|
2055
2016
|
app.root.append($el);
|
|
2056
|
-
modal.once(type
|
|
2017
|
+
modal.once(`${type}Closed`, () => {
|
|
2057
2018
|
if (wasInDom) {
|
|
2058
2019
|
$modalParentEl.append($el);
|
|
2059
2020
|
} else {
|
|
2060
2021
|
$el.remove();
|
|
2061
2022
|
}
|
|
2062
2023
|
});
|
|
2063
|
-
}
|
|
2064
|
-
|
|
2065
|
-
|
|
2024
|
+
}
|
|
2025
|
+
// Show Modal
|
|
2066
2026
|
$el.show();
|
|
2067
|
-
/* eslint no-underscore-dangle: ["error", { "allow": ["_clientLeft"] }] */
|
|
2068
2027
|
|
|
2069
|
-
|
|
2028
|
+
/* eslint no-underscore-dangle: ["error", { "allow": ["_clientLeft"] }] */
|
|
2029
|
+
modal._clientLeft = $el[0].clientLeft;
|
|
2070
2030
|
|
|
2031
|
+
// Modal
|
|
2071
2032
|
function transitionEnd() {
|
|
2072
2033
|
if ($el.hasClass('modal-out')) {
|
|
2073
2034
|
modal.onClosed();
|
|
@@ -2075,17 +2036,15 @@ var Modal = /*#__PURE__*/function (_Event) {
|
|
|
2075
2036
|
modal.onOpened();
|
|
2076
2037
|
}
|
|
2077
2038
|
}
|
|
2078
|
-
|
|
2079
2039
|
if (animate) {
|
|
2080
2040
|
if ($backdropEl) {
|
|
2081
2041
|
$backdropEl.removeClass('not-animated');
|
|
2082
2042
|
$backdropEl.addClass('backdrop-in');
|
|
2083
2043
|
}
|
|
2084
|
-
|
|
2085
|
-
$el.animationEnd(function () {
|
|
2044
|
+
$el.animationEnd(() => {
|
|
2086
2045
|
transitionEnd();
|
|
2087
2046
|
});
|
|
2088
|
-
$el.transitionEnd(
|
|
2047
|
+
$el.transitionEnd(() => {
|
|
2089
2048
|
transitionEnd();
|
|
2090
2049
|
});
|
|
2091
2050
|
$el.removeClass('modal-out not-animated').addClass('modal-in');
|
|
@@ -2094,21 +2053,22 @@ var Modal = /*#__PURE__*/function (_Event) {
|
|
|
2094
2053
|
if ($backdropEl) {
|
|
2095
2054
|
$backdropEl.addClass('backdrop-in not-animated');
|
|
2096
2055
|
}
|
|
2097
|
-
|
|
2098
2056
|
$el.removeClass('modal-out').addClass('modal-in not-animated');
|
|
2099
2057
|
modal.onOpen();
|
|
2100
2058
|
modal.onOpened();
|
|
2101
2059
|
}
|
|
2102
2060
|
|
|
2103
2061
|
return modal;
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
close(animateModal) {
|
|
2065
|
+
const modal = this;
|
|
2066
|
+
const $el = modal.$el;
|
|
2067
|
+
const $backdropEl = modal.$backdropEl;
|
|
2068
|
+
|
|
2069
|
+
let animate = true;
|
|
2070
|
+
if (typeof animateModal !== 'undefined') animate = animateModal;
|
|
2071
|
+
else if (typeof modal.params.animate !== 'undefined') {
|
|
2112
2072
|
animate = modal.params.animate;
|
|
2113
2073
|
}
|
|
2114
2074
|
|
|
@@ -2116,34 +2076,33 @@ var Modal = /*#__PURE__*/function (_Event) {
|
|
|
2116
2076
|
if (dialogsQueue.indexOf(modal) >= 0) {
|
|
2117
2077
|
dialogsQueue.splice(dialogsQueue.indexOf(modal), 1);
|
|
2118
2078
|
}
|
|
2119
|
-
|
|
2120
2079
|
return modal;
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2080
|
+
}
|
|
2123
2081
|
|
|
2082
|
+
// backdrop
|
|
2124
2083
|
if ($backdropEl) {
|
|
2125
|
-
|
|
2126
|
-
|
|
2084
|
+
let needToHideBackdrop = true;
|
|
2127
2085
|
if (modal.type === 'popup') {
|
|
2128
|
-
modal.$el.prevAll('.popup.modal-in').each(
|
|
2129
|
-
|
|
2086
|
+
modal.$el.prevAll('.popup.modal-in').each((index, popupEl) => {
|
|
2087
|
+
const popupInstance = popupEl.f7Modal;
|
|
2130
2088
|
if (!popupInstance) return;
|
|
2131
|
-
|
|
2132
|
-
|
|
2089
|
+
if (
|
|
2090
|
+
popupInstance.params.closeByBackdropClick &&
|
|
2091
|
+
popupInstance.params.backdrop &&
|
|
2092
|
+
popupInstance.backdropEl === modal.backdropEl
|
|
2093
|
+
) {
|
|
2133
2094
|
needToHideBackdrop = false;
|
|
2134
2095
|
}
|
|
2135
2096
|
});
|
|
2136
2097
|
}
|
|
2137
|
-
|
|
2138
2098
|
if (needToHideBackdrop) {
|
|
2139
2099
|
$backdropEl[animate ? 'removeClass' : 'addClass']('not-animated');
|
|
2140
2100
|
$backdropEl.removeClass('backdrop-in');
|
|
2141
2101
|
}
|
|
2142
|
-
}
|
|
2143
|
-
|
|
2102
|
+
}
|
|
2144
2103
|
|
|
2104
|
+
// Modal
|
|
2145
2105
|
$el[animate ? 'removeClass' : 'addClass']('not-animated');
|
|
2146
|
-
|
|
2147
2106
|
function transitionEnd() {
|
|
2148
2107
|
if ($el.hasClass('modal-out')) {
|
|
2149
2108
|
modal.onClosed();
|
|
@@ -2151,20 +2110,22 @@ var Modal = /*#__PURE__*/function (_Event) {
|
|
|
2151
2110
|
modal.onOpened();
|
|
2152
2111
|
}
|
|
2153
2112
|
}
|
|
2154
|
-
|
|
2155
2113
|
if (animate) {
|
|
2156
|
-
$el.animationEnd(
|
|
2114
|
+
$el.animationEnd(() => {
|
|
2157
2115
|
transitionEnd();
|
|
2158
2116
|
});
|
|
2159
|
-
$el.transitionEnd(
|
|
2117
|
+
$el.transitionEnd(() => {
|
|
2160
2118
|
transitionEnd();
|
|
2161
2119
|
});
|
|
2162
|
-
$el.removeClass('modal-in').addClass('modal-out');
|
|
2163
|
-
|
|
2120
|
+
$el.removeClass('modal-in').addClass('modal-out');
|
|
2121
|
+
// Emit close
|
|
2164
2122
|
modal.onClose();
|
|
2165
2123
|
} else {
|
|
2166
|
-
$el
|
|
2167
|
-
|
|
2124
|
+
$el
|
|
2125
|
+
.addClass('not-animated')
|
|
2126
|
+
.removeClass('modal-in')
|
|
2127
|
+
.addClass('modal-out');
|
|
2128
|
+
// Emit close
|
|
2168
2129
|
modal.onClose();
|
|
2169
2130
|
modal.onClosed();
|
|
2170
2131
|
}
|
|
@@ -2174,65 +2135,58 @@ var Modal = /*#__PURE__*/function (_Event) {
|
|
|
2174
2135
|
}
|
|
2175
2136
|
|
|
2176
2137
|
return modal;
|
|
2177
|
-
}
|
|
2138
|
+
}
|
|
2178
2139
|
|
|
2179
|
-
|
|
2180
|
-
|
|
2140
|
+
destroy() {
|
|
2141
|
+
const modal = this;
|
|
2181
2142
|
if (modal.destroyed) return;
|
|
2182
|
-
modal.emit(
|
|
2183
|
-
|
|
2143
|
+
modal.emit(
|
|
2144
|
+
`local::beforeDestroy modalBeforeDestroy ${modal.type}BeforeDestroy`,
|
|
2145
|
+
modal
|
|
2146
|
+
);
|
|
2184
2147
|
if (modal.$el) {
|
|
2185
|
-
modal.$el.trigger(
|
|
2186
|
-
|
|
2148
|
+
modal.$el.trigger(
|
|
2149
|
+
`modal:beforedestroy ${modal.type.toLowerCase()}:beforedestroy`
|
|
2150
|
+
);
|
|
2187
2151
|
if (modal.$el.length && modal.$el[0].f7Modal) {
|
|
2188
2152
|
delete modal.$el[0].f7Modal;
|
|
2189
2153
|
}
|
|
2190
2154
|
}
|
|
2191
|
-
|
|
2192
2155
|
Utils.deleteProps(modal);
|
|
2193
2156
|
modal.destroyed = true;
|
|
2194
|
-
};
|
|
2195
|
-
|
|
2196
|
-
return Modal;
|
|
2197
|
-
}(Event);
|
|
2198
|
-
|
|
2199
|
-
// replace react, use by @babel/plugin-transform-react-jsx
|
|
2200
|
-
|
|
2201
|
-
/* eslint-disable prefer-rest-params */
|
|
2202
|
-
function jsx(tag, props) {
|
|
2203
|
-
var attrs = props || {};
|
|
2204
|
-
|
|
2205
|
-
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
2206
|
-
args[_key - 2] = arguments[_key];
|
|
2207
|
-
}
|
|
2208
|
-
|
|
2209
|
-
var children = args || [];
|
|
2210
|
-
var attrsString = Object.keys(attrs).map(function (attr) {
|
|
2211
|
-
if (attr[0] === '_') {
|
|
2212
|
-
if (attrs[attr]) return attr.replace('_', '');
|
|
2213
|
-
return '';
|
|
2214
|
-
}
|
|
2215
|
-
|
|
2216
|
-
return attr + "=\"" + attrs[attr] + "\"";
|
|
2217
|
-
}).filter(function (attr) {
|
|
2218
|
-
return !!attr;
|
|
2219
|
-
}).join(' ');
|
|
2220
|
-
|
|
2221
|
-
if (['path', 'img', 'circle', 'polygon', 'line', 'input'].indexOf(tag) >= 0) {
|
|
2222
|
-
return ("<" + tag + " " + attrsString + " />").trim();
|
|
2223
2157
|
}
|
|
2224
|
-
|
|
2225
|
-
var childrenContent = children.filter(function (c) {
|
|
2226
|
-
return !!c;
|
|
2227
|
-
}).map(function (c) {
|
|
2228
|
-
return Array.isArray(c) ? c.join('') : c;
|
|
2229
|
-
}).join('');
|
|
2230
|
-
return ("<" + tag + " " + attrsString + ">" + childrenContent + "</" + tag + ">").trim();
|
|
2231
2158
|
}
|
|
2232
2159
|
|
|
2233
|
-
//
|
|
2160
|
+
// replace react, use by @babel/plugin-transform-react-jsx
|
|
2161
|
+
/* eslint-disable prefer-rest-params */
|
|
2162
|
+
function jsx(tag, props, ...args) {
|
|
2163
|
+
const attrs = props || {};
|
|
2164
|
+
const children = args || [];
|
|
2165
|
+
|
|
2166
|
+
const attrsString = Object.keys(attrs)
|
|
2167
|
+
.map((attr) => {
|
|
2168
|
+
if (attr[0] === '_') {
|
|
2169
|
+
if (attrs[attr]) return attr.replace('_', '');
|
|
2170
|
+
return '';
|
|
2171
|
+
}
|
|
2172
|
+
return `${attr}="${attrs[attr]}"`;
|
|
2173
|
+
})
|
|
2174
|
+
.filter((attr) => !!attr)
|
|
2175
|
+
.join(' ');
|
|
2176
|
+
|
|
2177
|
+
if (['path', 'img', 'circle', 'polygon', 'line', 'input'].indexOf(tag) >= 0) {
|
|
2178
|
+
return `<${tag} ${attrsString} />`.trim();
|
|
2179
|
+
}
|
|
2180
|
+
const childrenContent = children
|
|
2181
|
+
.filter((c) => !!c)
|
|
2182
|
+
.map((c) => (Array.isArray(c) ? c.join('') : c))
|
|
2183
|
+
.join('');
|
|
2184
|
+
return `<${tag} ${attrsString}>${childrenContent}</${tag}>`.trim();
|
|
2185
|
+
}
|
|
2234
2186
|
|
|
2235
|
-
|
|
2236
|
-
|
|
2187
|
+
// export {default as Support} from './support';
|
|
2188
|
+
// export {default as Device} from './device';
|
|
2189
|
+
const Support = $.support;
|
|
2190
|
+
const Device = $.device;
|
|
2237
2191
|
|
|
2238
2192
|
export { Ajax, App, Constructors, Device, Event, Lazy, Modal, Modals, Module, Page, Resize, SW$1 as SW, Support, Utils, jsx, loadModule };
|