Merge branch 'master' into funding
[wolnelektury.git] / apps / pdcounter / static / pdcounter / pdcounter.js
1 (function($) {
2     $(function() {
3
4         $('.countdown').each(function() {
5             var $this = $(this);
6
7             var serverTime = function() {
8                 var time = null;
9                 $.ajax({url: '/zegar/',
10                     async: false, dataType: 'text',
11                     success: function(text) {
12                         time = new Date(text);
13                     }, error: function(http, message, exc) {
14                         time = new Date();
15                 }});
16                 return time;
17             }
18
19             if (LANGUAGE_CODE != 'en') {
20                 $.countdown.setDefaults($.countdown.regional[LANGUAGE_CODE]);
21             }
22             else {
23                 $.countdown.setDefaults($.countdown.regional['']);
24             }
25
26             var options = {
27                 until: new Date($this.attr('data-until')),
28                 format: 'ydHMS',
29                 serverSync: serverTime,
30                 onExpiry: function(){location.reload()}, // TODO: no reload
31             };
32             if ($this.hasClass('inline')) {
33                 options.layout = '{d<}{dn} {dl} {d>}{hnn}{sep}{mnn}{sep}{snn}';
34             }
35             
36             $this.countdown(options);
37         });
38
39
40     });
41 })(jQuery);