Skip to content

Commit

Permalink
优化fastclick代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaran113 authored and Mickey- committed Nov 24, 2015
1 parent fcd3862 commit 6d05b64
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions js/fastclick.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@
*/
var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0;

/**
* 判断是否组合型label
* 夏苒添加
*
* @type {Boolean}
*/
var isCompositeLabel = false;

/**
* Determine whether a given element requires a native click.
*
Expand All @@ -238,7 +246,10 @@
// 夏苒添加start,如果label上有needsclick这个类,则用原生的点击,否则,用模拟点击
var parent = target;
while(parent && (parent.tagName.toUpperCase() !== "BODY")) {
if(parent.tagName.toUpperCase() === "LABEL" && (/\bneedsclick\b/).test(parent.className)) return true;
if (parent.tagName.toUpperCase() === "LABEL") {
isCompositeLabel = true;
if ((/\bneedsclick\b/).test(parent.className)) return true;
}
parent = parent.parentNode;
}
// 夏苒添加end
Expand Down Expand Up @@ -660,25 +671,6 @@
return true;
}

/**
* 夏苒添加 start
*
*/
var isCompositeLabel = false; // 是否组合型label
var parent = this.targetElement;

// 判断父元素中是否有 label,如果有则为组合型label
while(parent && (parent.tagName.toUpperCase() !== "BODY")) {
if(parent.tagName.toUpperCase() === "LABEL") {
isCompositeLabel = true;
}
parent = parent.parentNode;
}
/**
* 夏苒添加 end
*/


// Derive and check the target element to see whether the mouse event needs to be permitted;
// unless explicitly enabled, prevent non-touch click events from triggering actions,
// to prevent ghost/doubleclicks.
Expand Down

0 comments on commit 6d05b64

Please sign in to comment.