2 * QLIB 1.0 Animated Digital Counter
\r
3 * Copyright (C) 2002 2003, Quazzle.com Serge Dolgov
\r
4 * This program is free software; you can redistribute it and/or
\r
5 * modify it under the terms of the GNU General Public License
\r
6 * as published by the Free Software Foundation; either version 2
\r
7 * of the License, or (at your option) any later version.
\r
8 * http://qlib.quazzle.com
\r
11 function QCounter_update() {
\r
13 var v = Math.max(value, 0);
\r
15 for (var j=0; j<size; j++) {
\r
16 mod = Math.floor(v % 10);
\r
17 images[j].src = (v >= 1) || (!j) ? res.list[mod].src : res.list[10].src;
\r
23 function QCounter_count(value, step) {
\r
25 this.value += step;
\r
26 if ((step * (this.value - value)) >= 0) {
\r
27 this.value = value - 0; // convert to number
\r
29 this._cntt = setTimeout(this.name + ".count(" + value + "," + step + ")", 50);
\r
34 function QCounter_set(value) {
\r
35 this.setval = value;
\r
36 if (value != this.value) {
\r
38 clearTimeout(this._cntt);
\r
41 var dv = value - this.value;
\r
42 if (this.effect == 2) {
\r
43 dv = dv / Math.min(10, Math.abs(dv));
\r
44 } else if (this.effect == 3) {
\r
45 dv = dv / Math.abs(dv);
\r
47 this.count(value, dv);
\r
51 function QCounter(parent, name, res, size, effect) {
\r
52 this.init(parent, name);
\r
55 this.setval = this.value = 0;
\r
56 this.size = size || 4;
\r
57 this.effect = effect || 2;
\r
59 this.images = new Array(this.size);
\r
60 this.set = QCounter_set;
\r
61 this.update = QCounter_update;
\r
62 this.count = QCounter_count;
\r
64 document.write('<table class="qcounter" width="' + (res.width * size) + '" height="' + res.height +
\r
65 '" border="0" cellspacing="0" cellpadding="0" unselectable="on"><tr>');
\r
66 for (var j=(size - 1); j>=0; j--) {
\r
67 document.write('<td width="' + res.width + '" height="' + res.height +
\r
68 '" unselectable="on"><img name="' + id + j + '" src="' + (j ? res.list[10].src : res.list[0].src) +
\r
69 '" border="0" width="' + res.width + '" height="' + res.height + '"></td>');
\r
70 images[j] = document.images[id + j] || new Image(1, 1);
\r
72 document.write('</tr></table>');
\r
75 this.document.write("invalid resource");
\r
78 QCounter.prototype = new QControl();
\r
79 QCounter.INSTANT = 1;
\r