var eventObject = {};
_.extend(eventObject, Backbone.Events);
//http://jsfiddle.net/vBh47/8/
(function (codes, eventObject, code, evt) {
document.addEventListener && // Modern browsers only
document.addEventListener("keydown", function (e) {
code = codes[e.keyCode];
if (e.ctrlKey || e.metaKey && code) {
if(code)
{
eventObject.trigger(code);
console.log("sends");
}
}
}, false);
}({37: "prev", 39: "next"}, eventObject));
var View = Backbone.View.extend({
initialize : function (options) {
this.eventObject = options.eventObject;
this.eventObject.on("next", this.nextPage, this);
this.eventObject.on("prev", this.prevPage, this);
},
prevPage : function(){
alert("ctrl+left");
},
nextPage : function(){
alert("ctrl+right");
},
render : function() {
$(this.el).html(this.template());
return this;
}
});
var view = new View({ eventObject : eventObject });
view.render();
//demo: http://jincod.tumblr.com/hotkeys