|
8 | 8 | <div class="lightbox__element" @click.stop="">
|
9 | 9 | <div
|
10 | 10 | class="lightbox__arrow lightbox__arrow--left"
|
11 |
| - @click.stop.prevent="prev" |
12 |
| - :class="{'lightbox__arrow--invisible': ! has_prev()}" |
| 11 | + @click.stop.prevent="previous" |
| 12 | + :class="{ 'lightbox__arrow--invisible': !hasPrevious }" |
13 | 13 | >
|
14 | 14 | <svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
15 | 15 | <path d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"/>
|
|
23 | 23 | <div
|
24 | 24 | class="lightbox__arrow lightbox__arrow--right"
|
25 | 25 | @click.stop.prevent="next"
|
26 |
| - :class="{'lightbox__arrow--invisible': ! has_next()}" |
| 26 | + :class="{ 'lightbox__arrow--invisible': !hasNext }" |
27 | 27 | >
|
28 | 28 | <svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
29 | 29 | <path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"/>
|
|
51 | 51 | displayImage: true,
|
52 | 52 | }
|
53 | 53 | },
|
54 |
| - mounted() { |
55 |
| - window.addEventListener('keydown', this.eventListener) |
56 |
| - }, |
57 |
| - destroyed() { |
58 |
| - window.removeEventListener('keydown', this.eventListener) |
| 54 | + computed: { |
| 55 | + hasNext() { |
| 56 | + return (this.index + 1 < this.images.length) |
| 57 | + }, |
| 58 | + hasPrevious() { |
| 59 | + return (this.index - 1 >= 0) |
| 60 | + }, |
59 | 61 | },
|
60 | 62 | methods: {
|
61 | 63 | show() {
|
|
66 | 68 | this.visible = false
|
67 | 69 | this.index = 0
|
68 | 70 | },
|
69 |
| - has_next() { |
70 |
| - return (this.index + 1 < this.images.length) |
71 |
| - }, |
72 |
| - has_prev() { |
73 |
| - return (this.index - 1 >= 0) |
74 |
| - }, |
75 |
| - prev() { |
76 |
| - if (this.has_prev()) { |
| 71 | + previous() { |
| 72 | + if (this.hasPrevious) { |
77 | 73 | this.index -= 1
|
78 | 74 | this.tick()
|
79 | 75 | }
|
80 | 76 | },
|
81 | 77 | next() {
|
82 |
| - if (this.has_next()) { |
| 78 | + if (this.hasNext) { |
83 | 79 | this.index += 1
|
84 | 80 | this.tick()
|
85 | 81 | }
|
|
99 | 95 | if (this.visible) {
|
100 | 96 | switch (e.key) {
|
101 | 97 | case 'ArrowRight':
|
102 |
| - this.next() |
103 |
| - break |
| 98 | + return this.next() |
104 | 99 | case 'ArrowLeft':
|
105 |
| - this.prev() |
106 |
| - break |
| 100 | + return this.previous() |
107 | 101 | case 'ArrowDown':
|
108 | 102 | case 'ArrowUp':
|
109 | 103 | case ' ':
|
110 |
| - e.preventDefault() |
111 |
| - break |
| 104 | + return e.preventDefault() |
112 | 105 | case 'Escape':
|
113 |
| - this.hide() |
114 |
| - break |
| 106 | + return this.hide() |
115 | 107 | }
|
116 | 108 | }
|
117 | 109 | },
|
118 | 110 | },
|
| 111 | + mounted() { |
| 112 | + window.addEventListener('keydown', this.eventListener) |
| 113 | + }, |
| 114 | + destroyed() { |
| 115 | + window.removeEventListener('keydown', this.eventListener) |
| 116 | + }, |
119 | 117 | }
|
120 | 118 | </script>
|
121 | 119 |
|
|
0 commit comments