Created
August 15, 2014 02:39
-
-
Save JoshBarr/ee3b634cf220fdf86a7f to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Replace default renderer with nunjucks | |
* http://mozilla.github.io/nunjucks/ | |
* | |
* @param template | |
* @param data | |
* @returns {string} HTML | |
*/ | |
Backbone.Marionette.Renderer.render = function(template, data){ | |
return nunjucks.render(template, data); | |
}; | |
/** | |
* Force repaint for triggering CSS animations | |
* @returns {number} | |
*/ | |
window.repaint = function() { | |
return document.body.offsetLeft; | |
}; | |
(function(document, window) { | |
var App, $doc, app; | |
var Router = Marionette.AppRouter.extend({ | |
appRoutes: { | |
"": "index", | |
"region/:id": "region", | |
"region/:id/:detail": "detail" | |
} | |
}); | |
var Controller = Marionette.Controller.extend({ | |
initialize: function(options){ | |
this.app = options.app; | |
}, | |
index: function() { | |
}, | |
region: function(regionId) { | |
}, | |
road: function(detailId) { | |
} | |
}); | |
var View = Backbone.Marionette.ItemView.extend({ | |
template: "main.j2", | |
onShow: function() { | |
if (this.options.snapToTop) { | |
$(window).scrollTop(0); | |
} | |
this.el.classList.add("anim-reveal"); | |
} | |
}); | |
var Layout = Marionette.LayoutView.extend({ | |
onShow: function() { | |
this.$el.addClass("anim-reveal"); | |
} | |
}); | |
App = Backbone.Marionette.Application.extend({ | |
beforeStart: function() { | |
this.addRegions({ | |
main: "[data-region='main']", | |
modals: "[data-region='modals']" | |
}); | |
}, | |
afterStart: function() { | |
var app = this; | |
this.router = new Router({ controller: new Controller({ app: app }) }); | |
if (Backbone.history) { | |
Backbone.history.start({ pushState: true, root: '/traffic/' }); | |
if (window.backbonePath) { | |
Backbone.history.navigate(window.backbonePath, { trigger: true }); | |
} | |
} | |
} | |
}); | |
$doc = $(document); | |
app = new App(); | |
app.addInitializer(app.beforeStart); | |
app.on("start", app.afterStart); | |
// Handle actual booting | |
$doc.ready( function appInit() { | |
var el = document.querySelector("[data-app]"); | |
if (el) { | |
app.start(); | |
} | |
}); | |
window.Traffic = app; | |
})(document, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment