Файл: system/modules/voting/vote_start_data/countdown.js
Строк: 79
<?php
jQuery.fn.countdown = function (date, options) {
options = jQuery.extend({
lang: {
years: ['год', 'года', 'лет'],
months: ['месяц', 'месяца', 'месяцев'],
days: ['день', 'дня', 'дней'],
hours: ['час', 'часа', 'часов'],
minutes: ['минута', 'минуты', 'минут'],
seconds: ['секунда', 'секунды', 'секунд'],
plurar: function(n) {
return (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
}
},
prefix: "Осталось: ",
suffix: "left",
finish: "Всё"
}, options);
var timeDifference = function(begin, end) {
if (end < begin) {
return false;
}
var diff = {
seconds: [end.getSeconds() - begin.getSeconds(), 60],
minutes: [end.getMinutes() - begin.getMinutes(), 60],
hours: [end.getHours() - begin.getHours(), 24],
days: [end.getDate() - begin.getDate(), new Date(begin.getYear(), begin.getMonth() + 1, 0).getDate() - 1],
months: [end.getMonth() - begin.getMonth(), 12],
years: [end.getYear() - begin.getYear(), 0]
};
var result = new Array();
var flag = false;
for (i in diff) {
if (flag) {
diff[i][0]--;
flag = false;
}
if (diff[i][0] < 0) {
flag = true;
diff[i][0] += diff[i][1];
}
if (!diff[i][0]) continue;
result.push(diff[i][0] + ' ' + options.lang[i][options.lang.plurar(diff[i][0])]);
}
return result.reverse().join(' ');
};
var elem = $(this);
var timeUpdate = function () {
var s = timeDifference(new Date(), date);
if (s.length) {
elem.html(options.prefix + " " +s + " "+options.suffix);
} else {
clearInterval(timer);
elem.html(options.finish);
}
};
timeUpdate();
var timer = setInterval(timeUpdate, 1000);
};
?>