Skip to content

Commit c4ff827

Browse files
committed
Improved code style
1 parent 086f6a3 commit c4ff827

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

src/Components/Lightbox.vue

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<div class="lightbox__element" @click.stop="">
99
<div
1010
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 }"
1313
>
1414
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
1515
<path d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"/>
@@ -23,7 +23,7 @@
2323
<div
2424
class="lightbox__arrow lightbox__arrow--right"
2525
@click.stop.prevent="next"
26-
:class="{'lightbox__arrow--invisible': ! has_next()}"
26+
:class="{ 'lightbox__arrow--invisible': !hasNext }"
2727
>
2828
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
2929
<path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"/>
@@ -51,11 +51,13 @@
5151
displayImage: true,
5252
}
5353
},
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+
},
5961
},
6062
methods: {
6163
show() {
@@ -66,20 +68,14 @@
6668
this.visible = false
6769
this.index = 0
6870
},
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) {
7773
this.index -= 1
7874
this.tick()
7975
}
8076
},
8177
next() {
82-
if (this.has_next()) {
78+
if (this.hasNext) {
8379
this.index += 1
8480
this.tick()
8581
}
@@ -99,23 +95,25 @@
9995
if (this.visible) {
10096
switch (e.key) {
10197
case 'ArrowRight':
102-
this.next()
103-
break
98+
return this.next()
10499
case 'ArrowLeft':
105-
this.prev()
106-
break
100+
return this.previous()
107101
case 'ArrowDown':
108102
case 'ArrowUp':
109103
case ' ':
110-
e.preventDefault()
111-
break
104+
return e.preventDefault()
112105
case 'Escape':
113-
this.hide()
114-
break
106+
return this.hide()
115107
}
116108
}
117109
},
118110
},
111+
mounted() {
112+
window.addEventListener('keydown', this.eventListener)
113+
},
114+
destroyed() {
115+
window.removeEventListener('keydown', this.eventListener)
116+
},
119117
}
120118
</script>
121119

0 commit comments

Comments
 (0)