forked from dcloudio/mui
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmui.target.js
78 lines (74 loc) · 1.88 KB
/
mui.target.js
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
/**
* mui target(action>popover>modal>tab>toggle)
*/
(function($, window, document) {
/**
* targets
*/
$.targets = {};
/**
* target handles
*/
$.targetHandles = [];
/**
* register target
* @param {type} target
* @returns {$.targets}
*/
$.registerTarget = function(target) {
target.index = target.index || 1000;
$.targetHandles.push(target);
$.targetHandles.sort(function(a, b) {
return a.index - b.index;
});
return $.targetHandles;
};
window.addEventListener($.EVENT_START, function(event) {
var target = event.target;
var founds = {};
for (; target && target !== document; target = target.parentNode) {
var isFound = false;
$.each($.targetHandles, function(index, targetHandle) {
var name = targetHandle.name;
if (!isFound && !founds[name] && targetHandle.hasOwnProperty('handle')) {
$.targets[name] = targetHandle.handle(event, target);
if ($.targets[name]) {
founds[name] = true;
if (targetHandle.isContinue !== true) {
isFound = true;
}
}
} else {
if (!founds[name]) {
if (targetHandle.isReset !== false)
$.targets[name] = false;
}
}
});
if (isFound) {
break;
}
}
});
window.addEventListener('click', function(event) { //解决touch与click的target不一致的问题(比如链接边缘点击时,touch的target为html,而click的target为A)
var target = event.target;
var isFound = false;
for (; target && target !== document; target = target.parentNode) {
if (target.tagName === 'A') {
$.each($.targetHandles, function(index, targetHandle) {
var name = targetHandle.name;
if (targetHandle.hasOwnProperty('handle')) {
if (targetHandle.handle(event, target)) {
isFound = true;
event.preventDefault();
return false;
}
}
});
if (isFound) {
break;
}
}
}
});
})(mui, window, document);