2018-02-12 14:10:16 +02:00
|
|
|
<template>
|
2018-12-16 01:45:10 +02:00
|
|
|
<form class="wlvfdpkp" @submit.prevent="onSubmit">
|
2018-11-05 18:40:11 +02:00
|
|
|
<i><fa icon="search"/></i>
|
2018-12-16 01:45:10 +02:00
|
|
|
<input v-model="q" type="search" :placeholder="$t('placeholder')" v-autocomplete="{ model: 'q' }"/>
|
2018-02-12 14:10:16 +02:00
|
|
|
<div class="result"></div>
|
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-08 20:44:35 +02:00
|
|
|
import i18n from '../../../i18n';
|
2018-02-12 14:10:16 +02:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-11-08 20:44:35 +02:00
|
|
|
i18n: i18n('desktop/views/components/ui.header.search.vue'),
|
2018-02-12 14:10:16 +02:00
|
|
|
data() {
|
|
|
|
return {
|
2018-12-19 18:09:35 +02:00
|
|
|
q: '',
|
|
|
|
wait: false
|
2018-02-12 14:10:16 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
2018-12-19 18:09:35 +02:00
|
|
|
async onSubmit() {
|
|
|
|
if (this.wait) return;
|
|
|
|
|
2018-12-16 01:45:10 +02:00
|
|
|
const q = this.q.trim();
|
|
|
|
if (q.startsWith('@')) {
|
|
|
|
this.$router.push(`/${q}`);
|
|
|
|
} else if (q.startsWith('#')) {
|
|
|
|
this.$router.push(`/tags/${encodeURIComponent(q.substr(1))}`);
|
2018-12-19 18:09:35 +02:00
|
|
|
} else if (q.startsWith('https://')) {
|
|
|
|
this.wait = true;
|
|
|
|
try {
|
|
|
|
const res = await this.$root.api('ap/show', {
|
|
|
|
uri: q
|
|
|
|
});
|
|
|
|
if (res.type == 'User') {
|
|
|
|
this.$router.push(`/@${res.object.username}@${res.object.host}`);
|
|
|
|
} else if (res.type == 'Note') {
|
|
|
|
this.$router.push(`/notes/${res.object.id}`);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
this.wait = false;
|
2018-06-10 06:21:44 +03:00
|
|
|
} else {
|
2018-12-16 01:45:10 +02:00
|
|
|
this.$router.push(`/search?q=${encodeURIComponent(q)}`);
|
2018-06-10 06:21:44 +03:00
|
|
|
}
|
2018-02-12 14:10:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-12-16 01:45:10 +02:00
|
|
|
.wlvfdpkp
|
2018-10-15 11:43:25 +03:00
|
|
|
@media (max-width 800px)
|
|
|
|
display none !important
|
|
|
|
|
2018-11-05 18:40:11 +02:00
|
|
|
> i
|
2018-02-12 14:10:16 +02:00
|
|
|
display block
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
left 0
|
|
|
|
width 48px
|
|
|
|
text-align center
|
|
|
|
line-height 48px
|
2018-09-27 09:19:11 +03:00
|
|
|
color var(--desktopHeaderFg)
|
2018-02-12 14:10:16 +02:00
|
|
|
pointer-events none
|
|
|
|
|
|
|
|
> *
|
|
|
|
vertical-align middle
|
|
|
|
|
|
|
|
> input
|
|
|
|
user-select text
|
|
|
|
cursor auto
|
|
|
|
margin 8px 0 0 0
|
|
|
|
padding 6px 18px 6px 36px
|
|
|
|
width 14em
|
|
|
|
height 32px
|
|
|
|
font-size 1em
|
2018-09-27 09:19:11 +03:00
|
|
|
background var(--desktopHeaderSearchBg)
|
2018-02-12 14:10:16 +02:00
|
|
|
outline none
|
|
|
|
border none
|
|
|
|
border-radius 16px
|
|
|
|
transition color 0.5s ease, border 0.5s ease
|
2018-09-27 09:19:11 +03:00
|
|
|
color var(--desktopHeaderSearchFg)
|
2018-02-12 14:10:16 +02:00
|
|
|
|
2018-10-15 11:43:25 +03:00
|
|
|
@media (max-width 1000px)
|
|
|
|
width 10em
|
|
|
|
|
2018-02-12 14:10:16 +02:00
|
|
|
&::placeholder
|
2018-09-27 09:19:11 +03:00
|
|
|
color var(--desktopHeaderFg)
|
2018-02-12 14:10:16 +02:00
|
|
|
|
|
|
|
&:hover
|
2018-09-27 09:19:11 +03:00
|
|
|
background var(--desktopHeaderSearchHoverBg)
|
2018-02-12 14:10:16 +02:00
|
|
|
|
|
|
|
&:focus
|
2018-09-26 14:19:35 +03:00
|
|
|
box-shadow 0 0 0 2px var(--primaryAlpha05) !important
|
2018-02-12 14:10:16 +02:00
|
|
|
|
|
|
|
</style>
|