Comparing version 3.1.1 to 3.2.0
18
index.js
@@ -30,7 +30,7 @@ /* global MutationObserver */ | ||
module.exports = function onload (el, on, off) { | ||
module.exports = function onload (el, on, off, caller) { | ||
on = on || function () {} | ||
off = off || function () {} | ||
el.setAttribute(KEY_ATTR, 'o' + INDEX) | ||
watch['o' + INDEX] = [on, off, 0, onload.caller] | ||
watch['o' + INDEX] = [on, off, 0, caller || onload.caller] | ||
INDEX += 1 | ||
@@ -60,10 +60,8 @@ return el | ||
} | ||
Object.keys(watch).forEach(function (k) { | ||
if (mutation.oldValue === k) { | ||
off(k, mutation.target) | ||
} | ||
if (newValue === k) { | ||
on(k, mutation.target) | ||
} | ||
}) | ||
if (watch[mutation.oldValue]) { | ||
off(mutation.oldValue, mutation.target) | ||
} | ||
if (watch[newValue]) { | ||
on(newValue, mutation.target) | ||
} | ||
} | ||
@@ -70,0 +68,0 @@ |
{ | ||
"name": "on-load", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "On load/unload events for DOM elements using a MutationObserver", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
4468
80