-
-
Save redsquare/1671983 to your computer and use it in GitHub Desktop.
Moving Events from Module to separate file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var Events = { | |
dropMenu: function(evt) { | |
alert("Handle the click"); | |
}, | |
events: { | |
"click .drop-menu": "dropMenu", | |
}, | |
} | |
return Events; | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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