Browse code

Refactor and rewrite as contao bundle

Benjamin Roth authored on04/11/2022 22:32:32
Showing1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,197 +0,0 @@
1
-function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
-/* eslint no-bitwise: ["error", { "allow": [">>"] }] */
4
-import { nextTick, bindModuleMethods } from '../../utils/utils';
5
-var Controller = {
6
-  LinearSpline: function LinearSpline(x, y) {
7
-    var binarySearch = function search() {
8
-      var maxIndex;
9
-      var minIndex;
10
-      var guess;
11
-      return function (array, val) {
12
-        minIndex = -1;
13
-        maxIndex = array.length;
14
-
15
-        while (maxIndex - minIndex > 1) {
16
-          guess = maxIndex + minIndex >> 1;
17
-
18
-          if (array[guess] <= val) {
19
-            minIndex = guess;
20
-          } else {
21
-            maxIndex = guess;
22
-          }
23
-        }
24
-
25
-        return maxIndex;
26
-      };
27
-    }();
28
-
29
-    this.x = x;
30
-    this.y = y;
31
-    this.lastIndex = x.length - 1; // Given an x value (x2), return the expected y2 value:
32
-    // (x1,y1) is the known point before given value,
33
-    // (x3,y3) is the known point after given value.
34
-
35
-    var i1;
36
-    var i3;
37
-
38
-    this.interpolate = function interpolate(x2) {
39
-      if (!x2) return 0; // Get the indexes of x1 and x3 (the array indexes before and after given x2):
40
-
41
-      i3 = binarySearch(this.x, x2);
42
-      i1 = i3 - 1; // We have our indexes i1 & i3, so we can calculate already:
43
-      // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
44
-
45
-      return (x2 - this.x[i1]) * (this.y[i3] - this.y[i1]) / (this.x[i3] - this.x[i1]) + this.y[i1];
46
-    };
47
-
48
-    return this;
49
-  },
50
-  // xxx: for now i will just save one spline function to to
51
-  getInterpolateFunction: function getInterpolateFunction(c) {
52
-    var swiper = this;
53
-
54
-    if (!swiper.controller.spline) {
55
-      swiper.controller.spline = swiper.params.loop ? new Controller.LinearSpline(swiper.slidesGrid, c.slidesGrid) : new Controller.LinearSpline(swiper.snapGrid, c.snapGrid);
56
-    }
57
-  },
58
-  setTranslate: function setTranslate(_setTranslate, byController) {
59
-    var swiper = this;
60
-    var controlled = swiper.controller.control;
61
-    var multiplier;
62
-    var controlledTranslate;
63
-    var Swiper = swiper.constructor;
64
-
65
-    function setControlledTranslate(c) {
66
-      // this will create an Interpolate function based on the snapGrids
67
-      // x is the Grid of the scrolled scroller and y will be the controlled scroller
68
-      // it makes sense to create this only once and recall it for the interpolation
69
-      // the function does a lot of value caching for performance
70
-      var translate = swiper.rtlTranslate ? -swiper.translate : swiper.translate;
71
-
72
-      if (swiper.params.controller.by === 'slide') {
73
-        swiper.controller.getInterpolateFunction(c); // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
74
-        // but it did not work out
75
-
76
-        controlledTranslate = -swiper.controller.spline.interpolate(-translate);
77
-      }
78
-
79
-      if (!controlledTranslate || swiper.params.controller.by === 'container') {
80
-        multiplier = (c.maxTranslate() - c.minTranslate()) / (swiper.maxTranslate() - swiper.minTranslate());
81
-        controlledTranslate = (translate - swiper.minTranslate()) * multiplier + c.minTranslate();
82
-      }
83
-
84
-      if (swiper.params.controller.inverse) {
85
-        controlledTranslate = c.maxTranslate() - controlledTranslate;
86
-      }
87
-
88
-      c.updateProgress(controlledTranslate);
89
-      c.setTranslate(controlledTranslate, swiper);
90
-      c.updateActiveIndex();
91
-      c.updateSlidesClasses();
92
-    }
93
-
94
-    if (Array.isArray(controlled)) {
95
-      for (var i = 0; i < controlled.length; i += 1) {
96
-        if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
97
-          setControlledTranslate(controlled[i]);
98
-        }
99
-      }
100
-    } else if (controlled instanceof Swiper && byController !== controlled) {
101
-      setControlledTranslate(controlled);
102
-    }
103
-  },
104
-  setTransition: function setTransition(duration, byController) {
105
-    var swiper = this;
106
-    var Swiper = swiper.constructor;
107
-    var controlled = swiper.controller.control;
108
-    var i;
109
-
110
-    function setControlledTransition(c) {
111
-      c.setTransition(duration, swiper);
112
-
113
-      if (duration !== 0) {
114
-        c.transitionStart();
115
-
116
-        if (c.params.autoHeight) {
117
-          nextTick(function () {
118
-            c.updateAutoHeight();
119
-          });
120
-        }
121
-
122
-        c.$wrapperEl.transitionEnd(function () {
123
-          if (!controlled) return;
124
-
125
-          if (c.params.loop && swiper.params.controller.by === 'slide') {
126
-            c.loopFix();
127
-          }
128
-
129
-          c.transitionEnd();
130
-        });
131
-      }
132
-    }
133
-
134
-    if (Array.isArray(controlled)) {
135
-      for (i = 0; i < controlled.length; i += 1) {
136
-        if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
137
-          setControlledTransition(controlled[i]);
138
-        }
139
-      }
140
-    } else if (controlled instanceof Swiper && byController !== controlled) {
141
-      setControlledTransition(controlled);
142
-    }
143
-  }
144
-};
145
-export default {
146
-  name: 'controller',
147
-  params: {
148
-    controller: {
149
-      control: undefined,
150
-      inverse: false,
151
-      by: 'slide' // or 'container'
152
-
153
-    }
154
-  },
155
-  create: function create() {
156
-    var swiper = this;
157
-    bindModuleMethods(swiper, {
158
-      controller: _extends({
159
-        control: swiper.params.controller.control
160
-      }, Controller)
161
-    });
162
-  },
163
-  on: {
164
-    update: function update(swiper) {
165
-      if (!swiper.controller.control) return;
166
-
167
-      if (swiper.controller.spline) {
168
-        swiper.controller.spline = undefined;
169
-        delete swiper.controller.spline;
170
-      }
171
-    },
172
-    resize: function resize(swiper) {
173
-      if (!swiper.controller.control) return;
174
-
175
-      if (swiper.controller.spline) {
176
-        swiper.controller.spline = undefined;
177
-        delete swiper.controller.spline;
178
-      }
179
-    },
180
-    observerUpdate: function observerUpdate(swiper) {
181
-      if (!swiper.controller.control) return;
182
-
183
-      if (swiper.controller.spline) {
184
-        swiper.controller.spline = undefined;
185
-        delete swiper.controller.spline;
186
-      }
187
-    },
188
-    setTranslate: function setTranslate(swiper, translate, byController) {
189
-      if (!swiper.controller.control) return;
190
-      swiper.controller.setTranslate(translate, byController);
191
-    },
192
-    setTransition: function setTransition(swiper, duration, byController) {
193
-      if (!swiper.controller.control) return;
194
-      swiper.controller.setTransition(duration, byController);
195
-    }
196
-  }
197
-};
198 0
\ No newline at end of file
Browse code

