Skip to content

Instantly share code, notes, and snippets.

@tvpmb
Created January 24, 2012 21:06
Show Gist options
  • Save tvpmb/1672702 to your computer and use it in GitHub Desktop.
Save tvpmb/1672702 to your computer and use it in GitHub Desktop.
Separating Events/Event-Methods from the View (partial code, 2 examples, one is commented out)
//events
define([
"namespace",
// Libs
"use!backbone",
// Plugins
"use!plugins/backbone.layoutmanager",
],
function(custom, Backbone) {
var Events = function(obj){
obj.events = {
"click .drop-menu": "dropMenu",
};
obj.dropMenu = function(evt) {
alert("Handle the click");
};
}
return Events;
/*
return {
events: {
"click .drop-menu": "dropMenu",
},
dropMenu: function(evt) {
alert("Handle the click");
},
}
*/
});
define([
"namespace",
// Libs
"use!backbone",
// Events
"events/header",
// Plugins
"use!plugins/backbone.layoutmanager",
],
function(namespace, Backbone, Events) {
var app = namespace.app;
// Create a new module
var Main = namespace.module();
// Main header view
/*
Main.Views.Header = Backbone.LayoutManager.View.extend({
template: "main/header",
initialize: function() {
//console.log(Events);
this.dropMenu = Events.dropMenu;
this.events = Events.events;
}
});
*/
Main.Views.Header = Backbone.LayoutManager.View.extend({
template: "main/header",
initialize: function() {
new Events(this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment