Skip to content

Commit

Permalink
Merge pull request #112 from tbranyen/router
Browse files Browse the repository at this point in the history
reworked router out into separate file
  • Loading branch information
tbranyen committed Jun 20, 2012
2 parents 84c0989 + 029c435 commit 29ba2c9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 34 deletions.
6 changes: 4 additions & 2 deletions app/app.js
@@ -1,11 +1,12 @@
define([
// Libs
// Libraries.
"jquery",
"lodash",
"backbone"
],

function($, _, Backbone) {

// Localize or create a new JavaScript Template object.
var JST = window.JST = window.JST || {};

Expand Down Expand Up @@ -42,11 +43,12 @@ function($, _, Backbone) {
return JST[path];
},

// Create a custom object with a nested Views object
// Create a custom object with a nested Views object.
module: function(additionalProps) {
return _.extend({ Views: {} }, additionalProps);
}

// Mix Backbone.Events into the app object.
}, Backbone.Events);

});
9 changes: 6 additions & 3 deletions app/config.js
@@ -1,23 +1,26 @@
// Set the require.js configuration for your application.
require.config({
// Initialize the application with the main application file

// Initialize the application with the main application file.
deps: ["main"],

paths: {
// JavaScript folders
// JavaScript folders.
libs: "../assets/js/libs",
plugins: "../assets/js/plugins",

// Libraries
// Libraries.
jquery: "../assets/js/libs/jquery",
lodash: "../assets/js/libs/lodash",
backbone: "../assets/js/libs/backbone"
},

shim: {
// Backbone library depends on lodash and jQuery.
backbone: {
deps: ["lodash", "jquery"],
exports: "Backbone"
}
}

});
35 changes: 9 additions & 26 deletions app/main.js
@@ -1,36 +1,19 @@
require([
// Global
// Application.
"app",

// Libs
"jquery",
"backbone"
// Main Router.
"router"
],

function(app, $, Backbone) {
function(app, Router) {

// Defining the application router, you can attach sub routers here.
var Router = Backbone.Router.extend({
routes: {
"": "index"
},
// Define your master router on the application namespace and trigger all
// navigation from this instance.
app.router = new Router();

index: function() {

}
});

// Treat the jQuery ready function as the entry point to the application.
// Inside this function, kick-off all initialization, everything up to this
// point should be definitions.
$(function() {
// Define your master router on the application namespace and trigger all
// navigation from this instance.
app.router = new Router();

// Trigger the initial route and enable HTML5 History API support
Backbone.history.start({ pushState: true });
});
// Trigger the initial route and enable HTML5 History API support.
Backbone.history.start({ pushState: true });

// All navigation that is relative should be passed through the navigate
// method, to be processed by the router. If the link has a `data-bypass`
Expand Down
21 changes: 21 additions & 0 deletions app/router.js
@@ -0,0 +1,21 @@
define([
// Application.
"app"
],

function(app) {

// Defining the application router, you can attach sub routers here.
var Router = Backbone.Router.extend({
routes: {
"": "index"
},

index: function() {

}
});

return Router;

});
6 changes: 3 additions & 3 deletions index.html
Expand Up @@ -7,15 +7,15 @@

<title>Backbone Boilerplate</title>

<!-- Application styles -->
<!-- Application styles. -->
<link rel="stylesheet" href="/assets/css/index.css">
</head>

<body>
<!-- Main container -->
<!-- Main container. -->
<div role="main" id="main"></div>

<!-- Application source -->
<!-- Application source. -->
<script data-main="/app/config" src="/assets/js/libs/require.js"></script>
</body>
</html>

0 comments on commit 29ba2c9

Please sign in to comment.