Skip to content
Permalink
Browse files

Current to Part 6 of the blog series - http://brianmajewski.com/2015/…

  • Loading branch information...
bmajewski committed Feb 22, 2015
1 parent 82df0f2 commit e55dbc2be4ab5e8ce883ad7e397654e346f5d135
@@ -15,6 +15,12 @@
"tests"
],
"dependencies": {
"requirejs": "~2.1.16"
"requirejs": "~2.1.16",
"backbone": "~1.1.2",
"underscore": "~1.8.1",
"jquery": "~2.1.3",
"handlebars": "~3.0.0",
"requirejs-text": "~2.0.14",
"require-handlebars-plugin": "~0.11.2"
}
}
@@ -1,3 +1,44 @@
define(function (require) {
console.log('require module loading working');

var Router = require('router');
var mediator = require('mediator');

_.extend(Backbone.View.prototype, {
// Handle cleanup of view.
close: function () {
if (this.beforeClose) {
// Perform any cleanup specific to this view.
this.beforeClose();
}

if (this.model) {
// Remove all callbacks for this view's model.
this.model.off(null, null, this);
this.model = null;
}

// Something else might be named 'collection' so also check for the
// existence of `off`
if (this.collection && this.collection.off) {
// Remove all callbacks for this view's collection.
this.collection.off(null, null, this);
this.collection = null;
}

// Remove all delegated events.
this.undelegateEvents();
this.off(null, null, this);

// Remove all markup.
this.$el.empty();
}
});


var router = new Router();
Backbone.history.start({pushState: false});

if (Backbone.history.fragment === '') {
mediator.trigger('router:navigate', {route: 'home', options: {trigger: true}});
}
});
@@ -0,0 +1,10 @@
define(function(require){

'use strict';

var _ = require('underscore');
var Backbone = require('backbone');

return _.extend({}, Backbone.Events);

});
@@ -0,0 +1 @@
<div class="text-center">Relearning Backbone - http://brianmajewski.com</div>
@@ -0,0 +1,12 @@
<header>
<div class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a href="/" class="navbar-brand"><b>relearning backbone</b></a>
</div>
<ul class="nav navbar-nav navbar-right">
[Navigation Elements]
</ul>
</div>
</div>
</header>
@@ -0,0 +1,16 @@
define(function (require) {

'use strict';

var Backbone = require('backbone');
var template = require('hbs!page/headerTemplate');

return Backbone.View.extend({
el: '#header',

render: function(){
this.$el.html(template());
return this;
}
});
});
@@ -0,0 +1,3 @@
<div id="header"></div>
<div id="content" class="container"></div>
<div id="footer">{{> ./footerTemplate}}</div>
@@ -0,0 +1,42 @@
define(function (require) {

'use strict';
var Backbone = require('backbone');
var mediator = require('mediator');
var template = require('hbs!page/pageTemplate');
var HeaderView = require('page/headerView');


return Backbone.View.extend({
el: '#page',

initialize: function () {
this.contentView = null;
this.bindPageEvents();
},

render: function () {
this.$el.html(template());
this.headerView = new HeaderView();
this.headerView.render();
return this;
},

bindPageEvents: function () {
mediator.on('page:displayView', this.displayView, this);
},

displayView: function (view) {
if (this.contentView !== null) {
this.contentView.close();
this.contentView = null;
}

this.contentView = view;
if (this.contentView) {
this.contentView.render();
}
}
});

});
@@ -0,0 +1,38 @@
define(function (require) {

'use strict';
var mediator = require('mediator');
var Backbone = require('backbone');
var PageView = require('page/pageView');


return Backbone.Router.extend({
initialize: function () {
this.pageView = new PageView();
this.pageView.render();
this.bindApplicationEvents();
},

routes: {
'': 'home',
'home': 'home'
},

home: function () {
console.log('routing - home');
require(['welcome/view'], function (View) {
mediator.trigger('page:displayView', new View());
});
},

bindApplicationEvents: function () {
mediator.on('router:navigate', this._navigate, this);
},

_navigate: function (context) {
console.log('routing - trigger to ', context.route);
this.navigate(context.route, context.options);
}
});

});
@@ -0,0 +1,3 @@
<div class="jumbotron">
<h1>WELCOME TO OUR APPLICATION</h1>
</div>
@@ -0,0 +1,14 @@
define(function (require) {

'use strict';
var Backbone = require('backbone');
var template = require('hbs!welcome/template');

return Backbone.View.extend({
el: '#content',
render: function() {
this.$el.html(template());
}
});

});

This file was deleted.

@@ -5,11 +5,10 @@
<meta charset="UTF-8">
<title>Relearning Backbone</title>
<link rel="stylesheet" href="assets/css/bootstrap-lumen.min.css">
<link rel="stylesheet" href="assets/css/styles.css">

<script src="components/requirejs/require.js" data-main="require-main.js"></script>
</head>
<body>
<h3>Relearning Backbone</h3>
<div id="page"></div>
</body>
</html>
@@ -2,7 +2,12 @@ requirejs.config({
baseUrl: "app",

paths: {

"jquery": "../components/jquery/dist/jquery",
"underscore": "../components/underscore/underscore",
"backbone": "../components/backbone/backbone",
"handlebars": "../components/handlebars/handlebars.amd",
"text": "../components/requirejs-text/text",
"hbs": "../components/require-handlebars-plugin/hbs"
}
});

0 comments on commit e55dbc2

Please sign in to comment.
You can’t perform that action at this time.