From 70f1309579d0f4d08e23a874e205006382226cc1 Mon Sep 17 00:00:00 2001 From: xbr <2212268909@qq.com> Date: Sat, 6 Jan 2018 19:17:24 +0800 Subject: [PATCH] fixed #544: while layer.onclick set to null int the handler, but the handler still execute. --- lib/fastclick.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/fastclick.js b/lib/fastclick.js index 86bf83e0..972c232e 100644 --- a/lib/fastclick.js +++ b/lib/fastclick.js @@ -22,6 +22,7 @@ */ function FastClick(layer, options) { var oldOnClick; + var oldOnClickNoop = function () {}; options = options || {}; @@ -167,9 +168,11 @@ // - the old one won't work if passed to addEventListener directly. oldOnClick = layer.onclick; layer.addEventListener('click', function(event) { - oldOnClick(event); + if (layer.onclick === oldOnClickNoop) { + oldOnClick(event); + } }, false); - layer.onclick = null; + layer.onclick = oldOnClickNoop; } }