summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2014-08-13 02:12:40 -0400
committerJulie Lala <jules@okfoc.us>2014-08-13 02:12:40 -0400
commita279338f4dff62d87021ca28252d68b0c586d3a7 (patch)
tree832e81fca691d0eb693c6f41f3fbb2bcd79af8c6 /public/assets/javascripts/ui
parentb8b208d219cf782c39d054ad741724c6995a0b62 (diff)
add measurement stuff to media editor
Diffstat (limited to 'public/assets/javascripts/ui')
-rw-r--r--public/assets/javascripts/ui/builder/BuilderInfo.js83
-rw-r--r--public/assets/javascripts/ui/editor/MediaEditor.js34
2 files changed, 27 insertions, 90 deletions
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