forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathripple.js
More file actions
99 lines (87 loc) · 2.48 KB
/
ripple.js
File metadata and controls
99 lines (87 loc) · 2.48 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { position } from '../utils/event.js'
function showRipple (evt, el, { stop, center }) {
if (stop) {
evt.stopPropagation()
}
const
container = document.createElement('span'),
animNode = document.createElement('span'),
size = el.clientWidth > el.clientHeight ? el.clientWidth : el.clientHeight,
unit = `${center ? size : size * 2}px`,
offset = el.getBoundingClientRect()
container.appendChild(animNode)
container.className = 'q-ripple-container'
animNode.className = 'q-ripple-animation'
animNode.style.width = unit
animNode.style.height = unit
el.appendChild(container)
let x, y
if (center) {
x = y = 0
}
else {
const pos = position(evt)
x = pos.left - offset.left - size
y = pos.top - offset.top - size
}
animNode.classList.add('q-ripple-animation-enter')
animNode.classList.add('q-ripple-animation-visible')
animNode.style.transform = `translate(${x}px, ${y}px) scale3d(0, 0, 0)`
setTimeout(() => {
animNode.classList.remove('q-ripple-animation-enter')
animNode.style.transform = `translate(${x}px, ${y}px) scale3d(1, 1, 1)`
setTimeout(() => {
animNode.classList.remove('q-ripple-animation-visible')
setTimeout(() => { container.remove() }, 300)
}, 300)
}, 10)
}
function shouldAbort ({ mat, ios }) {
return (
(mat && process.env.THEME !== 'mat') ||
(ios && process.env.THEME !== 'ios')
)
}
export default {
name: 'ripple',
inserted (el, { value, modifiers }) {
if (shouldAbort(modifiers)) {
return
}
const ctx = {
enabled: value !== false,
modifiers: {
stop: modifiers.stop,
center: modifiers.center
},
click (evt) {
if (ctx.enabled && evt.detail !== -1) {
showRipple(evt, el, ctx.modifiers)
}
},
keyup (evt) {
if (ctx.enabled && evt.keyCode === 13) {
showRipple(evt, el, ctx.modifiers)
}
}
}
el.__qripple = ctx
el.addEventListener('click', ctx.click, false)
el.addEventListener('keyup', ctx.keyup, false)
},
update (el, { value, modifiers: { stop, center } }) {
const ctx = el.__qripple
if (ctx) {
ctx.enabled = value !== false
ctx.modifiers = { stop, center }
}
},
unbind (el, { modifiers }) {
const ctx = el.__qripple
if (ctx && !shouldAbort(modifiers)) {
el.removeEventListener('click', ctx.click, false)
el.removeEventListener('keyup', ctx.keyup, false)
delete el.__qripple
}
}
}