2019-04-08 20:06:22 +00:00
|
|
|
<template>
|
2020-08-23 21:43:42 +00:00
|
|
|
<form
|
|
|
|
|
@submit.prevent="formSubmit"
|
|
|
|
|
:class="{'max-w-lg': !homepage}"
|
|
|
|
|
class="flex self-start w-full h-full text-lg text-teal-100"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
v-if="open"
|
|
|
|
|
@click="open = false"
|
|
|
|
|
:style="{opacity: homepage ? 0 : 0.9}"
|
|
|
|
|
class="fixed inset-0 z-20 w-screen h-screen bg-gray-900"
|
|
|
|
|
></div>
|
2019-04-10 20:05:52 +00:00
|
|
|
<div class="relative w-full">
|
2020-04-01 10:55:55 +00:00
|
|
|
<button
|
2020-08-23 21:43:42 +00:00
|
|
|
v-if="homepage"
|
2020-04-01 10:55:55 +00:00
|
|
|
ref="submit"
|
2020-08-23 21:43:42 +00:00
|
|
|
class="absolute right-0 z-40 w-12 h-full hover:text-teal-200"
|
2020-04-01 10:55:55 +00:00
|
|
|
type="submit"
|
|
|
|
|
>
|
2020-06-11 18:55:39 +00:00
|
|
|
<svg class="absolute w-4 h-4 vertical-center horizontal-center">
|
2020-04-01 10:55:55 +00:00
|
|
|
<use xlink:href="#search" />
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
2019-04-16 13:34:38 +00:00
|
|
|
<input
|
2020-08-23 21:43:42 +00:00
|
|
|
v-if="homepage"
|
2020-02-10 19:53:32 +00:00
|
|
|
ref="input"
|
2019-08-23 14:48:16 +00:00
|
|
|
v-model="summoner"
|
2020-08-23 21:43:42 +00:00
|
|
|
@focus="open = true"
|
|
|
|
|
:class="dropdown ? 'bg-blue-1000' : 'input-color'"
|
|
|
|
|
class="relative z-30 w-full py-4 pl-6 pr-32 font-bold placeholder-teal-100 placeholder-opacity-75 rounded-lg outline-none focus:bg-blue-1000 summoner-input bypass-click"
|
2020-06-11 18:55:39 +00:00
|
|
|
spellcheck="false"
|
|
|
|
|
type="text"
|
2020-06-20 18:14:13 +00:00
|
|
|
placeholder="Search summoner"
|
2019-09-03 17:56:41 +00:00
|
|
|
/>
|
2020-08-23 21:43:42 +00:00
|
|
|
<button
|
|
|
|
|
v-if="!homepage"
|
|
|
|
|
@click="open = true"
|
|
|
|
|
class="w-full h-10 px-4 -mt-px text-base font-light text-left text-blue-200 rounded-md bg-blue-1000"
|
|
|
|
|
type="button"
|
|
|
|
|
>
|
|
|
|
|
<div class="flex items-center space-x-3">
|
|
|
|
|
<svg class="w-4 h-4">
|
|
|
|
|
<use xlink:href="#search" />
|
|
|
|
|
</svg>
|
|
|
|
|
<span>Search summoner (Press "/" to focus)</span>
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
2020-02-13 18:49:38 +00:00
|
|
|
<transition name="scale-fade">
|
2020-08-23 21:43:42 +00:00
|
|
|
<SearchFormDropdown
|
|
|
|
|
v-if="open"
|
|
|
|
|
v-model="summoner"
|
|
|
|
|
@close="open = false"
|
|
|
|
|
@toggle="dropdown = !dropdown"
|
|
|
|
|
:dropdown="dropdown"
|
|
|
|
|
:homepage="homepage"
|
|
|
|
|
/>
|
2020-02-10 19:53:32 +00:00
|
|
|
</transition>
|
|
|
|
|
|
2020-04-08 12:02:21 +00:00
|
|
|
<div ref="region-dropdown">
|
2020-08-23 21:43:42 +00:00
|
|
|
<SearchFormRegion
|
|
|
|
|
v-if="homepage"
|
|
|
|
|
@toggle="dropdown = !dropdown"
|
|
|
|
|
:dropdown="dropdown"
|
|
|
|
|
:homepage="homepage"
|
|
|
|
|
/>
|
2020-04-08 12:02:21 +00:00
|
|
|
</div>
|
2019-11-16 16:50:14 +00:00
|
|
|
</div>
|
2019-04-08 20:06:22 +00:00
|
|
|
</form>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2020-08-23 21:43:42 +00:00
|
|
|
import { mapState } from 'vuex'
|
2020-02-13 19:16:13 +00:00
|
|
|
import SearchFormDropdown from '@/components/Form/SearchFormDropdown.vue'
|
2020-08-23 21:43:42 +00:00
|
|
|
import SearchFormRegion from '@/components/Form/SearchFormRegion.vue'
|
2020-02-06 18:45:22 +00:00
|
|
|
|
2019-04-08 20:06:22 +00:00
|
|
|
export default {
|
2020-02-10 19:53:32 +00:00
|
|
|
components: {
|
|
|
|
|
SearchFormDropdown,
|
2020-08-23 21:43:42 +00:00
|
|
|
SearchFormRegion
|
2020-02-10 19:53:32 +00:00
|
|
|
},
|
|
|
|
|
|
2019-09-14 21:19:10 +00:00
|
|
|
props: {
|
2020-08-23 21:43:42 +00:00
|
|
|
homepage: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2019-09-14 21:19:10 +00:00
|
|
|
}
|
|
|
|
|
},
|
2020-02-10 19:53:32 +00:00
|
|
|
|
2019-04-08 20:06:22 +00:00
|
|
|
data() {
|
|
|
|
|
return {
|
2019-04-18 12:33:49 +00:00
|
|
|
summoner: '',
|
2019-04-08 20:06:22 +00:00
|
|
|
dropdown: false,
|
2020-08-23 21:43:42 +00:00
|
|
|
open: false,
|
2019-08-23 14:48:16 +00:00
|
|
|
}
|
2019-04-08 20:06:22 +00:00
|
|
|
},
|
2020-02-10 19:53:32 +00:00
|
|
|
|
2019-09-14 21:19:10 +00:00
|
|
|
computed: {
|
2020-02-06 18:45:22 +00:00
|
|
|
...mapState({
|
|
|
|
|
selectedRegion: state => state.settings.region
|
|
|
|
|
}),
|
2019-09-14 21:19:10 +00:00
|
|
|
},
|
2020-02-10 19:53:32 +00:00
|
|
|
|
2020-08-23 21:43:42 +00:00
|
|
|
watch: {
|
|
|
|
|
open(newVal) {
|
2020-08-24 12:24:09 +00:00
|
|
|
const header = document.querySelector('.header div')
|
2020-08-23 21:43:42 +00:00
|
|
|
// Search Dropdown open
|
|
|
|
|
if (newVal) {
|
2020-08-24 12:24:09 +00:00
|
|
|
console.log(this.getScrollbarWidth())
|
2020-08-23 21:43:42 +00:00
|
|
|
if (!this.homepage) {
|
2020-08-24 12:24:09 +00:00
|
|
|
document.body.style.marginLeft = `-${this.getScrollbarWidth()}px`
|
|
|
|
|
header.style.paddingRight = `${this.getScrollbarWidth()}px`
|
2020-08-23 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
document.body.style.overflow = 'hidden'
|
|
|
|
|
} else {
|
|
|
|
|
document.body.style.marginLeft = 0
|
2020-08-24 12:24:09 +00:00
|
|
|
header.style.paddingRight = 0
|
2020-08-23 21:43:42 +00:00
|
|
|
document.body.style.overflow = 'auto'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
$route() {
|
|
|
|
|
this.dropdown = false
|
|
|
|
|
this.open = false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2020-04-01 10:55:55 +00:00
|
|
|
created() {
|
2020-08-23 21:43:42 +00:00
|
|
|
if (!this.summoner.length && !this.homepage) {
|
2020-04-01 10:55:55 +00:00
|
|
|
this.summoner = this.$route.params.name
|
|
|
|
|
}
|
2020-02-10 19:53:32 +00:00
|
|
|
window.addEventListener('blur', this.windowBlur)
|
2020-04-08 12:02:21 +00:00
|
|
|
document.addEventListener('keydown', this.handleEscape)
|
2020-02-10 19:53:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
beforeDestroy() {
|
|
|
|
|
window.removeEventListener('blur', this.windowBlur)
|
2020-04-08 12:02:21 +00:00
|
|
|
document.removeEventListener('keydown', this.handleEscape)
|
2020-02-10 19:53:32 +00:00
|
|
|
},
|
|
|
|
|
|
2019-04-08 20:06:22 +00:00
|
|
|
methods: {
|
|
|
|
|
formSubmit() {
|
2019-09-03 17:56:41 +00:00
|
|
|
const search = this.summoner.split(' ').join('')
|
|
|
|
|
if (search.length) {
|
2020-02-06 18:45:22 +00:00
|
|
|
this.$emit('formSubmit', search, this.selectedRegion)
|
2019-08-22 22:50:00 +00:00
|
|
|
}
|
2020-02-06 18:45:22 +00:00
|
|
|
},
|
2020-08-24 12:24:09 +00:00
|
|
|
getScrollbarWidth() {
|
|
|
|
|
const outer = document.createElement('div')
|
|
|
|
|
outer.style.visibility = 'hidden'
|
|
|
|
|
outer.style.overflow = 'scroll' // forcing scrollbar to appear
|
|
|
|
|
outer.style.msOverflowStyle = 'scrollbar' // needed for WinJS apps
|
|
|
|
|
document.body.appendChild(outer)
|
|
|
|
|
|
|
|
|
|
const inner = document.createElement('div')
|
|
|
|
|
outer.appendChild(inner)
|
|
|
|
|
const scrollbarWidth = (outer.offsetWidth - inner.offsetWidth)
|
|
|
|
|
|
|
|
|
|
outer.parentNode.removeChild(outer)
|
|
|
|
|
|
|
|
|
|
return scrollbarWidth
|
|
|
|
|
},
|
2020-04-08 12:02:21 +00:00
|
|
|
handleEscape(e) {
|
|
|
|
|
if (e.key === 'Esc' || e.key === 'Escape') {
|
|
|
|
|
this.dropdown = false
|
2020-08-23 21:43:42 +00:00
|
|
|
this.open = false
|
|
|
|
|
} else if ((e.key === 'k' && (e.ctrlKey || e.metaKey)) || e.key === '/') {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
this.dropdown = false
|
|
|
|
|
this.open = !this.open
|
2020-04-08 12:02:21 +00:00
|
|
|
}
|
|
|
|
|
},
|
2020-02-10 19:53:32 +00:00
|
|
|
windowBlur() {
|
2020-08-23 21:43:42 +00:00
|
|
|
this.open = false
|
2020-02-10 19:53:32 +00:00
|
|
|
},
|
2019-04-08 20:06:22 +00:00
|
|
|
}
|
2019-08-23 14:48:16 +00:00
|
|
|
}
|
2019-04-08 20:06:22 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2020-06-20 18:14:13 +00:00
|
|
|
.summoner-input::placeholder {
|
|
|
|
|
@apply font-normal;
|
|
|
|
|
}
|
2019-04-08 20:06:22 +00:00
|
|
|
</style>
|