swiper.js version 6.3.3

Benjamin Roth authored on13/10/2020 19:31:56
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,197 @@
1
+function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+/* eslint no-bitwise: ["error", { "allow": [">>"] }] */
4
+import { nextTick, bindModuleMethods } from '../../utils/utils';
5
+var Controller = {
6
+  LinearSpline: function LinearSpline(x, y) {
7
+    var binarySearch = function search() {
8
+      var maxIndex;
9
+      var minIndex;
10
+      var guess;
11
+      return function (array, val) {
12
+        minIndex = -1;
13
+        maxIndex = array.length;
14
+
15
+        while (maxIndex - minIndex > 1) {
16
+          guess = maxIndex + minIndex >> 1;
17
+
18
+          if (array[guess] <= val) {
19
+            minIndex = guess;
20
+          } else {
21
+            maxIndex = guess;
22
+          }
23
+        }
24
+
25
+        return maxIndex;
26
+      };
27
+    }();
28
+
29
+    this.x = x;
30
+    this.y = y;
31
+    this.lastIndex = x.length - 1; // Given an x value (x2), return the expected y2 value:
32
+    // (x1,y1) is the known point before given value,
33
+    // (x3,y3) is the known point after given value.
34
+
35
+    var i1;
36
+    var i3;
37
+
38
+    this.interpolate = function interpolate(x2) {
39
+      if (!x2) return 0; // Get the indexes of x1 and x3 (the array indexes before and after given x2):
40
+
41
+      i3 = binarySearch(this.x, x2);
42
+      i1 = i3 - 1; // We have our indexes i1 & i3, so we can calculate already:
43
+      // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
44
+
45
+      return (x2 - this.x[i1]) * (this.y[i3] - this.y[i1]) / (this.x[i3] - this.x[i1]) + this.y[i1];
46
+    };
47
+
48
+    return this;
49
+  },
50
+  // xxx: for now i will just save one spline function to to
51
+  getInterpolateFunction: function getInterpolateFunction(c) {
52
+    var swiper = this;
53
+
54
+    if (!swiper.controller.spline) {
55
+      swiper.controller.spline = swiper.params.loop ? new Controller.LinearSpline(swiper.slidesGrid, c.slidesGrid) : new Controller.LinearSpline(swiper.snapGrid, c.snapGrid);
56
+    }
57
+  },
58
+  setTranslate: function setTranslate(_setTranslate, byController) {
59
+    var swiper = this;
60
+    var controlled = swiper.controller.control;
61
+    var multiplier;
62
+    var controlledTranslate;
63
+    var Swiper = swiper.constructor;
64
+
65
+    function setControlledTranslate(c) {
66
+      // this will create an Interpolate function based on the snapGrids
67
+      // x is the Grid of the scrolled scroller and y will be the controlled scroller
68
+      // it makes sense to create this only once and recall it for the interpolation
69
+      // the function does a lot of value caching for performance
70
+      var translate = swiper.rtlTranslate ? -swiper.translate : swiper.translate;
71
+
72
+      if (swiper.params.controller.by === 'slide') {
73
+        swiper.controller.getInterpolateFunction(c); // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
74
+        // but it did not work out
75
+
76
+        controlledTranslate = -swiper.controller.spline.interpolate(-translate);
77
+      }
78
+
79
+      if (!controlledTranslate || swiper.params.controller.by === 'container') {
80
+        multiplier = (c.maxTranslate() - c.minTranslate()) / (swiper.maxTranslate() - swiper.minTranslate());
81
+        controlledTranslate = (translate - swiper.minTranslate()) * multiplier + c.minTranslate();
82
+      }
83
+
84
+      if (swiper.params.controller.inverse) {
85
+        controlledTranslate = c.maxTranslate() - controlledTranslate;
86
+      }
87
+
88
+      c.updateProgress(controlledTranslate);
89
+      c.setTranslate(controlledTranslate, swiper);
90
+      c.updateActiveIndex();
91
+      c.updateSlidesClasses();
92
+    }
93
+
94
+    if (Array.isArray(controlled)) {
95
+      for (var i = 0; i < controlled.length; i += 1) {
96
+        if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
97
+          setControlledTranslate(controlled[i]);
98
+        }
99
+      }
100
+    } else if (controlled instanceof Swiper && byController !== controlled) {
101
+      setControlledTranslate(controlled);
102
+    }
103
+  },
104
+  setTransition: function setTransition(duration, byController) {
105
+    var swiper = this;
106
+    var Swiper = swiper.constructor;
107
+    var controlled = swiper.controller.control;
108
+    var i;
109
+
110
+    function setControlledTransition(c) {
111
+      c.setTransition(duration, swiper);
112
+
113
+      if (duration !== 0) {
114
+        c.transitionStart();
115
+
116
+        if (c.params.autoHeight) {
117
+          nextTick(function () {
118
+            c.updateAutoHeight();
119
+          });
120
+        }
121
+
122
+        c.$wrapperEl.transitionEnd(function () {
123
+          if (!controlled) return;
124
+
125
+          if (c.params.loop && swiper.params.controller.by === 'slide') {
126
+            c.loopFix();
127
+          }
128
+
129
+          c.transitionEnd();
130
+        });
131
+      }
132
+    }
133
+
134
+    if (Array.isArray(controlled)) {
135
+      for (i = 0; i < controlled.length; i += 1) {
136
+        if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
137
+          setControlledTransition(controlled[i]);
138
+        }
139
+      }
140
+    } else if (controlled instanceof Swiper && byController !== controlled) {
141
+      setControlledTransition(controlled);
142
+    }
143
+  }
144
+};
145
+export default {
146
+  name: 'controller',
147
+  params: {
148
+    controller: {
149
+      control: undefined,
150
+      inverse: false,
151
+      by: 'slide' // or 'container'
152
+
153
+    }
154
+  },
155
+  create: function create() {
156
+    var swiper = this;
157
+    bindModuleMethods(swiper, {
158
+      controller: _extends({
159
+        control: swiper.params.controller.control
160
+      }, Controller)
161
+    });
162
+  },
163
+  on: {
164
+    update: function update(swiper) {
165
+      if (!swiper.controller.control) return;
166
+
167
+      if (swiper.controller.spline) {
168
+        swiper.controller.spline = undefined;
169
+        delete swiper.controller.spline;
170
+      }
171
+    },
172
+    resize: function resize(swiper) {
173
+      if (!swiper.controller.control) return;
174
+
175
+      if (swiper.controller.spline) {
176
+        swiper.controller.spline = undefined;
177
+        delete swiper.controller.spline;
178
+      }
179
+    },
180
+    observerUpdate: function observerUpdate(swiper) {
181
+      if (!swiper.controller.control) return;
182
+
183
+      if (swiper.controller.spline) {
184
+        swiper.controller.spline = undefined;
185
+        delete swiper.controller.spline;
186
+      }
187
+    },
188
+    setTranslate: function setTranslate(swiper, translate, byController) {
189
+      if (!swiper.controller.control) return;
190
+      swiper.controller.setTranslate(translate, byController);
191
+    },
192
+    setTransition: function setTransition(swiper, duration, byController) {
193
+      if (!swiper.controller.control) return;
194
+      swiper.controller.setTransition(duration, byController);
195
+    }
196
+  }
197
+};
0 198
\ No newline at end of file