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,212 +0,0 @@
1
-import $ from '../../utils/dom';
2
-import Utils from '../../utils/utils';
3
-
4
-const a11y = {
5
-  makeElFocusable($el) {
6
-    $el.attr('tabIndex', '0');
7
-    return $el;
8
-  },
9
-  makeElNotFocusable($el) {
10
-    $el.attr('tabIndex', '-1');
11
-    return $el;
12
-  },
13
-  addElRole($el, role) {
14
-    $el.attr('role', role);
15
-    return $el;
16
-  },
17
-  addElLabel($el, label) {
18
-    $el.attr('aria-label', label);
19
-    return $el;
20
-  },
21
-  disableEl($el) {
22
-    $el.attr('aria-disabled', true);
23
-    return $el;
24
-  },
25
-  enableEl($el) {
26
-    $el.attr('aria-disabled', false);
27
-    return $el;
28
-  },
29
-  onEnterKey(e) {
30
-    const swiper = this;
31
-    const params = swiper.params.a11y;
32
-    if (e.keyCode !== 13) return;
33
-    const $targetEl = $(e.target);
34
-    if (swiper.navigation && swiper.navigation.$nextEl && $targetEl.is(swiper.navigation.$nextEl)) {
35
-      if (!(swiper.isEnd && !swiper.params.loop)) {
36
-        swiper.slideNext();
37
-      }
38
-      if (swiper.isEnd) {
39
-        swiper.a11y.notify(params.lastSlideMessage);
40
-      } else {
41
-        swiper.a11y.notify(params.nextSlideMessage);
42
-      }
43
-    }
44
-    if (swiper.navigation && swiper.navigation.$prevEl && $targetEl.is(swiper.navigation.$prevEl)) {
45
-      if (!(swiper.isBeginning && !swiper.params.loop)) {
46
-        swiper.slidePrev();
47
-      }
48
-      if (swiper.isBeginning) {
49
-        swiper.a11y.notify(params.firstSlideMessage);
50
-      } else {
51
-        swiper.a11y.notify(params.prevSlideMessage);
52
-      }
53
-    }
54
-    if (swiper.pagination && $targetEl.is(`.${swiper.params.pagination.bulletClass}`)) {
55
-      $targetEl[0].click();
56
-    }
57
-  },
58
-  notify(message) {
59
-    const swiper = this;
60
-    const notification = swiper.a11y.liveRegion;
61
-    if (notification.length === 0) return;
62
-    notification.html('');
63
-    notification.html(message);
64
-  },
65
-  updateNavigation() {
66
-    const swiper = this;
67
-
68
-    if (swiper.params.loop || !swiper.navigation) return;
69
-    const { $nextEl, $prevEl } = swiper.navigation;
70
-
71
-    if ($prevEl && $prevEl.length > 0) {
72
-      if (swiper.isBeginning) {
73
-        swiper.a11y.disableEl($prevEl);
74
-        swiper.a11y.makeElNotFocusable($prevEl);
75
-      } else {
76
-        swiper.a11y.enableEl($prevEl);
77
-        swiper.a11y.makeElFocusable($prevEl);
78
-      }
79
-    }
80
-    if ($nextEl && $nextEl.length > 0) {
81
-      if (swiper.isEnd) {
82
-        swiper.a11y.disableEl($nextEl);
83
-        swiper.a11y.makeElNotFocusable($nextEl);
84
-      } else {
85
-        swiper.a11y.enableEl($nextEl);
86
-        swiper.a11y.makeElFocusable($nextEl);
87
-      }
88
-    }
89
-  },
90
-  updatePagination() {
91
-    const swiper = this;
92
-    const params = swiper.params.a11y;
93
-    if (swiper.pagination && swiper.params.pagination.clickable && swiper.pagination.bullets && swiper.pagination.bullets.length) {
94
-      swiper.pagination.bullets.each((bulletIndex, bulletEl) => {
95
-        const $bulletEl = $(bulletEl);
96
-        swiper.a11y.makeElFocusable($bulletEl);
97
-        swiper.a11y.addElRole($bulletEl, 'button');
98
-        swiper.a11y.addElLabel($bulletEl, params.paginationBulletMessage.replace(/\{\{index\}\}/, $bulletEl.index() + 1));
99
-      });
100
-    }
101
-  },
102
-  init() {
103
-    const swiper = this;
104
-
105
-    swiper.$el.append(swiper.a11y.liveRegion);
106
-
107
-    // Navigation
108
-    const params = swiper.params.a11y;
109
-    let $nextEl;
110
-    let $prevEl;
111
-    if (swiper.navigation && swiper.navigation.$nextEl) {
112
-      $nextEl = swiper.navigation.$nextEl;
113
-    }
114
-    if (swiper.navigation && swiper.navigation.$prevEl) {
115
-      $prevEl = swiper.navigation.$prevEl;
116
-    }
117
-    if ($nextEl) {
118
-      swiper.a11y.makeElFocusable($nextEl);
119
-      swiper.a11y.addElRole($nextEl, 'button');
120
-      swiper.a11y.addElLabel($nextEl, params.nextSlideMessage);
121
-      $nextEl.on('keydown', swiper.a11y.onEnterKey);
122
-    }
123
-    if ($prevEl) {
124
-      swiper.a11y.makeElFocusable($prevEl);
125
-      swiper.a11y.addElRole($prevEl, 'button');
126
-      swiper.a11y.addElLabel($prevEl, params.prevSlideMessage);
127
-      $prevEl.on('keydown', swiper.a11y.onEnterKey);
128
-    }
129
-
130
-    // Pagination
131
-    if (swiper.pagination && swiper.params.pagination.clickable && swiper.pagination.bullets && swiper.pagination.bullets.length) {
132
-      swiper.pagination.$el.on('keydown', `.${swiper.params.pagination.bulletClass}`, swiper.a11y.onEnterKey);
133
-    }
134
-  },
135
-  destroy() {
136
-    const swiper = this;
137
-    if (swiper.a11y.liveRegion && swiper.a11y.liveRegion.length > 0) swiper.a11y.liveRegion.remove();
138
-
139
-    let $nextEl;
140
-    let $prevEl;
141
-    if (swiper.navigation && swiper.navigation.$nextEl) {
142
-      $nextEl = swiper.navigation.$nextEl;
143
-    }
144
-    if (swiper.navigation && swiper.navigation.$prevEl) {
145
-      $prevEl = swiper.navigation.$prevEl;
146
-    }
147
-    if ($nextEl) {
148
-      $nextEl.off('keydown', swiper.a11y.onEnterKey);
149
-    }
150
-    if ($prevEl) {
151
-      $prevEl.off('keydown', swiper.a11y.onEnterKey);
152
-    }
153
-
154
-    // Pagination
155
-    if (swiper.pagination && swiper.params.pagination.clickable && swiper.pagination.bullets && swiper.pagination.bullets.length) {
156
-      swiper.pagination.$el.off('keydown', `.${swiper.params.pagination.bulletClass}`, swiper.a11y.onEnterKey);
157
-    }
158
-  },
159
-};
160
-export default {
161
-  name: 'a11y',
162
-  params: {
163
-    a11y: {
164
-      enabled: true,
165
-      notificationClass: 'swiper-notification',
166
-      prevSlideMessage: 'Previous slide',
167
-      nextSlideMessage: 'Next slide',
168
-      firstSlideMessage: 'This is the first slide',
169
-      lastSlideMessage: 'This is the last slide',
170
-      paginationBulletMessage: 'Go to slide {{index}}',
171
-    },
172
-  },
173
-  create() {
174
-    const swiper = this;
175
-    Utils.extend(swiper, {
176
-      a11y: {
177
-        liveRegion: $(`<span class="${swiper.params.a11y.notificationClass}" aria-live="assertive" aria-atomic="true"></span>`),
178
-      },
179
-    });
180
-    Object.keys(a11y).forEach((methodName) => {
181
-      swiper.a11y[methodName] = a11y[methodName].bind(swiper);
182
-    });
183
-  },
184
-  on: {
185
-    init() {
186
-      const swiper = this;
187
-      if (!swiper.params.a11y.enabled) return;
188
-      swiper.a11y.init();
189
-      swiper.a11y.updateNavigation();
190
-    },
191
-    toEdge() {
192
-      const swiper = this;
193
-      if (!swiper.params.a11y.enabled) return;
194
-      swiper.a11y.updateNavigation();
195
-    },
196
-    fromEdge() {
197
-      const swiper = this;
198
-      if (!swiper.params.a11y.enabled) return;
199
-      swiper.a11y.updateNavigation();
200
-    },
201
-    paginationUpdate() {
202
-      const swiper = this;
203
-      if (!swiper.params.a11y.enabled) return;
204
-      swiper.a11y.updatePagination();
205
-    },
206
-    destroy() {
207
-      const swiper = this;
208
-      if (!swiper.params.a11y.enabled) return;
209
-      swiper.a11y.destroy();
210
-    },
211
-  },
212
-};
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,212 @@
1
+import $ from '../../utils/dom';
2
+import Utils from '../../utils/utils';
3
+
4
+const a11y = {
5
+  makeElFocusable($el) {
6
+    $el.attr('tabIndex', '0');
7
+    return $el;
8
+  },
9
+  makeElNotFocusable($el) {
10
+    $el.attr('tabIndex', '-1');
11
+    return $el;
12
+  },
13
+  addElRole($el, role) {
14
+    $el.attr('role', role);
15
+    return $el;
16
+  },
17
+  addElLabel($el, label) {
18
+    $el.attr('aria-label', label);
19
+    return $el;
20
+  },
21
+  disableEl($el) {
22
+    $el.attr('aria-disabled', true);
23
+    return $el;
24
+  },
25
+  enableEl($el) {
26
+    $el.attr('aria-disabled', false);
27
+    return $el;
28
+  },
29
+  onEnterKey(e) {
30
+    const swiper = this;
31
+    const params = swiper.params.a11y;
32
+    if (e.keyCode !== 13) return;
33
+    const $targetEl = $(e.target);
34
+    if (swiper.navigation && swiper.navigation.$nextEl && $targetEl.is(swiper.navigation.$nextEl)) {
35
+      if (!(swiper.isEnd && !swiper.params.loop)) {
36
+        swiper.slideNext();
37
+      }
38
+      if (swiper.isEnd) {
39
+        swiper.a11y.notify(params.lastSlideMessage);
40
+      } else {
41
+        swiper.a11y.notify(params.nextSlideMessage);
42
+      }
43
+    }
44
+    if (swiper.navigation && swiper.navigation.$prevEl && $targetEl.is(swiper.navigation.$prevEl)) {
45
+      if (!(swiper.isBeginning && !swiper.params.loop)) {
46
+        swiper.slidePrev();
47
+      }
48
+      if (swiper.isBeginning) {
49
+        swiper.a11y.notify(params.firstSlideMessage);
50
+      } else {
51
+        swiper.a11y.notify(params.prevSlideMessage);
52
+      }
53
+    }
54
+    if (swiper.pagination && $targetEl.is(`.${swiper.params.pagination.bulletClass}`)) {
55
+      $targetEl[0].click();
56
+    }
57
+  },
58
+  notify(message) {
59
+    const swiper = this;
60
+    const notification = swiper.a11y.liveRegion;
61
+    if (notification.length === 0) return;
62
+    notification.html('');
63
+    notification.html(message);
64
+  },
65
+  updateNavigation() {
66
+    const swiper = this;
67
+
68
+    if (swiper.params.loop || !swiper.navigation) return;
69
+    const { $nextEl, $prevEl } = swiper.navigation;
70
+
71
+    if ($prevEl && $prevEl.length > 0) {
72
+      if (swiper.isBeginning) {
73
+        swiper.a11y.disableEl($prevEl);
74
+        swiper.a11y.makeElNotFocusable($prevEl);
75
+      } else {
76
+        swiper.a11y.enableEl($prevEl);
77
+        swiper.a11y.makeElFocusable($prevEl);
78
+      }
79
+    }
80
+    if ($nextEl && $nextEl.length > 0) {
81
+      if (swiper.isEnd) {
82
+        swiper.a11y.disableEl($nextEl);
83
+        swiper.a11y.makeElNotFocusable($nextEl);
84
+      } else {
85
+        swiper.a11y.enableEl($nextEl);
86
+        swiper.a11y.makeElFocusable($nextEl);
87
+      }
88
+    }
89
+  },
90
+  updatePagination() {
91
+    const swiper = this;
92
+    const params = swiper.params.a11y;
93
+    if (swiper.pagination && swiper.params.pagination.clickable && swiper.pagination.bullets && swiper.pagination.bullets.length) {
94
+      swiper.pagination.bullets.each((bulletIndex, bulletEl) => {
95
+        const $bulletEl = $(bulletEl);
96
+        swiper.a11y.makeElFocusable($bulletEl);
97
+        swiper.a11y.addElRole($bulletEl, 'button');
98
+        swiper.a11y.addElLabel($bulletEl, params.paginationBulletMessage.replace(/\{\{index\}\}/, $bulletEl.index() + 1));
99
+      });
100
+    }
101
+  },
102
+  init() {
103
+    const swiper = this;
104
+
105
+    swiper.$el.append(swiper.a11y.liveRegion);
106
+
107
+    // Navigation
108
+    const params = swiper.params.a11y;
109
+    let $nextEl;
110
+    let $prevEl;
111
+    if (swiper.navigation && swiper.navigation.$nextEl) {
112
+      $nextEl = swiper.navigation.$nextEl;
113
+    }
114
+    if (swiper.navigation && swiper.navigation.$prevEl) {
115
+      $prevEl = swiper.navigation.$prevEl;
116
+    }
117
+    if ($nextEl) {
118
+      swiper.a11y.makeElFocusable($nextEl);
119
+      swiper.a11y.addElRole($nextEl, 'button');
120
+      swiper.a11y.addElLabel($nextEl, params.nextSlideMessage);
121
+      $nextEl.on('keydown', swiper.a11y.onEnterKey);
122
+    }
123
+    if ($prevEl) {
124
+      swiper.a11y.makeElFocusable($prevEl);
125
+      swiper.a11y.addElRole($prevEl, 'button');
126
+      swiper.a11y.addElLabel($prevEl, params.prevSlideMessage);
127
+      $prevEl.on('keydown', swiper.a11y.onEnterKey);
128
+    }
129
+
130
+    // Pagination
131
+    if (swiper.pagination && swiper.params.pagination.clickable && swiper.pagination.bullets && swiper.pagination.bullets.length) {
132
+      swiper.pagination.$el.on('keydown', `.${swiper.params.pagination.bulletClass}`, swiper.a11y.onEnterKey);
133
+    }
134
+  },
135
+  destroy() {
136
+    const swiper = this;
137
+    if (swiper.a11y.liveRegion && swiper.a11y.liveRegion.length > 0) swiper.a11y.liveRegion.remove();
138
+
139
+    let $nextEl;
140
+    let $prevEl;
141
+    if (swiper.navigation && swiper.navigation.$nextEl) {
142
+      $nextEl = swiper.navigation.$nextEl;
143
+    }
144
+    if (swiper.navigation && swiper.navigation.$prevEl) {
145
+      $prevEl = swiper.navigation.$prevEl;
146
+    }
147
+    if ($nextEl) {
148
+      $nextEl.off('keydown', swiper.a11y.onEnterKey);
149
+    }
150
+    if ($prevEl) {
151
+      $prevEl.off('keydown', swiper.a11y.onEnterKey);
152
+    }
153
+
154
+    // Pagination
155
+    if (swiper.pagination && swiper.params.pagination.clickable && swiper.pagination.bullets && swiper.pagination.bullets.length) {
156
+      swiper.pagination.$el.off('keydown', `.${swiper.params.pagination.bulletClass}`, swiper.a11y.onEnterKey);
157
+    }
158
+  },
159
+};
160
+export default {
161
+  name: 'a11y',
162
+  params: {
163
+    a11y: {
164
+      enabled: true,
165
+      notificationClass: 'swiper-notification',
166
+      prevSlideMessage: 'Previous slide',
167
+      nextSlideMessage: 'Next slide',
168
+      firstSlideMessage: 'This is the first slide',
169
+      lastSlideMessage: 'This is the last slide',
170
+      paginationBulletMessage: 'Go to slide {{index}}',
171
+    },
172
+  },
173
+  create() {
174
+    const swiper = this;
175
+    Utils.extend(swiper, {
176
+      a11y: {
177
+        liveRegion: $(`<span class="${swiper.params.a11y.notificationClass}" aria-live="assertive" aria-atomic="true"></span>`),
178
+      },
179
+    });
180
+    Object.keys(a11y).forEach((methodName) => {
181
+      swiper.a11y[methodName] = a11y[methodName].bind(swiper);
182
+    });
183
+  },
184
+  on: {
185
+    init() {
186
+      const swiper = this;
187
+      if (!swiper.params.a11y.enabled) return;
188
+      swiper.a11y.init();
189
+      swiper.a11y.updateNavigation();
190
+    },
191
+    toEdge() {
192
+      const swiper = this;
193
+      if (!swiper.params.a11y.enabled) return;
194
+      swiper.a11y.updateNavigation();
195
+    },
196
+    fromEdge() {
197
+      const swiper = this;
198
+      if (!swiper.params.a11y.enabled) return;
199
+      swiper.a11y.updateNavigation();
200
+    },
201
+    paginationUpdate() {
202
+      const swiper = this;
203
+      if (!swiper.params.a11y.enabled) return;
204
+      swiper.a11y.updatePagination();
205
+    },
206
+    destroy() {
207
+      const swiper = this;
208
+      if (!swiper.params.a11y.enabled) return;
209
+      swiper.a11y.destroy();
210
+    },
211
+  },
212
+};