Browse Source

Increment day only when selection not focused

Manual increment will be done only if the selection element is not
focused, otherwise it would be incremented by two days.
master
Schneider 7 years ago
parent
commit
32e40891f4
  1. 60
      src/App.vue

60
src/App.vue

@ -6,7 +6,7 @@
<option v-for="mensa in mensen" :value="mensa.url">{{mensa.name}}</option> <option v-for="mensa in mensen" :value="mensa.url">{{mensa.name}}</option>
</select> </select>
Wann? <select v-model="when">
Wann? <select v-model="when" id="selWhen">
<option v-for="day in days" :value="day" :key="day">{{dayOfWeek[day]}}</option> <option v-for="day in days" :value="day" :key="day">{{dayOfWeek[day]}}</option>
</select> </select>
<router-view></router-view> <router-view></router-view>
@ -28,9 +28,9 @@
import Mensen from '@/lib/Mensen.js' import Mensen from '@/lib/Mensen.js'
export default { export default {
name: 'app', name: 'app',
data () {
data() {
return { return {
menu: {},
selWhen: {},
mensen: Mensen, mensen: Mensen,
days: [1, 2, 3, 4, 5, 6], days: [1, 2, 3, 4, 5, 6],
dayOfWeek: { dayOfWeek: {
@ -44,24 +44,24 @@ export default {
} }
}, },
methods: { methods: {
previousDay () {
this.when === 1 ? this.when = 6 : this.when--
previousDay() {
this.when === 1 ? (this.when = 6) : this.when--
}, },
nextDay () {
this.when === 6 ? this.when = 1 : this.when++
nextDay() {
this.when === 6 ? (this.when = 1) : this.when++
} }
}, },
filters: { filters: {
noBreak (value) {
noBreak(value) {
return value.replace(/\s/g, '\u00a0') return value.replace(/\s/g, '\u00a0')
} }
}, },
computed: { computed: {
where: { where: {
get () {
get() {
return this.$store.state.where return this.$store.state.where
}, },
set (value) {
set(value) {
this.$store.dispatch('loadMeals', { this.$store.dispatch('loadMeals', {
when: this.when, when: this.when,
where: value where: value
@ -69,10 +69,10 @@ export default {
} }
}, },
when: { when: {
get () {
get() {
return this.$store.state.when return this.$store.state.when
}, },
set (value) {
set(value) {
this.$store.dispatch('loadMeals', { this.$store.dispatch('loadMeals', {
when: value, when: value,
where: this.where where: this.where
@ -80,32 +80,44 @@ export default {
} }
} }
}, },
created () {
created() {
this.$store.dispatch('loadMeals', { this.$store.dispatch('loadMeals', {
when: this.when, when: this.when,
where: this.where where: this.where
}) })
let vm = this let vm = this
document.onkeydown = (evt) => {
document.onkeydown = evt => {
evt = evt || window.event evt = evt || window.event
switch (evt.keyCode) { switch (evt.keyCode) {
case 37: case 37:
vm.previousDay()
if (vm.selWhen !== document.activeElement) {
// increment only if selection is not focused, avoid double execution
vm.previousDay()
}
break break
case 39: case 39:
vm.nextDay()
break
if (vm.selWhen !== document.activeElement) {
// increment only if selection is not focused, avoid double execution
vm.nextDay()
break
}
} }
} }
},
mounted() {
this.selWhen = document.getElementById('selWhen')
} }
} }
</script> </script>
<style src="./assets/base.css"></style>
<style src="./assets/links.css"></style>
<style src="./assets/base.css">
</style>
<style src="./assets/links.css">
</style>
<style> <style>
#app { #app {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
text-align: center; text-align: center;
@ -114,21 +126,21 @@ export default {
max-width: 30em; max-width: 30em;
margin: 0 auto; margin: 0 auto;
} }
footer{
footer {
margin: 1em 0; margin: 1em 0;
} }
footer > div { footer > div {
margin: 0.5em; margin: 0.5em;
} }
nav>a{
nav > a {
margin: 0.3em; margin: 0.3em;
wrap: no-wrap; wrap: no-wrap;
} }
.router-link-active:before{
.router-link-active:before {
content: '>'; content: '>';
} }
.router-link-active:after{
.router-link-active:after {
content: '<'; content: '<';
} }
</style> </style>
Loading…
Cancel
Save