Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ The methods supported by Sprint are, for the most part, identical to jQuery's. T
* [off](http://api.jquery.com/off/) - _no support for selector_
* [offset](http://api.jquery.com/offset/)
* [offsetParent](http://api.jquery.com/offsetParent/)
* [on](http://api.jquery.com/on/) - _no support for selector and data_
* [on](http://api.jquery.com/on/) - _no support for data_
* [parent](http://api.jquery.com/parent/)
* [parents](http://api.jquery.com/parents/)
* [position](http://api.jquery.com/position/)
Expand Down
19 changes: 17 additions & 2 deletions sprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ var Sprint;
}
return stringValue
}
}())
}());

var createDelegator = function(handler, selector, context){
return function(e){
if (Sprint(e.target).closest(selector, context).size()){
handler.apply(e.target, arguments);
}
}
};

var createDOM = function(HTMLString) {
var tmp = document.createElement("div")
Expand Down Expand Up @@ -1126,12 +1134,19 @@ var Sprint;
})
return Sprint(dom)
},
on: function(events, handler) {
on: function(events, selector, handler) {
if(typeof selector !== "string"){
handler = selector;
selector = null;
}
// .on(events, handler)
if (handler) {
var eventsArr = events.trim().split(" ")

return this.each(function() {
if(selector){
handler = createDelegator(handler, selector, this);
}
if (!getEvents(this)) {
this.sprintEventListeners = {}
}
Expand Down
36 changes: 1 addition & 35 deletions sprint.min.js

Large diffs are not rendered by default.