Skip to content

Commit

Permalink
Remove redundant or unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Oct 21, 2019
1 parent 15f3f7b commit e8c70e8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ Selection.utils

* on(el`:HTMLElement`, event`:String`, fn`:Function`[, options `:Object`]) _- Attach an event handler function._
* off(el`:HTMLElement`, event`:String`, fn`:Function`[, options `:Object`]) _- Remove an event handler._
* css(el`:HTMLElement`)`:Object` _- Get all css properties from this element._
* css(el`:HTMLElement`, attr`:String`)`:Mixed` _- Get the value from a style property._
* css(el`:HTMLElement`, attr`:String`, val`:String`) _- Set a specific style property._
* css(el`:HTMLElement`, attr`:Object`) _- Set multiple style properties._
* intersects(ela`:HTMLElement`, elb`:HTMLElement`)`:Boolean` _- Check if an HTMLElement intersects another._
Expand Down
2 changes: 1 addition & 1 deletion dist/selection.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/selection.min.js.map

Large diffs are not rendered by default.

41 changes: 19 additions & 22 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,16 @@ const unitify = (val, unit = 'px') => typeof val === 'number' ? val + unit : val
*/
export function css(el, attr, val) {
const style = el && el.style;
if (!style) return;
if (style) {
if (typeof attr === 'object') {

if (typeof attr === 'object') {
for (const [key, value] of Object.entries(attr)) {
style[key] = unitify(value);
}

for (const prop in attr) {
style[prop] = unitify(attr[prop]);
} else if (val && typeof attr === 'string') {
style[attr] = unitify(val);
}

} else if (val === null) {

const dw = document.defaultView;
if (dw && dw.getComputedStyle) {
val = dw.getComputedStyle(el, null);
} else if (el.currentStyle) {
val = el.currentStyle;
}

return attr === null ? val : val[attr];
} else {
style[attr] = unitify(val);
}
}

Expand Down Expand Up @@ -141,11 +131,15 @@ export function selectAll(selector) {
*/
export function eventPath(evt) {
let path = evt.path || (evt.composedPath && evt.composedPath());
if (path) return path;

let el = evt.target.parentElement;
path = [evt.target, el];
while (el = el.parentElement) path.push(el);
if (path) {
return path;
}

let el = evt.target;
for (path = [el]; (el = el.parentElement);) {
path.push(el);
}

path.push(document, window);
return path;
Expand All @@ -156,7 +150,10 @@ export function eventPath(evt) {
*/
export function removeElement(arr, el) {
const index = arr.indexOf(el);
if (~index) arr.splice(index, 1);

if (~index) {
arr.splice(index, 1);
}
}

export function simplifyEvent(evt) {
Expand Down

0 comments on commit e8c70e8

Please sign in to comment.