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,164 +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
-import $ from '../../utils/dom';
4
-import { extend, bindModuleMethods } from '../../utils/utils';
5
-var Navigation = {
6
-  update: function update() {
7
-    // Update Navigation Buttons
8
-    var swiper = this;
9
-    var params = swiper.params.navigation;
10
-    if (swiper.params.loop) return;
11
-    var _swiper$navigation = swiper.navigation,
12
-        $nextEl = _swiper$navigation.$nextEl,
13
-        $prevEl = _swiper$navigation.$prevEl;
14
-
15
-    if ($prevEl && $prevEl.length > 0) {
16
-      if (swiper.isBeginning) {
17
-        $prevEl.addClass(params.disabledClass);
18
-      } else {
19
-        $prevEl.removeClass(params.disabledClass);
20
-      }
21
-
22
-      $prevEl[swiper.params.watchOverflow && swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
23
-    }
24
-
25
-    if ($nextEl && $nextEl.length > 0) {
26
-      if (swiper.isEnd) {
27
-        $nextEl.addClass(params.disabledClass);
28
-      } else {
29
-        $nextEl.removeClass(params.disabledClass);
30
-      }
31
-
32
-      $nextEl[swiper.params.watchOverflow && swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
33
-    }
34
-  },
35
-  onPrevClick: function onPrevClick(e) {
36
-    var swiper = this;
37
-    e.preventDefault();
38
-    if (swiper.isBeginning && !swiper.params.loop) return;
39
-    swiper.slidePrev();
40
-  },
41
-  onNextClick: function onNextClick(e) {
42
-    var swiper = this;
43
-    e.preventDefault();
44
-    if (swiper.isEnd && !swiper.params.loop) return;
45
-    swiper.slideNext();
46
-  },
47
-  init: function init() {
48
-    var swiper = this;
49
-    var params = swiper.params.navigation;
50
-    if (!(params.nextEl || params.prevEl)) return;
51
-    var $nextEl;
52
-    var $prevEl;
53
-
54
-    if (params.nextEl) {
55
-      $nextEl = $(params.nextEl);
56
-
57
-      if (swiper.params.uniqueNavElements && typeof params.nextEl === 'string' && $nextEl.length > 1 && swiper.$el.find(params.nextEl).length === 1) {
58
-        $nextEl = swiper.$el.find(params.nextEl);
59
-      }
60
-    }
61
-
62
-    if (params.prevEl) {
63
-      $prevEl = $(params.prevEl);
64
-
65
-      if (swiper.params.uniqueNavElements && typeof params.prevEl === 'string' && $prevEl.length > 1 && swiper.$el.find(params.prevEl).length === 1) {
66
-        $prevEl = swiper.$el.find(params.prevEl);
67
-      }
68
-    }
69
-
70
-    if ($nextEl && $nextEl.length > 0) {
71
-      $nextEl.on('click', swiper.navigation.onNextClick);
72
-    }
73
-
74
-    if ($prevEl && $prevEl.length > 0) {
75
-      $prevEl.on('click', swiper.navigation.onPrevClick);
76
-    }
77
-
78
-    extend(swiper.navigation, {
79
-      $nextEl: $nextEl,
80
-      nextEl: $nextEl && $nextEl[0],
81
-      $prevEl: $prevEl,
82
-      prevEl: $prevEl && $prevEl[0]
83
-    });
84
-  },
85
-  destroy: function destroy() {
86
-    var swiper = this;
87
-    var _swiper$navigation2 = swiper.navigation,
88
-        $nextEl = _swiper$navigation2.$nextEl,
89
-        $prevEl = _swiper$navigation2.$prevEl;
90
-
91
-    if ($nextEl && $nextEl.length) {
92
-      $nextEl.off('click', swiper.navigation.onNextClick);
93
-      $nextEl.removeClass(swiper.params.navigation.disabledClass);
94
-    }
95
-
96
-    if ($prevEl && $prevEl.length) {
97
-      $prevEl.off('click', swiper.navigation.onPrevClick);
98
-      $prevEl.removeClass(swiper.params.navigation.disabledClass);
99
-    }
100
-  }
101
-};
102
-export default {
103
-  name: 'navigation',
104
-  params: {
105
-    navigation: {
106
-      nextEl: null,
107
-      prevEl: null,
108
-      hideOnClick: false,
109
-      disabledClass: 'swiper-button-disabled',
110
-      hiddenClass: 'swiper-button-hidden',
111
-      lockClass: 'swiper-button-lock'
112
-    }
113
-  },
114
-  create: function create() {
115
-    var swiper = this;
116
-    bindModuleMethods(swiper, {
117
-      navigation: _extends({}, Navigation)
118
-    });
119
-  },
120
-  on: {
121
-    init: function init(swiper) {
122
-      swiper.navigation.init();
123
-      swiper.navigation.update();
124
-    },
125
-    toEdge: function toEdge(swiper) {
126
-      swiper.navigation.update();
127
-    },
128
-    fromEdge: function fromEdge(swiper) {
129
-      swiper.navigation.update();
130
-    },
131
-    destroy: function destroy(swiper) {
132
-      swiper.navigation.destroy();
133
-    },
134
-    click: function click(swiper, e) {
135
-      var _swiper$navigation3 = swiper.navigation,
136
-          $nextEl = _swiper$navigation3.$nextEl,
137
-          $prevEl = _swiper$navigation3.$prevEl;
138
-
139
-      if (swiper.params.navigation.hideOnClick && !$(e.target).is($prevEl) && !$(e.target).is($nextEl)) {
140
-        var isHidden;
141
-
142
-        if ($nextEl) {
143
-          isHidden = $nextEl.hasClass(swiper.params.navigation.hiddenClass);
144
-        } else if ($prevEl) {
145
-          isHidden = $prevEl.hasClass(swiper.params.navigation.hiddenClass);
146
-        }
147
-
148
-        if (isHidden === true) {
149
-          swiper.emit('navigationShow');
150
-        } else {
151
-          swiper.emit('navigationHide');
152
-        }
153
-
154
-        if ($nextEl) {
155
-          $nextEl.toggleClass(swiper.params.navigation.hiddenClass);
156
-        }
157
-
158
-        if ($prevEl) {
159
-          $prevEl.toggleClass(swiper.params.navigation.hiddenClass);
160
-        }
161
-      }
162
-    }
163
-  }
164
-};
165 0
\ No newline at end of file
Browse code

swiper.js version 6.4.5

Benjamin Roth authored on17/01/2021 16:24:34
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,164 @@
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
+import $ from '../../utils/dom';
4
+import { extend, bindModuleMethods } from '../../utils/utils';
5
+var Navigation = {
6
+  update: function update() {
7
+    // Update Navigation Buttons
8
+    var swiper = this;
9
+    var params = swiper.params.navigation;
10
+    if (swiper.params.loop) return;
11
+    var _swiper$navigation = swiper.navigation,
12
+        $nextEl = _swiper$navigation.$nextEl,
13
+        $prevEl = _swiper$navigation.$prevEl;
14
+
15
+    if ($prevEl && $prevEl.length > 0) {
16
+      if (swiper.isBeginning) {
17
+        $prevEl.addClass(params.disabledClass);
18
+      } else {
19
+        $prevEl.removeClass(params.disabledClass);
20
+      }
21
+
22
+      $prevEl[swiper.params.watchOverflow && swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
23
+    }
24
+
25
+    if ($nextEl && $nextEl.length > 0) {
26
+      if (swiper.isEnd) {
27
+        $nextEl.addClass(params.disabledClass);
28
+      } else {
29
+        $nextEl.removeClass(params.disabledClass);
30
+      }
31
+
32
+      $nextEl[swiper.params.watchOverflow && swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
33
+    }
34
+  },
35
+  onPrevClick: function onPrevClick(e) {
36
+    var swiper = this;
37
+    e.preventDefault();
38
+    if (swiper.isBeginning && !swiper.params.loop) return;
39
+    swiper.slidePrev();
40
+  },
41
+  onNextClick: function onNextClick(e) {
42
+    var swiper = this;
43
+    e.preventDefault();
44
+    if (swiper.isEnd && !swiper.params.loop) return;
45
+    swiper.slideNext();
46
+  },
47
+  init: function init() {
48
+    var swiper = this;
49
+    var params = swiper.params.navigation;
50
+    if (!(params.nextEl || params.prevEl)) return;
51
+    var $nextEl;
52
+    var $prevEl;
53
+
54
+    if (params.nextEl) {
55
+      $nextEl = $(params.nextEl);
56
+
57
+      if (swiper.params.uniqueNavElements && typeof params.nextEl === 'string' && $nextEl.length > 1 && swiper.$el.find(params.nextEl).length === 1) {
58
+        $nextEl = swiper.$el.find(params.nextEl);
59
+      }
60
+    }
61
+
62
+    if (params.prevEl) {
63
+      $prevEl = $(params.prevEl);
64
+
65
+      if (swiper.params.uniqueNavElements && typeof params.prevEl === 'string' && $prevEl.length > 1 && swiper.$el.find(params.prevEl).length === 1) {
66
+        $prevEl = swiper.$el.find(params.prevEl);
67
+      }
68
+    }
69
+
70
+    if ($nextEl && $nextEl.length > 0) {
71
+      $nextEl.on('click', swiper.navigation.onNextClick);
72
+    }
73
+
74
+    if ($prevEl && $prevEl.length > 0) {
75
+      $prevEl.on('click', swiper.navigation.onPrevClick);
76
+    }
77
+
78
+    extend(swiper.navigation, {
79
+      $nextEl: $nextEl,
80
+      nextEl: $nextEl && $nextEl[0],
81
+      $prevEl: $prevEl,
82
+      prevEl: $prevEl && $prevEl[0]
83
+    });
84
+  },
85
+  destroy: function destroy() {
86
+    var swiper = this;
87
+    var _swiper$navigation2 = swiper.navigation,
88
+        $nextEl = _swiper$navigation2.$nextEl,
89
+        $prevEl = _swiper$navigation2.$prevEl;
90
+
91
+    if ($nextEl && $nextEl.length) {
92
+      $nextEl.off('click', swiper.navigation.onNextClick);
93
+      $nextEl.removeClass(swiper.params.navigation.disabledClass);
94
+    }
95
+
96
+    if ($prevEl && $prevEl.length) {
97
+      $prevEl.off('click', swiper.navigation.onPrevClick);
98
+      $prevEl.removeClass(swiper.params.navigation.disabledClass);
99
+    }
100
+  }
101
+};
102
+export default {
103
+  name: 'navigation',
104
+  params: {
105
+    navigation: {
106
+      nextEl: null,
107
+      prevEl: null,
108
+      hideOnClick: false,
109
+      disabledClass: 'swiper-button-disabled',
110
+      hiddenClass: 'swiper-button-hidden',
111
+      lockClass: 'swiper-button-lock'
112
+    }
113
+  },
114
+  create: function create() {
115
+    var swiper = this;
116
+    bindModuleMethods(swiper, {
117
+      navigation: _extends({}, Navigation)
118
+    });
119
+  },
120
+  on: {
121
+    init: function init(swiper) {
122
+      swiper.navigation.init();
123
+      swiper.navigation.update();
124
+    },
125
+    toEdge: function toEdge(swiper) {
126
+      swiper.navigation.update();
127
+    },
128
+    fromEdge: function fromEdge(swiper) {
129
+      swiper.navigation.update();
130
+    },
131
+    destroy: function destroy(swiper) {
132
+      swiper.navigation.destroy();
133
+    },
134
+    click: function click(swiper, e) {
135
+      var _swiper$navigation3 = swiper.navigation,
136
+          $nextEl = _swiper$navigation3.$nextEl,
137
+          $prevEl = _swiper$navigation3.$prevEl;
138
+
139
+      if (swiper.params.navigation.hideOnClick && !$(e.target).is($prevEl) && !$(e.target).is($nextEl)) {
140
+        var isHidden;
141
+
142
+        if ($nextEl) {
143
+          isHidden = $nextEl.hasClass(swiper.params.navigation.hiddenClass);
144
+        } else if ($prevEl) {
145
+          isHidden = $prevEl.hasClass(swiper.params.navigation.hiddenClass);
146
+        }
147
+
148
+        if (isHidden === true) {
149
+          swiper.emit('navigationShow');
150
+        } else {
151
+          swiper.emit('navigationHide');
152
+        }
153
+
154
+        if ($nextEl) {
155
+          $nextEl.toggleClass(swiper.params.navigation.hiddenClass);
156
+        }
157
+
158
+        if ($prevEl) {
159
+          $prevEl.toggleClass(swiper.params.navigation.hiddenClass);
160
+        }
161
+      }
162
+    }
163
+  }
164
+};
0 165
\ No newline at end of file