Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
b660c94e
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
720
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b660c94e
编写于
3月 12, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(h5): remove touch emulator
上级
25bba0c9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
1 addition
and
373 deletion
+1
-373
packages/vue-cli-plugin-uni/lib/h5/index.js
packages/vue-cli-plugin-uni/lib/h5/index.js
+1
-3
packages/vue-cli-plugin-uni/lib/h5/touch-emulator.js
packages/vue-cli-plugin-uni/lib/h5/touch-emulator.js
+0
-370
未找到文件。
packages/vue-cli-plugin-uni/lib/h5/index.js
浏览文件 @
b660c94e
...
...
@@ -106,7 +106,6 @@ module.exports = {
const
qihooCode
=
process
.
env
.
UNI_SUB_PLATFORM
===
'
mp-360
'
?
`
import 'uni-touch-emulator';
import qh from 'uni-qh';
global.qh = qh;
global.onAppShow = function(){};
...
...
@@ -119,8 +118,7 @@ global.onAppShow = function(){};
alias
:
{
'
vue-router
'
:
resolve
(
'
packages/h5-vue-router
'
),
'
uni-h5
'
:
require
.
resolve
(
'
@dcloudio/uni-h5
'
),
'
uni-qh
'
:
path
.
resolve
(
__dirname
,
'
qh-api.js
'
),
'
uni-touch-emulator
'
:
path
.
resolve
(
__dirname
,
'
touch-emulator.js
'
)
'
uni-qh
'
:
path
.
resolve
(
__dirname
,
'
qh-api.js
'
)
}
},
module
:
{
...
...
packages/vue-cli-plugin-uni/lib/h5/touch-emulator.js
已删除
100644 → 0
浏览文件 @
25bba0c9
(
function
(
window
,
document
,
exportName
,
undefined
)
{
'
use strict
'
var
isMultiTouch
=
false
var
multiTouchStartPos
var
eventTarget
var
touchElements
=
{}
// polyfills
if
(
!
document
.
createTouch
)
{
document
.
createTouch
=
function
(
view
,
target
,
identifier
,
pageX
,
pageY
,
screenX
,
screenY
,
clientX
,
clientY
)
{
// auto set
if
(
clientX
==
undefined
||
clientY
==
undefined
)
{
clientX
=
pageX
-
window
.
pageXOffset
clientY
=
pageY
-
window
.
pageYOffset
}
return
new
Touch
(
target
,
identifier
,
{
pageX
:
pageX
,
pageY
:
pageY
,
screenX
:
screenX
,
screenY
:
screenY
,
clientX
:
clientX
,
clientY
:
clientY
})
}
}
if
(
!
document
.
createTouchList
)
{
document
.
createTouchList
=
function
()
{
var
touchList
=
new
TouchList
()
for
(
var
i
=
0
;
i
<
arguments
.
length
;
i
++
)
{
touchList
[
i
]
=
arguments
[
i
]
}
touchList
.
length
=
arguments
.
length
return
touchList
}
}
/**
* create an touch point
* @constructor
* @param target
* @param identifier
* @param pos
* @param deltaX
* @param deltaY
* @returns {Object} touchPoint
*/
function
Touch
(
target
,
identifier
,
pos
,
deltaX
,
deltaY
)
{
deltaX
=
deltaX
||
0
deltaY
=
deltaY
||
0
this
.
identifier
=
identifier
this
.
target
=
target
this
.
clientX
=
pos
.
clientX
+
deltaX
this
.
clientY
=
pos
.
clientY
+
deltaY
this
.
screenX
=
pos
.
screenX
+
deltaX
this
.
screenY
=
pos
.
screenY
+
deltaY
this
.
pageX
=
pos
.
pageX
+
deltaX
this
.
pageY
=
pos
.
pageY
+
deltaY
}
/**
* create empty touchlist with the methods
* @constructor
* @returns touchList
*/
function
TouchList
()
{
var
touchList
=
[]
touchList
.
item
=
function
(
index
)
{
return
this
[
index
]
||
null
}
// specified by Mozilla
touchList
.
identifiedTouch
=
function
(
id
)
{
return
this
[
id
+
1
]
||
null
}
return
touchList
}
/**
* Simple trick to fake touch event support
* this is enough for most libraries like Modernizr and Hammer
*/
function
fakeTouchSupport
()
{
var
objs
=
[
window
,
document
.
documentElement
]
var
props
=
[
'
ontouchstart
'
,
'
ontouchmove
'
,
'
ontouchcancel
'
,
'
ontouchend
'
]
for
(
var
o
=
0
;
o
<
objs
.
length
;
o
++
)
{
for
(
var
p
=
0
;
p
<
props
.
length
;
p
++
)
{
if
(
objs
[
o
]
&&
objs
[
o
][
props
[
p
]]
==
undefined
)
{
objs
[
o
][
props
[
p
]]
=
null
}
}
}
}
/**
* we don't have to emulate on a touch device
* @returns {boolean}
*/
function
hasTouchSupport
()
{
return
(
'
ontouchstart
'
in
window
)
||
// touch events
(
window
.
Modernizr
&&
window
.
Modernizr
.
touch
)
||
// modernizr
(
navigator
.
msMaxTouchPoints
||
navigator
.
maxTouchPoints
)
>
2
// pointer events
}
/**
* disable mouseevents on the page
* @param ev
*/
function
preventMouseEvents
(
ev
)
{
ev
.
preventDefault
()
ev
.
stopPropagation
()
}
/**
* only trigger touches when the left mousebutton has been pressed
* @param touchType
* @returns {Function}
*/
function
onMouse
(
touchType
)
{
return
function
(
ev
)
{
// prevent mouse events
// 过滤 输入框 和 可编辑元素
// preventMouseEvents(ev);
ev
.
stopPropagation
()
var
computedStyle
var
target
=
ev
.
target
if
(
target
.
tagName
!==
'
INPUT
'
&&
target
.
tagName
!==
'
TEXTAREA
'
&&
(
computedStyle
=
window
.
getComputedStyle
(
target
))
&&
(
computedStyle
[
'
user-modify
'
]
||
computedStyle
[
'
-webkit-user-modify
'
]).
indexOf
(
'
write
'
)
<
0
)
{
ev
.
preventDefault
()
}
if
(
ev
.
which
!==
1
)
{
return
}
// The EventTarget on which the touch point started when it was first placed on the surface,
// even if the touch point has since moved outside the interactive area of that element.
// also, when the target doesnt exist anymore, we update it
if
(
ev
.
type
==
'
mousedown
'
||
!
eventTarget
||
(
eventTarget
&&
!
eventTarget
.
dispatchEvent
))
{
eventTarget
=
ev
.
target
}
// shiftKey has been lost, so trigger a touchend
if
(
isMultiTouch
&&
!
ev
.
shiftKey
)
{
triggerTouch
(
'
touchend
'
,
ev
)
isMultiTouch
=
false
}
triggerTouch
(
touchType
,
ev
)
// we're entering the multi-touch mode!
if
(
!
isMultiTouch
&&
ev
.
shiftKey
)
{
isMultiTouch
=
true
multiTouchStartPos
=
{
pageX
:
ev
.
pageX
,
pageY
:
ev
.
pageY
,
clientX
:
ev
.
clientX
,
clientY
:
ev
.
clientY
,
screenX
:
ev
.
screenX
,
screenY
:
ev
.
screenY
}
triggerTouch
(
'
touchstart
'
,
ev
)
}
// reset
if
(
ev
.
type
==
'
mouseup
'
)
{
multiTouchStartPos
=
null
isMultiTouch
=
false
eventTarget
=
null
}
}
}
/**
* trigger a touch event
* @param eventName
* @param mouseEv
*/
function
triggerTouch
(
eventName
,
mouseEv
)
{
var
touchEvent
=
document
.
createEvent
(
'
Event
'
)
touchEvent
.
initEvent
(
eventName
,
true
,
true
)
touchEvent
.
altKey
=
mouseEv
.
altKey
touchEvent
.
ctrlKey
=
mouseEv
.
ctrlKey
touchEvent
.
metaKey
=
mouseEv
.
metaKey
touchEvent
.
shiftKey
=
mouseEv
.
shiftKey
touchEvent
.
touches
=
getActiveTouches
(
mouseEv
,
eventName
)
touchEvent
.
targetTouches
=
getActiveTouches
(
mouseEv
,
eventName
)
touchEvent
.
changedTouches
=
getChangedTouches
(
mouseEv
,
eventName
)
eventTarget
.
dispatchEvent
(
touchEvent
)
}
/**
* create a touchList based on the mouse event
* @param mouseEv
* @returns {TouchList}
*/
function
createTouchList
(
mouseEv
)
{
var
touchList
=
new
TouchList
()
if
(
isMultiTouch
)
{
var
f
=
TouchEmulator
.
multiTouchOffset
var
deltaX
=
multiTouchStartPos
.
pageX
-
mouseEv
.
pageX
var
deltaY
=
multiTouchStartPos
.
pageY
-
mouseEv
.
pageY
touchList
.
push
(
new
Touch
(
eventTarget
,
1
,
multiTouchStartPos
,
(
deltaX
*
-
1
)
-
f
,
(
deltaY
*
-
1
)
+
f
))
touchList
.
push
(
new
Touch
(
eventTarget
,
2
,
multiTouchStartPos
,
deltaX
+
f
,
deltaY
-
f
))
}
else
{
touchList
.
push
(
new
Touch
(
eventTarget
,
1
,
mouseEv
,
0
,
0
))
}
return
touchList
}
/**
* receive all active touches
* @param mouseEv
* @returns {TouchList}
*/
function
getActiveTouches
(
mouseEv
,
eventName
)
{
// empty list
if
(
mouseEv
.
type
==
'
mouseup
'
)
{
return
new
TouchList
()
}
var
touchList
=
createTouchList
(
mouseEv
)
if
(
isMultiTouch
&&
mouseEv
.
type
!=
'
mouseup
'
&&
eventName
==
'
touchend
'
)
{
touchList
.
splice
(
1
,
1
)
}
return
touchList
}
/**
* receive a filtered set of touches with only the changed pointers
* @param mouseEv
* @param eventName
* @returns {TouchList}
*/
function
getChangedTouches
(
mouseEv
,
eventName
)
{
var
touchList
=
createTouchList
(
mouseEv
)
// we only want to return the added/removed item on multitouch
// which is the second pointer, so remove the first pointer from the touchList
//
// but when the mouseEv.type is mouseup, we want to send all touches because then
// no new input will be possible
if
(
isMultiTouch
&&
mouseEv
.
type
!=
'
mouseup
'
&&
(
eventName
==
'
touchstart
'
||
eventName
==
'
touchend
'
))
{
touchList
.
splice
(
0
,
1
)
}
return
touchList
}
/**
* show the touchpoints on the screen
*/
function
showTouches
(
ev
)
{
var
touch
,
i
,
el
,
styles
// first all visible touches
for
(
i
=
0
;
i
<
ev
.
touches
.
length
;
i
++
)
{
touch
=
ev
.
touches
[
i
]
el
=
touchElements
[
touch
.
identifier
]
if
(
!
el
)
{
el
=
touchElements
[
touch
.
identifier
]
=
document
.
createElement
(
'
div
'
)
document
.
body
.
appendChild
(
el
)
}
styles
=
TouchEmulator
.
template
(
touch
)
for
(
var
prop
in
styles
)
{
el
.
style
[
prop
]
=
styles
[
prop
]
}
}
// remove all ended touches
if
(
ev
.
type
==
'
touchend
'
||
ev
.
type
==
'
touchcancel
'
)
{
for
(
i
=
0
;
i
<
ev
.
changedTouches
.
length
;
i
++
)
{
touch
=
ev
.
changedTouches
[
i
]
el
=
touchElements
[
touch
.
identifier
]
if
(
el
)
{
el
.
parentNode
.
removeChild
(
el
)
delete
touchElements
[
touch
.
identifier
]
}
}
}
}
/**
* TouchEmulator initializer
*/
function
TouchEmulator
()
{
if
(
hasTouchSupport
())
{
return
}
fakeTouchSupport
()
window
.
addEventListener
(
'
mousedown
'
,
onMouse
(
'
touchstart
'
),
true
)
window
.
addEventListener
(
'
mousemove
'
,
onMouse
(
'
touchmove
'
),
true
)
window
.
addEventListener
(
'
mouseup
'
,
onMouse
(
'
touchend
'
),
true
)
window
.
addEventListener
(
'
mouseenter
'
,
preventMouseEvents
,
true
)
window
.
addEventListener
(
'
mouseleave
'
,
preventMouseEvents
,
true
)
window
.
addEventListener
(
'
mouseout
'
,
preventMouseEvents
,
true
)
window
.
addEventListener
(
'
mouseover
'
,
preventMouseEvents
,
true
)
// it uses itself!
// 关闭触摸显示
// window.addEventListener("touchstart", showTouches, false);
// window.addEventListener("touchmove", showTouches, false);
// window.addEventListener("touchend", showTouches, false);
// window.addEventListener("touchcancel", showTouches, false);
}
// start distance when entering the multitouch mode
TouchEmulator
.
multiTouchOffset
=
75
/**
* css template for the touch rendering
* @param touch
* @returns object
*/
TouchEmulator
.
template
=
function
(
touch
)
{
var
size
=
30
var
transform
=
'
translate(
'
+
(
touch
.
clientX
-
(
size
/
2
))
+
'
px,
'
+
(
touch
.
clientY
-
(
size
/
2
))
+
'
px)
'
return
{
position
:
'
fixed
'
,
left
:
0
,
top
:
0
,
background
:
'
#fff
'
,
border
:
'
solid 1px #999
'
,
opacity
:
0.6
,
borderRadius
:
'
100%
'
,
height
:
size
+
'
px
'
,
width
:
size
+
'
px
'
,
padding
:
0
,
margin
:
0
,
display
:
'
block
'
,
overflow
:
'
hidden
'
,
pointerEvents
:
'
none
'
,
webkitUserSelect
:
'
none
'
,
mozUserSelect
:
'
none
'
,
userSelect
:
'
none
'
,
webkitTransform
:
transform
,
mozTransform
:
transform
,
transform
:
transform
}
}
// export
// 直接启用
// if (typeof define == "function" && define.amd) {
// define(function() {
// return TouchEmulator;
// });
// } else if (typeof module != "undefined" && module.exports) {
// module.exports = TouchEmulator;
// } else {
// window[exportName] = TouchEmulator;
// }
TouchEmulator
()
})(
window
,
document
,
'
TouchEmulator
'
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录