zombie.js browser.fire not working with Backbone.Events
The browser.fire method does not seem to trigger event handlers attached through Backbone.Events. (it works fine for other cases such as clicking anchor tags/buttons)
See this gist for a test case on documentClouds site: https://gist.github.com/1256944
If the first thing you do when going to the url is click the 'Open' button you get an alert, but also the 'overlay' class is added to the body element - this is what im checking for.
You can see from the test that when using browser.fire 'click', that the prompt isn't shown, and the overlay class is not seen.
However, when triggering the click event using jQuery's c开发者_如何学运维lick() method (via browser.evaluate), then the overlay class is seen...
In your backbone view, you should add the el property. Specify an element upon which the events should be bound. For example:
dc.ui.Toolbar = Backbone.View.extend({
id : 'toolbar',
el : "body",
events : {
'click #open_viewers' : '_clickOpenViewers',
'click #size_toggle' : '_toggleSize'
},
_clickOpenViewers : function() {
this.openViewers();
},
openViewers : function(checkEdit, suffix, afterLoad) {
if (!Documents.selectedCount) return dc.ui.Dialog.alert('Please select a document to open.');
var continuation = function(docs) {
_.each(docs, function(doc){
var win = doc.openAppropriateVersion(suffix);
if (afterLoad) {
win.DV || (win.DV = {});
win.DV.afterLoad = afterLoad;
}
});
};
checkEdit ? this.edit(continuation) : continuation(Documents.selected());
}
});
精彩评论