1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import Component from '@egjs/component';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | var extendStatics = function (d, b) {
|
28 | extendStatics = Object.setPrototypeOf || {
|
29 | __proto__: []
|
30 | } instanceof Array && function (d, b) {
|
31 | d.__proto__ = b;
|
32 | } || function (d, b) {
|
33 | for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
34 | };
|
35 |
|
36 | return extendStatics(d, b);
|
37 | };
|
38 |
|
39 | function __extends(d, b) {
|
40 | extendStatics(d, b);
|
41 |
|
42 | function __() {
|
43 | this.constructor = d;
|
44 | }
|
45 |
|
46 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
47 | }
|
48 | var __assign = function () {
|
49 | __assign = Object.assign || function __assign(t) {
|
50 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
51 | s = arguments[i];
|
52 |
|
53 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
54 | }
|
55 |
|
56 | return t;
|
57 | };
|
58 |
|
59 | return __assign.apply(this, arguments);
|
60 | };
|
61 | function __spreadArrays() {
|
62 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
63 |
|
64 | for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
|
65 |
|
66 | return r;
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | var isWindow = typeof window !== "undefined";
|
75 | var ua = isWindow ? window.navigator.userAgent : "";
|
76 | var SUPPORT_COMPUTEDSTYLE = isWindow ? !!("getComputedStyle" in window) : false;
|
77 | var IS_IE = /MSIE|Trident|Windows Phone|Edge/.test(ua);
|
78 | var SUPPORT_ADDEVENTLISTENER = isWindow ? !!("addEventListener" in document) : false;
|
79 | var WIDTH = "width";
|
80 | var HEIGHT = "height";
|
81 |
|
82 | function getAttribute(el, name) {
|
83 | return el.getAttribute(name) || "";
|
84 | }
|
85 | function toArray(arr) {
|
86 | return [].slice.call(arr);
|
87 | }
|
88 | function hasSizeAttribute(target, prefix) {
|
89 | if (prefix === void 0) {
|
90 | prefix = "data-";
|
91 | }
|
92 |
|
93 | return !!target.getAttribute(prefix + "width");
|
94 | }
|
95 | function hasLoadingAttribute(target) {
|
96 | return "loading" in target && target.getAttribute("loading") === "lazy";
|
97 | }
|
98 | function hasSkipAttribute(target, prefix) {
|
99 | if (prefix === void 0) {
|
100 | prefix = "data-";
|
101 | }
|
102 |
|
103 | return !!target.getAttribute(prefix + "skip");
|
104 | }
|
105 | function addEvent(element, type, handler) {
|
106 | if (SUPPORT_ADDEVENTLISTENER) {
|
107 | element.addEventListener(type, handler, false);
|
108 | } else if (element.attachEvent) {
|
109 | element.attachEvent("on" + type, handler);
|
110 | } else {
|
111 | element["on" + type] = handler;
|
112 | }
|
113 | }
|
114 | function removeEvent(element, type, handler) {
|
115 | if (element.removeEventListener) {
|
116 | element.removeEventListener(type, handler, false);
|
117 | } else if (element.detachEvent) {
|
118 | element.detachEvent("on" + type, handler);
|
119 | } else {
|
120 | element["on" + type] = null;
|
121 | }
|
122 | }
|
123 | function innerWidth(el) {
|
124 | return getSize(el, "Width");
|
125 | }
|
126 | function innerHeight(el) {
|
127 | return getSize(el, "Height");
|
128 | }
|
129 | function getStyles(el) {
|
130 | return (SUPPORT_COMPUTEDSTYLE ? window.getComputedStyle(el) : el.currentStyle) || {};
|
131 | }
|
132 |
|
133 | function getSize(el, name) {
|
134 | var size = el["client" + name] || el["offset" + name];
|
135 | return parseFloat(size || getStyles(el)[name.toLowerCase()]) || 0;
|
136 | }
|
137 |
|
138 | function getContentElements(element, tags, prefix) {
|
139 | var skipElements = toArray(element.querySelectorAll(__spreadArrays(["[" + prefix + "skip] [" + prefix + "width]"], tags.map(function (tag) {
|
140 | return ["[" + prefix + "skip] " + tag, tag + "[" + prefix + "skip]", "[" + prefix + "width] " + tag].join(", ");
|
141 | })).join(", ")));
|
142 | return toArray(element.querySelectorAll("[" + prefix + "width], " + tags.join(", "))).filter(function (el) {
|
143 | return skipElements.indexOf(el) === -1;
|
144 | });
|
145 | }
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | var elements = [];
|
153 | function addAutoSizer(element, prefix) {
|
154 | !elements.length && addEvent(window, "resize", resizeAllAutoSizers);
|
155 | element.__PREFIX__ = prefix;
|
156 | elements.push(element);
|
157 | resize(element);
|
158 | }
|
159 | function removeAutoSizer(element, prefix) {
|
160 | var index = elements.indexOf(element);
|
161 |
|
162 | if (index < 0) {
|
163 | return;
|
164 | }
|
165 |
|
166 | var fixed = getAttribute(element, prefix + "fixed");
|
167 | delete element.__PREFIX__;
|
168 | element.style[fixed === HEIGHT ? WIDTH : HEIGHT] = "";
|
169 | elements.splice(index, 1);
|
170 | !elements.length && removeEvent(window, "resize", resizeAllAutoSizers);
|
171 | }
|
172 |
|
173 | function resize(element, prefix) {
|
174 | if (prefix === void 0) {
|
175 | prefix = "data-";
|
176 | }
|
177 |
|
178 | var elementPrefix = element.__PREFIX__ || prefix;
|
179 | var dataWidth = parseInt(getAttribute(element, "" + elementPrefix + WIDTH), 10) || 0;
|
180 | var dataHeight = parseInt(getAttribute(element, "" + elementPrefix + HEIGHT), 10) || 0;
|
181 | var fixed = getAttribute(element, elementPrefix + "fixed");
|
182 |
|
183 | if (fixed === HEIGHT) {
|
184 | var size = innerHeight(element) || dataHeight;
|
185 | element.style[WIDTH] = dataWidth / dataHeight * size + "px";
|
186 | } else {
|
187 | var size = innerWidth(element) || dataWidth;
|
188 | element.style[HEIGHT] = dataHeight / dataWidth * size + "px";
|
189 | }
|
190 | }
|
191 |
|
192 | function resizeAllAutoSizers() {
|
193 | elements.forEach(function (element) {
|
194 | resize(element);
|
195 | });
|
196 | }
|
197 |
|
198 | var Loader =
|
199 |
|
200 | function (_super) {
|
201 | __extends(Loader, _super);
|
202 |
|
203 | function Loader(element, options) {
|
204 | if (options === void 0) {
|
205 | options = {};
|
206 | }
|
207 |
|
208 | var _this = _super.call(this) || this;
|
209 |
|
210 | _this.isReady = false;
|
211 | _this.isPreReady = false;
|
212 | _this.hasDataSize = false;
|
213 | _this.hasLoading = false;
|
214 | _this.isSkip = false;
|
215 |
|
216 | _this.onCheck = function (e) {
|
217 | _this.clear();
|
218 |
|
219 | if (e && e.type === "error") {
|
220 | _this.onError(_this.element);
|
221 | }
|
222 |
|
223 |
|
224 | var withPreReady = !_this.hasDataSize && !_this.hasLoading;
|
225 |
|
226 | _this.onReady(withPreReady);
|
227 | };
|
228 |
|
229 | _this.options = __assign({
|
230 | prefix: "data-"
|
231 | }, options);
|
232 | _this.element = element;
|
233 | var prefix = _this.options.prefix;
|
234 | _this.hasDataSize = hasSizeAttribute(element, prefix);
|
235 | _this.isSkip = hasSkipAttribute(element, prefix);
|
236 | _this.hasLoading = hasLoadingAttribute(element);
|
237 | return _this;
|
238 | }
|
239 |
|
240 | var __proto = Loader.prototype;
|
241 |
|
242 | __proto.check = function () {
|
243 | if (this.isSkip || !this.checkElement()) {
|
244 |
|
245 | this.onAlreadyReady(true);
|
246 | return false;
|
247 | }
|
248 |
|
249 | if (this.hasDataSize) {
|
250 | addAutoSizer(this.element, this.options.prefix);
|
251 | }
|
252 |
|
253 | if (this.hasDataSize || this.hasLoading) {
|
254 |
|
255 | this.onAlreadyPreReady();
|
256 | }
|
257 |
|
258 |
|
259 | return true;
|
260 | };
|
261 |
|
262 | __proto.addEvents = function () {
|
263 | var _this = this;
|
264 |
|
265 | var element = this.element;
|
266 | this.constructor.EVENTS.forEach(function (name) {
|
267 | addEvent(element, name, _this.onCheck);
|
268 | });
|
269 | };
|
270 |
|
271 | __proto.clear = function () {
|
272 | var _this = this;
|
273 |
|
274 | var element = this.element;
|
275 | this.constructor.EVENTS.forEach(function (name) {
|
276 | removeEvent(element, name, _this.onCheck);
|
277 | });
|
278 | this.removeAutoSizer();
|
279 | };
|
280 |
|
281 | __proto.destroy = function () {
|
282 | this.clear();
|
283 | this.off();
|
284 | };
|
285 |
|
286 | __proto.removeAutoSizer = function () {
|
287 | if (this.hasDataSize) {
|
288 |
|
289 | var prefix = this.options.prefix;
|
290 | removeAutoSizer(this.element, prefix);
|
291 | }
|
292 | };
|
293 |
|
294 | __proto.onError = function (target) {
|
295 | this.trigger("error", {
|
296 | element: this.element,
|
297 | target: target
|
298 | });
|
299 | };
|
300 |
|
301 | __proto.onPreReady = function () {
|
302 | if (this.isPreReady) {
|
303 | return;
|
304 | }
|
305 |
|
306 | this.isPreReady = true;
|
307 | this.trigger("preReady", {
|
308 | element: this.element,
|
309 | hasLoading: this.hasLoading,
|
310 | isSkip: this.isSkip
|
311 | });
|
312 | };
|
313 |
|
314 | __proto.onReady = function (withPreReady) {
|
315 | if (this.isReady) {
|
316 | return;
|
317 | }
|
318 |
|
319 | withPreReady = !this.isPreReady && withPreReady;
|
320 |
|
321 | if (withPreReady) {
|
322 | this.isPreReady = true;
|
323 | }
|
324 |
|
325 | this.removeAutoSizer();
|
326 | this.isReady = true;
|
327 | this.trigger("ready", {
|
328 | element: this.element,
|
329 | withPreReady: withPreReady,
|
330 | hasLoading: this.hasLoading,
|
331 | isSkip: this.isSkip
|
332 | });
|
333 | };
|
334 |
|
335 | __proto.onAlreadyError = function (target) {
|
336 | var _this = this;
|
337 |
|
338 | setTimeout(function () {
|
339 | _this.onError(target);
|
340 | });
|
341 | };
|
342 |
|
343 | __proto.onAlreadyPreReady = function () {
|
344 | var _this = this;
|
345 |
|
346 | setTimeout(function () {
|
347 | _this.onPreReady();
|
348 | });
|
349 | };
|
350 |
|
351 | __proto.onAlreadyReady = function (withPreReady) {
|
352 | var _this = this;
|
353 |
|
354 | setTimeout(function () {
|
355 | _this.onReady(withPreReady);
|
356 | });
|
357 | };
|
358 |
|
359 | Loader.EVENTS = [];
|
360 | return Loader;
|
361 | }(Component);
|
362 |
|
363 | var ElementLoader =
|
364 |
|
365 | function (_super) {
|
366 | __extends(ElementLoader, _super);
|
367 |
|
368 | function ElementLoader() {
|
369 | return _super !== null && _super.apply(this, arguments) || this;
|
370 | }
|
371 |
|
372 | var __proto = ElementLoader.prototype;
|
373 |
|
374 | __proto.setHasLoading = function (hasLoading) {
|
375 | this.hasLoading = hasLoading;
|
376 | };
|
377 |
|
378 | __proto.check = function () {
|
379 | if (this.isSkip) {
|
380 |
|
381 | this.onAlreadyReady(true);
|
382 | return false;
|
383 | }
|
384 |
|
385 | if (this.hasDataSize) {
|
386 | addAutoSizer(this.element, this.options.prefix);
|
387 | this.onAlreadyPreReady();
|
388 | } else {
|
389 |
|
390 | this.trigger("requestChildren");
|
391 | }
|
392 |
|
393 | return true;
|
394 | };
|
395 |
|
396 | __proto.checkElement = function () {
|
397 | return true;
|
398 | };
|
399 |
|
400 | __proto.destroy = function () {
|
401 | this.clear();
|
402 | this.trigger("requestDestroy");
|
403 | this.off();
|
404 | };
|
405 |
|
406 | __proto.onAlreadyPreReady = function () {
|
407 |
|
408 | _super.prototype.onAlreadyPreReady.call(this);
|
409 |
|
410 | this.trigger("reqeustReadyChildren");
|
411 | };
|
412 |
|
413 | ElementLoader.EVENTS = [];
|
414 | return ElementLoader;
|
415 | }(Loader);
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 | var ImReadyManager =
|
423 |
|
424 | function (_super) {
|
425 | __extends(ImReadyManager, _super);
|
426 | |
427 |
|
428 |
|
429 |
|
430 |
|
431 | function ImReadyManager(options) {
|
432 | if (options === void 0) {
|
433 | options = {};
|
434 | }
|
435 |
|
436 | var _this = _super.call(this) || this;
|
437 |
|
438 | _this.readyCount = 0;
|
439 | _this.preReadyCount = 0;
|
440 | _this.totalCount = 0;
|
441 | _this.totalErrorCount = 0;
|
442 | _this.isPreReadyOver = true;
|
443 | _this.elementInfos = [];
|
444 | _this.options = __assign({
|
445 | loaders: {},
|
446 | prefix: "data-"
|
447 | }, options);
|
448 | return _this;
|
449 | }
|
450 | |
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 | var __proto = ImReadyManager.prototype;
|
480 |
|
481 | __proto.check = function (elements) {
|
482 | var _this = this;
|
483 |
|
484 | var prefix = this.options.prefix;
|
485 | this.clear();
|
486 | this.elementInfos = toArray(elements).map(function (element, index) {
|
487 | var loader = _this.getLoader(element, {
|
488 | prefix: prefix
|
489 | });
|
490 |
|
491 | loader.check();
|
492 | loader.on("error", function (e) {
|
493 | _this.onError(index, e.target);
|
494 | }).on("preReady", function (e) {
|
495 | var info = _this.elementInfos[index];
|
496 | info.hasLoading = e.hasLoading;
|
497 | info.isSkip = e.isSkip;
|
498 |
|
499 | var isPreReady = _this.checkPreReady(index);
|
500 |
|
501 | _this.onPreReadyElement(index);
|
502 |
|
503 | isPreReady && _this.onPreReady();
|
504 | }).on("ready", function (_a) {
|
505 | var withPreReady = _a.withPreReady,
|
506 | hasLoading = _a.hasLoading,
|
507 | isSkip = _a.isSkip;
|
508 | var info = _this.elementInfos[index];
|
509 | info.hasLoading = hasLoading;
|
510 | info.isSkip = isSkip;
|
511 |
|
512 | var isPreReady = withPreReady && _this.checkPreReady(index);
|
513 |
|
514 | var isReady = _this.checkReady(index);
|
515 |
|
516 |
|
517 | withPreReady && _this.onPreReadyElement(index);
|
518 |
|
519 | _this.onReadyElement(index);
|
520 |
|
521 | isPreReady && _this.onPreReady();
|
522 | isReady && _this.onReady();
|
523 | });
|
524 | return {
|
525 | loader: loader,
|
526 | element: element,
|
527 | hasLoading: false,
|
528 | hasError: false,
|
529 | isPreReady: false,
|
530 | isReady: false,
|
531 | isSkip: false
|
532 | };
|
533 | });
|
534 | var length = this.elementInfos.length;
|
535 | this.totalCount = length;
|
536 |
|
537 | if (!length) {
|
538 | setTimeout(function () {
|
539 | _this.onPreReady();
|
540 |
|
541 | _this.onReady();
|
542 | });
|
543 | }
|
544 |
|
545 | return this;
|
546 | };
|
547 | |
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 | __proto.getTotalCount = function () {
|
554 | return this.totalCount;
|
555 | };
|
556 | |
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 | __proto.isPreReady = function () {
|
563 | return this.elementInfos.every(function (info) {
|
564 | return info.isPreReady;
|
565 | });
|
566 | };
|
567 | |
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 | __proto.isReady = function () {
|
574 | return this.elementInfos.every(function (info) {
|
575 | return info.isReady;
|
576 | });
|
577 | };
|
578 | |
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 | __proto.hasError = function () {
|
585 | return this.totalErrorCount > 0;
|
586 | };
|
587 | |
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 | __proto.clear = function () {
|
594 | this.isPreReadyOver = false;
|
595 | this.totalCount = 0;
|
596 | this.preReadyCount = 0;
|
597 | this.readyCount = 0;
|
598 | this.totalErrorCount = 0;
|
599 | this.elementInfos.forEach(function (info) {
|
600 | if (!info.isReady && info.loader) {
|
601 | info.loader.destroy();
|
602 | }
|
603 | });
|
604 | this.elementInfos = [];
|
605 | };
|
606 | |
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 | __proto.destroy = function () {
|
613 | this.clear();
|
614 | this.off();
|
615 | };
|
616 |
|
617 | __proto.getLoader = function (element, options) {
|
618 | var _this = this;
|
619 |
|
620 | var tagName = element.tagName.toLowerCase();
|
621 | var loaders = this.options.loaders;
|
622 | var tags = Object.keys(loaders);
|
623 |
|
624 | if (loaders[tagName]) {
|
625 | return new loaders[tagName](element, options);
|
626 | }
|
627 |
|
628 | var loader = new ElementLoader(element, options);
|
629 | var children = toArray(element.querySelectorAll(tags.join(", ")));
|
630 | loader.setHasLoading(children.some(function (el) {
|
631 | return hasLoadingAttribute(el);
|
632 | }));
|
633 | var withPreReady = false;
|
634 | var childrenImReady = this.clone().on("error", function (e) {
|
635 | loader.onError(e.target);
|
636 | }).on("ready", function () {
|
637 | loader.onReady(withPreReady);
|
638 | });
|
639 | loader.on("requestChildren", function () {
|
640 |
|
641 | var contentElements = getContentElements(element, tags, _this.options.prefix);
|
642 | childrenImReady.check(contentElements).on("preReady", function (e) {
|
643 | withPreReady = e.isReady;
|
644 |
|
645 | if (!withPreReady) {
|
646 | loader.onPreReady();
|
647 | }
|
648 | });
|
649 | }).on("reqeustReadyChildren", function () {
|
650 |
|
651 |
|
652 |
|
653 | childrenImReady.check(children);
|
654 | }).on("requestDestroy", function () {
|
655 | childrenImReady.destroy();
|
656 | });
|
657 | return loader;
|
658 | };
|
659 |
|
660 | __proto.clone = function () {
|
661 | return new ImReadyManager(__assign({}, this.options));
|
662 | };
|
663 |
|
664 | __proto.checkPreReady = function (index) {
|
665 | this.elementInfos[index].isPreReady = true;
|
666 | ++this.preReadyCount;
|
667 |
|
668 | if (this.preReadyCount < this.totalCount) {
|
669 | return false;
|
670 | }
|
671 |
|
672 | return true;
|
673 | };
|
674 |
|
675 | __proto.checkReady = function (index) {
|
676 | this.elementInfos[index].isReady = true;
|
677 | ++this.readyCount;
|
678 |
|
679 | if (this.readyCount < this.totalCount) {
|
680 | return false;
|
681 | }
|
682 |
|
683 | return true;
|
684 | };
|
685 |
|
686 | __proto.onError = function (index, target) {
|
687 | var info = this.elementInfos[index];
|
688 | info.hasError = true;
|
689 | |
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 | this.trigger("error", {
|
722 | element: info.element,
|
723 | index: index,
|
724 | target: target,
|
725 | errorCount: this.getErrorCount(),
|
726 | totalErrorCount: ++this.totalErrorCount
|
727 | });
|
728 | };
|
729 |
|
730 | __proto.onPreReadyElement = function (index) {
|
731 | var info = this.elementInfos[index];
|
732 | |
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 | this.trigger("preReadyElement", {
|
771 | element: info.element,
|
772 | index: index,
|
773 | preReadyCount: this.preReadyCount,
|
774 | readyCount: this.readyCount,
|
775 | totalCount: this.totalCount,
|
776 | isPreReady: this.isPreReady(),
|
777 | isReady: this.isReady(),
|
778 | hasLoading: info.hasLoading,
|
779 | isSkip: info.isSkip
|
780 | });
|
781 | };
|
782 |
|
783 | __proto.onPreReady = function () {
|
784 | this.isPreReadyOver = true;
|
785 | |
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 | this.trigger("preReady", {
|
817 | readyCount: this.readyCount,
|
818 | totalCount: this.totalCount,
|
819 | isReady: this.isReady(),
|
820 | hasLoading: this.hasLoading()
|
821 | });
|
822 | };
|
823 |
|
824 | __proto.onReadyElement = function (index) {
|
825 | var info = this.elementInfos[index];
|
826 | |
827 |
|
828 |
|
829 |
|
830 |
|
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 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 | this.trigger("readyElement", {
|
869 | index: index,
|
870 | element: info.element,
|
871 | hasError: info.hasError,
|
872 | errorCount: this.getErrorCount(),
|
873 | totalErrorCount: this.totalErrorCount,
|
874 | preReadyCount: this.preReadyCount,
|
875 | readyCount: this.readyCount,
|
876 | totalCount: this.totalCount,
|
877 | isPreReady: this.isPreReady(),
|
878 | isReady: this.isReady(),
|
879 | hasLoading: info.hasLoading,
|
880 | isPreReadyOver: this.isPreReadyOver,
|
881 | isSkip: info.isSkip
|
882 | });
|
883 | };
|
884 |
|
885 | __proto.onReady = function () {
|
886 | |
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 | this.trigger("ready", {
|
920 | errorCount: this.getErrorCount(),
|
921 | totalErrorCount: this.totalErrorCount,
|
922 | totalCount: this.totalCount
|
923 | });
|
924 | };
|
925 |
|
926 | __proto.getErrorCount = function () {
|
927 | return this.elementInfos.filter(function (info) {
|
928 | return info.hasError;
|
929 | }).length;
|
930 | };
|
931 |
|
932 | __proto.hasLoading = function () {
|
933 | return this.elementInfos.some(function (info) {
|
934 | return info.hasLoading;
|
935 | });
|
936 | };
|
937 |
|
938 | return ImReadyManager;
|
939 | }(Component);
|
940 |
|
941 | var ImageLoader =
|
942 |
|
943 | function (_super) {
|
944 | __extends(ImageLoader, _super);
|
945 |
|
946 | function ImageLoader() {
|
947 | return _super !== null && _super.apply(this, arguments) || this;
|
948 | }
|
949 |
|
950 | var __proto = ImageLoader.prototype;
|
951 |
|
952 | __proto.checkElement = function () {
|
953 | var element = this.element;
|
954 | var src = element.getAttribute("src");
|
955 |
|
956 | if (element.complete) {
|
957 | if (src) {
|
958 |
|
959 | if (!element.naturalWidth) {
|
960 | this.onAlreadyError(element);
|
961 | }
|
962 |
|
963 | return false;
|
964 | } else {
|
965 |
|
966 | this.onAlreadyPreReady();
|
967 | }
|
968 | }
|
969 |
|
970 | this.addEvents();
|
971 | IS_IE && element.setAttribute("src", src);
|
972 | return true;
|
973 | };
|
974 |
|
975 | ImageLoader.EVENTS = ["load", "error"];
|
976 | return ImageLoader;
|
977 | }(Loader);
|
978 |
|
979 | var VideoLoader =
|
980 |
|
981 | function (_super) {
|
982 | __extends(VideoLoader, _super);
|
983 |
|
984 | function VideoLoader() {
|
985 | return _super !== null && _super.apply(this, arguments) || this;
|
986 | }
|
987 |
|
988 | var __proto = VideoLoader.prototype;
|
989 |
|
990 | __proto.checkElement = function () {
|
991 | var element = this.element;
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 | if (element.readyState >= 1) {
|
998 | return false;
|
999 | }
|
1000 |
|
1001 | if (element.error) {
|
1002 | this.onAlreadyError(element);
|
1003 | return false;
|
1004 | }
|
1005 |
|
1006 | this.addEvents();
|
1007 | return true;
|
1008 | };
|
1009 |
|
1010 | VideoLoader.EVENTS = ["loadedmetadata", "error"];
|
1011 | return VideoLoader;
|
1012 | }(Loader);
|
1013 |
|
1014 | var ImReady =
|
1015 |
|
1016 | function (_super) {
|
1017 | __extends(ImReady, _super);
|
1018 |
|
1019 | function ImReady(options) {
|
1020 | if (options === void 0) {
|
1021 | options = {};
|
1022 | }
|
1023 |
|
1024 | return _super.call(this, __assign({
|
1025 | loaders: {
|
1026 | img: ImageLoader,
|
1027 | video: VideoLoader
|
1028 | }
|
1029 | }, options)) || this;
|
1030 | }
|
1031 |
|
1032 | return ImReady;
|
1033 | }(ImReadyManager);
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 | export default ImReady;
|
1042 | export { ImageLoader, Loader, ImReadyManager as Manager, VideoLoader };
|
1043 |
|