Browse code

Remove old version 5

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

Initial commit

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