PageSourceSearch

https://nba.gov.cy/wp-content/themes/enfold/config-templatebuilder…/countdown/countdown.js?ver=5.6.2

js nba.gov.cy collected 2026-10-02 06:06:32 UTC 9,781 bytes, 374 lines download raw bytes

1// -------------------------------------------------------------------------------------------
2//
3// AVIA Countdown
4//
5// @since 4.5.6  Countdown is UTC based to reflect different browser timezones
6// @since 5.5  flip clocks added
7//
8// -------------------------------------------------------------------------------------------
9
10var aviaJS = aviaJS || {};
11
12(function($)
13{
14	"use strict";
15
16	var _units	= ['years','months','weeks','days','hours','minutes','seconds'],
17		_second = 1000,
18		_minute = _second * 60,
19		_hour 	= _minute * 60,
20		_day 	= _hour * 24,
21		_week	= _day * 7,
22
23		getDaysInMonth = function( month, year )
24		{
25			//	January is 1 based
26			return new Date( year, month, 0 ).getDate();
27		},
28
29		splitStartDate = function( date )
30		{
31			var result = {
32						year: date.getFullYear(),
33						month: date.getMonth() + 1,
34						day: date.getDate(),
35						hours: date.getHours(),
36						minutes: date.getMinutes(),
37						seconds: date.getSeconds()
38					};
39
40			return result;
41		},
42
43		getYears = function( start, endDate )
44		{
45			var diff = endDate.getFullYear() - start.year;
46
47			if( diff > 0 )
48			{
49				//	take care of leap year
50				var check = new Date( start.year + diff, start.month - 1, start.day, start.hours, start.minutes, start.seconds );
51				if( check > endDate )
52				{
53					diff --;
54				}
55			}
56
57			return ( diff >= 0 ) ? diff : 0;
58		},
59
60		getMonths = function( start, endDate )
61		{
62			var endMonth = endDate.getMonth() + 1;
63			var diff = endMonth - start.month;
64			if( diff < 0 )
65			{
66				diff = 12 - start.month + endMonth;
67			}
68
69			if( diff > 0 )
70			{
71				//	take care of leap year
72				var check = new Date( start.year, start.month - 1 + diff, start.day, start.hours, start.minutes, start.seconds );
73				if( check > endDate )
74				{
75					diff --;
76				}
77			}
78
79			return ( diff >= 0 ) ? diff : 0;
80		},
81
82		getDays = function( start, endDate )
83		{
84			var endDay = endDate.getDate();
85			var diff = endDay - start.day;
86			if( diff < 0 )
87			{
88				diff = getDaysInMonth( start.month, start.year ) - start.day + endDay;
89			}
90
91			if( diff > 0 )
92			{
93				var check = new Date( start.year, start.month - 1, start.day + diff, start.hours, start.minutes, start.seconds );
94				if( check > endDate )
95				{
96					diff --;
97				}
98			}
99
100			return ( diff >= 0 ) ? diff : 0;
101		},
102
103		getBetween = function( startDate, endDate )
104		{
105			var start = splitStartDate( startDate ),
106				result = {
107							years: 0,
108							year_months: 0,
109							month_months: 0,
110							days: 0
111						};
112
113
114			result.years = getYears( start, endDate );
115			start.year += result.years;
116
117			result.year_months = getMonths( start, endDate );
118			start.month += result.year_months;
119
120			result.days = getDays( start, endDate );
121			start.day += result.days;
122
123			result.month_months = result.years * 12 + result.year_months;
124
125			return result;
126		},
127
128		setLabelMinWidth = function( _self, reset )
129		{
130			if( true === reset )
131			{
132				for( let i in _self.time )
133				{
134					if( typeof _self.update[i] == "object"  && _self.update[i].label_container.length )
135					{
136						_self.update[i].label_container.css( { "min-width": '' } );
137					}
138				}
139
140				_self.labelMinWidth = 0;
141
142				return;
143			}
144
145			let newMin = _self.labelMinWidth;
146
147			for( let i in _self.time )
148			{
149				if( typeof _self.update[i] == "object"  && _self.update[i].label_container.length )
150				{
151					let curr = _self.update[i].label_container.outerWidth( true );
152
153					if( newMin < curr )
154					{
155						newMin = curr;
156					}
157				}
158			}
159
160			if( newMin > _self.labelMinWidth )
161			{
162				for( let i in _self.time )
163				{
164					if( typeof _self.update[i] == "object"  && _self.update[i].label_container.length )
165					{
166						_self.update[i].label_container.css( { "min-width": newMin + "px" } );
167					}
168				}
169
170				_self.labelMinWidth = newMin;
171			}
172		},
173
174		ticker = function( _self )
175		{
176			var tmLoc = new Date(),
177				_now = new Date( tmLoc.getTime() + tmLoc.getTimezoneOffset() * 60000 ),		//	get UTC time
178				_timestamp = _self.end - _now;
179
180			if( _timestamp <= 0 )
181			{
182				clearInterval( _self.countdown );
183				return;
184			}
185
186			_self.time.years	= 0;
187			_self.time.months	= 0;
188			_self.time.weeks   	= Math.floor( _timestamp / _week );
189			_self.time.days 	= Math.floor( ( _timestamp % _week ) / _day );
190			_self.time.hours	= Math.floor( ( _timestamp % _day ) / _hour );
191			_self.time.minutes 	= Math.floor( ( _timestamp % _hour ) / _minute );
192			_self.time.seconds 	= Math.floor( ( _timestamp % _minute ) / _second );
193
194			var between = getBetween( _now, _self.end );
195
196			switch( _self.data.maximum )
197			{
198				case 1:
199					_self.time.seconds = Math.floor( _timestamp / _second );
200					break;
201				case 2:
202					_self.time.minutes = Math.floor( _timestamp / _minute );
203					break;
204				case 3:
205					_self.time.hours = Math.floor( _timestamp / _hour );
206					break;
207				case 4:
208					_self.time.days = Math.floor( _timestamp / _day );
209					break;
210				case 6:
211					_self.time.days = between.days;
212					_self.time.months = between.month_months;
213					break;
214				case 7:
215					_self.time.days = between.days;
216					_self.time.months = between.year_months;
217					_self.time.years  = between.years;
218					break;
219			}
220
221			for( let i in _self.time )
222			{
223				if( typeof _self.update[i] == "object" && _self.update[i].label_container.length )
224				{
225					if(_self.firstrun || _self.oldtime[i] != _self.time[i])
226					{
227						let labelkey = ( _self.time[i] === 1 ) ? "single" : "multi",
228							new_label = _self.update[i][labelkey],
229							old_label = _self.update[i].label_container.text();
230
231						if( old_label != new_label )
232						{
233							_self.update[i].label_container.text( new_label );
234						}
235
236						if( _self.isFlipNumbers )
237						{
238							if( _self.update[i].unitContainer.length )
239							{
240								if( ! _self.firstrun )
241								{
242									_self.update[i].backCard.attr( 'data-value', _self.oldtime[i] );
243									_self.update[i].bottomCard.attr( 'data-value', _self.oldtime[i] );
244								}
245
246								_self.update[i].topCard.text( _self.time[i] );
247								_self.update[i].backBottomCard.attr( 'data-value', _self.time[i] );
248
249								_self.update[i].unitContainer.removeClass( 'flip' );
250								void _self.update[i].unitContainer[0].offsetWidth;
251								_self.update[i].unitContainer.addClass( 'flip' );
252							}
253						}
254						else if( _self.isFlipClock )
255						{
256							if( _self.update[i].unitContainer.length )
257							{
258								if( ! _self.firstrun )
259								{
260									_self.update[i].currentTop.text( _self.oldtime[i] );
261									_self.update[i].currentBottom.text( _self.oldtime[i] );
262								}
263
264								_self.update[i].nextTop.text( _self.time[i] );
265								_self.update[i].nextBottom.text( _self.time[i] );
266
267								_self.update[i].unitContainer.removeClass( 'flip' );
268								void _self.update[i].unitContainer[0].offsetWidth;
269								_self.update[i].unitContainer.addClass( 'flip' );
270							}
271						}
272						else
273						{
274							_self.update[i].time_container.text(_self.time[i]);
275						}
276					}
277				}
278			}
279
280			//show ticker
281			if( _self.firstrun )
282			{
283				_self.container.addClass('av-countdown-active');
284			}
285
286			_self.oldtime = $.extend( {}, _self.time );
287			_self.firstrun = false;
288
289			if( ( _self.isFlipNumbers || _self.isFlipClock ) && _self.number_space )
290			{
291				setTimeout( function()
292				{
293					setLabelMinWidth( _self );
294				}, 50 );
295			}
296		};
297
298
299	$.fn.aviaCountdown = function( options )
300	{
301		if( ! this.length )
302		{
303			return;
304		}
305
306		return this.each( function()
307		{
308			var _self = {};
309
310			_self.update = {};
311			_self.time = {};
312			_self.oldtime = {};
313			_self.firstrun = true;
314			_self.container = $(this);
315			_self.data = _self.container.data();
316			_self.end = new Date( _self.data.year, _self.data.month, _self.data.day, _self.data.hour, _self.data.minute );
317			_self.isFlipNumbers = _self.container.hasClass('av-flip-numbers');
318			_self.isFlipClock = _self.container.hasClass('av-flip-clock');
319			_self.number_space = _self.container.hasClass('av-number-space-equal');
320			_self.labelMinWidth = 0;
321
322			var onResize = function( e )
323			{
324				if( _self.number_space )
325				{
326					setLabelMinWidth( _self, true );
327				}
328			};
329
330			if( _self.data.timezone != '0' )
331			{
332				_self.end = new Date( _self.end.getTime() - _self.data.timezone * 60000 );
333			}
334
335			for( var i in _units )
336			{
337				let unitContainer = _self.container.find('.av-countdown-' + _units[i] );
338
339				_self.update[_units[i]] = {
340										unitContainer:	 unitContainer,
341										time_container:  _self.container.find('.av-countdown-' + _units[i] + ' .av-countdown-time'),
342										label_container: _self.container.find('.av-countdown-' + _units[i] + ' .av-countdown-time-label')
343									};
344
345				if( _self.update[_units[i]].label_container.length )
346				{
347					_self.update[_units[i]].single = _self.update[_units[i]].label_container.data('label');
348					_self.update[_units[i]].multi  = _self.update[_units[i]].label_container.data('label-multi');
349				}
350
351				if( _self.isFlipNumbers )
352				{
353					_self.update[_units[i]].topCard = unitContainer.find('.card__top');
354					_self.update[_units[i]].bottomCard = unitContainer.find('.card__bottom');
355					_self.update[_units[i]].backCard = unitContainer.find('.card__back');
356					_self.update[_units[i]].backBottomCard = unitContainer.find('.card__back .card__bottom');
357				}
358				else if( _self.isFlipClock )
359				{
360					_self.update[_units[i]].currentTop = unitContainer.find('.curr.top');
361					_self.update[_units[i]].nextTop = unitContainer.find('.next.top');
362					_self.update[_units[i]].nextBottom = unitContainer.find('.next.bottom');
363					_self.update[_units[i]].currentBottom = unitContainer.find('.curr.bottom');
364				}
365			}
366
367			ticker( _self );
368			_self.countdown = setInterval( function(){ ticker( _self ); }, 1000 );
369
370			window.addEventListener( 'resize', aviaJS.aviaJSHelpers.debounce( onResize.bind( this ), 50 ) );
371		});
372	};
373
374}(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.