Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Moving Events from Module to separate file
(function() {
var Events = {
dropMenu: function(evt) {
alert("Handle the click");
},
events: {
"click .drop-menu": "dropMenu",
},
}
return Events;
})();
define([
"namespace",
// Libs
"use!backbone",
// Plugins
"use!plugins/backbone.layoutmanager",
// Events
"app/events/header.js",
],
function(custom, Backbone, Events) {
var app = custom.app;
// Create a new module
var Main = custom.module();
// Main header view
Main.Views.Header = Backbone.LayoutManager.View.extend({
template: "main/header",
events: Events,
});
Main.Router = Backbone.Router.extend({
initialize: function() {
_.bindAll(this, "index");
},
routes: {
"main": "index",
},
getLayout: function(layoutName) {
if (app[layoutName]) {
return app[layoutName];
}
app[layoutName] = new Backbone.LayoutManager({
template: "main",
className: "main-wrapper"
});
return app[layoutName];
},
index: function() {
var mainLayout = this.getLayout("main");
mainLayout.view("header", new Main.Views.Header());
mainLayout.view("aside", new Main.Views.SideBar());
mainLayout.view("section", new Main.Views.DataTable());
// Render out the layout
mainLayout.render(function(el) {
$("#main").html(el);
});
},
});
// Required, return the module for AMD compliance
return Main;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment