Add OldSchoolSpinner for loading animation
[blerg.git] / www / jssrc / lib / OldSchoolSpinner.js
diff --git a/www/jssrc/lib/OldSchoolSpinner.js b/www/jssrc/lib/OldSchoolSpinner.js
new file mode 100644 (file)
index 0000000..3c359e2
--- /dev/null
@@ -0,0 +1,27 @@
+enyo.kind({
+    name: "OldSchoolSpinner",
+    kind: "Control",
+    style: "font-family: Inconsolata, Consolas, Fixedsys, fixed, monospace; font-size: 16px",
+    content: '|',
+    steps: '/-\\|',
+    step: 0,
+    animationInterval: null,
+    destroy: function() {
+        this.stop();
+        this.inherited(arguments);
+    },
+    start: function() {
+        if (this.animationInterval)
+            return;
+
+        this.animationInterval = setInterval(this.animate.bind(this), 100);
+    },
+    stop: function() {
+        clearInterval(this.animationInterval);
+        this.animationInterval = null;
+    },
+    animate: function() {
+        this.step = (this.step + 1) % this.steps.length;
+        this.setContent(this.steps[this.step]);
+    }
+});