forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContextMenuMobile.js
More file actions
61 lines (60 loc) · 1.51 KB
/
ContextMenuMobile.js
File metadata and controls
61 lines (60 loc) · 1.51 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
import { QModal } from '../modal'
export default {
name: 'q-context-menu',
props: {
disable: Boolean
},
methods: {
close () {
this.target.classList.remove('non-selectable')
this.$refs.dialog.close()
},
__open () {
if (!this.disable && this.$refs.dialog) {
this.$refs.dialog.open()
}
},
__touchStartHandler (evt) {
this.target.classList.add('non-selectable')
this.touchTimer = setTimeout(() => {
evt.preventDefault()
evt.stopPropagation()
setTimeout(() => {
this.__cleanup()
this.__open()
}, 10)
}, 600)
},
__cleanup () {
this.target.classList.remove('non-selectable')
clearTimeout(this.touchTimer)
}
},
render (h) {
return h(QModal, {
ref: 'dialog',
props: {
minimized: true
},
on: {
open: () => { this.$emit('open') },
close: () => { this.$emit('close') }
}
}, this.$slots.default)
},
mounted () {
this.$nextTick(() => {
this.target = this.$el.parentNode
this.target.addEventListener('touchstart', this.__touchStartHandler)
;['touchcancel', 'touchmove', 'touchend'].forEach(evt => {
this.target.addEventListener(evt, this.__cleanup)
})
})
},
beforeDestroy () {
this.target.removeEventListener('touchstart', this.__touchStartHandler)
;['touchcancel', 'touchmove', 'touchend'].forEach(evt => {
this.target.removeEventListener(evt, this.__cleanup)
})
}
}