Skip to content

Instantly share code, notes, and snippets.

@redsquare
Forked from tvpmb/header.js
Created January 24, 2012 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redsquare/1671983 to your computer and use it in GitHub Desktop.
Save redsquare/1671983 to your computer and use it in GitHub Desktop.
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