diff options
Diffstat (limited to 'public/assets')
| -rw-r--r-- | public/assets/javascripts/app.js | 17 | ||||
| -rw-r--r-- | public/assets/javascripts/mx/extensions/mx.movementsMobile.js | 56 | ||||
| -rw-r--r-- | public/assets/javascripts/rectangles/models/rect.js | 4 | ||||
| -rw-r--r-- | public/assets/javascripts/rectangles/models/vec2.js | 3 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/_router.js | 22 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/editor/EditorSettings.js | 2 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/lib/Router.js | 21 |
7 files changed, 99 insertions, 26 deletions
diff --git a/public/assets/javascripts/app.js b/public/assets/javascripts/app.js index 1419d1d..ad3c601 100644 --- a/public/assets/javascripts/app.js +++ b/public/assets/javascripts/app.js @@ -27,11 +27,7 @@ app.init = function () { } app.launch = function () { - var mainbox, - coords, - box, size, - floor, - movements + var movements scene = new MX.Scene().addTo('#scene') scene.width = window.innerWidth @@ -50,14 +46,19 @@ app.launch = function () { if (MX.Map) map = app.map = new MX.Map() - movements = app.movements = new MX.Movements(cam, viewHeight) - movements.init() + if (is_mobile) { + app.movements = new MX.MobileMovements(cam, viewHeight) + } + else { + app.movements = new MX.Movements(cam, viewHeight) + } + app.movements.init() function animate (t) { requestAnimationFrame(animate) environment.update(t) window.path && path.update(t) - movements.update() + app.movements.update() scene.update() } diff --git a/public/assets/javascripts/mx/extensions/mx.movementsMobile.js b/public/assets/javascripts/mx/extensions/mx.movementsMobile.js new file mode 100644 index 0000000..7e1cc92 --- /dev/null +++ b/public/assets/javascripts/mx/extensions/mx.movementsMobile.js @@ -0,0 +1,56 @@ + +MX.MobileMovements = function (cam) { + + var touching = true, + moving = false, + v = 12, + vr = Math.PI * 0.012, + jumpV = 23, + vx = vy = vz = 0, + creepFactor = 0.3 + + var DEFAULT_SCALE = 1.0, scale = DEFAULT_SCALE + + var pos = { x: 0, y: 0, z: 0, rotationX: 0, rotationY: 0 } + + var mouse = new Rect( 0,0,0,0 ) + + return { + + init: function () { + document.addEventListener("touchstart", function(e){ + if (e.touches.length == 1) { + touching = true + mouse.x.a = mouse.x.b = event.touches[ 0 ].pageX + mouse.y.a = mouse.y.b = event.touches[ 0 ].pageY + } + }) + document.addEventListener("touchmove", function(e){ + if (e.touches.length == 1) { + + } + }) + document.addEventListener("touchend", function(e){ + if (e.touches.length == 0) { + touching = false + mouse.zero() + } + }) + }, + + update: function () { + if (moving) { + app.tube("move", pos) + } + }, + + lock: function(){ locked = true }, + unlock: function(){ locked = false }, + scale: function(n){ if (n) scale = n; return scale }, + resetScale: function(n){ scale = DEFAULT_SCALE }, + gravity: function(g){ return typeof g == "boolean" ? gravity = g : gravity }, + velocity: function(n){ v = clamp(n, 1, 50) }, + jumpVelocity: function(n){ jumpV = clamp(n, 1, 50) }, + } + +} diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js index 590440a..58469bc 100644 --- a/public/assets/javascripts/rectangles/models/rect.js +++ b/public/assets/javascripts/rectangles/models/rect.js @@ -107,6 +107,10 @@ Rect.prototype.eq = function(r){ return this.x.eq(r.x) && this.y.eq(r.y) } + Rect.prototype.zero = function(){ + this.a.zero() + this.b.zero() + } Rect.prototype.nearEdge = function (x, y, r) { var edges = 0 if (x < this.x.a+r) { diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index 2bf286b..104c6f7 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -55,6 +55,9 @@ this.b /= n return this } + vec2.prototype.zero = function(){ + this.a = this.b = 0 + } vec2.prototype.setPosition = function(n){ var len = this.length() this.a = n diff --git a/public/assets/javascripts/ui/_router.js b/public/assets/javascripts/ui/_router.js index 4ff3581..d07810e 100644 --- a/public/assets/javascripts/ui/_router.js +++ b/public/assets/javascripts/ui/_router.js @@ -36,11 +36,18 @@ var SiteRouter = Router.extend({ "/project": 'projectPicker', "/project/new": 'newProject', "/project/new/:layout": 'projectNewWithLayout', - "/project/:name": 'project', + "/project/:name": 'projectViewer', + "/project/:name/edit": 'projectEditor', "/project/:name/view": 'projectViewer', "/test/wallpaper": 'testWallpaper', }, + + mobileRoutes: { + "/": 'home', + "/profile": 'profile', + "/project/:name": 'projectViewer', + }, initialize: function(){ this.signUpModal = new SignUpModal() @@ -56,6 +63,11 @@ var SiteRouter = Router.extend({ this.route() + if (is_mobile) { + $(".topLinks").hide() + $(".share").hide() + } + $("body").removeClass("loading") }, @@ -123,14 +135,6 @@ var SiteRouter = Router.extend({ this.readerView.load(name) }, -/* - editProject: function(e){ - e && e.preventDefault() - window.history.pushState(null, document.title, "/project/edit") - this.editProjectModal.load() - }, -*/ - signup: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/signup") diff --git a/public/assets/javascripts/ui/editor/EditorSettings.js b/public/assets/javascripts/ui/editor/EditorSettings.js index 13a6f60..d6a79fb 100644 --- a/public/assets/javascripts/ui/editor/EditorSettings.js +++ b/public/assets/javascripts/ui/editor/EditorSettings.js @@ -130,7 +130,7 @@ var EditorSettings = FormView.extend({ this.$name.val(data.name) this.action = this.updateAction - window.history.pushState(null, document.title, "/project/" + data.slug) + window.history.pushState(null, document.title, "/project/" + data.slug + "/edit") }, }) diff --git a/public/assets/javascripts/ui/lib/Router.js b/public/assets/javascripts/ui/lib/Router.js index 5877f93..0b6385c 100644 --- a/public/assets/javascripts/ui/lib/Router.js +++ b/public/assets/javascripts/ui/lib/Router.js @@ -4,7 +4,8 @@ var Router = View.extend({ this.originalPath = window.location.pathname - var pathname = 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++) { @@ -13,7 +14,7 @@ var Router = View.extend({ } } - if (pathname in this.routes) { + if (pathname in routes) { this[this.routes[pathname]](null) } @@ -21,35 +22,39 @@ var Router = View.extend({ path.pop() } - for (var route in this.routes) { + 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]) - break; + return } else if (routePath[2] == path[2]) { if (routePath[3] && path[3]) { if (routePath[3].indexOf(":") !== -1) { this[this.routes[route]](null, path[3]) - break; + return } else if (routePath[3] == path[3]) { this[this.routes[route]](null) - break; + return } } else if (! routePath[3] && ! path[3]) { this[this.routes[route]](null) - break; + return } } else if (! routePath[2] && (! path[2].length || ! path[2])) { this[this.routes[route]](null) - break; + return } } } + + if (is_mobile) { + window.location.href = "/" + } } }) |
