From 43af2bebd1de70f0e2f5627815812dbfd01a5c9a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 5 Aug 2014 15:30:07 -0400 Subject: cutting out stuff for mobile --- .../mx/extensions/mx.movementsMobile.js | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 public/assets/javascripts/mx/extensions/mx.movementsMobile.js (limited to 'public/assets/javascripts/mx') 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) }, + } + +} -- cgit v1.2.3-70-g09d2 From bac4d6a8c8566814e851452bedf5fa7ce596d54d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 5 Aug 2014 17:56:38 -0400 Subject: very basic mobile ui --- .../mx/extensions/mx.movementsMobile.js | 92 +++++++++++++++++++--- public/assets/javascripts/util.js | 2 +- 2 files changed, 81 insertions(+), 13 deletions(-) (limited to 'public/assets/javascripts/mx') diff --git a/public/assets/javascripts/mx/extensions/mx.movementsMobile.js b/public/assets/javascripts/mx/extensions/mx.movementsMobile.js index 7e1cc92..994c8d7 100644 --- a/public/assets/javascripts/mx/extensions/mx.movementsMobile.js +++ b/public/assets/javascripts/mx/extensions/mx.movementsMobile.js @@ -3,43 +3,83 @@ MX.MobileMovements = function (cam) { var touching = true, moving = false, + startTime = null, v = 12, vr = Math.PI * 0.012, - jumpV = 23, - vx = vy = vz = 0, - creepFactor = 0.3 + vx = vy = vz = 0; - var DEFAULT_SCALE = 1.0, scale = DEFAULT_SCALE - - var pos = { x: 0, y: 0, z: 0, rotationX: 0, rotationY: 0 } + var directionLocked = false, + directionLockThreshold = 5 - var mouse = new Rect( 0,0,0,0 ) + var pos = { x: 0, y: viewHeight, z: 0, rotationX: 0, rotationY: 0 } + var pointX, pointY, deltaX, deltaY, distX = 0, distY = 0, absDistX = 0, absDistY = 0, startTime + 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 + + startTime = Date.now() + + var point = event.touches[0] + pointX = point.pageX + pointY = point.pageY + distX = distY = 0 + pos.x = cam.x + pos.z = cam.z + pos.rotationY = cam.rotationY } }) document.addEventListener("touchmove", function(e){ + e.preventDefault() if (e.touches.length == 1) { + + var timestamp = Date.now() + var point = event.touches[0] + deltaX = point.pageX - pointX + deltaY = point.pageY - pointY + pointX = point.pageX + pointY = point.pageY + + distX += deltaX + distY += deltaY + absDistX = abs(distX) + absDistY = abs(distY) } }) document.addEventListener("touchend", function(e){ + e.preventDefault() if (e.touches.length == 0) { - touching = false - mouse.zero() + touching = directionLocked = false + var timestamp = Date.now() + var duration = startTime - timestamp + if (duration < 300) { + } } }) }, update: function () { - if (moving) { + if (distX || distY) { + var oldDistY = absDistY, oldDistX = absDistX + absDistY = avg(absDistY, 0, 5) + var dy = (oldDistY - absDistY) * sign(distY) * 2 + + absDistX = avg(absDistX, 0, 5) + var dx = (oldDistX - absDistX) * sign(distX) * 2 + + distY = sign(distY) * absDistY + distX = sign(distX) * absDistX + + pos.x -= dy * Math.cos(pos.rotationY + Math.PI / 2) + pos.z -= dy * Math.sin(pos.rotationY + Math.PI / 2) + pos.rotationY += dx / (window.innerWidth) * Math.PI / 2 + cam.rotationY = pos.rotationY + app.tube("move", pos) } }, @@ -54,3 +94,31 @@ MX.MobileMovements = function (cam) { } } + + +// function momentum (current, start, time, lowerMargin, wrapperSize, deceleration) { +// var distance = current - start, +// speed = Math.abs(distance) / time, +// destination, +// duration; +// +// deceleration = deceleration === undefined ? 0.0006 : deceleration; +// +// destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 ); +// duration = speed / deceleration; +// +// if ( destination < lowerMargin ) { +// destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin; +// distance = Math.abs(destination - current); +// duration = distance / speed; +// } else if ( destination > 0 ) { +// destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0; +// distance = Math.abs(current) + destination; +// duration = distance / speed; +// } +// +// return { +// destination: Math.round(destination), +// duration: duration +// }; +// } diff --git a/public/assets/javascripts/util.js b/public/assets/javascripts/util.js index 58dcc3a..b92dcf3 100644 --- a/public/assets/javascripts/util.js +++ b/public/assets/javascripts/util.js @@ -31,7 +31,7 @@ function quantize(n,a){ return round(n / a) * a } function max(a,b){ return Math.max(a,b) } function min(a,b){ return Math.min(a,b) } function abs(n){ return Math.abs(n) } -function sign(n){ return Math.abs(n)/n } +function sign(n){ return n ? Math.abs(n)/n : 0 } function pow(n,b) { return Math.pow(n,b) } function exp(n) { return Math.exp(n) } function log(n){ return Math.log(n) } -- cgit v1.2.3-70-g09d2 From 0bf50fee4d35467c5335cbaf6c1ca3b7ae2dd1e4 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 12 Aug 2014 16:01:42 -0400 Subject: different ui on map editor --- public/assets/img/destroy-cursor.png | Bin 0 -> 1082 bytes .../assets/javascripts/mx/primitives/mx.image.js | 1 + .../assets/javascripts/mx/primitives/mx.video.js | 1 + .../assets/javascripts/mx/primitives/mx.vimeo.js | 1 + .../assets/javascripts/mx/primitives/mx.youtube.js | 1 + .../javascripts/rectangles/engine/map/draw.js | 4 +- .../javascripts/rectangles/engine/map/ui_editor.js | 46 ++++++++++++++++++--- .../javascripts/rectangles/util/constants.js | 6 +++ .../javascripts/rectangles/util/permissions.js | 12 ++++++ .../javascripts/ui/builder/BuilderToolbar.js | 12 +++--- public/assets/stylesheets/app.css | 40 ++++++++++++++---- views/controls/builder/toolbar.ejs | 2 + 12 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 public/assets/img/destroy-cursor.png (limited to 'public/assets/javascripts/mx') diff --git a/public/assets/img/destroy-cursor.png b/public/assets/img/destroy-cursor.png new file mode 100644 index 0000000..eebe3cd Binary files /dev/null and b/public/assets/img/destroy-cursor.png differ diff --git a/public/assets/javascripts/mx/primitives/mx.image.js b/public/assets/javascripts/mx/primitives/mx.image.js index 278fa1e..a640620 100644 --- a/public/assets/javascripts/mx/primitives/mx.image.js +++ b/public/assets/javascripts/mx/primitives/mx.image.js @@ -14,6 +14,7 @@ MX.Image = MX.Object3D.extend({ ops.className && this.el.classList.add(ops.className) this.backface && this.el.classList.add("backface-visible") this.el.classList.add("image") + this.el.classList.add("mx-scenery") this.el.style.backgroundRepeat = 'no-repeat' diff --git a/public/assets/javascripts/mx/primitives/mx.video.js b/public/assets/javascripts/mx/primitives/mx.video.js index cdb92c8..7c0cd33 100644 --- a/public/assets/javascripts/mx/primitives/mx.video.js +++ b/public/assets/javascripts/mx/primitives/mx.video.js @@ -19,6 +19,7 @@ MX.Video = MX.Object3D.extend({ ops.className && this.el.classList.add(ops.className) this.backface && this.el.classList.add("backface-visible") this.el.classList.add("video") + this.el.classList.add("mx-scenery") this.paused = !! this.media.autoplay this.muted = app.muted || !! this.media.mute diff --git a/public/assets/javascripts/mx/primitives/mx.vimeo.js b/public/assets/javascripts/mx/primitives/mx.vimeo.js index 64d9103..5b22821 100644 --- a/public/assets/javascripts/mx/primitives/mx.vimeo.js +++ b/public/assets/javascripts/mx/primitives/mx.vimeo.js @@ -19,6 +19,7 @@ MX.Vimeo = MX.Object3D.extend({ ops.className && this.el.classList.add(ops.className) this.backface && this.el.classList.add("backface-visible") this.el.classList.add("video") + this.el.classList.add("mx-scenery") this.paused = !! this.media.autoplay this.muted = app.muted || !! this.media.mute this.started = false diff --git a/public/assets/javascripts/mx/primitives/mx.youtube.js b/public/assets/javascripts/mx/primitives/mx.youtube.js index f7f00aa..7846649 100644 --- a/public/assets/javascripts/mx/primitives/mx.youtube.js +++ b/public/assets/javascripts/mx/primitives/mx.youtube.js @@ -19,6 +19,7 @@ MX.Youtube = MX.Object3D.extend({ ops.className && this.el.classList.add(ops.className) this.backface && this.el.classList.add("backface-visible") this.el.classList.add("video") + this.el.classList.add("mx-scenery") this.paused = !! this.media.autoplay this.muted = app.muted || !! this.media.mute diff --git a/public/assets/javascripts/rectangles/engine/map/draw.js b/public/assets/javascripts/rectangles/engine/map/draw.js index 8e1fe5a..3e185d2 100644 --- a/public/assets/javascripts/rectangles/engine/map/draw.js +++ b/public/assets/javascripts/rectangles/engine/map/draw.js @@ -29,7 +29,7 @@ Map.Draw = function(map, opt){ ctx.translate( map.center.a, map.center.b ) ctx.scale( -1, 1 ) - draw.regions(Rooms.regions, colors) + draw.regions(Rooms.regions, [ "#f8f8f8" ]) draw.mouse(map.ui.mouse.cursor) draw.coords() scene && draw.camera(scene.camera) @@ -55,7 +55,7 @@ Map.Draw = function(map, opt){ } draw.clear = function(){ - ctx.fillStyle = "rgba(255,255,255,0.9)" + ctx.fillStyle = "rgba(255,255,255,0.98)" ctx.clearRect(0, 0, map.dimensions.a, map.dimensions.b) ctx.fillRect(0, 0, map.dimensions.a, map.dimensions.b) } diff --git a/public/assets/javascripts/rectangles/engine/map/ui_editor.js b/public/assets/javascripts/rectangles/engine/map/ui_editor.js index 577ea32..016a8ad 100644 --- a/public/assets/javascripts/rectangles/engine/map/ui_editor.js +++ b/public/assets/javascripts/rectangles/engine/map/ui_editor.js @@ -56,18 +56,15 @@ Map.UI.Editor = function(map){ app.tube("builder-destroy-room", intersects[0]) return } - else if (intersects.length && (base.permissions.move || base.permissions.resize)) { + else if (intersects.length) { base.dragging = intersects[0] - base.resizing = base.permissions.resize && base.dragging.rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom) + base.resizing = base.dragging.rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom) base.dragging.rect.translation.sides = base.resizing app.tube("builder-pick-room", intersects[0]) } else if (base.permissions.create) { base.creating = true } - else if (intersects.length) { - app.tube("builder-pick-room", intersects[0]) - } if (e.shiftKey && base.dragging) { base.dragging.rect.quantize(10/map.zoom) @@ -77,6 +74,45 @@ Map.UI.Editor = function(map){ function move (e, cursor) { cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) + + var intersects = Rooms.filter(function(r){ + return r.rect.contains(cursor.x.a, cursor.y.a) + }) + + if (base.permissions.destroy) { + map.el.className = "destroy" + } + else if (intersects.length) { + var edges = intersects[0].rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom) + switch (edges) { + case FRONT_LEFT: + case BACK_RIGHT: + map.el.className = "nesw-resize" + break + + case FRONT_RIGHT: + case BACK_LEFT: + map.el.className = "nwse-resize" + break + + case FRONT: + case BACK: + map.el.className = "ns-resize" + break + + case LEFT: + case RIGHT: + map.el.className = "ew-resize" + break + + default: + map.el.className = "move" + break + } + } + else { + map.el.className = "" + } } function drag (e, cursor) { diff --git a/public/assets/javascripts/rectangles/util/constants.js b/public/assets/javascripts/rectangles/util/constants.js index 58cb1a5..b9485ca 100644 --- a/public/assets/javascripts/rectangles/util/constants.js +++ b/public/assets/javascripts/rectangles/util/constants.js @@ -8,6 +8,12 @@ var TOP = CEILING, BOTTOM = FLOOR, BOTTOM_RIGHT = BOTTOM | RIGHT, TOP_BOTTOM = TOP | BOTTOM +var FRONT_LEFT = FRONT | LEFT, + FRONT_RIGHT = FRONT | RIGHT, + BACK_LEFT = BACK | LEFT, + BACK_RIGHT = BACK | RIGHT + + var height_min = 200, height_max = 2000, side_min = 10, diff --git a/public/assets/javascripts/rectangles/util/permissions.js b/public/assets/javascripts/rectangles/util/permissions.js index adb2498..394b7d6 100644 --- a/public/assets/javascripts/rectangles/util/permissions.js +++ b/public/assets/javascripts/rectangles/util/permissions.js @@ -24,6 +24,18 @@ Permissions.prototype.assign = function (key, state) { return state } +Permissions.prototype.add = function (key) { + var base = this + base[op] = true + return state +} + +Permissions.prototype.remove = function (key) { + var base = this + base[op] = true + return state +} + Permissions.prototype.clear = function () { var base = this base.keys.forEach(function(op){ diff --git a/public/assets/javascripts/ui/builder/BuilderToolbar.js b/public/assets/javascripts/ui/builder/BuilderToolbar.js index df98ab0..239b05e 100644 --- a/public/assets/javascripts/ui/builder/BuilderToolbar.js +++ b/public/assets/javascripts/ui/builder/BuilderToolbar.js @@ -6,9 +6,9 @@ var BuilderToolbar = View.extend({ "click [data-role='toggle-map-view']": 'toggleMap', "click [data-role='toggle-layout-settings']": 'toggleSettings', "click [data-role='undo']": 'undo', - "click [data-role='create-mode']": 'create', - "click [data-role='resize-mode']": 'resize', - "click [data-role='move-mode']": 'move', +// "click [data-role='create-mode']": 'create', +// "click [data-role='resize-mode']": 'resize', +// "click [data-role='move-mode']": 'move', "click [data-role='destroy-mode']": 'destroy', }, @@ -27,7 +27,8 @@ var BuilderToolbar = View.extend({ undo: function(){ }, - + +/* create: function(e){ var state = map.ui.permissions.toggle("create") $(".inuse").removeClass("inuse") @@ -45,7 +46,8 @@ var BuilderToolbar = View.extend({ $(".inuse").removeClass("inuse") $(e.currentTarget).toggleClass("inuse", state) }, - +*/ + destroy: function(e){ var state = map.ui.permissions.toggle("destroy") $(".inuse").removeClass("inuse") diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css index a5b1733..1863add 100755 --- a/public/assets/stylesheets/app.css +++ b/public/assets/stylesheets/app.css @@ -526,20 +526,25 @@ iframe.embed { position:fixed; top:0; left:0; - cursor: -webkit-grab; - cursor: -moz-grab; z-index: 1; position: fixed; top: 50%; left: 50%; -webkit-transform: translate3d(-50%, -50%, 0); transform: translate3d(-50%, -50%, 0); - cursor:pointer; + cursor: -webkit-grab; + cursor: -moz-grab; } .mx-scene:active{ cursor: -webkit-grabbing; cursor: -moz-grabbing; } +.mx-scenery { + cursor: pointer; +} +.mx-scenery:active { + cursor: pointer; +} .mx-object3d.image, .mx-object3d.video, .mx-object3d iframe, @@ -573,6 +578,28 @@ iframe.embed { z-index: 10; } +#map { + cursor: crosshair; +} +#map.move { + cursor: move; +} +#map.ew-resize { + cursor: ew-resize; +} +#map.ns-resize { + cursor: ns-resize; +} +#map.nesw-resize { + cursor: nesw-resize; +} +#map.nwse-resize { + cursor: nwse-resize; +} +#map.destroy { + cursor: url(/assets/img/destroy-cursor.png) 12 12, auto; +} + .face { background-color: #fff; transition: 0.1s background-color ease; @@ -581,11 +608,10 @@ iframe.embed { .back { background-color: #fff; } .left { background-color: #fff; } .right { background-color: #fff; } -.floor { background-color: #eee; } -.ceiling { background-color: rgba(230,230,255,0.3); } +.floor { background-color: #f8f8f8; } +.ceiling { background-color: rgba(255,525,255,0.3); } -.active.floor { background-color: #ffe; } -.active.ceiling { background-color: rgba(230,230,255,0.3); } +.active.floor { background-color: #f8f8f8; } .dragging .mx-object3d.image { pointer-events: none; diff --git a/views/controls/builder/toolbar.ejs b/views/controls/builder/toolbar.ejs index 98aee1e..a00249c 100644 --- a/views/controls/builder/toolbar.ejs +++ b/views/controls/builder/toolbar.ejs @@ -3,6 +3,7 @@ data-role='toggle-map-view' data-info="toggle map view" class="icon-ios7-photos-outline"> + Date: Wed, 13 Aug 2014 02:12:40 -0400 Subject: add measurement stuff to media editor --- .../javascripts/mx/extensions/mx.movements.js | 4 +- .../rectangles/engine/scenery/types/_object.js | 4 ++ .../javascripts/rectangles/util/measurement.js | 82 +++++++++++++++++++++ .../assets/javascripts/ui/builder/BuilderInfo.js | 83 ---------------------- public/assets/javascripts/ui/editor/MediaEditor.js | 34 +++++++-- public/assets/stylesheets/app.css | 7 ++ test/09-test-undo.js | 1 + views/controls/editor/media-editor.ejs | 20 ++++-- views/partials/scripts.ejs | 1 + 9 files changed, 138 insertions(+), 98 deletions(-) create mode 100644 public/assets/javascripts/rectangles/util/measurement.js (limited to 'public/assets/javascripts/mx') diff --git a/public/assets/javascripts/mx/extensions/mx.movements.js b/public/assets/javascripts/mx/extensions/mx.movements.js index 191088f..3b7d3e2 100644 --- a/public/assets/javascripts/mx/extensions/mx.movements.js +++ b/public/assets/javascripts/mx/extensions/mx.movements.js @@ -149,7 +149,8 @@ MX.Movements = function (cam) { case 32: // space moveUp = moveDown = false break - + +/* case 48: // 0 cam.rotationX = 0 cam.rotationY = 0 @@ -157,6 +158,7 @@ MX.Movements = function (cam) { cam.y = viewHeight cam.z = 0 break +*/ } }) diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js index 7202ce0..66e0faf 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js @@ -66,6 +66,10 @@ Scenery.types.base = Fiber.extend(function(base){ this.center = this.wall.center() }, + set_scale: function(scale){ + this.scale = this.mx.scale = this.mx.ops.scale = scale || 1.0 + }, + recenter: function(){ this.mx.move({ x: this.center.a, diff --git a/public/assets/javascripts/rectangles/util/measurement.js b/public/assets/javascripts/rectangles/util/measurement.js new file mode 100644 index 0000000..d6a0b35 --- /dev/null +++ b/public/assets/javascripts/rectangles/util/measurement.js @@ -0,0 +1,82 @@ +$.fn.resetUnitVal = function(){ + this.each(function(){ + var n = $(this).data("px") + $(this).unitVal(n) + }); +} + +$.fn.unitVal = function(n){ + var s + if (typeof n === "undefined") { + s = $(this).val() + n = stringToMeasurement( s ) + if (! n || isNaN(n)) { + n = $(this).data("px") + } + } + s = measurementToString( n ) + $(this).val( s ).data("px", n) + return n +} + +function measurementToString( n ) { + var s, ft, inch + switch (app.units) { + case 'm': + s = round(n/36 * 0.3048 * 100) / 100 + " m" + break + case 'ft': + ft = floor(n / 36) + inch = abs(round((n % 36) / 3)) + s = ft + "'" + if (inch > 0) { + s += " " + inch + '"' + } + break + case 'px': + default: + s = round(n) + " px" + break + } + return s +} +function stringToMeasurement( s ) { + var ft, inch, ft_in, type + if (! s.match(/[0-9]/)) { + return NaN + } + if (s.indexOf("'") !== -1 || s.indexOf('"') !== -1 || s.indexOf('ft') !== -1) { + ft_in = s.match(/[0-9.]+/g) + if (ft_in.length >= 2) { + ft = parseFloat( ft_in[0] ) + inch = parseFloat( ft_in[1] ) + } + else if (ft_in.length == 1) { + if (s.indexOf('"') !== -1) { + ft = 0 + inch = parseFloat( ft_in[0] ) + } + else { + ft = parseFloat( ft_in[0] ) + inch = 0 + } + } + else { + ft = inch = 0 + } + n = ft * 36 + inch * 3 + } + else if (s.indexOf("m") !== -1) { + n = parseFloat(s.match(/[0-9.]+/)) * 36 / 0.3048 + } + else if (s.indexOf("px") !== -1) { + n = parseFloat(s.match(/[0-9.]+/)) + } + else { + n = abs( stringToMeasurement( s + app.units ) ) + } + if (s.indexOf('-') !== -1) { + n *= -1 + } + return n +} diff --git a/public/assets/javascripts/ui/builder/BuilderInfo.js b/public/assets/javascripts/ui/builder/BuilderInfo.js index 56f1338..2fffdba 100644 --- a/public/assets/javascripts/ui/builder/BuilderInfo.js +++ b/public/assets/javascripts/ui/builder/BuilderInfo.js @@ -96,86 +96,3 @@ var BuilderInfo = View.extend({ }, }) - -$.fn.resetUnitVal = function(){ - this.each(function(){ - var n = $(this).data("px") - $(this).unitVal(n) - }); -} - -$.fn.unitVal = function(n){ - var s - if (typeof n === "undefined") { - s = $(this).val() - n = stringToMeasurement( s ) - if (! n || isNaN(n)) { - n = $(this).data("px") - } - } - s = measurementToString( n ) - $(this).val( s ).data("px", n) - return n -} - -function measurementToString( n ) { - var s, ft, inch - switch (app.units) { - case 'm': - s = round(n/36 * 0.3048 * 100) / 100 + " m" - break - case 'ft': - ft = floor(n / 36) - inch = abs(round((n % 36) / 3)) - s = ft + "'" - if (inch > 0) { - s += " " + inch + '"' - } - break - case 'px': - default: - s = round(n) + " px" - break - } - return s -} -function stringToMeasurement( s ) { - var ft, inch, ft_in, type - if (! s.match(/[0-9]/)) { - return NaN - } - if (s.indexOf("'") !== -1 || s.indexOf('"') !== -1 || s.indexOf('ft') !== -1) { - ft_in = s.match(/[0-9.]+/g) - if (ft_in.length >= 2) { - ft = parseFloat( ft_in[0] ) - inch = parseFloat( ft_in[1] ) - } - else if (ft_in.length == 1) { - if (s.indexOf('"') !== -1) { - ft = 0 - inch = parseFloat( ft_in[0] ) - } - else { - ft = parseFloat( ft_in[0] ) - inch = 0 - } - } - else { - ft = inch = 0 - } - n = ft * 36 + inch * 3 - } - else if (s.indexOf("m") !== -1) { - n = parseFloat(s.match(/[0-9.]+/)) * 36 / 0.3048 - } - else if (s.indexOf("px") !== -1) { - n = parseFloat(s.match(/[0-9.]+/)) - } - else { - n = abs( stringToMeasurement( s + app.units ) ) - } - if (s.indexOf('-') !== -1) { - n *= -1 - } - return n -} \ No newline at end of file diff --git a/public/assets/javascripts/ui/editor/MediaEditor.js b/public/assets/javascripts/ui/editor/MediaEditor.js index cd8fb63..b9eb8fc 100644 --- a/public/assets/javascripts/ui/editor/MediaEditor.js +++ b/public/assets/javascripts/ui/editor/MediaEditor.js @@ -11,6 +11,9 @@ var MediaEditor = FormView.extend({ "change [name=autoplay]": "setAutoplay", "change [name=loop]": "setLoop", "change [name=mute]": "setMute", + "change [name=width]": 'changeWidth', + "change [name=height]": 'changeHeight', + "change [name=units]": 'changeUnits', "click [data-role=destroy-media]": "destroy", }, @@ -22,8 +25,8 @@ var MediaEditor = FormView.extend({ this.$description = this.$("[name=description]") // image fields - this.$widthDimension = this.$("[name=width]") - this.$heightDimension = this.$("[name=height]") + this.$width = this.$("[name=width]") + this.$height = this.$("[name=height]") this.$units = this.$("[name=units]") // video fields @@ -55,16 +58,14 @@ var MediaEditor = FormView.extend({ this.$name.val(media.title) this.$description.val(media.description) + this.setDimensions() + this.$units.val( "ft" ) switch (media.type) { case "image": this.$(".image").show() this.$(".video").hide() - - this.$widthDimension.val( Number(media.widthDimension) || "" ) - this.$heightDimension.val( Number(media.heightDimension) || "" ) - this.$units.val( media.units || "cm" ) - + break case "youtube": @@ -113,6 +114,25 @@ var MediaEditor = FormView.extend({ this.scenery.mute(checked) }, + setDimensions: function(){ + this.$width.unitVal( Number(this.scenery.dimensions.a * this.scenery.scale) || "" ) + this.$height.unitVal( Number(this.scenery.dimensions.b * this.scenery.scale) || "" ) + }, + changeWidth: function(e){ + e.stopPropagation() + this.scenery.set_scale( this.$width.unitVal() / this.scenery.dimensions.a ) + this.setDimensions() + }, + changeHeight: function(e){ + e.stopPropagation() + this.scenery.set_scale( this.$height.unitVal() / this.scenery.dimensions.b ) + this.setDimensions() + }, + changeUnits: function(){ + app.units = this.$units.val() + this.$('.units').resetUnitVal() + }, + bind: function(scenery){ this.scenery = scenery this.scenery.mx.bound = true diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css index 1863add..8508cf7 100755 --- a/public/assets/stylesheets/app.css +++ b/public/assets/stylesheets/app.css @@ -1295,6 +1295,13 @@ input[type="range"]::-webkit-slider-thumb { top: 0px; } +#mediaEditor .setting.number label { + width: 40px; +} +#mediaEditor .setting.number [type=text] { + width: 140px; +} + .playButton,.muteButton { color: white; background: black; diff --git a/test/09-test-undo.js b/test/09-test-undo.js index 17998a9..f774c04 100644 --- a/test/09-test-undo.js +++ b/test/09-test-undo.js @@ -1,5 +1,6 @@ var assert = require("assert") var UndoStack = require("../public/assets/javascripts/rectangles/util/undo.js") +UndoStack.debug = false describe('undo', function(){ diff --git a/views/controls/editor/media-editor.ejs b/views/controls/editor/media-editor.ejs index 5db1fb2..7f8f299 100644 --- a/views/controls/editor/media-editor.ejs +++ b/views/controls/editor/media-editor.ejs @@ -34,13 +34,19 @@ -
- Dimensions
- - - +
+
+ + +
+
+
diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs index b63d1bf..087c0d7 100644 --- a/views/partials/scripts.ejs +++ b/views/partials/scripts.ejs @@ -23,6 +23,7 @@ + -- cgit v1.2.3-70-g09d2 From 14228e82f4836b1bffa3389aa9e8d12959aa3810 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 13 Aug 2014 13:25:44 -0400 Subject: embed privacy check --- .../assets/javascripts/mx/primitives/mx.video.js | 2 -- .../assets/javascripts/mx/primitives/mx.vimeo.js | 23 +++++++++++----------- .../assets/javascripts/mx/primitives/mx.youtube.js | 2 -- .../rectangles/engine/scenery/types/video.js | 3 ++- public/assets/javascripts/ui/lib/ModalView.js | 7 ++++--- public/assets/javascripts/ui/lib/Parser.js | 6 ++++++ 6 files changed, 23 insertions(+), 20 deletions(-) (limited to 'public/assets/javascripts/mx') diff --git a/public/assets/javascripts/mx/primitives/mx.video.js b/public/assets/javascripts/mx/primitives/mx.video.js index 7c0cd33..12d3dcb 100644 --- a/public/assets/javascripts/mx/primitives/mx.video.js +++ b/public/assets/javascripts/mx/primitives/mx.video.js @@ -22,8 +22,6 @@ MX.Video = MX.Object3D.extend({ this.el.classList.add("mx-scenery") this.paused = !! this.media.autoplay this.muted = app.muted || !! this.media.mute - - this.load() }, load: function(ops){ diff --git a/public/assets/javascripts/mx/primitives/mx.vimeo.js b/public/assets/javascripts/mx/primitives/mx.vimeo.js index 5b22821..4922519 100644 --- a/public/assets/javascripts/mx/primitives/mx.vimeo.js +++ b/public/assets/javascripts/mx/primitives/mx.vimeo.js @@ -23,8 +23,6 @@ MX.Vimeo = MX.Object3D.extend({ this.paused = !! this.media.autoplay this.muted = app.muted || !! this.media.mute this.started = false - - this.load() }, load: function (ops) { @@ -42,23 +40,24 @@ MX.Vimeo = MX.Object3D.extend({ this.el.appendChild(preload) this.player = $f(preload) - this.player.addEvent('ready', this.ready.bind(this)) + this.player.addEvent('ready', $.proxy(this.ready, this)) }, ready: function(){ console.log("vimeo ready") + this.started = true // wait until ready before binding events. other events: play, pause - this.player.addEvent('play', this.onPlay.bind(this)) - this.player.addEvent('pause', this.onPause.bind(this)) - this.player.addEvent('finish', this.finished.bind(this)) + this.player.addEvent('play', $.proxy(this.onPlay, this)) + this.player.addEvent('pause', $.proxy(this.onPause, this)) + this.player.addEvent('finish', $.proxy(this.finished, this)) // this is async on vimeo so call it asap - this.player.api('getDuration', function(n){ + this.player.api('getDuration', $.proxy(function(n){ console.log("vimeo duration", n) this.player.duration = n - }.bind(this)) + }, this)) if (this.media.mute) { this.mute() @@ -91,9 +90,9 @@ MX.Vimeo = MX.Object3D.extend({ seek: function(n){ // defer seek until we have duration if (! this.duration()) { - setTimeout(function(){ + setTimeout($.proxy(function(){ this.seek(n) - }.bind(this), 300) + }, this), 300) return } @@ -109,9 +108,9 @@ MX.Vimeo = MX.Object3D.extend({ this.paused = false this.play() this.pause() - setTimeout(function(){ + setTimeout($.proxy(function(){ this.pause() - }.bind(this), 100) + }, this), 100) } }, diff --git a/public/assets/javascripts/mx/primitives/mx.youtube.js b/public/assets/javascripts/mx/primitives/mx.youtube.js index 7846649..873348f 100644 --- a/public/assets/javascripts/mx/primitives/mx.youtube.js +++ b/public/assets/javascripts/mx/primitives/mx.youtube.js @@ -22,8 +22,6 @@ MX.Youtube = MX.Object3D.extend({ this.el.classList.add("mx-scenery") this.paused = !! this.media.autoplay this.muted = app.muted || !! this.media.mute - - this.load() }, load: function (ops) { diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/video.js b/public/assets/javascripts/rectangles/engine/scenery/types/video.js index 79cfb1c..a8df875 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/video.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/video.js @@ -34,7 +34,8 @@ Scenery.types.video = Scenery.types.base.extend(function(base){ y: this.scale * this.media.height/2, backface: false, }) - scene.add( this.mx ) + scene.add(this.mx) + this.mx.load() }, play: function(){ diff --git a/public/assets/javascripts/ui/lib/ModalView.js b/public/assets/javascripts/ui/lib/ModalView.js index 957a54d..937c1e9 100644 --- a/public/assets/javascripts/ui/lib/ModalView.js +++ b/public/assets/javascripts/ui/lib/ModalView.js @@ -11,9 +11,10 @@ var ModalView = View.extend({ }, show: function(){ - $(".mediaDrawer").removeClass("active"); - this.$el.addClass("active"); - $("body").addClass("noOverflow"); + $(".mediaDrawer").removeClass("active") + $(".fileUpload").removeClass("active") + this.$el.addClass("active") + $("body").addClass("noOverflow") }, hide: function(){ diff --git a/public/assets/javascripts/ui/lib/Parser.js b/public/assets/javascripts/ui/lib/Parser.js index dfff7b2..8867c0b 100644 --- a/public/assets/javascripts/ui/lib/Parser.js +++ b/public/assets/javascripts/ui/lib/Parser.js @@ -84,8 +84,14 @@ var Parser = { type: 'GET', url: 'http://vimeo.com/api/v2/video/' + id + '.json', success: function(result){ + console.log(result) + // embed_privacy: "nowhere" if (result.length == 0) { return done(id, "", 640, 360) } var res = result[0] + if (res.embed_privacy != "anywhere") { + AlertModal.alert("Sorry, the author of this video has marked it private, preventing it from being embedded.", function(){}) + return + } done({ token: id, thumbnail: res.thumbnail_large, -- cgit v1.2.3-70-g09d2