DHTML progress bar for glacial rate adding and editing, closes: Bug#1100
[freeside.git] / httemplate / elements / qlib / counter.js
diff --git a/httemplate/elements/qlib/counter.js b/httemplate/elements/qlib/counter.js
new file mode 100644 (file)
index 0000000..72aeddb
--- /dev/null
@@ -0,0 +1,81 @@
+/**\r
+ * QLIB 1.0 Animated Digital Counter\r
+ * Copyright (C) 2002 2003, Quazzle.com Serge Dolgov\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * http://qlib.quazzle.com\r
+ */\r
+\r
+function QCounter_update() {\r
+    with (this) {\r
+        var v = Math.max(value, 0);\r
+        var mod;\r
+        for (var j=0; j<size; j++) {\r
+            mod = Math.floor(v % 10);\r
+            images[j].src = (v >= 1) || (!j) ? res.list[mod].src : res.list[10].src;\r
+            v /= 10;\r
+        }\r
+    }\r
+}\r
+\r
+function QCounter_count(value, step) {\r
+    this._cntt = false;\r
+    this.value += step; \r
+    if ((step * (this.value - value)) >= 0) {\r
+        this.value = value - 0;  // convert to number\r
+    } else {\r
+        this._cntt = setTimeout(this.name + ".count(" + value + "," + step + ")", 50);\r
+    }\r
+    this.update();\r
+}\r
+         \r
+function QCounter_set(value) {\r
+    this.setval = value;\r
+    if (value != this.value) {\r
+        if (this._cntt) {\r
+            clearTimeout(this._cntt);\r
+            this._cntt = false;\r
+        }\r
+        var dv = value - this.value;\r
+        if (this.effect == 2) {\r
+            dv = dv / Math.min(10, Math.abs(dv));\r
+        } else if (this.effect == 3) {\r
+            dv = dv / Math.abs(dv);\r
+        }\r
+        this.count(value, dv);\r
+    }\r
+}\r
+\r
+function QCounter(parent, name, res, size, effect) {\r
+    this.init(parent, name);\r
+    if (res) {\r
+        this.res = res;\r
+        this.setval = this.value = 0;\r
+        this.size = size || 4;\r
+        this.effect = effect || 2;\r
+        this._cntt = false;\r
+        this.images = new Array(this.size);\r
+        this.set = QCounter_set;\r
+        this.update = QCounter_update;\r
+        this.count = QCounter_count;\r
+        with (this) {\r
+            document.write('<table class="qcounter" width="' + (res.width * size) + '" height="' + res.height +\r
+                '" border="0" cellspacing="0" cellpadding="0" unselectable="on"><tr>');\r
+            for (var j=(size - 1); j>=0; j--) {\r
+                document.write('<td width="' + res.width + '" height="' + res.height +\r
+                    '" unselectable="on"><img name="' + id + j + '" src="' + (j ? res.list[10].src : res.list[0].src) +\r
+                    '" border="0" width="' + res.width + '" height="' + res.height + '"></td>');\r
+                images[j] = document.images[id + j] || new Image(1, 1);\r
+            }\r
+            document.write('</tr></table>');\r
+        }\r
+    } else {\r
+        this.document.write("invalid resource");\r
+    }\r
+}\r
+QCounter.prototype = new QControl();\r
+QCounter.INSTANT   = 1;\r
+QCounter.FAST      = 2;\r
+QCounter.SLOW      = 3;\r