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,104 +0,0 @@
1
-import { window, document } from 'ssr-window';
2
-import $ from '../../utils/dom';
3
-import Utils from '../../utils/utils';
4
-
5
-const HashNavigation = {
6
-  onHashCange() {
7
-    const swiper = this;
8
-    swiper.emit('hashChange');
9
-    const newHash = document.location.hash.replace('#', '');
10
-    const activeSlideHash = swiper.slides.eq(swiper.activeIndex).attr('data-hash');
11
-    if (newHash !== activeSlideHash) {
12
-      const newIndex = swiper.$wrapperEl.children(`.${swiper.params.slideClass}[data-hash="${newHash}"]`).index();
13
-      if (typeof newIndex === 'undefined') return;
14
-      swiper.slideTo(newIndex);
15
-    }
16
-  },
17
-  setHash() {
18
-    const swiper = this;
19
-    if (!swiper.hashNavigation.initialized || !swiper.params.hashNavigation.enabled) return;
20
-    if (swiper.params.hashNavigation.replaceState && window.history && window.history.replaceState) {
21
-      window.history.replaceState(null, null, (`#${swiper.slides.eq(swiper.activeIndex).attr('data-hash')}` || ''));
22
-      swiper.emit('hashSet');
23
-    } else {
24
-      const slide = swiper.slides.eq(swiper.activeIndex);
25
-      const hash = slide.attr('data-hash') || slide.attr('data-history');
26
-      document.location.hash = hash || '';
27
-      swiper.emit('hashSet');
28
-    }
29
-  },
30
-  init() {
31
-    const swiper = this;
32
-    if (!swiper.params.hashNavigation.enabled || (swiper.params.history && swiper.params.history.enabled)) return;
33
-    swiper.hashNavigation.initialized = true;
34
-    const hash = document.location.hash.replace('#', '');
35
-    if (hash) {
36
-      const speed = 0;
37
-      for (let i = 0, length = swiper.slides.length; i < length; i += 1) {
38
-        const slide = swiper.slides.eq(i);
39
-        const slideHash = slide.attr('data-hash') || slide.attr('data-history');
40
-        if (slideHash === hash && !slide.hasClass(swiper.params.slideDuplicateClass)) {
41
-          const index = slide.index();
42
-          swiper.slideTo(index, speed, swiper.params.runCallbacksOnInit, true);
43
-        }
44
-      }
45
-    }
46
-    if (swiper.params.hashNavigation.watchState) {
47
-      $(window).on('hashchange', swiper.hashNavigation.onHashCange);
48
-    }
49
-  },
50
-  destroy() {
51
-    const swiper = this;
52
-    if (swiper.params.hashNavigation.watchState) {
53
-      $(window).off('hashchange', swiper.hashNavigation.onHashCange);
54
-    }
55
-  },
56
-};
57
-export default {
58
-  name: 'hash-navigation',
59
-  params: {
60
-    hashNavigation: {
61
-      enabled: false,
62
-      replaceState: false,
63
-      watchState: false,
64
-    },
65
-  },
66
-  create() {
67
-    const swiper = this;
68
-    Utils.extend(swiper, {
69
-      hashNavigation: {
70
-        initialized: false,
71
-        init: HashNavigation.init.bind(swiper),
72
-        destroy: HashNavigation.destroy.bind(swiper),
73
-        setHash: HashNavigation.setHash.bind(swiper),
74
-        onHashCange: HashNavigation.onHashCange.bind(swiper),
75
-      },
76
-    });
77
-  },
78
-  on: {
79
-    init() {
80
-      const swiper = this;
81
-      if (swiper.params.hashNavigation.enabled) {
82
-        swiper.hashNavigation.init();
83
-      }
84
-    },
85
-    destroy() {
86
-      const swiper = this;
87
-      if (swiper.params.hashNavigation.enabled) {
88
-        swiper.hashNavigation.destroy();
89
-      }
90
-    },
91
-    transitionEnd() {
92
-      const swiper = this;
93
-      if (swiper.hashNavigation.initialized) {
94
-        swiper.hashNavigation.setHash();
95
-      }
96
-    },
97
-    slideChange() {
98
-      const swiper = this;
99
-      if (swiper.hashNavigation.initialized && swiper.params.cssMode) {
100
-        swiper.hashNavigation.setHash();
101
-      }
102
-    },
103
-  },
104
-};
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,104 @@
1
+import { window, document } from 'ssr-window';
2
+import $ from '../../utils/dom';
3
+import Utils from '../../utils/utils';
4
+
5
+const HashNavigation = {
6
+  onHashCange() {
7
+    const swiper = this;
8
+    swiper.emit('hashChange');
9
+    const newHash = document.location.hash.replace('#', '');
10
+    const activeSlideHash = swiper.slides.eq(swiper.activeIndex).attr('data-hash');
11
+    if (newHash !== activeSlideHash) {
12
+      const newIndex = swiper.$wrapperEl.children(`.${swiper.params.slideClass}[data-hash="${newHash}"]`).index();
13
+      if (typeof newIndex === 'undefined') return;
14
+      swiper.slideTo(newIndex);
15
+    }
16
+  },
17
+  setHash() {
18
+    const swiper = this;
19
+    if (!swiper.hashNavigation.initialized || !swiper.params.hashNavigation.enabled) return;
20
+    if (swiper.params.hashNavigation.replaceState && window.history && window.history.replaceState) {
21
+      window.history.replaceState(null, null, (`#${swiper.slides.eq(swiper.activeIndex).attr('data-hash')}` || ''));
22
+      swiper.emit('hashSet');
23
+    } else {
24
+      const slide = swiper.slides.eq(swiper.activeIndex);
25
+      const hash = slide.attr('data-hash') || slide.attr('data-history');
26
+      document.location.hash = hash || '';
27
+      swiper.emit('hashSet');
28
+    }
29
+  },
30
+  init() {
31
+    const swiper = this;
32
+    if (!swiper.params.hashNavigation.enabled || (swiper.params.history && swiper.params.history.enabled)) return;
33
+    swiper.hashNavigation.initialized = true;
34
+    const hash = document.location.hash.replace('#', '');
35
+    if (hash) {
36
+      const speed = 0;
37
+      for (let i = 0, length = swiper.slides.length; i < length; i += 1) {
38
+        const slide = swiper.slides.eq(i);
39
+        const slideHash = slide.attr('data-hash') || slide.attr('data-history');
40
+        if (slideHash === hash && !slide.hasClass(swiper.params.slideDuplicateClass)) {
41
+          const index = slide.index();
42
+          swiper.slideTo(index, speed, swiper.params.runCallbacksOnInit, true);
43
+        }
44
+      }
45
+    }
46
+    if (swiper.params.hashNavigation.watchState) {
47
+      $(window).on('hashchange', swiper.hashNavigation.onHashCange);
48
+    }
49
+  },
50
+  destroy() {
51
+    const swiper = this;
52
+    if (swiper.params.hashNavigation.watchState) {
53
+      $(window).off('hashchange', swiper.hashNavigation.onHashCange);
54
+    }
55
+  },
56
+};
57
+export default {
58
+  name: 'hash-navigation',
59
+  params: {
60
+    hashNavigation: {
61
+      enabled: false,
62
+      replaceState: false,
63
+      watchState: false,
64
+    },
65
+  },
66
+  create() {
67
+    const swiper = this;
68
+    Utils.extend(swiper, {
69
+      hashNavigation: {
70
+        initialized: false,
71
+        init: HashNavigation.init.bind(swiper),
72
+        destroy: HashNavigation.destroy.bind(swiper),
73
+        setHash: HashNavigation.setHash.bind(swiper),
74
+        onHashCange: HashNavigation.onHashCange.bind(swiper),
75
+      },
76
+    });
77
+  },
78
+  on: {
79
+    init() {
80
+      const swiper = this;
81
+      if (swiper.params.hashNavigation.enabled) {
82
+        swiper.hashNavigation.init();
83
+      }
84
+    },
85
+    destroy() {
86
+      const swiper = this;
87
+      if (swiper.params.hashNavigation.enabled) {
88
+        swiper.hashNavigation.destroy();
89
+      }
90
+    },
91
+    transitionEnd() {
92
+      const swiper = this;
93
+      if (swiper.hashNavigation.initialized) {
94
+        swiper.hashNavigation.setHash();
95
+      }
96
+    },
97
+    slideChange() {
98
+      const swiper = this;
99
+      if (swiper.hashNavigation.initialized && swiper.params.cssMode) {
100
+        swiper.hashNavigation.setHash();
101
+      }
102
+    },
103
+  },
104
+};