From 40ff56d26ccc920a356ac6b5e1601d25bd78af24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 8 Aug 2019 19:13:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A7=E7=9A=84=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/02-core.js | 13 ++++++------- src/04-dom.patch.js | 40 ---------------------------------------- 3 files changed, 7 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index d56fc3d..0bbafae 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .LSOverride .idea .vscode +package-lock.json node_modules/ dist/ diff --git a/src/02-core.js b/src/02-core.js index 6ea0398..49da09f 100644 --- a/src/02-core.js +++ b/src/02-core.js @@ -4,7 +4,7 @@ let Anot = function(el) { } /*视浏览器情况采用最快的异步回调*/ -Anot.nextTick = new function() { +Anot.nextTick = new (function() { // jshint ignore:line let tickImmediate = window.setImmediate let tickObserver = window.MutationObserver @@ -35,7 +35,7 @@ Anot.nextTick = new function() { return function(fn) { setTimeout(fn, 4) } -}() // jshint ignore:line +})() // jshint ignore:line /********************************************************************* * Anot的静态方法定义区 * @@ -290,7 +290,7 @@ Anot.mix({ t = t.trim() let hook = hooks[t] if (typeof hook === 'object') { - type = hook.type || type + t = hook.type || type phase = hook.phase || !!phase fn = hook.fix ? hook.fix(el, fn) : fn } @@ -307,7 +307,7 @@ Anot.mix({ t = t.trim() let hook = hooks[t] if (typeof hook === 'object') { - type = hook.type || type + t = hook.type || type phase = hook.phase || !!phase } el.removeEventListener(t, fn, phase) @@ -349,13 +349,12 @@ Anot.mix({ each: function(obj, fn) { if (obj) { //排除null, undefined - let i = 0 if (isArrayLike(obj)) { - for (let n = obj.length; i < n; i++) { + for (let i = 0, n = obj.length; i < n; i++) { if (fn(i, obj[i]) === false) break } } else { - for (i in obj) { + for (let i in obj) { if (obj.hasOwnProperty(i) && fn(i, obj[i]) === false) { break } diff --git a/src/04-dom.patch.js b/src/04-dom.patch.js index 8a67eca..79af8b3 100644 --- a/src/04-dom.patch.js +++ b/src/04-dom.patch.js @@ -21,46 +21,6 @@ Anot.contains = function(root, el) { let eventHooks = Anot.eventHooks -//针对firefox, chrome修正mouseenter, mouseleave(chrome30+) -if (!('onmouseenter' in root)) { - Anot.each( - { - mouseenter: 'mouseover', - mouseleave: 'mouseout' - }, - function(origType, fixType) { - eventHooks[origType] = { - type: fixType, - fix: function(elem, fn) { - return function(e) { - let t = e.relatedTarget - if (!t || (t !== elem && !(elem.compareDocumentPosition(t) & 16))) { - delete e.type - e.type = origType - return fn.call(elem, e) - } - } - } - } - } - ) -} - -//针对IE9+, w3c修正animationend -Anot.each( - { - AnimationEvent: 'animationend', - WebKitAnimationEvent: 'webkitAnimationEnd' - }, - function(construct, fixType) { - if (window[construct] && !eventHooks.animationend) { - eventHooks.animationend = { - type: fixType - } - } - } -) - if (DOC.onmousewheel === void 0) { /* IE6-11 chrome mousewheel wheelDetla 下 -120 上 120 firefox DOMMouseScroll detail 下3 上-3