Mercurial > hg > dml-open-vis
diff src/DML/MainVisBundle/Resources/assets/marionette/App.90-routing.js @ 0:493bcb69166c
added public content
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 20:54:02 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/DML/MainVisBundle/Resources/assets/marionette/App.90-routing.js Tue Feb 09 20:54:02 2016 +0100 @@ -0,0 +1,49 @@ +"use strict"; + +App.addInitializer(function(options){ + var _this = this; + + var popupsAreInstant = true; + var appRouter = new (Backbone.Router.extend({ + routes: { + "help": "navigateToHelp", + "help/:id": "navigateToHelp", + "": "navigateToDefault", + "*notFound": "notFound", + }, + + navigateToHelp: function(id){ + //App.logger.log("Navigating to help with material id: ", id); + App.HelpModule.show({materialId: id !== null ? id : "", instant: popupsAreInstant}); + }, + + navigateToDefault: function(id){ + //App.logger.log("Navigating to default"); + App.HelpModule.hide(); + }, + + notFound: function(context){ + App.logger.warn("Route not found", context); + } + }))(); + + App.HelpModule.on("show", function(options) { + var urlHash = "help"; + if (options.materialId) { + urlHash += "/" + options.materialId; + } + var needToReplace = Backbone.history.fragment.slice(0, 4) == "help"; + appRouter.navigate(urlHash, {"replace": needToReplace}); + }); + + App.HelpModule.on("hide", function(options) { + appRouter.navigate("/"); + }); + + Backbone.history.start({ + // "pushState": true, + // "root": "/chords" + }); + + popupsAreInstant: false; +});