PageSourceSearch

https://stopchildlabor.org/wp-content/themes/enfold/config-templat…/countdown/countdown.js?ver=7.0.5

js stopchildlabor.org collected 2026-10-02 06:55:53 UTC 5,864 bytes, 239 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//
7// -------------------------------------------------------------------------------------------
8(function($)
9{
10	"use strict";
11
12	var _units	= ['years','months','weeks','days','hours','minutes','seconds'],
13		_second = 1000,
14		_minute = _second * 60,
15		_hour 	= _minute * 60,
16		_day 	= _hour * 24,
17		_week	= _day * 7,
18
19		getDaysInMonth = function( month, year )
20		{
21			//	January is 1 based
22			return new Date( year, month, 0 ).getDate();
23		},
24
25		splitStartDate = function( date )
26		{
27			var result = {
28						year: date.getFullYear(),
29						month: date.getMonth() + 1,
30						day: date.getDate(),
31						hours: date.getHours(),
32						minutes: date.getMinutes(),
33						seconds: date.getSeconds()
34					};
35
36			return result;
37		},
38
39		getYears = function( start, endDate )
40		{
41			var diff = endDate.getFullYear() - start.year;
42
43			if( diff > 0 )
44			{
45				//	take care of leap year
46				var check = new Date( start.year + diff, start.month - 1, start.day, start.hours, start.minutes, start.seconds );
47				if( check > endDate )
48				{
49					diff --;
50				}
51			}
52
53			return ( diff >= 0 ) ? diff : 0;
54		},
55
56		getMonths = function( start, endDate )
57		{
58			var endMonth = endDate.getMonth() + 1;
59			var diff = endMonth - start.month;
60			if( diff < 0 )
61			{
62				diff = 12 - start.month + endMonth;
63			}
64
65			if( diff > 0 )
66			{
67				//	take care of leap year
68				var check = new Date( start.year, start.month - 1 + diff, start.day, start.hours, start.minutes, start.seconds );
69				if( check > endDate )
70				{
71					diff --;
72				}
73			}
74
75			return ( diff >= 0 ) ? diff : 0;
76		},
77
78		getDays = function( start, endDate )
79		{
80			var endDay = endDate.getDate();
81			var diff = endDay - start.day;
82			if( diff < 0 )
83			{
84				diff = getDaysInMonth( start.month, start.year ) - start.day + endDay;
85			}
86
87			if( diff > 0 )
88			{
89				var check = new Date( start.year, start.month - 1, start.day + diff, start.hours, start.minutes, start.seconds );
90				if( check > endDate )
91				{
92					diff --;
93				}
94			}
95
96			return ( diff >= 0 ) ? diff : 0;
97		},
98
99		getBetween = function( startDate, endDate )
100		{
101			var start = splitStartDate( startDate ),
102				result = {
103							years: 0,
104							year_months: 0,
105							month_months: 0,
106							days: 0
107						};
108
109
110			result.years = getYears( start, endDate );
111			start.year += result.years;
112
113			result.year_months = getMonths( start, endDate );
114			start.month += result.year_months;
115
116			result.days = getDays( start, endDate );
117			start.day += result.days;
118
119			result.month_months = result.years * 12 + result.year_months;
120
121			return result;
122		},
123
124		ticker = function( _self )
125		{
126			var tmLoc = new Date(),
127				_now = new Date( tmLoc.getTime() + tmLoc.getTimezoneOffset() * 60000 ),		//	get UTC time
128				_timestamp = _self.end - _now;
129
130			if( _timestamp <= 0 )
131			{
132				clearInterval( _self.countdown );
133				return;
134			}
135
136			_self.time.years	= 0;
137			_self.time.months	= 0;
138			_self.time.weeks   	= Math.floor( _timestamp / _week );
139			_self.time.days 	= Math.floor( ( _timestamp % _week ) / _day );
140			_self.time.hours	= Math.floor( ( _timestamp % _day ) / _hour );
141			_self.time.minutes 	= Math.floor( ( _timestamp % _hour ) / _minute );
142			_self.time.seconds 	= Math.floor( ( _timestamp % _minute ) / _second );
143
144			var between = getBetween( _now, _self.end );
145
146			switch( _self.data.maximum )
147			{
148				case 1:
149					_self.time.seconds = Math.floor( _timestamp / _second );
150					break;
151				case 2:
152					_self.time.minutes = Math.floor( _timestamp / _minute );
153					break;
154				case 3:
155					_self.time.hours = Math.floor( _timestamp / _hour );
156					break;
157				case 4:
158					_self.time.days = Math.floor( _timestamp / _day );
159					break;
160				case 6:
161					_self.time.days = between.days;
162					_self.time.months = between.month_months;
163					break;
164				case 7:
165					_self.time.days = between.days;
166					_self.time.months = between.year_months;
167					_self.time.years  = between.years;
168					break;
169			}
170
171			for( var i in _self.time )
172			{
173				if( typeof _self.update[i] == "object" )
174				{
175					if(_self.firstrun || _self.oldtime[i] != _self.time[i])
176					{
177						var labelkey = ( _self.time[i] === 1 ) ? "single" : "multi";
178
179						_self.update[i].time_container.text(_self.time[i]);
180						_self.update[i].label_container.text(_self.update[i][labelkey]);
181					}
182				}
183			}
184
185			//show ticker
186			if( _self.firstrun )
187			{
188				_self.container.addClass('av-countdown-active');
189			}
190
191			_self.oldtime = $.extend( {}, _self.time );
192			_self.firstrun = false;
193		};
194
195
196	$.fn.aviaCountdown = function( options )
197	{
198		if( ! this.length )
199		{
200			return;
201		}
202
203		return this.each( function()
204		{
205			var _self = {};
206
207			_self.update = {};
208			_self.time = {};
209			_self.oldtime = {};
210			_self.firstrun = true;
211			_self.container = $(this);
212			_self.data = _self.container.data();
213			_self.end = new Date( _self.data.year, _self.data.month, _self.data.day, _self.data.hour, _self.data.minute );
214
215			if( _self.data.timezone != '0' )
216			{
217				_self.end = new Date( _self.end.getTime() - _self.data.timezone * 60000 );
218			}
219
220			for( var i in _units )
221			{
222				_self.update[_units[i]] = {
223										time_container:  _self.container.find('.av-countdown-' + _units[i] + ' .av-countdown-time'),
224										label_container: _self.container.find('.av-countdown-' + _units[i] + ' .av-countdown-time-label')
225									};
226
227				if( _self.update[_units[i]].label_container.length )
228				{
229					_self.update[_units[i]].single = _self.update[_units[i]].label_container.data('label');
230					_self.update[_units[i]].multi  = _self.update[_units[i]].label_container.data('label-multi');
231				}
232			}
233
234			ticker( _self );
235			_self.countdown = setInterval( function(){ ticker( _self ); }, 1000 );
236		});
237	};
238
239}(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.