diff options
| author | Julie Lala <jules@okfoc.us> | 2014-08-15 09:26:10 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-08-15 09:26:10 -0400 |
| commit | aecaf2de2b4ed5277b34e9209a0f31602e8a7999 (patch) | |
| tree | 78e46648032b91ebb0267e38f39f6227da7d8732 /public/assets/javascripts/rectangles/util | |
| parent | 02bde51c24ae1c6e189d031b80226e6a9f7cbc59 (diff) | |
| parent | 1be685f9fe4a7f3a3e947d45f865fe07c03ddbaf (diff) | |
Merge branch 'walls' of github.com:okfocus/vvalls into walls
Diffstat (limited to 'public/assets/javascripts/rectangles/util')
| -rw-r--r-- | public/assets/javascripts/rectangles/util/constants.js | 6 | ||||
| -rw-r--r-- | public/assets/javascripts/rectangles/util/keys.js | 6 | ||||
| -rw-r--r-- | public/assets/javascripts/rectangles/util/measurement.js | 82 | ||||
| -rw-r--r-- | public/assets/javascripts/rectangles/util/minotaur.js | 64 | ||||
| -rw-r--r-- | public/assets/javascripts/rectangles/util/permissions.js | 17 | ||||
| -rw-r--r-- | public/assets/javascripts/rectangles/util/undostack.js (renamed from public/assets/javascripts/rectangles/util/undo.js) | 18 |
6 files changed, 186 insertions, 7 deletions
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/keys.js b/public/assets/javascripts/rectangles/util/keys.js index 5a5c9d2..62d763f 100644 --- a/public/assets/javascripts/rectangles/util/keys.js +++ b/public/assets/javascripts/rectangles/util/keys.js @@ -19,7 +19,7 @@ var keys = (function(){ break; default: if (keys.debug) console.log(key) - base.tube(key) + base.tube(key, e) break; } }) @@ -158,8 +158,8 @@ var keys = (function(){ 'backslash' : '220', 'closebracket' : '221', 'single_quote' : '222' - } - var KEY_NAMES = invert_hash(KEYCODES) + }, + KEY_NAMES = invert_hash(KEYCODES) return base })()
\ No newline at end of file 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/rectangles/util/minotaur.js b/public/assets/javascripts/rectangles/util/minotaur.js new file mode 100644 index 0000000..039a053 --- /dev/null +++ b/public/assets/javascripts/rectangles/util/minotaur.js @@ -0,0 +1,64 @@ +(function(){ + + var Monitor = function () { + var base = this + base.$el = $("#minotaur") + base.timeout = null + base.delay = 500 + base.objects = {} + + base.init = function () { + base.$el.removeClass() + base.$el.click(base.save) + } + + base.watch = function (object) { + base.objects[object.type] = base.objects[object.type] || {} + base.objects[object.type][object._id] = object + base.clear() + base.timeout = setTimeout(base.save, base.delay) + } + + base.unwatch = function (object) { + if (base.objects[object.type] && base.objects[object.type][object._id]) { + delete base.objects[object.type][object._id] + } + } + + base.clear = function () { + if (base.timeout) clearTimeout(base.timeout) + base.timeout = false + } + + base.save = function () { + var saving = false + base.clear() + + for (var type in base.objects) { + for (var id in base.objects[type]) { + var obj = base.objects[type][id] + if (obj) { + obj.save(null, function(){ base.hide() }, function(){}) + } + delete base.objects[type][id] + saving = true + } + } + + saving ? base.show() : base.hide() + } + + base.show = function () { + base.$el.removeClass().addClass('saving') + } + + base.hide = function () { + base.$el.removeClass() + } + + base.init(); + } + + window.Minotaur = new Monitor (); + +})() diff --git a/public/assets/javascripts/rectangles/util/permissions.js b/public/assets/javascripts/rectangles/util/permissions.js index adb2498..1b5a1b5 100644 --- a/public/assets/javascripts/rectangles/util/permissions.js +++ b/public/assets/javascripts/rectangles/util/permissions.js @@ -24,9 +24,26 @@ Permissions.prototype.assign = function (key, state) { return state } +Permissions.prototype.add = function (key) { + var base = this + base[key] = true +} + +Permissions.prototype.remove = function (key) { + var base = this + base[key] = true +} + Permissions.prototype.clear = function () { var base = this base.keys.forEach(function(op){ base[op] = false }) } + +Permissions.prototype.log = function () { + var base = this + base.keys.forEach(function(op){ + console.log(op, base[op]) + }) +}
\ No newline at end of file diff --git a/public/assets/javascripts/rectangles/util/undo.js b/public/assets/javascripts/rectangles/util/undostack.js index 3700817..b93c79e 100644 --- a/public/assets/javascripts/rectangles/util/undo.js +++ b/public/assets/javascripts/rectangles/util/undostack.js @@ -1,6 +1,7 @@ (function(){ var UndoStack = function(){ + this.debug = true this.stack = [] this.types = {} this.pointer = -1 @@ -17,7 +18,8 @@ UndoStack.prototype.undo = function(){ if (this.pointer == -1) return false var action = this.stack[this.pointer] - this.types[ action.type ].undo(action) + this.debug && console.log("undo", action.type) + this.types[ action.type ].undo(action.undo) this.pointer-- return this.pointer > -1 } @@ -25,13 +27,21 @@ if (this.pointer == this.stack.length-1) return false this.pointer++ var action = this.stack[this.pointer] - this.types[ action.type ].redo(action) + this.debug && console.log("redo", action.type) + this.types[ action.type ].redo(action.redo) return this.pointer < this.stack.length-1 } UndoStack.prototype.register = function(actionType){ - this.types[ actionType.type ] = actionType + if (actionType.length) { + actionType.forEach(this.registerOne.bind(this)) + } + else { + this.registerOne(actionType) + } } - + UndoStack.prototype.registerOne = function(actionType){ + this.types[ actionType.type ] = actionType + } if ('window' in this) { window.UndoStack = new UndoStack } |
