Created
September 5, 2012 04:58
Trying to learn Marionette
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 (app, $, backbone, marionette, options, undefined) { | |
app = new marionette.Application(); | |
app.addInitializer(function () { | |
app.Log("configuring marionette template compiler"); | |
marionette.TemplateCache.prototype.compileTemplate = function (rawTemplate) { | |
return Hogan.compile(rawTemplate); | |
}; | |
}); | |
app.addInitializer(function () { | |
app.Log("configuring marionette template renderer"); | |
marionette.Renderer = { | |
render: function (template, data) { | |
var templateFunc = typeof template === 'function' ? template : marionette.TemplateCache.get(template); | |
var html = templateFunc.render(data); //hogan rendering | |
return html; | |
} | |
}; | |
}); | |
app.addInitializer(function () { | |
app.Log("precompiling templates"); | |
$("#templates script").each(function (index, value) { | |
var templateSelector = "#" + value.id; | |
marionette.TemplateCache.get(templateSelector); | |
}); | |
}); | |
app.Log = function (msg) { | |
if (options.IsDebug) { | |
if (typeof console !== 'undefined') | |
console.log(msg); | |
} else { | |
//eat the log msg | |
} | |
}; | |
app.addRegions({ | |
MainRegion: "#main-content", | |
TopNavigationRegion: "#top-nav" | |
}); | |
app.Log("Starting App"); | |
app.start(options); | |
app.vent.on("routing:started", function () { | |
if (!backbone.History.started) | |
backbone.history.start({ hashChange: options.SupportsHistoryApi, silent: true }); | |
}); | |
//var regView = new RegisterView(); | |
//app.MainRegion.show(regView); | |
} (window.MyApp = window.MyApp || {}, jQuery, Backbone, Backbone.Marionette, window.ApplicationOptions)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment