UNPKG

6.49 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5const animation = require('./animation-13cbbb20.js');
6const ios_transition = require('./ios.transition-ce21ff9f.js');
7const md_transition = require('./md.transition-59017746.js');
8const cubicBezier = require('./cubic-bezier-0b2ccc35.js');
9const index = require('./index-a1dd5c93.js');
10const ionicGlobal = require('./ionic-global-06f21c1a.js');
11const helpers = require('./helpers-d381ec4d.js');
12const index$1 = require('./index-e1bb33c3.js');
13const index$2 = require('./index-222357e4.js');
14const index$3 = require('./index-ea5f8e16.js');
15const overlays = require('./overlays-59863ad4.js');
16require('./gesture-controller-29adda71.js');
17require('./index-a0a08b2a.js');
18require('./hardware-back-button-148ce546.js');
19
20const setupConfig = (config) => {
21 const win = window;
22 const Ionic = win.Ionic;
23 if (Ionic && Ionic.config && Ionic.config.constructor.name !== 'Object') {
24 return;
25 }
26 win.Ionic = win.Ionic || {};
27 win.Ionic.config = Object.assign(Object.assign({}, win.Ionic.config), config);
28 return win.Ionic.config;
29};
30const getMode = () => {
31 const win = window;
32 const config = win && win.Ionic && win.Ionic.config;
33 if (config) {
34 if (config.mode) {
35 return config.mode;
36 }
37 else {
38 return config.get('mode');
39 }
40 }
41 return 'md';
42};
43
44/**
45 * This is a plugin for Swiper that allows it to work
46 * with Ionic Framework and the routing integrations.
47 * Without this plugin, Swiper would be incapable of correctly
48 * determining the dimensions of the slides component as
49 * each view is initially hidden before transitioning in.
50 */
51const setupSwiperInIonic = (swiper, watchForIonPageChanges = true) => {
52 if (typeof window === 'undefined') {
53 return;
54 }
55 const swiperEl = swiper.el;
56 const ionPage = swiperEl.closest('.ion-page');
57 if (!ionPage) {
58 if (watchForIonPageChanges) {
59 /**
60 * If no ion page found, it is possible
61 * that we are in the overlay setup step
62 * where the inner component has been
63 * created but not attached to the DOM yet.
64 * If so, wait for the .ion-page class to
65 * appear on the root div and re-run setup.
66 */
67 const rootNode = swiperEl.getRootNode();
68 if (rootNode.tagName === 'DIV') {
69 const mo = new MutationObserver((m) => {
70 const mutation = m[0];
71 const wasEmpty = mutation.oldValue === null;
72 const hasIonPage = rootNode.classList.contains('ion-page');
73 /**
74 * Now that we have an .ion-page class
75 * we can safely attempt setup again.
76 */
77 if (wasEmpty && hasIonPage) {
78 mo.disconnect();
79 /**
80 * Set false here so we do not
81 * get infinite loops
82 */
83 setupSwiperInIonic(swiper, false);
84 }
85 });
86 mo.observe(rootNode, {
87 attributeFilter: ['class'],
88 attributeOldValue: true
89 });
90 }
91 }
92 return;
93 }
94 /**
95 * If using slides in a modal or
96 * popover we need to wait for the
97 * overlay to be shown as these components
98 * are hidden when they are initially created.
99 */
100 const modalOrPopover = swiperEl.closest('ion-modal, ion-popover');
101 if (modalOrPopover) {
102 const eventName = modalOrPopover.tagName === 'ION-MODAL' ? 'ionModalWillPresent' : 'ionPopoverWillPresent';
103 const overlayCallback = () => {
104 /**
105 * We need an raf here so the update
106 * is fired one tick after the overlay is shown.
107 */
108 helpers.raf(() => {
109 swiperEl.swiper.update();
110 helpers.removeEventListener(modalOrPopover, eventName, overlayCallback);
111 });
112 };
113 helpers.addEventListener(modalOrPopover, eventName, overlayCallback);
114 }
115 else {
116 /**
117 * If using slides in a page
118 * we need to wait for the ion-page-invisible
119 * class to be removed so Swiper can correctly
120 * compute the dimensions of the slides.
121 */
122 const mo = new MutationObserver((m) => {
123 var _a;
124 const mutation = m[0];
125 const wasPageHidden = (_a = mutation.oldValue) === null || _a === void 0 ? void 0 : _a.includes('ion-page-invisible');
126 const isPageHidden = ionPage.classList.contains('ion-page-invisible');
127 /**
128 * Only update Swiper if the page was
129 * hidden but is no longer hidden.
130 */
131 if (!isPageHidden && isPageHidden !== wasPageHidden) {
132 swiperEl.swiper.update();
133 }
134 });
135 mo.observe(ionPage, {
136 attributeFilter: ['class'],
137 attributeOldValue: true
138 });
139 }
140 /**
141 * We also need to listen for the appload event
142 * which is emitted by Stencil in the
143 * event that Swiper is being used on the
144 * view that is rendered initially.
145 */
146 const onAppLoad = () => {
147 swiperEl.swiper.update();
148 helpers.removeEventListener(window, 'appload', onAppLoad);
149 };
150 helpers.addEventListener(window, 'appload', onAppLoad);
151};
152const IonicSwiper = {
153 name: 'ionic',
154 on: {
155 afterInit(swiper) {
156 setupSwiperInIonic(swiper);
157 }
158 }
159};
160
161exports.createAnimation = animation.createAnimation;
162exports.iosTransitionAnimation = ios_transition.iosTransitionAnimation;
163exports.mdTransitionAnimation = md_transition.mdTransitionAnimation;
164exports.getTimeGivenProgression = cubicBezier.getTimeGivenProgression;
165exports.createGesture = index.createGesture;
166exports.getPlatforms = ionicGlobal.getPlatforms;
167exports.initialize = ionicGlobal.initialize;
168exports.isPlatform = ionicGlobal.isPlatform;
169exports.componentOnReady = helpers.componentOnReady;
170exports.IonicSafeString = index$1.IonicSafeString;
171exports.LIFECYCLE_DID_ENTER = index$2.LIFECYCLE_DID_ENTER;
172exports.LIFECYCLE_DID_LEAVE = index$2.LIFECYCLE_DID_LEAVE;
173exports.LIFECYCLE_WILL_ENTER = index$2.LIFECYCLE_WILL_ENTER;
174exports.LIFECYCLE_WILL_LEAVE = index$2.LIFECYCLE_WILL_LEAVE;
175exports.LIFECYCLE_WILL_UNLOAD = index$2.LIFECYCLE_WILL_UNLOAD;
176exports.menuController = index$3.menuController;
177exports.actionSheetController = overlays.actionSheetController;
178exports.alertController = overlays.alertController;
179exports.loadingController = overlays.loadingController;
180exports.modalController = overlays.modalController;
181exports.pickerController = overlays.pickerController;
182exports.popoverController = overlays.popoverController;
183exports.toastController = overlays.toastController;
184exports.IonicSwiper = IonicSwiper;
185exports.getMode = getMode;
186exports.setupConfig = setupConfig;