Skip to content

Commit 3040c3c

Browse files
author
egoist
committed
fix mobile
1 parent 4111dc2 commit 3040c3c

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-preload",
3-
"version": "0.1.1",
3+
"version": "0.1.11",
44
"description": "Preloading data for Vue component",
55
"main": "./vue-preload.js",
66
"scripts": {

src/register.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ export default function (Vue, options) {
2424
})
2525
}
2626

27+
function isMobile() {
28+
return navigator.userAgent.indexOf('Windows Phone') > -1
29+
|| navigator.userAgent.indexOf('Android') > -1
30+
|| navigator.userAgent.indexOf('iPad') > -1
31+
|| navigator.userAgent.indexOf('iPhone') > -1
32+
|| navigator.userAgent.indexOf('Mobile') > -1
33+
}
34+
2735
Vue.directive('preload', {
2836
bind() {
2937
this.preLoading = false
@@ -48,8 +56,12 @@ export default function (Vue, options) {
4856
}
4957
this.setState(this.tmp)
5058
}
51-
_.on(this.el, 'mouseover', this.handleMouseOver)
52-
_.on(this.el, 'click', this.handleClick)
59+
if (isMobile()) {
60+
_.on(this.el, 'touchstart', this.handleMouseOver)
61+
} else {
62+
_.on(this.el, 'mouseover', this.handleMouseOver)
63+
_.on(this.el, 'click', this.handleClick)
64+
}
5365
},
5466
set(obj) {
5567
this.tmp = obj
@@ -64,7 +76,7 @@ export default function (Vue, options) {
6476
end() {
6577
this.preLoading = false
6678
this.hideBar()
67-
if (this.clickToPreload) {
79+
if (this.clickToPreload || isMobile()) {
6880
this.setState(this.tmp)
6981
this.clickToPreload = false
7082
}
@@ -86,8 +98,12 @@ export default function (Vue, options) {
8698
}
8799
},
88100
reset() {
89-
_.off(this.el, 'mouseover', this.handleMouseOver)
90-
_.off(this.el, 'click', this.handleClick)
101+
if (isMobile()) {
102+
_.off(this.el, 'touchstart', this.handleMouseOver)
103+
} else {
104+
_.off(this.el, 'mouseover', this.handleMouseOver)
105+
_.off(this.el, 'click', this.handleClick)
106+
}
91107
},
92108
unbind() {
93109
this.reset()

tests/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
56
<title>Vue-Preload</title>
67
<style>
78
body {

0 commit comments

Comments
 (0)