From: Radek Czajka Date: Fri, 28 May 2010 10:59:08 +0000 (+0200) Subject: jquery.countdown upgraded, added Ukrainian l10n X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/e431bb30d0e8d1feaad3a1c335b7bae596bade03?ds=inline;hp=-c jquery.countdown upgraded, added Ukrainian l10n --- e431bb30d0e8d1feaad3a1c335b7bae596bade03 diff --git a/wolnelektury/settings.py b/wolnelektury/settings.py index d40fd5532..94388a5f4 100644 --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@ -154,7 +154,7 @@ COMPRESS_JS = { 'all': { 'source_filenames': ('js/jquery.autocomplete.js', 'js/jquery.form.js', 'js/jquery.countdown.js', 'js/jquery.countdown-pl.js', - 'js/jquery.countdown-de.js', + 'js/jquery.countdown-de.js', 'js/jquery.countdown-uk.js', 'js/jquery.countdown-es.js', 'js/jquery.countdown-lt.js', 'js/jquery.countdown-ru.js', 'js/jquery.countdown-fr.js', 'js/jquery.jqmodal.js', 'js/jquery.labelify.js', 'js/catalogue.js', diff --git a/wolnelektury/static/js/jquery.countdown-de.js b/wolnelektury/static/js/jquery.countdown-de.js index a578c9fca..0e02ce571 100644 --- a/wolnelektury/static/js/jquery.countdown-de.js +++ b/wolnelektury/static/js/jquery.countdown-de.js @@ -1,11 +1,12 @@ -/* http://keith-wood.name/countdown.html - German initialisation for the jQuery countdown extension - Written by Keith Wood (kbwood@virginbroadband.com.au) Jan 2008. */ -(function($) { - $.countdown.regional['de'] = { - labels: ['Jahren', 'Monate', 'Wochen', 'Tage', 'Stunden', 'Minuten', 'Sekunden'], - labels1: ['Jahre', 'Monat', 'Woche', 'Tag', 'Stunde', 'Minute', 'Sekunde'], - compactLabels: ['J', 'M', 'W', 'T'], - timeSeparator: ':', isRTL: false}; - //$.countdown.setDefaults($.countdown.regional['de']); -})(jQuery); +/* http://keith-wood.name/countdown.html + German initialisation for the jQuery countdown extension + Written by Keith Wood (kbwood@virginbroadband.com.au) Jan 2008. */ +(function($) { + $.countdown.regional['de'] = { + labels: ['Jahren', 'Monate', 'Wochen', 'Tage', 'Stunden', 'Minuten', 'Sekunden'], + labels1: ['Jahre', 'Monat', 'Woche', 'Tag', 'Stunde', 'Minute', 'Sekunde'], + compactLabels: ['J', 'M', 'W', 'T'], + whichLabels: null, + timeSeparator: ':', isRTL: false}; + $.countdown.setDefaults($.countdown.regional['de']); +})(jQuery); diff --git a/wolnelektury/static/js/jquery.countdown-es.js b/wolnelektury/static/js/jquery.countdown-es.js index 07fea6d69..09657bc45 100644 --- a/wolnelektury/static/js/jquery.countdown-es.js +++ b/wolnelektury/static/js/jquery.countdown-es.js @@ -1,11 +1,12 @@ -/* http://keith-wood.name/countdown.html - * Spanish initialisation for the jQuery countdown extension - * Written by Sergio Carracedo Martinez webmaster@neodisenoweb.com (2008) */ -(function($) { - $.countdown.regional['es'] = { - labels: ['Años', 'Meses', 'Semanas', 'Dias', 'Horas', 'Minutos', 'Segundos'], - labels1: ['Años', 'Meses', 'Semanas', 'Dias', 'Horas', 'Minutos', 'Segundos'], - compactLabels: ['a', 'm', 's', 'g'], - timeSeparator: ':', isRTL: false}; - //$.countdown.setDefaults($.countdown.regional['es']); -})(jQuery); +/* http://keith-wood.name/countdown.html + * Spanish initialisation for the jQuery countdown extension + * Written by Sergio Carracedo Martinez webmaster@neodisenoweb.com (2008) */ +(function($) { + $.countdown.regional['es'] = { + labels: ['Años', 'Meses', 'Semanas', 'Dias', 'Horas', 'Minutos', 'Segundos'], + labels1: ['Años', 'Meses', 'Semanas', 'Dias', 'Horas', 'Minutos', 'Segundos'], + compactLabels: ['a', 'm', 's', 'g'], + whichLabels: null, + timeSeparator: ':', isRTL: false}; + $.countdown.setDefaults($.countdown.regional['es']); +})(jQuery); diff --git a/wolnelektury/static/js/jquery.countdown-fr.js b/wolnelektury/static/js/jquery.countdown-fr.js index 45a5990d1..5f5fac98b 100644 --- a/wolnelektury/static/js/jquery.countdown-fr.js +++ b/wolnelektury/static/js/jquery.countdown-fr.js @@ -1,11 +1,12 @@ -/* http://keith-wood.name/countdown.html - French initialisation for the jQuery countdown extension - Written by Keith Wood (kbwood{at}iinet.com.au) Jan 2008. */ -(function($) { - $.countdown.regional['fr'] = { - labels: ['Années', 'Mois', 'Semaines', 'Jours', 'Heures', 'Minutes', 'Secondes'], - labels1: ['Année', 'Mois', 'Semaine', 'Jour', 'Heure', 'Minute', 'Seconde'], - compactLabels: ['a', 'm', 's', 'j'], - timeSeparator: ':', isRTL: false}; - //$.countdown.setDefaults($.countdown.regional['fr']); -})(jQuery); +/* http://keith-wood.name/countdown.html + French initialisation for the jQuery countdown extension + Written by Keith Wood (kbwood{at}iinet.com.au) Jan 2008. */ +(function($) { + $.countdown.regional['fr'] = { + labels: ['Années', 'Mois', 'Semaines', 'Jours', 'Heures', 'Minutes', 'Secondes'], + labels1: ['Année', 'Mois', 'Semaine', 'Jour', 'Heure', 'Minute', 'Seconde'], + compactLabels: ['a', 'm', 's', 'j'], + whichLabels: null, + timeSeparator: ':', isRTL: false}; + $.countdown.setDefaults($.countdown.regional['fr']); +})(jQuery); diff --git a/wolnelektury/static/js/jquery.countdown-lt.js b/wolnelektury/static/js/jquery.countdown-lt.js index 37afdd414..ee11c71c5 100644 --- a/wolnelektury/static/js/jquery.countdown-lt.js +++ b/wolnelektury/static/js/jquery.countdown-lt.js @@ -6,6 +6,7 @@ labels: ['Metų', 'Mėnesių', 'Savaičių', 'Dienų', 'Valandų', 'Minučių', 'Sekundžių'], labels1: ['Metai', 'Mėnuo', 'Savaitė', 'Diena', 'Valanda', 'Minutė', 'Sekundė'], compactLabels: ['m', 'm', 's', 'd'], + whichLabels: null, timeSeparator: ':', isRTL: false}; - //$.countdown.setDefaults($.countdown.regional['lt']); + $.countdown.setDefaults($.countdown.regional['lt']); })(jQuery); diff --git a/wolnelektury/static/js/jquery.countdown-pl.js b/wolnelektury/static/js/jquery.countdown-pl.js index c881a3d7a..77a8a172b 100644 --- a/wolnelektury/static/js/jquery.countdown-pl.js +++ b/wolnelektury/static/js/jquery.countdown-pl.js @@ -1,19 +1,17 @@ /* http://keith-wood.name/countdown.html * Polish initialisation for the jQuery countdown extension - * Written by Pawel Lewtak lewtak@gmail.com (2008) - * and Radek Czajka radoslaw.czajka@nowoczesnapolska.org.pl (2010) */ + * Written by Pawel Lewtak lewtak@gmail.com (2008) */ (function($) { $.countdown.regional['pl'] = { labels: ['lat', 'miesięcy', 'tygodni', 'dni', 'godzin', 'minut', 'sekund'], labels1: ['rok', 'miesiąc', 'tydzień', 'dzień', 'godzina', 'minuta', 'sekunda'], - labels2: ['lata', 'miesiące', 'tygodnie', 'dni', 'godziny', 'minuty', 'sekundy'], - compactLabels: ['l', 'm', 't', 'd'], - compactLabels1: ['r', 'm', 't', 'd'], - compactLabels2: ['l', 'm', 't', 'd'], - timeSeparator: ':', isRTL: false, - which: function(n){ - return n==1 ? 1 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 2 : 0; - } - }; - //$.countdown.setDefaults($.countdown.regional['pl']); -})(jQuery); \ No newline at end of file + labels2: ['lata', 'miesiące', 'tygodnie', 'dni', 'godziny', 'minuty', 'sekundy'], + compactLabels: ['l', 'm', 't', 'd'], compactLabels1: ['r', 'm', 't', 'd'], + whichLabels: function(amount) { + var units = amount % 10; + var tens = Math.floor((amount % 100) / 10); + return (amount == 1 ? 1 : (units >= 2 && units <= 4 && tens != 1 ? 2 : 0)); + }, + timeSeparator: ':', isRTL: false}; + $.countdown.setDefaults($.countdown.regional['pl']); +})(jQuery); diff --git a/wolnelektury/static/js/jquery.countdown-ru.js b/wolnelektury/static/js/jquery.countdown-ru.js index 83303b3ae..1d1ca96e1 100644 --- a/wolnelektury/static/js/jquery.countdown-ru.js +++ b/wolnelektury/static/js/jquery.countdown-ru.js @@ -1,11 +1,12 @@ -/* http://keith-wood.name/countdown.html - * Russian initialisation for the jQuery countdown extension - * Written by Dominus i3rixon@gmail.com (2008) */ -(function($) { - $.countdown.regional['ru'] = { - labels: ['Лет', 'Месяцев', 'Недель', 'Дней', 'Часов', 'Минут', 'Секунд'], - labels1: ['Год', 'Месяц', 'Неделя', 'День', 'Час', 'Минута', 'Секунда'], - compactLabels: ['l', 'm', 'n', 'd'], compactLabels1: ['g', 'm', 'n', 'd'], - timeSeparator: ':', isRTL: false}; - //$.countdown.setDefaults($.countdown.regional['ru']); -})(jQuery); +/* http://keith-wood.name/countdown.html + * Russian initialisation for the jQuery countdown extension + * Written by Dominus i3rixon@gmail.com (2008) */ +(function($) { + $.countdown.regional['ru'] = { + labels: ['Лет', 'Месяцев', 'Недель', 'Дней', 'Часов', 'Минут', 'Секунд'], + labels1: ['Год', 'Месяц', 'Неделя', 'День', 'Час', 'Минута', 'Секунда'], + compactLabels: ['l', 'm', 'n', 'd'], compactLabels1: ['g', 'm', 'n', 'd'], + whichLabels: null, + timeSeparator: ':', isRTL: false}; + $.countdown.setDefaults($.countdown.regional['ru']); +})(jQuery); diff --git a/wolnelektury/static/js/jquery.countdown-uk.js b/wolnelektury/static/js/jquery.countdown-uk.js new file mode 100644 index 000000000..e38ab0479 --- /dev/null +++ b/wolnelektury/static/js/jquery.countdown-uk.js @@ -0,0 +1,12 @@ +/* http://keith-wood.name/countdown.html + * Ukrainian initialisation for the jQuery countdown extension + * Written by Goloborodko M misha.gm@gmail.com (2009) */ +(function($) { + $.countdown.regional['uk'] = { + labels: ['Років', 'Місяців', 'Тижднів', 'Днів', 'Годин', 'Хвилин', 'Секунд'], + labels1: ['Рік', 'Місяць', 'Тиждень', 'День', 'Година', 'Хвилина', 'Секунда'], + compactLabels: ['r', 'm', 't', 'd'], + whichLabels: null, + timeSeparator: ':', isRTL: false}; + $.countdown.setDefaults($.countdown.regional['uk']); +})(jQuery); diff --git a/wolnelektury/static/js/jquery.countdown.js b/wolnelektury/static/js/jquery.countdown.js index d00dca0da..27e2f4a10 100644 --- a/wolnelektury/static/js/jquery.countdown.js +++ b/wolnelektury/static/js/jquery.countdown.js @@ -1,12 +1,10 @@ /* http://keith-wood.name/countdown.html - Countdown for jQuery v1.5.7. + Countdown for jQuery v1.5.8. Written by Keith Wood (kbwood{at}iinet.com.au) January 2008. Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. Please attribute the author if you use it. */ -/* Modified by Radek Czajka, Fundacja Nowoczesna Polska (radoslaw.czajka(at)nowoczesnapolska.org.pl) */ - /* Display a countdown timer. Attach it with options like: $('div selector').countdown( @@ -23,9 +21,9 @@ function Countdown() { // The display texts for the counters if only one labels1: ['Year', 'Month', 'Week', 'Day', 'Hour', 'Minute', 'Second'], compactLabels: ['y', 'm', 'w', 'd'], // The compact texts for the counters + whichLabels: null, // Function to determine which labels to use timeSeparator: ':', // Separator for time periods - isRTL: false, // True for right-to-left languages, false for left-to-right - which: function(n) {return n} + isRTL: false // True for right-to-left languages, false for left-to-right }; this._defaults = { until: null, // new Date(year, mth - 1, day, hr, min, sec) - date/time to count down to @@ -41,6 +39,7 @@ function Countdown() { // 'Y' years, 'O' months, 'W' weeks, 'D' days, 'H' hours, 'M' minutes, 'S' seconds layout: '', // Build your own layout for the countdown compact: false, // True to display in a compact format, false for an expanded one + significant: 0, // The number of periods with values to show, zero for all description: '', // The description displayed for the countdown expiryUrl: '', // A URL to load upon expiry, replacing the current page expiryText: '', // Text to display upon expiry, replacing the countdown @@ -194,7 +193,7 @@ $.extend(Countdown.prototype, { var onTick = this._get(inst, 'onTick'); if (onTick) { var periods = inst._hold != 'lap' ? inst._periods : - this._calculatePeriods(inst, inst._show, new Date()); + this._calculatePeriods(inst, inst._show, this._get(inst, 'significant'), new Date()); var tickInterval = this._get(inst, 'tickInterval'); if (tickInterval == 1 || this.periodsToSeconds(periods) % tickInterval == 0) { onTick.apply(target, [periods]); @@ -265,7 +264,7 @@ $.extend(Countdown.prototype, { _resetExtraLabels: function(base, options) { var changingLabels = false; for (var n in options) { - if (n.match(/[Ll]abels/)) { + if (n != 'whichLabels' && n.match(/[Ll]abels/)) { changingLabels = true; break; } @@ -380,7 +379,7 @@ $.extend(Countdown.prototype, { _getTimesCountdown: function(target) { var inst = $.data(target, PROP_NAME); return (!inst ? null : (!inst._hold ? inst._periods : - this._calculatePeriods(inst, inst._show, new Date()))); + this._calculatePeriods(inst, inst._show, this._get(inst, 'significant'), new Date()))); }, /* Get a setting value, defaulting if necessary. @@ -449,57 +448,75 @@ $.extend(Countdown.prototype, { return 32 - new Date(year, month, 32).getDate(); }, + /* Determine which set of labels should be used for an amount. + @param num (number) the amount to be displayed + @return (number) the set of labels to be used for this amount */ + _normalLabels: function(num) { + return num; + }, + /* Generate the HTML to display the countdown widget. @param inst (object) the current settings for this instance @return (string) the new HTML for the countdown display */ _generateHTML: function(inst) { // Determine what to show - inst._periods = periods = (inst._hold ? inst._periods : - this._calculatePeriods(inst, inst._show, new Date())); + var significant = this._get(inst, 'significant'); + inst._periods = (inst._hold ? inst._periods : + this._calculatePeriods(inst, inst._show, significant, new Date())); // Show all 'asNeeded' after first non-zero value var shownNonZero = false; var showCount = 0; + var sigCount = significant; var show = $.extend({}, inst._show); - for (var period = 0; period < inst._show.length; period++) { - shownNonZero |= (inst._show[period] == '?' && periods[period] > 0); + for (var period = Y; period <= S; period++) { + shownNonZero |= (inst._show[period] == '?' && inst._periods[period] > 0); show[period] = (inst._show[period] == '?' && !shownNonZero ? null : inst._show[period]); showCount += (show[period] ? 1 : 0); + sigCount -= (inst._periods[period] > 0 ? 1 : 0); + } + var showSignificant = [false, false, false, false, false, false, false]; + for (var period = S; period >= Y; period--) { // Determine significant periods + if (inst._show[period]) { + if (inst._periods[period]) { + showSignificant[period] = true; + } + else { + showSignificant[period] = sigCount > 0; + sigCount--; + } + } } var compact = this._get(inst, 'compact'); var layout = this._get(inst, 'layout'); var labels = (compact ? this._get(inst, 'compactLabels') : this._get(inst, 'labels')); + var whichLabels = this._get(inst, 'whichLabels') || this._normalLabels; var timeSeparator = this._get(inst, 'timeSeparator'); var description = this._get(inst, 'description') || ''; var showCompact = function(period) { - var which = $.countdown._get(inst, 'which'); - if (which) { - var labelsNum = $.countdown._get(inst, 'compactLabels' + which(periods[period])); - } - return (show[period] ? periods[period] + + var labelsNum = $.countdown._get(inst, + 'compactLabels' + whichLabels(inst._periods[period])); + return (show[period] ? inst._periods[period] + (labelsNum ? labelsNum[period] : labels[period]) + ' ' : ''); }; var showFull = function(period) { - var which = $.countdown._get(inst, 'which'); - if (which) { - var labelsNum = $.countdown._get(inst, 'labels' + which(periods[period])); - } - return (show[period] ? + var labelsNum = $.countdown._get(inst, 'labels' + whichLabels(inst._periods[period])); + return ((!significant && show[period]) || (significant && showSignificant[period]) ? '' + - periods[period] + '
' + + inst._periods[period] + '

' + (labelsNum ? labelsNum[period] : labels[period]) + '' : ''); }; - return (layout ? this._buildLayout(inst, show, layout, compact) : + return (layout ? this._buildLayout(inst, show, layout, compact, significant, showSignificant) : ((compact ? // Compact version '' + showCompact(Y) + showCompact(O) + showCompact(W) + showCompact(D) + - (show[H] ? this._minDigits(periods[H], 2) : '') + + (show[H] ? this._minDigits(inst._periods[H], 2) : '') + (show[M] ? (show[H] ? timeSeparator : '') + - this._minDigits(periods[M], 2) : '') + + this._minDigits(inst._periods[M], 2) : '') + (show[S] ? (show[H] || show[M] ? timeSeparator : '') + - this._minDigits(periods[S], 2) : '') : + this._minDigits(inst._periods[S], 2) : '') : // Full version - '' + showFull(Y) + showFull(O) + showFull(W) + showFull(D) + showFull(H) + showFull(M) + showFull(S)) + '' + @@ -507,16 +524,19 @@ $.extend(Countdown.prototype, { }, /* Construct a custom layout. - @param inst (object) the current settings for this instance - @param show (string[7]) flags indicating which periods are requested - @param layout (string) the customised layout - @param compact (boolean) true if using compact labels + @param inst (object) the current settings for this instance + @param show (string[7]) flags indicating which periods are requested + @param layout (string) the customised layout + @param compact (boolean) true if using compact labels + @param significant (number) the number of periods with values to show, zero for all + @param showSignificant (boolean[7]) other periods to show for significance @return (string) the custom HTML */ - _buildLayout: function(inst, show, layout, compact) { + _buildLayout: function(inst, show, layout, compact, significant, showSignificant) { var labels = this._get(inst, (compact ? 'compactLabels' : 'labels')); + var whichLabels = this._get(inst, 'whichLabels') || this._normalLabels; var labelFor = function(index) { return ($.countdown._get(inst, - (compact ? 'compactLabels' : 'labels') + inst._periods[index]) || + (compact ? 'compactLabels' : 'labels') + whichLabels(inst._periods[index])) || labels)[index]; }; var digit = function(value, position) { @@ -553,10 +573,11 @@ $.extend(Countdown.prototype, { s1000: digit(inst._periods[S], 1000)}; var html = layout; // Replace period containers: {p<}...{p>} - for (var i = 0; i < 7; i++) { + for (var i = Y; i <= S; i++) { var period = 'yowdhms'.charAt(i); var re = new RegExp('\\{' + period + '<\\}(.*)\\{' + period + '>\\}', 'g'); - html = html.replace(re, (show[i] ? '$1' : '')); + html = html.replace(re, ((!significant && show[i]) || + (significant && showSignificant[i]) ? '$1' : '')); } // Replace period values: {pn} $.each(subs, function(n, v) { @@ -597,12 +618,13 @@ $.extend(Countdown.prototype, { }, /* Calculate the requested periods between now and the target time. - @param inst (object) the current settings for this instance - @param show (string[7]) flags indicating which periods are requested/required - @param now (Date) the current date and time + @param inst (object) the current settings for this instance + @param show (string[7]) flags indicating which periods are requested/required + @param significant (number) the number of periods with values to show, zero for all + @param now (Date) the current date and time @return (number[7]) the current time periods (always positive) by year, month, week, day, hour, minute, second */ - _calculatePeriods: function(inst, show, now) { + _calculatePeriods: function(inst, show, significant, now) { // Find endpoints inst._now = now; inst._now.setMilliseconds(0); @@ -640,25 +662,17 @@ $.extend(Countdown.prototype, { periods[Y] = (show[Y] ? Math.floor(months / 12) : 0); periods[O] = (show[O] ? months - periods[Y] * 12 : 0); // Adjust for months difference and end of month if necessary - var adjustDate = function(date, offset, last) { - var wasLastDay = (date.getDate() == last); - var lastDay = $.countdown._getDaysInMonth(date.getFullYear() + offset * periods[Y], - date.getMonth() + offset * periods[O]); - if (date.getDate() > lastDay) { - date.setDate(lastDay); - } - date.setFullYear(date.getFullYear() + offset * periods[Y]); - date.setMonth(date.getMonth() + offset * periods[O]); - if (wasLastDay) { - date.setDate(lastDay); - } - return date; - }; - if (inst._since) { - until = adjustDate(until, -1, lastUntil); + now = new Date(now.getTime()); + var wasLastDay = (now.getDate() == lastNow); + var lastDay = $.countdown._getDaysInMonth(now.getFullYear() + periods[Y], + now.getMonth() + periods[O]); + if (now.getDate() > lastDay) { + now.setDate(lastDay); } - else { - now = adjustDate(new Date(now.getTime()), +1, lastNow); + now.setFullYear(now.getFullYear() + periods[Y]); + now.setMonth(now.getMonth() + periods[O]); + if (wasLastDay) { + now.setDate(lastDay); } } var diff = Math.floor((until.getTime() - now.getTime()) / 1000); @@ -691,6 +705,16 @@ $.extend(Countdown.prototype, { max *= multiplier[period]; } } + if (significant) { // Zero out insignificant periods + for (var period = Y; period <= S; period++) { + if (significant && periods[period]) { + significant--; + } + else if (!significant) { + periods[period] = 0; + } + } + } return periods; } }); @@ -732,4 +756,4 @@ $.fn.countdown = function(options) { /* Initialise the countdown functionality. */ $.countdown = new Countdown(); // singleton instance -})(jQuery); \ No newline at end of file +})(jQuery);