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,154 +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 { getWindow } from 'ssr-window';
4
-import { bindModuleMethods } from '../../utils/utils';
5
-var History = {
6
-  init: function init() {
7
-    var swiper = this;
8
-    var window = getWindow();
9
-    if (!swiper.params.history) return;
10
-
11
-    if (!window.history || !window.history.pushState) {
12
-      swiper.params.history.enabled = false;
13
-      swiper.params.hashNavigation.enabled = true;
14
-      return;
15
-    }
16
-
17
-    var history = swiper.history;
18
-    history.initialized = true;
19
-    history.paths = History.getPathValues(swiper.params.url);
20
-    if (!history.paths.key && !history.paths.value) return;
21
-    history.scrollToSlide(0, history.paths.value, swiper.params.runCallbacksOnInit);
22
-
23
-    if (!swiper.params.history.replaceState) {
24
-      window.addEventListener('popstate', swiper.history.setHistoryPopState);
25
-    }
26
-  },
27
-  destroy: function destroy() {
28
-    var swiper = this;
29
-    var window = getWindow();
30
-
31
-    if (!swiper.params.history.replaceState) {
32
-      window.removeEventListener('popstate', swiper.history.setHistoryPopState);
33
-    }
34
-  },
35
-  setHistoryPopState: function setHistoryPopState() {
36
-    var swiper = this;
37
-    swiper.history.paths = History.getPathValues(swiper.params.url);
38
-    swiper.history.scrollToSlide(swiper.params.speed, swiper.history.paths.value, false);
39
-  },
40
-  getPathValues: function getPathValues(urlOverride) {
41
-    var window = getWindow();
42
-    var location;
43
-
44
-    if (urlOverride) {
45
-      location = new URL(urlOverride);
46
-    } else {
47
-      location = window.location;
48
-    }
49
-
50
-    var pathArray = location.pathname.slice(1).split('/').filter(function (part) {
51
-      return part !== '';
52
-    });
53
-    var total = pathArray.length;
54
-    var key = pathArray[total - 2];
55
-    var value = pathArray[total - 1];
56
-    return {
57
-      key: key,
58
-      value: value
59
-    };
60
-  },
61
-  setHistory: function setHistory(key, index) {
62
-    var swiper = this;
63
-    var window = getWindow();
64
-    if (!swiper.history.initialized || !swiper.params.history.enabled) return;
65
-    var location;
66
-
67
-    if (swiper.params.url) {
68
-      location = new URL(swiper.params.url);
69
-    } else {
70
-      location = window.location;
71
-    }
72
-
73
-    var slide = swiper.slides.eq(index);
74
-    var value = History.slugify(slide.attr('data-history'));
75
-
76
-    if (!location.pathname.includes(key)) {
77
-      value = key + "/" + value;
78
-    }
79
-
80
-    var currentState = window.history.state;
81
-
82
-    if (currentState && currentState.value === value) {
83
-      return;
84
-    }
85
-
86
-    if (swiper.params.history.replaceState) {
87
-      window.history.replaceState({
88
-        value: value
89
-      }, null, value);
90
-    } else {
91
-      window.history.pushState({
92
-        value: value
93
-      }, null, value);
94
-    }
95
-  },
96
-  slugify: function slugify(text) {
97
-    return text.toString().replace(/\s+/g, '-').replace(/[^\w-]+/g, '').replace(/--+/g, '-').replace(/^-+/, '').replace(/-+$/, '');
98
-  },
99
-  scrollToSlide: function scrollToSlide(speed, value, runCallbacks) {
100
-    var swiper = this;
101
-
102
-    if (value) {
103
-      for (var i = 0, length = swiper.slides.length; i < length; i += 1) {
104
-        var slide = swiper.slides.eq(i);
105
-        var slideHistory = History.slugify(slide.attr('data-history'));
106
-
107
-        if (slideHistory === value && !slide.hasClass(swiper.params.slideDuplicateClass)) {
108
-          var index = slide.index();
109
-          swiper.slideTo(index, speed, runCallbacks);
110
-        }
111
-      }
112
-    } else {
113
-      swiper.slideTo(0, speed, runCallbacks);
114
-    }
115
-  }
116
-};
117
-export default {
118
-  name: 'history',
119
-  params: {
120
-    history: {
121
-      enabled: false,
122
-      replaceState: false,
123
-      key: 'slides'
124
-    }
125
-  },
126
-  create: function create() {
127
-    var swiper = this;
128
-    bindModuleMethods(swiper, {
129
-      history: _extends({}, History)
130
-    });
131
-  },
132
-  on: {
133
-    init: function init(swiper) {
134
-      if (swiper.params.history.enabled) {
135
-        swiper.history.init();
136
-      }
137
-    },
138
-    destroy: function destroy(swiper) {
139
-      if (swiper.params.history.enabled) {
140
-        swiper.history.destroy();
141
-      }
142
-    },
143
-    transitionEnd: function transitionEnd(swiper) {
144
-      if (swiper.history.initialized) {
145
-        swiper.history.setHistory(swiper.params.history.key, swiper.activeIndex);
146
-      }
147
-    },
148
-    slideChange: function slideChange(swiper) {
149
-      if (swiper.history.initialized && swiper.params.cssMode) {
150
-        swiper.history.setHistory(swiper.params.history.key, swiper.activeIndex);
151
-      }
152
-    }
153
-  }
154
-};
155 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,154 @@
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 { getWindow } from 'ssr-window';
4
+import { bindModuleMethods } from '../../utils/utils';
5
+var History = {
6
+  init: function init() {
7
+    var swiper = this;
8
+    var window = getWindow();
9
+    if (!swiper.params.history) return;
10
+
11
+    if (!window.history || !window.history.pushState) {
12
+      swiper.params.history.enabled = false;
13
+      swiper.params.hashNavigation.enabled = true;
14
+      return;
15
+    }
16
+
17
+    var history = swiper.history;
18
+    history.initialized = true;
19
+    history.paths = History.getPathValues(swiper.params.url);
20
+    if (!history.paths.key && !history.paths.value) return;
21
+    history.scrollToSlide(0, history.paths.value, swiper.params.runCallbacksOnInit);
22
+
23
+    if (!swiper.params.history.replaceState) {
24
+      window.addEventListener('popstate', swiper.history.setHistoryPopState);
25
+    }
26
+  },
27
+  destroy: function destroy() {
28
+    var swiper = this;
29
+    var window = getWindow();
30
+
31
+    if (!swiper.params.history.replaceState) {
32
+      window.removeEventListener('popstate', swiper.history.setHistoryPopState);
33
+    }
34
+  },
35
+  setHistoryPopState: function setHistoryPopState() {
36
+    var swiper = this;
37
+    swiper.history.paths = History.getPathValues(swiper.params.url);
38
+    swiper.history.scrollToSlide(swiper.params.speed, swiper.history.paths.value, false);
39
+  },
40
+  getPathValues: function getPathValues(urlOverride) {
41
+    var window = getWindow();
42
+    var location;
43
+
44
+    if (urlOverride) {
45
+      location = new URL(urlOverride);
46
+    } else {
47
+      location = window.location;
48
+    }
49
+
50
+    var pathArray = location.pathname.slice(1).split('/').filter(function (part) {
51
+      return part !== '';
52
+    });
53
+    var total = pathArray.length;
54
+    var key = pathArray[total - 2];
55
+    var value = pathArray[total - 1];
56
+    return {
57
+      key: key,
58
+      value: value
59
+    };
60
+  },
61
+  setHistory: function setHistory(key, index) {
62
+    var swiper = this;
63
+    var window = getWindow();
64
+    if (!swiper.history.initialized || !swiper.params.history.enabled) return;
65
+    var location;
66
+
67
+    if (swiper.params.url) {
68
+      location = new URL(swiper.params.url);
69
+    } else {
70
+      location = window.location;
71
+    }
72
+
73
+    var slide = swiper.slides.eq(index);
74
+    var value = History.slugify(slide.attr('data-history'));
75
+
76
+    if (!location.pathname.includes(key)) {
77
+      value = key + "/" + value;
78
+    }
79
+
80
+    var currentState = window.history.state;
81
+
82
+    if (currentState && currentState.value === value) {
83
+      return;
84
+    }
85
+
86
+    if (swiper.params.history.replaceState) {
87
+      window.history.replaceState({
88
+        value: value
89
+      }, null, value);
90
+    } else {
91
+      window.history.pushState({
92
+        value: value
93
+      }, null, value);
94
+    }
95
+  },
96
+  slugify: function slugify(text) {
97
+    return text.toString().replace(/\s+/g, '-').replace(/[^\w-]+/g, '').replace(/--+/g, '-').replace(/^-+/, '').replace(/-+$/, '');
98
+  },
99
+  scrollToSlide: function scrollToSlide(speed, value, runCallbacks) {
100
+    var swiper = this;
101
+
102
+    if (value) {
103
+      for (var i = 0, length = swiper.slides.length; i < length; i += 1) {
104
+        var slide = swiper.slides.eq(i);
105
+        var slideHistory = History.slugify(slide.attr('data-history'));
106
+
107
+        if (slideHistory === value && !slide.hasClass(swiper.params.slideDuplicateClass)) {
108
+          var index = slide.index();
109
+          swiper.slideTo(index, speed, runCallbacks);
110
+        }
111
+      }
112
+    } else {
113
+      swiper.slideTo(0, speed, runCallbacks);
114
+    }
115
+  }
116
+};
117
+export default {
118
+  name: 'history',
119
+  params: {
120
+    history: {
121
+      enabled: false,
122
+      replaceState: false,
123
+      key: 'slides'
124
+    }
125
+  },
126
+  create: function create() {
127
+    var swiper = this;
128
+    bindModuleMethods(swiper, {
129
+      history: _extends({}, History)
130
+    });
131
+  },
132
+  on: {
133
+    init: function init(swiper) {
134
+      if (swiper.params.history.enabled) {
135
+        swiper.history.init();
136
+      }
137
+    },
138
+    destroy: function destroy(swiper) {
139
+      if (swiper.params.history.enabled) {
140
+        swiper.history.destroy();
141
+      }
142
+    },
143
+    transitionEnd: function transitionEnd(swiper) {
144
+      if (swiper.history.initialized) {
145
+        swiper.history.setHistory(swiper.params.history.key, swiper.activeIndex);
146
+      }
147
+    },
148
+    slideChange: function slideChange(swiper) {
149
+      if (swiper.history.initialized && swiper.params.cssMode) {
150
+        swiper.history.setHistory(swiper.params.history.key, swiper.activeIndex);
151
+      }
152
+    }
153
+  }
154
+};
0 155
\ No newline at end of file