dom-event-helpers
Advanced tools
Comparing version 0.3.0 to 1.0.0
{ | ||
"name": "dom-event-helpers", | ||
"version": "0.3.0", | ||
"description": "Super tiny DOM event helpers.", | ||
"repository": "git@github.com:jsor/dom-event-helpers.git", | ||
"version": "1.0.0", | ||
"description": "A super tiny DOM event helper library.", | ||
"repository": "https://github.com/jsor/dom-event-helpers.git", | ||
"author": { | ||
@@ -16,4 +16,56 @@ "name": "Jan Sorgalla", | ||
"helper", | ||
"utility" | ||
] | ||
"utility", | ||
"on", | ||
"off", | ||
"ready" | ||
], | ||
"files": [ | ||
"src", | ||
"index.js" | ||
], | ||
"xo": { | ||
"space": 4, | ||
"rules": { | ||
"max-params": [ | ||
"warn", | ||
{ | ||
"max": 5 | ||
} | ||
] | ||
}, | ||
"ignores": [ | ||
"test/**", | ||
"karma*" | ||
], | ||
"envs": [ | ||
"node", | ||
"browser" | ||
] | ||
}, | ||
"scripts": { | ||
"lint": "xo", | ||
"dev": "karma start", | ||
"test": "npm run lint && karma start --single-run" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-loader": "^7.1.4", | ||
"babel-preset-env": "^1.6.1", | ||
"chai": "^4.1.2", | ||
"istanbul-instrumenter-loader": "^3.0.0", | ||
"karma": "^2.0.0", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-coverage": "^1.1.1", | ||
"karma-coverage-istanbul-reporter": "^1.4.2", | ||
"karma-firefox-launcher": "^1.1.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"karma-sauce-launcher": "^1.2.0", | ||
"karma-webpack": "^2.0.13", | ||
"mocha": "^4.1.0", | ||
"simulant": "^0.2.2", | ||
"webpack": "^4.1.1", | ||
"xo": "^0.20.3" | ||
} | ||
} |
import optionsArgument from './options-argument'; | ||
export default function off(node, type, listener, options = {capture: false}) { | ||
node.removeEventListener(type, listener, optionsArgument(options)); | ||
}; | ||
export default function off(target, type, listener, options = {capture: false}) { | ||
target.removeEventListener(type, listener, optionsArgument(options)); | ||
} |
@@ -5,20 +5,19 @@ import optionsSupport from './options-support'; | ||
export default function on(node, type, listener, options = {capture: false}) { | ||
let cb = listener; | ||
let rm; | ||
export default function on(target, type, listener, options = {capture: false}) { | ||
let callback = listener; | ||
const remove = () => { | ||
off(target, type, callback, options); | ||
}; | ||
if (options.once && !optionsSupport().once) { | ||
cb = (event) => { | ||
rm(); | ||
listener.call(node, event); | ||
callback = event => { | ||
remove(); | ||
listener.call(target, event); | ||
}; | ||
} | ||
rm = () => { | ||
off(node, type, cb, options); | ||
}; | ||
target.addEventListener(type, callback, optionsArgument(options)); | ||
node.addEventListener(type, cb, optionsArgument(options)); | ||
return rm; | ||
}; | ||
return remove; | ||
} |
import support from './options-support'; | ||
export default function(options = {}) { | ||
export default function optionsArgument(options = {}) { | ||
const {once, passive, capture} = support(); | ||
@@ -5,0 +5,0 @@ |
let supportedOptions; | ||
export default function(force = false) { | ||
if (supportedOptions && !force) { | ||
export default function optionsSupport() { | ||
if (supportedOptions) { | ||
return supportedOptions; | ||
@@ -9,12 +9,12 @@ } | ||
supportedOptions = { | ||
capture: false, | ||
once: false, | ||
passive: false, | ||
capture: false, | ||
passive: false | ||
}; | ||
if (!window) { | ||
return supportedOptions; | ||
} | ||
const options = { | ||
get capture() { | ||
supportedOptions.capture = true; | ||
return false; | ||
}, | ||
get once() { | ||
@@ -27,6 +27,2 @@ supportedOptions.once = true; | ||
return false; | ||
}, | ||
get capture() { | ||
supportedOptions.capture = true; | ||
return false; | ||
} | ||
@@ -33,0 +29,0 @@ }; |
import optionsArgument from './options-argument'; | ||
export default function(listener) { | ||
if ( | ||
document.readyState === 'interactive' || | ||
document.readyState === 'complete' | ||
) { | ||
setTimeout(() => { | ||
listener(); | ||
}, 0); | ||
export default function ready(listener) { | ||
const state = document.readyState; | ||
if (state === 'complete' || state === 'interactive') { | ||
setTimeout(listener, 0); | ||
return; | ||
@@ -20,8 +16,10 @@ } | ||
}, | ||
optionsArgument({ | ||
capture: true, | ||
once: true, | ||
passive: true | ||
}) | ||
optionsArgument( | ||
{ | ||
capture: true, | ||
once: true, | ||
passive: true | ||
} | ||
) | ||
); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
1
127
7521
19
9
91