diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-08-22 19:41:37 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-08-22 19:41:37 -0400 |
| commit | 2235c34e498499b8141e835998b962067583a0ce (patch) | |
| tree | 22406e6484a7cccc1c72fb47cc4e5848f57ee2c4 /public/assets/javascripts/rectangles/util/minotaur.js | |
| parent | ed5751766079a62ce596dcc0abc1a211b5b633dc (diff) | |
| parent | 4ef340497ef24bb2ecacb2c9c4106c24515c874f (diff) | |
merge
Diffstat (limited to 'public/assets/javascripts/rectangles/util/minotaur.js')
| -rw-r--r-- | public/assets/javascripts/rectangles/util/minotaur.js | 64 |
1 files changed, 64 insertions, 0 deletions
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 (); + +})() |
