bitovi/canjs — pull request #760 by andykant (2014-03-03 22:44:24+00:00)
Title: Added delegate/undelegate fallbacks to bind/unbind and fixed broken Zepto/Dojo delegate implementations

`can.delegate` and `can.undelegate` (in util/LIBRARY/LIBRARY.js) don't implement fallback binding for objects for non-elements and objects that don't explicitly define delegate/undelegate. (#754)

This is an updated pull request based on the **minor** branch instead of **master**. (see #758 for the original pull request)

Additionally, the existing Zepto/Dojo delegate methods completely fail in cases where the `selector === ""`.

This pull request fixes these issues by having `can.delegate/undelegate` fallback to their `can.bind/unbind` counterparts in cases where normal object instances don't implement delegate/undelegate. Also included is the addition of `can/util/event` and `can/control/modifier` tests to the tests run with all libraries in `test/*` as well as adding `test/jquery-2.html` to `test/index.html`.

For example in **util/jquery/jquery.js**:
``` javascript
delegate: function(selector, ev , cb){
if(this.delegate) {
this.delegate(selector, ev , cb)
}
else if(isBindableElement(this)) {
$(this).delegate(selector, ev, cb)
} else {
// make it bind-able ...
}
return this;
},
undelegate: function(selector, ev , cb){
if(this.undelegate) {
this.undelegate(selector, ev , cb)
}
else if(isBindableElement(this)) {
$(this).undelegate(selector, ev, cb)
} else {
// make it bind-able ...

}
return this;
},
```

The problem with this is there are portions of the CanJS codebase that call `.delegate` instead of `.bind`. Specifically, modifier functions like in `can/control/modifier`.
``` javascript
steal("can/construct", "can/control", "can/control/modifier", function(Construct, Control) {
Construct("SomeObject", {
bind: can.bind,
unbind: can.unbind,
dispatch: can.dispatch
});

Control('SomeClass', {
init: function() {
this.options.some_object = new SomeObject();
this.on();
},
"{some_object} some_event:debounce(100)": function() {
// THIS NEVER FIRES
}
});

var control = new SomeClass(document.body);
control.options.some_object.dispatch("some_event");
});
```