summaryrefslogtreecommitdiff
path: root/assets/javascripts/util/minotaur.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-11-17 15:46:39 -0500
committerJules Laplace <jules@okfoc.us>2014-11-17 15:46:39 -0500
commit5fa235a556d384117840b7088575012dcd1787dd (patch)
tree2e819d13093cd446bdb32a2885c068da4ab94cf0 /assets/javascripts/util/minotaur.js
parent548ef92e8157f1ae0b594d0fd2c609438d748222 (diff)
polygonal lasso
Diffstat (limited to 'assets/javascripts/util/minotaur.js')
-rw-r--r--assets/javascripts/util/minotaur.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/assets/javascripts/util/minotaur.js b/assets/javascripts/util/minotaur.js
new file mode 100644
index 0000000..d165ccc
--- /dev/null
+++ b/assets/javascripts/util/minotaur.js
@@ -0,0 +1,66 @@
+(function(){
+
+ var Monitor = function () {
+ var base = this
+ base.$el = $("#minotaur")
+ base.timeout = null
+ base.delay = 2500
+ 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 () {
+ setTimeout(function(){
+ base.$el.removeClass()
+ }, 500)
+ }
+
+ base.init();
+ }
+
+ window.Minotaur = new Monitor ();
+
+})()