jquery-countdown-rails 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jquery-countdown-rails.rb +7 -7
- data/lib/jquery-countdown-rails/sprockets.rb +1 -1
- data/lib/jquery-countdown-rails/version.rb +2 -1
- data/vendor/assets/javascripts/jquery.countdown-da.js +1 -1
- data/vendor/assets/javascripts/jquery.countdown-fo.js +13 -0
- data/vendor/assets/javascripts/jquery.countdown-hr.js +20 -7
- data/vendor/assets/javascripts/jquery.countdown-is.js +13 -0
- data/vendor/assets/javascripts/jquery.countdown.js +1 -858
- data/vendor/assets/javascripts/jquery.countdown.upstream.js +853 -0
- data/vendor/assets/javascripts/jquery.plugin.js +2 -2
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed634544ae94ed960de9cd9524e740c8d96dd287
|
4
|
+
data.tar.gz: 2ce8ba956821119fa47f91db8fbc065929dff116
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50747f65481e55e013fe0a39ecd72df03e9cb5347386262baab9ca1bf0a222ce21433a621fd54a3c784ad683b9010f1d84ba75aa294c92e0f193f69fb319703f
|
7
|
+
data.tar.gz: 110ff4526134e8639e1a8be439da442be013bf31e36099aa2fc149648957c628b001fd954e86b7e1216ef77e513e5c8026e4aba733a3173ac2f967803eb23891
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'jquery-countdown-rails/version'
|
2
2
|
|
3
|
-
#
|
3
|
+
# Public: Adds jquery-countdown to the asset pipeline, for rails and
|
4
|
+
# standalone Sprockets
|
4
5
|
module JqueryCountdownRails
|
5
|
-
|
6
6
|
if defined? ::Rails
|
7
|
-
if ::Rails.version.to_s <
|
8
|
-
require
|
7
|
+
if ::Rails.version.to_s < '3.1'
|
8
|
+
require 'jquery-countdown-rails/railtie'
|
9
9
|
else
|
10
|
-
require
|
10
|
+
require 'jquery-countdown-rails/engine'
|
11
11
|
end
|
12
12
|
elsif defined? ::Sprockets
|
13
|
-
require
|
13
|
+
require 'jquery-countdown-rails/sprockets'
|
14
14
|
end
|
15
15
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
(function($) {
|
5
5
|
$.countdown.regionalOptions['da'] = {
|
6
6
|
labels: ['År', 'Måneder', 'Uger', 'Dage', 'Timer', 'Minutter', 'Sekunder'],
|
7
|
-
labels1: ['År', '
|
7
|
+
labels1: ['År', 'Måned', 'Uge', 'Dag', 'Time', 'Minut', 'Sekund'],
|
8
8
|
compactLabels: ['Å', 'M', 'U', 'D'],
|
9
9
|
whichLabels: null,
|
10
10
|
digits: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/* http://keith-wood.name/countdown.html
|
2
|
+
Faroese initialisation for the jQuery countdown extension
|
3
|
+
Written by Kasper Friis Christensen (kasper@friischristensen.com). */
|
4
|
+
(function($) {
|
5
|
+
$.countdown.regionalOptions['fo'] = {
|
6
|
+
labels: ['Ár', 'Mánaðir', 'Vikur', 'Dagar', 'Tímar', 'Minuttir', 'Sekund'],
|
7
|
+
labels1: ['Ár', 'Mánaður', 'Vika', 'Dagur', 'Tími', 'Minuttur', 'Sekund'],
|
8
|
+
compactLabels: ['Á', 'M', 'V', 'D'],
|
9
|
+
whichLabels: null,
|
10
|
+
digits: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
11
|
+
timeSeparator: ':', isRTL: false};
|
12
|
+
$.countdown.setDefaults($.countdown.regionalOptions['fo']);
|
13
|
+
})(jQuery);
|
@@ -1,14 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
/**
|
2
|
+
* http://keith-wood.name/countdown.html
|
3
|
+
* Croatian l10n for the jQuery countdown plugin
|
4
|
+
* Written by Dejan Broz info@hqfactory.com (2011)
|
5
|
+
* Improved by zytzagoo (2014)
|
6
|
+
*/
|
4
7
|
(function($) {
|
5
8
|
$.countdown.regionalOptions['hr'] = {
|
9
|
+
// plurals
|
6
10
|
labels: ['Godina', 'Mjeseci', 'Tjedana', 'Dana', 'Sati', 'Minuta', 'Sekundi'],
|
7
|
-
|
8
|
-
|
11
|
+
// singles
|
12
|
+
labels1: ['Godina', 'Mjesec', 'Tjedan', 'Dan', 'Sat', 'Minutu', 'Sekundu'],
|
13
|
+
// paucals
|
14
|
+
labels2: ['Godine', 'Mjeseca', 'Tjedana', 'Dana', 'Sata', 'Minute', 'Sekunde'],
|
9
15
|
compactLabels: ['g', 'm', 't', 'd'],
|
10
|
-
whichLabels: function(amount)
|
11
|
-
|
16
|
+
whichLabels: function(amount){
|
17
|
+
amount = parseInt(amount, 10);
|
18
|
+
if (amount % 10 === 1 && amount % 100 !== 11) {
|
19
|
+
return 1; // singles (/.*1$/ && ! /.*11$/)
|
20
|
+
}
|
21
|
+
if (amount % 10 >= 2 && amount % 10 <= 4 && (amount % 100 < 10 || amount % 100 >= 20)) {
|
22
|
+
return 2; // paucals (/.*[234]$/ && ! /.*1[234]$/
|
23
|
+
}
|
24
|
+
return 0; // default plural (most common case)
|
12
25
|
},
|
13
26
|
digits: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
14
27
|
timeSeparator: ':', isRTL: false};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/* http://keith-wood.name/countdown.html
|
2
|
+
Icelandic initialisation for the jQuery countdown extension
|
3
|
+
Written by Róbert K. L. */
|
4
|
+
(function($) {
|
5
|
+
$.countdown.regionalOptions['is'] = {
|
6
|
+
labels: ['Ár', 'Mánuðir', 'Vikur', 'Dagar', 'Klukkustundir', 'Mínútur', 'Sekúndur'],
|
7
|
+
labels1: ['Ár', 'Mánuður', 'Vika', 'Dagur', 'Klukkustund', 'Mínúta', 'Sekúnda'],
|
8
|
+
compactLabels: ['ár.', 'mán.', 'vik.', 'dag.', 'klst.', 'mín.', 'sek.'],
|
9
|
+
whichLabels: null,
|
10
|
+
digits: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
11
|
+
timeSeparator: ':', isRTL: false};
|
12
|
+
$.countdown.setDefaults($.countdown.regionalOptions['is']);
|
13
|
+
})(jQuery);
|
@@ -1,860 +1,3 @@
|
|
1
1
|
// Countdown dependency as a manifest
|
2
2
|
//= require jquery.plugin
|
3
|
-
|
4
|
-
/* http://keith-wood.name/countdown.html
|
5
|
-
Countdown for jQuery v2.0.0.
|
6
|
-
Written by Keith Wood (kbwood{at}iinet.com.au) January 2008.
|
7
|
-
Available under the MIT (https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt) license.
|
8
|
-
Please attribute the author if you use it. */
|
9
|
-
|
10
|
-
(function($) { // Hide scope, no $ conflict
|
11
|
-
|
12
|
-
var pluginName = 'countdown';
|
13
|
-
|
14
|
-
var Y = 0; // Years
|
15
|
-
var O = 1; // Months
|
16
|
-
var W = 2; // Weeks
|
17
|
-
var D = 3; // Days
|
18
|
-
var H = 4; // Hours
|
19
|
-
var M = 5; // Minutes
|
20
|
-
var S = 6; // Seconds
|
21
|
-
|
22
|
-
/** Create the countdown plugin.
|
23
|
-
<p>Sets an element to show the time remaining until a given instant.</p>
|
24
|
-
<p>Expects HTML like:</p>
|
25
|
-
<pre><div></div></pre>
|
26
|
-
<p>Provide inline configuration like:</p>
|
27
|
-
<pre><div data-countdown="name: 'value'"></div></pre>
|
28
|
-
@module Countdown
|
29
|
-
@augments JQPlugin
|
30
|
-
@example $(selector).countdown({until: +300}) */
|
31
|
-
$.JQPlugin.createPlugin({
|
32
|
-
|
33
|
-
/** The name of the plugin. */
|
34
|
-
name: pluginName,
|
35
|
-
|
36
|
-
/** Countdown expiry callback.
|
37
|
-
Triggered when the countdown expires.
|
38
|
-
@callback expiryCallback */
|
39
|
-
|
40
|
-
/** Countdown server synchronisation callback.
|
41
|
-
Triggered when the countdown is initialised.
|
42
|
-
@callback serverSyncCallback
|
43
|
-
@return {Date} The current date/time on the server as expressed in the local timezone. */
|
44
|
-
|
45
|
-
/** Countdown tick callback.
|
46
|
-
Triggered on every <code>tickInterval</code> ticks of the countdown.
|
47
|
-
@callback tickCallback
|
48
|
-
@param periods {number[]} The breakdown by period (years, months, weeks, days,
|
49
|
-
hours, minutes, seconds) of the time remaining/passed. */
|
50
|
-
|
51
|
-
/** Countdown which labels callback.
|
52
|
-
Triggered when the countdown is being display to determine which set of labels
|
53
|
-
(<code>labels</code>, <code>labels1</code>, ...) are to be used for the current period value.
|
54
|
-
@callback whichLabelsCallback
|
55
|
-
@param num {number} The current period value.
|
56
|
-
@return {number} The suffix for the label set to use. */
|
57
|
-
|
58
|
-
/** Default settings for the plugin.
|
59
|
-
@property until {Date|number|string} The date/time to count down to, or number of seconds
|
60
|
-
offset from now, or string of amounts and units for offset(s) from now:
|
61
|
-
'Y' years, 'O' months, 'W' weeks, 'D' days, 'H' hours, 'M' minutes, 'S' seconds.
|
62
|
-
@example until: new Date(2013, 12-1, 25, 13, 30)
|
63
|
-
until: +300
|
64
|
-
until: '+1O -2D'
|
65
|
-
@property [since] {Date|number|string} The date/time to count up from, or
|
66
|
-
number of seconds offset from now, or string for unit offset(s):
|
67
|
-
'Y' years, 'O' months, 'W' weeks, 'D' days, 'H' hours, 'M' minutes, 'S' seconds.
|
68
|
-
@example since: new Date(2013, 1-1, 1)
|
69
|
-
since: -300
|
70
|
-
since: '-1O +2D'
|
71
|
-
@property [timezone=null] {number} The timezone (hours or minutes from GMT) for the target times,
|
72
|
-
or null for client local timezone.
|
73
|
-
@example timezone: +10
|
74
|
-
timezone: -60
|
75
|
-
@property [serverSync=null] {serverSyncCallback} A function to retrieve the current server time
|
76
|
-
for synchronisation.
|
77
|
-
@property [format='dHMS'] {string} The format for display - upper case for always, lower case only if non-zero,
|
78
|
-
'Y' years, 'O' months, 'W' weeks, 'D' days, 'H' hours, 'M' minutes, 'S' seconds.
|
79
|
-
@property [layout=''] {string} Build your own layout for the countdown.
|
80
|
-
@example layout: '{d<}{dn} {dl}{d>} {hnn}:{mnn}:{snn}'
|
81
|
-
@property [compact=false] {boolean} True to display in a compact format, false for an expanded one.
|
82
|
-
@property [padZeroes=false] {boolean} True to add leading zeroes
|
83
|
-
@property [significant=0] {number} The number of periods with non-zero values to show, zero for all.
|
84
|
-
@property [description=''] {string} The description displayed for the countdown.
|
85
|
-
@property [expiryUrl=''] {string} A URL to load upon expiry, replacing the current page.
|
86
|
-
@property [expiryText=''] {string} Text to display upon expiry, replacing the countdown. This may be HTML.
|
87
|
-
@property [alwaysExpire=false] {boolean} True to trigger <code>onExpiry</code> even if target time has passed.
|
88
|
-
@property [onExpiry=null] {expiryCallback} Callback when the countdown expires -
|
89
|
-
receives no parameters and <code>this</code> is the containing division.
|
90
|
-
@example onExpiry: function() {
|
91
|
-
...
|
92
|
-
}
|
93
|
-
@property [onTick=null] {tickCallback} Callback when the countdown is updated -
|
94
|
-
receives <code>number[7]</code> being the breakdown by period
|
95
|
-
(years, months, weeks, days, hours, minutes, seconds - based on
|
96
|
-
<code>format</code>) and <code>this</code> is the containing division.
|
97
|
-
@example onTick: function(periods) {
|
98
|
-
var secs = $.countdown.periodsToSeconds(periods);
|
99
|
-
if (secs < 300) { // Last five minutes
|
100
|
-
...
|
101
|
-
}
|
102
|
-
}
|
103
|
-
@property [tickInterval=1] {number} The interval (seconds) between <code>onTick</code> callbacks. */
|
104
|
-
defaultOptions: {
|
105
|
-
until: null,
|
106
|
-
since: null,
|
107
|
-
timezone: null,
|
108
|
-
serverSync: null,
|
109
|
-
format: 'dHMS',
|
110
|
-
layout: '',
|
111
|
-
compact: false,
|
112
|
-
padZeroes: false,
|
113
|
-
significant: 0,
|
114
|
-
description: '',
|
115
|
-
expiryUrl: '',
|
116
|
-
expiryText: '',
|
117
|
-
alwaysExpire: false,
|
118
|
-
onExpiry: null,
|
119
|
-
onTick: null,
|
120
|
-
tickInterval: 1
|
121
|
-
},
|
122
|
-
|
123
|
-
/** Localisations for the plugin.
|
124
|
-
Entries are objects indexed by the language code ('' being the default US/English).
|
125
|
-
Each object has the following attributes.
|
126
|
-
@property [labels=['Years','Months','Weeks','Days','Hours','Minutes','Seconds']] {string[]}
|
127
|
-
The display texts for the counter periods.
|
128
|
-
@property [labels1=['Year','Month','Week','Day','Hour','Minute','Second']] {string[]}
|
129
|
-
The display texts for the counter periods if they have a value of 1.
|
130
|
-
Add other <code>labels<em>n</em></code> attributes as necessary to
|
131
|
-
cater for other numeric idiosyncrasies of the localisation.
|
132
|
-
@property [compactLabels=['y','m','w','d']] {string[]} The compact texts for the counter periods.
|
133
|
-
@property [whichLabels=null] {whichLabelsCallback} A function to determine which
|
134
|
-
<code>labels<em>n</em></code> to use.
|
135
|
-
@example whichLabels: function(num) {
|
136
|
-
return (num > 1 ? 0 : 1);
|
137
|
-
}
|
138
|
-
@property [digits=['0','1',...,'9']] {number[]} The digits to display (0-9).
|
139
|
-
@property [timeSeparator=':'] {string} Separator for time periods in the compact layout.
|
140
|
-
@property [isRTL=false] {boolean} True for right-to-left languages, false for left-to-right. */
|
141
|
-
regionalOptions: { // Available regional settings, indexed by language/country code
|
142
|
-
'': { // Default regional settings - English/US
|
143
|
-
labels: ['Years', 'Months', 'Weeks', 'Days', 'Hours', 'Minutes', 'Seconds'],
|
144
|
-
labels1: ['Year', 'Month', 'Week', 'Day', 'Hour', 'Minute', 'Second'],
|
145
|
-
compactLabels: ['y', 'm', 'w', 'd'],
|
146
|
-
whichLabels: null,
|
147
|
-
digits: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
148
|
-
timeSeparator: ':',
|
149
|
-
isRTL: false
|
150
|
-
}
|
151
|
-
},
|
152
|
-
|
153
|
-
/** Names of getter methods - those that can't be chained. */
|
154
|
-
_getters: ['getTimes'],
|
155
|
-
|
156
|
-
/* Class name for the right-to-left marker. */
|
157
|
-
_rtlClass: pluginName + '-rtl',
|
158
|
-
/* Class name for the countdown section marker. */
|
159
|
-
_sectionClass: pluginName + '-section',
|
160
|
-
/* Class name for the period amount marker. */
|
161
|
-
_amountClass: pluginName + '-amount',
|
162
|
-
/* Class name for the period name marker. */
|
163
|
-
_periodClass: pluginName + '-period',
|
164
|
-
/* Class name for the countdown row marker. */
|
165
|
-
_rowClass: pluginName + '-row',
|
166
|
-
/* Class name for the holding countdown marker. */
|
167
|
-
_holdingClass: pluginName + '-holding',
|
168
|
-
/* Class name for the showing countdown marker. */
|
169
|
-
_showClass: pluginName + '-show',
|
170
|
-
/* Class name for the description marker. */
|
171
|
-
_descrClass: pluginName + '-descr',
|
172
|
-
|
173
|
-
/* List of currently active countdown elements. */
|
174
|
-
_timerElems: [],
|
175
|
-
|
176
|
-
/** Additional setup for the countdown.
|
177
|
-
Apply default localisations.
|
178
|
-
Create the timer. */
|
179
|
-
_init: function() {
|
180
|
-
var self = this;
|
181
|
-
this._super();
|
182
|
-
this._serverSyncs = [];
|
183
|
-
var now = (typeof Date.now == 'function' ? Date.now :
|
184
|
-
function() { return new Date().getTime(); });
|
185
|
-
var perfAvail = (window.performance && typeof window.performance.now == 'function');
|
186
|
-
// Shared timer for all countdowns
|
187
|
-
function timerCallBack(timestamp) {
|
188
|
-
var drawStart = (timestamp < 1e12 ? // New HTML5 high resolution timer
|
189
|
-
(perfAvail ? (performance.now() + performance.timing.navigationStart) : now()) :
|
190
|
-
// Integer milliseconds since unix epoch
|
191
|
-
timestamp || now());
|
192
|
-
if (drawStart - animationStartTime >= 1000) {
|
193
|
-
self._updateElems();
|
194
|
-
animationStartTime = drawStart;
|
195
|
-
}
|
196
|
-
requestAnimationFrame(timerCallBack);
|
197
|
-
}
|
198
|
-
var requestAnimationFrame = window.requestAnimationFrame ||
|
199
|
-
window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame ||
|
200
|
-
window.oRequestAnimationFrame || window.msRequestAnimationFrame || null;
|
201
|
-
// This is when we expect a fall-back to setInterval as it's much more fluid
|
202
|
-
var animationStartTime = 0;
|
203
|
-
if (!requestAnimationFrame || $.noRequestAnimationFrame) {
|
204
|
-
$.noRequestAnimationFrame = null;
|
205
|
-
setInterval(function() { self._updateElems(); }, 980); // Fall back to good old setInterval
|
206
|
-
}
|
207
|
-
else {
|
208
|
-
animationStartTime = window.animationStartTime ||
|
209
|
-
window.webkitAnimationStartTime || window.mozAnimationStartTime ||
|
210
|
-
window.oAnimationStartTime || window.msAnimationStartTime || now();
|
211
|
-
requestAnimationFrame(timerCallBack);
|
212
|
-
}
|
213
|
-
},
|
214
|
-
|
215
|
-
/** Convert a date/time to UTC.
|
216
|
-
@param tz {number} The hour or minute offset from GMT, e.g. +9, -360.
|
217
|
-
@param year {Date|number} the date/time in that timezone or the year in that timezone.
|
218
|
-
@param [month] {number} The month (0 - 11) (omit if <code>year</code> is a <code>Date</code>).
|
219
|
-
@param [day] {number} The day (omit if <code>year</code> is a <code>Date</code>).
|
220
|
-
@param [hours] {number} The hour (omit if <code>year</code> is a <code>Date</code>).
|
221
|
-
@param [mins] {number} The minute (omit if <code>year</code> is a <code>Date</code>).
|
222
|
-
@param [secs] {number} The second (omit if <code>year</code> is a <code>Date</code>).
|
223
|
-
@param [ms] {number} The millisecond (omit if <code>year</code> is a <code>Date</code>).
|
224
|
-
@return {Date} The equivalent UTC date/time.
|
225
|
-
@example $.countdown.UTCDate(+10, 2013, 12-1, 25, 12, 0)
|
226
|
-
$.countdown.UTCDate(-7, new Date(2013, 12-1, 25, 12, 0)) */
|
227
|
-
UTCDate: function(tz, year, month, day, hours, mins, secs, ms) {
|
228
|
-
if (typeof year == 'object' && year.constructor == Date) {
|
229
|
-
ms = year.getMilliseconds();
|
230
|
-
secs = year.getSeconds();
|
231
|
-
mins = year.getMinutes();
|
232
|
-
hours = year.getHours();
|
233
|
-
day = year.getDate();
|
234
|
-
month = year.getMonth();
|
235
|
-
year = year.getFullYear();
|
236
|
-
}
|
237
|
-
var d = new Date();
|
238
|
-
d.setUTCFullYear(year);
|
239
|
-
d.setUTCDate(1);
|
240
|
-
d.setUTCMonth(month || 0);
|
241
|
-
d.setUTCDate(day || 1);
|
242
|
-
d.setUTCHours(hours || 0);
|
243
|
-
d.setUTCMinutes((mins || 0) - (Math.abs(tz) < 30 ? tz * 60 : tz));
|
244
|
-
d.setUTCSeconds(secs || 0);
|
245
|
-
d.setUTCMilliseconds(ms || 0);
|
246
|
-
return d;
|
247
|
-
},
|
248
|
-
|
249
|
-
/** Convert a set of periods into seconds.
|
250
|
-
Averaged for months and years.
|
251
|
-
@param periods {number[]} The periods per year/month/week/day/hour/minute/second.
|
252
|
-
@return {number} The corresponding number of seconds.
|
253
|
-
@example var secs = $.countdown.periodsToSeconds(periods) */
|
254
|
-
periodsToSeconds: function(periods) {
|
255
|
-
return periods[0] * 31557600 + periods[1] * 2629800 + periods[2] * 604800 +
|
256
|
-
periods[3] * 86400 + periods[4] * 3600 + periods[5] * 60 + periods[6];
|
257
|
-
},
|
258
|
-
|
259
|
-
_instSettings: function(elem, options) {
|
260
|
-
return {_periods: [0, 0, 0, 0, 0, 0, 0]};
|
261
|
-
},
|
262
|
-
|
263
|
-
/** Add an element to the list of active ones.
|
264
|
-
@private
|
265
|
-
@param elem {Element} The countdown element. */
|
266
|
-
_addElem: function(elem) {
|
267
|
-
if (!this._hasElem(elem)) {
|
268
|
-
this._timerElems.push(elem);
|
269
|
-
}
|
270
|
-
},
|
271
|
-
|
272
|
-
/** See if an element is in the list of active ones.
|
273
|
-
@private
|
274
|
-
@param elem {Element} The countdown element.
|
275
|
-
@return {boolean} True if present, false if not. */
|
276
|
-
_hasElem: function(elem) {
|
277
|
-
return ($.inArray(elem, this._timerElems) > -1);
|
278
|
-
},
|
279
|
-
|
280
|
-
/** Remove an element from the list of active ones.
|
281
|
-
@private
|
282
|
-
@param elem {Element} The countdown element. */
|
283
|
-
_removeElem: function(elem) {
|
284
|
-
this._timerElems = $.map(this._timerElems,
|
285
|
-
function(value) { return (value == elem ? null : value); }); // delete entry
|
286
|
-
},
|
287
|
-
|
288
|
-
/** Update each active timer element.
|
289
|
-
@private */
|
290
|
-
_updateElems: function() {
|
291
|
-
for (var i = this._timerElems.length - 1; i >= 0; i--) {
|
292
|
-
this._updateCountdown(this._timerElems[i]);
|
293
|
-
}
|
294
|
-
},
|
295
|
-
|
296
|
-
_optionsChanged: function(elem, inst, options) {
|
297
|
-
if (options.layout) {
|
298
|
-
options.layout = options.layout.replace(/</g, '<').replace(/>/g, '>');
|
299
|
-
}
|
300
|
-
this._resetExtraLabels(inst.options, options);
|
301
|
-
var timezoneChanged = (inst.options.timezone != options.timezone);
|
302
|
-
$.extend(inst.options, options);
|
303
|
-
this._adjustSettings(elem, inst,
|
304
|
-
options.until != null || options.since != null || timezoneChanged);
|
305
|
-
var now = new Date();
|
306
|
-
if ((inst._since && inst._since < now) || (inst._until && inst._until > now)) {
|
307
|
-
this._addElem(elem[0]);
|
308
|
-
}
|
309
|
-
this._updateCountdown(elem, inst);
|
310
|
-
},
|
311
|
-
|
312
|
-
/** Redisplay the countdown with an updated display.
|
313
|
-
@private
|
314
|
-
@param elem {Element|jQuery} The containing division.
|
315
|
-
@param inst {object} The current settings for this instance. */
|
316
|
-
_updateCountdown: function(elem, inst) {
|
317
|
-
elem = elem.jquery ? elem : $(elem);
|
318
|
-
inst = inst || elem.data(this.name);
|
319
|
-
if (!inst) {
|
320
|
-
return;
|
321
|
-
}
|
322
|
-
elem.html(this._generateHTML(inst)).toggleClass(this._rtlClass, inst.options.isRTL);
|
323
|
-
if ($.isFunction(inst.options.onTick)) {
|
324
|
-
var periods = inst._hold != 'lap' ? inst._periods :
|
325
|
-
this._calculatePeriods(inst, inst._show, inst.options.significant, new Date());
|
326
|
-
if (inst.options.tickInterval == 1 ||
|
327
|
-
this.periodsToSeconds(periods) % inst.options.tickInterval == 0) {
|
328
|
-
inst.options.onTick.apply(elem[0], [periods]);
|
329
|
-
}
|
330
|
-
}
|
331
|
-
var expired = inst._hold != 'pause' &&
|
332
|
-
(inst._since ? inst._now.getTime() < inst._since.getTime() :
|
333
|
-
inst._now.getTime() >= inst._until.getTime());
|
334
|
-
if (expired && !inst._expiring) {
|
335
|
-
inst._expiring = true;
|
336
|
-
if (this._hasElem(elem[0]) || inst.options.alwaysExpire) {
|
337
|
-
this._removeElem(elem[0]);
|
338
|
-
if ($.isFunction(inst.options.onExpiry)) {
|
339
|
-
inst.options.onExpiry.apply(elem[0], []);
|
340
|
-
}
|
341
|
-
if (inst.options.expiryText) {
|
342
|
-
var layout = inst.options.layout;
|
343
|
-
inst.options.layout = inst.options.expiryText;
|
344
|
-
this._updateCountdown(elem[0], inst);
|
345
|
-
inst.options.layout = layout;
|
346
|
-
}
|
347
|
-
if (inst.options.expiryUrl) {
|
348
|
-
window.location = inst.options.expiryUrl;
|
349
|
-
}
|
350
|
-
}
|
351
|
-
inst._expiring = false;
|
352
|
-
}
|
353
|
-
else if (inst._hold == 'pause') {
|
354
|
-
this._removeElem(elem[0]);
|
355
|
-
}
|
356
|
-
},
|
357
|
-
|
358
|
-
/** Reset any extra labelsn and compactLabelsn entries if changing labels.
|
359
|
-
@private
|
360
|
-
@param base {object} The options to be updated.
|
361
|
-
@param options {object} The new option values. */
|
362
|
-
_resetExtraLabels: function(base, options) {
|
363
|
-
var changingLabels = false;
|
364
|
-
for (var n in options) {
|
365
|
-
if (n != 'whichLabels' && n.match(/[Ll]abels/)) {
|
366
|
-
changingLabels = true;
|
367
|
-
break;
|
368
|
-
}
|
369
|
-
}
|
370
|
-
if (changingLabels) {
|
371
|
-
for (var n in base) { // Remove custom numbered labels
|
372
|
-
if (n.match(/[Ll]abels[02-9]|compactLabels1/)) {
|
373
|
-
base[n] = null;
|
374
|
-
}
|
375
|
-
}
|
376
|
-
}
|
377
|
-
},
|
378
|
-
|
379
|
-
/** Calculate internal settings for an instance.
|
380
|
-
@private
|
381
|
-
@param elem {jQuery} The containing division.
|
382
|
-
@param inst {object} The current settings for this instance.
|
383
|
-
@param recalc {boolean} True if until or since are set. */
|
384
|
-
_adjustSettings: function(elem, inst, recalc) {
|
385
|
-
var now;
|
386
|
-
var serverOffset = 0;
|
387
|
-
var serverEntry = null;
|
388
|
-
for (var i = 0; i < this._serverSyncs.length; i++) {
|
389
|
-
if (this._serverSyncs[i][0] == inst.options.serverSync) {
|
390
|
-
serverEntry = this._serverSyncs[i][1];
|
391
|
-
break;
|
392
|
-
}
|
393
|
-
}
|
394
|
-
if (serverEntry != null) {
|
395
|
-
serverOffset = (inst.options.serverSync ? serverEntry : 0);
|
396
|
-
now = new Date();
|
397
|
-
}
|
398
|
-
else {
|
399
|
-
var serverResult = ($.isFunction(inst.options.serverSync) ?
|
400
|
-
inst.options.serverSync.apply(elem[0], []) : null);
|
401
|
-
now = new Date();
|
402
|
-
serverOffset = (serverResult ? now.getTime() - serverResult.getTime() : 0);
|
403
|
-
this._serverSyncs.push([inst.options.serverSync, serverOffset]);
|
404
|
-
}
|
405
|
-
var timezone = inst.options.timezone;
|
406
|
-
timezone = (timezone == null ? -now.getTimezoneOffset() : timezone);
|
407
|
-
if (recalc || (!recalc && inst._until == null && inst._since == null)) {
|
408
|
-
inst._since = inst.options.since;
|
409
|
-
if (inst._since != null) {
|
410
|
-
inst._since = this.UTCDate(timezone, this._determineTime(inst._since, null));
|
411
|
-
if (inst._since && serverOffset) {
|
412
|
-
inst._since.setMilliseconds(inst._since.getMilliseconds() + serverOffset);
|
413
|
-
}
|
414
|
-
}
|
415
|
-
inst._until = this.UTCDate(timezone, this._determineTime(inst.options.until, now));
|
416
|
-
if (serverOffset) {
|
417
|
-
inst._until.setMilliseconds(inst._until.getMilliseconds() + serverOffset);
|
418
|
-
}
|
419
|
-
}
|
420
|
-
inst._show = this._determineShow(inst);
|
421
|
-
},
|
422
|
-
|
423
|
-
/** Remove the countdown widget from a div.
|
424
|
-
@param elem {jQuery} The containing division.
|
425
|
-
@param inst {object} The current instance object. */
|
426
|
-
_preDestroy: function(elem, inst) {
|
427
|
-
this._removeElem(elem[0]);
|
428
|
-
elem.empty();
|
429
|
-
},
|
430
|
-
|
431
|
-
/** Pause a countdown widget at the current time.
|
432
|
-
Stop it running but remember and display the current time.
|
433
|
-
@param elem {Element} The containing division.
|
434
|
-
@example $(selector).countdown('pause') */
|
435
|
-
pause: function(elem) {
|
436
|
-
this._hold(elem, 'pause');
|
437
|
-
},
|
438
|
-
|
439
|
-
/** Pause a countdown widget at the current time.
|
440
|
-
Stop the display but keep the countdown running.
|
441
|
-
@param elem {Element} The containing division.
|
442
|
-
@example $(selector).countdown('lap') */
|
443
|
-
lap: function(elem) {
|
444
|
-
this._hold(elem, 'lap');
|
445
|
-
},
|
446
|
-
|
447
|
-
/** Resume a paused countdown widget.
|
448
|
-
@param elem {Element} The containing division.
|
449
|
-
@example $(selector).countdown('resume') */
|
450
|
-
resume: function(elem) {
|
451
|
-
this._hold(elem, null);
|
452
|
-
},
|
453
|
-
|
454
|
-
/** Toggle a paused countdown widget.
|
455
|
-
@param elem {Element} The containing division.
|
456
|
-
@example $(selector).countdown('toggle') */
|
457
|
-
toggle: function(elem) {
|
458
|
-
var inst = $.data(elem, this.name) || {};
|
459
|
-
this[!inst._hold ? 'pause' : 'resume'](elem);
|
460
|
-
},
|
461
|
-
|
462
|
-
/** Toggle a lapped countdown widget.
|
463
|
-
@param elem {Element} The containing division.
|
464
|
-
@example $(selector).countdown('toggleLap') */
|
465
|
-
toggleLap: function(elem) {
|
466
|
-
var inst = $.data(elem, this.name) || {};
|
467
|
-
this[!inst._hold ? 'lap' : 'resume'](elem);
|
468
|
-
},
|
469
|
-
|
470
|
-
/** Pause or resume a countdown widget.
|
471
|
-
@private
|
472
|
-
@param elem {Element} The containing division.
|
473
|
-
@param hold {string} The new hold setting. */
|
474
|
-
_hold: function(elem, hold) {
|
475
|
-
var inst = $.data(elem, this.name);
|
476
|
-
if (inst) {
|
477
|
-
if (inst._hold == 'pause' && !hold) {
|
478
|
-
inst._periods = inst._savePeriods;
|
479
|
-
var sign = (inst._since ? '-' : '+');
|
480
|
-
inst[inst._since ? '_since' : '_until'] =
|
481
|
-
this._determineTime(sign + inst._periods[0] + 'y' +
|
482
|
-
sign + inst._periods[1] + 'o' + sign + inst._periods[2] + 'w' +
|
483
|
-
sign + inst._periods[3] + 'd' + sign + inst._periods[4] + 'h' +
|
484
|
-
sign + inst._periods[5] + 'm' + sign + inst._periods[6] + 's');
|
485
|
-
this._addElem(elem);
|
486
|
-
}
|
487
|
-
inst._hold = hold;
|
488
|
-
inst._savePeriods = (hold == 'pause' ? inst._periods : null);
|
489
|
-
$.data(elem, this.name, inst);
|
490
|
-
this._updateCountdown(elem, inst);
|
491
|
-
}
|
492
|
-
},
|
493
|
-
|
494
|
-
/** Return the current time periods.
|
495
|
-
@param elem {Element} The containing division.
|
496
|
-
@return {number[]} The current periods for the countdown.
|
497
|
-
@example var periods = $(selector).countdown('getTimes') */
|
498
|
-
getTimes: function(elem) {
|
499
|
-
var inst = $.data(elem, this.name);
|
500
|
-
return (!inst ? null : (inst._hold == 'pause' ? inst._savePeriods : (!inst._hold ? inst._periods :
|
501
|
-
this._calculatePeriods(inst, inst._show, inst.options.significant, new Date()))));
|
502
|
-
},
|
503
|
-
|
504
|
-
/** A time may be specified as an exact value or a relative one.
|
505
|
-
@private
|
506
|
-
@param setting {string|number|Date} The date/time value as a relative or absolute value.
|
507
|
-
@param defaultTime {Date} The date/time to use if no other is supplied.
|
508
|
-
@return {Date} The corresponding date/time. */
|
509
|
-
_determineTime: function(setting, defaultTime) {
|
510
|
-
var self = this;
|
511
|
-
var offsetNumeric = function(offset) { // e.g. +300, -2
|
512
|
-
var time = new Date();
|
513
|
-
time.setTime(time.getTime() + offset * 1000);
|
514
|
-
return time;
|
515
|
-
};
|
516
|
-
var offsetString = function(offset) { // e.g. '+2d', '-4w', '+3h +30m'
|
517
|
-
offset = offset.toLowerCase();
|
518
|
-
var time = new Date();
|
519
|
-
var year = time.getFullYear();
|
520
|
-
var month = time.getMonth();
|
521
|
-
var day = time.getDate();
|
522
|
-
var hour = time.getHours();
|
523
|
-
var minute = time.getMinutes();
|
524
|
-
var second = time.getSeconds();
|
525
|
-
var pattern = /([+-]?[0-9]+)\s*(s|m|h|d|w|o|y)?/g;
|
526
|
-
var matches = pattern.exec(offset);
|
527
|
-
while (matches) {
|
528
|
-
switch (matches[2] || 's') {
|
529
|
-
case 's': second += parseInt(matches[1], 10); break;
|
530
|
-
case 'm': minute += parseInt(matches[1], 10); break;
|
531
|
-
case 'h': hour += parseInt(matches[1], 10); break;
|
532
|
-
case 'd': day += parseInt(matches[1], 10); break;
|
533
|
-
case 'w': day += parseInt(matches[1], 10) * 7; break;
|
534
|
-
case 'o':
|
535
|
-
month += parseInt(matches[1], 10);
|
536
|
-
day = Math.min(day, self._getDaysInMonth(year, month));
|
537
|
-
break;
|
538
|
-
case 'y':
|
539
|
-
year += parseInt(matches[1], 10);
|
540
|
-
day = Math.min(day, self._getDaysInMonth(year, month));
|
541
|
-
break;
|
542
|
-
}
|
543
|
-
matches = pattern.exec(offset);
|
544
|
-
}
|
545
|
-
return new Date(year, month, day, hour, minute, second, 0);
|
546
|
-
};
|
547
|
-
var time = (setting == null ? defaultTime :
|
548
|
-
(typeof setting == 'string' ? offsetString(setting) :
|
549
|
-
(typeof setting == 'number' ? offsetNumeric(setting) : setting)));
|
550
|
-
if (time) time.setMilliseconds(0);
|
551
|
-
return time;
|
552
|
-
},
|
553
|
-
|
554
|
-
/** Determine the number of days in a month.
|
555
|
-
@private
|
556
|
-
@param year {number} The year.
|
557
|
-
@param month {number} The month.
|
558
|
-
@return {number} The days in that month. */
|
559
|
-
_getDaysInMonth: function(year, month) {
|
560
|
-
return 32 - new Date(year, month, 32).getDate();
|
561
|
-
},
|
562
|
-
|
563
|
-
/** Default implementation to determine which set of labels should be used for an amount.
|
564
|
-
Use the <code>labels</code> attribute with the same numeric suffix (if it exists).
|
565
|
-
@private
|
566
|
-
@param num {number} The amount to be displayed.
|
567
|
-
@return {number} The set of labels to be used for this amount. */
|
568
|
-
_normalLabels: function(num) {
|
569
|
-
return num;
|
570
|
-
},
|
571
|
-
|
572
|
-
/** Generate the HTML to display the countdown widget.
|
573
|
-
@private
|
574
|
-
@param inst {object} The current settings for this instance.
|
575
|
-
@return {string} The new HTML for the countdown display. */
|
576
|
-
_generateHTML: function(inst) {
|
577
|
-
var self = this;
|
578
|
-
// Determine what to show
|
579
|
-
inst._periods = (inst._hold ? inst._periods :
|
580
|
-
this._calculatePeriods(inst, inst._show, inst.options.significant, new Date()));
|
581
|
-
// Show all 'asNeeded' after first non-zero value
|
582
|
-
var shownNonZero = false;
|
583
|
-
var showCount = 0;
|
584
|
-
var sigCount = inst.options.significant;
|
585
|
-
var show = $.extend({}, inst._show);
|
586
|
-
for (var period = Y; period <= S; period++) {
|
587
|
-
shownNonZero |= (inst._show[period] == '?' && inst._periods[period] > 0);
|
588
|
-
show[period] = (inst._show[period] == '?' && !shownNonZero ? null : inst._show[period]);
|
589
|
-
showCount += (show[period] ? 1 : 0);
|
590
|
-
sigCount -= (inst._periods[period] > 0 ? 1 : 0);
|
591
|
-
}
|
592
|
-
var showSignificant = [false, false, false, false, false, false, false];
|
593
|
-
for (var period = S; period >= Y; period--) { // Determine significant periods
|
594
|
-
if (inst._show[period]) {
|
595
|
-
if (inst._periods[period]) {
|
596
|
-
showSignificant[period] = true;
|
597
|
-
}
|
598
|
-
else {
|
599
|
-
showSignificant[period] = sigCount > 0;
|
600
|
-
sigCount--;
|
601
|
-
}
|
602
|
-
}
|
603
|
-
}
|
604
|
-
var labels = (inst.options.compact ? inst.options.compactLabels : inst.options.labels);
|
605
|
-
var whichLabels = inst.options.whichLabels || this._normalLabels;
|
606
|
-
var showCompact = function(period) {
|
607
|
-
var labelsNum = inst.options['compactLabels' + whichLabels(inst._periods[period])];
|
608
|
-
return (show[period] ? self._translateDigits(inst, inst._periods[period]) +
|
609
|
-
(labelsNum ? labelsNum[period] : labels[period]) + ' ' : '');
|
610
|
-
};
|
611
|
-
var minDigits = (inst.options.padZeroes ? 2 : 1);
|
612
|
-
var showFull = function(period) {
|
613
|
-
var labelsNum = inst.options['labels' + whichLabels(inst._periods[period])];
|
614
|
-
return ((!inst.options.significant && show[period]) ||
|
615
|
-
(inst.options.significant && showSignificant[period]) ?
|
616
|
-
'<span class="' + self._sectionClass + '">' +
|
617
|
-
'<span class="' + self._amountClass + '">' +
|
618
|
-
self._minDigits(inst, inst._periods[period], minDigits) + '</span>' +
|
619
|
-
'<span class="' + self._periodClass + '">' +
|
620
|
-
(labelsNum ? labelsNum[period] : labels[period]) + '</span></span>' : '');
|
621
|
-
};
|
622
|
-
return (inst.options.layout ? this._buildLayout(inst, show, inst.options.layout,
|
623
|
-
inst.options.compact, inst.options.significant, showSignificant) :
|
624
|
-
((inst.options.compact ? // Compact version
|
625
|
-
'<span class="' + this._rowClass + ' ' + this._amountClass +
|
626
|
-
(inst._hold ? ' ' + this._holdingClass : '') + '">' +
|
627
|
-
showCompact(Y) + showCompact(O) + showCompact(W) + showCompact(D) +
|
628
|
-
(show[H] ? this._minDigits(inst, inst._periods[H], 2) : '') +
|
629
|
-
(show[M] ? (show[H] ? inst.options.timeSeparator : '') +
|
630
|
-
this._minDigits(inst, inst._periods[M], 2) : '') +
|
631
|
-
(show[S] ? (show[H] || show[M] ? inst.options.timeSeparator : '') +
|
632
|
-
this._minDigits(inst, inst._periods[S], 2) : '') :
|
633
|
-
// Full version
|
634
|
-
'<span class="' + this._rowClass + ' ' + this._showClass + (inst.options.significant || showCount) +
|
635
|
-
(inst._hold ? ' ' + this._holdingClass : '') + '">' +
|
636
|
-
showFull(Y) + showFull(O) + showFull(W) + showFull(D) +
|
637
|
-
showFull(H) + showFull(M) + showFull(S)) + '</span>' +
|
638
|
-
(inst.options.description ? '<span class="' + this._rowClass + ' ' + this._descrClass + '">' +
|
639
|
-
inst.options.description + '</span>' : '')));
|
640
|
-
},
|
641
|
-
|
642
|
-
/** Construct a custom layout.
|
643
|
-
@private
|
644
|
-
@param inst {object} The current settings for this instance.
|
645
|
-
@param show {boolean[]} Flags indicating which periods are requested.
|
646
|
-
@param layout {string} The customised layout.
|
647
|
-
@param compact {boolean} True if using compact labels.
|
648
|
-
@param significant {number} The number of periods with values to show, zero for all.
|
649
|
-
@param showSignificant {boolean[]} Other periods to show for significance.
|
650
|
-
@return {string} The custom HTML. */
|
651
|
-
_buildLayout: function(inst, show, layout, compact, significant, showSignificant) {
|
652
|
-
var labels = inst.options[compact ? 'compactLabels' : 'labels'];
|
653
|
-
var whichLabels = inst.options.whichLabels || this._normalLabels;
|
654
|
-
var labelFor = function(index) {
|
655
|
-
return (inst.options[(compact ? 'compactLabels' : 'labels') +
|
656
|
-
whichLabels(inst._periods[index])] || labels)[index];
|
657
|
-
};
|
658
|
-
var digit = function(value, position) {
|
659
|
-
return inst.options.digits[Math.floor(value / position) % 10];
|
660
|
-
};
|
661
|
-
var subs = {desc: inst.options.description, sep: inst.options.timeSeparator,
|
662
|
-
yl: labelFor(Y), yn: this._minDigits(inst, inst._periods[Y], 1),
|
663
|
-
ynn: this._minDigits(inst, inst._periods[Y], 2),
|
664
|
-
ynnn: this._minDigits(inst, inst._periods[Y], 3), y1: digit(inst._periods[Y], 1),
|
665
|
-
y10: digit(inst._periods[Y], 10), y100: digit(inst._periods[Y], 100),
|
666
|
-
y1000: digit(inst._periods[Y], 1000),
|
667
|
-
ol: labelFor(O), on: this._minDigits(inst, inst._periods[O], 1),
|
668
|
-
onn: this._minDigits(inst, inst._periods[O], 2),
|
669
|
-
onnn: this._minDigits(inst, inst._periods[O], 3), o1: digit(inst._periods[O], 1),
|
670
|
-
o10: digit(inst._periods[O], 10), o100: digit(inst._periods[O], 100),
|
671
|
-
o1000: digit(inst._periods[O], 1000),
|
672
|
-
wl: labelFor(W), wn: this._minDigits(inst, inst._periods[W], 1),
|
673
|
-
wnn: this._minDigits(inst, inst._periods[W], 2),
|
674
|
-
wnnn: this._minDigits(inst, inst._periods[W], 3), w1: digit(inst._periods[W], 1),
|
675
|
-
w10: digit(inst._periods[W], 10), w100: digit(inst._periods[W], 100),
|
676
|
-
w1000: digit(inst._periods[W], 1000),
|
677
|
-
dl: labelFor(D), dn: this._minDigits(inst, inst._periods[D], 1),
|
678
|
-
dnn: this._minDigits(inst, inst._periods[D], 2),
|
679
|
-
dnnn: this._minDigits(inst, inst._periods[D], 3), d1: digit(inst._periods[D], 1),
|
680
|
-
d10: digit(inst._periods[D], 10), d100: digit(inst._periods[D], 100),
|
681
|
-
d1000: digit(inst._periods[D], 1000),
|
682
|
-
hl: labelFor(H), hn: this._minDigits(inst, inst._periods[H], 1),
|
683
|
-
hnn: this._minDigits(inst, inst._periods[H], 2),
|
684
|
-
hnnn: this._minDigits(inst, inst._periods[H], 3), h1: digit(inst._periods[H], 1),
|
685
|
-
h10: digit(inst._periods[H], 10), h100: digit(inst._periods[H], 100),
|
686
|
-
h1000: digit(inst._periods[H], 1000),
|
687
|
-
ml: labelFor(M), mn: this._minDigits(inst, inst._periods[M], 1),
|
688
|
-
mnn: this._minDigits(inst, inst._periods[M], 2),
|
689
|
-
mnnn: this._minDigits(inst, inst._periods[M], 3), m1: digit(inst._periods[M], 1),
|
690
|
-
m10: digit(inst._periods[M], 10), m100: digit(inst._periods[M], 100),
|
691
|
-
m1000: digit(inst._periods[M], 1000),
|
692
|
-
sl: labelFor(S), sn: this._minDigits(inst, inst._periods[S], 1),
|
693
|
-
snn: this._minDigits(inst, inst._periods[S], 2),
|
694
|
-
snnn: this._minDigits(inst, inst._periods[S], 3), s1: digit(inst._periods[S], 1),
|
695
|
-
s10: digit(inst._periods[S], 10), s100: digit(inst._periods[S], 100),
|
696
|
-
s1000: digit(inst._periods[S], 1000)};
|
697
|
-
var html = layout;
|
698
|
-
// Replace period containers: {p<}...{p>}
|
699
|
-
for (var i = Y; i <= S; i++) {
|
700
|
-
var period = 'yowdhms'.charAt(i);
|
701
|
-
var re = new RegExp('\\{' + period + '<\\}([\\s\\S]*)\\{' + period + '>\\}', 'g');
|
702
|
-
html = html.replace(re, ((!significant && show[i]) ||
|
703
|
-
(significant && showSignificant[i]) ? '$1' : ''));
|
704
|
-
}
|
705
|
-
// Replace period values: {pn}
|
706
|
-
$.each(subs, function(n, v) {
|
707
|
-
var re = new RegExp('\\{' + n + '\\}', 'g');
|
708
|
-
html = html.replace(re, v);
|
709
|
-
});
|
710
|
-
return html;
|
711
|
-
},
|
712
|
-
|
713
|
-
/** Ensure a numeric value has at least n digits for display.
|
714
|
-
@private
|
715
|
-
@param inst {object} The current settings for this instance.
|
716
|
-
@param value {number} The value to display.
|
717
|
-
@param len {number} The minimum length.
|
718
|
-
@return {string} The display text. */
|
719
|
-
_minDigits: function(inst, value, len) {
|
720
|
-
value = '' + value;
|
721
|
-
if (value.length >= len) {
|
722
|
-
return this._translateDigits(inst, value);
|
723
|
-
}
|
724
|
-
value = '0000000000' + value;
|
725
|
-
return this._translateDigits(inst, value.substr(value.length - len));
|
726
|
-
},
|
727
|
-
|
728
|
-
/** Translate digits into other representations.
|
729
|
-
@private
|
730
|
-
@param inst {object} The current settings for this instance.
|
731
|
-
@param value {string} The text to translate.
|
732
|
-
@return {string} The translated text. */
|
733
|
-
_translateDigits: function(inst, value) {
|
734
|
-
return ('' + value).replace(/[0-9]/g, function(digit) {
|
735
|
-
return inst.options.digits[digit];
|
736
|
-
});
|
737
|
-
},
|
738
|
-
|
739
|
-
/** Translate the format into flags for each period.
|
740
|
-
@private
|
741
|
-
@param inst {object} The current settings for this instance.
|
742
|
-
@return {string[]} Flags indicating which periods are requested (?) or
|
743
|
-
required (!) by year, month, week, day, hour, minute, second. */
|
744
|
-
_determineShow: function(inst) {
|
745
|
-
var format = inst.options.format;
|
746
|
-
var show = [];
|
747
|
-
show[Y] = (format.match('y') ? '?' : (format.match('Y') ? '!' : null));
|
748
|
-
show[O] = (format.match('o') ? '?' : (format.match('O') ? '!' : null));
|
749
|
-
show[W] = (format.match('w') ? '?' : (format.match('W') ? '!' : null));
|
750
|
-
show[D] = (format.match('d') ? '?' : (format.match('D') ? '!' : null));
|
751
|
-
show[H] = (format.match('h') ? '?' : (format.match('H') ? '!' : null));
|
752
|
-
show[M] = (format.match('m') ? '?' : (format.match('M') ? '!' : null));
|
753
|
-
show[S] = (format.match('s') ? '?' : (format.match('S') ? '!' : null));
|
754
|
-
return show;
|
755
|
-
},
|
756
|
-
|
757
|
-
/** Calculate the requested periods between now and the target time.
|
758
|
-
@private
|
759
|
-
@param inst {object} The current settings for this instance.
|
760
|
-
@param show {string[]} Flags indicating which periods are requested/required.
|
761
|
-
@param significant {number} The number of periods with values to show, zero for all.
|
762
|
-
@param now {Date} The current date and time.
|
763
|
-
@return {number[]} The current time periods (always positive)
|
764
|
-
by year, month, week, day, hour, minute, second. */
|
765
|
-
_calculatePeriods: function(inst, show, significant, now) {
|
766
|
-
// Find endpoints
|
767
|
-
inst._now = now;
|
768
|
-
inst._now.setMilliseconds(0);
|
769
|
-
var until = new Date(inst._now.getTime());
|
770
|
-
if (inst._since) {
|
771
|
-
if (now.getTime() < inst._since.getTime()) {
|
772
|
-
inst._now = now = until;
|
773
|
-
}
|
774
|
-
else {
|
775
|
-
now = inst._since;
|
776
|
-
}
|
777
|
-
}
|
778
|
-
else {
|
779
|
-
until.setTime(inst._until.getTime());
|
780
|
-
if (now.getTime() > inst._until.getTime()) {
|
781
|
-
inst._now = now = until;
|
782
|
-
}
|
783
|
-
}
|
784
|
-
// Calculate differences by period
|
785
|
-
var periods = [0, 0, 0, 0, 0, 0, 0];
|
786
|
-
if (show[Y] || show[O]) {
|
787
|
-
// Treat end of months as the same
|
788
|
-
var lastNow = this._getDaysInMonth(now.getFullYear(), now.getMonth());
|
789
|
-
var lastUntil = this._getDaysInMonth(until.getFullYear(), until.getMonth());
|
790
|
-
var sameDay = (until.getDate() == now.getDate() ||
|
791
|
-
(until.getDate() >= Math.min(lastNow, lastUntil) &&
|
792
|
-
now.getDate() >= Math.min(lastNow, lastUntil)));
|
793
|
-
var getSecs = function(date) {
|
794
|
-
return (date.getHours() * 60 + date.getMinutes()) * 60 + date.getSeconds();
|
795
|
-
};
|
796
|
-
var months = Math.max(0,
|
797
|
-
(until.getFullYear() - now.getFullYear()) * 12 + until.getMonth() - now.getMonth() +
|
798
|
-
((until.getDate() < now.getDate() && !sameDay) ||
|
799
|
-
(sameDay && getSecs(until) < getSecs(now)) ? -1 : 0));
|
800
|
-
periods[Y] = (show[Y] ? Math.floor(months / 12) : 0);
|
801
|
-
periods[O] = (show[O] ? months - periods[Y] * 12 : 0);
|
802
|
-
// Adjust for months difference and end of month if necessary
|
803
|
-
now = new Date(now.getTime());
|
804
|
-
var wasLastDay = (now.getDate() == lastNow);
|
805
|
-
var lastDay = this._getDaysInMonth(now.getFullYear() + periods[Y],
|
806
|
-
now.getMonth() + periods[O]);
|
807
|
-
if (now.getDate() > lastDay) {
|
808
|
-
now.setDate(lastDay);
|
809
|
-
}
|
810
|
-
now.setFullYear(now.getFullYear() + periods[Y]);
|
811
|
-
now.setMonth(now.getMonth() + periods[O]);
|
812
|
-
if (wasLastDay) {
|
813
|
-
now.setDate(lastDay);
|
814
|
-
}
|
815
|
-
}
|
816
|
-
var diff = Math.floor((until.getTime() - now.getTime()) / 1000);
|
817
|
-
var extractPeriod = function(period, numSecs) {
|
818
|
-
periods[period] = (show[period] ? Math.floor(diff / numSecs) : 0);
|
819
|
-
diff -= periods[period] * numSecs;
|
820
|
-
};
|
821
|
-
extractPeriod(W, 604800);
|
822
|
-
extractPeriod(D, 86400);
|
823
|
-
extractPeriod(H, 3600);
|
824
|
-
extractPeriod(M, 60);
|
825
|
-
extractPeriod(S, 1);
|
826
|
-
if (diff > 0 && !inst._since) { // Round up if left overs
|
827
|
-
var multiplier = [1, 12, 4.3482, 7, 24, 60, 60];
|
828
|
-
var lastShown = S;
|
829
|
-
var max = 1;
|
830
|
-
for (var period = S; period >= Y; period--) {
|
831
|
-
if (show[period]) {
|
832
|
-
if (periods[lastShown] >= max) {
|
833
|
-
periods[lastShown] = 0;
|
834
|
-
diff = 1;
|
835
|
-
}
|
836
|
-
if (diff > 0) {
|
837
|
-
periods[period]++;
|
838
|
-
diff = 0;
|
839
|
-
lastShown = period;
|
840
|
-
max = 1;
|
841
|
-
}
|
842
|
-
}
|
843
|
-
max *= multiplier[period];
|
844
|
-
}
|
845
|
-
}
|
846
|
-
if (significant) { // Zero out insignificant periods
|
847
|
-
for (var period = Y; period <= S; period++) {
|
848
|
-
if (significant && periods[period]) {
|
849
|
-
significant--;
|
850
|
-
}
|
851
|
-
else if (!significant) {
|
852
|
-
periods[period] = 0;
|
853
|
-
}
|
854
|
-
}
|
855
|
-
}
|
856
|
-
return periods;
|
857
|
-
}
|
858
|
-
});
|
859
|
-
|
860
|
-
})(jQuery);
|
3
|
+
//= require jquery.countdown.upstream
|