diff options
| author | yo mama <pepper@scannerjammer.com> | 2014-12-04 19:50:41 -0800 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2014-12-04 19:50:41 -0800 |
| commit | 213f2d5cd258d6ddedd47b169b5e3e2482bc3583 (patch) | |
| tree | f362cc3db1bf2108e03c021ad677e09914808212 | |
| parent | 8fee508e5fbfdf35386ec82a5ec7860df20626d6 (diff) | |
made it make some sense
| -rw-r--r-- | .mobile_test.js.swp | bin | 0 -> 12288 bytes | |||
| -rw-r--r-- | Router.js | 61 | ||||
| -rw-r--r-- | View.js | 2 | ||||
| -rw-r--r-- | _router.js | 234 | ||||
| -rw-r--r-- | app.js | 43 | ||||
| -rw-r--r-- | mobile_test.js | 1 | ||||
| -rw-r--r-- | test.html | 4 |
7 files changed, 344 insertions, 1 deletions
diff --git a/.mobile_test.js.swp b/.mobile_test.js.swp Binary files differnew file mode 100644 index 0000000..f6626ed --- /dev/null +++ b/.mobile_test.js.swp diff --git a/Router.js b/Router.js new file mode 100644 index 0000000..28905b2 --- /dev/null +++ b/Router.js @@ -0,0 +1,61 @@ +var Router = View.extend({ + + route: function(){ + + this.originalPath = window.location.pathname + + var routes = is_mobile ? this.mobileRoutes : this.routes, + pathname = window.location.pathname, + path = pathname.split("/"); + + for (var i = 0; i < path.length; i++) { + if (! path[i].length) { + path[i] = null + } + } + + if (pathname in routes) { + this[this.routes[pathname]](null) + return + } + + if (path[path.length-1] == null) { + path.pop() + } + + for (var route in routes) { + var routePath = route.split("/") + if (routePath[1] == path[1]) { + if (routePath[2] && routePath[2].indexOf(":") !== -1 && path[2] && (path[3] === routePath[3]) ) { + this[this.routes[route]](null, path[2]) + return + } + else if (routePath[2] == path[2]) { + if (routePath[3] && path[3]) { + if (routePath[3].indexOf(":") !== -1) { + this[this.routes[route]](null, path[3]) + return + } + else if (routePath[3] == path[3]) { + this[this.routes[route]](null) + return + } + } + else if (! routePath[3] && ! path[3]) { + this[this.routes[route]](null) + return + } + } + else if (! routePath[2] && (! path[2].length || ! path[2])) { + this[this.routes[route]](null) + return + } + } + } + + if (is_mobile) { + window.location.href = "/" + } + } + +}) @@ -60,7 +60,7 @@ var View = (function($, _){ var eventName = match[1], selector = match[2]; method = _.bind(method, this); eventName += '.delegateEvents' + this._id; - if ((typeof(is_mobile) != undefined) && (selector === 'mouseenter' || selector === 'mouseleave')) { + if ((typeof(is_mobile) != undefined) && is_mobile && (selector === 'mouseenter' || selector === 'mouseleave')) { continue } else if (selector === '') { diff --git a/_router.js b/_router.js new file mode 100644 index 0000000..77d0541 --- /dev/null +++ b/_router.js @@ -0,0 +1,234 @@ + +var SiteRouter = Router.extend({ + el: "body", + + events: { + "click [data-role='show-signup-modal']": 'signup', + "click [data-role='show-signin-modal']": 'signin', + "click [data-role='forgot-password']": 'passwordForgot', + "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', + "click [data-role='destroy-document-modal']": 'destroyDocument', + "click [data-role='show-layouts-modal']": 'layoutPicker', + "click [data-role='show-projects-modal']": 'projectPicker', + }, + + routes: { + "/": 'home', + "/home": 'home', + "/login": 'signin', + "/signin": 'signin', + "/signup": 'signup', + + "/auth/usernameTaken": 'usernameTaken', + "/auth/password": 'passwordReset', + "/auth/forgotPassword": 'passwordForgot', + + "/profile": 'profile', + "/profile/edit": 'editProfile', + "/profile/:name": 'profile', + "/about/:name/edit": 'editDocument', + "/about/new": 'newDocument', + + "/layout": 'layoutPicker', + "/layout/:name": 'layoutEditor', + + "/project": 'projectPicker', + "/project/new": 'newProject', + "/project/new/:layout": 'projectNewWithLayout', + "/project/:name": 'projectViewer', + "/project/:name/edit": 'projectEditor', + "/project/:name/view": 'projectViewer', + }, + + mobileRoutes: { + "/": 'home', + "/home": 'home', + "/login": 'signin', + "/signin": 'signin', + "/signup": 'signup', + "/auth/usernameTaken": 'usernameTaken', + "/auth/password": 'passwordReset', + "/auth/forgotPassword": 'passwordForgot', + + "/profile": 'profile', + "/profile/edit": 'editProfile', + "/profile/:name": 'profile', + + "/project/:name": 'projectViewer', + }, + + initialize: function(){ +// this.signUpModal = new SignUpModal() +// this.signInModal = new SignInModal() +// this.layoutsModal = new LayoutsModal() +// this.projectsModal = new ProjectsModal() +// this.newProjectModal = new NewProjectModal() +// this.editProjectModal = new EditProjectModal() +// this.editProfileModal = new EditProfileModal() +// this.passwordForgotModal = new PasswordForgot() +// this.documentModal = new DocumentModal() +// this.profileView = new ProfileView() + + this.route() + + if (is_mobile) { + // $(".topLinks").hide() + // $(".share").hide() + $('.projectItem').each(function(){ + this.href = this.href.replace(/\/edit$/, "") + }) + } + + $("body").removeClass("loading") + }, + + layoutEditor: function(e, name){ + app.mode.builder = true + app.launch() + if (app.unsupported) return + +// this.builderView = app.controller = new BuilderView() +// this.builderView.load(name) + }, + + layoutPicker: function(e){ + e && e.preventDefault() + window.history.pushState(null, document.title, "/layout") + this.layoutsModal.load() + }, + + projectPicker: function(e){ + e && e.preventDefault() + window.history.pushState(null, document.title, "/project") + this.projectsModal.load() + }, + + newProject: function(e){ + e && e.preventDefault() + window.history.pushState(null, document.title, "/project/new") + this.newProjectModal.load() + }, + + projectNewWithLayout: function(e, layout){ + e && e.preventDefault() + + app.mode.editor = true + app.launch() + if (app.unsupported) return + + layout = slugify(layout) + + window.history.pushState(null, document.title, "/project/new/" + layout) +// this.editorView = app.controller = new EditorView() +// this.editorView.loadLayout(layout) + }, + + project: function(e, name){ + if ($(".aboutRoom").length) { + this.projectViewer(e, name) + } + else { + this.projectEditor(e, name) + } + }, + + projectEditor: function(e, name){ + app.mode.editor = true + app.launch() + if (app.unsupported) return + + this.editorView = app.controller = new EditorView() + this.editorView.load(name) + }, + + projectViewer: function(e, name){ + app.mode.editor = true + app.launch() + if (app.unsupported) return + + this.readerView = app.controller = new ReaderView() + this.readerView.load(name) + }, + + 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() + }, + + usernameTaken: function(e){ + this.usernameTakenModal = new UsernameTaken () + this.usernameTakenModal.load() + }, + passwordForgot: function(e){ + e && e.preventDefault() + window.history.pushState(null, document.title, "/auth/forgotPassword") + this.passwordForgotModal.load() + }, + passwordReset: function(e){ + this.passwordResetModal = new PasswordReset () + this.passwordResetModal.load() + }, + + + home: function(){ + this.homeView = new HomeView () + this.homeView.load() + }, + + profile: function(e){ + this.profileView.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) + }, + + destroyDocument: function(e, name){ + e && e.preventDefault() + + var name = e ? $(e.currentTarget).data("name") : name + + ConfirmModal.confirm("Are you sure you want to delete " + name + "?", function(){ + this.documentModal.destroy(name, function(){ + AlertModal.alert("Document deleted!", function(){ + window.location.href = "/about" + }.bind(this)) + }.bind(this)) + }.bind(this)) + + // this.documentModal.destroy(name) + }, + +}) + @@ -0,0 +1,43 @@ + +if (is_mobile) { + $("html").addClass("mobile") +} +else { + $("html").addClass("desktop") +} + +var app = new function(){} + +app.mode = { editor: false, builder: false } + +app.init = function () { + app.router = new SiteRouter () +} + +app.launch = function () { + + var loader = new Loader(function(){ + $("#loader").hide() + window.environment && window.environment.init() + // window.editor && window.editor.init() + // window.path && window.path.init() + animate() + }) + + // loader.preloadImages([]) + loader.ready() + + window.scrollTo(0,0) +} + +app.fallback = function(){ + app.unsupported = true + var msg = "Sorry, your browser is not supported.<br><br>" + + "Please use <a href='http://chrome.com/'>Chrome</a> or <a href='https://www.apple.com/safari/'>Safari</a> or <a href='http://getfirefox.com/'>Firefox</a>." + var $fallback = $("<div>") + $fallback.attr('id', 'fallback') + $fallback.html(msg) + $('body').append($fallback) +} + +document.addEventListener('DOMContentLoaded', app.init) diff --git a/mobile_test.js b/mobile_test.js new file mode 100644 index 0000000..ddb59fc --- /dev/null +++ b/mobile_test.js @@ -0,0 +1 @@ +var is_mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? true: false; @@ -47,9 +47,13 @@ <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="underscore.js"></script> +<script type="text/javascript" src="mobile_test.js" ></script> <script type="text/javascript" src="loader.js" ></script> <script type="text/javascript" src="minotaur.js" ></script> <script type="text/javascript" src="View.js" ></script> +<script type="text/javascript" src="Router.js" ></script> +<script type="text/javascript" src="_router.js" ></script> +<script type="text/javascript" src="app.js" ></script> <script type="text/javascript" src="ModalView.js" ></script> <script type="text/javascript" src="FormView.js" ></script> <script type="text/javascript" src="AlertModal.js" ></script> |
