debian-mirror-gitlab/app/assets/javascripts/behaviors/shortcuts/shortcuts_toggle.vue

41 lines
1,015 B
Vue
Raw Normal View History

2020-03-13 15:44:24 +05:30
<script>
2020-07-28 23:09:34 +05:30
import { GlToggle } from '@gitlab/ui';
2020-03-13 15:44:24 +05:30
import AccessorUtilities from '~/lib/utils/accessor';
import { disableShortcuts, enableShortcuts, shouldDisableShortcuts } from './shortcuts_toggle';
export default {
components: {
GlToggle,
},
data() {
return {
localStorageUsable: AccessorUtilities.isLocalStorageAccessSafe(),
shortcutsEnabled: !shouldDisableShortcuts(),
};
},
methods: {
onChange(value) {
this.shortcutsEnabled = value;
if (value) {
enableShortcuts();
} else {
disableShortcuts();
}
},
},
};
</script>
<template>
<div v-if="localStorageUsable" class="d-inline-flex align-items-center js-toggle-shortcuts">
<gl-toggle
v-model="shortcutsEnabled"
aria-describedby="shortcutsToggle"
2020-07-28 23:09:34 +05:30
label="Keyboard shortcuts"
label-position="left"
2020-03-13 15:44:24 +05:30
@change="onChange"
2020-07-28 23:09:34 +05:30
/>
2020-03-13 15:44:24 +05:30
<div id="shortcutsToggle" class="sr-only">{{ __('Enable or disable keyboard shortcuts') }}</div>
</div>
</template>