You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.0 KiB
68 lines
2.0 KiB
/**
|
|
* fastclick(only for radio,checkbox)
|
|
*/
|
|
(function($, window, name) {
|
|
if (!$.os.android && !$.os.ios) { //目前仅识别android和ios
|
|
return;
|
|
}
|
|
if (window.FastClick) {
|
|
return;
|
|
}
|
|
|
|
var handle = function(event, target) {
|
|
if (target.tagName === 'LABEL') {
|
|
if (target.parentNode) {
|
|
target = target.parentNode.querySelector('input');
|
|
}
|
|
}
|
|
if (target && (target.type === 'radio' || target.type === 'checkbox')) {
|
|
if (!target.disabled) { //disabled
|
|
return target;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
$.registerTarget({
|
|
name: name,
|
|
index: 40,
|
|
handle: handle,
|
|
target: false
|
|
});
|
|
var dispatchEvent = function(event) {
|
|
var targetElement = $.targets.click;
|
|
if (targetElement) {
|
|
var clickEvent, touch;
|
|
// On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect
|
|
if (document.activeElement && document.activeElement !== targetElement) {
|
|
document.activeElement.blur();
|
|
}
|
|
touch = event.detail.gesture.changedTouches[0];
|
|
// Synthesise a click event, with an extra attribute so it can be tracked
|
|
clickEvent = document.createEvent('MouseEvents');
|
|
clickEvent.initMouseEvent('click', true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
|
|
clickEvent.forwardedTouchEvent = true;
|
|
targetElement.dispatchEvent(clickEvent);
|
|
event.detail && event.detail.gesture.preventDefault();
|
|
}
|
|
};
|
|
window.addEventListener('tap', dispatchEvent);
|
|
window.addEventListener('doubletap', dispatchEvent);
|
|
//捕获
|
|
window.addEventListener('click', function(event) {
|
|
if ($.targets.click) {
|
|
if (!event.forwardedTouchEvent) { //stop click
|
|
if (event.stopImmediatePropagation) {
|
|
event.stopImmediatePropagation();
|
|
} else {
|
|
// Part of the hack for browsers that don't support Event#stopImmediatePropagation
|
|
event.propagationStopped = true;
|
|
}
|
|
event.stopPropagation();
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
}
|
|
}, true);
|
|
|
|
})(mui, window, 'click'); |