PageSourceSearch

https://www.lindemansaalst.be/js/jquery.downCount.js

js lindemansaalst.be collected 2026-10-01 13:01:43 UTC 3,581 bytes, 104 lines download raw bytes

1/**
2 * downCount: Simple Countdown clock with offset
3 * Author: Sonny T. <[email protected]>, sonnyt.com
4 */
5
6(function ($) {
7
8    $.fn.downCount = function (options, callback) {
9        var settings = $.extend({
10                date: null,
11                offset: null
12            }, options);
13
14        // Throw error if date is not set
15        if (!settings.date) {
16            $.error('Date is not defined.');
17        }
18
19        // Throw error if date is set incorectly
20        if (!Date.parse(settings.date)) {
21            $.error('Incorrect date format, it should look like this, 12/24/2012 12:00:00.');
22        }
23
24        // Save container
25        var container = this;
26
27        /**
28         * Change client's local date to match offset timezone
29         * @return {Object} Fixed Date object.
30         */
31        var currentDate = function () {
32            // get client's current date
33            var date = new Date();
34
35            // turn date to utc
36            var utc = date.getTime() + (date.getTimezoneOffset() * 60000);
37
38            // set new Date object
39            var new_date = new Date(utc + (3600000*settings.offset))
40
41            return new_date;
42        };
43
44        /**
45         * Main downCount function that calculates everything
46         */
47        function countdown () {
48            var target_date = new Date(settings.date), // set target date
49                current_date = currentDate(); // get fixed current date
50
51            // difference of dates
52            var difference = target_date - current_date;
53
54            // if difference is negative than it's pass the target date
55            if (difference < 0) {
56                // stop timer
57                clearInterval(interval);
58
59                if (callback && typeof callback === 'function') callback();
60
61                return;
62            }
63
64            // basic math variables
65            var _second = 1000,
66                _minute = _second * 60,
67                _hour = _minute * 60,
68                _day = _hour * 24;
69
70            // calculate dates
71            var days = Math.floor(difference / _day),
72                hours = Math.floor((difference % _day) / _hour),
73                minutes = Math.floor((difference % _hour) / _minute),
74                seconds = Math.floor((difference % _minute) / _second);
75
76                // fix dates so that it will show two digets
77                days = (String(days).length >= 2) ? days : '0' + days;
78                hours = (String(hours).length >= 2) ? hours : '0' + hours;
79                minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes;
80                seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds;
81
82            // based on the date change the refrence wording
83            var ref_days = (days === 1) ? 'day' : 'days',
84                ref_hours = (hours === 1) ? 'hour' : 'hours',
85                ref_minutes = (minutes === 1) ? 'minute' : 'minutes',
86                ref_seconds = (seconds === 1) ? 'second' : 'seconds';
87
88            // set to DOM
89            container.find('.days').text(days);
90            container.find('.hours').text(hours);
91            container.find('.minutes').text(minutes);
92            container.find('.seconds').text(seconds);
93
94            container.find('.days_ref').text(ref_days);
95            container.find('.hours_ref').text(ref_hours);
96            container.find('.minutes_ref').text(ref_minutes);
97            container.find('.seconds_ref').text(ref_seconds);
98        };
99        
100        // start
101        var interval = setInterval(countdown, 1000);
102    };
103
104})(jQuery);

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.