Skip to content

Commit

Permalink
bugfixes + test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jaz303 committed Jun 27, 2014
1 parent 55b5b5b commit 1ed9463
Show file tree
Hide file tree
Showing 11 changed files with 5,972 additions and 7 deletions.
32 changes: 30 additions & 2 deletions README.md
Expand Up @@ -14,6 +14,8 @@ In the codes:

## API

### Classes

#### `du.hasClass(el, className)`

#### `du.addClass(el, className)`
Expand All @@ -22,7 +24,21 @@ In the codes:

#### `du.toggleClass(el, className)`

#### `du.viewportSize(document)`
### Events

#### `du.bind(el, evtType, cb, [useCapture])`

#### `du.bind_c(el, evtType, cb, [useCapture])`

As above, but returns a cancellation function.

#### `du.delegate(el, evtType, selector, cb, [useCapture])`

#### `du.delegate_c(el, evtType, selector, cb, [useCapture])`

As above, but returns a cancellation function.

#### `du.unbind(el, evtType, cb, [useCapture])`

#### `du.stop(evt)`

Expand All @@ -31,8 +47,20 @@ Shortcut for:
evt.preventDefault();
evt.stopPropagation();

### Layout

#### `du.setPosition(el, x, y)`

#### `du.setSize(el, width, height)`

#### `du.isElement(thing)`
### Matches Selector

#### `du.matchesSelector(selector, el)`

### Node

#### `du.isElement(thing)`

### Viewport

#### `du.viewportSize()`
8 changes: 5 additions & 3 deletions impl/events.js
Expand Up @@ -46,14 +46,16 @@ if (typeof window.addEventListener === 'function') {

function delegate(el, evtType, selector, cb, useCapture) {
return bind(el, evtType, function(evt) {
var currTarget = evt.target || evt.srcElement;
var currTarget = evt.target;
while (currTarget && currTarget !== el) {
if (matchesSelector(selector, currTarget)) {
evt.delegateTarget = currTarget;
cb.call(el, evt);
break;
}
currTarget = currTarget.parentNode;
}
});
}, useCapture);
}

function bind_c(el, evtType, cb, useCapture) {
Expand Down Expand Up @@ -89,5 +91,5 @@ exports.bind = bind;
exports.unbind = unbind;
exports.delegate = delegate;
exports.bind_c = bind_c;
exports.delegate = delegate_c;
exports.delegate_c = delegate_c;
exports.stop = stop;
2 changes: 1 addition & 1 deletion impl/matches_selector.js
Expand Up @@ -7,7 +7,7 @@ var nativeMatch = proto.webkitMatchesSelector
if (nativeMatch) {

exports.matchesSelector = function(selector, el) {
return matchesSelector.call(el, selector);
return nativeMatch.call(el, selector);
}

} else {
Expand Down
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -3,6 +3,9 @@
"main": "index.js",
"version": "0.2.1",
"description": "DOM utility functions",
"scripts": {
"watch-demo-js": "watchify test/main.js -o test/bundle.js"
},
"keywords": [
"dom",
"utility"
Expand All @@ -14,6 +17,7 @@
"url": "https://github.com/jaz303/domutil.git"
},
"devDependencies": {
"uglify-js": "~2.4.14"
"uglify-js": "~2.4.14",
"tape": "~2.13.3"
}
}

0 comments on commit 1ed9463

Please sign in to comment.