Skip to content

Commit c893f4d

Browse files
qitmac000408qitmac000408
authored andcommitted
Merge branch 'master' of github.com:RubyLouvre/avalon
Conflicts: dist/avalon.mobile.min.js
2 parents 50667b9 + 4883d18 commit c893f4d

File tree

5 files changed

+172
-328
lines changed

5 files changed

+172
-328
lines changed

dist/avalon.mobile.js

Lines changed: 42 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,7 +5033,7 @@ avalon.config({
50335033
avalon.ready(function () {
50345034
avalon.scan(DOC.body)
50355035
})
5036-
new function () {// jshint ignore:line
5036+
new function() {// jshint ignore:line
50375037
var touchProxy = {}
50385038
var IEtouch = navigator.pointerEnabled
50395039
var IEMStouch = navigator.msPointerEnabled
@@ -5050,16 +5050,16 @@ new function () {// jshint ignore:line
50505050

50515051
if (IEtouch) {
50525052
touchNames = ["pointerdown", "pointermove", "pointerup", "pointercancel"]
5053-
}
5053+
}
50545054
if (IEMStouch) {
50555055
touchNames = ["MSPointerDown", "MSPointerMove", "MSPointerUp", "MSPointerCancel"]
50565056
}
5057-
function isPrimaryTouch(event) {
5057+
function isPrimaryTouch(event){
50585058
return (event.pointerType === 'touch' || event.pointerType === event.MSPOINTER_TYPE_TOUCH) && event.isPrimary
50595059
}
50605060

5061-
function isPointerEventType(e, type) {
5062-
return (e.type === 'pointer' + type || e.type.toLowerCase() === 'mspointer' + type)
5061+
function isPointerEventType(e, type){
5062+
return (e.type === 'pointer'+type || e.type.toLowerCase() === 'mspointer'+type)
50635063
}
50645064

50655065
//判定滑动方向
@@ -5076,63 +5076,40 @@ new function () {// jshint ignore:line
50765076
}
50775077
el.dispatchEvent(event)
50785078
}
5079-
function needsClick(target) {
5080-
switch (target.nodeName.toLowerCase()) {
5081-
// Don't send a synthetic click to disabled inputs (issue #62)
5082-
case 'button':
5083-
case 'select':
5084-
case 'textarea':
5085-
if (target.disabled) {
5086-
return true;
5087-
}
5088-
5089-
break;
5090-
case 'input':
50915079

5092-
// File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
5093-
if ((isAndroid && target.type === 'file') || target.disabled) {
5094-
return true;
5095-
}
5096-
5097-
break;
5098-
case 'label':
5099-
case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames
5100-
case 'video':
5101-
return true;
5102-
}
5103-
5104-
return (/\bneedsclick\b/).test(target.className);
5105-
}
5106-
;
5107-
function onMouse(event) {
5108-
var target = event.target
5109-
5080+
function onMouse(event) {
5081+
var target = event.target,
5082+
element = touchProxy.element
51105083

5111-
if (!needsClick(target)|| touchProxy.cancelNextClick ) {
5112-
5084+
if (element && element !== target) {
5085+
var type = target.type || '',
5086+
targetTag = target.tagName.toLowerCase(),
5087+
elementTag = element.tagName.toLowerCase()
5088+
// 通过手机的“前往”提交表单时不可禁止默认行为;通过label focus input时也不可以阻止默认行为
5089+
if ((targetTag === 'input' && elementTag === "label") || type === 'submit') {
5090+
return false
5091+
}
51135092
if (event.stopImmediatePropagation) {
51145093
event.stopImmediatePropagation()
51155094
} else {
51165095
event.propagationStopped = true
51175096
}
5118-
event.stopPropagation()
5097+
event.stopPropagation()
51195098
event.preventDefault()
51205099
}
51215100
}
51225101
function cancelLongTap() {
5123-
if (longTapTimeout)
5124-
clearTimeout(longTapTimeout)
5102+
if (longTapTimeout) clearTimeout(longTapTimeout)
51255103
longTapTimeout = null
51265104
}
51275105
function touchstart(event) {
51285106
var _isPointerType = isPointerEventType(event, "down"),
5129-
firstTouch = _isPointerType ? event : event.touches[0],
5130-
element = "tagName" in firstTouch.target ? firstTouch.target : firstTouch.target.parentNode,
5131-
now = Date.now(),
5132-
delta = now - (touchProxy.last || now)
5107+
firstTouch = _isPointerType ? event : event.touches[0],
5108+
element = "tagName" in firstTouch.target ? firstTouch.target: firstTouch.target.parentNode,
5109+
now = Date.now(),
5110+
delta = now - (touchProxy.last || now)
51335111

5134-
if (_isPointerType && !isPrimaryTouch(event))
5135-
return
5112+
if (_isPointerType && !isPrimaryTouch(event)) return
51365113
if (touchProxy.x1 || touchProxy.y1) {
51375114
touchProxy.x1 = undefined
51385115
touchProxy.y1 = undefined
@@ -5147,7 +5124,7 @@ new function () {// jshint ignore:line
51475124
touchProxy.last = now
51485125
touchProxy.element = element
51495126

5150-
longTapTimeout = setTimeout(function () {
5127+
longTapTimeout = setTimeout(function() {
51515128
longTapTimeout = null
51525129
fireEvent(element, "hold")
51535130
fireEvent(element, "longtap")
@@ -5158,43 +5135,30 @@ new function () {// jshint ignore:line
51585135
function touchmove(event) {
51595136

51605137
var _isPointerType = isPointerEventType(event, 'down'),
5161-
firstTouch = _isPointerType ? event : event.touches[0],
5162-
x = firstTouch.pageX,
5163-
y = firstTouch.pageY
5164-
if (_isPointerType && !isPrimaryTouch(event))
5165-
return
5138+
firstTouch = _isPointerType ? event : event.touches[0],
5139+
x = firstTouch.pageX,
5140+
y = firstTouch.pageY
5141+
if (_isPointerType && !isPrimaryTouch(event)) return
51665142
/*
5167-
android下某些浏览器触发了touchmove事件的话touchend事件不触发,禁用touchmove可以解决此bug
5168-
http://stackoverflow.com/questions/14486804/understanding-touch-events
5169-
*/
5143+
android下某些浏览器触发了touchmove事件的话touchend事件不触发,禁用touchmove可以解决此bug
5144+
http://stackoverflow.com/questions/14486804/understanding-touch-events
5145+
*/
51705146
if (isGoingtoFixTouchEndEvent && Math.abs(touchProxy.x - x) > 10) {
51715147
event.preventDefault()
51725148
}
51735149
cancelLongTap()
5174-
5150+
51755151
touchProxy.x1 = x // touchend事件没有pageX、pageY始终为0,且没有clientX和clientY事件
51765152
touchProxy.y1 = y
51775153
touchProxy.mx += Math.abs(touchProxy.x - x)
51785154
touchProxy.my += Math.abs(touchProxy.y - y)
51795155
}
5180-
function touchend(event) {
5181-
5182-
5183-
//如果点得太快,直接忽略
5184-
if ((event.timeStamp - touchProxy.lastClickTime) < 200) {
5185-
touchProxy.cancelNextClick = true;
5186-
return true;
5187-
}
5188-
touchProxy.cancelNextClick = false;
5189-
5190-
touchProxy.lastClickTime = event.timeStamp;
5156+
function touchend(event) {
51915157
var _isPointerType = isPointerEventType(event, 'down'),
5192-
element = touchProxy.element
5158+
element = touchProxy.element
51935159

5194-
if (_isPointerType && !isPrimaryTouch(event))
5195-
return
5196-
if (!element)
5197-
return // longtap|hold触发后touchProxy为{}
5160+
if (_isPointerType && !isPrimaryTouch(event)) return
5161+
if (!element) return // longtap|hold触发后touchProxy为{}
51985162

51995163
cancelLongTap()
52005164
if ((touchProxy.x1 && Math.abs(touchProxy.x1 - touchProxy.x) > dragDistance) || (touchProxy.y1 && Math.abs(touchProxy.y1 - touchProxy.y) > dragDistance)) {
@@ -5214,11 +5178,10 @@ new function () {// jshint ignore:line
52145178
touchProxy = {}
52155179
touchProxy.element = element
52165180
} else {
5217-
touchTimeout = setTimeout(function () {
5181+
touchTimeout = setTimeout(function() {
52185182
clearTimeout(touchTimeout)
52195183
touchTimeout = null
5220-
if (touchProxy.element)
5221-
fireEvent(touchProxy.element, "singletap")
5184+
if (touchProxy.element) fireEvent(touchProxy.element, "singletap")
52225185
touchProxy = {};
52235186
touchProxy.element = element
52245187
}, 250)
@@ -5234,16 +5197,14 @@ new function () {// jshint ignore:line
52345197
document.addEventListener(touchNames[1], touchmove)
52355198
document.addEventListener(touchNames[2], touchend)
52365199
if (touchNames[3]) {
5237-
document.addEventListener(touchNames[3], function (event) {
5238-
if (longTapTimeout)
5239-
clearTimeout(longTapTimeout)
5240-
if (touchTimeout)
5241-
clearTimeout(touchTimeout)
5200+
document.addEventListener(touchNames[3], function(event) {
5201+
if (longTapTimeout) clearTimeout(longTapTimeout)
5202+
if (touchTimeout) clearTimeout(touchTimeout)
52425203
longTapTimeout = touchTimeout = null
52435204
touchProxy = {}
52445205
})
52455206
}
5246-
["swipe", "swipeleft", "swiperight", "swipeup", "swipedown", "doubletap", "tap", "singletap", "longtap", "hold"].forEach(function (method) {
5207+
["swipe", "swipeleft", "swiperight", "swipeup", "swipedown", "doubletap", "tap", "singletap", "dblclick", "longtap", "hold"].forEach(function(method) {
52475208
me[method + "Hook"] = me["clickHook"]
52485209
})
52495210

dist/avalon.mobile.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)