/
util.js
48 lines (47 loc) · 1.46 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { ADVANCED } from '../constants'
export default {
methods: {
inputFocus () {
if (!this.query) return
this.$nextTick(() => {
// fix open drop down list and set input focus, the page will scroll to top
// that.$refs.search.focus({preventScroll:true}); only work on Chrome and EDGE
if (this.isChrome() || this.isEdge()) this.$refs.search.focus({ preventScroll: true })
else {
const x = window.pageXOffset; const y = window.pageYOffset
this.$refs.search.focus()
if (window.pageYOffset !== y) setTimeout(function () { window.scrollTo(x, y) }, 0)
}
})
},
reset () {
if (this.type === ADVANCED) this.highlight = -1
},
clear () {
if (this.type !== ADVANCED) return
this.picked = []
if (!this.multiple) this.close()
},
close () {
if (this.show && !this.embed) this.$refs.drop.visible()
},
adjust () {
this.$nextTick(() => {
this.$refs.drop.adjust()
})
},
inPickedIndex (row) {
if (!row || !Object.keys(row).length || !this.picked.length) return -1
return this.picked.findIndex(val => val[this.keyField] === row[this.keyField])
},
inPicked (row) {
return this.inPickedIndex(row) !== -1
},
isChrome () {
return navigator.vendor !== undefined && navigator.vendor.indexOf('Google') !== -1
},
isEdge () {
return navigator.userAgent.indexOf('Edge') >= 0
}
}
}