koel/resources/assets/js/components/site-header/search-form.vue

81 lines
1.4 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
2016-06-25 16:05:24 +00:00
<div class="side search" id="searchForm" :class="{ showing: showing }">
<input type="search"
:class="{ dirty: q }"
@input="filter"
placeholder="Search"
v-model="q"
2016-12-11 13:08:30 +00:00
v-koel-focus
>
2016-06-25 16:05:24 +00:00
</div>
2015-12-13 04:42:28 +00:00
</template>
<script>
2016-11-26 03:25:35 +00:00
import isMobile from 'ismobilejs'
import { debounce } from 'lodash'
2015-12-13 04:42:28 +00:00
2016-11-26 03:25:35 +00:00
import { event } from '../../utils'
2016-06-25 05:24:55 +00:00
2016-06-25 16:05:24 +00:00
export default {
name: 'site-header--search-form',
2016-06-25 10:15:57 +00:00
2016-11-26 03:25:35 +00:00
data () {
2016-06-25 16:05:24 +00:00
return {
q: '',
2016-11-26 03:25:35 +00:00
showing: !isMobile.phone
}
2016-06-25 16:05:24 +00:00
},
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
methods: {
/**
* Limit the filter's execution rate using lodash's debounce.
*/
filter: debounce(function () {
2016-11-26 03:25:35 +00:00
event.emit('filter:changed', this.q)
}, 200)
2016-06-25 16:05:24 +00:00
},
2015-12-13 04:42:28 +00:00
2016-11-26 03:25:35 +00:00
created () {
2016-06-25 16:05:24 +00:00
event.on('search:toggle', () => {
2016-11-26 03:25:35 +00:00
this.showing = !this.showing
})
}
}
2015-12-13 04:42:28 +00:00
</script>
2017-02-14 06:53:02 +00:00
<style lang="scss">
2016-06-25 16:05:24 +00:00
@import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss";
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
#searchForm {
@include vertical-center();
flex: 0 0 256px;
order: -1;
background: $colorSearchFormBgr;
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
input[type="search"] {
width: 218px;
margin-top: 0;
}
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
@media only screen and (max-width : 667px) {
z-index: -1;
position: absolute;
left: 0;
background: rgba(0, 0, 0, .8);
width: 100%;
padding: 12px;
top: 0;
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
&.showing {
top: $headerHeight;
z-index: 100;
}
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
input[type="search"] {
width: 100%;
2015-12-13 04:42:28 +00:00
}
2016-06-25 16:05:24 +00:00
}
}
2015-12-13 04:42:28 +00:00
</style>