|
7 | 7 | <style lang="scss" src="./mdInkRipple.scss"></style>
|
8 | 8 |
|
9 | 9 | <script>
|
10 |
| - const hasTouch = 'ontouchstart' in document; |
11 |
| - const getEventName = (type) => { |
| 10 | + const addEvent = (target, type, handler) => { |
12 | 11 | if (type === 'start') {
|
13 |
| - return hasTouch ? 'touchstart' : 'mousedown'; |
| 12 | + target.addEventListener('mousedown', handler); |
| 13 | + target.addEventListener('touchstart', handler); |
| 14 | + } else { |
| 15 | + target.addEventListener('mouseup', handler); |
| 16 | + target.addEventListener('touchend', handler); |
14 | 17 | }
|
15 |
| -
|
16 |
| - return hasTouch ? 'touchend' : 'mouseup'; |
17 |
| - }; |
18 |
| - const addEvent = (target, type, handler) => { |
19 |
| - target.addEventListener(getEventName(type), handler); |
20 | 18 | };
|
21 | 19 | const removeEvent = (target, type, handler) => {
|
22 |
| - target.removeEventListener(getEventName(type), handler); |
| 20 | + if (type === 'start') { |
| 21 | + target.removeEventListener('mousedown', handler); |
| 22 | + target.removeEventListener('touchstart', handler); |
| 23 | + } else { |
| 24 | + target.removeEventListener('mouseup', handler); |
| 25 | + target.removeEventListener('touchend', handler); |
| 26 | + } |
23 | 27 | };
|
24 | 28 |
|
25 | 29 | export default {
|
|
135 | 139 | removeEvent(document.body, 'end', this.endRipple);
|
136 | 140 | },
|
137 | 141 | startRipple(event) {
|
| 142 | + if (event.type === 'touchstart') { |
| 143 | + this.previous.push('touch'); |
| 144 | + } else { |
| 145 | + this.previous.push('mouse'); |
| 146 | + } |
| 147 | +
|
| 148 | + this.previous = this.previous.splice(this.previous.length - 2, this.previous.length); |
| 149 | +
|
| 150 | + if (this.previous.length >= 2 && this.previous[1] === 'touch' && this.previous[0] === 'mouse') { |
| 151 | + return; |
| 152 | + } |
| 153 | +
|
138 | 154 | this.clearState();
|
139 | 155 | this.awaitingComplete = window.setTimeout(() => {
|
140 | 156 | this.hasCompleted = true;
|
|
169 | 185 | init() {
|
170 | 186 | this.rippleElement = this.$el;
|
171 | 187 | this.parentElement = this.getClosestPositionedParent(this.$el.parentNode);
|
| 188 | + this.previous = ['mouse']; |
172 | 189 |
|
173 | 190 | if (!this.parentElement) {
|
174 | 191 | this.$destroy();
|
|
0 commit comments