summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.mobile_test.js.swpbin0 -> 12288 bytes
-rw-r--r--Router.js61
-rw-r--r--View.js2
-rw-r--r--_router.js234
-rw-r--r--app.js43
-rw-r--r--mobile_test.js1
-rw-r--r--test.html4
7 files changed, 344 insertions, 1 deletions
diff --git a/.mobile_test.js.swp b/.mobile_test.js.swp
new file mode 100644
index 0000000..f6626ed
--- /dev/null
+++ b/.mobile_test.js.swp
Binary files differ
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 = "/"
+ }
+ }
+
+})
diff --git a/View.js b/View.js
index 8c6cb1e..f411986 100644
--- a/View.js
+++ b/View.js
@@ -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)
+ },
+
+})
+
diff --git a/app.js b/app.js
new file mode 100644
index 0000000..1cd2ba7
--- /dev/null
+++ b/app.js
@@ -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;
diff --git a/test.html b/test.html
index c0cfd4c..e30678e 100644
--- a/test.html
+++ b/test.html
@@ -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>