PageSourceSearch

https://www.edenfantasys.com/Scripts/libs/JQuery_plugins/jquery.rendro.countdown.js

js edenfantasys.com collected 2026-09-24 18:14:15 UTC 4,264 bytes, 146 lines download raw bytes

1// Generated by CoffeeScript 1.6.2
2/*
3countdown is a simple jquery plugin for countdowns
4
5Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
6and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
7
8@source: http://github.com/rendro/countdown/
9@autor: Robert Fleischmann
10@version: 1.0.1
11*/
12
13/*
14 Extented with referenceDate paramter
15*/
16
17;(function() {
18  (function($) {
19    $.countdown = function(el, options) {
20      var getDateData,
21        _this = this;
22	  var referenceDateDiff = 0;
23      this.el = el;
24      this.$el = $(el);
25      this.$el.data("countdown", this);
26      this.init = function() {
27        _this.options = $.extend({}, $.countdown.defaultOptions, options);
28        if(_this.options.referenceDate){
29			referenceDateDiff = _this.options.referenceDate
30		}
31		if (_this.options.refresh) {
32          _this.interval = setInterval(function() {
33            return _this.render();
34          }, _this.options.refresh);
35        }
36        _this.render();
37        return _this;
38      };
39      getDateData = function(endDate) {
40        var dateData, diff;
41
42        endDate = Date.parse($.isPlainObject(_this.options.date) ? _this.options.date : new Date(_this.options.date));
43		startDate = new Date;
44		if (referenceDateDiff) {
45			referenceDateDiff = new Date(new Date(referenceDateDiff).getTime() + _this.options.refresh);
46			startDate = referenceDateDiff;
47		}
48        diff = (endDate - Date.parse(startDate)) / 1000;
49        if (diff <= 0) {
50          diff = 0;
51          if (_this.interval) {
52            _this.stop();
53          }
54          _this.options.onEnd.apply(_this);
55        }
56        dateData = {
57          years: 0,
58          days: 0,
59          hours: 0,
60          min: 0,
61          sec: 0,
62          millisec: 0
63        };
64        if (diff >= (365.25 * 86400)) {
65          dateData.years = Math.floor(diff / (365.25 * 86400));
66          diff -= dateData.years * 365.25 * 86400;
67        }
68        if (diff >= 86400) {
69          dateData.days = Math.floor(diff / 86400);
70          diff -= dateData.days * 86400;
71        }
72        if (diff >= 3600) {
73          dateData.hours = Math.floor(diff / 3600);
74          diff -= dateData.hours * 3600;
75        }
76        if (diff >= 60) {
77          dateData.min = Math.floor(diff / 60);
78          diff -= dateData.min * 60;
79        }
80        dateData.sec = diff;
81        return dateData;
82      };
83      this.leadingZeros = function(num, length) {
84        if (length == null) {
85          length = 2;
86        }
87        num = String(num);
88        while (num.length < length) {
89          num = "0" + num;
90        }
91        return num;
92      };
93      this.update = function(newDate) {
94        _this.options.date = newDate;
95        return _this;
96      };
97      this.render = function() {
98        _this.options.render.apply(_this, [getDateData(_this.options.date)]);
99        return _this;
100      };
101      this.stop = function() {
102        if (_this.interval) {
103          clearInterval(_this.interval);
104        }
105        _this.interval = null;
106        return _this;
107      };
108      this.start = function(refresh) {
109        if (refresh == null) {
110          refresh = _this.options.refresh || $.countdown.defaultOptions.refresh;
111        }
112        if (_this.interval) {
113          clearInterval(_this.interval);
114        }
115        _this.render();
116        _this.options.refresh = refresh;
117        _this.interval = setInterval(function() {
118          return _this.render();
119        }, _this.options.refresh);
120        return _this;
121      };
122      return this.init();
123    };
124    $.countdown.defaultOptions = {
125      date: "June 7, 2087 15:03:25",
126	  referenceDate: null,
127      refresh: 1000,
128      onEnd: $.noop,
129      render: function(date) {
130        return $(this.el).html("" + date.years + " years, " + date.days + " days, " + (this.leadingZeros(date.hours)) + " hours, " + (this.leadingZeros(date.min)) + " min and " + (this.leadingZeros(date.sec)) + " sec");
131      }
132    };
133    $.fn.countdown = function(options) {
134      return $.each(this, function(i, el) {
135        var $el;
136
137        $el = $(el);
138        if (!$el.data('countdown')) {
139          return $el.data('countdown', new $.countdown(el, options));
140        }
141      });
142    };
143    return void 0;
144  })(jQuery);
145
146}
146).call(this);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.