var Router = View.extend({ el: "body", events: { "click [data-role='show-signup-modal']": 'signup', "click [data-role='show-signin-modal']": 'signin', "click [data-role='new-project-modal']": 'newProject', "click [data-role='edit-project-modal']": 'editProject', "click [data-role='edit-profile-modal']": 'editProfile', "click [data-role='new-document-modal']": 'newDocument', "click [data-role='edit-document-modal']": 'editDocument', }, routes: { "/login": 'signin', "/signup": 'signup', "/project/new": 'newProject', "/profile/edit": 'editProfile', "/about/:name/edit": 'editDocument', "/about/new": 'newDocument', "/app": 'launch', }, initialize: function(){ this.signUpModal = new SignUpModal() this.signInModal = new SignInModal() this.newProjectModal = new NewProjectModal() this.editProjectModal = new EditProjectModal() this.editProfileModal = new EditProfileModal() this.documentModal = new DocumentModal() this.originalPath = window.location.pathname var path = window.location.pathname.split("/") console.log(path) for (var route in this.routes) { var routePath = route.split("/") if (routePath[1] == path[1]) { if (routePath[2] && routePath[2].indexOf(":") !== -1 && path[2] && (path[3] === routePath[3]) ) { console.log("GOT :") console.log(routePath) this[this.routes[route]](null, path[2]) break; } else if (routePath[2] == path[2]) { this[this.routes[route]](null) break; } else if (! routePath[2] && (! path[2].length || ! path[2])) { this[this.routes[route]](null) break; } } } $("body").removeClass("loading") }, launch: function(){ app.launch() }, signup: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/signup") this.signUpModal.load() }, signin: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/login") this.signInModal.load() }, newProject: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/project/new") this.newProjectModal.load() }, editProject: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/project/edit") this.editProjectModal.load() }, editProfile: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/profile/edit") this.editProfileModal.load() }, newDocument: function(e){ e && e.preventDefault() var name = e ? $(e.currentTarget).data("name") : "new" window.history.pushState(null, document.title, "/about/new") this.documentModal.load(name, true) }, editDocument: function(e, name){ e && e.preventDefault() var name = e ? $(e.currentTarget).data("name") : name window.history.pushState(null, document.title, "/about/" + name + "/edit") this.documentModal.load(name, false) }, })