/[drupal]/contributions/modules/countdown/countdown.js
ViewVC logotype

Diff of /contributions/modules/countdown/countdown.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Mon May 12 15:13:13 2008 UTC revision 1.2, Mon May 12 15:28:25 2008 UTC
# Line 0  Line 1 
1    // $Id$
2    
3    var _countdown_accuracy, _countdown_freq, _countdown_interval, _countdown_direction, _countdown_this;
4    
5    function init_countdown(accuracy) {
6      _countdown_accuracy = String('dhms').indexOf(accuracy);
7      _countdown_interval = [24, 60, 60, 1];
8      _countdown_freq = [86400, 3600, 60, 1];
9      _countdown_direction = -1;
10    }
11    
12    if (Drupal.jsEnabled) {
13      function countUp() {
14        _countdown_this.objDirText.nodeValue = _countdown_this.objDirText.nodeValue.replace(' until', ' since');
15        _countdown_direction = 1;
16        _countdown_this.initTime[0] = 0;
17        _countdown_this.initTime[1] = 0;
18        _countdown_this.initTime[2] = 0;
19        _countdown_this.initTime[3] = 0;
20        _countdown_this.objEM[0].innerHTML = String('0');
21        _countdown_this.objEM[1].innerHTML = String('0');
22        _countdown_this.objEM[2].innerHTML = String('0');
23        _countdown_this.objEM[3].innerHTML = String('0');
24      }
25    
26      jQuery.fn.extend({
27        onready : function() { return this.each(function() {
28          this.objEM = new Array();
29          this.initTime = new Array();
30          for (i = 0; i < this.childNodes.length; i ++) {
31            thisChild = this.childNodes.item(i);
32            if (thisChild.tagName == 'EM') {
33              this.objEM[this.objEM.length] = thisChild;
34              this.initTime[this.initTime.length] = parseInt(thisChild.innerHTML);
35            }
36            else if (thisChild.nodeName == '#text') {
37              if (thisChild.nodeValue.indexOf(' since') >= 0) {
38                _countdown_direction = 1;
39                this.objDirText = thisChild;
40              }
41              else if (thisChild.nodeValue.indexOf(' until') >= 0) {
42                this.objDirText = thisChild;
43              }
44            }
45          }
46    
47          _countdown_this = this;
48          setInterval(function() {
49            more = 1;
50            for (accuracy = _countdown_accuracy; accuracy >= 0 && more; accuracy --) {
51              value = _countdown_this.initTime[accuracy];
52              if (_countdown_direction == 1) {
53                if (accuracy > 0 && value >= _countdown_interval[accuracy - 1] - 1) {
54                  newValue = 0;
55                }
56                else {
57                  newValue = value + 1;
58                  more = 0;
59                }
60              }
61              else {
62                if (value) {
63                  newValue = value - 1;
64                  more = 0;
65                }
66                else if (accuracy == 0) {
67                  countUp();
68                  accuracy = _countdown_accuracy + 1;
69                  continue;
70                }
71                else {
72                  newValue = _countdown_interval[accuracy - 1] - 1;
73                }
74              }
75              _countdown_this.initTime[accuracy] = newValue;
76              _countdown_this.objEM[accuracy].innerHTML = String(newValue);
77            }
78          }, _countdown_freq[_countdown_accuracy] * 1000);
79        }); }
80      });
81    
82      $(document).ready(function() {
83          $(".block-countdown .content").onready();
84        }
85      );
86    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2