1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,90 +0,0 @@ |
1 |
-import { window } from 'ssr-window'; |
|
2 |
-import Utils from '../../utils/utils'; |
|
3 |
-import Support from '../../utils/support'; |
|
4 |
- |
|
5 |
-const Observer = { |
|
6 |
- func: window.MutationObserver || window.WebkitMutationObserver, |
|
7 |
- attach(target, options = {}) { |
|
8 |
- const swiper = this; |
|
9 |
- |
|
10 |
- const ObserverFunc = Observer.func; |
|
11 |
- const observer = new ObserverFunc((mutations) => { |
|
12 |
- // The observerUpdate event should only be triggered |
|
13 |
- // once despite the number of mutations. Additional |
|
14 |
- // triggers are redundant and are very costly |
|
15 |
- if (mutations.length === 1) { |
|
16 |
- swiper.emit('observerUpdate', mutations[0]); |
|
17 |
- return; |
|
18 |
- } |
|
19 |
- const observerUpdate = function observerUpdate() { |
|
20 |
- swiper.emit('observerUpdate', mutations[0]); |
|
21 |
- }; |
|
22 |
- |
|
23 |
- if (window.requestAnimationFrame) { |
|
24 |
- window.requestAnimationFrame(observerUpdate); |
|
25 |
- } else { |
|
26 |
- window.setTimeout(observerUpdate, 0); |
|
27 |
- } |
|
28 |
- }); |
|
29 |
- |
|
30 |
- observer.observe(target, { |
|
31 |
- attributes: typeof options.attributes === 'undefined' ? true : options.attributes, |
|
32 |
- childList: typeof options.childList === 'undefined' ? true : options.childList, |
|
33 |
- characterData: typeof options.characterData === 'undefined' ? true : options.characterData, |
|
34 |
- }); |
|
35 |
- |
|
36 |
- swiper.observer.observers.push(observer); |
|
37 |
- }, |
|
38 |
- init() { |
|
39 |
- const swiper = this; |
|
40 |
- if (!Support.observer || !swiper.params.observer) return; |
|
41 |
- if (swiper.params.observeParents) { |
|
42 |
- const containerParents = swiper.$el.parents(); |
|
43 |
- for (let i = 0; i < containerParents.length; i += 1) { |
|
44 |
- swiper.observer.attach(containerParents[i]); |
|
45 |
- } |
|
46 |
- } |
|
47 |
- // Observe container |
|
48 |
- swiper.observer.attach(swiper.$el[0], { childList: swiper.params.observeSlideChildren }); |
|
49 |
- |
|
50 |
- // Observe wrapper |
|
51 |
- swiper.observer.attach(swiper.$wrapperEl[0], { attributes: false }); |
|
52 |
- }, |
|
53 |
- destroy() { |
|
54 |
- const swiper = this; |
|
55 |
- swiper.observer.observers.forEach((observer) => { |
|
56 |
- observer.disconnect(); |
|
57 |
- }); |
|
58 |
- swiper.observer.observers = []; |
|
59 |
- }, |
|
60 |
-}; |
|
61 |
- |
|
62 |
-export default { |
|
63 |
- name: 'observer', |
|
64 |
- params: { |
|
65 |
- observer: false, |
|
66 |
- observeParents: false, |
|
67 |
- observeSlideChildren: false, |
|
68 |
- }, |
|
69 |
- create() { |
|
70 |
- const swiper = this; |
|
71 |
- Utils.extend(swiper, { |
|
72 |
- observer: { |
|
73 |
- init: Observer.init.bind(swiper), |
|
74 |
- attach: Observer.attach.bind(swiper), |
|
75 |
- destroy: Observer.destroy.bind(swiper), |
|
76 |
- observers: [], |
|
77 |
- }, |
|
78 |
- }); |
|
79 |
- }, |
|
80 |
- on: { |
|
81 |
- init() { |
|
82 |
- const swiper = this; |
|
83 |
- swiper.observer.init(); |
|
84 |
- }, |
|
85 |
- destroy() { |
|
86 |
- const swiper = this; |
|
87 |
- swiper.observer.destroy(); |
|
88 |
- }, |
|
89 |
- }, |
|
90 |
-}; |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,90 @@ |
1 |
+import { window } from 'ssr-window'; |
|
2 |
+import Utils from '../../utils/utils'; |
|
3 |
+import Support from '../../utils/support'; |
|
4 |
+ |
|
5 |
+const Observer = { |
|
6 |
+ func: window.MutationObserver || window.WebkitMutationObserver, |
|
7 |
+ attach(target, options = {}) { |
|
8 |
+ const swiper = this; |
|
9 |
+ |
|
10 |
+ const ObserverFunc = Observer.func; |
|
11 |
+ const observer = new ObserverFunc((mutations) => { |
|
12 |
+ // The observerUpdate event should only be triggered |
|
13 |
+ // once despite the number of mutations. Additional |
|
14 |
+ // triggers are redundant and are very costly |
|
15 |
+ if (mutations.length === 1) { |
|
16 |
+ swiper.emit('observerUpdate', mutations[0]); |
|
17 |
+ return; |
|
18 |
+ } |
|
19 |
+ const observerUpdate = function observerUpdate() { |
|
20 |
+ swiper.emit('observerUpdate', mutations[0]); |
|
21 |
+ }; |
|
22 |
+ |
|
23 |
+ if (window.requestAnimationFrame) { |
|
24 |
+ window.requestAnimationFrame(observerUpdate); |
|
25 |
+ } else { |
|
26 |
+ window.setTimeout(observerUpdate, 0); |
|
27 |
+ } |
|
28 |
+ }); |
|
29 |
+ |
|
30 |
+ observer.observe(target, { |
|
31 |
+ attributes: typeof options.attributes === 'undefined' ? true : options.attributes, |
|
32 |
+ childList: typeof options.childList === 'undefined' ? true : options.childList, |
|
33 |
+ characterData: typeof options.characterData === 'undefined' ? true : options.characterData, |
|
34 |
+ }); |
|
35 |
+ |
|
36 |
+ swiper.observer.observers.push(observer); |
|
37 |
+ }, |
|
38 |
+ init() { |
|
39 |
+ const swiper = this; |
|
40 |
+ if (!Support.observer || !swiper.params.observer) return; |
|
41 |
+ if (swiper.params.observeParents) { |
|
42 |
+ const containerParents = swiper.$el.parents(); |
|
43 |
+ for (let i = 0; i < containerParents.length; i += 1) { |
|
44 |
+ swiper.observer.attach(containerParents[i]); |
|
45 |
+ } |
|
46 |
+ } |
|
47 |
+ // Observe container |
|
48 |
+ swiper.observer.attach(swiper.$el[0], { childList: swiper.params.observeSlideChildren }); |
|
49 |
+ |
|
50 |
+ // Observe wrapper |
|
51 |
+ swiper.observer.attach(swiper.$wrapperEl[0], { attributes: false }); |
|
52 |
+ }, |
|
53 |
+ destroy() { |
|
54 |
+ const swiper = this; |
|
55 |
+ swiper.observer.observers.forEach((observer) => { |
|
56 |
+ observer.disconnect(); |
|
57 |
+ }); |
|
58 |
+ swiper.observer.observers = []; |
|
59 |
+ }, |
|
60 |
+}; |
|
61 |
+ |
|
62 |
+export default { |
|
63 |
+ name: 'observer', |
|
64 |
+ params: { |
|
65 |
+ observer: false, |
|
66 |
+ observeParents: false, |
|
67 |
+ observeSlideChildren: false, |
|
68 |
+ }, |
|
69 |
+ create() { |
|
70 |
+ const swiper = this; |
|
71 |
+ Utils.extend(swiper, { |
|
72 |
+ observer: { |
|
73 |
+ init: Observer.init.bind(swiper), |
|
74 |
+ attach: Observer.attach.bind(swiper), |
|
75 |
+ destroy: Observer.destroy.bind(swiper), |
|
76 |
+ observers: [], |
|
77 |
+ }, |
|
78 |
+ }); |
|
79 |
+ }, |
|
80 |
+ on: { |
|
81 |
+ init() { |
|
82 |
+ const swiper = this; |
|
83 |
+ swiper.observer.init(); |
|
84 |
+ }, |
|
85 |
+ destroy() { |
|
86 |
+ const swiper = this; |
|
87 |
+ swiper.observer.destroy(); |
|
88 |
+ }, |
|
89 |
+ }, |
|
90 |
+}; |