Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 16 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){
return function(e){
if (Sprint(e.target).is(selector)){
handler.apply(e.target, arguments);
}
}
};

var createDOM = function(HTMLString) {
var tmp = document.createElement("div")
Expand Down Expand Up @@ -1126,9 +1134,15 @@ var Sprint;
})
return Sprint(dom)
},
on: function(events, handler) {
on: function(events, selector, handler) {
if(typeof selector !== "string"){
handler = selector;
}
// .on(events, handler)
if (handler) {
if(selector){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be check if selector is a string, because if user do not pass selector it becomes a handler function which evaluates to true ofc :)

handler = createDelegator(handler, selector);
}
var eventsArr = events.trim().split(" ")

return this.each(function() {
Expand Down
37 changes: 2 additions & 35 deletions sprint.min.js

Large diffs are not rendered by default.